public L2Packet handlePacket(byte[] incPacket, bool fromServer) { if (!fromServer) return null; this.decryptPacket(incPacket); ByteBuffer binPacket = new ByteBuffer(incPacket); binPacket.ReadBytes(2); // discard first 2 bytes byte id = binPacket.ReadByte(); switch (id) { case 0x00: // Init //Console.Out.WriteLine("LoginServerpacket::Init"); this.handleInit(binPacket); break; case 0x01: // LoginFail //Console.Out.WriteLine("LoginServerpacket::LoginFail"); break; case 0x02: // AccountKicked //Console.Out.WriteLine("LoginServerpacket::AccountKicked"); break; case 0x03: // LoginOk //Console.Out.WriteLine("LoginServerpacket::LoginOk"); break; case 0x04: // Serverlist //Console.Out.WriteLine("LoginServerpacket::Serverlist"); break; case 0x06: // PlayFail //Console.Out.WriteLine("LoginServerpacket::PlayFail"); break; case 0x07: // PlayOk //Console.Out.WriteLine("LoginServerpacket::PlayOK"); break; case 0x0b: // GGAuth // Console.Out.WriteLine("LoginServerpacket::GGAuth"); break; } return new LoginServerPacket(binPacket); }
public L2Packet handlePacket(byte[] rawPacket, bool fromServer) { if (rawPacket.Length < 3) // Valid data? return null; if (fromServer) serverCrypt.decrypt(rawPacket, 2, rawPacket.Length); else clientCrypt.decrypt(rawPacket, 2, rawPacket.Length); ByteBuffer binPacket = new ByteBuffer(rawPacket); binPacket.ReadBytes(2); // Read 2 bytes ahead int opcode = binPacket.ReadByte(); int secondOpCode = -1; switch (state) { case GameClientState.CONNECTED: // Vom Server (ServerPacket) if (fromServer) { switch (opcode) { case 0x2e: // KeyPacket (Contains key, NOT Encrypted xD ) this.onKeyPacket(binPacket); break; case 0x09: // CharSelectionInfo this.state = GameClientState.AUTHED; break; } } // Vom Clienten else { } break; case GameClientState.AUTHED: if (fromServer) { switch (opcode) { case 0x73: this.state = GameClientState.IN_GAME; //Console.Out.WriteLine(Util.printData(binPacket)); break; } } else { switch (opcode) { case 0x0d: // get secondOpCode and set secondOpCode = binPacket.ReadInt16(); break; case 0x12: // CharacterSelect break; } } break; case GameClientState.IN_GAME: if (fromServer) { switch (opcode) { case 0xfe: // get secondOpCode secondOpCode = binPacket.ReadInt16(); break; case 0x0b: //CharSelected this.onCharSelected(binPacket); break; } } else { switch (opcode) { case 0x1f: break; case 0xd0: // get secondOpCode secondOpCode = binPacket.ReadInt16(); break; } } break; } if (fromServer) return new GameServerPacket(binPacket); else { return new ClientPacket(binPacket); } }
private void onKeyPacket(ByteBuffer packet) { packet.ReadByte(); this.cryptKey = packet.ReadBytes(16); this.cryptKey[8] = (byte)0xc8; this.cryptKey[9] = (byte)0x27; this.cryptKey[10] = (byte)0x93; this.cryptKey[11] = (byte)0x01; this.cryptKey[12] = (byte)0xa1; this.cryptKey[13] = (byte)0x6c; this.cryptKey[14] = (byte)0x31; this.cryptKey[15] = (byte)0x97; serverCrypt.setKey(this.cryptKey); clientCrypt.setKey(this.cryptKey); // ddcd packet.ReadInt32(); packet.ReadInt32(); packet.ReadByte(); this.obfusicateKey = packet.ReadInt32(); this.clientCrypt.generateOpcodeTable(this.obfusicateKey); }