Skip to content

Commit

Permalink
Refactoring - Changed Rule Set to MS Basic Design Guideline Rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sledmore committed Dec 21, 2017
1 parent 1c77499 commit eeb9ce2
Show file tree
Hide file tree
Showing 40 changed files with 199 additions and 236 deletions.
2 changes: 1 addition & 1 deletion Communication/ConnectionManager/ConnectionInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void handlePacketData(byte[] packet)
{
if (parser != null)
{
parser.handlePacketData(packet);
parser.HandlePacketData(packet);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Plus.Communication.ConnectionManager
{
public class GameSocketManagerStatics
public static class GameSocketManagerStatics
{
public static readonly int BUFFER_SIZE = 8192;
public static readonly int MAX_PACKET_SIZE = BUFFER_SIZE - 4;
Expand Down
2 changes: 1 addition & 1 deletion Communication/ConnectionManager/IDataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Plus.Communication.ConnectionManager
{
public interface IDataParser : IDisposable, ICloneable
{
void handlePacketData(byte[] packet);
void HandlePacketData(byte[] packet);
}
}
34 changes: 17 additions & 17 deletions Communication/GamePacketParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@ namespace Plus.Communication
{
public class GamePacketParser : IDataParser
{
private static readonly ILog log = LogManager.GetLogger("Plus.Messages.Net.GamePacketParser");
private static readonly ILog log = LogManager.GetLogger("Plus.Communication.GamePacketParser");

public delegate void HandlePacket(ClientPacket message);

private readonly GameClient currentClient;
private ConnectionInformation con;
private readonly GameClient _currentClient;
private ConnectionInformation _con;

private bool _halfDataRecieved = false;
private byte[] _halfData = null;
private bool _deciphered = false;

public GamePacketParser(GameClient me)
{
currentClient = me;
_currentClient = me;
}

public void handlePacketData(byte[] Data)
public void HandlePacketData(byte[] data)
{
try
{
if (this.currentClient.RC4Client != null && !this._deciphered)
if (this._currentClient.RC4Client != null && !this._deciphered)
{
this.currentClient.RC4Client.Decrypt(ref Data);
this._currentClient.RC4Client.Decrypt(ref data);
this._deciphered = true;
}

if (this._halfDataRecieved)
{
byte[] FullDataRcv = new byte[this._halfData.Length + Data.Length];
byte[] FullDataRcv = new byte[this._halfData.Length + data.Length];
Buffer.BlockCopy(this._halfData, 0, FullDataRcv, 0, this._halfData.Length);
Buffer.BlockCopy(Data, 0, FullDataRcv, this._halfData.Length, Data.Length);
Buffer.BlockCopy(data, 0, FullDataRcv, this._halfData.Length, data.Length);

this._halfDataRecieved = false; // mark done this round
handlePacketData(FullDataRcv); // repeat now we have the combined array
HandlePacketData(FullDataRcv); // repeat now we have the combined array
return;
}

using (BinaryReader Reader = new BinaryReader(new MemoryStream(Data)))
using (BinaryReader Reader = new BinaryReader(new MemoryStream(data)))
{
if (Data.Length < 4)
if (data.Length < 4)
return;

int MsgLen = HabboEncoding.DecodeInt32(Reader.ReadBytes(4));
if ((Reader.BaseStream.Length - 4) < MsgLen)
{
this._halfData = Data;
this._halfData = data;
this._halfDataRecieved = true;
return;
}
Expand All @@ -80,10 +80,10 @@ public void handlePacketData(byte[] Data)
if (Reader.BaseStream.Length - 4 > MsgLen)
{
byte[] Extra = new byte[Reader.BaseStream.Length - Reader.BaseStream.Position];
Buffer.BlockCopy(Data, (int)Reader.BaseStream.Position, Extra, 0, (int)(Reader.BaseStream.Length - Reader.BaseStream.Position));
Buffer.BlockCopy(data, (int)Reader.BaseStream.Position, Extra, 0, (int)(Reader.BaseStream.Length - Reader.BaseStream.Position));

this._deciphered = true;
handlePacketData(Extra);
HandlePacketData(Extra);
}
}
}
Expand All @@ -101,14 +101,14 @@ public void Dispose()

public object Clone()
{
return new GamePacketParser(currentClient);
return new GamePacketParser(_currentClient);
}

public event HandlePacket onNewPacket;

public void SetConnection(ConnectionInformation con)
{
this.con = con;
_con = con;
onNewPacket = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Communication/InitialPacketParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class InitialPacketParser : IDataParser

public byte[] currentData;

public void handlePacketData(byte[] packet)
public void HandlePacketData(byte[] packet)
{
if (packet[0] == 60 && PolicyRequest != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void ReloadOffers(GameClient Session)
}
}

Session.SendPacket(new MarketPlaceOffersComposer(MinCost, MaxCost, dictionary, dictionary2));
Session.SendPacket(new MarketPlaceOffersComposer(dictionary, dictionary2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}
}

Session.SendPacket(new MarketPlaceOffersComposer(MinCost, MaxCost, dictionary, dictionary2));
Session.SendPacket(new MarketPlaceOffersComposer(dictionary, dictionary2));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Incoming;
using Plus.Communication.Packets.Outgoing.Navigator;
using Plus.HabboHotel.Navigator;

namespace Plus.Communication.Packets.Incoming.Navigator
{
class GetNavigatorFlatsEvent : IPacketEvent
{
public void Parse(GameClient Session, ClientPacket Packet)
public void Parse(GameClient session, ClientPacket packet)
{
ICollection<SearchResultList> Categories = PlusEnvironment.GetGame().GetNavigator().GetEventCategories();
ICollection<SearchResultList> categories = PlusEnvironment.GetGame().GetNavigator().GetEventCategories();

Session.SendPacket(new NavigatorFlatCatsComposer(Categories, Session.GetHabbo().Rank));
session.SendPacket(new NavigatorFlatCatsComposer(categories));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

RoomUser BotUser = Room.GetRoomUserManager().DeployBot(new RoomBot(Bot.Id, Session.GetHabbo().CurrentRoomId, Convert.ToString(GetData["ai_type"]), Convert.ToString(GetData["walk_mode"]), Bot.Name, "", Bot.Figure, X, Y, 0, 4, 0, 0, 0, 0, ref BotSpeechList, "", 0, Bot.OwnerId, PlusEnvironment.EnumToBool(GetData["automatic_chat"].ToString()), Convert.ToInt32(GetData["speaking_interval"]), PlusEnvironment.EnumToBool(GetData["mix_sentences"].ToString()), Convert.ToInt32(GetData["chat_bubble"])), null);
BotUser.Chat("Hello!",false, 0);
BotUser.Chat("Hello!", 0);

Room.GetGameMap().UpdateUserMovement(new System.Drawing.Point(X,Y), new System.Drawing.Point(X, Y), BotUser);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Items;



using Plus.Communication.Packets.Outgoing.Rooms.Engine;
using Plus.Communication.Packets.Outgoing.Rooms.AI.Pets;

Expand All @@ -17,28 +10,26 @@ namespace Plus.Communication.Packets.Incoming.Rooms.AI.Pets.Horse
{
class ApplyHorseEffectEvent : IPacketEvent
{
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet)
public void Parse(HabboHotel.GameClients.GameClient session, ClientPacket packet)
{
if (!Session.GetHabbo().InRoom)
if (!session.GetHabbo().InRoom)
return;

Room Room;

if (!PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room))

if (!PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(session.GetHabbo().CurrentRoomId, out Room room))
return;

int ItemId = Packet.PopInt();
Item Item = Room.GetRoomItemHandler().GetItem(ItemId);
int ItemId = packet.PopInt();
Item Item = room.GetRoomItemHandler().GetItem(ItemId);
if (Item == null)
return;

int PetId = Packet.PopInt();
int PetId = packet.PopInt();

RoomUser PetUser = null;
if (!Room.GetRoomUserManager().TryGetPet(PetId, out PetUser))
if (!room.GetRoomUserManager().TryGetPet(PetId, out PetUser))
return;

if (PetUser.PetData == null || PetUser.PetData.OwnerId != Session.GetHabbo().Id)
if (PetUser.PetData == null || PetUser.PetData.OwnerId != session.GetHabbo().Id)
return;

if (Item.Data.InteractionType == InteractionType.HORSE_SADDLE_1)
Expand All @@ -51,7 +42,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

//We only want to use this if we're successful.
Room.GetRoomItemHandler().RemoveFurniture(Session, Item.Id, false);
room.GetRoomItemHandler().RemoveFurniture(session, Item.Id);
}
else if (Item.Data.InteractionType == InteractionType.HORSE_SADDLE_2)
{
Expand All @@ -63,7 +54,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

//We only want to use this if we're successful.
Room.GetRoomItemHandler().RemoveFurniture(Session, Item.Id, false);
room.GetRoomItemHandler().RemoveFurniture(session, Item.Id);
}
else if (Item.Data.InteractionType == InteractionType.HORSE_HAIRSTYLE)
{
Expand All @@ -80,7 +71,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

//We only want to use this if we're successful.
Room.GetRoomItemHandler().RemoveFurniture(Session, Item.Id, false);
room.GetRoomItemHandler().RemoveFurniture(session, Item.Id);
}
else if (Item.Data.InteractionType == InteractionType.HORSE_HAIR_DYE)
{
Expand All @@ -97,7 +88,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

//We only want to use this if we're successful.
Room.GetRoomItemHandler().RemoveFurniture(Session, Item.Id, false);
room.GetRoomItemHandler().RemoveFurniture(session, Item.Id);
}
else if (Item.Data.InteractionType == InteractionType.HORSE_BODY_DYE)
{
Expand All @@ -121,12 +112,12 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

//We only want to use this if we're successful.
Room.GetRoomItemHandler().RemoveFurniture(Session, Item.Id, false);
room.GetRoomItemHandler().RemoveFurniture(session, Item.Id);
}

//Update the Pet and the Pet figure information.
Room.SendPacket(new UsersComposer(PetUser));
Room.SendPacket(new PetHorseFigureInformationComposer(PetUser));
room.SendPacket(new UsersComposer(PetUser));
room.SendPacket(new PetHorseFigureInformationComposer(PetUser));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
{
string[] Speech2 = PlusEnvironment.GetGame().GetChatManager().GetPetLocale().GetValue("pet.alreadymounted");
var RandomSpeech2 = new Random();
Pet.Chat(Speech2[RandomSpeech2.Next(0, Speech2.Length - 1)], false);
Pet.Chat(Speech2[RandomSpeech2.Next(0, Speech2.Length - 1)]);
}
else if (User.RidingHorse)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet

try
{
DoorZ = parse(modelData[DoorY][DoorX]);
DoorZ = Parse(modelData[DoorY][DoorX]);
}
catch { }

Expand Down Expand Up @@ -173,7 +173,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}
}

public static short parse(char input)
public static short Parse(char input)
{

switch (input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
}

Session.SendPacket(new FurniListUpdateComposer());
Room.GetRoomItemHandler().RemoveFurniture(null, Exchange.Id, false);
Room.GetRoomItemHandler().RemoveFurniture(null, Exchange.Id);
Session.GetHabbo().GetInventoryComponent().RemoveItem(Exchange.Id);

}
Expand Down
8 changes: 4 additions & 4 deletions Communication/Packets/Incoming/Rooms/Furni/OpenGiftEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
if (Data == null)
{
Session.SendNotification("Oops! Appears there was a bug with this gift.\nWe'll just get rid of it for you.");
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id, false);
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id);

using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
{
Expand All @@ -67,7 +67,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
if (!int.TryParse(Present.ExtraData.Split(Convert.ToChar(5))[2], out PurchaserId))
{
Session.SendNotification("Oops! Appears there was a bug with this gift.\nWe'll just get rid of it for you.");
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id, false);
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id);

using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
{
Expand All @@ -83,7 +83,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
if (Purchaser == null)
{
Session.SendNotification("Oops! Appears there was a bug with this gift.\nWe'll just get rid of it for you.");
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id, false);
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id);

using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
{
Expand All @@ -99,7 +99,7 @@ public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet
if (!PlusEnvironment.GetGame().GetItemManager().GetItem(Convert.ToInt32(Data["base_id"]), out BaseItem))
{
Session.SendNotification("Oops, it appears that the item within the gift is no longer in the hotel!");
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id, false);
Room.GetRoomItemHandler().RemoveFurniture(null, Present.Id);

using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
{
Expand Down
Loading

0 comments on commit eeb9ce2

Please sign in to comment.