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 PumpNetwork() { NetworkServer.Update(); while (NetworkServer.Receive(out var packet)) { if (packet.ClientId == -1) { if (packet.DataSize == MasterServerPackets.SERVERBROWSE_GETINFO.Length + 1 && packet.Data.ArrayCompare( MasterServerPackets.SERVERBROWSE_GETINFO, MasterServerPackets.SERVERBROWSE_GETINFO.Length)) { SendServerInfo( packet.EndPoint, packet.Data[MasterServerPackets.SERVERBROWSE_GETINFO.Length], false ); } else if (packet.DataSize == MasterServerPackets.SERVERBROWSE_GETINFO_64_LEGACY.Length + 1 && packet.Data.ArrayCompare( MasterServerPackets.SERVERBROWSE_GETINFO_64_LEGACY, MasterServerPackets.SERVERBROWSE_GETINFO_64_LEGACY.Length)) { SendServerInfo( packet.EndPoint, packet.Data[MasterServerPackets.SERVERBROWSE_GETINFO.Length], true ); } continue; } ProcessClientPacket(packet); } if (Config["SvFastDownload"]) { for (var i = 0; i < Clients.Length; i++) { if (Clients[i].State != ServerClientState.CONNECTING) { continue; } if (_lastAskTick[i] < Tick - TickSpeed) { _lastSent[i] = _lastAsk[i]; _lastAskTick[i] = Tick; } if (_lastAsk[i] < _lastSent[i] - Config["SvMapWindow"]) { continue; } var chunk = _lastSent[i]++; var chunkSize = 1024 - 128; var offset = chunk * chunkSize; var last = 0; // drop faulty map data requests if (chunk < 0 || offset > CurrentMap.Size) { continue; } if (offset + chunkSize >= CurrentMap.Size) { chunkSize = CurrentMap.Size - offset; if (chunkSize < 0) { chunkSize = 0; } last = 1; } SendMapData(last, chunk, chunkSize, offset, i); } } NetworkBan.Update(); }