Jump to content
Sign in to follow this  

rewriting code... php -> autoit

Recommended Posts


Hi all.. I'm having a program that connects to a game server console (RCON) and I'm trying to rewrite the code from php to autoit. There's the problem. In php I've got one string.. that's send to the server (i think is hex). The part of the code that I can't rewrite is:

$send = "\xff\xff\xff\xff\x02" . 'rcon "' . $server_rconpass . '" '.$cmd.(($server_extra_footer)?"\x0a\x00":'');


$send = "\xFF\xFF\xFF\xFFgetstatus\x00";

how to deal with it? :/

Share this post

Link to post
Share on other sites

I have the solution on VB also...

here is it...

Public Function sendCommand(ByVal rconCommand As String, ByVal gameServerIP As String, ByVal password As String, ByVal gameServerPort As Integer) As String
            On Error Resume Next

            'connecting to server
            Dim client As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
            client.Connect(IPAddress.Parse(gameServerIP), gameServerPort)

            Dim command As String
            command = "rcon " & password & " " & rconCommand
            Dim bufferTemp() As Byte = Encoding.ASCII.GetBytes(command)
            Dim bufferSend(bufferTemp.Length + 5 - 1) As Byte

            'intial 5 characters as per standard
            bufferSend(0) = Byte.Parse("255")
            bufferSend(1) = Byte.Parse("255")
            bufferSend(2) = Byte.Parse("255")
            bufferSend(3) = Byte.Parse("255")
            bufferSend(4) = Byte.Parse("02")
            Dim j As Integer = 5

            For i As Integer = 0 To bufferTemp.Length - 1
                bufferSend(j) = bufferTemp(i)
                j += 1
            Next i

            'send rcon command and get response
            Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
            client.Send(bufferSend, SocketFlags.None)

            'big enough to receive response
            Dim bufferRec(64999) As Byte
            Return Encoding.ASCII.GetString(bufferRec)
        End Function

how to.. byte.parse?!

Share this post

Link to post
Share on other sites

I can't help you because you only posted one line, I need more to understand it but I can give you some advice.

. is same as & in AutoIt to concatenate a string.

the last part with a questionmark is a short IF statement. In AutoIt there is no such thing so use normal if and else.

If ($server_extra_footer) Then
    $var = "\x0a\x00"
    $var = ''

\xff is hex, so \xff = chr(255)

\x02 = chr(2)

\x0a = chr(10) or @LF

\x00 = chr(0)

Share this post

Link to post
Share on other sites

Thanks! I have forgot about the chr() lol...

Share this post

Link to post
Share on other sites

Pain is right, The closest thing to a 'ternary if' is _Iif() from the #Include Misc.au3 (of course you wouldn't want to include the whole Misc.au3 just for that purpose!)

$string = True
$hello = "Hello world; " & _Iif($string, "Yes, really", "Not really")
;similar to $hello = "Hello world; " & $string ? "Yes, really!" : "Not really!"

MsgBox(0, "", $hello)

Func _Iif($fTest, $vTrueVal, $vFalseVal)
    If $fTest Then
        Return $vTrueVal
        Return $vFalseVal
EndFunc  ;==>_Iif

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

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