Sign in to follow this  
Followers 0
JRSmile

Minecraft EmuServer

36 posts in this topic

Hello There,

i want to create a little Minecraft 1.1 server which is capable of using the Minecraft client as GUI for AutoIT to do homeautomation.

this is what i have so far.

#NoTrayIcon
#include "TCP.au3"
ToolTip("SERVER: Creating server...", 10, 30)
$hServer = _TCP_Server_Create(25565); A MineCraftServer. Tadaa!
_TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient")
_TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect")
_TCP_RegisterEvent($hServer, $TCP_RECEIVE, "Received")
While 1
WEnd
Func NewClient($hSocket, $iError)
ToolTip("SERVER: New client connected.", 10, 30)
EndFunc   ;==>NewClient
Func Disconnect($hSocket, $iError)
ToolTip("SERVER: Client disconnected.", 10, 30)
EndFunc   ;==>Disconnect
Func Received($hSocket, $sReceived, $iError)
ConsoleWrite(">| " & Binary($sReceived) & @CRLF)
Protocol(Binary($sReceived),$hSocket)
EndFunc   ;==>Disconnect
Func Protocol($stream,$hSocket)
switch StringLeft($stream,4)
  Case 0xFE
   ConsoleWrite("+| Server List Ping" & @CRLF)
   _TCP_Send($hSocket, 0xFF)
  Case 0x02
   $username = BinaryToString("0x" & StringTrimLeft($stream,8),3) ; all strings are UCS-2 encoded which is luckily the same as UTF-16 BigEndian.
   ConsoleWrite("+| Handshake by " & $username & @CRLF)
   _TCP_Send($hSocket, "0x020001002D") ; StringToBinary("-",3)
  case Else
   ConsoleWrite("!| Unknown Packet!" & @CRLF)
   _TCP_Send($hSocket, 0xFF)
EndSwitch
EndFunc

It uses the from Kip.

as you can see it's not very much, the minecraft client recognices the server as online and can connect to it.

As of the Server Protocol specs http://wiki.vg/Protocol i have to send a Handshake reply to the client in order to proceed.

the specs say i have to send the packetid which is 0x02 for Handshake then the length of the string which would be 1 char because i don't use authentification and the a "-" (minus) in UTF-16 BigEndian.

But it Doesn't work, either autoit can't send HEX values longer then 8 i think or i have to send it as string which is bad to for the client.

Can' somebody explain to me how i can send it the correct way, or tell me a bit about binary analyses?

I don't think that doing a stringleft with binary is the right way but i can't figure out the correct one.

Best regards,

J.


$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ok, did some progress, the handshake is working ....

still no clue how to do binary stuff correctly.

and hanging on the Login Request Reply...

in addition from Ward is beeing used to compress chunk data for the Client, some how.

#NoTrayIcon
#include "TCP.au3"
#Include "ZLIB.au3"

; >>>>>>>>>> http://wiki.vg/Protocol

ToolTip("SERVER: Creating server...", 10, 30)
$hServer = _TCP_Server_Create(25565); A MineCraftServer. Tadaa!

_TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient")
_TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect")
_TCP_RegisterEvent($hServer, $TCP_RECEIVE, "Received")
While 1

WEnd

Func NewClient($hSocket, $iError)
    ToolTip("SERVER: New client connected.", 10, 30)
EndFunc   ;==>NewClient

Func Disconnect($hSocket, $iError)
    ToolTip("SERVER: Client disconnected.", 10, 30)
EndFunc   ;==>Disconnect

Func Received($hSocket, $sReceived, $iError)
    ConsoleWrite(">| " & Binary($sReceived) & @CRLF)
    Protocol(Binary($sReceived),$hSocket)
EndFunc   ;==>Disconnect

Func Protocol($stream,$hSocket)
    switch StringLeft($stream,4)
        Case 0xFE
            ConsoleWrite("+| Server List Ping" & @CRLF)
            _TCP_Send($hSocket, 0xFF)
        Case 0x02
            $username = BinaryToString("0x" & StringTrimLeft($stream,8),3) ; all strings are UCS-2 encoded which is luckily the same as UTF-16 BigEndian.
            ConsoleWrite("+| Handshake by " & $username & @CRLF)
            _TCP_Send($hSocket, "0x020001002D") ; StringToBinary("-",3)
        case 0x01
            $loginname = BinaryToString("0x" & StringTrimLeft($stream,16),3)
            ConsoleWrite("+| Login Request by " & $loginname & @CRLF)
            _TCP_Send($hSocket, "0x0100000148000060440b732bf1f642000000000001801406fffffbd600000040000001ef0400000000003fbb1503000800a7003500a7003600a7003400a70035") ; Login accepted
            _TCP_Send($hSocket, "0x05") ; Entity Equipment (Head,Body,pants,boots) ;EntitiyID (int), Slot 0= Hand 1-4 armor slot (short), Item ID (short), Damaged (short)...
            _TCP_Send($hSocket, "0x32000000001") ; Chunk init
            _TCP_Send($hSocket, "0x330000000000037F03") ; Chunk region data
            _TCP_Send($hSocket, "0x0D00000000000000000000000000000000000000001") ; player pos and Look
        case 0x03
            $message = BinaryToString("0x" & StringTrimLeft($stream,5),3)
            ConsoleWrite("-| Chat: " & $message & @CRLF)
        case Else
            ConsoleWrite("!| Unimplemented Packettype! Player KICKED!" & @CRLF)
            _TCP_Send($hSocket, 0xFF)
    EndSwitch
