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

            PacketLog.Write(packet.GetData(), opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType);

            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);
        }
Example #2
0
        ReadDataHandlerResult ReadData()
        {
            PacketHeader header = new PacketHeader();

            header.Read(_headerBuffer.GetData());

            if (!_worldCrypt.Decrypt(_packetBuffer.GetData(), header.Tag))
            {
                Log.outError(LogFilter.Network, $"WorldSocket.ReadData(): client {GetRemoteIpAddress()} failed to decrypt packet (size: {header.Size})");
                return(ReadDataHandlerResult.Error);
            }

            WorldPacket packet = new WorldPacket(_packetBuffer.GetData());

            _packetBuffer.Reset();

            if (packet.GetOpcode() >= (int)ClientOpcodes.Max)
            {
                Log.outError(LogFilter.Network, $"WorldSocket.ReadData(): client {GetRemoteIpAddress()} sent wrong opcode (opcode: {packet.GetOpcode()})");
                return(ReadDataHandlerResult.Error);
            }

            PacketLog.Write(packet.GetData(), packet.GetOpcode(), GetRemoteIpAddress(), _connectType, true);

            ClientOpcodes opcode = (ClientOpcodes)packet.GetOpcode();

            switch (opcode)
            {
            case ClientOpcodes.Ping:
                Ping ping = new Ping(packet);
                ping.Read();
                if (!HandlePing(ping))
                {
                    return(ReadDataHandlerResult.Error);
                }
                break;

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

                AuthSession authSession = new AuthSession(packet);
                authSession.Read();
                HandleAuthSession(authSession);
                return(ReadDataHandlerResult.WaitingForQuery);

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

                AuthContinuedSession authContinuedSession = new AuthContinuedSession(packet);
                authContinuedSession.Read();
                HandleAuthContinuedSession(authContinuedSession);
                return(ReadDataHandlerResult.WaitingForQuery);

            case ClientOpcodes.KeepAlive:
                if (_worldSession != null)
                {
                    _worldSession.ResetTimeOutTime(true);
                }
                break;

            case ClientOpcodes.LogDisconnect:
                break;

            case ClientOpcodes.EnableNagle:
                SetNoDelay(false);
                break;

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

            case ClientOpcodes.EnterEncryptedModeAck:
                HandleEnterEncryptedModeAck();
                break;

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

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

                // Our Idle timer will reset on any non PING opcodes on login screen, allowing us to catch people idling.
                _worldSession.ResetTimeOutTime(false);

                // Copy the packet to the heap before enqueuing
                _worldSession.QueuePacket(packet);
                break;
            }

            return(ReadDataHandlerResult.Ok);
        }