/// <summary> /// Occurs when the client has been sucessfully authenticated by the loginserver. /// Called by UILoginDialog.cs. /// </summary> /// <param name="Client">The client that received the packet.</param> /// <param name="Packet">The packet that was received.</param> public static void OnInitLoginNotify(NetworkClient Client, PacketStream Packet) { byte Opcode = (byte)Packet.ReadByte(); //Account was authenticated, so add the client to the player's account. PlayerAccount.Client = Client; if (!Directory.Exists("CharacterCache")) { Directory.CreateDirectory("CharacterCache"); //The charactercache didn't exist, so send the current time, which is //newer than the server's stamp. This will cause the server to send the entire cache. UIPacketSenders.SendCharacterInfoRequest(DateTime.Now.ToString("yyyy.MM.dd hh:mm:ss")); } else { if (!File.Exists("CharacterCache\\Sims.tempcache")) { //The charactercache didn't exist, so send the current time, which is //newer than the server's stamp. This will cause the server to send the entire cache. UIPacketSenders.SendCharacterInfoRequest(DateTime.Now.ToString("yyyy.MM.dd hh:mm:ss")); } } }
public static void Handle(PacketStream stream) { byte ID = (byte)stream.ReadByte(); if (m_Handlers.ContainsKey(ID)) { m_Handlers[ID].Handler(stream); } }
public static void OnSimulationState(NetworkClient Client, PacketStream Packet, LotScreen Lot) { List <SimulationObject> SimObjects = new List <SimulationObject>(); byte Opcode = (byte)Packet.ReadByte(); byte NumTicks = (byte)Packet.ReadByte(); int NumObjects = Packet.ReadInt32(); BinaryFormatter BinFormatter = new BinaryFormatter(); for (int i = 0; i < NumObjects; i++) { SimulationObject SimObject = (SimulationObject)BinFormatter.Deserialize(Packet); SimObjects.Add(SimObject); } Lot.UpdateSimulationState(NumTicks, SimObjects); }
public static void OnSimulationState(NetworkClient Client, PacketStream Packet, LotScreen Lot) { List<SimulationObject> SimObjects = new List<SimulationObject>(); byte Opcode = (byte)Packet.ReadByte(); byte NumTicks = (byte)Packet.ReadByte(); int NumObjects = Packet.ReadInt32(); BinaryFormatter BinFormatter = new BinaryFormatter(); for (int i = 0; i < NumObjects; i++) { SimulationObject SimObject = (SimulationObject)BinFormatter.Deserialize(Packet); SimObjects.Add(SimObject); } Lot.UpdateSimulationState(NumTicks, SimObjects); }
/// <summary> /// LoginServer sent information about the player's characters. /// </summary> /// <param name="Packet">The packet that was received.</param> public static void OnCharacterInfoResponse(PacketStream Packet, NetworkClient Client) { byte Opcode = (byte)Packet.ReadByte(); byte Length = (byte)Packet.ReadByte(); byte DecryptedLength = (byte)Packet.ReadByte(); Packet.DecryptPacket(PlayerAccount.EncKey, new DESCryptoServiceProvider(), DecryptedLength); //If the decrypted length == 1, it means that there were 0 //characters that needed to be updated, or that the user //hasn't created any characters on his/her account yet. //Since the Packet.Length property is equal to the length //of the encrypted data, it cannot be used to get the length //of the decrypted data. if (DecryptedLength > 1) { byte NumCharacters = (byte)Packet.ReadByte(); List <Sim> FreshSims = new List <Sim>(); for (int i = 0; i < NumCharacters; i++) { int CharacterID = Packet.ReadInt32(); Sim FreshSim = new Sim(Packet.ReadString()); FreshSim.CharacterID = CharacterID; FreshSim.Timestamp = Packet.ReadString(); FreshSim.Name = Packet.ReadString(); FreshSim.Sex = Packet.ReadString(); FreshSims.Add(FreshSim); } NetworkFacade.Avatars = FreshSims; CacheSims(FreshSims); } PacketStream CityInfoRequest = new PacketStream(0x06, 0); CityInfoRequest.WriteByte(0x00); //Dummy Client.SendEncrypted(0x06, CityInfoRequest.ToArray()); }
/// <summary> /// LoginServer sent information about the player's characters. /// </summary> /// <param name="Packet">The packet that was received.</param> public static void OnCharacterInfoResponse(PacketStream Packet, NetworkClient Client) { byte Opcode = (byte)Packet.ReadByte(); byte Length = (byte)Packet.ReadByte(); byte DecryptedLength = (byte)Packet.ReadByte(); Packet.DecryptPacket(PlayerAccount.EncKey, new DESCryptoServiceProvider(), DecryptedLength); //If the decrypted length == 1, it means that there were 0 //characters that needed to be updated, or that the user //hasn't created any characters on his/her account yet. //Since the Packet.Length property is equal to the length //of the encrypted data, it cannot be used to get the length //of the decrypted data. if (DecryptedLength > 1) { byte NumCharacters = (byte)Packet.ReadByte(); List<Sim> FreshSims = new List<Sim>(); for (int i = 0; i < NumCharacters; i++) { int CharacterID = Packet.ReadInt32(); Sim FreshSim = new Sim(Packet.ReadString()); FreshSim.CharacterID = CharacterID; FreshSim.Timestamp = Packet.ReadString(); FreshSim.Name = Packet.ReadString(); FreshSim.Sex = Packet.ReadString(); FreshSims.Add(FreshSim); } NetworkFacade.Avatars = FreshSims; CacheSims(FreshSims); } PacketStream CityInfoRequest = new PacketStream(0x06, 0); CityInfoRequest.WriteByte(0x00); //Dummy Client.SendEncrypted(0x06, CityInfoRequest.ToArray()); }
public static void OnCityInfoResponse(PacketStream Packet) { byte Opcode = (byte)Packet.ReadByte(); byte Length = (byte)Packet.ReadByte(); byte DecryptedLength = (byte)Packet.ReadByte(); Packet.DecryptPacket(PlayerAccount.EncKey, new DESCryptoServiceProvider(), DecryptedLength); byte NumCities = (byte)Packet.ReadByte(); for (int i = 0; i < NumCities; i++) { string Name = Packet.ReadString(); string Description = Packet.ReadString(); string IP = Packet.ReadString(); int Port = Packet.ReadInt32(); CityInfoStatus Status = (CityInfoStatus)Packet.ReadByte(); ulong Thumbnail = Packet.ReadUInt64(); string UUID = Packet.ReadString(); CityInfo Info = new CityInfo(Name, Description, Thumbnail, UUID, 0, IP, Port); NetworkFacade.Cities.Add(Info); } }
/// <summary> /// Occurs when the client was not authenticated by the loginserver. /// Called by UILoginDialog.cs. /// </summary> /// <param name="Client">The client that received the packet.</param> /// <param name="Packet">The packet that was received.</param> /// <param name="Screen">A UIScreen instance on which to display a messagebox to inform the player of the /// failure state.</param> public static void OnLoginFailResponse(ref NetworkClient Client, PacketStream Packet, UIScreen Screen) { byte Opcode = (byte)Packet.ReadByte(); switch (Packet.ReadByte()) { case 0x01: Screen.CreateMsgBox(250, 200, "Invalid accountname!"); break; case 0x02: Screen.CreateMsgBox(250, 200, "Invalid password!"); break; } Client.Disconnect(); }
public static void OnCityInfoResponse(PacketStream Packet) { byte Opcode = (byte)Packet.ReadByte(); byte Length = (byte)Packet.ReadByte(); byte DecryptedLength = (byte)Packet.ReadByte(); Packet.DecryptPacket(PlayerAccount.EncKey, new DESCryptoServiceProvider(), DecryptedLength); byte NumCities = (byte)Packet.ReadByte(); for (int i = 0; i < NumCities; i++) { string Name = Packet.ReadString(); string Description = Packet.ReadString(); string IP = Packet.ReadString(); int Port = Packet.ReadInt32(); CityInfoStatus Status = (CityInfoStatus)Packet.ReadByte(); ulong Thumbnail = Packet.ReadUInt64(); string UUID = Packet.ReadString(); CityInfo Info = new CityInfo(Name, Description, Thumbnail, UUID, 0, IP, Port); NetworkFacade.Cities.Add(Info); } }
/// <summary> /// Occurs when the client was not authenticated by the loginserver. /// Called by UILoginDialog.cs. /// </summary> /// <param name="Client">The client that received the packet.</param> /// <param name="Packet">The packet that was received.</param> /// <param name="Screen">A UIScreen instance on which to display a messagebox to inform the player of the /// failure state.</param> public static void OnLoginFailResponse(ref NetworkClient Client, PacketStream Packet) { byte Opcode = (byte)Packet.ReadByte(); switch (Packet.ReadByte()) { case 0x01: UIAlertOptions Options = new UIAlertOptions(); Options.Title = "Network error"; Options.Message = "Invalid username!"; Options.Buttons = UIAlertButtons.OK; UIScreen.ShowAlert(Options, true); break; case 0x02: Options = new UIAlertOptions(); Options.Title = "Network error"; Options.Message = "Invalid password!"; Options.Buttons = UIAlertButtons.OK; UIScreen.ShowAlert(Options, true); break; } Client.Disconnect(); }