EndFunc

Func _MC_String($sText)
    Local $iLen = StringLen($sText)
    Local $bLen = Binary("0x" & hex(StringLen($sText),4))
    Local $bText = StringTrimLeft(StringToBinary($sText,3),2)
    Return Binary($bLen & $bText)
EndFunc

;~ Dim $Compressed = _ZLIB_Compress($Original, 9)
;~ Dim $Decompressed = _ZLIB_Uncompress($Compressed)

#cs
What's the normal login sequence for a client?

See Authentication for communication with minecraft.net

    The recommended login sequence looks like this, where C is the client and S is the server:

    C <> S : Connects
    C >  S : Sends handshake
    C <  S : Sends handshake response
    C >  S : After authenticating (if needed), sends the login packet
    C <  S : Either kicks (invalid login) or sends a login response
    C <  S : Sends pre-chunks and chunks and entities
    C <  S : Sends spawn position
    C <  S : Sends inventory [Need to verify this since inventory changed] (beta 1.1_02: looks like Window items with type=0, then a Set slot with window id = -1 and slot = -1)
    C <  S : Tell the client they're ready to spawn by sending a position + look packet. Note: The stance and Y should be swapped when the server sends it to the client (See Protocol Page)!
    C >  S : Sends a position + look packet to confirm the spawn position, with the stance and Y swapped back to the correct positions

I think I've done everything right, but…
…my player isn't spawning!

    After sending the common-sense packets (Handshake, Login, Inventory, Compass and Pre-chunk/Chunk pairs) you need to finally send the player their initial position for them to leave the "Loading Map" screen.

…my client isn't receiving complete map chunks!

    The standard Minecraft server server sends full chunks only when your client is sending player status update packets (any of Player (0x0A) through Player Position & Look (0x0D)).

…all connecting clients spasm and jerk uncontrollably!

    For newer clients, your server needs to send 49 chunks ahead of time, not just one. Send a 7x7 square of chunks, centered on the connecting client's position, before spawning them.
#ce
Edited by JRSmile

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

This looks very nice... keep up the good work :)

Share this post


Link to post
Share on other sites

This thread was reported since it has the word "game" in it. I'm on the fence about this one. On the one hand, yeah, it breaks the rules. On the other hand, I'm fairly sure Notch would be okay with something like this because it's a rather interesting thing. I also think it may be a bit above the heads of anyone who would use it maliciously. So I think I'll let this thread live.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This thread was reported since it has the word "game" in it. I'm on the fence about this one. On the one hand, yeah, it breaks the rules. On the other hand, I'm fairly sure Notch would be okay with something like this because it's a rather interesting thing. I also think it may be a bit above the heads of anyone who would use it maliciously. So I think I'll let this thread live.

Hey Valik,

thanks for letting me life :)

Just to prevent further distraction, its a server, so to the impact on the minecraft community is rather low ;)

you still have to pay for minecraft if you want to use it as client.

the protocol is mentioned on the official wiki and you are encouraged to create 3rd party clients and servers.

in addition you won't be able to "play" the "game" as usual.

Just having a map build previously and imported is used to place buttons and levers and maybe some signs for ingame feedback for the user.

MAYBE Redstone state, which i don't think will be implemented.

No block breaking or placing.

implementation of the protocol just to the state the client thinks it is ingame and starts displaying things i want ;)

ps: any tricks to concatenate binarys ?

Edited by JRSmile

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I'm not sure what you mean by concatenate binary. I'm also not so familiar with TCP, but I imagine that packets can't be greater than a certain size. At first I thought perhaps you need to use BitOR, but some of the hex values in your code are too large and would need to be split. Could you give an example of what you mean by binary concatenation? I hope to learn something new here. :)

Edited by czardas

Share this post


Link to post
Share on other sites

This is from the winhttp UDF. Is that what you where looking for?

; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpBinaryConcat
; Description ...: Concatenates two binary data returned by _WinHttpReadData() in binary mode.
; Syntax.........: _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)
; Parameters ....: $bBinary1 - Binary data that is to be concatenated.
;                 $bBinary2 - Binary data to concat.
; Return values .: Success - Returns concatenated binary data.
;                 Failure - Returns empty binary and sets @error:
;                 |1 - Invalid input.
; Author ........: ProgAndy
; Modified.......: trancexx
; Remarks .......:
; Related .......: _WinHttpReadData
; Link ..........:
; Example .......:
;============================================================================================
Func _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)
    Switch IsBinary($bBinary1) + 2 * IsBinary($bBinary2)
        Case 0
            Return SetError(1, 0, Binary(''))
        Case 1
            Return $bBinary1
        Case 2
            Return $bBinary2
    EndSwitch
    Local $tAuxiliary = DllStructCreate("byte[" & BinaryLen($bBinary1) & "];byte[" & BinaryLen($bBinary2) & "]")
    DllStructSetData($tAuxiliary, 1, $bBinary1)
    DllStructSetData($tAuxiliary, 2, $bBinary2)
    Local $tOutput = DllStructCreate("byte[" & DllStructGetSize($tAuxiliary) & "]", DllStructGetPtr($tAuxiliary))
    Return DllStructGetData($tOutput, 1)
