Fix to multiplayer out of sync issue
The fix works, but if someone could review it, that would be great!
This commit is contained in:
parent
b84bb69423
commit
87d4a68c27
1 changed files with 26 additions and 7 deletions
|
@ -98,11 +98,19 @@ size_t serialize(unsigned char *buf, const std::string &s)
|
|||
buf += serialize16(buf, uint16_t(s.size()));
|
||||
memcpy(buf, s.c_str(), s.size());
|
||||
buf += s.size();
|
||||
//Wyrmgus start
|
||||
//Andrettin: fix to the multiplayer OOS issue - the fix works, but it would be better if someone reviewed the code! I am leaving the Wyrmgus tags on these changes until the code has been properly reviewed
|
||||
/*
|
||||
if ((s.size() & 0x03) != 0) {
|
||||
memset(buf, 0, s.size() & 0x03);
|
||||
}
|
||||
*/
|
||||
//Wyrmgus end
|
||||
}
|
||||
return 2 + ((s.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
//Wyrmgus start
|
||||
// return 2 + ((s.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
return 2 + (s.size() + 3);
|
||||
//Wyrmgus end
|
||||
}
|
||||
size_t serialize(unsigned char *buf, const std::vector<unsigned char> &data)
|
||||
{
|
||||
|
@ -113,11 +121,16 @@ size_t serialize(unsigned char *buf, const std::vector<unsigned char> &data)
|
|||
buf += serialize16(buf, uint16_t(data.size()));
|
||||
memcpy(buf, &data[0], data.size());
|
||||
buf += data.size();
|
||||
if ((data.size() & 0x03) != 0) {
|
||||
memset(buf, 0, data.size() & 0x03);
|
||||
}
|
||||
//Wyrmgus start
|
||||
// if ((data.size() & 0x03) != 0) {
|
||||
// memset(buf, 0, data.size() & 0x03);
|
||||
// }
|
||||
//Wyrmgus end
|
||||
}
|
||||
return 2 + ((data.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
//Wyrmgus start
|
||||
// return 2 + ((data.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
return 2 + (data.size() + 3);
|
||||
//Wyrmgus end
|
||||
}
|
||||
|
||||
size_t deserialize32(const unsigned char *buf, uint32_t *data)
|
||||
|
@ -162,7 +175,10 @@ size_t deserialize(const unsigned char *buf, std::string &s)
|
|||
|
||||
buf += deserialize16(buf, &size);
|
||||
s = std::string(reinterpret_cast<const char *>(buf), size);
|
||||
return 2 + ((s.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
//Wyrmgus start
|
||||
// return 2 + ((s.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
return 2 + (s.size() + 3);
|
||||
//Wyrmgus end
|
||||
}
|
||||
size_t deserialize(const unsigned char *buf, std::vector<unsigned char> &data)
|
||||
{
|
||||
|
@ -170,7 +186,10 @@ size_t deserialize(const unsigned char *buf, std::vector<unsigned char> &data)
|
|||
|
||||
buf += deserialize16(buf, &size);
|
||||
data.assign(buf, buf + size);
|
||||
return 2 + ((data.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
//Wyrmgus start
|
||||
// return 2 + ((data.size() + 3) & ~0x03); // round up to multiple of 4 for alignment.
|
||||
return 2 + (data.size() + 3);
|
||||
//Wyrmgus end
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue