140 lines
3.2 KiB
C++
140 lines
3.2 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;
|
||
|
void* nom = &linfo->name;
|
||
|
char* buff = *buf + 1;
|
||
|
|
||
|
size_t namesize = 1;
|
||
|
|
||
|
for (int x = 0; x < sizeof(linfo->name); ++x)
|
||
|
if (linfo->name[x] != (char)'\0')
|
||
|
++namesize;
|
||
|
else break;
|
||
|
|
||
|
memcpy(buff, nom, sizeof(linfo->name));
|
||
|
uint64_t sid = linfo->sid;
|
||
|
char diff[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 };
|
||
|
|
||
|
void* ptrsid = *buf + namesize;
|
||
|
memcpy(ptrsid, &diff, sizeof(uint64_t));
|
||
|
|
||
|
*buflen = sizeof(LoginInfo) + 1;
|
||
|
}
|
||
|
|
||
|
void netprot::Serialize(SelfInfo* sinfo, char* buf[], uint32_t* buflen) {
|
||
|
|
||
|
}
|
||
|
|
||
|
void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
|
||
|
|
||
|
}
|
||
|
|
||
|
void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) {
|
||
|
|
||
|
}
|
||
|
|
||
|
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(sizeof(LoginInfo)) + 1)
|
||
|
return false;
|
||
|
|
||
|
size_t namesize = 0;
|
||
|
|
||
|
for (int x = 0; x < sizeof(linfo->name); ++x)
|
||
|
if (buf[x] != (char)'\0')
|
||
|
++namesize;
|
||
|
else break;
|
||
|
|
||
|
memcpy((void*)&linfo->name, (void*)&buf[1], namesize);
|
||
|
|
||
|
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||
|
memcpy(&diff, &buf[namesize], 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];
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool netprot::Deserialize(SelfInfo* sinfo, char* buf, const uint32_t buflen) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
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];
|
||
|
}
|