コード例 #1
0
        public static void OPCode(Decode decode)
        {
            try
            {
                Systems sys = (Systems)decode.Packet;
                sys.PacketInformation = decode;
                PacketReader Reader = new PacketReader(sys.PacketInformation.buffer);
                LogDebug.Show("Opcode: {0}", decode.opcode);
                Opcode opc = (Opcode)decode.opcode;
                switch (opc)
                {
                case Opcode._MSG_LOGIN:
                {
                    string username_shift = Reader.String(32);
                    string password_md5   = Reader.String(32);
                    Reader.Skip(4);
                    string client_mac = Reader.String(32);
                    Reader.Skip(32);
                    uint        unk3     = Reader.UInt32();
                    StringShift shift    = new StringShift();
                    string      username = shift.Parser(username_shift);
                    LogDebug.Show("username: {0}", username);
                    LogDebug.Show("password_md5: {0}", password_md5);
                    LogDebug.Show("Mac: {0}", client_mac);
                    LogDebug.Show("unk3: {0}", unk3);
                    int res = UserLogin(username, password_md5, client_mac);
                    if (res == (int)AuthenticationStatus.OK)
                    {
                        sys.client.SendC(NewCharacterPacket());
                    }
                    else if (res == (int)AuthenticationStatus.BANNED)
                    {
                        sys.client.SendC(UserFail(0xF0, Reason.BANNED));
                    }
                    else
                    {
                        sys.client.SendC(UserFail(0xF0, Reason.AUTH_FAILED));
                    }
                }
                break;

                default:
                    LogConsole.Show("Default Opcode: {0:X} - {1}", decode.opcode, opc);
                    LogDebug.HexDump(sys.PacketInformation.buffer, 16, true, false);
                    break;
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #2
0
ファイル: Networking.cs プロジェクト: Try-Parser/TestProjects
            public void ReceiveData(IAsyncResult ar)
            {
                Socket wSocket = (Socket)ar.AsyncState;

                try
                {
                    if (wSocket.Connected)
                    {
                        int  recvSize  = wSocket.EndReceive(ar); // get the count of received bytes
                        bool checkData = true;
                        if (recvSize > 0)
                        {
                            if ((recvSize + bufCount) > MAX_BUFFER)  // that may be a try to force buffer overflow, we don't allow that ;)
                            {
                                checkData = false;
                                LocalDisconnect(wSocket);
                            }
                            else
                            {                                                            // we have something in input buffer and it is not beyond our limits
                                Buffer.BlockCopy(tmpbuf, 0, buffer, bufCount, recvSize); // copy the new data to our buffer
                                bufCount += recvSize;                                    // increase our buffer-counter
                            }
                        }
                        else
                        {   // 0 bytes received, this should be a disconnect
                            checkData = false;
                            LocalDisconnect(wSocket);
                        }

                        while (checkData) // repeat while we have data
                        {
                            checkData = false;
                            if (bufCount >= 4) // a minimum of 4 byte is required for us
                            {
                                byte[] _newtmp = new byte[bufCount];
                                Buffer.BlockCopy(buffer, 0, _newtmp, 0, bufCount);
                                LogDebug.HexDump(_newtmp, 16, true, true);
                                Decode de = new Decode(buffer);                                         // only get the size first.
                                LogConsole.Show("bufCount: {0} dataSize: {1}", bufCount, de.dataSize);
                                if (bufCount >= (de.dataSize - 2))                                      // It's a complete packet. Call the handler.
                                {
                                    de = new Decode(wSocket, de.tempbuff, this, Packets);               // build up the Decode structure for next step
                                    OnReceiveData(de);                                                  // call the handling routine
                                    bufCount -= (de.dataSize);                                          // decrease buffer-counter
                                    if (bufCount >= 0)                                                  // was the buffer greater than what the packet needs? then it may be the next packet.
                                    {
                                        Buffer.BlockCopy(buffer, 2 + de.dataSize, buffer, 0, bufCount); // move the rest to buffer start
                                        checkData = true;                                               // loop for next packet
                                    }
                                }
                                else
                                {
                                    byte[] _tempddd = new byte[bufCount];
                                    EncDec end      = new EncDec();
                                    byte[] dddxx    = end.Crypt(buffer);
                                    Buffer.BlockCopy(dddxx, 0, _tempddd, 0, de.dataSize);
                                    LogConsole.Show("bufCount: {0} dataSize: {1}", bufCount, de.dataSize);
                                }
                                de = null;
                            }
                        }
                        // start the next async read
                        if (wSocket != null && wSocket.Connected)
                        {
                            wSocket.BeginReceive(tmpbuf, 0, tmpbuf.Length, SocketFlags.None, new AsyncCallback(ReceiveData), wSocket);
                        }
                    }
                    else
                    {
                        LocalDisconnect(wSocket);
                    }
                }
                catch (SocketException)  // explicit handling of SocketException
                {
                    LocalDisconnect(wSocket);
                }
                catch (Exception) // other exceptions
                {
                    LocalDisconnect(wSocket);
                }
            }