private bool HandleClientPacket(byte[] data, int bytesRead) { UOStream Data = new UOStream(data); switch(data[0]) { case OpCode.CMSG_GumpMenuSelection: var p = new Packets.FromClient._0xB1GumpMenuSelection(Data); if (_0xB1GumpMenuSelection != null) _0xB1GumpMenuSelection((Packets.FromClient._0xB1GumpMenuSelection)p); break; case OpCode.CMSG_TalkRequest: var ptalk = new Packets.FromClient._0x03TalkRequest(Data); if (ptalk.Message.StartsWith("~")) { HandleProxyCommand(ptalk); //dont forward to server return false; } if (_0x03TalkRequest != null) _0x03TalkRequest(ptalk); break; } return true; }
private int GetServerPacketSize(byte[] data, int bytesRead) { int size = 0; switch (data[0]) { case 0x8C: size = 11; break; default: break; } if (size > 0) return size; else { // no client handler, what to do? var tempstream = new UOStream(data); tempstream.ReadBit(); return tempstream.ReadShort(); } }
private void HandlePacketFromServer(byte[] data, TcpClient client) { //HandlersEvents.Add(0x8c, this._0x8CConnectToGameServer); UOStream Data = new UOStream(data); Packet packet = new Packet(); if (data == null) { return; } if (data.Length < 1) { return; } Data.Position = 0; while (Data.Position < Data.Length - 1) { if (HandlersServer.ContainsKey(Data.PeekBit())) { var olddatapos = Data.Position; packet = (Packet)Activator.CreateInstance(HandlersServer[Data.PeekBit()], new object[] { Data }); //Logger.Log(packet.OpCode.ToString("x") + " Handled from Server"); Logger.Log(BitConverter.ToString(packet.PacketData, (int)olddatapos, (int)(Data.Position - olddatapos)) + " Handled from Server"); var eventinfo = this.GetType().GetField(packet.GetType().Name, BindingFlags.Instance | BindingFlags.NonPublic); if (eventinfo != null) { var member = eventinfo.GetValue(this); if (member != null) { //Logger.Log(member.ToString()); member.GetType().GetMethod("Invoke").Invoke(member, new object[] { packet }); } else { //Logger.Log("MEMBER WAS NULL FOR EVENT: " + eventinfo.Name); } } else { //Logger.Log("EVENTFIELD WAS NULL FOR PACKET : " + packet.ToString()); } } else { Logger.Log(Data.PeekBit().ToString("x") + BitConverter.ToString(Data.ToArray(), (int)Data.Position, (int)(Data.Length-Data.Position)) + "No Server Handler"); break; } if (Data.Position < Data.Length -1) { byte[] tempdata = new byte[Data.Length - Data.Position]; Array.Copy(Data.ToArray(), Data.Position, tempdata, 0, Data.Length - Data.Position); Data = new UOStream(tempdata); Logger.Log("IT HAPPENED! Data left after parsing packet" + BitConverter.ToString(tempdata, 0, (int)tempdata.Length)); // this should never happen } } return; }
private int GetClientPacketSize(byte[] data, int bytesRead) { // need to handle byte packet i guess?? if (ClientSizes(data[0]) != 0) { return ClientSizes(data[0]); } else if(bytesRead > 3) { // Known packet with unknown size or size of 0 try and read size from data[] var tempstream = new UOStream(data); tempstream.ReadBit(); return tempstream.ReadShort(); } return 0; }
private void HandleClientPacket(byte[] data, int bytesRead) { UOStream Data = new UOStream(data); Packet packet; while (Data.Position < Data.Length - 1) { if (HandlersClient.ContainsKey(Data.PeekBit())) { var olddatapos = Data.Position; packet = (Packet)Activator.CreateInstance(HandlersClient[Data.PeekBit()], new object[] { Data }); //Logger.Log(packet.OpCode.ToString("x") + " Handled from Client "); Logger.Log(BitConverter.ToString(packet.PacketData, (int)olddatapos, (int)(Data.Position - olddatapos)) + " len:" + (Data.Position - olddatapos) + " Handled from Client "); var eventinfo = this.GetType().GetField("Client" + packet.GetType().Name, BindingFlags.Instance | BindingFlags.NonPublic); if (eventinfo != null) { var member = eventinfo.GetValue(this); if (member != null) { //Logger.Log(member.ToString()); member.GetType().GetMethod("Invoke").Invoke(member, new object[] { packet }); } else { //Logger.Log("MEMBER WAS NULL FOR EVENT: " + eventinfo.Name); } } else { // Logger.Log("EVENTFIELD WAS NULL FOR PACKET : " + packet.ToString()); } } else { Logger.Log(Data.PeekBit().ToString("x") + BitConverter.ToString(data, (int)Data.Position, (int)(Data.Length - Data.Position)) + "No Client Handler Discarding"); break; } } }