un tipeu de cleanup
This commit is contained in:
parent
0ef437600d
commit
ab84e42c72
@ -1017,6 +1017,7 @@ void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, Buffer* buf)
|
||||
return;
|
||||
case PACKET_TYPE::CHUNKMOD:
|
||||
//sendPack<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf);
|
||||
return;
|
||||
case PACKET_TYPE::PLAYERMOD:
|
||||
//sendPack<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf);
|
||||
return;
|
||||
|
@ -16,6 +16,8 @@ namespace netprot {
|
||||
LAST_PACK
|
||||
};
|
||||
|
||||
/* Structures */
|
||||
|
||||
struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
|
||||
char* ptr = new char[BUFFER_LENGTH] { 1 };
|
||||
uint32_t len = BUFFER_LENGTH;
|
||||
@ -29,8 +31,12 @@ namespace netprot {
|
||||
PACKET_TYPE type = PACKET_TYPE::ERR;
|
||||
};
|
||||
|
||||
/* Constantes */
|
||||
|
||||
inline const char Footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' }; // constante de footer qui est ajoutée à chaque paquet envoyé.
|
||||
|
||||
/* Sous-structures */
|
||||
|
||||
struct Keys {
|
||||
bool forward,
|
||||
backward,
|
||||
@ -52,6 +58,8 @@ namespace netprot {
|
||||
running;
|
||||
};
|
||||
|
||||
/* Structures de paquets */
|
||||
|
||||
struct Input { // cli -> srv UDP ~frame
|
||||
Timestamp timestamp;
|
||||
uint64_t sid = 0;
|
||||
@ -125,6 +133,8 @@ namespace netprot {
|
||||
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(err->mess, mess); }
|
||||
};
|
||||
|
||||
/* Fonctions */
|
||||
|
||||
void Serialize(Input* in, char* buf[], uint32_t* buflen); // cli
|
||||
void Serialize(Output* out, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(Sync* sync, char* buf[], uint32_t* buflen); // srv
|
||||
@ -154,6 +164,8 @@ namespace netprot {
|
||||
|
||||
Packet makePack(void* ptr, PACKET_TYPE type); // Pour pouvoir faire une liste de stock a supprimer sans avoir a en faire une pour chaque type.
|
||||
|
||||
template <class T> T copyPack(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);
|
||||
|
||||
@ -162,6 +174,11 @@ namespace netprot {
|
||||
|
||||
std::vector<char*> recvPacks(SOCKET sock, Buffer* buf);
|
||||
|
||||
/* Templates */
|
||||
|
||||
template <class T>
|
||||
T copyPack(Packet* pck) { return T((T*)pck->ptr); }
|
||||
|
||||
template <class T>
|
||||
void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) {
|
||||
netprot::Serialize(pack, buf, buflen);
|
||||
|
Loading…
Reference in New Issue
Block a user