Jump to content

rewriting code... php -> autoit


Didonet
 Share

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":'');

or

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

how to deal with it? :/

Link to comment
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
            client.Receive(bufferRec)
            Return Encoding.ASCII.GetString(bufferRec)
        End Function

how to.. byte.parse?!

Link to comment
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"
Else
    $var = ''
EndIf

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

\x02 = chr(2)

\x0a = chr(10) or @LF

\x00 = chr(0)

Link to comment
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
    Else
        Return $vFalseVal
    EndIf
EndFunc  ;==>_Iif
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...