Sign in to follow this  
Followers 0
FreeFry

Communicating with HL Servers through RCon Functions

33 posts in this topic

#1 ·  Posted (edited)

Hi, these are some functions I've made that makes it possible to "command" a half-life/counter-strike server ( basicly any server based on the hl1 engine ) using RCon connections.

Here's an example of how to use it:

_RConCommand("say Hello everyone!", "my_rcon_password", @IPAddress1, 27015, 5000)

Syntax:

_RConCommand("command", "password", "Ipaddress of server", port, timeout in ms)

And ofcourse you must know the rcon password... lol

I also attached a simple test program with gui to use this.

Please leave a comment if you like it, or find any bugs in it, or if you just have a proposal of how to make it better! :whistle:

Edit:

Oh btw. this also includes my _UDPReceiveData and my _UDPSendData functions which makes it easier to send and receive data with the UDP functions

#include <String.au3>

Dim $RConChallengePacket = _HexToString("FFFFFFFF6368616C6C656E67652072636F6E0A00")
Dim $RconCommandPacket_1 = _HexToString("FFFFFFFF72636F6E20")

Func _RConCommand($s_Command, $s_Password, $s_IPAddress, $s_Port = 27015, $i_TimeOut = 5000)
    
    Local $s_Return
    Local $ConnectedSocket = UDPOpen($s_IPAddress, $s_Port)
    Local $RCon_Challenge = _GetRConChallenge($ConnectedSocket, $i_TimeOut)
    
    If @error Then
        If $RCon_Challenge = -1 Then
            SetError(1)
            Return -1
        ElseIf $RCon_Challenge = -2 Then
            SetError(@error)
            Return -2
        EndIf
    EndIf
    
    _UDPSendData($ConnectedSocket, $RconCommandPacket_1 & $RCon_Challenge & " " & $s_Password & " " & $s_Command & " " & Chr(0))
    
    $s_Return = _UDPReceiveData($ConnectedSocket, $i_TimeOut)
    
    $s_Return = StringReplace(StringTrimRight(StringTrimLeft($s_Return, 5), 3), @LF, @CRLF)

    UDPCloseSocket($ConnectedSocket)
    
    Return $s_Return
    
EndFunc

Func _GetRConChallenge($o_Socket, $v_TimeOut = 5000)
    
    Local $s_Return
    
    _UDPSendData($o_Socket, $RConChallengePacket)
    
    $s_Return = _UDPReceiveData($o_Socket, $v_TimeOut)
    
    If @error Then
        If $s_Return = -1 Then
            SetError(1)
            Return -1
        ElseIf $s_Return = -2 Then
            SetError(@error)
            Return -2
        EndIf
    EndIf
    
    $s_Return = StringTrimRight(StringTrimLeft($s_Return, 19), 2)
    
    Return $s_Return
    
EndFunc

Func _UDPReceiveData($o_Socket, $m_TimeOut = 5000, $s_BufferSize = 999)
    
    Local $r_data
    Local $t_Handle = TimerInit()
    
    Do
        
        $r_data = UDPRecv($o_Socket, $s_BufferSize)
        
    Until $r_data <> "" Or TimerDiff($t_Handle) > $m_TimeOut Or @error
    
    If @error Then
        SetError(@error); Other Error
        Return -2; Other Error
    ElseIf TimerDiff($t_Handle) > $m_TimeOut Then
        SetError(1); Timed Out
        Return -1; Timed Out
    Else
        Return $r_data; No error
    EndIf
    
EndFunc

Func _UDPSendData($o_Socket, $s_Data)
    
    Local $n_Data = UDPSend($o_Socket, $s_Data)
    
    If @error = 1 Then
        SetError(1); Ip-adress error
        Return -1; Ip-adress error
    ElseIf @error = 2 Then
        SetError(2); Port error
        Return -2; Port error
    ElseIf @error Then
        SetError(@error); Other error
        Return -3; Other error
    ElseIf $n_Data > 0 Then
        Return $n_Data; No error
    EndIf
    
EndFunc
Edited by FreeFry

Share this post


Link to post
Share on other sites



:whistle: Fantastic!

Thanks!!!!! ;)


Console Browse: Navigate on the WEB in a textual consoleMultiPing!: Show computer on the lan and/or show the local/remote task, ALL animated!KillaWin: Event executingCryptPage: Crypt your webpage and show only with key

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm delighted to hear that you like it. ^^

Hope you find good use for it, I sure did! :whistle:

I use it for checking if my cs 1.6 server have hanged/crashed, and if it has it restarts it and sends a few "say" commands to the server telling the users on it that it hanged(in case any clients reconnect to the game straight afterwards) ;)

