Compare commits

...

11 Commits

Author SHA1 Message Date
MarcEricMartel
63d70be488 Make player spawn point random working? 2023-12-08 05:07:05 -05:00
MarcEricMartel
3da68297e4 Cleanup + client. 2023-12-08 04:58:27 -05:00
MarcEricMartel
34976ef7ec /* delete[] mess */ Well there's your mem leak. 2023-12-08 04:55:00 -05:00
MarcEricMartel
7d46536acc Can now clean bullets off the forest. 2023-12-08 04:31:10 -05:00
MarcEricMartel
7e98eeb852 whyyyyyyyyy 2023-12-07 15:47:31 -05:00
MarcEricMartel
db95c6ef10 Merge branch 'SQC-15_online' of https://github.com/CegepSTH/SQCSim2023 into SQC-15_online 2023-12-07 15:14:24 -05:00
MarcEricMartel
486c823da1 OH 2023-12-07 15:14:16 -05:00
Claudel-D-Roy
fcd1c869b9 Enlever les commentaires 2023-12-07 15:13:45 -05:00
MarcEricMartel
8bfee4a9ff :Q 2023-12-07 14:24:09 -05:00
Claudel-D-Roy
58c97587bf Merge branch 'SQC-15_online' of https://github.com/CegepSTH/SQCSim2023 into SQC-15_online 2023-12-07 14:04:38 -05:00
MarcEricMartel
ab87da7d88 Ehm. 2023-12-07 14:03:58 -05:00
8 changed files with 95 additions and 112 deletions

View File

