Little C# RCON Tool


(Mistery) #1

Hey guys :wink:

I am trying to create a little RCON tool for Enemy Territory using C#.
So i started a new console application project in VS and wrote this RCON class


class rcon
    {

// DECLARATION
        private Socket srvCON;
        private IPAddress srvIP;

        private int srvPORT;
        private string srvRPW;
        private string srvRCMD;

        private List<byte> bytes = new List<byte>();

// CONSTRUCTOR
        public rcon(string IP, string PORT)
        {
            srvIP = IPAddress.Parse(IP);
            srvPORT = int.Parse(PORT);

            srvCON = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            srvCON.Connect(srvIP, srvPORT);
        }

// METHOD
        public void cmdSend(string PW, string CMD)
        {
            srvRPW = PW;
            srvRCMD = CMD;

            srvRCMD = string.Format("rcon {0} {1}", srvRPW, srvRCMD);

            for (int i = 0; i < 4; i++)
                bytes.Add((byte)255);
            foreach (char c in srvRCMD)
            {
                bytes.Add((byte)c);
            }

            byte[] send = new byte[bytes.Count];
            for (int i = 0; i < bytes.Count; i++)
                send[i] = bytes[i];

            srvCON.Send(send, SocketFlags.None);
        }
    }

In main i use it with:


            rcon rcon = new rcon("00.00.00.00","27960");//(string IPAdress, sting PORT)
            rcon.cmdSend("pw", "[B][U]restart[/U][/B]");//(string RCONPW, string RCONCMD)

WORKS FINE! The server restarts …

But if i want to change the map.


            rcon rcon = new rcon("00.00.00.00","27960");//(string IPAdress, sting PORT)
            rcon.cmdSend("pw", "[B][U]map oasis[/U][/B]");//(string RCONPW, string RCONCMD)

The server will only receive “map” without " oasis" :confused:
Does anyone got an idea how to “fix” this?

Would be great! :wink:

Thanks in advance and greetings,
M!$T3rY


(Indloon) #2

Maybe this …


rcon.cmdSend("pw", "[B][U]map\u0020oasis[/U][/B]");//(string RCONPW, string RCONCMD)


(Mistery) #3

Does not seem to work, same problem.

ETDED.exe output :

Rcon from xxx.xxx.xxx.xxx:xxxxx:
map

It looks like the server is cutting the command, hmmmm …


(Indloon) #4

[QUOTE=Mistery;406269]Does not seem to work, same problem.

ETDED.exe output :

Rcon from xxx.xxx.xxx.xxx:xxxxx:
map

It looks like the server is cutting the command, hmmmm …[/QUOTE]

Can’t be, lol! :smiley:

Are you sure, that the program itself isn’t ending the command sentence after space?


(Mistery) #5

I am not sure but i shouldn’t :confused:


public void cmdSend(string PW, string CMD)
        {
            srvRPW = PW;
            srvRCMD = CMD;

            srvRCMD = string.Format("rcon {0} {1}", srvRPW, srvRCMD); 
// the space between rcon and srvRPW and srvRPW and svrRCMD works

            for (int i = 0; i < 4; i++)
                bytes.Add((byte)255);
// this tells ETDED.exe that someone is sending a rcon command

            foreach (char c in srvRCMD)
            {
                bytes.Add((byte)c);
            }
// this should convert the whole srvRCMD string to bytes

            byte[] send = new byte[bytes.Count];
            for (int i = 0; i < bytes.Count; i++)
                send[i] = bytes[i];

            srvCON.Send(send, SocketFlags.None);
        }

EDIT: Maybe i have to add special bytes at the end of the command?

Like in this PHP-Script:


 $cmdinput = "\xFF\xFF/rcon\x00". $command . "\x00\x00"; //Input command: /rcon <command>


(Mistery) #6

OMG … OK … it works, sorry! ^^


Rcon from xxx.xxx.xxx.xxx:xxxxx:
map

is just the response of the console.


(Smurfer) #7

maybe you need a " {2} " ? Make it accept one more srvRCMD somehow?

I mean
{0} password
{1} map
{2} oasis


(Mistery) #8

Yes should work too :wink:


(Domagoj) #9

well I hope you will post your program here after youre finished creating it :smiley:


(Nail) #10

(Domagoj) #11

thanks man!


(acQu) #12

Here a little c version of the rcon tool. If there is additional functionality i should add (only basic commands i mean :)), then post.

Note: this is only for linu, windows not planned. Should work on all linux versions.

EDIT 1000 posts whohoo :smiley: