public override bool Process(WorldPacket packet) { PacketHandler opHandle = PacketManager.GetHandler((ClientOpcodes)packet.GetOpcode()); //check if packet handler is supposed to be safe if (opHandle.processingPlace == PacketProcessing.Inplace) { return(true); } //thread-unsafe packets should be processed in World.UpdateSessions() if (opHandle.processingPlace == PacketProcessing.ThreadUnsafe) { return(true); } //no player attached? . our client! ^^ Player player = m_pSession.GetPlayer(); if (!player) { return(true); } //lets process all packets for non-in-the-world player return(!player.IsInWorld); }
public override bool Process(WorldPacket packet) { PacketHandler opHandle = PacketManager.GetHandler((ClientOpcodes)packet.GetOpcode()); //check if packet handler is supposed to be safe if (opHandle.processingPlace == PacketProcessing.Inplace) { return(true); } //we do not process thread-unsafe packets if (opHandle.processingPlace == PacketProcessing.ThreadUnsafe) { return(false); } Player player = m_pSession.GetPlayer(); if (!player) { return(false); } //in Map.Update() we do not process packets where player is not in world! return(player.IsInWorld); }
public override void ReadHandler(int transferredBytes) { if (!IsOpen()) { return; } while (transferredBytes > 5) { PacketHeader header; if (!ReadHeader(out header)) { CloseSocket(); return; } var data = new byte[header.Size]; Buffer.BlockCopy(GetReceiveBuffer(), 16, data, 0, header.Size); if (!_worldCrypt.Decrypt(ref data, header.Tag)) { Log.outError(LogFilter.Network, $"WorldSocket.ReadHandler(): client {GetRemoteIpAddress().ToString()} failed to decrypt packet (size: {header.Size})"); return; } WorldPacket worldPacket = new WorldPacket(data); if (worldPacket.GetOpcode() >= (int)ClientOpcodes.Max) { Log.outError(LogFilter.Network, $"WorldSocket.ReadHandler(): client {GetRemoteIpAddress().ToString()} sent wrong opcode (opcode: {worldPacket.GetOpcode()})"); return; } PacketLog.Write(data, worldPacket.GetOpcode(), GetRemoteIpAddress(), GetRemotePort(), _connectType, true); if (!ProcessPacket(worldPacket)) { CloseSocket(); return; } transferredBytes -= header.Size + 16; Buffer.BlockCopy(GetReceiveBuffer(), header.Size + 16, GetReceiveBuffer(), 0, transferredBytes); } AsyncRead(); }
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); }