Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
+ Fixed Enter on Hotel
+ Fixed some Castings
+ Fixed Creating Rooms
+ Fixed PathFinder FindPath
+ Fixed Buy Item
+ Cleaned some Code
+ Improved Database things
+ Continued Database improvement
+ Continued Core Refactoring
  • Loading branch information
ovflowd committed Dec 15, 2015
1 parent 7777464 commit bee3910
Show file tree
Hide file tree
Showing 41 changed files with 6,110 additions and 5,892 deletions.
10,348 changes: 5,205 additions & 5,143 deletions SQL/Database.sql

Large diffs are not rendered by default.

427 changes: 427 additions & 0 deletions Yupi/Build/Variables/Cache/FurniDataCache.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Yupi/Build/Variables/Settings/Welcome/settings.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
welcome.message.enabled=true
welcome.message.enabled=false
welcome.message.title=Notification
welcome.message.image=builders_club_membership_extended
13 changes: 3 additions & 10 deletions Yupi/Build/Variables/Settings/main.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
## Azure Emulator System Configuration File
## Must be edited for the server to work
## Yupi Server Settings

## MySQL Configuration
db.hostname=172.16.9.69
db.hostname=172.16.9.84
db.port=3306
db.username=azure
db.password=123
db.name=teste
db.type=MySQL

## MySQL pooling setup (controls amount of connections)
db.pool.minsize=1
Expand All @@ -19,15 +17,10 @@ game.tcp.port=30000
game.tcp.conlimit=11000
game.tcp.enablenagles=true

##Tcp Flood AntiDDoS Comment: For proxy antiddos=false
## Tcp Flood AntiDDoS Comment: For proxy antiddos=false
game.tcp.antiddos=false
game.tcp.conperip=30

## MUS TCP/IP Configuration
mus.tcp.bindip=127.0.0.1
mus.tcp.port=30008
mus.tcp.allowedaddr=127.0.0.1