@ -16,11 +16,9 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
for (auto& [key, player] : mapPlayer) { for (auto& [key, player] : mapPlayer) {
bool hit = false; bool hit = false;
if ((m_currentpos - player->GetPosition()).Length() < .6f) { if ((m_currentpos - player->GetPosition()).Length() < .6f) {
std::cout << "hit" << std::endl;
hit = true; hit = true;
} }
if ((m_currentpos - player->GetPOV()).Length() < .2f) { if ((m_currentpos - player->GetPOV()).Length() < .2f) {
std::cout << "headshot" << std::endl;
damage *= 2; // HEADSHOT! damage *= 2; // HEADSHOT!
hit = true; hit = true;
} }

View File

@ -29,13 +29,13 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
Keys keys = in->keys; Keys keys = in->keys;
uint8_t keys8 = // Reste un bit. uint8_t keys8 = // Reste un bit.
(keys.forward? 0b10000000: 0) | (keys.forward ? 0b10000000 : 0) |
(keys.backward? 0b01000000: 0) | (keys.backward ? 0b01000000 : 0) |
(keys.left? 0b00100000: 0) | (keys.left ? 0b00100000 : 0) |
(keys.right? 0b00010000: 0) | (keys.right ? 0b00010000 : 0) |
(keys.jump? 0b00001000: 0) | (keys.jump ? 0b00001000 : 0) |
(keys.shoot? 0b00000100: 0) | (keys.shoot ? 0b00000100 : 0) |
(keys.block? 0b00000010: 0); (keys.block ? 0b00000010 : 0);
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t)); memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
@ -90,14 +90,14 @@ void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
States states = out->states; States states = out->states;
uint8_t states8 = uint8_t states8 =
(states.jumping? 0b10000000: 0) | (states.jumping ? 0b10000000 : 0) |
(states.shooting? 0b01000000: 0) | (states.shooting ? 0b01000000 : 0) |
(states.hit? 0b00100000: 0) | (states.hit ? 0b00100000 : 0) |
(states.powerup? 0b00010000: 0) | (states.powerup ? 0b00010000 : 0) |
(states.dead? 0b00001000: 0) | (states.dead ? 0b00001000 : 0) |
(states.still? 0b00000100: 0) | (states.still ? 0b00000100 : 0) |
(states.jumpshot? 0b00000010: 0) | (states.jumpshot ? 0b00000010 : 0) |
(states.running? 0b00000001: 0); (states.running ? 0b00000001 : 0);
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &states8, sizeof(uint8_t)); memcpy(*buf + sizeof(uint64_t) * 2 + 1, &states8, sizeof(uint8_t));
@ -204,7 +204,7 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
memcpy(&hp, &sync->hp, sizeof(float)); memcpy(&hp, &sync->hp, sizeof(float));
uint8_t hp8[4] = { uint8_t hp8[4] = {
(uint8_t)((hp >> 24) & 0xFF), (uint8_t)((hp >> 24) & 0xFF),
(uint8_t)((hp >> 16) & 0xFF), (uint8_t)((hp >> 16) & 0xFF),
(uint8_t)((hp >> 8) & 0xFF), (uint8_t)((hp >> 8) & 0xFF),
@ -523,7 +523,7 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) { bool netprot::Deserialize(Input* in, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(Input)) if (*buflen <= sizeof(Input))
return false; return false;
@ -538,7 +538,7 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
(uint64_t)diff[5] << 16 | (uint64_t)diff[5] << 16 |
(uint64_t)diff[6] << 8 | (uint64_t)diff[6] << 8 |
(uint64_t)diff[7]; (uint64_t)diff[7];
memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
in->sid = in->sid =
(uint64_t)diff[0] << 56 | (uint64_t)diff[0] << 56 |
@ -583,7 +583,7 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) { bool netprot::Deserialize(Output* out, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(Output)) if (*buflen <= sizeof(Output))
return false; return false;
@ -662,7 +662,7 @@ bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) { bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(Sync)) if (*buflen <= sizeof(Sync))
return false; return false;
@ -725,9 +725,9 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t)); memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
uint32_t hp = (uint32_t)hp8[0] << 24 | uint32_t hp = (uint32_t)hp8[0] << 24 |
(uint32_t)hp8[1] << 16 | (uint32_t)hp8[1] << 16 |
(uint32_t)hp8[2] << 8 | (uint32_t)hp8[2] << 8 |
(uint32_t)hp8[3]; (uint32_t)hp8[3];
memcpy(&sync->hp, &hp, sizeof(float)); memcpy(&sync->hp, &hp, sizeof(float));
@ -736,7 +736,7 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t *buflen) { bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(LoginInfo)) if (*buflen <= sizeof(LoginInfo))
return false; return false;
@ -764,7 +764,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t *buflen) { bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(LoginInfo)) if (*buflen <= sizeof(LoginInfo))
return false; return false;
@ -803,7 +803,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t *buflen) { bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(PlayerInfo)) if (*buflen <= sizeof(PlayerInfo))
return false; return false;
@ -842,7 +842,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t *buflen) { bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(GameInfo)) if (*buflen <= sizeof(GameInfo))
return false; return false;
@ -885,7 +885,7 @@ bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t *buflen) {
return true; return true;
} }
bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) { bool netprot::Deserialize(Chat* chat, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(Chat)) if (*buflen <= sizeof(Chat))
return false; return false;
@ -935,7 +935,7 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) {
strcpy(chat->mess, 140, ciboire); strcpy(chat->mess, 140, ciboire);
//*buflen = messsize + sizeof(uint64_t) * 3 + 1; //*buflen = messsize + sizeof(uint64_t) * 3 + 1;
return true; return true;
} }
@ -1037,7 +1037,7 @@ bool netprot::Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen) {
return true; return true;
} }
bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t *buflen) { bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) {
if (*buflen <= sizeof(ErrorLog)) if (*buflen <= sizeof(ErrorLog))
return false; return false;
@ -1064,7 +1064,7 @@ netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) {
return (netprot::PACKET_TYPE)buf[0]; return (netprot::PACKET_TYPE)buf[0];
} }
netprot::Packet netprot::getPack(char* buf, uint32_t *buflen) { netprot::Packet netprot::getPack(char* buf, uint32_t* buflen) {
Packet pck = { nullptr, PACKET_TYPE::ERR }; Packet pck = { nullptr, PACKET_TYPE::ERR };
Input* in = nullptr; Input* in = nullptr;
Output* out = nullptr; Output* out = nullptr;
@ -1167,13 +1167,12 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
return pck; return pck;
} }
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf) { void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector<char*>* lsPck) {
std::vector<char*> lsPck; int len = buf->tmp ? buf->tmp - buf->ptr : 0,
int len = buf->tmp? buf->tmp - buf->ptr: 0,
end = 0; end = 0;
char * cursor = buf->tmp ? buf->tmp: nullptr , char* cursor = buf->tmp ? buf->tmp : nullptr,
* next = buf->tmp ? buf->tmp + 1: buf->ptr, * next = buf->tmp ? buf->tmp + 1 : buf->ptr,
* last = buf->tmp ? buf->tmp: buf->ptr; * last = buf->tmp ? buf->tmp : buf->ptr;
bool ended = true; bool ended = true;
struct pollfd fds[1]; struct pollfd fds[1];
@ -1184,15 +1183,15 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
if (!poll(fds, 1, 0)) { if (!poll(fds, 1, 0)) {
if (ended) if (ended)
buf->tmp = nullptr; buf->tmp = nullptr;
return lsPck; return;
} }
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0); int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité. if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
if (ended) if (ended)
buf->tmp = nullptr; buf->tmp = nullptr;
return lsPck; return;
} }
len += bytes; len += bytes;
end = len; end = len;
@ -1215,24 +1214,14 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
cmp = memcmp(cursor, Footer, sizeof(uint32_t)); cmp = memcmp(cursor, Footer, sizeof(uint32_t));
if (cmp == 0) { if (cmp == 0) {
if (!outbuf) { lsPck->push_back(last);
lsPck.push_back(last); cursor += sizeof(uint32_t);
cursor += sizeof(uint32_t); last = cursor;
last = cursor; next = cursor + 1;
next = cursor + 1;
}
else {
memcpy(&outbuf->ptr[cursor - last], last, cursor - last);
lsPck.push_back(&outbuf->ptr[cursor - last]);
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
} }
} }
else { else {
if (!outbuf) buf->tmp = last;
buf->tmp = last;
cursor = &buf->ptr[len]; cursor = &buf->ptr[len];
next = cursor + 1; next = cursor + 1;
break; break;
@ -1241,8 +1230,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf, Buffer* outbuf)
} }
} }
std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* outbuf) { void netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector<char*>* lsPck) {
std::vector<char*> lsPck;
int len = buf->tmp ? buf->tmp - buf->ptr : 0, int len = buf->tmp ? buf->tmp - buf->ptr : 0,
end = 0; end = 0;
char* cursor = buf->tmp ? buf->tmp : nullptr, char* cursor = buf->tmp ? buf->tmp : nullptr,
@ -1260,14 +1248,14 @@ std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in
if (!poll(fds, 1, 0)) { if (!poll(fds, 1, 0)) {
if (ended) if (ended)
buf->tmp = nullptr; buf->tmp = nullptr;
return lsPck; return;
} }
int bytes = recvfrom(sock, &buf->ptr[len], buf->len - len, 0, (sockaddr*)&sockad, &socklen); int bytes = recvfrom(sock, &buf->ptr[len], buf->len - len, 0, (sockaddr*)&sockad, &socklen);
if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité. if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
if (ended) if (ended)
buf->tmp = nullptr; buf->tmp = nullptr;
return lsPck; return;
} }
len += bytes; len += bytes;
end = len; end = len;
@ -1291,24 +1279,14 @@ std::vector<char*> netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in
cmp = memcmp(cursor, Footer, sizeof(uint32_t)); cmp = memcmp(cursor, Footer, sizeof(uint32_t));
if (cmp == 0) { if (cmp == 0) {
if (!outbuf) { lsPck->push_back(last);
lsPck.push_back(last); cursor += sizeof(uint32_t);
cursor += sizeof(uint32_t); last = cursor;
last = cursor; next = cursor + 1;
next = cursor + 1;
}
else {
memcpy(&outbuf->ptr[cursor - last], last, cursor - last);
lsPck.push_back(&outbuf->ptr[cursor - last]);
cursor += sizeof(uint32_t);
last = cursor;
next = cursor + 1;
}
} }
} }
else { else {
if (!outbuf) buf->tmp = last;
buf->tmp = last;
cursor = &buf->ptr[len]; cursor = &buf->ptr[len];
next = cursor + 1; next = cursor + 1;
break; break;

View File

@ -129,7 +129,7 @@ namespace netprot {
Chat() {} Chat() {}
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { 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); } strcpy(mess, 140, cha->mess); }
~Chat() {/* delete[] mess; */} ~Chat() { delete[] mess; }
}; };
struct ChunkMod { struct ChunkMod {
@ -193,8 +193,8 @@ namespace netprot {
template <class T> void sendPack(SOCKET sock, T* pack, Buffer* buf); template <class T> void sendPack(SOCKET sock, T* pack, Buffer* buf);
template <class T> void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad); template <class T> void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad);
std::vector<char*> recvPacks(SOCKET sock, Buffer* buf, Buffer* oufbuf = nullptr); void recvPacks(SOCKET sock, Buffer* buf, std::vector<char*>* lsPck);
std::vector<char*> recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, Buffer* oufbuf = nullptr); void recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector<char*>* lsPck);
/* Templates */ /* Templates */

