🚫 👂 🐆

This commit is contained in:
MarcEricMartel
2023-12-09 12:02:04 -05:00
parent 63d70be488
commit 9aaad6426c
11 changed files with 130 additions and 74 deletions

View File

@@ -38,11 +38,10 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
if (chunkmod) {
using namespace netprot;
ChunkMod* cmod = *chunkmod;
cmod = new ChunkMod();
cmod->old_b_type = world->BlockAt(m_currentpos);
cmod->b_type = BTYPE_AIR;
cmod->pos = m_currentpos;
*chunkmod = new ChunkMod();
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
(*chunkmod)->b_type = BTYPE_AIR;
(*chunkmod)->pos = m_currentpos;
}
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);

View File

@@ -198,7 +198,7 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
(uint8_t)((vec[2] >> 8) & 0xFF),
(uint8_t)(vec[2] & 0xFF) };
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3);
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, vec8, sizeof(uint32_t) * 3);
uint32_t hp;
@@ -210,6 +210,8 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
(uint8_t)((hp >> 8) & 0xFF),
(uint8_t)(hp & 0xFF) };
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 1, hp8, sizeof(float));
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1;
}
@@ -218,7 +220,8 @@ void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
size_t namesize = std::strlen(tinfo->name) + 1;
memcpy(*buf + 1, &tinfo->name, namesize);
strcpy(*buf + 1, namesize, tinfo->name);
uint64_t tid = tinfo->id;
uint8_t tid8[sizeof(uint64_t)] = {
(uint8_t)((tid >> 56) & 0xFF),
@@ -241,7 +244,8 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) {
size_t namesize = std::strlen(linfo->name) + 1;
memcpy(*buf + 1, &linfo->name, namesize);
strcpy(*buf + 1, namesize, linfo->name);
uint64_t sid = linfo->sid;
uint8_t sid8[sizeof(uint64_t)] = {
(uint8_t)((sid >> 56) & 0xFF),
@@ -278,7 +282,8 @@ void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) {
size_t namesize = std::strlen(pinfo->name) + 1;
memcpy(*buf + 1, &pinfo->name, namesize);
strcpy(*buf + 1, namesize, pinfo->name);
uint64_t id = pinfo->id;
uint8_t id8[sizeof(uint64_t)] = {
(uint8_t)((id >> 56) & 0xFF),
@@ -703,7 +708,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
uint32_t vec[3] = {
(uint32_t)subvec[0] << 24 |
(uint32_t)subvec[1] << 16 |
@@ -722,7 +727,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
uint8_t hp8[4];
memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
memcpy(&hp8, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
uint32_t hp = (uint32_t)hp8[0] << 24 |
(uint32_t)hp8[1] << 16 |
@@ -731,7 +736,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
memcpy(&sync->hp, &hp, sizeof(float));
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
return true;
}
@@ -745,7 +750,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen) {
if (namesize > 32)
return false;
memcpy(&tinfo->name, &buf[1], namesize);
strcpy(tinfo->name, namesize, &buf[1]);
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
@@ -773,7 +778,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen) {
if (namesize > 32)
return false;
memcpy(&linfo->name, &buf[1], namesize);
strcpy(linfo->name, namesize, &buf[1]);
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));
@@ -812,7 +817,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen) {
if (namesize > 32)
return false;
memcpy(&pinfo->name, &buf[1], namesize);
strcpy(pinfo->name, namesize, &buf[1]);
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
memcpy(diff, &buf[namesize + 1], sizeof(uint64_t));

View File

@@ -19,7 +19,7 @@ namespace netprot {
/* Structures */
struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
char* ptr = new char[BUFFER_LENGTH] { 1 }, * tmp = nullptr;
char *ptr = new char[BUFFER_LENGTH] { 1 }, *tmp = nullptr;
uint32_t len = BUFFER_LENGTH;
~Buffer() { delete[] ptr; }
@@ -27,7 +27,7 @@ namespace netprot {
};
struct Packet { // Pour pouvoir recevoir les paquets du recv() sans avoir à les aiguiller dans la même thread.
void* ptr = nullptr; // Notez que le pointeur doit être supprimé séparément lorsqu'il n'est plus utile.
void *ptr = nullptr; // Notez que le pointeur doit être supprimé séparément lorsqu'il n'est plus utile.
PACKET_TYPE type = PACKET_TYPE::ERR;
};
@@ -87,30 +87,30 @@ namespace netprot {
};
struct TeamInfo { // cli <-> srv TCP once
char name[32];
char *name = new char[32];
uint64_t id = 0;
TeamInfo() {}
TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(tem->name, name); }
TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(name, 32, tem->name); }
~TeamInfo() { delete[] name; }
};
struct LoginInfo { // cli <-> srv TCP once
char name[32];
char *name = new char[32];
uint64_t sid = 0,
tid = 0;
LoginInfo() {}
LoginInfo(LoginInfo* ply): sid(ply->sid), tid(ply->tid) { strcpy(ply->name, name); }
LoginInfo(LoginInfo* log): sid(log->sid), tid(log->tid) { strcpy(name, 32, log->name); }
~LoginInfo() { delete[] name; }
};
struct PlayerInfo { // cli <-> srv TCP once
char name[32];
char *name = new char[32];
uint64_t id = 0,
tid = 0;
PlayerInfo() {}
PlayerInfo(PlayerInfo* log) : id(log->id), tid(log->tid) {
strcpy(log->name, name);
};
PlayerInfo(int id, int tid, std::string strname) : id(id), tid(tid) { memcpy((void*)strname.c_str(), name, strname.length());
}
PlayerInfo(PlayerInfo* ply) : id(ply->id), tid(ply->tid) { strcpy(name, 32, ply->name); };
PlayerInfo(int id, int tid, std::string strname) : id(id), tid(tid) { strcpy(name, 32, strname.c_str()); }
~PlayerInfo() { delete[] name; }
};
struct GameInfo { // cli <-> srv TCP event (before game start)/ once
@@ -125,10 +125,9 @@ namespace netprot {
uint64_t src_id = 0,
dest_id = 0,
dest_team_id = 0;
char* mess = new char[140]; // Good 'nough for twitr, good 'nough for me.
char *mess = new char[140]; // Good 'nough for twitr, good 'nough for me.
Chat() {}
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) {
strcpy(mess, 140, cha->mess); }
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(mess, 140, cha->mess); }
~Chat() { delete[] mess; }
};
@@ -144,10 +143,11 @@ namespace netprot {
};
struct ErrorLog { // srv -> cli TCP event
char mess[140];
bool is_fatal;
char *mess = new char[140];
bool is_fatal = false;
ErrorLog() {};
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(err->mess, mess); }
ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(mess, 140, err->mess); }
~ErrorLog() { delete[] mess; }
};
/* Fonctions */