protected override void PumpNetwork() { NetworkServer.Update(); Chunk packet = null; uint responseToken = 0; while (NetworkServer.Receive(ref packet, ref responseToken)) { if (packet.Flags.HasFlag(SendFlags.Connless)) { if (Register.RegisterProcessPacket(packet, responseToken)) { continue; } if (packet.DataSize >= MasterServerPackets.GetInfo.Length && packet.Data.ArrayCompare(MasterServerPackets.GetInfo, MasterServerPackets.GetInfo.Length)) { var unpacker = new UnPacker(); unpacker.Reset(packet.Data, packet.DataSize, MasterServerPackets.GetInfo.Length); var serverBrowserToken = unpacker.GetInt(); if (unpacker.Error) { continue; } var packer = new Packer(); GenerateServerInfo(packer, serverBrowserToken); var response = new Chunk() { ClientId = -1, EndPoint = packet.EndPoint, Flags = SendFlags.Connless, Data = packer.Data(), DataSize = packer.Size(), }; NetworkServer.Send(response, responseToken); } } else { ProcessClientPacket(packet); } } // TODO Econ.Update(); NetworkBan.Update(); }
protected override void ProcessClientPacket(Chunk packet) { var clientId = packet.ClientId; var unpacker = new UnPacker(); unpacker.Reset(packet.Data, packet.DataSize); var msg = unpacker.GetInt(); var system = (msg & 1) != 0; msg >>= 1; if (unpacker.Error) { return; } if (system) { var networkMsg = (NetworkMessages)msg; switch (networkMsg) { case NetworkMessages.ClientInfo: NetMsgInfo(packet, unpacker, clientId); break; case NetworkMessages.ClientRequestMapData: NetMsgRequestMapData(packet, unpacker, clientId); break; case NetworkMessages.ClientReady: NetMsgReady(packet, unpacker, clientId); break; case NetworkMessages.ClientEnterGame: NetMsgEnterGame(packet, unpacker, clientId); break; case NetworkMessages.ClientInput: NetMsgInput(packet, unpacker, clientId); break; case NetworkMessages.ClientRconCommand: NetMsgRconCmd(packet, unpacker, clientId); break; case NetworkMessages.ClientRconAuth: NetMsgRconAuth(packet, unpacker, clientId); break; case NetworkMessages.Ping: NetMsgPing(packet, unpacker, clientId); break; default: Console.Print(OutputLevel.Debug, "server", $"strange message clientId={clientId} msg={msg} data_size={packet.DataSize}"); break; } } else if (packet.Flags.HasFlag(SendFlags.Vital) && Clients[clientId].State >= ServerClientState.Ready) { GameContext.OnMessage((GameMessage)msg, unpacker, clientId); } }