using System; using System.Collections.Generic; using System.Text; using Lidgren.Network; namespace RageCoop.Core { public partial class Packets { public class Handshake : Packet { public int PedID { get; set; } public string Username { get; set; } public string ModVersion { get; set; } /// /// The asymetrically crypted Aes key /// public byte[] AesKeyCrypted; /// /// The asymetrically crypted Aes IV /// public byte[] AesIVCrypted; /// /// The password hash with client Aes /// public byte[] PassHashEncrypted { get; set; } public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage message.Write((byte)PacketTypes.Handshake); List byteArray = new List(); // Write Player Ped ID byteArray.AddRange(BitConverter.GetBytes(PedID)); // Write Username byte[] usernameBytes = Encoding.UTF8.GetBytes(Username); byteArray.AddRange(BitConverter.GetBytes(usernameBytes.Length)); byteArray.AddRange(usernameBytes); // Write ModVersion byte[] modVersionBytes = Encoding.UTF8.GetBytes(ModVersion); byteArray.AddRange(BitConverter.GetBytes(modVersionBytes.Length)); byteArray.AddRange(modVersionBytes); // Write AesKeyCrypted byteArray.AddArray(AesKeyCrypted); // Write AesIVCrypted byteArray.AddArray(AesIVCrypted); // Write PassHash byteArray.AddArray(PassHashEncrypted); byte[] result = byteArray.ToArray(); message.Write(result.Length); message.Write(result); #endregion } public override void Unpack(byte[] array) { #region NetIncomingMessageToPacket BitReader reader = new BitReader(array); // Read player netHandle PedID = reader.ReadInt(); // Read Username Username = reader.ReadString(reader.ReadInt()); // Read ModVersion ModVersion = reader.ReadString(reader.ReadInt()); AesKeyCrypted=reader.ReadByteArray(); AesIVCrypted=reader.ReadByteArray(); PassHashEncrypted=reader.ReadByteArray(); #endregion } } public class PlayerConnect : Packet { public int PedID { get; set; } public string Username { get; set; } public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage message.Write((byte)PacketTypes.PlayerConnect); List byteArray = new List(); // Write NetHandle byteArray.AddRange(BitConverter.GetBytes(PedID)); // Get Username bytes byte[] usernameBytes = Encoding.UTF8.GetBytes(Username); // Write UsernameLength byteArray.AddRange(BitConverter.GetBytes(usernameBytes.Length)); // Write Username byteArray.AddRange(usernameBytes); byte[] result = byteArray.ToArray(); message.Write(result.Length); message.Write(result); #endregion } public override void Unpack(byte[] array) { #region NetIncomingMessageToPacket BitReader reader = new BitReader(array); // Read player netHandle PedID = reader.ReadInt(); // Read Username int usernameLength = reader.ReadInt(); Username = reader.ReadString(usernameLength); #endregion } } public class PlayerDisconnect : Packet { public int PedID { get; set; } public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage message.Write((byte)PacketTypes.PlayerDisconnect); List byteArray = new List(); byteArray.AddRange(BitConverter.GetBytes(PedID)); byte[] result = byteArray.ToArray(); message.Write(result.Length); message.Write(result); #endregion } public override void Unpack(byte[] array) { #region NetIncomingMessageToPacket BitReader reader = new BitReader(array); PedID = reader.ReadInt(); #endregion } } public class PlayerInfoUpdate : Packet { /// /// Ped ID for this Player /// public int PedID { get; set; } public string Username { get; set; } public float Latency { get; set; } public PlayerConfigFlags Flags { get; set; } public GTA.BlipColor BlipColor { get; set; } public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage message.Write((byte)PacketTypes.PlayerInfoUpdate); List byteArray = new List(); // Write ID byteArray.AddRange(BitConverter.GetBytes(PedID)); // Get Username bytes byte[] usernameBytes = Encoding.UTF8.GetBytes(Username); // Write UsernameLength byteArray.AddRange(BitConverter.GetBytes(usernameBytes.Length)); // Write Username byteArray.AddRange(usernameBytes); // Write Latency byteArray.AddFloat(Latency); // Write Flags byteArray.Add((byte)Flags); // Write BlipColor byteArray.Add((byte)BlipColor); byte[] result = byteArray.ToArray(); message.Write(result.Length); message.Write(result); #endregion } public override void Unpack(byte[] array) { BitReader reader = new BitReader(array); // Read player ID PedID = reader.ReadInt(); // Read Username int usernameLength = reader.ReadInt(); Username = reader.ReadString(usernameLength); Latency=reader.ReadFloat(); Flags=(PlayerConfigFlags)reader.ReadByte(); BlipColor=(GTA.BlipColor)reader.ReadByte(); } } public class PublicKeyResponse : Packet { public byte[] Modulus; public byte[] Exponent; public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage message.Write((byte)PacketTypes.PublicKeyResponse); List byteArray = new List(); byteArray.AddArray(Modulus); byteArray.AddArray(Exponent); byte[] result = byteArray.ToArray(); message.Write(result.Length); message.Write(result); #endregion } public override void Unpack(byte[] array) { #region NetIncomingMessageToPacket var reader=new BitReader(array); Modulus=reader.ReadByteArray(); Exponent=reader.ReadByteArray(); #endregion } } public class PublicKeyRequest : Packet { public override void Pack(NetOutgoingMessage message) { #region PacketToNetOutGoingMessage message.Write((byte)PacketTypes.PublicKeyRequest); #endregion } public override void Unpack(byte[] array) { } } } }