public ServerInfoModel GetServerInfo()
        {
            var queryConnection = new QueryConnection
            {
                Host = Settings.CsServerIp,
                Port = Settings.CsServerPort
            };

            try
            {
                queryConnection.Connect();
                var info = queryConnection.GetInfo();

                return(new ServerInfoModel
                {
                    IsAlive = true,
                    PlayersCount = info.Players,
                    Map = info.Map
                });
            }
            catch (Exception e)
            {
                return(new ServerInfoModel
                {
                    IsAlive = false,
                    PlayersCount = 0
                });
            }
        }
        public void TestQuery()
        {
            IQueryConnection conn = new QueryConnection();

            conn.Host = "192.168.100.241";
            conn.Port = 27015;

            conn.Connect();
            var info = conn.GetInfo();

            //var players = conn.GetPlayers();
            //var rules = conn.GetRules();
            //conn.Disconnect();
            Console.WriteLine(info.ToString());
        }
Esempio n. 3
0
        public List <GameServer> GetServers()
        {
            List <GameServer> servers = new List <GameServer>();

            foreach (var server in Servers)
            {
                IQueryConnection query = new QueryConnection();
                query.Host = server.IP;
                query.Port = server.QueryPort;
                query.Connect();
                var info = query.GetInfo();
                server.Status = new GameServerStatus(info.Name, info.Players, info.MaxPlayers, info.Map, info.HasPort ? info.Port.Value : default(int));
                servers.Add(server);
            }

            return(servers);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            IQueryConnection conn = new QueryConnection();

            conn.Host = "127.0.0.1";
            conn.Port = 27015;

            conn.Connect();

            var info = conn.GetInfo();

            Console.WriteLine($"Server info: {info.ToString()}");
            var players = conn.GetPlayers();

            Console.WriteLine($"Current players: {string.Join("; ", players.Players.Select(p => p.Name))}");
            var rules = conn.GetRules();

            Console.WriteLine($"Rules: {string.Join("; ", rules.Rules.Select(r => $"{r.Key}: {r.Value}"))}");
        }
        public void MultipleQueriesTest()
        {
            IQueryConnection conn = new QueryConnection();

            // Exampleserver: ARK VALGUERO Server
            conn.Host = "89.163.146.91";
            conn.Port = 27023;

            conn.Connect();
            var players1 = conn.GetPlayers();
            var players2 = conn.GetPlayers();

            //conn.Disconnect();
            // Console.WriteLine(players1.ToString());
            // Console.WriteLine(players2.ToString());
            // Console.WriteLine(players3.ToString());
            // Console.WriteLine(players4.ToString());
            // Console.WriteLine(players5.ToString());
        }