예제 #1
0
        bool ProcessPacket(WorldPacket packet)
        {
            ClientOpcodes opcode = (ClientOpcodes)packet.GetOpcode();

            try
            {
                switch (opcode)
                {
                case ClientOpcodes.Ping:
                    Ping ping = new Ping(packet);
                    ping.Read();
                    return(HandlePing(ping));

                case ClientOpcodes.AuthSession:
                    if (_worldSession != null)
                    {
                        Log.outError(LogFilter.Network, "WorldSocket.ProcessPacket: received duplicate CMSG_AUTH_SESSION from {0}", _worldSession.GetPlayerInfo());
                        return(false);
                    }

                    AuthSession authSession = new AuthSession(packet);
                    authSession.Read();
                    HandleAuthSession(authSession);
                    break;

                case ClientOpcodes.AuthContinuedSession:
                    if (_worldSession != null)
                    {
                        Log.outError(LogFilter.Network, "WorldSocket.ProcessPacket: received duplicate CMSG_AUTH_CONTINUED_SESSION from {0}", _worldSession.GetPlayerInfo());
                        return(false);
                    }

                    AuthContinuedSession authContinuedSession = new AuthContinuedSession(packet);
                    authContinuedSession.Read();
                    HandleAuthContinuedSession(authContinuedSession);
                    break;

                case ClientOpcodes.LogDisconnect:
                    break;

                case ClientOpcodes.EnableNagle:
                    Log.outDebug(LogFilter.Network, "Client {0} requested enabling nagle algorithm", GetRemoteIpAddress().ToString());
                    SetNoDelay(false);
                    break;

                case ClientOpcodes.ConnectToFailed:
                    ConnectToFailed connectToFailed = new ConnectToFailed(packet);
                    connectToFailed.Read();
                    HandleConnectToFailed(connectToFailed);
                    break;

                case ClientOpcodes.EnableEncryptionAck:
                    HandleEnableEncryptionAck();
                    break;

                default:
                    if (_worldSession == null)
                    {
                        Log.outError(LogFilter.Network, "ProcessIncoming: Client not authed opcode = {0}", opcode);
                        return(false);
                    }

                    if (!PacketManager.ContainsHandler(opcode))
                    {
                        Log.outError(LogFilter.Network, "No defined handler for opcode {0} sent by {1}", opcode, _worldSession.GetPlayerInfo());
                        break;
                    }

                    // Our Idle timer will reset on any non PING opcodes.
                    // Catches people idling on the login screen and any lingering ingame connections.
                    _worldSession.ResetTimeOutTime();
                    _worldSession.QueuePacket(packet);
                    break;
                }
            }
            catch (IOException)
            {
                Log.outError(LogFilter.Network, "WorldSocket.ProcessPacket(): client {0} sent malformed {1}", GetRemoteIpAddress().ToString(), opcode);
                return(false);
            }

            return(true);
        }