View File

@ -51,7 +51,7 @@ void Connection::getPacks(SOCKET sock) {
std::vector<char*> lsPck; std::vector<char*> lsPck;
Input in; Input in;
Sync sync; Sync sync;
lsPck = recvPacksFrom(sock, &m_buf, m_addr); recvPacksFrom(sock, &m_buf, m_addr, &lsPck);
for (auto& pck : lsPck) { for (auto& pck : lsPck) {
uint32_t bsize = m_buf.len - (pck - m_buf.ptr); uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
switch (netprot::getType(pck, 1)) { switch (netprot::getType(pck, 1)) {

View File

@ -163,7 +163,6 @@ int Server::Ready() {
play.tid = log->tid; play.tid = log->tid;
sendPackTo<GameInfo>(m_sock_udp, &m_game, &m_buf, &sockad); sendPackTo<GameInfo>(m_sock_udp, &m_game, &m_buf, &sockad);
std::cout << m_game.seed << std::endl;
Connection* conn = new Connection(sock, sockad, *log, play); Connection* conn = new Connection(sock, sockad, *log, play);
m_conns[log->sid] = conn; m_conns[log->sid] = conn;
@ -201,8 +200,12 @@ void Server::Run() {
m_world->BuildWorld(); m_world->BuildWorld();
for (auto& [key, conn] : m_conns) { // Creation des instances de joueurs et premier sync. for (auto& [key, conn] : m_conns) { // Creation des instances de joueurs et premier sync.
int x = 0,// (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1)),// -(CHUNK_SIZE_X * WORLD_SIZE_X / 2), if (!conn) {
y = 0;// (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1));// -(CHUNK_SIZE_Y * WORLD_SIZE_Y / 2); m_conns.erase(key);
continue;
}
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 4,
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 4;
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f)); conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
conn->player->m_username = conn->GetName(); conn->player->m_username = conn->GetName();
m_players[key] = conn->player; m_players[key] = conn->player;
@ -221,12 +224,14 @@ void Server::Run() {
Timestamp last = 0; Timestamp last = 0;
std::vector<Chat*> chatlog; std::vector<Chat*> chatlog;
std::vector<ChunkMod*> chunkdiffs; std::vector<ChunkMod*> chunkdiffs;
std::vector<Bullet*> bullets, outbox_bullets; std::vector<Bullet*> bullets;
std::vector<std::vector<Bullet*>::iterator> bullit;
std::vector<BulletAdd*> netbull; std::vector<BulletAdd*> netbull;
std::vector<char*> lsPck;
Chat* startchat = new Chat(); Chat* startchat = new Chat();
startchat->src_id = 0; startchat->src_id = 0;
char startmess[] = "How would -YOU- like to die today, motherfuckers?"; char startmess[] = "How would -YOU- like to die today, motherf-words?";
strcpy(startchat->mess, 140, startmess); strcpy(startchat->mess, 140, startmess);
@ -248,29 +253,27 @@ void Server::Run() {
} }
last = tstamp; last = tstamp;
for (auto& [key, conn] : m_conns) {
for (auto& [key, conn] : m_conns) {
/* In */ /* In */
std::vector<char*> lsPck; Input in; Sync sync;
Input in; Chat chat; Sync sync;
lsPck = recvPacks(m_sock_udp, &m_buf); recvPacks(m_sock_udp, &m_buf, &lsPck);
for (auto& pck : lsPck) { for (auto& pck : lsPck) {
uint32_t bsize = m_buf.len - (pck - m_buf.ptr); uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
switch (netprot::getType(pck, 1)) { switch (netprot::getType(pck, 1)) {
using enum netprot::PACKET_TYPE; using enum netprot::PACKET_TYPE;
case INPUT: case INPUT:
if (Deserialize(&in, pck, &bsize)) if (Deserialize(&in, pck, &bsize)) {
m_conns[in.sid]->AddInput(in); if (m_conns.count(in.sid))
m_conns[in.sid]->AddInput(in);
}
break; break;
case SYNC: case SYNC:
if (Deserialize(&sync, pck, &bsize)) {} if (Deserialize(&sync, pck, &bsize)) {}
break; break;
case CHAT:
//if (Deserialize(&chat, pck, &bsize))
//chatlog.push_back(chat);
break;
default: break; default: break;
} }
} }
@ -327,17 +330,21 @@ void Server::Run() {
sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr()); sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr());
delete bull; delete bull;
} }
netbull.clear();
for (auto& bull : bullets) { for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
ChunkMod* cmod = nullptr; ChunkMod* cmod = nullptr;
if (bull->Update(m_world, (1. / 60.), 20, m_players, &cmod)) { Bullet* bullet = *bull;
if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) {
if (cmod) if (cmod)
chunkdiffs.emplace_back(std::move(cmod)); chunkdiffs.emplace_back(cmod);
outbox_bullets.emplace_back(std::move(bull)); bullit.push_back(bull);
delete bullet;
} }
} }
netbull.clear(); for (auto& bull: bullit)
bullets.erase(bull);
bullit.clear();
for (auto& chat : chatlog) { for (auto& chat : chatlog) {
Log(chat->mess, false, false); Log(chat->mess, false, false);
@ -353,18 +360,19 @@ void Server::Run() {
delete chmo; delete chmo;
} }
chunkdiffs.clear(); chunkdiffs.clear();
for (auto& bull : outbox_bullets)
delete bull;
outbox_bullets.clear();
} }
Chat end; Chat end;
end.src_id = 0; end.src_id = 0;
char endmess[] = "Game over, man. Game over."; char endmess[] = "Game over, man. Game over.";
strcpy(end.mess, 140, endmess); strcpy(end.mess, 140, endmess);
for (auto& [key, conn] : m_conns) {
std::string str = conn->player->GetUsername();
Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false);
}
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
sendPackTo<Chat>(m_sock_udp, &end, &m_buf, conn->getAddr()); sendPackTo<Chat>(m_sock_udp, &end, &m_buf, conn->getAddr());

