mIRC Home    About    Download    Register    News    Help

Print Thread
#127001 07/08/05 01:53 PM
Joined: Jul 2005
Posts: 40
K
Karas Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
I want to use null byte in mirc.. is it possible ?

I must send this info with tcp/ip:

The command packet format consists of:

* packet size (int)
o the number of bytes from the start of the requestid to the end of string2 (including the null byte). It must be at least 10.
* request id (int)
* SERVERDATA_EXECCOMMAND / SERVERDATA_AUTH (int)
o SERVERDATA_AUTH is currently 3
o SERVERDATA_EXECCOMMAND is currently 2
* string1 (is the command to run).
* string2 must be null ("");

For RCON connections the first command must be a SERVERDATA_AUTH command. If a SERVERDATA_EXECCOMMAND command is sent prior to successful authentication then a SERVERDATA_AUTH_RESPONSE response packet with the failure condition is sent (see the response section for details). The INT's are 32 Bit Little Endian byte order.


j0k3r @ k4s.ch
#127002 07/08/05 02:47 PM
Joined: Sep 2004
Posts: 200
I
Fjord artisan
Offline
Fjord artisan
I
Joined: Sep 2004
Posts: 200
bset &bvar 00
sockwrite -<look for the one that says the text is binary> &bvar
that should work

#127003 07/08/05 03:46 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
There isn't a switch for sending a binary variable, instead you just make sure you don't use the -t switch.


New username: hixxy
#127004 07/08/05 04:13 PM
Joined: Jul 2005
Posts: 40
K
Karas Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
yes ok but doesn't work ufff...

i've to send: packet size request id SERVERDATA_AUTH string1 string2(must be null)