Edited by FreeFry

Share this post


Link to post
Share on other sites

thx a lot !

i've let this project because my lack of knowledge with UDP

i will try to add some function to monitor my CS server (i don't play anymore since i play AutoIt :whistle:)

GG man


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

Hehe this reminds me of my old project, AutoIt HLSW...

Good job and welcome to UDP world

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

thx a lot !

i've let this project because my lack of knowledge with UDP

i will try to add some function to monitor my CS server (i don't play anymore since i play AutoIt ;))

GG man

Hehe good luck, it's not that hard, because the RConCommand functions returns any data the server sends back.

Example:

$Status = _RConCommand("status", "password", "ip,", port)

It would save the output of the status command in the variable $Status :whistle:

Hehe this reminds me of my old project, AutoIt HLSW...

Good job and welcome to UDP world

Okay, I searched for it but couldn't find it :/

Anyways, I wouldn't even touch the UDP protocol with a stick if I didn't have to, lol. I don't like the idea of not knowing if data reached its destination or not. :P

Edited by FreeFry

Share this post


Link to post
Share on other sites

I never released it thats why you didn't find it :whistle: IF you want a copy send me a pm. cheers

Share this post


Link to post
Share on other sites

Ah, that explains it. ;)

Yeah, sound interesting, I'll send you a pm. :whistle:

Share this post


Link to post
Share on other sites

HLSW in autoit ? OMG

please publish it !


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

Hello, I have problems with this old script... When I send any command to my server I get next returned to Edit control of your script: FFFFF39426164206368616C6C656E67652E0

Can you explain me what I'm doing wrong?

Share this post


Link to post
Share on other sites

nice script!!!

/\

||

you didnt saw : Nov 15 2006, 11:55 AM

so start a new topic (in general support forum)!! add script and xplain the error better

Share this post


Link to post
Share on other sites

I saw it... but as far I know packets has not been changed since this date... so that's why I'm asking why it's not working

My prob:

1. I type my rcon password

2. Type in my server IP and port

3. When I try to send any command I get FFFFF39426164206368616C6C656E67652E0 in respond and nothing happends

P.S.: Does this script works for you, c4nm7?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I actually stumbled onto this problem myself recently with (not this) an old script of mine. AutoIt have had it's handling of binary strings changed, and any Binary string is now treated as such.

To actually fix this, you'd just use BinaryToString() to interpret the data the server sends back.

ie. replace the _RConCommand function with this, and it should work:

Func _RConCommand($s_Command, $s_Password, $s_IPAddress, $s_Port = 27015, $i_TimeOut = 5000)
    
    Local $s_Return
    Local $ConnectedSocket = UDPOpen($s_IPAddress, $s_Port)
    Local $RCon_Challenge = _GetRConChallenge($ConnectedSocket, $i_TimeOut)
    
    If @error Then
        If $RCon_Challenge = -1 Then
            SetError(1)
            Return -1
        ElseIf $RCon_Challenge = -2 Then
            SetError(@error)
            Return -2
        EndIf
    EndIf
    
    _UDPSendData($ConnectedSocket, $RconCommandPacket_1 & $RCon_Challenge & " " & $s_Password & " " & $s_Command & " " & Chr(0))
    
    $s_Return = BinaryToString(_UDPReceiveData($ConnectedSocket, $i_TimeOut))
    
    $s_Return = StringReplace(StringTrimRight(StringTrimLeft($s_Return, 5), 3), @LF, @CRLF)

    UDPCloseSocket($ConnectedSocket)
    
    Return $s_Return
    
EndFunc
Edited by FreeFry

Share this post


Link to post
Share on other sites

Hey,

I'd just like to hear how you found these addresses?

And what program did you use? I'd like to create a program alike, for some other games :)

WhOOt

Share this post


Link to post
Share on other sites

For starters I used a packet sniffer then called Etheral - now called WireShark - to sniff the packets, but that was taking to long to figure out what everything was.

So I googled it, and found that valve has a developer page on wikipedia, where the exact format of their packets was laid out. :)

If I may, for which game is it you're trying to do it?

Good luck with your attempt m8 :)

Share this post


Link to post
Share on other sites

Can you remake this for source servers? :)


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

It doesn't work for source servers already?

Share this post


Link to post
Share on other sites

Well...I havn't tried. But your first post said only HL engine.


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

It doesn't work for source servers already?

Why it shouldn't work? I Think you just have to change the string you send to the server, or not?

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I'm not sure if it works for source servers, can't test. :/

Edited by FreeFry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0