231 lines
5.6 KiB
C++
231 lines
5.6 KiB
C++
#include "netprotocol.h"
|
|
|
|
void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
|
|
*buf[0] = netprot::PACKET_TYPE::LOGINF;
|
|
|
|
size_t namesize = std::strlen(linfo->name) + 1;
|
|
|
|
memcpy(*buf + 1, &linfo->name, namesize);
|
|
uint64_t sid = linfo->sid;
|
|
uint8_t sid8[sizeof(uint64_t)] = {
|
|
(sid >> 56) & 0xFF,
|
|
(sid >> 48) & 0xFF,
|
|
(sid >> 40) & 0xFF,
|
|
(sid >> 32) & 0xFF,
|
|
(sid >> 24) & 0xFF,
|
|
(sid >> 16) & 0xFF,
|
|
(sid >> 8) & 0xFF,
|
|
sid & 0xFF
|
|
};
|
|
|
|
memcpy(*buf + namesize + 2, sid8, sizeof(uint64_t));
|
|
|
|
uint64_t tid = linfo->tid;
|
|
uint8_t tid8[sizeof(uint64_t)] = {
|
|
(tid >> 56) & 0xFF,
|
|
(tid >> 48) & 0xFF,
|
|
(tid >> 40) & 0xFF,
|
|
(tid >> 32) & 0xFF,
|
|
(tid >> 24) & 0xFF,
|
|
(tid >> 16) & 0xFF,
|
|
(tid >> 8) & 0xFF,
|
|
tid & 0xFF
|
|
};
|
|
|
|
memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t));
|
|
|
|
*buflen = namesize + sizeof(uint64_t) * 2 + 2;
|
|
}
|
|
|
|
void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
|
|
*buf[0] = netprot::PACKET_TYPE::GAMEINFO;
|
|
|
|
uint64_t game = ginfo->seed;
|
|
uint8_t seed8[sizeof(uint64_t)] = {
|
|
(game >> 56) & 0xFF,
|
|
(game >> 48) & 0xFF,
|
|
(game >> 40) & 0xFF,
|
|
(game >> 32) & 0xFF,
|
|
(game >> 24) & 0xFF,
|
|
(game >> 16) & 0xFF,
|
|
(game >> 8) & 0xFF,
|
|
game & 0xFF
|
|
};
|
|
|
|
memcpy(*buf + 1, seed8, sizeof(uint64_t));
|
|
|
|
game = ginfo->countdown;
|
|
uint8_t count8[sizeof(uint64_t)] = {
|
|
(game >> 56) & 0xFF,
|
|
(game >> 48) & 0xFF,
|
|
(game >> 40) & 0xFF,
|
|
(game >> 32) & 0xFF,
|
|
(game >> 24) & 0xFF,
|
|
(game >> 16) & 0xFF,
|
|
(game >> 8) & 0xFF,
|
|
game & 0xFF
|
|
};
|
|
|
|
memcpy(*buf + sizeof(uint64_t) + 1, count8, sizeof(uint64_t));
|
|
|
|
game = ginfo->countdown;
|
|
uint8_t gtype8[sizeof(uint64_t)] = {
|
|
(game >> 56) & 0xFF,
|
|
(game >> 48) & 0xFF,
|
|
(game >> 40) & 0xFF,
|
|
(game >> 32) & 0xFF,
|
|
(game >> 24) & 0xFF,
|
|
(game >> 16) & 0xFF,
|
|
(game >> 8) & 0xFF,
|
|
game & 0xFF
|
|
};
|
|
|
|
memcpy(*buf + sizeof(uint64_t) + 1, gtype8, sizeof(uint64_t));
|
|
|
|
*buflen = sizeof(uint64_t) * 3 + 1;
|
|
}
|
|
|
|
void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) {
|
|
if (buflen < sizeof(LoginInfo) + 3)
|
|
return false;
|
|
|
|
size_t namesize = std::strlen(buf) + 1;
|
|
|
|
if (namesize > 32)
|
|
return false;
|
|
|
|
memcpy(&linfo->name, &buf[1], namesize);
|
|
|
|
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
|
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
|
|
linfo->sid =
|
|
(uint64_t)diff[0] << 56 |
|
|
(uint64_t)diff[1] << 48 |
|
|
(uint64_t)diff[2] << 40 |
|
|
(uint64_t)diff[3] << 32 |
|
|
(uint64_t)diff[4] << 24 |
|
|
(uint64_t)diff[5] << 16 |
|
|
(uint64_t)diff[6] << 8 |
|
|
(uint64_t)diff[7];
|
|
|
|
memcpy(diff, &buf[namesize + sizeof(uint64_t) + 1], sizeof(uint64_t));
|
|
linfo->tid =
|
|
(uint64_t)diff[0] << 56 |
|
|
(uint64_t)diff[1] << 48 |
|
|
(uint64_t)diff[2] << 40 |
|
|
(uint64_t)diff[3] << 32 |
|
|
(uint64_t)diff[4] << 24 |
|
|
(uint64_t)diff[5] << 16 |
|
|
(uint64_t)diff[6] << 8 |
|
|
(uint64_t)diff[7];
|
|
|
|
return true;
|
|
}
|
|
|
|
bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) {
|
|
if (buflen < sizeof(GameInfo) + 1)
|
|
return false;
|
|
|
|
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
|
memcpy(diff, &buf[1], sizeof(uint64_t));
|
|
ginfo->seed =
|
|
(uint64_t)diff[0] << 56 |
|
|
(uint64_t)diff[1] << 48 |
|
|
(uint64_t)diff[2] << 40 |
|
|
(uint64_t)diff[3] << 32 |
|
|
(uint64_t)diff[4] << 24 |
|
|
(uint64_t)diff[5] << 16 |
|
|
(uint64_t)diff[6] << 8 |
|
|
(uint64_t)diff[7];
|
|
|
|
memcpy(diff, &buf[sizeof(uint64_t) + 1], sizeof(uint64_t));
|
|
ginfo->countdown =
|
|
(uint64_t)diff[0] << 56 |
|
|
(uint64_t)diff[1] << 48 |
|
|
(uint64_t)diff[2] << 40 |
|
|
(uint64_t)diff[3] << 32 |
|
|
(uint64_t)diff[4] << 24 |
|
|
(uint64_t)diff[5] << 16 |
|
|
(uint64_t)diff[6] << 8 |
|
|
(uint64_t)diff[7];
|
|
|
|
memcpy(diff, &buf[sizeof(uint64_t) * 2 + 1], sizeof(uint64_t));
|
|
ginfo->gameType =
|
|
(uint64_t)diff[0] << 56 |
|
|
(uint64_t)diff[1] << 48 |
|
|
(uint64_t)diff[2] << 40 |
|
|
(uint64_t)diff[3] << 32 |
|
|
(uint64_t)diff[4] << 24 |
|
|
(uint64_t)diff[5] << 16 |
|
|
(uint64_t)diff[6] << 8 |
|
|
(uint64_t)diff[7];
|
|
|
|
return true;
|
|
}
|
|
|
|
bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) {
|
|
return false;
|
|
}
|
|
|
|
netprot::PacketType netprot::getType(char* buf, const uint32_t buflen) {
|
|
if (buflen < 1 ||
|
|
buf[0] >= netprot::PACKET_TYPE::LAST_PACK ||
|
|
buf[0] <= netprot::PACKET_TYPE::ERR)
|
|
return netprot::PACKET_TYPE::ERR;
|
|
return buf[0];
|
|
}
|