コード例 #1
0
        public IRconClient CreateInstance(GameType gameType, Guid serverId, string hostname, int queryPort, string rconPassword)
        {
            IRconClient rconClient;

            switch (gameType)
            {
            case GameType.CallOfDuty2:
            case GameType.CallOfDuty4:
            case GameType.CallOfDuty5:
                rconClient = new Quake3RconClient(_logger);
                break;

            case GameType.Insurgency:
            case GameType.Rust:
            case GameType.Left4Dead2:
                rconClient = new SourceRconClient(_logger);
                break;

            default:
                throw new Exception("Unsupported game type");
            }

            rconClient.Configure(gameType, serverId, hostname, queryPort, rconPassword);
            return(rconClient);
        }
コード例 #2
0
        private async void SetupRCON()
        {
            await Task.Delay(10000);

            if (this.State != ApplicationState.Starting)
            {
                module.log.Warning("Tried to start RCON but server is not running!");
                return;
            }

            try
            {
                rcon = new SourceRconClient();
                rcon.DataRecieved += Rcon_DataRecieved;

                bool connectResult = false;
                int  rconRetry     = 0;

                //Keep trying to connect to RCON over and over until we either succeed, get a permission denied, or the server stops.
                do
                {
                    string rconTargetIP = "";
                    if (IPAddress.TryParse(module.settings.Rust.IP, out var BindIP))
                    {
                        rconTargetIP = IPAddress.Equals(BindIP, IPAddress.Any) ? IPAddress.Loopback.ToString() : BindIP.ToString();
                    }

                    connectResult = await rcon.Connect(rconTargetIP, module.settings.Rust.RconPort);

                    if (connectResult == false)
                    {
                        await Task.Delay(10000);

                        rconRetry++;
                    }
                } while (connectResult == false && this.State == ApplicationState.Starting);

                if (!connectResult)
                {
                    throw new Exception("Unable to connect.");
                }

                var authResult = await rcon.Login(RandomRCONPassword);

                //Once we're connected, the application can transition to the Ready state - even if auth failed (but this stops the console being usable)
                if (connectResult && authResult)
                {
                    PostMessage("chat.serverlog true");
                    module.log.Info("RCON connection successful.");
                    State = ApplicationState.Ready;
                }
                else
                {
                    module.log.Warning("RCON connection failed, console write unavailable.");
                    State = ApplicationState.Ready;
                }
            }
            catch
            {
                module.log.Warning("RCON connection failed, console write unavailable.");
                State = ApplicationState.Ready;
            }
        }