Пример #1
0
        public ClassicubeServer[] GetAllServers()
        {
            var serverString = GetServers();
            var jsonObj = (JArray)(JToken.Parse(serverString)["servers"]);
            var result = new ClassicubeServer[jsonObj.Count];

            for (var i = 0; i < result.Length; i++) {
                result[i] = new ClassicubeServer {
                    Hash = jsonObj[i]["hash"].Value<string>(),
                    Ip = jsonObj[i]["ip"].Value<string>(),
                    Port = jsonObj[i]["port"].Value<int>(),
                    OnlinePlayers = jsonObj[i]["players"].Value<int>(),
                    MaxPlayers = jsonObj[i]["maxplayers"].Value<int>(),
                    Mppass = jsonObj[i]["mppass"].Value<string>(),
                    Name = jsonObj[i]["name"].Value<string>(),
                    Software = jsonObj[i]["software"].Value<string>(),
                    Uptime = jsonObj[i]["uptime"].Value<int>()
                };
            }

            return result;
        }
Пример #2
0
        public ClassicubeServer GetServerByUrl(string url)
        {
            var serverString = GetServers();
            var jsonObj = (JArray) (JToken.Parse(serverString)["servers"]);
            var mySplits = url.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);

            url = mySplits[mySplits.Length - 1];

            var server = new ClassicubeServer();

            foreach (var item in jsonObj) {
                if (!String.Equals(item["hash"].Value<string>(), url, StringComparison.CurrentCultureIgnoreCase))
                    continue;

                server.Hash = item["hash"].Value<string>();
                server.Ip = item["ip"].Value<string>();
                server.Mppass = item["mppass"].Value<string>();
                server.Port = item["port"].Value<int>();
                server.MaxPlayers = item["maxplayers"].Value<int>();
                server.OnlinePlayers = item["players"].Value<int>();
                server.Software = item["software"].Value<string>();
                server.Uptime = item ["uptime"].Value<int> ();
                break;
            }

            return server;
        }
Пример #3
0
        public ClassicubeServer GetServerInfo(string serverName)
        {
            var serverString = GetServers();
            var jsonObj = (JArray) (JToken.Parse(serverString)["servers"]);
            var server = new ClassicubeServer();

            foreach (var item in jsonObj) {
                if (item["name"].Value<string>().ToLower() != serverName.ToLower())
                    continue;

                server.Hash = item["hash"].Value<string>();
                server.Ip = item["ip"].Value<string>();
                server.Mppass = item["mppass"].Value<string>();
                server.Port = item["port"].Value<int>();
                server.MaxPlayers = item["maxplayers"].Value<int>();
                server.OnlinePlayers = item["players"].Value<int>();
                server.Software = item["software"].Value<string>();
                server.Uptime = item ["uptime"].Value<int> ();
                break;
            }

            return server;
        }