EndFunc   ;==>_WinHttpBinaryConcat

@Valik You know you're going to have to explain game-botters why this thread is still open at least twice a day from now on right?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@Valik You know you're going to have to explain game-botters why this thread is still open at least twice a day from now on right?

First your question, then your answer :)

I don't think he needs to, because a bot is used to get advantage out of automation in a game, during the fact that this is a server you won't get any advantages out of it for the real game, except the fact that you can use it as GUI as intended.

Thanks for the Help, but it isn't working as i expect.

for example:

$bBinary1 = Binary(0x00000001)
$bBinary2 = Binary(0x00000002)
ConsoleWrite(Hex(_WinHttpBinaryConcat($bBinary1, $bBinary2)))

Func _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)
    Switch IsBinary($bBinary1) + 2 * IsBinary($bBinary2)
        Case 0
            Return SetError(1, 0, Binary(''))
        Case 1
            Return $bBinary1
        Case 2
            Return $bBinary2
    EndSwitch
    Local $tAuxiliary = DllStructCreate("byte[" & BinaryLen($bBinary1) & "];byte[" & BinaryLen($bBinary2) & "]")
    DllStructSetData($tAuxiliary, 1, $bBinary1)
    DllStructSetData($tAuxiliary, 2, $bBinary2)
    Local $tOutput = DllStructCreate("byte[" & DllStructGetSize($tAuxiliary) & "]", DllStructGetPtr($tAuxiliary))
    Return DllStructGetData($tOutput, 1)
EndFunc   ;==>_WinHttpBinaryConcat

results in: 0100000002000000

Which isn't what i need.

I will give a short example of my requirements:

$bBinary1 = Binary(0x00000001)
$bBinary2 = Binary(0x00000002)

$result = MAGIC($bBinary1, $bBinary2)

Consolewrite ($result & @CRLF)

Which should result in: 0x0000000100000002 [isBinary = TRUE]

Do i really have to code it with Stringreplace?

Or maybe is it possible to split the incomming packets into a Struct?

Edited by JRSmile

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I have done a function that returns the thing i want, but is it the correct way to do so?

Func MAGIC($b1,$b2)
if not (IsBinary($b1) and IsBinary($b2)) then return False
ConsoleWrite($b1 & " " & $b2 & @CRLF)
$b1_string = string($b1)
$b2_string = string($b2)
ConsoleWrite($b1_string & @CRLF)
ConsoleWrite($b2_string & @CRLF)
$b1_short = StringTrimLeft($b1_string,2)
$b2_short = StringTrimLeft($b2_string,2)
return Binary("0x" & $b1_short & $b2_short)
EndFunc
Edited by JRSmile

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

I don't think he needs to, because a bot is used to get advantage out of automation in a game, during the fact that this is a server you won't get any advantages out of it for the real game, except the fact that you can use it as GUI as intended.

You're not making abot and I hope botters will realise that, but the experience is that they will use any reason why they would be allowed to break the rules.

Anyways back to the topic.

I think the problem with how you use 'my' example is the input. I'll try to demonstrate is with an example:

$bBinary1 = Binary(0x00000001)
$bBinary2 = Binary(0x00000002)
ConsoleWrite($bBinary1 & @CRLF) ;this is probably not the input you want?
ConsoleWrite($bBinary2 & @CRLF)
$bReturn = _WinHttpBinaryConcat($bBinary1, $bBinary2)
ConsoleWrite($bReturn & @CRLF) ;concat seems correct to me
ConsoleWrite(IsBinary($bReturn) & @CRLF & @CRLF) ;return type seems correct to me

$bBinary1 = Binary(0x01000000)
$bBinary2 = Binary(0x02000000)
ConsoleWrite($bBinary1 & @CRLF) ;this is probably the input you want?
ConsoleWrite($bBinary2 & @CRLF)
$bReturn = _WinHttpBinaryConcat($bBinary1, $bBinary2)
ConsoleWrite($bReturn & @CRLF) ;concat seems correct to me
ConsoleWrite(IsBinary($bReturn) & @CRLF) ;return type seems correct to me

Func _WinHttpBinaryConcat(ByRef $bBinary1, ByRef $bBinary2)
    Switch IsBinary($bBinary1) + 2 * IsBinary($bBinary2)
        Case 0
            Return SetError(1, 0, Binary(''))
        Case 1
            Return $bBinary1
        Case 2
            Return $bBinary2
    EndSwitch
    Local $tAuxiliary = DllStructCreate("byte[" & BinaryLen($bBinary1) & "];byte[" & BinaryLen($bBinary2) & "]")
    DllStructSetData($tAuxiliary, 1, $bBinary1)
    DllStructSetData($tAuxiliary, 2, $bBinary2)
    Local $tOutput = DllStructCreate("byte[" & DllStructGetSize($tAuxiliary) & "]", DllStructGetPtr($tAuxiliary))
    Return DllStructGetData($tOutput, 1)
EndFunc   ;==>_WinHttpBinaryConcat

I have done a function that returns the thing i want, but is it the correct way to do so?

It should work, You might want to make some speed comparisons with different methods though.

I'd use whatever works for you as a place holder and put a review on your TODO list.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

