Exemplo n.º 1
0
 private Server getServer(string IP, int port, bool responded, bool info)
 {
     var servers = _servers;
     if (responded)
         servers = _respondedServers;
     if (info)
         servers = _infoServers;
     var server = new Server();
     for(int i = 0; i < servers.Count; i++)
     {
         if (servers[i].IP == IP && servers[i].Port == port)
         {
             server = servers[i];
             break;
         }
     }
     return server;
 }
Exemplo n.º 2
0
 private void parseQuery(string data, string ip, int ping)
 {
     var strData = data.Substring(4).Split('\n');
     if (strData[0].StartsWith("disconnect"))
         throw new System.ArgumentException("Data is disconnect!");
     else if (string.IsNullOrEmpty(strData[0]))
         throw new System.ArgumentNullException("Data is empty!");
     else if (strData[0].StartsWith("statusResponse"))
     {
         var dvars = GetParams(strData[1].Split('\\'));
         var players = getPlayers(strData);
         Server server = new Server();
         server.IP = ip.Split(':')[0];
         server.Port = int.Parse(ip.Split(':')[1]);
         server.Players = players;
         server.Dvars = dvars;
         server.Ping = ping;
         _respondedServers.Add(server);
         //Thread.Sleep(100);
         getInfo(server);
     }
     else if (strData[0].StartsWith("infoResponse"))
     {
         Queue queue = Queue.Synchronized(_updateQueue);
         var dvars = GetParams(strData[1].Split('\\'));
         var server = getServer(ip.Split(':')[0], int.Parse(ip.Split(':')[1]), true, false);
         if (string.IsNullOrEmpty(server.IP))
             return;
         server.InfoDvars = dvars;
         if (server.Ping == 0 && ping == 0)
             server.Ping = 999;
         else if (server.Ping == 0 && ping != 0)
             server.Ping = ping;
         _infoServers.Add(server);
         if (checkFilter(server))
             //addItem(prepareItem(server));
             queue.Enqueue(prepareItem(server));
     }
 }
Exemplo n.º 3
0
 private void displayData(Server server)
 {
     listViewPlayers.Items.Clear();
     listViewDvars.Items.Clear();
     foreach (var pair in server.Dvars)
     {
         var item = listViewDvars.Items.Add(pair.Key);
         item.SubItems.Add(pair.Value);
     }
     foreach (var player in server.Players)
     {
         var item = listViewPlayers.Items.Add(removeQuakeColorCodes(player.Name));
         item.SubItems.Add(player.Score.ToString());
         item.SubItems.Add(player.Ping.ToString());
     }
 }
Exemplo n.º 4
0
 private bool checkFilter(Server server)
 {
     var dvars = server.Dvars;
     var info = server.InfoDvars;
     var players = server.Players;
     var namefilter = _filter.ServerName;//getControlText(nameFilter, ControlType.Textbox);
     var mapfilter = _filter.Map;//getControlText(mapFilter, ControlType.Combobox);
     var typefilter = _filter.GameType;//getControlText(typeFilter, ControlType.Combobox);
     var playerfilter = _filter.PlayerName;//getControlText(playerFilter, ControlType.Textbox);
     var modfilter = _filter.Mod;//getControlText(modFilter, ControlType.Combobox);
     if (removeQuakeColorCodes(dvars["sv_hostname"]).ToUpper().IndexOf(namefilter.ToUpper()) > -1)
         if (_mapNames[mapfilter] == dvars["mapname"] || mapfilter == "Any")
             if (_gameType[typefilter] == dvars["g_gametype"] || typefilter == "Any")
                 if (containsPlayer(players, playerfilter))
                     if (isHardcore(dvars["g_hardcore"], _filter.HC))
                         if (checkFull(info["clients"], getTrueMaxClients(new string[] { getValue(info, "shortversion"), dvars["sv_maxclients"], dvars["sv_privateClients"] } ), _filter.Full))
                             if (checkEmpty(info["clients"], _filter.Empty))
                                 if (check03(getValue(info, "shortversion"), _filter.v03))
                                     if (checkMod(getValue(dvars, "fs_game"), modfilter))
                                         return true;
     return false;
 }
Exemplo n.º 5
0
 private void readFav()
 {
     if (File.Exists("favourites.txt"))
     {
         var lines = File.ReadAllLines("favourites.txt");
         foreach (var line in lines)
         {
             try
             {
                 if (line.StartsWith("//"))
                     continue;
                 if (string.IsNullOrEmpty(line))
                     continue;
                 if (line.Split(':').Length != 2)
                     continue;
                 var server = new Server();
                 server.IP = line.Split(':')[0];
                 server.Port = int.Parse(line.Split(':')[1]);
                 _servers.Add(server);
             }
             catch
             {
             }
         }
     }
     else
     {
         File.Create("favourites.txt");
         MessageBox.Show("favourites.txt was not found, resetting to default 0 servers", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Exemplo n.º 6
0
 private string[] prepareItem(Server server)
 {
     var data = new string[7];
     data[0] = removeQuakeColorCodes(server.Dvars["sv_hostname"]);
     data[1] = server.IP + ":" + server.Port.ToString();
     data[2] = mapName(server.Dvars["mapname"]);
     data[3] = getPlayerString(new string[] { server.InfoDvars["clients"], server.Dvars["sv_maxclients"], server.Dvars["sv_privateClients"], getValue(server.InfoDvars, "shortversion") });
     data[4] = gameType(server.Dvars["g_gametype"]);
     data[5] = getValue(server.Dvars, "fs_game");
     if (data[5].StartsWith("mods"))
         data[5] = data[5].Substring(5);
     data[6] = server.Ping.ToString();
     return data;
 }
Exemplo n.º 7
0
 private void parseResponse(byte[] data)
 {
     var strData = Encoding.UTF7.GetString(data).Substring(4).Split('\\');
     for (int i = 0; i < strData.Length; i++)
     {
         if (strData[i].Contains("serverresponse"))
             continue;
         else if (strData[i].Contains("EOT"))
             break;
         else
         {
             var ip = new int[6];
             var port = 0;
             if (strData[i] != "")
             {
                 if (strData[i].Length == 6)
                 {
                     for (int h = 0; h < strData[i].Length; h++)
                         ip[h] = (int)strData[i][h];
                     port = (256 * ip[4] + ip[5]);
                     Server server = new Server(string.Format("{0}.{1}.{2}.{3}", ip[0], ip[1], ip[2], ip[3]), port);
                     _servers.Add(server);
                 }
             }
             if (strData[i] == "")
                 strData[i + 1] = strData[i] + "\\" + strData[i + 1];
         }
     }
 }