コード例 #1
0
        public virtual StateGameResult GetState(UserGameParam userGameParam)
        {
            if (string.IsNullOrEmpty(GameServerId))
            {
                GameServerId = userGameParam.GameServerId;
            }
            var result = new StateGameResult();
            var run    = $"cd {Path}/{GameName};" +
                         $"./{GameName} monitor -servicename {GameName}{GameServerId} -port {userGameParam.GamePort};";

            Command.Execute(run);
            var states = Regex.Matches(EscapeUtf8(Command.Result),
                                       @"\r\[\s*(?<value>\w+)\s*\][^\r]*Monitor[^\:\r]+:\s*(?<name>[\w\s]+)[^\r]*\n")
                         .Cast <Match>()
                         .Select(m => new ServerStateModel
            {
                ParameterName  = m.Groups["name"].Value,
                ParameterValue = m.Groups["value"].Value
            }).ToList();

            if (!states.All(o => o.ParameterValue.Equals("OK")))
            {
                result.Succes = false;
                foreach (var st in states)
                {
                    result.ErrorMessage += $"{st.ParameterName}: {st.ParameterValue}\n";
                }
                result.Status = GameHostTypeStatus.Disable;
                return(result);
            }
            result.Status = GameHostTypeStatus.Enable;
            return(result);
        }
コード例 #2
0
ファイル: L4D.cs プロジェクト: Maxusbr/Crytex.GameServers
        public override AdvancedStateGameResult GetAdvancedState(UserGameParam userGameParam)
        {
            var result = base.GetAdvancedState(userGameParam);

            SendConsoleCommand("status", true);
            CloseConsole(userGameParam);
            result        = CreateTableData(result);
            result.Status = result.ServerStates.Any() ? GameHostTypeStatus.Enable : GameHostTypeStatus.Disable;
            return(result);
        }
コード例 #3
0
        public virtual AdvancedStateGameResult GetAdvancedState(UserGameParam userGameParam)
        {
            OpenConsole(userGameParam);
            CollectResiveString = string.Empty;

            var result = new AdvancedStateGameResult {
                Succes = false
            };

            return(result);
        }
コード例 #4
0
        public virtual string CloseConsole(UserGameParam param, string closeCommand = "")
        {
            var run = $"^b d";

            if (Terminal == null || Writer == StreamWriter.Null)
            {
                return("");
            }
            Writer?.WriteLine(run);
            FoundConsoleEnd        = null;
            Terminal.DataReceived += Terminal_DataReceived;
            Writer?.Close(); Writer?.Dispose(); Writer = StreamWriter.Null;
            Terminal?.Close(); Terminal?.Dispose();
            return(CollectResiveString);
        }
コード例 #5
0
        public virtual bool OpenConsole(UserGameParam param, string openCommand = "")
        {
            if (string.IsNullOrEmpty(GameServerId))
            {
                GameServerId = param.GameServerId;
            }
            IDictionary <TerminalModes, uint> termkvp = new Dictionary <TerminalModes, uint>();

            termkvp.Add(TerminalModes.ECHO, 53);
            Terminal = Client.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp);

            var tsc = new TaskCompletionSource <bool>();
            EventHandler <ShellDataEventArgs> lambda = (obj, args) =>
            {
                CollectResiveString += EscapeUtf8(Encoding.UTF8.GetString(args.Data));
                if (FoundConsoleEnd?.IsMatch(CollectResiveString) ?? true)
                {
                    tsc.SetResult(true);
                }
            };

            Terminal.DataReceived += lambda;
            Terminal.DataReceived += Terminal_DataReceived;
            Writer = new StreamWriter(Terminal)
            {
                AutoFlush = true
            };
            if (string.IsNullOrEmpty(openCommand))
            {
                openCommand = $"cd {Path}/{GameName};./{GameName} console -servicename {GameName}{GameServerId} -port {param.GamePort};";
            }
            try
            {
                Writer.WriteLine(openCommand);
                var result = tsc.Task == Task.WhenAny(Task.Delay(TimeSpan.FromSeconds(10)), tsc.Task).Result;
            }
            catch (Exception e)
            {
                Terminal.DataReceived -= lambda;
                return(false);
            }

            Terminal.DataReceived -= lambda;
            return(true);
        }
コード例 #6
0
ファイル: L4D.cs プロジェクト: Maxusbr/Crytex.GameServers
 public override bool OpenConsole(UserGameParam param, string openCommand = "")
 {
     FoundConsoleEnd = new Regex(@"\[" + $"{GameName}{GameServerId}" + @"\].+");
     return(base.OpenConsole(param));
 }