Пример #1
0
        public async Task InvokesStopMatch()
        {
            var taskCompletionSource = new TaskCompletionSource <bool>();
            var server = new HttpServer(HttpServer.GetNextPort());

            server.Start();

            server.OnRequest += async(Uri endpoint, NameValueCollection headers, Stream stream) =>
            {
                StreamReader reader     = new StreamReader(stream);
                var          jsonString = await reader.ReadToEndAsync();

                var jsonObject = JsonConvert.DeserializeObject <StopMatchCommandPayload>(jsonString);

                Assert.IsTrue(endpoint.PathAndQuery.Contains("stop-match"));
                Assert.AreEqual("matchKey", jsonObject.MatchKey);

                taskCompletionSource.SetResult(true);
            };

            var config = new GameyeClientConfig($"http://127.0.0.1:{server.Port}", "1234");
            var client = new GameyeClient(config);

            var matchConfig = new Dictionary <string, object> {
                { "key", "value" }
            };
            await client.CommandStopMatch("matchKey");

            taskCompletionSource.Task.Wait();
            server.Stop();
        }
Пример #2
0
        public async Task Run()
        {
            var config    = new GameyeClientConfig();
            var client    = new GameyeClient(config);
            var sessionId = Guid.NewGuid().ToString();

            Console.WriteLine($"Creating session with id {sessionId}");

            JObject finalStats            = null;
            IEnumerable <LogLine> allLogs = null;

            client.SessionStore.OnChange += (SessionState state) =>
            {
                session = state.SelectSession(sessionId);
            };

            client.StatisticsStore.OnChange += (StatisticsState state) =>
            {
                finalStats = state.SelectRawStatistics();
            };

            var currentLine = 0;

            client.LogStore.OnChange += (LogState state) =>
            {
                var lastLogs = state.SelectLogsSince(currentLine);
                foreach (var log in lastLogs)
                {
                    Console.WriteLine(log);
                }
                currentLine += lastLogs.Count();

                allLogs = state.SelectAllLogs();
            };

            await client.SubscribeSessionEvents();

            await client.CommandStartMatch(sessionId,
                                           "csgo-dem",
                                           new[] { "frankfurt" },
                                           "bots",
                                           new Dictionary <string, object> {
                { "maxRounds", 2 }
            });

            while (session == null)
            {
                Sleep(10);
            }

            Console.WriteLine($"Got Session at {session.Host}");

            await client.SubscribeStatisticsEvents(sessionId);

            await client.SubscribeLogEvents(sessionId);

            while (session != null)
            {
                Sleep(10);
            }

            File.WriteAllText("Stats.txt", finalStats.ToString());
            File.WriteAllText("Logs.txt", string.Join("", allLogs));

            Console.WriteLine($"Session Destroyed");
        }