Example #1
0
        public void Send(byte[] p)
        {
            Packet packet = Packet.Encrypt(new Packet(p), key);

            client.Send(packet.GetBuffer());
        }
Example #2
0
        private void HandlePacket(Packet p)
        {
            int curByte = 0;
            int maxByte = p.Length;

            while (curByte < maxByte)
            {
                int    parsedLength = p.ReadShort((curByte + 2)) + 4;
                byte[] parsed       = new byte[parsedLength];

                // read bytes from buffer to parsed packets.
                for (int i = 0; i < parsed.Length; i++)
                {
                    parsed[i] = p.GetBuffer()[i + curByte];
                }

                // decrypt those bytes as a new real deal parsed packet
                Packet Parsed = Packet.Decrypt(new Packet(parsed), key);
                curByte += parsedLength;

                PacketIds PI = (PacketIds)Parsed.ReadShort();
                switch (PI)
                {
                    #region Login Recvs
                case PacketIds.Recv_GameLogin:
                    HandleRecvGameLogin(Parsed);
                    break;

                case PacketIds.Recv_ConnectWorld:
                    HandleRecvConnectWorld(Parsed);
                    break;

                    #endregion

                    #region World Recvs

                case PacketIds.RecvUnitLogin:
                    HandleRecvUnitLogin(Parsed);
                    break;

                case PacketIds.RecvCreateCharacter:
                    HandleRecvCreateCharacter(Parsed);
                    break;

                case PacketIds.RecvChannelRequest:
                    HandleRecvChannelRequest(Parsed);
                    break;

                    #endregion

                    #region Channel Recvs
                case PacketIds.RecvPing:
                    // needs check if too fast or so :I
                    break;

                case PacketIds.RecvChannelLogin:
                    HandleRecvChannelLogin(Parsed);
                    break;

                case PacketIds.RecvChannelChange:
                    HandleRecvChannelChange(Parsed);
                    break;

                case PacketIds.RecvChannelSomething:
                    HandleRecvChannelStuff(Parsed);
                    break;

                case PacketIds.RecvLoadMap:
                    HandleRecvMapRequest(Parsed);
                    break;

                case PacketIds.RecvRequestSkillList:
                    HandleRecvSkillRequest(Parsed);
                    break;

                case PacketIds.RecvRequestInventory:
                    HandleRecvInventoryRequest(Parsed);
                    break;

                case PacketIds.RecvMoveItem:
                    HandleRecvMoveItem(Parsed);
                    break;

                case PacketIds.RecvDropItem:
                    HandleRecvDropItem(Parsed);
                    break;

                case PacketIds.RecvPickItem:
                    HandleRecvPickItem(Parsed);
                    break;

                case PacketIds.RecvImbueItem:
                    HandleRecvImbueItem(Parsed);
                    break;

                case PacketIds.RecvAcceptImbueItem:
                    HandleRecvAcceptImbueItem(Parsed);
                    break;

                case PacketIds.RecvNpcTrade:
                    HandleRecvNpcTrade(Parsed);
                    break;

                case PacketIds.RecvBuyItem:
                    HandleRecvBuyItem(Parsed);
                    break;

                case PacketIds.RecvSomething:
                    Send(PacketManager.SendSomething());
                    break;

                case PacketIds.RecvRequestFriendList:
                    Send(PacketManager.SendFriendList());
                    break;

                case PacketIds.RecvRequestGuildList:
                    // AD GUILD LIST SEND
                    break;

                case PacketIds.RecvSomething2:
                    Send(PacketManager.SendSomething2());
                    break;

                case PacketIds.RecvStatRequest:
                    HandleRecvStatRequest(Parsed);
                    break;

                case PacketIds.RecvSpawnRequest:
                    HandleRecvSpawnRequest(Parsed);
                    break;

                case PacketIds.RecvSpawnPlayer:     // request for other player to spawn
                    HandleRecvSpawnOtherPlayerRequest(Parsed);
                    break;

                case PacketIds.RecvRequestStats:
                    HandleRecvRequestStats(Parsed);
                    break;

                case PacketIds.RecvAddStat:
                    HandleRecvAddStat(Parsed);
                    break;

                case PacketIds.RecvPlayerID:
                    HandleRecvSendPlayerIDRequest(Parsed);
                    break;

                case PacketIds.RecvStartMoving:
                    HandleRecvStartMoving(Parsed);
                    break;

                case PacketIds.RecvKeepMoving:
                    HandleRecvKeepMoving(Parsed);
                    break;

                case PacketIds.RecvStopMoving:
                    HandleRecvStopMoving(Parsed);
                    break;

                case PacketIds.RecvWalkToPortal:
                    HandleRecvWalkToPortal(Parsed);
                    break;

                case PacketIds.RecvChatMessage:
                    HandleRecvChatMessage(Parsed);
                    break;

                case PacketIds.RecvCommand:
                    HandleRecvCommand(Parsed);
                    break;

                    #endregion

                default:
                    HandleRecvUnknownPacket(Parsed);
                    break;     // needs logging system like "packet id received: " then whole buffer like in old one
                }
            }
        }