## Client configuration
client.ping.enabled=1
client.ping.interval=20000
Expand Down
2 changes: 0 additions & 2 deletions Yupi/Build/Variables/Settings/other.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ stories.api.thumbnail.url=http://azure-stories-content.azurewebsites.net/servert
# Interactive stuff #
everyone.use.floor=true
admin.can.useHTML=true
commands.new.page=true
figuredata.url=http://localhost/gamedata/figuredata/1.xml
furnidata.url=http://www.maniahotel.com.br/source/gamedata/furnidata_xml/furnidata_xml.xml
youtube.thumbnail.suburl=youtubethumbnail.php?Video
1 change: 0 additions & 1 deletion Yupi/Core/Settings/ConsoleCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ internal static void InvokeCommand(string inputData)
switch (strArray[1])
{
case "database":
Yupi.GetDatabaseManager().Destroy();
Console.WriteLine("Database destroyed");
Console.WriteLine();
break;
Expand Down
91 changes: 28 additions & 63 deletions Yupi/Data/Base/Connections/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,109 +14,75 @@ namespace Yupi.Data.Base.Connections
{
public class ConnectionManager
{
public static string DatabaseConnectionType = "MySQL";
public static bool DbEnabled = true;

private readonly uint _beginClientAmount;
private readonly uint _maxPoolSize;

private readonly Queue _connections;

private string _connectionString;

private List<MySqlClient> _databaseClients;
private bool _isConnected;

private DatabaseServer _server;

public ConnectionManager(uint maxPoolSize, uint clientAmount)
{
if (maxPoolSize < clientAmount)
throw new DatabaseException("The poolsize can not be larger than the client amount!");

_beginClientAmount = clientAmount;
_maxPoolSize = maxPoolSize;

_connections = new Queue();
}

public void Destroy()
{
var flag = false;
try
{
Monitor.Enter(this, ref flag);
_isConnected = false;
if (_databaseClients == null)
return;
foreach (var current in _databaseClients)
{
if (!current.IsAvailable())
current.Dispose();
current.Disconnect();
}
_databaseClients.Clear();
}
finally
if (_databaseClients == null)
return;

foreach (MySqlClient current in _databaseClients)
{
if (flag)
Monitor.Exit(this);
if (!current.IsAvailable())
current.Dispose();

current.Disconnect();
}
}

public string GetConnectionString()
{
return _connectionString;
_databaseClients.Clear();
}

public string GetConnectionString() => _connectionString;

public IQueryAdapter GetQueryReactor()
{
IDatabaseClient databaseClient = new MySqlClient(this);

databaseClient.Connect();
databaseClient.Prepare();

return databaseClient.GetQueryReactor();
}

public void FreeConnection(IDatabaseClient dbClient)
{
lock (_connections.SyncRoot)
{
_connections.Enqueue(dbClient);
}
}

public void Init()
{
try
{
CreateNewConnectionString();
_databaseClients = new List<MySqlClient>((int)_maxPoolSize);
}
catch (MySqlException ex)
{
_isConnected = false;
throw new Exception($"Could not connect the clients to the database: {ex.Message}");
}
_isConnected = true;
}
CreateNewConnectionString();

public bool IsConnectedToDatabase()
{
return _isConnected;
_databaseClients = new List<MySqlClient>((int)_maxPoolSize);
}

public bool SetServerDetails(string host, uint port, string username, string password, string databaseName)
{
bool result;
try
{
_server = new DatabaseServer(host, port, username, password, databaseName);
result = true;
}
catch (DatabaseException)
{
_isConnected = false;
result = false;
}
return result;
}
public void SetServerDetails(string host, uint port, string username, string password, string databaseName) => _server = new DatabaseServer(host, port, username, password, databaseName);

private void CreateNewConnectionString()
{
var mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder
MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder
{
Server = _server.GetHost(),
Port = _server.GetPort(),
Expand All @@ -131,13 +97,12 @@ private void CreateNewConnectionString()
DefaultCommandTimeout = 300,
ConnectionTimeout = 10
};
var mySqlConnectionStringBuilder2 = mySqlConnectionStringBuilder;

MySqlConnectionStringBuilder mySqlConnectionStringBuilder2 = mySqlConnectionStringBuilder;

SetConnectionString(mySqlConnectionStringBuilder2.ToString());
}

private void SetConnectionString(string connectionString)
{
_connectionString = connectionString;
}
private void SetConnectionString(string connectionString) => _connectionString = connectionString;
}
}
65 changes: 14 additions & 51 deletions Yupi/Data/Base/Connections/DatabaseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,80 +33,43 @@ public class DatabaseConnection : IDatabaseClient
{
private readonly MySqlConnection _mysqlConnection;
private readonly IQueryAdapter _adapter;
private readonly int _type;

public DatabaseConnection(string connectionStr, string connType)
public DatabaseConnection(string connectionStr)
{
switch (connType.ToLower())
{
default: // MySQL
_mysqlConnection = new MySqlConnection(connectionStr);
_adapter = new NormalQueryReactor(this);
_type = 1;
break;
}
_mysqlConnection = new MySqlConnection(connectionStr);
_adapter = new NormalQueryReactor(this);
}

public void Open()
{
if (_type == 1 && _mysqlConnection.State == ConnectionState.Closed)
if (_mysqlConnection.State == ConnectionState.Closed)
_mysqlConnection.Open();
}

public void Close()
{
if (_type == 1 && _mysqlConnection.State == ConnectionState.Open)
if (_mysqlConnection.State == ConnectionState.Open)
_mysqlConnection.Close();
}

public void Dispose()
{
switch (_type)
{
case 1:
if (_mysqlConnection.State == ConnectionState.Open)
_mysqlConnection.Close();
break;
}
if (_mysqlConnection.State == ConnectionState.Open)
_mysqlConnection.Close();
}

public void Connect()
{
Open();
}
public void Connect() => Open();

public void Disconnect()
{
Close();
}
public void Disconnect() => Close();

public IQueryAdapter GetQueryReactor()
{
return _adapter;
}

public bool IsAvailable()
{
return false;
}
public IQueryAdapter GetQueryReactor() => _adapter;

public void Prepare()
{
}
public bool IsAvailable() => _mysqlConnection.State == ConnectionState.Open;

public void ReportDone()
{
Dispose();
}
public void ReportDone() => Dispose();

public MySqlCommand CreateNewCommandMySql()
{
return _mysqlConnection.CreateCommand();
}
public MySqlCommand CreateNewCommandMySql() => _mysqlConnection.CreateCommand();

public MySqlTransaction GetTransactionMySql()
{
return _mysqlConnection.BeginTransaction();
}
public MySqlTransaction GetTransactionMySql() => _mysqlConnection.BeginTransaction();
}
}
14 changes: 3 additions & 11 deletions Yupi/Data/Base/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,22 @@ Corporation Oy. Yupi! has nothing linked with Sulake.

namespace Yupi.Data.Base
{
public sealed class DatabaseManager
public class DatabaseManager
{
private readonly string _connectionStr;
private readonly string _typer;

public DatabaseManager(string connectionStr, string connType)
public DatabaseManager(string connectionStr)
{
_connectionStr = connectionStr;
_typer = connType;
}

public IQueryAdapter GetQueryReactor()
{
IDatabaseClient databaseClient = new DatabaseConnection(_connectionStr, _typer);
IDatabaseClient databaseClient = new DatabaseConnection(_connectionStr);

databaseClient.Connect();
databaseClient.Prepare();

return databaseClient.GetQueryReactor();
}

public void Destroy()
{
// Nothing Implemented
}
}
}
Loading

2 comments on commit bee3910

@HotelXz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this c:

@ovflowd
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome ;)

Please sign in to comment.