What I don't understand is that the function Binary() seems to perform a BitRotate() operation (actually this is wrong, it's more like byte size segments in reverse order :) ). It says that Binary() returns a binary variant but this is not clear to me.

Edited by czardas

Share this post


Link to post
Share on other sites

What I don't understand is that the function Binary() seems to perform a BitRotate() operation (actually this is wrong). It says that Binary() returns a binary variant but this is not clear to me.

I have the same problem understanding it, maybe because of the Big/LittleEndian annoyance?


$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Sorry, I was editing as you replied. Perhaps a search around the forum will reveal its secrets. :)

Edit

Here's a promising link:

Edited by czardas

Share this post


Link to post
Share on other sites

thank you very much, i may be able to proceed from here,

one additional question :)

is it possible to create a struct lets say DllStructCreate("byte[" & BinaryLen($bBinary1) & "]) and split it by using a struct which has a different structure and copy the pointer somehow?


$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

Well I have learned something today. I noticed that Manadar was passing a string to the function Binary() and that made quite a difference. :)

1 person likes this

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I played a lot with the Binary functions with the Encryption stuff I did. If I recall, it was making sure both parts of the concatenation were Binary, so something like this:

Local $bFirst = "0x01020304"
Local $bSecond = "0x05060708"
ConsoleWrite(Binary($bFirst) & Binary($bSecond) & @CRLF)

@JRSmile, yes, you can do that. While using DLLStructCreate(), just use it's pointer option to point to the other struct's pointer, like this:

Local $tBinary1 = DllStructCreate("byte[4]")
Local $tInt1 = DllstructCreate("int", DllStructGetPtr($tBinary1))
Local $iNumber = DllStructGetData($tInt1, 1)

I think I remember writing a func that I could pass arbitrary Binary data into, and a type, and it took care of creating structs, getting pointers, and just returned the data I was looking for. If no one else thinks of it before I can get home and find it, I'll try to post it here.

Edited by SkinnyWhiteGuy

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

@JRSmile, yes, you can do that. While using DLLStructCreate(), just use it's pointer option to point to the other struct's pointer, like this:

Thank you very much, that would help me a lot with analysing incomming packet structures.

ps, works great already:

$bBinary1 = 0x0000000F
Local $tBinary1 = DllStructCreate("byte[4]")
DllStructSetData($tBinary1,1,$bBinary1)
Local $tInt1 = DllstructCreate("int", DllStructGetPtr($tBinary1))
ConsoleWrite(DllStructGetData($tInt1,1))
$tBinary1 = 0
$tInt1 = 0

can't wait for your function to arrive :)

pps: love your avatar ;)

Edited by JRSmile

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Found a copy of that function on my laptop:

Local $bData = Binary("0x00000001")
ConsoleWrite(LoadState($bData, "int") & @CRLF)

Func LoadState(ByRef $byte_stream, $type)
    If $type = "string" Then
        Local $size = LoadState($byte_stream, "int")
        Return LoadState($data, "char[" & $size - 1 & "]")
    EndIf
    Local $temp = DllStructCreate($type), $output = DllStructCreate("byte[" & DllStructGetSize($temp) & "]", DllStructGetPtr($temp))
    DllStructSetData($output, 1, BinaryMid($byte_stream, 1, DllStructGetSize($temp)))
    $byte_stream = BinaryMid($byte_stream, 1 + DllStructGetSize($temp))
    Return DllStructGetData($temp, 1)
EndFunc

This version was made to take the data off the Binary Stream coming in, so you could call it multiple times to pull out different values.

Just as a note: this will pull values from the Binary data as Little Endian order (which from my Wikipedia searching is what Windows stores things as). If you need it as Big Endian, you will have to do some massaging of the data.

Edited by SkinnyWhiteGuy

Share this post


Link to post
Share on other sites

thanks, i deal with a java client so Big Endian is the word of the day... will have to figure that out :)


$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])))''Chr("a")&"HI"Next;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)

Share this post


Link to post
Share on other sites

I play Minecraft too, I might have to try out your script and see what it's doing.

