ajout LoginInfo dans le parseur de paquet.

This commit is contained in:
MarcEricMartel
2023-10-25 10:00:54 -04:00
parent 4964bc5394
commit dd2396e5e4
3 changed files with 108 additions and 164 deletions

View File

@@ -571,46 +571,89 @@ netprot::Packet netprot::getPack(char* buf, uint32_t buflen) {
Chat* chat = nullptr;
GameInfo* ginfo = nullptr;
ErrorLog* errlog = nullptr;
LoginInfo* loginf = nullptr;
switch (getType(buf, buflen)) {
case PACKET_TYPE::INPUT:
in = new Input();
netprot::Deserialize(in, buf, buflen);
pck.type = PACKET_TYPE::INPUT;
pck.ptr = (void*)in;
if (netprot::Deserialize(in, buf, buflen)) {
pck.type = PACKET_TYPE::INPUT;
pck.ptr = (void*)in;
}
break;
case PACKET_TYPE::OUTPUT:
out = new Output();
netprot::Deserialize(out, buf, buflen);
pck.type = PACKET_TYPE::OUTPUT;
pck.ptr = (void*)out;
if (netprot::Deserialize(out, buf, buflen)) {
pck.type = PACKET_TYPE::OUTPUT;
pck.ptr = (void*)out;
}
break;
case PACKET_TYPE::SYNC:
sync = new Sync();
netprot::Deserialize(sync, buf, buflen);
pck.type = PACKET_TYPE::SYNC;
pck.ptr = (void*)sync;
if (netprot::Deserialize(sync, buf, buflen)) {
pck.type = PACKET_TYPE::SYNC;
pck.ptr = (void*)sync;
}
break;
case PACKET_TYPE::CHAT:
chat = new Chat();
netprot::Deserialize(chat, buf, buflen);
pck.type = PACKET_TYPE::CHAT;
pck.ptr = (void*)chat;
if (netprot::Deserialize(chat, buf, buflen)) {
pck.type = PACKET_TYPE::CHAT;
pck.ptr = (void*)chat;
}
break;
case PACKET_TYPE::GAMEINFO:
ginfo = new GameInfo();
netprot::Deserialize(ginfo, buf, buflen);
pck.type = PACKET_TYPE::GAMEINFO;
pck.ptr = (void*)ginfo;
if (netprot::Deserialize(ginfo, buf, buflen)) {
pck.type = PACKET_TYPE::GAMEINFO;
pck.ptr = (void*)ginfo;
}
break;
case PACKET_TYPE::ERRLOG:
errlog = new ErrorLog();
netprot::Deserialize(errlog, buf, buflen);
pck.type = PACKET_TYPE::ERRLOG;
pck.ptr = (void*)errlog;
if (netprot::Deserialize(errlog, buf, buflen)) {
pck.type = PACKET_TYPE::ERRLOG;
pck.ptr = (void*)errlog;
}
break;
case PACKET_TYPE::LOGINF:
loginf = new LoginInfo();
if (netprot::Deserialize(loginf, buf, buflen)) {
pck.type = PACKET_TYPE::LOGINF;
pck.ptr = (void*)loginf;
}
break;
default:
break;
}
return pck;
}
bool netprot::emptyPack(netprot::Packet pck) {
switch (pck.type) {
case PACKET_TYPE::INPUT:
delete (Input*)pck.ptr;
break;
case PACKET_TYPE::OUTPUT:
delete (Output*)pck.ptr;
break;
case PACKET_TYPE::SYNC:
delete (Sync*)pck.ptr;
break;
case PACKET_TYPE::CHAT:
delete (Chat*)pck.ptr;
break;
case PACKET_TYPE::GAMEINFO:
delete (GameInfo*)pck.ptr;
break;
case PACKET_TYPE::ERRLOG:
delete (ErrorLog*)pck.ptr;
break;
case PACKET_TYPE::LOGINF:
delete (LoginInfo*)pck.ptr;
break;
default:
return false;
}
return true;
}

View File

@@ -20,7 +20,7 @@ namespace netprot {
};
struct Packet {
void* ptr;
void* ptr = nullptr;
PACKET_TYPE type;
};
@@ -120,9 +120,10 @@ namespace netprot {
bool Deserialize(Chat* chat, char* buf, const uint32_t buflen); // srv/cli
bool Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen); // srv
PacketType getType(char* buf, uint32_t buflen); // srv/cli
PacketType getType(char* buf, uint32_t buflen);
Packet getPack(char* buf, uint32_t buflen);
bool emptyPack(Packet pck);
template <class T> void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen);
template <class T> void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad);