Skip to content

Commit

Permalink
Continued Socket System
Browse files Browse the repository at this point in the history
+ As far i can see Socket system is Ready
+ Improved Codes
+ More?
  • Loading branch information
ovflowd committed Feb 18, 2016
1 parent 5bd193a commit ff024ad
Show file tree
Hide file tree
Showing 35 changed files with 160 additions and 198 deletions.
12 changes: 6 additions & 6 deletions Yupi/Emulator/Core/Io/Logger/YupiLogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Stop()
/// <param name="exceptionText">The log text.</param>
/// <param name="writerBody"></param>
/// <param name="writerHeader"></param>
public static void LogException(string exceptionText, string writerBody = "Registered HabboHotel Exception.", string writerHeader = "Yupi.Error")
public static void LogException(string exceptionText, string writerBody = "Registered HabboHotel Exception.", string writerHeader = "Yupi.Fail")
{
lock (_yupiLogManager)
_yupiLogManager.Error(exceptionText);
Expand All @@ -43,7 +43,7 @@ public static void LogException(string exceptionText, string writerBody = "Regis
/// <param name="exceptionLog"></param>
/// <param name="writerBody"></param>
/// <param name="writerHeader"></param>
public static void LogException(Exception exceptionLog, string writerBody = "Registered HabboHotel Exception.", string writerHeader = "Yupi.Error")
public static void LogException(Exception exceptionLog, string writerBody = "Registered HabboHotel Exception.", string writerHeader = "Yupi.Fail")
{
lock (_yupiLogManager)
_yupiLogManager.Error(exceptionLog);
Expand All @@ -55,7 +55,7 @@ public static void LogException(Exception exceptionLog, string writerBody = "Reg
/// <param name="exceptionText">The log text.</param>
/// <param name="writerBody"></param>
/// <param name="writerHeader"></param>
public static void LogCriticalException(string exceptionText, string writerBody = "Registered HabboHotel Critical Exception.", string writerHeader = "Yupi.Error")
public static void LogCriticalException(string exceptionText, string writerBody = "Registered HabboHotel Critical Exception.", string writerHeader = "Yupi.Fail")
{
lock (_yupiLogManager)
_yupiLogManager.Fatal(exceptionText);
Expand All @@ -69,7 +69,7 @@ public static void LogCriticalException(string exceptionText, string writerBody
/// <param name="exceptionLog"></param>
/// <param name="writerBody"></param>
/// <param name="writerHeader"></param>
public static void LogCriticalException(Exception exceptionLog, string writerBody = "Registered HabboHotel Critical Exception.", string writerHeader = "Yupi.Error")
public static void LogCriticalException(Exception exceptionLog, string writerBody = "Registered HabboHotel Critical Exception.", string writerHeader = "Yupi.Fail")
{
lock (_yupiLogManager)
_yupiLogManager.Fatal(exceptionLog);
Expand All @@ -83,7 +83,7 @@ public static void LogCriticalException(Exception exceptionLog, string writerBod
/// <param name="logText">The log text.</param>
/// <param name="writerHeader"></param>
/// <param name="output"></param>
public static void LogWarning(string logText, string writerHeader = "Yupi.Infos", bool output = true)
public static void LogWarning(string logText, string writerHeader = "Yupi.Info", bool output = true)
{
lock (_yupiLogManager)
_yupiLogManager.Warn(logText);
Expand All @@ -98,7 +98,7 @@ public static void LogWarning(string logText, string writerHeader = "Yupi.Infos"
/// <param name="logText">The log text.</param>
/// <param name="writerHeader"></param>
/// <param name="output"></param>
public static void LogMessage(string logText, string writerHeader = "Yupi.Infos", bool output = true)
public static void LogMessage(string logText, string writerHeader = "Yupi.Info", bool output = true)
{
lock (_yupiLogManager)
_yupiLogManager.Info(logText);
Expand Down
2 changes: 1 addition & 1 deletion Yupi/Emulator/Data/FurnitureDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static void SetCache(bool forceReload = false)
}
catch (NullReferenceException)
{
YupiWriterManager.WriteLine("The content of the FurniData file is empty, impossible to parse.", "Yupi.XML", ConsoleColor.Red);
YupiWriterManager.WriteLine("The content of the FurniData file is empty, impossible to parse.", "Yupi.Data", ConsoleColor.Red);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Yupi/Emulator/Data/ServerCPULowPriorityWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static void Process()
{
DateTime dateTime = new DateTime((DateTime.Now - Yupi.YupiServerStartDateTime).Ticks);

Console.Title = string.Concat("Yupi | Time: ", int.Parse(dateTime.ToString("dd")) - 1, "d:", dateTime.ToString("HH"), "h:", dateTime.ToString("mm"), "m | Users: ", Yupi.GetGame().GetClientManager().ClientCount(), " | Rooms: ", Yupi.GetGame().GetRoomManager().LoadedRoomsCount);
Console.Title = string.Concat("Yupi | Time: ", int.Parse(dateTime.ToString("dd")) - 1, "d:", dateTime.ToString("HH"), "h:", dateTime.ToString("mm"), "m | Users: ", Yupi.GetGame().GetClientManager().GetOnlineClients(), " | Rooms: ", Yupi.GetGame().GetRoomManager().LoadedRoomsCount);

Yupi.GetGame().GetNavigator().LoadNewPublicRooms();
}
Expand Down
7 changes: 4 additions & 3 deletions Yupi/Emulator/Game/Commands/CommandsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,15 @@ public static void UpdateInfo()
{
if (AliasDictionary.ContainsKey(alias))
{
YupiWriterManager.WriteLine("Duplicate alias key: " + alias, "Yupi.Commands", ConsoleColor.DarkRed);
YupiWriterManager.WriteLine("Duplicate alias key: " + alias, "Yupi.Fuse", ConsoleColor.DarkRed);

continue;
}

if (CommandsDictionary.ContainsKey(alias))
{
YupiWriterManager.WriteLine("An alias cannot have same name as a normal command", "Yupi.Commands",
ConsoleColor.DarkRed);
YupiWriterManager.WriteLine("An alias cannot have same name as a normal command", "Yupi.Fuse", ConsoleColor.DarkRed);

continue;
}

Expand Down
2 changes: 1 addition & 1 deletion Yupi/Emulator/Game/Commands/Controllers/BanUserIp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override bool Execute(GameClient session, string[] pms)
}
catch
{
YupiLogManager.LogException($"An error occurred when {session.GetHabbo().UserName} tried to ban {user.GetHabbo().UserName}", "Failed Banning User.", "Yupi.Users");
YupiLogManager.LogException($"An error occurred when {session.GetHabbo().UserName} tried to ban {user.GetHabbo().UserName}", "Failed Banning User.", "Yupi.User");
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Yupi/Emulator/Game/Commands/Controllers/DisconnectUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override bool Execute(GameClient session, string[] pms)
return true;
}

user.GetConnection().Close();
user.Disconnect("Disconnected By Command.");

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, user.GetHabbo().UserName, "dc", $"Disconnect User[{pms[1]}]");

Expand Down
11 changes: 7 additions & 4 deletions Yupi/Emulator/Game/Commands/Controllers/GiveBadge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ public GiveBadge()
public override bool Execute(GameClient session, string[] pms)
{
GameClient client = Yupi.GetGame().GetClientManager().GetClientByUserName(pms[0]);

if (client == null)
{
session.SendNotif(Yupi.GetLanguage().GetVar("user_not_found"));

return true;
}

client.GetHabbo().GetBadgeComponent().GiveBadge(pms[1], true, client);

session.SendNotif(Yupi.GetLanguage().GetVar("command_badge_give_done"));
Yupi.GetGame()
.GetModerationTool()
.LogStaffEntry(session.GetHabbo().UserName, client.GetHabbo().UserName,
"Badge", $"Badge given to user [{pms[1]}]");

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, client.GetHabbo().UserName, "Badge", $"Badge given to user [{pms[1]}]");

return true;
}
}
Expand Down
8 changes: 6 additions & 2 deletions Yupi/Emulator/Game/Commands/Controllers/GiveCredits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override bool Execute(GameClient session, string[] pms)
if (client == null)
{
session.SendWhisper(Yupi.GetLanguage().GetVar("user_not_found"));

return true;
}

Expand All @@ -34,14 +35,17 @@ public override bool Execute(GameClient session, string[] pms)
if (!uint.TryParse(pms[1], out amount))
{
session.SendWhisper(Yupi.GetLanguage().GetVar("enter_numbers"));

return true;
}

client.GetHabbo().Credits += amount;

client.GetHabbo().UpdateCreditsBalance();

client.SendNotif(string.Format(Yupi.GetLanguage().GetVar("staff_gives_credits"), session.GetHabbo().UserName,
amount));
client.SendNotif(string.Format(Yupi.GetLanguage().GetVar("staff_gives_credits"), session.GetHabbo().UserName, amount));

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, string.Empty, "Credits", string.Concat("Give Credits to User [", pms[0], "] with amount [", pms[1], "]"));

return true;
}
Expand Down
8 changes: 6 additions & 2 deletions Yupi/Emulator/Game/Commands/Controllers/GiveDiamonds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override bool Execute(GameClient session, string[] pms)
if (client == null)
{
session.SendWhisper(Yupi.GetLanguage().GetVar("user_not_found"));

return true;
}

Expand All @@ -34,14 +35,17 @@ public override bool Execute(GameClient session, string[] pms)
if (!uint.TryParse(pms[1], out amount))
{
session.SendWhisper(Yupi.GetLanguage().GetVar("enter_numbers"));

return true;
}

client.GetHabbo().Diamonds += amount;

client.GetHabbo().UpdateSeasonalCurrencyBalance();

client.SendNotif(string.Format(Yupi.GetLanguage().GetVar("staff_gives_diamonds"),
session.GetHabbo().UserName, amount));
client.SendNotif(string.Format(Yupi.GetLanguage().GetVar("staff_gives_diamonds"), session.GetHabbo().UserName, amount));

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, string.Empty, "Diamonds", string.Concat("Give Diamonds to User [", pms[0], "] with amount [", pms[1], "]"));

return true;
}
Expand Down
6 changes: 6 additions & 0 deletions Yupi/Emulator/Game/Commands/Controllers/GiveRank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ public override bool Execute(GameClient session, string[] pms)
session.SendWhisper(Yupi.GetLanguage().GetVar("user_not_found"));
return true;
}

if (user.GetHabbo().Rank >= session.GetHabbo().Rank)
{
session.SendWhisper(Yupi.GetLanguage().GetVar("user_is_higher_rank"));

return true;
}

string userName = pms[0];
string rank = pms[1];

using (IQueryAdapter adapter = Yupi.GetDatabaseManager().GetQueryReactor())
{
adapter.SetQuery("UPDATE users SET rank=@rank WHERE username=@user LIMIT 1");
Expand All @@ -46,6 +49,9 @@ public override bool Execute(GameClient session, string[] pms)
}

session.SendWhisper(Yupi.GetLanguage().GetVar("user_rank_update"));

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, string.Empty, "Rank", string.Concat("Give Rank to User [", pms[0], "] Rank Level [", pms[1], "]"));

return true;
}
}
Expand Down
9 changes: 7 additions & 2 deletions Yupi/Emulator/Game/Commands/Controllers/MassCredits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override bool Execute(GameClient session, string[] pms)
if (!uint.TryParse(pms[0], out amount))
{
session.SendNotif(Yupi.GetLanguage().GetVar("enter_numbers"));

return true;
}

Expand All @@ -35,11 +36,15 @@ public override bool Execute(GameClient session, string[] pms)
continue;

client.GetHabbo().Credits += amount;

client.GetHabbo().UpdateCreditsBalance();
client.SendNotif(Yupi.GetLanguage().GetVar("command_mass_credits_one_give") + amount +
Yupi.GetLanguage().GetVar("command_mass_credits_two_give"));

client.SendNotif(Yupi.GetLanguage().GetVar("command_mass_credits_one_give") + amount + Yupi.GetLanguage().GetVar("command_mass_credits_two_give"));
}

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, string.Empty, "Credits", string.Concat("RoomCredits in room [", session.GetHabbo().CurrentRoom.RoomId, "] with amount [", pms[0], "]"));


return true;
}
}
Expand Down
10 changes: 7 additions & 3 deletions Yupi/Emulator/Game/Commands/Controllers/MassDiamonds.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Yupi.Emulator.Game.Commands.Interfaces;
using System.Web.ModelBinding;
using Yupi.Emulator.Game.Commands.Interfaces;
using Yupi.Emulator.Game.GameClients.Interfaces;
using Yupi.Emulator.Game.Users;

Expand Down Expand Up @@ -27,6 +28,7 @@ public override bool Execute(GameClient session, string[] pms)
if (!uint.TryParse(pms[0], out amount))
{
session.SendNotif(Yupi.GetLanguage().GetVar("enter_numbers"));

return true;
}

Expand All @@ -38,12 +40,14 @@ public override bool Execute(GameClient session, string[] pms)
Habbo habbo = client.GetHabbo();

habbo.Diamonds += amount;

client.GetHabbo().UpdateSeasonalCurrencyBalance();

client.SendNotif(Yupi.GetLanguage().GetVar("command_diamonds_one_give") + amount +
Yupi.GetLanguage().GetVar("command_diamonds_two_give"));
client.SendNotif(Yupi.GetLanguage().GetVar("command_diamonds_one_give") + amount + Yupi.GetLanguage().GetVar("command_diamonds_two_give"));
}

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, string.Empty, "Diamonds", string.Concat("RoomDiamonds in room [", session.GetHabbo().CurrentRoom.RoomId, "] with amount [", pms[0], "]"));

return true;
}
}
Expand Down
30 changes: 9 additions & 21 deletions Yupi/Emulator/Game/Commands/Controllers/RoomBadge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,17 @@ public RoomBadge()

public override bool Execute(GameClient session, string[] pms)
{
if (pms[0].Length < 2) return true;
if (pms[0].Length < 2)
return true;

Room room = session.GetHabbo().CurrentRoom;

foreach (RoomUser current in room.GetRoomUserManager().UserList.Values)
{
try
{
if (!current.IsBot && current.GetClient() != null &&
current.GetClient().GetHabbo() != null)
{
current.GetClient()
.GetHabbo()
.GetBadgeComponent()
.GiveBadge(pms[0], true, current.GetClient());
}
}
catch
{
}
}
Yupi.GetGame().GetModerationTool()
.LogStaffEntry(session.GetHabbo().UserName,
string.Empty, "Badge",
string.Concat("Roombadge in room [", room.RoomId, "] with badge [", pms[0], "]"));
if (!current.IsBot && current.GetClient() != null && current.GetClient().GetHabbo() != null)
current.GetClient().GetHabbo().GetBadgeComponent().GiveBadge(pms[0], true, current.GetClient());

Yupi.GetGame().GetModerationTool().LogStaffEntry(session.GetHabbo().UserName, string.Empty, "Badge", string.Concat("Roombadge in room [", room.RoomId, "] with badge [", pms[0], "]"));

return true;
}
}
Expand Down
27 changes: 7 additions & 20 deletions Yupi/Emulator/Game/GameClients/GameClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal GameClientManager()
/// Return Online Clients Count
/// </summary>
/// <returns>Online Client Count.</returns>
internal int GetOnlineClients() => Clients.Values.Count(client => !CheckClientOnlineStatus(client.ClientAddress));
internal int GetOnlineClients() => Clients.Values.Count(client => CheckClientOnlineStatus(client.ClientAddress));

/// <summary>
/// Gets the name by identifier.
Expand Down Expand Up @@ -180,6 +180,7 @@ internal void OnCycle()
try
{
GiveBadges();

BroadcastPackets();

Yupi.GetGame().ClientManagerCycleEnded = true;
Expand Down Expand Up @@ -242,14 +243,9 @@ internal void AddOrUpdateClient(string clientAddress, ConnectionActor connection
/// <param name="clientAddress">The client identifier.</param>
internal void RemoveClient(string clientAddress)
{
GameClient client = GetClientByAddress(clientAddress);

if(client != null)
{
client.Stop();
GameClient client;

Clients.TryRemove(client.ClientAddress, out client);
}
Clients.TryRemove(clientAddress, out client);
}

/// <summary>
Expand All @@ -258,16 +254,6 @@ internal void RemoveClient(string clientAddress)
/// <param name="message">The message.</param>
internal void QueueBroadcaseMessage(SimpleServerMessageBuffer message) => _broadcastQueue.Enqueue(message.GetReversedBytes());

/// <summary>
/// Queues the badge update.
/// </summary>
/// <param name="badge">The badge.</param>
internal void QueueBadgeUpdate(string badge)
{
lock (_badgeQueue.SyncRoot)
_badgeQueue.Enqueue(badge);
}

/// <summary>
/// Logs the clones out.
/// </summary>
Expand All @@ -276,7 +262,7 @@ internal void LogClonesOut(uint userId)
{
GameClient clientByUserId = GetClientByUserId(userId);

clientByUserId?.Disconnect("User Clones");
clientByUserId?.Disconnect("User is Clone.");
}

/// <summary>
Expand Down Expand Up @@ -339,7 +325,7 @@ internal void CloseAll()
YupiWriterManager.WriteLine("Closing YupiDatabase Manager...", "Yupi.Data", ConsoleColor.DarkMagenta);

foreach (GameClient current4 in Clients.Values.Where(current4 => current4?.GetConnection() != null))
current4.GetConnection().Close();
current4.Disconnect("Server Shutdown.");

YupiWriterManager.WriteLine("Yupi DataBase Manager Closed!", "Yupi.Data", ConsoleColor.DarkMagenta);

Expand All @@ -361,6 +347,7 @@ internal void UpdateClient(string oldName, string newName)
GameClient old = (GameClient) _userNameRegister[oldName.ToLower()];

_userNameRegister.Remove(oldName.ToLower());

_userNameRegister.Add(newName.ToLower(), old);
}

Expand Down
Loading

0 comments on commit ff024ad

Please sign in to comment.