Bug?
- Tank Program
- Forum & Project Admin, PhD
- Posts: 6711
- Joined: Thu Dec 18, 2003 7:03 pm
- Tank Program
- Forum & Project Admin, PhD
- Posts: 6711
- Joined: Thu Dec 18, 2003 7:03 pm
- wrtlprnft
- Reverse Outside Corner Grinder
- Posts: 1679
- Joined: Wed Jan 04, 2006 4:42 am
- Location: 0x08048000
- Contact:
I finally figured it out:
Arma encodes all network traffic as 16- bit integers. Therefore, to send a string (like the player names), the individual characters are paired together, the first char of each pair becoming the lower byte of the new short, the second thar becoming the upper byte.
At least that's what tank was probably thinking when he originally wrote the script (and nobody noticed it afterwards).
Well, what actually happens is this:(nNetwork.cpp:~985)
It multiplies the second char by 256 and adds that to the first char to get the short to be sent. This works alright until the first char gets bigger than 127. Because sRaw is a signed char* sRaw is actually a negative number and gets subtracted from (sRaw[i+1] << 8), therefore causing some mess (the second char's ascii value gets lowered by 1).
Anyways, here's my fix. I don't know exactly how robust/correct/ugly it is, but it appears to work:becomes
Arma encodes all network traffic as 16- bit integers. Therefore, to send a string (like the player names), the individual characters are paired together, the first char of each pair becoming the lower byte of the new short, the second thar becoming the upper byte.
At least that's what tank was probably thinking when he originally wrote the script (and nobody noticed it afterwards).
Well, what actually happens is this:
Code: Select all
char const * sRaw = s;
// write first pairs of bytes
for(i=0;i+1<len;i+=2)
Write(sRaw[i]+(sRaw[i+1] << 8));
It multiplies the second char by 256 and adds that to the first char to get the short to be sent. This works alright until the first char gets bigger than 127. Because sRaw is a signed char* sRaw is actually a negative number and gets subtracted from (sRaw[i+1] << 8), therefore causing some mess (the second char's ascii value gets lowered by 1).
Anyways, here's my fix. I don't know exactly how robust/correct/ugly it is, but it appears to work:
Code: Select all
for ($c = 0; $c < strlen($this->rawpacket); $c = $c + 2)
{
$this->swappedpacket[$c] = $this->rawpacket[$c + 1];
$this->swappedpacket[$c + 1] = $this->rawpacket[$c];
}
Code: Select all
for ($c = 0; $c < strlen($this->rawpacket); $c = $c + 2)
{
$this->swappedpacket[$c] = $this->rawpacket[$c + 1];
$this->swappedpacket[$c + 1] = $this->rawpacket[$c];
if(ord($this->swappedpacket[$c]) > 127) {
$this->swappedpacket[$c + 1] = chr(1 + ord($this->swappedpacket[$c + 1])) ;
}
}
There's no place like ::1
- Tank Program
- Forum & Project Admin, PhD
- Posts: 6711
- Joined: Thu Dec 18, 2003 7:03 pm
- wrtlprnft
- Reverse Outside Corner Grinder
- Posts: 1679
- Joined: Wed Jan 04, 2006 4:42 am
- Location: 0x08048000
- Contact:
It appears to work so I committed it to aabeta. I also changedto. I don't think that extra short is used from anywhere inside arma. Just because it took me a while to figure out, here's what the first shorts of a nMessage mean:
Code: Select all
$query = pack("xCxxxxxC", 0x35, 0x11);
Code: Select all
$query = pack("xCxxxx", 0x35);
- Packet “type”
- Packet ID
- Length of the actual message
There's no place like ::1
- Tank Program
- Forum & Project Admin, PhD
- Posts: 6711
- Joined: Thu Dec 18, 2003 7:03 pm