示例#1
0
        public Server(Config config, MasterClient masterClient)
        {
            Logger.Log($"SERVER creating...");
            _masterClient = masterClient;
            _config       = config;
            _gameMode     = (GameMode)_config.GameMode;

            _world               = new World(_config, _gameMode);
            _world.OnGameEnd    += World_OnGameEnd;
            _world.OnPlayerDead += World_OnPlayerDead;

            _server = new NetManager(this, 100 + _config.MaxPlayers, _config.ConnectionKey)
            {
                UpdateTime = _config.UpdateDelay / 3,
            };

            Logger.Log($"SERVER register packets");
            _netSerializer = new NetSerializer();
            Packet.Register(_netSerializer);
            _netSerializer.SubscribeReusable <ClientConnection, NetPeer>(OnClientConnection);
            _netSerializer.SubscribeReusable <ClientInput, NetPeer>(OnClientInput);
            _netSerializer.SubscribeReusable <ClientSpawn, NetPeer>(OnClientSpawn);
            _netSerializer.SubscribeReusable <ClientLeave, NetPeer>(OnClentLeave);

            Logger.Log($"SERVER created");
        }
示例#2
0
        static async Task AMain(string[] args)
        {
            var config = new Config(args);

            Logger.Init(config.DiscordLog, config.DiscordAll > 0);
            Logger.Log("LOGGER init");

            var masterClient = new MasterClient(config);

            var additionalArgs = await masterClient.RequestConfig();

            config.AppendArgs(additionalArgs.Args.ToArray());

            try
            {
                var server = new Server(config, masterClient);
                await server.Run();
            }
            catch (Exception e)
            { Logger.Log($"SERVER ERROR: {e.ToString()}", true); }

            await Task.Delay(3000);

            Logger.Stop();
            await Task.Delay(2000);
        }