(http://wikki.kquery.net/index.php/Other:SourceRcon)

on 1:sockopen:rcon: {
bset &auth 1 97 115 100 97 115 100 97 115 100 97 115 100 97 00
sockwrite rcon $calc($bvar(&auth,0) + 2) $+ 13 $+ &auth
echo -a ...sending...
}

on 1:sockread:rcon:{
if ($sockerr > 0) return
:nextread
sockread &data
if ($sockbr == 0) return
if (%temp == $null) %temp = -
var %i = 0
while (%i <= $bvar(&data,0)) {
echo -a %i --> $bvar(&data,%i).text --> $bvar(&data,%i)
inc %i
}
goto nextread
}

awww...it doesn't work i dont receive anything.. any idea ?


j0k3r @ k4s.ch
#127005 07/08/05 04:16 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
You have to add all data to the variable I think, I don't think mIRC lets you send a binary variable as well as normal data.


New username: hixxy
#127006 07/08/05 05:33 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Ints are requested, not ascii bytes that match numbers.
It should probably look somewhat like this:

bset &requestid 1 0 0 0 1
bset &serverdata 1 0 0 0 3
bset &auth 1 97 115 100 97 115 100 97 115 100 97 115 100 97 0
bset &auth2 1 0
var %packetsize = $calc($bvar(&requestid,0) + $bvar(&serverdata,0) + $bvar(&auth,0) + $bvar(&auth2,0))
bset &size 4 $numtoint(%packetsize)
sockwrite rcon &size
sockwrite rcon &requestid
sockwrite rcon &serverdata
sockwrite rcon &auth
sockwrite rcon &auth2

Both &auth and &auth2 must end with a 0 as last byte!

Something that might help:
; $numtoint(257) returns 0 0 1 0
alias numtoint {
var %1 = $1, %r
if (%1 !isnum 0-4294967295) return
var %r = $calc(%1 % 256), %1 = $int($calc(%1 / 256))
var %r = $calc(%1 % 256) %r, %1 = $int($calc(%1 / 256))
var %r = $calc(%1 % 256) %r, %1 = $int($calc(%1 / 256))
var %r = $calc(%1 % 256) %r, %1 = $int($calc(%1 / 256))
return %r
}
; $inttonum(0 0 1 0) returns 257
alias inttonum {
if (!$regex($1-,^(\d+) (\d+) (\d+) (\d+)$)) return
return $calc( ((($regml(1) * 256 + $regml(2) ) * 256 + $regml(3) ) * 256 + $regml(4) ))
}

#127007 07/08/05 10:11 PM
Joined: Jul 2005
Posts: 40
K
Karas Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
Hey, that's nice ! really thx smile

But, doesn't work :I

Awwwwww, i'm hopeless frown

Code:
alias rcon {
  sockopen rcon 82.192.78.16 27025
}

on 1:sockopen:rcon: {

  bset &amp;requestid 1 0 0 0 1
  bset &amp;serverdata 1 0 0 0 3
  bset &amp;auth 1 97 115 100 97 115 100 97 115 100 97 115 100 97 0
  bset &amp;auth2 1 0
  var %packetsize = $calc($bvar(&amp;requestid,0) + $bvar(&amp;serverdata,0) + $bvar(&amp;auth,0) + $bvar(&amp;auth2,0))
  bset &amp;size 1 $numtoint(%packetsize)

  echo -a $bvar(&amp;size,1-) $bvar(&amp;requestid,1-) $bvar(&amp;serverdata,1-) $bvar(&amp;auth,1-) $bvar(&amp;auth2,1-)

  sockwrite rcon &amp;size
  sockwrite rcon &amp;requestid
  sockwrite rcon &amp;serverdata
  sockwrite rcon &amp;auth
  sockwrite rcon &amp;auth2

  echo -a ...sending...
}

on 1:sockread:rcon:{
  if ($sockerr &gt; 0) return
  :nextread
  sockread &amp;data
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  var %i = 0
  while (%i &lt;= $bvar(&amp;data,0)) {
    echo -a %i --&gt; $bvar(&amp;data,%i).text --&gt; $bvar(&amp;data,%i)
    inc %i
  }
  goto nextread
}

; $numtoint(257) returns 0 0 1 0
alias numtoint {
  var %1 = $1, %r
  if (%1 !isnum 0-4294967295) return
  var %r = $calc(%1 % 256), %1 = $int($calc(%1 / 256))
  var %r = $calc(%1 % 256) %r, %1 = $int($calc(%1 / 256))
  var %r = $calc(%1 % 256) %r, %1 = $int($calc(%1 / 256))
  var %r = $calc(%1 % 256) %r, %1 = $int($calc(%1 / 256))
  return %r
}



btw why bset &size 4 $numtoint(%packetsize) ?

i think it's 1 ...

(in this exemple the pass is wrong, however the server should respond.. but that's not frown )


j0k3r @ k4s.ch
#127008 07/08/05 10:49 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
You're right it's 1 not 4. But an int (number data type) should be 4 bytes long. It could be because of that little/big endian stuff, so maybe try reversing the different bytes of the int's.
0 0 0 1 -> 1 0 0 0
1 2 3 4 -> 4 3 2 1

What you should do, is download a packet sniffer like ethereal and use that to see what actually gets sent by a standalone rcon client, by your client and by the game server. This way you can determine what the difference is, and if it's really the sending or the receiving that's not working in mIRC.
In this case, enable the packet sniffer, un the rcon program and stop the sniffer, then check the log for the connection to the server and see what data is sent, and what it should actually be.

I also find the on sockread event handler very strange, I think there's some $bvar problems. Try just writing everything to a file and open that with a hex editor. Make sure to remove or rename the file before each test smile

sockread &data
bwrite rcon.txt -1 -1 &data

#127009 08/08/05 12:07 AM
Joined: Jul 2005
Posts: 40
K
Karas Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
With the sniffer:

17 00 00 00 02 00 00 00 03 00 00 00 61 73 64 61 73 64 61 73 64 61 73 64 61 00 00

So what must i do ? :I

thx xD


j0k3r @ k4s.ch
#127010 08/08/05 12:48 AM
Joined: Jul 2005
Posts: 40
K
Karas Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
i've modified the script: bset &size 1 %packetsize
now with mirc it is:

00000000 17 .
00000001 00 00 00 02 00 00 00 03 61 73 64 61 73 64 61 73 ........ asdasdas
00000011 64 61 73 64 61 00 00 dasda..

and the working must be:

00000000 17 00 00 00 02 00 00 00 03 00 00 00 61 73 64 61 ........ ....asda
00000010 73 64 61 73 64 61 73 64 61 00 00 sdasdasd a..


j0k3r @ k4s.ch
#127011 08/08/05 01:48 AM
Joined: Jul 2005
Posts: 40
K
Karas Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Jul 2005
Posts: 40
AHHAHA ! IT WORKS ! WHAHAHA !!!


on 1:sockopen:rcon: {

bset &requestid 1 0 0 0 1
bset &serverdata 1 0 0 0 3
bset &auth 1 0 0 0 97 115 100 97 115 100 97 115 100 97 115 100 97 0
bset &auth2 1 0

set %packetsize $calc($bvar(&requestid,0) + $bvar(&serverdata,0) + $bvar(&auth,0) + $bvar(&auth2,0) - 3)

bset &all 1 %packetsize $bvar(&requestid,1-) $bvar(&serverdata,1-) $bvar(&auth,1-) $bvar(&auth2,1-)

sockwrite rcon &all

}

my only trouble is that i must subtract 3 bytes i think is because of the red text.. but no problem XDDDD

Ty for all !!! (and thx to Ethereal :angel: )


j0k3r @ k4s.ch
#127012 08/08/05 12:22 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
It's the reverse of what I said:

1 is 00 00 00 01 in bytes, but the bytes are reversed during transport so it becomes 01 00 00 00
258 becomes 02 01 00 00 == 2 + 1*256 + 0*256^2 + 0 * 256^3


alias numtoint {
var %1 = $1, %r
if (%1 !isnum 0-4294967295) return
var %r = $calc(%1 % 256), %1 = $int($calc(%1 / 256))
var %r = %r $calc(%1 % 256), %1 = $int($calc(%1 / 256))
var %r = %r $calc(%1 % 256), %1 = $int($calc(%1 / 256))
var %r = %r $calc(%1 % 256), %1 = $int($calc(%1 / 256))
return %r
}
alias inttonum {
if (!$regex($1-,^(\d+) (\d+) (\d+) (\d+)$)) return
return $calc( ((($regml(4) * 256 + $regml(3) ) * 256 + $regml(2) ) * 256 + $regml(1) ))
}

I colored the output so you know what belongs together:
17 00 00 00 02 00 00 00 03 00 00 00 61 73 64 61 73 64 61 73 64 61 73 64 61 00 00

bset &requestid 1 $numtoint(1)
bset &serverdata 1 $numtoint(3)

bset &auth 1 61 73 64 61 73 64 61 73 64 61 73 64 61 0 0
OR
bset -t &auth1 1 asdfasdasd
; you still need to append the 0 after that text, maybe easiest to just
bset &auth2 1 0 0

var %len = $calc(4+4+ $len(asdfasdasd) +1+1)
bset &len 1 $numtoint(%len)

You can use your solution to append everything to one &binvar, but since you have to convert it back to digits, it can get longer than 900 chars very easily. Just using multiple sockwrites should not give a problem. Otherwise, you can use the /bcopy command to copy everything to a single &binvar without the $bvar conversions.

Glad it works though smile

Last edited by Kelder; 08/08/05 12:46 PM.

Link Copied to Clipboard