Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Packet sending long ignores 3 bytes?

Joined
Aug 14, 2009
Messages
2,304
Reaction score
1,189
So because I'm kind of lost, and to be honest.. Frustrated. Can somebody help me with this?

This is how I sent my data to the server (So basically the "client")
PHP:
$ip = '127.0.0.1';
$queryport = 34005;

$socket =  [USER=493081]fsockopen[/USER]("udp://".$ip, $queryport , $errno, $errstr, 1);

stream_set_timeout($socket, 1);
stream_set_blocking($socket, TRUE);
fwrite($socket, "\xFF\xFF\xFF\xFF\x56\x00\x00\x00\x1");
$response = fread($socket, 4096);
@fclose($socket);

header('Content-type: text/plain');
hex_dump($response);

This should result in:
Code:
ID = -1
Header = 0x56 / 86 (int)
SuperID = 1

But.. My server is getting everything right. Except SuperID. Which is:
Code:
3452816641 (ulong / DWORD) / cdcdcd01 (Hex)

The server is simply just reintpret_cast to my struct. Which is:
Code:
struct A2S_SUPERINFO
{
	long id;
	BYTE header;
	DWORD superId;
};

And after testing a while. The following works.
PHP:
fwrite($socket, "\xFF\xFF\xFF\xFF\x56\x00\x00\x00\x1\x00\x00\x00");

Somehow.. The c++ server ignores the first 3 bytes of the superid.

My question now is.. Why

EDIT:
Also this:
PHP:
fwrite($socket, "\xFF\xFF\xFF\xFF\x56\x1\x00\x00\x00");

Results in:
Code:
3452816640 / cdcdcd00

If somebody wonders.. I'm outputting the superID like this:
Code:
printf("%lu / %lx\n", p->superId, p->superId);
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
I'm no expert, but it's probably due to struct padding. From what I know compiler translates your struct to something like:

Code:
struct A2S_SUPERINFO
{
    long id;
    BYTE header;
    BYTE padding0;
    BYTE padding1;
    BYTE padding2;
    DWORD superId;
};

If you're using Visual Studio you can remove the padding with(from SO):
Code:
[COLOR=#848A91]#pragma[/COLOR][COLOR=#2E3133] pack[/COLOR][COLOR=#2E3133]([/COLOR][COLOR=#2E3133]push[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#6B291B]1[/COLOR][COLOR=#2E3133])
[/COLOR][COLOR=#00008B]struct[/COLOR][COLOR=#2E3133] foo [/COLOR][COLOR=#2E3133]{[/COLOR][COLOR=#2E3133] 
  [/COLOR][COLOR=#848A91]// etc..[/COLOR][COLOR=#2E3133]
[/COLOR][COLOR=#2E3133]};[/COLOR][COLOR=#2E3133]
[/COLOR][COLOR=#848A91]#pragma[/COLOR][COLOR=#2E3133] pack[/COLOR][COLOR=#2E3133]([/COLOR][COLOR=#2E3133]pop[/COLOR][COLOR=#2E3133])
[/COLOR]
 
Last edited:
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
What happens if you assemble the data in a human-friendly way, as opposed to "\xFF\xFF\xFF\xFF\x56\x00\x00\x00\x1\x00\x00\x00"?

I should ask what the purpose of this is.. Are you trying to make a relay service in PHP or something? The C++ program appears to be local.. If that's going to be the case forever, might a pipe be more appropriate than a UDP socket?
 
Last edited:
Joined
Aug 14, 2009
Messages
2,304
Reaction score
1,189
The purpose of using hex codes is a UDP query. Kind of like the Source Query Protocol.



And no. The server is currently local for development purposes. But after I'm finished I have something like this:

Webserver (mydomain.com / 192.168.178.30) -> PHP Calls socket via UDP -> Checks online status of server (server.mydomain.com / 192.168.178.31)

AcarX
lol. I forgot about that part. Thanks. It works now ;)

The thread can be closed :)
 
Back
Top