I've got everything working the way it should except for one problem:
Whenever i try to use "ReadChars" it cuts short for the null characters. This has been trialled and tested and confirmed.
Because of the complexity of the issue, a GML source won't be extremely helpful, but anyway...
if (peekmessage(client,0,clientbuffer) > 4) {
complete = readchars(buffsize(clientbuffer),clientbuffer);
//show_message("CLIENT SENDS")
clearbuffer(clientbuffer);
receivemessage(client,4,clientbuffer);
lengthpacket = real(readuint(clientbuffer));
//show_message("LENGTH= :" + string(lengthpacket) + ":")
receivemessage(client,4,clientbuffer);
type = real(readuint(clientbuffer));
//show_message("TYPE = :" + string(type) + ":")
receivemessage(client,lengthpacket-4,clientbuffer);
data = readchars(lengthpacket-4,clientbuffer);
//show_message("DATA = :" + string(string_length(data)) + ":")
clearbuffer(clientbuffer);
//writeuint(real(lengthpacket),clientbuffer);
//show_message("size length: " + string(real(buffsize(clientbuffer))))
//writeuint(real(type),clientbuffer);
//show_message("size type: " + string(real(buffsize(clientbuffer))-4))
//writechars(string(data),clientbuffer);
//show_message("size data: " + string(real(buffsize(clientbuffer))-8))
//show_message("size final: " + string(real(buffsize(clientbuffer))))
//input = readchars(24,clientbuffer)
//clearbuffer(clientbuffer);
//show_message("INPUT = %" + input + "%")
show_message(str2hex(complete)) //A simple debug script to show the raw packet data.
//show_message("length: " + string(length) + "#type: " + string(type) + "#data: " + string(data))
switch (real(type)) {
case (1): show_message("LoginPacketData: " + string(data))break; //login packet
}
sendmessage(server, "", 0, clientbuffer) //socket, ip, port, buffer
clearbuffer(clientbuffer);
}EXPECTED PACKET:
[UnsignedInt-SizeOfPacket(MinusThisInteger)][UnsignedInt-ThePacketTypeID][Characters-ThePacketData]So that's:4bytes:4bytes:restofthedataexample:18:00:00:00:01:00:00:00:64:6f:69:6e:67:5f:74:65:73:74:73:00:00:00:00:00:7f:db:32:01
Packet I am working with:
"[int-24]" + "[int-01]"+ "[YSRAAF][ACM]Fl" + "[NULL]" + "[int-20110207]"
This particular code is a login packet, which contains 1 int for size, 1 int for type, 16 bytes (last byte is always "NULL") username, 1 int for version.
What my code ends up reading:
Size: 24 (Correct)
Type: 1 (Correct)
Length Data: 15 (Incorrect, is terminated by the "NULL")
Data: "[YSRAAF][ACM]Fl" (Should also have "NULL" plus int-20110207)
LONG STORY SHORT:
How can I get readchars to work around the "null" character termination so that the variable "data" becomes length 20 instead of 15?
Thanks for any help!
Edited by OfficerFlake, 03 February 2012 - 04:13 AM.











