Ejemplo n.º 1
0
        private void contextKick_Click(object sender, EventArgs e)
        {
            Player        P       = (Player)(playerListBox.SelectedItem);
            RCON_Response Request = currentServer.Console.rconQuery("kick \"" + P.Name + "\" \"You have been kicked by qRcon\".");

            queryUserFeedback(Request);
        }
Ejemplo n.º 2
0
 private void rconCommandSubmit_Click(object sender, EventArgs e)
 {
     if (rconCommandBox.Text.Length > 0 && currentServer != null)
     {
         RCON_Response Request = currentServer.Console.rconQuery(rconCommandBox.Text.Trim());
         queryUserFeedback(Request);
         rconCommandBox.Text = String.Empty;
     }
 }
Ejemplo n.º 3
0
 private void queryUserFeedback(RCON_Response Request)
 {
     if (Request.Success)
     {
         if (Request.Response.Description != "")
         {
             updateConsoleOutput("=== {0} ===\r\nCurrent: {1}\r\nDefault: {2}\r\n{3}", Request.Response.valueName, Request.Response.Value, Request.Response.defaultValue, Request.Response.Description);
         }
         else
         {
             updateConsoleOutput(Request.Response.Value);
         }
     }
     else
     {
         updateConsoleOutput("Unable to complete rcon request: " + Request.Error);
     }
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public override RCON_Response rconQuery(String queryString)
        {
            RCON_Response Response = new RCON_Response(queryString);

            // prevent accidental flooding
            double timeSinceLastQuery = (int)(DateTime.Now - lastQuery).TotalMilliseconds;

            if (timeSinceLastQuery < 140 && timeSinceLastQuery > 0)
            {
                Thread.Sleep(140 - (int)timeSinceLastQuery);
            }
            lastQuery = DateTime.Now;

            // set up our socket
            rconConnection = new UdpClient();
            rconConnection.Client.SendTimeout    = 2500;
            rconConnection.Client.ReceiveTimeout = 2500;

            if (queryString == "getstatus")
            {
                queryString = String.Format("ÿÿÿÿ {0}", queryString);
            }
            else
            {
                queryString = String.Format("ÿÿÿÿrcon {0} {1}", this.rconPassword, queryString);
            }

            if (queryString.Length > 255)
            {
                Response.Error = RCON_Error.REQUEST_TOO_LONG;
                return(Response);
            }

            if (IP == IPAddress.Loopback)
            {
                Response.Error = RCON_Error.INVALID_IP;
                return(Response);
            }

            Byte[]     queryBytes = getRequestBytes(queryString);
            IPEndPoint endPoint   = new IPEndPoint(IP, Port);
            DateTime   startTime  = DateTime.Now;

            try
            {
                rconConnection.Connect(endPoint);
            }
            catch (ObjectDisposedException)
            {
                Response.Error = RCON_Error.CONNECTION_TERMINATED;
                return(Response);
            }
            catch (SocketException)
            {
                Response.Error = RCON_Error.REQUEST_TIMED_OUT;
                return(Response);
            }

            rconConnection.Send(queryBytes, queryBytes.Length);

            StringBuilder incomingString = new StringBuilder();

            byte[] bufferRecv = new byte[ushort.MaxValue];
ignoreException:
            try
            {
                do
                {
                    bufferRecv = rconConnection.Receive(ref endPoint);
                    incomingString.Append(Encoding.ASCII.GetString(bufferRecv, 0, bufferRecv.Length));
                } while (rconConnection.Available > 0);
            }

            catch (SocketException E)
            {
                if (E.SocketErrorCode == SocketError.ConnectionReset)
                {
                    Response.Error = RCON_Error.CONNECTION_TERMINATED;
                }
                else if (E.SocketErrorCode == SocketError.TimedOut)
                {
                    Response.Error = RCON_Error.REQUEST_TIMED_OUT;
                }
                else
                {
                    goto ignoreException;
                }
                return(Response);
            }

            String[] splitResponse = stripColors(incomingString.ToString()).Split(new char[] { (char)10 }, StringSplitOptions.RemoveEmptyEntries);

            if (splitResponse.Length == 4)
            {
                Response.Response.Description = splitResponse[2].Trim();
                String[] splitValue = splitResponse[1].Split('\"');
                if (splitValue.Length == 7)
                {
                    Response.Response.Value        = splitValue[3];
                    Response.Response.defaultValue = splitValue[5];
                }
            }

            else if (splitResponse.Length == 3)
            {
                Response.Response.Value = splitResponse[1];
            }

            else if (splitResponse.Length == 2)
            {
                Response.Response.Value = "Command Sent";
            }

            else
            {
                Response.Response.Value = stripColors(incomingString.ToString()).Substring(10);
            }
            Response.responseTime = (int)(DateTime.Now - startTime).TotalMilliseconds;
            if (Response.Response.Value.Contains("Invalid password."))
            {
                Response.Error = RCON_Error.INVALID_PASSWORD;
                return(Response);
            }

            Response.Error   = RCON_Error.REQUEST_COMPLETE;
            Response.Success = true;

            rconConnection.Close();
            rconConnection = null;
            return(Response);
        }
Ejemplo n.º 6
0
        protected Dictionary <String, String> rconQueryDict(String queryString)
        {
            Dictionary <String, String> serverInfo = new Dictionary <String, String>();
            RCON_Response Resp = rconQuery(queryString);

            if (!Resp.Success)
            {
                (mainWindow.ActiveForm as mainWindow).rconCommandResponse.AppendText("There was an error processing your command: " + Resp.Error + "\r\n");
            }
            else
            {
                if (queryString.Contains("dumpuser"))
                {
                    String[] initialSplit = Resp.Response.Value.Split(new char[] { (char)10 }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (String S in initialSplit)
                    {
                        String[] clientInfo = S.Split(new char[] { ' ', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (clientInfo.Length > 1)
                        {
                            StringBuilder cName = new StringBuilder();
                            for (int i = 1; i < clientInfo.Length; i++)
                            {
                                if (clientInfo [i].Length > 0)
                                {
                                    cName.Append(clientInfo [i]);
                                }
                            }

                            serverInfo.Add(clientInfo[0], cName.ToString());
                        }
                    }
                }
                else
                {
                    String[] initialSplit = Resp.Response.Value.Split(new char[] { (char)10 }, StringSplitOptions.RemoveEmptyEntries);
                    String[] Responses;
                    if (initialSplit.Length == 0)
                    {
                        return(serverInfo);
                    }
                    else if (initialSplit.Length == 1)
                    {
                        Responses = initialSplit[0].Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    else
                    {
                        Responses = initialSplit[1].Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                    }

                    for (int i = 0; i < Responses.Length; i += 2)
                    {
                        serverInfo.Add(Responses[i], Responses[i + 1]);
                    }

                    if (queryString == "getstatus")
                    {
                        if (initialSplit.Length > 1)
                        {
                            String[] player = new String[initialSplit.Length - 3];

                            for (int i = 2; i < initialSplit.Length - 1; i++)
                            {
                                player[i - 2] = initialSplit[i];
                            }

                            serverInfo.Add("Players", String.Join(",", player));
                        }

                        else
                        {
                            serverInfo.Add("Players", "");
                        }
                    }
                }
            }
            return(serverInfo);
        }
Ejemplo n.º 7
0
        private void setSettingsButton_Click(object sender, EventArgs e)
        {
            if (currentServer == null)
            {
                return;
            }

            List <String> rconCommands = new List <String>();
            String        newMap       = String.Empty;

            if (timeLimitBox.Text.Length > 0)
            {
                int timeLimit = -1;
                if (Int32.TryParse(timeLimitBox.Text, out timeLimit))
                {
                    rconCommands.Add("scr_" + currentServer.Gametype + "_timelimit " + timeLimit);
                }
                else
                {
                    updateConsoleOutput("Ignoring invalid entry \"{0}\" for timelimit", timeLimitBox.Text);
                }
            }

            if (modBox.Text.Length > 0)
            {
                rconCommands.Add("fs_game \"mods/" + modBox.Text + "\"");
            }

            if (passwordBox.Text.Length > 0)
            {
                rconCommands.Add("g_password \"" + passwordBox.Text + "\"");
            }

            if (gametypeSelectionBox.SelectedItem != null)
            {
                Gametype Selected = (Gametype)gametypeSelectionBox.SelectedItem;
                rconCommands.Add("g_gametype \"" + Selected.Name + "\"");
            }

            if (mapSelectionBox.SelectedItem != null)
            {
                Map desiredMap = (Map)mapSelectionBox.SelectedItem;
                newMap = desiredMap.Name;
            }

            if (ffCheckBox.Checked)
            {
                rconCommands.Add("scr_team_fftype 2");
            }
            else
            {
                rconCommands.Add("scr_team_fftype 0");
            }

            if (hardcoreCheckBox.Checked)
            {
                rconCommands.Add("g_hardcore 1");
            }
            else
            {
                rconCommands.Add("g_hardcore 0");
            }

            foreach (String Command in rconCommands)
            {
                RCON_Response Request = currentServer.Console.rconQuery(Command);
                queryUserFeedback(Request);
            }

            if (newMap == String.Empty)
            {
                currentServer.Console.rconQuery("fast_restart");
            }
            else
            {
                currentServer.Console.rconQuery("map \"" + newMap + "\"");
            }

            updateConsoleOutput("Finished applying game settings.");
        }
Ejemplo n.º 8
0
 private void queryUserFeedback(RCON_Response Request)
 {
     if (Request.Success)
     {
         if (Request.Response.Description != "")
             updateConsoleOutput("=== {0} ===\r\nCurrent: {1}\r\nDefault: {2}\r\n{3}", Request.Response.valueName, Request.Response.Value, Request.Response.defaultValue, Request.Response.Description);
         else
             updateConsoleOutput(Request.Response.Value);
     }
     else
         updateConsoleOutput("Unable to complete rcon request: " + Request.Error);
 }
Ejemplo n.º 9
0
        public override RCON_Response rconQuery(String queryString)
        {
            RCON_Response Response = new RCON_Response(queryString);

            // prevent accidental flooding
            double timeSinceLastQuery = (int)(DateTime.Now - lastQuery).TotalMilliseconds;
            if (timeSinceLastQuery < 140 && timeSinceLastQuery > 0)
                Thread.Sleep(140 - (int)timeSinceLastQuery);
            lastQuery = DateTime.Now;

            // set up our socket
            rconConnection = new UdpClient();
            rconConnection.Client.SendTimeout = 2500;
            rconConnection.Client.ReceiveTimeout = 2500;

            if (queryString == "getstatus")
                queryString = String.Format("ÿÿÿÿ {0}", queryString);
            else
                queryString = String.Format("ÿÿÿÿrcon {0} {1}", this.rconPassword, queryString);

            if (queryString.Length > 255)
            {
                Response.Error = RCON_Error.REQUEST_TOO_LONG;
                return Response;
            }

            if (IP == IPAddress.Loopback)
            {
                Response.Error = RCON_Error.INVALID_IP;
                return Response;
            }

            Byte[] queryBytes = getRequestBytes(queryString);
            IPEndPoint endPoint = new IPEndPoint(IP, Port);
            DateTime startTime = DateTime.Now;

            try
            {
                rconConnection.Connect(endPoint);
            }
            catch (ObjectDisposedException)
            {
                Response.Error = RCON_Error.CONNECTION_TERMINATED;
                return Response;
            }
            catch (SocketException)
            {
                Response.Error = RCON_Error.REQUEST_TIMED_OUT;
                return Response;
            }

            rconConnection.Send(queryBytes, queryBytes.Length);

            StringBuilder incomingString = new StringBuilder();
            byte[] bufferRecv = new byte[ushort.MaxValue];
            ignoreException:
            try
            {
                do
                {
                    bufferRecv = rconConnection.Receive(ref endPoint);
                    incomingString.Append(Encoding.ASCII.GetString(bufferRecv, 0, bufferRecv.Length));
                } while (rconConnection.Available > 0);
            }

            catch (SocketException E)
            {
                if (E.SocketErrorCode == SocketError.ConnectionReset)
                    Response.Error = RCON_Error.CONNECTION_TERMINATED;
                else if (E.SocketErrorCode == SocketError.TimedOut)
                    Response.Error = RCON_Error.REQUEST_TIMED_OUT;
                else
                    goto ignoreException;
                return Response;
            }

            String[] splitResponse = stripColors(incomingString.ToString()).Split(new char[] { (char)10 }, StringSplitOptions.RemoveEmptyEntries);

            if (splitResponse.Length == 4)
            {
                Response.Response.Description = splitResponse[2].Trim();
                String[] splitValue = splitResponse[1].Split('\"');
                if (splitValue.Length == 7)
                {
                    Response.Response.Value = splitValue[3];
                    Response.Response.defaultValue = splitValue[5];
                }
            }

            else if (splitResponse.Length == 3)
            {
                Response.Response.Value = splitResponse[1];
            }

            else if (splitResponse.Length == 2)
            {
                Response.Response.Value = "Command Sent";
            }

            else
                Response.Response.Value = stripColors(incomingString.ToString()).Substring(10);
            Response.responseTime = (int)(DateTime.Now - startTime).TotalMilliseconds;
            if (Response.Response.Value.Contains("Invalid password."))
            {
                Response.Error = RCON_Error.INVALID_PASSWORD;
                return Response;
            }

            Response.Error = RCON_Error.REQUEST_COMPLETE;
            Response.Success = true;

            rconConnection.Close();
            rconConnection = null;
            return Response;
        }