示例#1
1
文件: Server.cs 项目: RaidMax/qRCON
 public Server(String H, int P, int mP, String G, String M, Player[] Players, ILocalization Localization, String Mapname, RCON Con)
 {
     Hostname = stripColors(H);
     currentPlayers = P;
     maxPlayers = mP;
     Gametype = G;
     Mod = stripColors(M);
     this.Players = Players;
     this.Localization = Localization;
     Console = Con;
     Map = Mapname;
     MapList = Localization.getAvailableMaps();
     gametypeList = Localization.getAvailableGametypes();
 }
示例#2
0
        public static List <RCON> loadSavedServers()
        {
            List <RCON> savedServers = new List <RCON>();

            foreach (String filePath in Directory.GetFiles(Directory.GetCurrentDirectory()))
            {
                if (!filePath.Contains(".ss"))
                {
                    continue;
                }

                Stream curFile = File.Open(filePath, FileMode.Open);
                var    Format  = new BinaryFormatter();
                try
                {
                    RCON newServer = (RCON)Format.Deserialize(curFile);
                    curFile.Close();
                    savedServers.Add(newServer);
                }

                catch (Exception)
                {
                    curFile.Close();
                    continue;
                }
            }
            return(savedServers);
        }
示例#3
0
 public override bool Equals(Object obj)
 {
     if (obj.GetType().IsAssignableFrom(this.GetType()))
     {
         RCON ob = (RCON)obj;
         return(ob.IP == this.IP && ob.Port == this.Port);
     }
     return(false);
 }
示例#4
0
 public Server(String H, int P, int mP, String G, String M, Player[] Players, ILocalization Localization, String Mapname, RCON Con)
 {
     Hostname          = stripColors(H);
     currentPlayers    = P;
     maxPlayers        = mP;
     Gametype          = G;
     Mod               = stripColors(M);
     this.Players      = Players;
     this.Localization = Localization;
     Console           = Con;
     Map               = Mapname;
     MapList           = Localization.getAvailableMaps();
     gametypeList      = Localization.getAvailableGametypes();
 }
示例#5
0
        private Server getServerInfo(RCON R)
        {
            Dictionary <String, String> getStatus = R.getStatus();
            RCON_Response maxPlayers = R.rconQuery("sv_maxclients");
            RCON_Response fs_game    = R.rconQuery("fs_game");

            if (getStatus.Count > 0 && maxPlayers.Success && fs_game.Success)
            {
                Player[] playerList = new Player[Int32.Parse(maxPlayers.Response.Value)];

                int count = 0;
                foreach (String S in getStatus["Players"].Split(','))
                {
                    if (S.Length > 0)
                    {
                        String[] eachPlayers     = S.Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);
                        String[] eachPlayerScore = eachPlayers[0].Split(' ');
                        Player   newPlayer       = new Player(eachPlayers[1], Int32.Parse(eachPlayerScore[1]), Int32.Parse(eachPlayerScore[0]), count);
                        playerList[count] = newPlayer;
                        count++;
                    }
                }

                Server newServer = new Server(getStatus["sv_hostname"], count, Int32.Parse(maxPlayers.Response.Value), getStatus["g_gametype"], fs_game.Response.Value, playerList, LocalizationType.Get(getStatus["gamename"]), getStatus["mapname"], R);
                refreshServerInfo(newServer);
                updateConsoleOutput("[" + maxPlayers.responseTime + "ms] Successfully updated server: " + newServer.Hostname);
                return(newServer);
            }

            else if (currentServer == null)
            {
                if (maxPlayers.Error == RCON_Error.REQUEST_TIMED_OUT)
                {
                    MessageBox.Show("Timed out trying to connect to the server.\nPerhaps it is offline or no RCON password is set.");
                }
                else
                {
                    queryUserFeedback(maxPlayers);
                }
            }

            return(null);
        }
示例#6
0
        private Server getServerInfo(RCON R)
        {
            Dictionary<String, String> getStatus = R.getStatus();
            RCON_Response maxPlayers = R.rconQuery("sv_maxclients");
            RCON_Response fs_game = R.rconQuery("fs_game");

            if (getStatus.Count > 0 && maxPlayers.Success && fs_game.Success)
            {
                Player[] playerList = new Player[Int32.Parse(maxPlayers.Response.Value)];

                int count = 0;
                foreach (String S in getStatus["Players"].Split(','))
                {
                    if (S.Length > 0)
                    {
                        String[] eachPlayers = S.Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);
                        String[] eachPlayerScore = eachPlayers[0].Split(' ');
                        Player newPlayer = new Player(eachPlayers[1], Int32.Parse(eachPlayerScore[1]), Int32.Parse(eachPlayerScore[0]), count);
                        playerList[count] = newPlayer;
                        count++;
                    }
                }

                Server newServer = new Server(getStatus["sv_hostname"], count, Int32.Parse(maxPlayers.Response.Value), getStatus["g_gametype"], fs_game.Response.Value, playerList, LocalizationType.Get(getStatus["gamename"]), getStatus["mapname"], R);
                refreshServerInfo(newServer);
                updateConsoleOutput("[" + maxPlayers.responseTime + "ms] Successfully updated server: " + newServer.Hostname);
                return newServer;
            }

            else if (currentServer == null)
                if (maxPlayers.Error == RCON_Error.REQUEST_TIMED_OUT)
                    MessageBox.Show("Timed out trying to connect to the server.\nPerhaps it is offline or no RCON password is set.");
            else
                queryUserFeedback(maxPlayers);

            return null;
        }