public override void OnClientData(ClientBase aClient, byte[] data) { LoginClient client = aClient as LoginClient; BinReader read = new BinReader(data); read.BaseStream.Position += 2; // skip len CMSG msgID = (CMSG)read.ReadInt32(); if (!LoginPacketManager.HandlePacket(client, msgID, read)) { if (client.WorldConnection != null) { ClientPacket pkg = new ClientPacket(msgID, client.Character.ObjectId, data, 6, data.Length - 6); client.SendWorldServer(pkg); } } }
/* * internal bool processWorldServerData() * { * if(m_client.PendingSendData) * m_client.SendWork(); * if(m_client.Connected == false) * return false; * byte[] data; * while((data = m_client.GetNextPacketData()) != null) * OnWorldServerData(data); * return m_client.Connected; * }*/ private void OnWorldServerData(ClientBase c, byte[] data) { BinReader read = new BinReader(data); read.BaseStream.Position += 4; // skip len WORLDMSG msgID = (WORLDMSG)read.ReadInt32(); if (msgID == WORLDMSG.SERVER_MESSAGE) { SMSG smsg = (SMSG)read.ReadInt32(); Console.WriteLine("WorldServer sent: " + smsg); int len = read.ReadInt32(); BinWriter pkg = LoginClient.NewPacket(smsg); if (len > 0) { pkg.Write(read.ReadBytes(len)); } while (read.BaseStream.Position < read.BaseStream.Length) { uint plrID = read.ReadUInt32(); LoginClient client = LoginServer.GetLoginClientByCharacterID(plrID); if (client == null) { Console.WriteLine("client missing for plrID " + plrID + " while sending " + smsg.ToString()); } else { client.Send(pkg); } } } else if (msgID == WORLDMSG.SCRIPT_MESSAGE) { LoginServer.Scripts.OnScriptMessage(read.ReadInt32(), read); } else { LoginPacketManager.HandlePacket(this, msgID, read); } }
public override void OnClientData(ClientBase aClient, byte[] data) { LoginClient client = aClient as LoginClient; BinReader read = new BinReader(data); CMSG msgID; if (client.Authenticated == true) { // Why do we discard the first two bytes? read.BaseStream.Position += 2; byte[] header = read.ReadBytes(4); client.Decode(header, 4); BinReader decoded = new BinReader(header); msgID = (CMSG)decoded.ReadInt32(); /*BinReader ops = new BinReader(client.m_opcode); * msgID = (CMSG)ops.ReadInt32();*/ } else { read.BaseStream.Position += 2; // skip len msgID = (CMSG)read.ReadInt32(); } // Console.WriteLine("CMSG:"+ msgID.ToString()); // log opcode to console if (!LoginPacketManager.HandlePacket(client, msgID, read)) { Console.WriteLine("Login Handler not found for CMSG " + msgID + " ..sending to worldserver"); // report error if (client.WorldConnection != null) { ClientPacket pkg = new ClientPacket(msgID, client.Character.ObjectId, data, 6, data.Length - 6); client.SendWorldServer(pkg); } } }