View File

@ -73,7 +73,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
int errors = 0; int errors = 0;
std::vector<char*> lsPck; std::vector<char*> lsPck;
while (!ready) { while (!ready) {
lsPck = netprot::recvPacks(m_sock_udp, &bf); netprot::recvPacks(m_sock_udp, &bf, &lsPck);
for (auto& pck : lsPck) { for (auto& pck : lsPck) {
uint32_t bsize = bf.len - (pck - bf.ptr); uint32_t bsize = bf.len - (pck - bf.ptr);
@ -94,6 +94,7 @@ int Connector::Connect(const char* srv_addr, std::string name) {
++errors; ++errors;
else { else {
m_players[pl->id] = pl; m_players[pl->id] = pl;
std::cout << "A challenger appears! " << pl->name << std::endl;
} }
break; break;
case TEAMINF: case TEAMINF:

View File

@ -1387,7 +1387,7 @@ void Engine::Render(float elapsedTime) {
sendPackTo<Input>(m_conn.m_sock_udp, &input, &m_bufout, &m_conn.m_srvsockaddr); sendPackTo<Input>(m_conn.m_sock_udp, &input, &m_bufout, &m_conn.m_srvsockaddr);
lsPck = recvPacks(m_conn.m_sock_udp, &m_buf); recvPacks(m_conn.m_sock_udp, &m_buf, &lsPck);
char* prevptr = nullptr; char* prevptr = nullptr;
for (auto& pck : lsPck) { // We could make a few threads out of this. for (auto& pck : lsPck) { // We could make a few threads out of this.
Sync sync; Output out; ChunkMod cmod; BulletAdd bull; Chat chat; Sync sync; Output out; ChunkMod cmod; BulletAdd bull; Chat chat;

View File

@ -32,8 +32,6 @@ void RemotePlayer::Feed(const netprot::Output out) {
m_position = Vector3f(out.position); m_position = Vector3f(out.position);
m_direction = Vector3f(out.direction); m_direction = Vector3f(out.direction);
std::cout << "Dead: " << out.states.dead << " Hit:" << out.states.hit << " Jump:" << out.states.jumping << " JumpShot: " << out.states.jumpshot << " Running: " << out.states.running << " Shooting: " << out.states.shooting << " Still: " << out.states.still << std::endl;
//std::cout << "powerUp " << out.states.powerup << std::endl;
current.states = out.states; current.states = out.states;
//current.position = out.position; //current.position = out.position;