public byte[] GetBytes() { List <byte> retVal = new List <byte>(); //retVal.AddRange(BitConverter.GetBytes((int)SubPacketType)); retVal.Add((byte)SubPacketType); if (_log.IsInfoEnabled) { _log.InfoFormat("~~~~SubPacketType added to bytes: {0}", Utility.BytesToDebugString(retVal.ToArray())); } if (SubPacketData != null) { retVal.AddRange(SubPacketData); if (_log.IsInfoEnabled) { _log.InfoFormat("~~~~####SubPacketData added to bytes: {0}", Utility.BytesToDebugString(retVal.ToArray())); } } return(retVal.ToArray()); }
public CommsIncomingPacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } Priority = BitConverter.ToInt32(byteArray, 0); Sender = new ArtemisString(byteArray, 4); int newStart = 4 + (Sender.Length * 2) + 4; Message = new ArtemisString(byteArray, newStart); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
void Initialize(byte[] byteArray, int index) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--{2} bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray, index), (byteArray.Length - index).ToString()); } if (_log.IsInfoEnabled) { _log.InfoFormat("(a)index={0}", index); } ID = BitConverter.ToInt32(byteArray, index); if (_log.IsInfoEnabled) { _log.InfoFormat("ID={0}, index={1}", ID.ToString(), index); } List <PropertyInfo> propertyList = new List <PropertyInfo>(); Type t = this.GetType(); PropertyInfo[] properties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in properties) { if (prop.Name != "ID" && prop.Name != "IncludedFields") { propertyList.Add(prop); } } if (_log.IsInfoEnabled) { _log.InfoFormat("(b)index={0}", index); } IncludedFields = ProcessBitFlags(propertyList.Count, byteArray, index + 4); int flagsize = (propertyList.Count - 1) / 8 + 1; int position = index + 4 + flagsize; ProcessVariableData(propertyList.ToArray(), this, byteArray, position, IncludedFields); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public PlayerShip(byte[] byteArray, int startIndex) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } Unknown0 = BitConverter.ToInt32(byteArray, startIndex); if (_log.IsInfoEnabled) { _log.InfoFormat("Unknown0={0}", Unknown0.ToString()); } Unknown1 = BitConverter.ToInt32(byteArray, startIndex + 4); if (_log.IsInfoEnabled) { _log.InfoFormat("Unknown1={0}", Unknown1.ToString()); } Unknown2 = BitConverter.ToInt32(byteArray, startIndex + 8); if (_log.IsInfoEnabled) { _log.InfoFormat("Unknown2={0}", Unknown2.ToString()); } Name = new ArtemisString(byteArray, startIndex + 12); if (_log.IsInfoEnabled) { _log.InfoFormat("Name={0}", Name.ToString()); } Length = 16 + Name.Length * 2; if (_log.IsInfoEnabled) { _log.InfoFormat("Length={0}", Length.ToString()); } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public VersionPacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } if (byteArray.Length > 3) //Protection in case of bad packet. { Unknown = BitConverter.ToInt32(byteArray, 0); if (_log.IsInfoEnabled) { _log.InfoFormat("Unknown={0}", Unknown); } } if (byteArray.Length > 7) //Protection in case of bad packet. { Version = BitConverter.ToSingle(byteArray, 4); Packet.CurrentActiveArtemisVersion = Version; if (_log.IsInfoEnabled) { _log.InfoFormat("Version={0}", Version); } } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public EngGridUpdatePacket(byte[] byteArray) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } Systems = SystemNode.GetNodes(byteArray); int index = 0; foreach (SystemNode node in Systems) { index += node.DataLength; } DamageControlTeams = DamComStatus.GetDamComTeams(byteArray, ++index); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } }
public Unknown2Packet(byte[] byteArray) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } }
public StationStatusPacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } ShipNumber = BitConverter.ToInt32(byteArray, 0); if (_log.IsInfoEnabled) { _log.InfoFormat("ShipNumber={0}", ShipNumber); } List <BridgeStationStatuses> stat = new List <BridgeStationStatuses>(); if (byteArray.Length > 4) { MainScreen = (BridgeStationStatuses)byteArray[4]; if (_log.IsInfoEnabled) { _log.InfoFormat("MainScreen={0}", MainScreen); } } if (byteArray.Length > 5) { Helm = (BridgeStationStatuses)byteArray[5]; if (_log.IsInfoEnabled) { _log.InfoFormat("Helm={0}", Helm); } } if (byteArray.Length > 6) { Weapons = (BridgeStationStatuses)byteArray[6]; if (_log.IsInfoEnabled) { _log.InfoFormat("Weapons={0}", Weapons); } } if (byteArray.Length > 7) { Engineering = (BridgeStationStatuses)byteArray[7]; if (_log.IsInfoEnabled) { _log.InfoFormat("Engineering={0}", Engineering); } } if (byteArray.Length > 8) { Science = (BridgeStationStatuses)byteArray[8]; if (_log.IsInfoEnabled) { _log.InfoFormat("Science={0}", Science); } } if (byteArray.Length > 9) { Communications = (BridgeStationStatuses)byteArray[9]; if (_log.IsInfoEnabled) { _log.InfoFormat("Communications={0}", Communications); } } if (byteArray.Length > 10) { Observer = (BridgeStationStatuses)byteArray[10]; if (_log.IsInfoEnabled) { _log.InfoFormat("Observer={0}", Observer); } } if (byteArray.Length > 11) { CaptainMap = (BridgeStationStatuses)byteArray[11]; if (_log.IsInfoEnabled) { _log.InfoFormat("CaptainMap={0}", CaptainMap); } } if (byteArray.Length > 12) { GameMaster = (BridgeStationStatuses)byteArray[12]; if (_log.IsInfoEnabled) { _log.InfoFormat("GameMaster={0}", GameMaster); } } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public ShipAction2Packet(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } if (byteArray.Length > 3) { SubPacketType = (ShipAction2SubPacketTypes)BitConverter.ToUInt32(byteArray, 0); } if (byteArray.Length > 4) { List <byte> bytes = new List <byte>(); for (int i = 4; i < byteArray.Length; i++) { bytes.Add(byteArray[i]); } SubPacketData = bytes.ToArray(); _subPacket = GetSubPacket(SubPacketData); } else { _subPacket = null; SubPacketData = null; } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public CommsOutgoingPacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } RecipientType = BitConverter.ToInt32(byteArray, 0); RecipientID = BitConverter.ToInt32(byteArray, 4); MessageID = BitConverter.ToInt32(byteArray, 8); TargetObjectID = BitConverter.ToInt32(byteArray, 12); Unknown = BitConverter.ToInt32(byteArray, 16); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public AudioCommandPacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } ID = BitConverter.ToInt32(byteArray, 0); PlayOrDismiss = BitConverter.ToInt32(byteArray, 4); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public IntelPacket(byte[] byteArray) { if (byteArray != null) { #if LOG4NET if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } #endif ID = BitConverter.ToInt32(byteArray, 0); Unknown2 = byteArray[4]; Message = new ArtemisString(byteArray, 5); #if LOG4NET if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } #endif } }
public GameStartPacket(byte[] byteArray) { #if LOG4NET if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } #endif Unknown1 = BitConverter.ToInt32(byteArray, 0); #if LOG4NET if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } #endif }
void Initialize(byte[] byteArray, int index) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } TeamNumber = Convert.ToByte(byteArray[index] - 0x0a); if (_log.IsInfoEnabled) { _log.InfoFormat("TeamNumber={0}", TeamNumber); } GoalX = BitConverter.ToInt32(byteArray, index + 1); if (_log.IsInfoEnabled) { _log.InfoFormat("GoalX={0}", GoalX); } CurrentX = BitConverter.ToInt32(byteArray, index + 5); if (_log.IsInfoEnabled) { _log.InfoFormat("CurrentX={0}", CurrentX); } GoalY = BitConverter.ToInt32(byteArray, index + 9); if (_log.IsInfoEnabled) { _log.InfoFormat("GoalY={0}", GoalY); } CurrentY = BitConverter.ToInt32(byteArray, index + 13); if (_log.IsInfoEnabled) { _log.InfoFormat("CurrentY={0}", CurrentY); } GoalZ = BitConverter.ToInt32(byteArray, index + 17); if (_log.IsInfoEnabled) { _log.InfoFormat("GoalZ={0}", GoalZ); } CurrentZ = BitConverter.ToInt32(byteArray, index + 21); if (_log.IsInfoEnabled) { _log.InfoFormat("CurrentZ={0}", CurrentZ); } Progress = BitConverter.ToSingle(byteArray, index + 25); if (_log.IsInfoEnabled) { _log.InfoFormat("Progress={0}", Progress); } NumberOfTeamMembers = BitConverter.ToInt32(byteArray, index + 29); if (_log.IsInfoEnabled) { _log.InfoFormat("NumberOfTeamMembers={0}", NumberOfTeamMembers); } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public IncomingAudioPacket(byte[] byteArray) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } MessageID = BitConverter.ToInt32(byteArray, 0); AudioMode = (AudioModes)BitConverter.ToInt32(byteArray, 4); Title = new ArtemisString(byteArray, 8); File = new ArtemisString(byteArray, 8 + Title.Length); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } }
public DestroyObjectPacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } Target = (ObjectTypes)byteArray[0]; ID = BitConverter.ToInt32(byteArray, 1); if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public WelcomePacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } Unknown = BitConverter.ToInt32(byteArray, 0); if (_log.IsInfoEnabled) { _log.InfoFormat("Unknown={0}", Unknown.ToString()); } Message = System.Text.ASCIIEncoding.ASCII.GetString(byteArray, 4, byteArray.Length - 4); if (_log.IsInfoEnabled) { _log.InfoFormat("Message={0}", Message); } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public ObjectStatusUpdatePacket(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } if (byteArray.Length > 1) { SubPacketType = (ObjectStatusUpdateSubPacketTypes)byteArray[0]; //BitConverter.ToInt32(byteArray, 0); if (_log.IsInfoEnabled) { _log.InfoFormat("SubPacketType={0}", SubPacketType.ToString()); } } List <byte> bytes = new List <byte>(); for (int i = 1; i < byteArray.Length; i++) { bytes.Add(byteArray[i]); } SubPacketData = bytes.ToArray(); _subPacket = GetSubPacket(SubPacketData); //if (byteArray.Length > 4) //{ // List<byte> bytes = new List<byte>(); // for (int i = 4; i < byteArray.Length; i++) // { // bytes.Add(byteArray[i]); // } // SubPacketData = bytes.ToArray(); // _subPacket = GetSubPacket(SubPacketData); //} //else //{ // _subPacket = null; // SubPacketData = null; //} if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }
public Packet(byte[] byteArray) { if (byteArray != null) { if (_log.IsInfoEnabled) { _log.Info("~~~~~~~~~~~~~~~~Starting Packet Creation.~~~~~~~~~~~~~~~~~~~~~~~~"); } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--{2} bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray), byteArray.Length.ToString()); } ID = BitConverter.ToUInt32(byteArray, 0); //Len = 4 if (ID != Connector.StandardID) { if (ThrowWhenInvalid) { throw new InvalidPacketException(); } else { return; } } if (_log.IsInfoEnabled) { _log.InfoFormat("ID={0}", ID.ToString()); } Length = BitConverter.ToInt32(byteArray, 4);//Len = 4 if (_log.IsInfoEnabled) { _log.InfoFormat("Length={0}", Length.ToString()); } Origin = (OriginType)BitConverter.ToInt32(byteArray, 8);//Len = 4 if (_log.IsInfoEnabled) { _log.InfoFormat("Origin={0}", Origin.ToString()); } Unknown = BitConverter.ToInt32(byteArray, 12);//Len = 4 if (_log.IsInfoEnabled) { _log.InfoFormat("Unknown={0}", Unknown.ToString()); } PayloadLength = BitConverter.ToInt32(byteArray, 16);//Len = 4 if (_log.IsInfoEnabled) { _log.InfoFormat("RemainingPacketLength={0}", PayloadLength.ToString()); } PacketType = (PacketTypes)BitConverter.ToUInt32(byteArray, 20);//Len = 4 if (_log.IsInfoEnabled) { _log.InfoFormat("PacketType={0}", PacketType.ToString()); } List <byte> newArray = new List <byte>(); int ln = byteArray.Length; if (ln > Length) { ln = Length; } for (int i = HeaderLength; i < ln; i++) { newArray.Add(byteArray[i]); } Payload = newArray.ToArray(); _package = GetPackage(Payload); int packetLength = 0; if (_package != null) { byte[] packetBytes = _package.GetBytes(); packetLength = packetBytes.Length; } if (packetLength + HeaderLength != Length && ThrowWhenInvalid) { throw new InvalidPacketException(); } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--{2} Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes()), this.GetBytes().Length); } if (_log.IsInfoEnabled) { _log.Info("~~~~~~~~~~~~~~~~Packet Creation Ended.~~~~~~~~~~~~~~~~~~~~~~~~"); } } }
void Initialize(byte[] byteArray, int index) { if (byteArray != null) { bool isDone = false; if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--bytes in: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(byteArray)); } if (byteArray[index] == 255) { isDone = true; } if (index < byteArray.Length && !isDone) { X = byteArray[index]; if (_log.IsInfoEnabled) { _log.InfoFormat("X={0}", X); } if (byteArray[index + 1] == 255) { isDone = true; } } if (index + 1 < byteArray.Length && !isDone) { Y = byteArray[index + 1]; if (_log.IsInfoEnabled) { _log.InfoFormat("Y={0}", Y); } if (byteArray[index + 2] == 255) { isDone = true; } } if (index + 2 < byteArray.Length && !isDone) { Z = byteArray[index + 2]; if (_log.IsInfoEnabled) { _log.InfoFormat("Z={0}", Z); } if (byteArray[index + 3] == 255) { isDone = true; } } if (index + 7 <= byteArray.Length && !isDone) { Damage = BitConverter.ToSingle(byteArray, index + 3); if (_log.IsInfoEnabled) { _log.InfoFormat("Damage={0}", Damage); } } else { isDone = true; } if (_log.IsInfoEnabled) { _log.InfoFormat("{0}--Result bytes: {1}", MethodBase.GetCurrentMethod().ToString(), Utility.BytesToDebugString(this.GetBytes())); } } }