Forum Moderators: coopster

Message Too Old, No Replies

converting perl vec script to php

perl to php conversion

         

phazei

7:37 am on Jan 30, 2007 (gmt 0)

10+ Year Member



I have a perl script and I was able to covert the socket connection part just fine. But I have NO idea as to what this vec stuff does. I looked up the vec function and saw it was a bit vector function, but even after looking at how it works I'm still clueless... heh.

# send P_SET_BOARD packet (15)
vec($line, 0, 8) = 0x0f; # board_id packet
vec($line, 1, 8) = $board_id >> 24;
vec($line, 2, 8) = ($board_id>>16) & 0xff;
vec($line, 3, 8) = ($board_id>>8) & 0xff;
vec($line, 4, 8) = $board_id & 0xff;
vec($line, 5, 8) = 0; # high byte of password length
vec($line, 6, 8) = 0; # low byte of password length
syswrite SOCKET, $line, 7;

# Read the 1-byte response from server:
# 16 = P_ENTER_BOARD (followed by 2-byte integer giving number of users,
# followed by other data about the board
# 17 = P_ERROR (followed by string)
# 18 = P_TOO_MANY_USERS

sysread(SOCKET, $line, 1);
if (vec($line, 0, 8) == 0x10)
{
# Read number of users
sysread(SOCKET, $line, 2);
my $users = vec($line, 0, 16);
print $users;
}

The sysread/write stuff I can figure out, but I haven't a clue what to do with the vec stuff. Could someone please help. I don't have perl and don't even know how to run it on our server to see what the results of the vecs are.

Help, please,
Adam

phazei

7:43 am on Jan 30, 2007 (gmt 0)

10+ Year Member



Sorry, forgot to mention that $board_id is a 5 digit number.

Also wasn't sure to post this in the perl or php forum, I hope this one is ok.

phazei

9:25 am on Jan 30, 2007 (gmt 0)

10+ Year Member



ok, so I've been reading these:
[developertutorials.com...]
[gamedev.net...]

And I'm guessing vec is just converting the $board_id number to hex...

But I'm a bit confused because my board_id is in the 90,000's so it would require a 32bit since it's just beyond 16bit.
It looks like it's only working with 1 byte, I think.

I'm still lost, but I'm really trying here... heh.