Try it and see what it returns, if the numbers/data doesn't look right, I might can help get it flipped back around.

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

  • Similar Content

    • comtech80
      By comtech80
      Folks,
      I have an issue I've been trying to solve for a while, I'm trying to add static routes in DHCP via a 121 route rule in Windows 2012 R2 is a brutal manual process and wanted to automate this via AutoIT.
       
      When I use the "ControlGetText" everything displays properly in the MSG box but when I try and use "ControlSetText" or "ControlSend" the values won't display in the input box but the action comes back as successful?
      Anyone able to help me with this? I'm thinking this might be an active window issue but i'm not sure.
      Here is a part of my code.
       
      $hWnd = WinWait("[TITLE:Add a Static Route]","", 10)
      WinActivate($hWnd)
      $Status = ControlSend($hWnd, "", "[CLASS:Edit; INSTANCE:4]", "192"); Does not add 192 to the text box.
      Local $sTextEdit1 = ControlGetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]")
      ConsoleWrite ( "ControlSend Status: " &  $Status & @CRLF); Returns a Value of 1
      ConsoleWrite ( "ControlGetText Value Edit1: " &  $sTextEdit1 & @CRLF);
       
      Please see attachment for more info.

    • ur
      By ur
      I have a button control as below screen.

      This one I am able to suppress using below code in all the OS.
      But on server 2008, sometimes the button highlighted in the image is not getting clicked and some times it is working.
      I have cross checked the IDs when it is not working, but it is working only.
       
      $win1 = "erwin Mart Configuration" $MartConfigWindow = _WinWaitActivate1($win1,"Database Details") ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a6", $dbserver) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a4", $dbname) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a9", $dbuser) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a8", $dbpassword) ;Button clicl logic $iControlClickStatus = ControlClick($MartConfigWindow, "", "[CLASS:WindowsForms10.BUTTON.app.0.378734a; INSTANCE:2]") ;If above button click fails, trying with mouse click on the control if ControlFocus($MartConfigWindow, "", "WindowsForms10.BUTTON.app.0.378734a2")=1 then ;sometimes above button fails in win server 2008,so this loop Send("{ENTER") EndIf  
      Any suggestion on how to resolve this.?
    • AlexFing17
      By AlexFing17
      i am trying to figure out how a server can connect to a client Over the internet. 
      In this is script. The client connects to the server on the same machine (localhost) and executes the commands from the client.
      How can I change that instead communicating over localhost to communicate over the internet with tcp ipaddress and a port.
       
      What i actually need help of is
      1. The server will open a port and  listen to communication from a No-ip address
      2. I input the no-ip address and correct port in the client side, and when i click on connect, it connects to the server if its online
       
       
      This is the client
      #include <GuiConstantsEx.au3> THIS IS THE CLIENT #include <NamedPipes.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ; =============================================================================================================================== ; Description ...: This is the client side of the pipe demo ; Author ........: Paul Campbell (PaulIA) ; Notes .........: ; =============================================================================================================================== ; =============================================================================================================================== ; Global constants ; =============================================================================================================================== Global Const $BUFSIZE = 4096 Global Const $DEFCMD = "cmd.exe /c dir c:\" Global Const $PIPE_NAME = "\\$\\pipe\\AutoIt3" Global Const $ERROR_MORE_DATA = 234 ; =============================================================================================================================== ; Global variables ; =============================================================================================================================== Global $g_idEdit, $g_idMemo, $g_idSend, $g_idServer, $g_hPipe ; =============================================================================================================================== ; Main ; =============================================================================================================================== CreateGUI() MsgLoop() ; =============================================================================================================================== ; Creates a GUI for the client ; =============================================================================================================================== Func CreateGUI() Local $hGUI = GUICreate("FarC0nn3c7", 500, 400, -1, -1, $WS_SIZEBOX) GUICtrlCreateLabel("Server:", 2, 14, 52, 20, $SS_RIGHT) $g_idServer = GUICtrlCreateEdit("<local>", 56, 10, 200, 20, $SS_LEFT) GUICtrlCreateLabel("Command:", 2, 36, 52, 20, $SS_RIGHT) $g_idEdit = GUICtrlCreateEdit($DEFCMD, 56, 32, 370, 20, $SS_LEFT) $g_idSend = GUICtrlCreateButton("Pawn Dem", 430, 32, 60, 20) $g_idMemo = GUICtrlCreateEdit("", 0, 62, _WinAPI_GetClientWidth($hGUI), 332) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState() EndFunc ;==>CreateGUI ; =============================================================================================================================== ; Logs an error message to the display ; =============================================================================================================================== Func LogError($sMessage) $sMessage &= " (" & _WinAPI_GetLastErrorMessage() & ")" GUICtrlSetData($g_idMemo, GUICtrlRead($g_idMemo) & $sMessage & @CRLF) EndFunc ;==>LogError ; =============================================================================================================================== ; Logs a message to the display ; =============================================================================================================================== Func LogMsg($sMessage) GUICtrlSetData($g_idMemo, GUICtrlRead($g_idMemo) & $sMessage & @CRLF) EndFunc ;==>LogMsg ; =============================================================================================================================== ; MsgLoop ; =============================================================================================================================== Func MsgLoop() While True Switch GUIGetMsg() Case $g_idSend SendCmd() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ;==>MsgLoop ; =============================================================================================================================== ; This function opens a pipe to the server ; =============================================================================================================================== Func OpenPipe() Local $sName, $sPipe ; Get pipe handle $sName = GUICtrlRead($g_idServer) If $sName = "<local>" Then $sName = "." $sPipe = StringReplace($PIPE_NAME, "$", $sName) $g_hPipe = _WinAPI_CreateFile($sPipe, 2, 6) If $g_hPipe <> -1 Then Return True LogError("OpenPipe failed") Return False EndFunc ;==>OpenPipe ; =============================================================================================================================== ; This function reads a message from the pipe ; =============================================================================================================================== Func ReadMsg() Local $bSuccess, $iRead, $pBuffer, $tBuffer $tBuffer = DllStructCreate("char Text[4096]") $pBuffer = DllStructGetPtr($tBuffer) GUICtrlSetData($g_idMemo, "") While 1 $bSuccess = _WinAPI_ReadFile($g_hPipe, $pBuffer, $BUFSIZE, $iRead, 0) If $iRead = 0 Then ExitLoop If Not $bSuccess Or (_WinAPI_GetLastError() = $ERROR_MORE_DATA) Then ExitLoop GUICtrlSetData($g_idMemo, StringLeft(DllStructGetData($tBuffer, "Text"), $iRead), 1) WEnd EndFunc ;==>ReadMsg ; =============================================================================================================================== ; This function sends a command to the server ; =============================================================================================================================== Func SendCmd() If OpenPipe() Then SetReadMode() WriteMsg(GUICtrlRead($g_idEdit)) ReadMsg() _WinAPI_CloseHandle($g_hPipe) EndIf EndFunc ;==>SendCmd ; =============================================================================================================================== ; This function sets the pipe read mode ; =============================================================================================================================== Func SetReadMode() If Not _NamedPipes_SetNamedPipeHandleState($g_hPipe, 1, 0, 0, 0) Then LogError("SetReadMode: _NamedPipes_SetNamedPipeHandleState failed") EndIf EndFunc ;==>SetReadMode ; =============================================================================================================================== ; This function writes a message to the pipe ; =============================================================================================================================== Func WriteMsg($sMessage) Local $iWritten, $iBuffer, $pBuffer, $tBuffer $iBuffer = StringLen($sMessage) + 1 $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]") $pBuffer = DllStructGetPtr($tBuffer) DllStructSetData($tBuffer, "Text", $sMessage) If Not _WinAPI_WriteFile($g_hPipe, $pBuffer, $iBuffer, $iWritten, 0) Then LogError("WriteMsg: _WinAPI_WriteFile failed") EndIf EndFunc ;==>WriteMsg  
      And this is the server
      #include <GuiConstantsEx.au3> #include <NamedPipes.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #NoTrayIcon ; =============================================================================================================================== ; Description ...: This is the server side of the pipe demo ; Author ........: Paul Campbell (PaulIA) ; Notes .........: ; =============================================================================================================================== ; =============================================================================================================================== ; Global constants ; =============================================================================================================================== Global Const $DEBUGGING = False Global Const $BUFSIZE = 4096 Global Const $PIPE_NAME = "\\.\\pipe\\AutoIt3" Global Const $TIMEOUT = 5000 Global Const $WAIT_TIMEOUT = 258 Global Const $ERROR_IO_PENDING = 997 Global Const $ERROR_PIPE_CONNECTED = 535 ; =============================================================================================================================== ; Global variables ; =============================================================================================================================== Global $g_hEvent, $g_idMemo, $g_pOverlap, $g_tOverlap, $g_hPipe, $g_hReadPipe, $g_iState, $g_iToWrite ; =============================================================================================================================== ; Main ; =============================================================================================================================== CreateGUI() InitPipe() MsgLoop() ; =============================================================================================================================== ; Creates a GUI for the server ; =============================================================================================================================== Func CreateGUI() Local $hGUI $hGUI = GUICreate("Pipe Server", 500, 400, -1, -1, $WS_SIZEBOX) $g_idMemo = GUICtrlCreateEdit("", 0, 0, _WinAPI_GetClientWidth($hGUI), _WinAPI_GetClientHeight($hGUI)) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState() EndFunc ;==>CreateGUI ; =============================================================================================================================== ; This function creates an instance of a named pipe ; =============================================================================================================================== Func InitPipe() ; Create an event object for the instance $g_tOverlap = DllStructCreate($tagOVERLAPPED) $g_pOverlap = DllStructGetPtr($g_tOverlap) $g_hEvent = _WinAPI_CreateEvent() If $g_hEvent = 0 Then LogError("InitPipe ..........: API_CreateEvent failed") Return EndIf DllStructSetData($g_tOverlap, "hEvent", $g_hEvent) ; Create a named pipe $g_hPipe = _NamedPipes_CreateNamedPipe($PIPE_NAME, _ ; Pipe name 2, _ ; The pipe is bi-directional 2, _ ; Overlapped mode is enabled 0, _ ; No security ACL flags 1, _ ; Data is written to the pipe as a stream of messages 1, _ ; Data is read from the pipe as a stream of messages 0, _ ; Blocking mode is enabled 1, _ ; Maximum number of instances $BUFSIZE, _ ; Output buffer size $BUFSIZE, _ ; Input buffer size $TIMEOUT, _ ; Client time out 0) ; Default security attributes If $g_hPipe = -1 Then LogError("InitPipe ..........: _NamedPipes_CreateNamedPipe failed") Else ; Connect pipe instance to client ConnectClient() EndIf EndFunc ;==>InitPipe ; =============================================================================================================================== ; This function loops waiting for a connection event or the GUI to close ; =============================================================================================================================== Func MsgLoop() Local $iEvent Do $iEvent = _WinAPI_WaitForSingleObject($g_hEvent, 0) If $iEvent < 0 Then LogError("MsgLoop ...........: _WinAPI_WaitForSingleObject failed") Exit EndIf If $iEvent = $WAIT_TIMEOUT Then ContinueLoop Debug("MsgLoop ...........: Instance signaled") Switch $g_iState Case 0 CheckConnect() Case 1 ReadRequest() Case 2 CheckPending() Case 3 RelayOutput() EndSwitch Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>MsgLoop ; =============================================================================================================================== ; Checks to see if the pending client connection has finished ; =============================================================================================================================== Func CheckConnect() Local $iBytes ; Was the operation successful? If Not _WinAPI_GetOverlappedResult($g_hPipe, $g_pOverlap, $iBytes, False) Then LogError("CheckConnect ......: Connection failed") ReconnectClient() Else $g_iState = 1 EndIf EndFunc ;==>CheckConnect ; =============================================================================================================================== ; This function reads a request message from the client ; =============================================================================================================================== Func ReadRequest() Local $pBuffer, $tBuffer, $iRead, $bSuccess $tBuffer = DllStructCreate("char Text[" & $BUFSIZE & "]") $pBuffer = DllStructGetPtr($tBuffer) $bSuccess = _WinAPI_ReadFile($g_hPipe, $pBuffer, $BUFSIZE, $iRead, $g_pOverlap) If $bSuccess And ($iRead <> 0) Then ; The read operation completed successfully Debug("ReadRequest .......: Read success") Else ; Wait for read Buffer to complete If Not _WinAPI_GetOverlappedResult($g_hPipe, $g_pOverlap, $iRead, True) Then LogError("ReadRequest .......: _WinAPI_GetOverlappedResult failed") ReconnectClient() Return Else ; Read the command from the pipe $bSuccess = _WinAPI_ReadFile($g_hPipe, $pBuffer, $BUFSIZE, $iRead, $g_pOverlap) If Not $bSuccess Or ($iRead = 0) Then LogError("ReadRequest .......: _WinAPI_ReadFile failed") ReconnectClient() Return EndIf EndIf EndIf ; Execute the console command If Not ExecuteCmd(DllStructGetData($tBuffer, "Text")) Then ReconnectClient() Return EndIf ; Relay console output back to the client $g_iState = 3 EndFunc ;==>ReadRequest ; =============================================================================================================================== ; This function relays the console output back to the client ; =============================================================================================================================== Func CheckPending() Local $bSuccess, $iWritten $bSuccess = _WinAPI_GetOverlappedResult($g_hPipe, $g_pOverlap, $iWritten, False) If Not $bSuccess Or ($iWritten <> $g_iToWrite) Then Debug("CheckPending ......: Write reconnecting") ReconnectClient() Else Debug("CheckPending ......: Write complete") $g_iState = 3 EndIf EndFunc ;==>CheckPending ; =============================================================================================================================== ; This function relays the console output back to the client ; =============================================================================================================================== Func RelayOutput() Local $pBuffer, $tBuffer, $sLine, $iRead, $bSuccess, $iWritten $tBuffer = DllStructCreate("char Text[" & $BUFSIZE & "]") $pBuffer = DllStructGetPtr($tBuffer) ; Read data from console pipe _WinAPI_ReadFile($g_hReadPipe, $pBuffer, $BUFSIZE, $iRead) If $iRead = 0 Then LogMsg("RelayOutput .......: Write done") _WinAPI_CloseHandle($g_hReadPipe) _WinAPI_FlushFileBuffers($g_hPipe) ReconnectClient() Return EndIf ; Get the data and strip out the extra carriage returns $sLine = StringLeft(DllStructGetData($tBuffer, "Text"), $iRead) $sLine = StringReplace($sLine, @CR & @CR, @CR) $g_iToWrite = StringLen($sLine) DllStructSetData($tBuffer, "Text", $sLine) ; Relay the data back to the client $bSuccess = _WinAPI_WriteFile($g_hPipe, $pBuffer, $g_iToWrite, $iWritten, $g_pOverlap) If $bSuccess And ($iWritten = $g_iToWrite) Then Debug("RelayOutput .......: Write success") Else If Not $bSuccess And (_WinAPI_GetLastError() = $ERROR_IO_PENDING) Then Debug("RelayOutput .......: Write pending") $g_iState = 2 Else ; An error occurred, disconnect from the client LogError("RelayOutput .......: Write failed") ReconnectClient() EndIf EndIf EndFunc ;==>RelayOutput ; =============================================================================================================================== ; This function is called to start an overlapped connection operation ; =============================================================================================================================== Func ConnectClient() $g_iState = 0 ; Start an overlapped connection If _NamedPipes_ConnectNamedPipe($g_hPipe, $g_pOverlap) Then LogError("ConnectClient .....: ConnectNamedPipe 1 failed") Else Switch @error ; The overlapped connection is in progress Case $ERROR_IO_PENDING Debug("ConnectClient .....: Pending") ; Client is already connected, so signal an event Case $ERROR_PIPE_CONNECTED LogMsg("ConnectClient .....: Connected") $g_iState = 1 If Not _WinAPI_SetEvent(DllStructGetData($g_tOverlap, "hEvent")) Then LogError("ConnectClient .....: SetEvent failed") EndIf ; Error occurred during the connection event Case Else LogError("ConnectClient .....: ConnectNamedPipe 2 failed") EndSwitch EndIf EndFunc ;==>ConnectClient ; =============================================================================================================================== ; Dumps debug information to the screen ; =============================================================================================================================== Func Debug($sMessage) If $DEBUGGING Then LogMsg($sMessage) EndFunc ;==>Debug ; =============================================================================================================================== ; Executes a command and returns the results ; =============================================================================================================================== Func ExecuteCmd($sCmd) Local $tProcess, $tSecurity, $tStartup, $hWritePipe ; Set up security attributes $tSecurity = DllStructCreate($tagSECURITY_ATTRIBUTES) DllStructSetData($tSecurity, "Length", DllStructGetSize($tSecurity)) DllStructSetData($tSecurity, "InheritHandle", True) ; Create a pipe for the child process's STDOUT If Not _NamedPipes_CreatePipe($g_hReadPipe, $hWritePipe, $tSecurity) Then LogError("ExecuteCmd ........: _NamedPipes_CreatePipe failed") Return False EndIf ; Create child process $tProcess = DllStructCreate($tagPROCESS_INFORMATION) $tStartup = DllStructCreate($tagSTARTUPINFO) DllStructSetData($tStartup, "Size", DllStructGetSize($tStartup)) DllStructSetData($tStartup, "Flags", BitOR($STARTF_USESTDHANDLES, $STARTF_USESHOWWINDOW)) DllStructSetData($tStartup, "StdOutput", $hWritePipe) DllStructSetData($tStartup, "StdError", $hWritePipe) If Not _WinAPI_CreateProcess("", $sCmd, 0, 0, True, 0, 0, "", DllStructGetPtr($tStartup), DllStructGetPtr($tProcess)) Then LogError("ExecuteCmd ........: _WinAPI_CreateProcess failed") _WinAPI_CloseHandle($g_hReadPipe) _WinAPI_CloseHandle($hWritePipe) Return False EndIf _WinAPI_CloseHandle(DllStructGetData($tProcess, "hProcess")) _WinAPI_CloseHandle(DllStructGetData($tProcess, "hThread")) ; Close the write end of the pipe so that we can read from the read end _WinAPI_CloseHandle($hWritePipe) LogMsg("ExecuteCommand ....: " & $sCmd) Return True EndFunc ;==>ExecuteCmd ; =============================================================================================================================== ; Logs an error message to the display ; =============================================================================================================================== Func LogError($sMessage) $sMessage &= " (" & _WinAPI_GetLastErrorMessage() & ")" ConsoleWrite($sMessage & @LF) EndFunc ;==>LogError ; =============================================================================================================================== ; This function is called when an error occurs or when the client closes its handle to the pipe ; =============================================================================================================================== Func ReconnectClient() ; Disconnect the pipe instance If Not _NamedPipes_DisconnectNamedPipe($g_hPipe) Then LogError("ReconnectClient ...: DisonnectNamedPipe failed") Return EndIf ; Connect to a new client ConnectClient() EndFunc ;==>ReconnectClient  
    • Jefrey
      By Jefrey
      I've ported these two functions from PHP to AU3 to work with URLs.
      Made them for those who work with libraries like HTTP.au3 (not the one I coded), that needs passing the server domain, path, etc., instead of the full URL.
      Grab the lib here.
      ParseURL( $sURL )
      Parses the URL and splits it into defined parts. Returns an array:
      [0] = Full URL (same as $sURL) [1] = Protocol (i.e.: http, https, ftp, ws...) [2] = Domain [3] = Port (or null if not specified) [4] = Path (or null if not specified) [5] = Query string (everything after the ? - or null if not specified) Example:
      $aExample = ParseURL("https://google.com:8080/?name=doe") MsgBox(0, "Test", "URL: " & $aExample[0] & @CRLF & _ "Protocol: " & $aExample[1] & @CRLF & _ "Domain: " & $aExample[2] & @CRLF & _ "Port: " & $aExample[3] & @CRLF & _ "Path: " & $aExample[4] & @CRLF & _ "Query string: " & $aExample[5])  
      ParseStr( $sStr )
      Parses a query string (similar to the [5] of the previous function) and returns a multidimensional array, where:
      [0][0] = number of variables found [0][1] = ununsed [1][0] = key name of the first variable [1][1] = first variable value (already URL decoded) [n][0] = key name of the nth variable [n][1] = nth variable value (already URL decoded) Example:
      include <Array.au3> ; need only to do _ArrayDisplay, not needed by the lib _ArrayDisplay(ParseStr("foo=bar&test=lol%20123")) #cs Result is: [0][0] = 2 [0][1] = ununsed [1][0] = foo [1][1] = bar [2][0] = test [2][1] = lol 123 #ce Feel free to fork!
    • razor999
      By razor999
      please help me,
      my script not working, i want gui run like local real time
      #NoTrayIcon #include <INet.au3> #include <String.au3> #include <array.au3> Local $Refresh = 0 ; Set refresh OFF Local $Timer = TimerInit() Local $RefreshEvery = 1 ; seconds ;Global $nCheck Global $link = BinaryToString (InetRead ("http://test.no-ip.info/time.asp")) Global $timeserver = _StringBetween($link, 'id="timeserver">' , '</span>') Global $realtime = $timeserver[0] GuiCreate("Time My Server",200,50) $htime = GuiCtrlCreateLabel("", 10, 10, 180, 20) $btnStart = GUICtrlCreateButton("Start", 40, 30, 57, 17) $btnStop = GUICtrlCreateButton("Stop", 110, 30, 57, 17) GuiSetState() While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $btnStart $Refresh = 1 ; Set refresh ON Case $nMsg = $btnStop $Refresh = 0 ; Set refresh OFF EndSelect If $Refresh And (TimerDiff($Timer) > $RefreshEvery*1000) Then time() $Timer = TimerInit() EndIf WEnd Func time() ;If @SEC <> $nCheck Then GUICtrlSetData($htime, "The current time is " & $realtime) ;$nCheck = @SEC ;EndIf EndFunc