SQC-15_online #1

Merged
memartel_loc merged 349 commits from SQC-15_online into master 2023-12-10 17:41:26 -05:00
3 changed files with 11 additions and 18 deletions
Showing only changes of commit 775c8cf26f - Show all commits

View File

@ -50,6 +50,7 @@ sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; }
void Connection::getPacks(SOCKET sock) {
std::vector<char*> lsPck;
Input in;
Sync sync;
lsPck = recvPacksFrom(sock, &m_buf, m_addr);
for (auto& pck : lsPck) {
@ -62,6 +63,10 @@ void Connection::getPacks(SOCKET sock) {
m_input_vector.push_back(in);
}
break;
case SYNC:
if (Deserialize(&sync, pck, &bsize))
m_nsync = true;
break;
default: break;
}
}

View File

@ -39,6 +39,8 @@ public:
void Run(World* world);
void CleanInputManifest(Timestamp time);
bool m_nsync = true;
private:
std::unordered_map<Timestamp, Input> m_input_manifest;
std::vector<Input> m_input_vector;

View File

@ -200,28 +200,14 @@ void Server::Run() {
sync.timer = m_game.countdown;
sendPack<Sync>(conn->getSock(), &sync, &m_buf);
}
int clients_ready = 0;
while (clients_ready < players) {
Packet pck = getPack(&m_buf);
if (pck.type != PACKET_TYPE::SYNC) {
Log("Paquet invalide.", true, false);
if (pck.type != PACKET_TYPE::ERR)
netprot::emptyPack(pck);
continue;
}
Sync* sync = (Sync*)pck.ptr;
clients_ready++;
//m_players[sync->sid]
delete sync;
}
while (!endgame) {
for (auto& [key, conn] : m_players) {
conn->getPacks(m_sock_udp);
conn->Run(m_world);
conn->sendPacks(m_sock_udp, m_players);
if (conn->m_nsync) {
conn->Run(m_world);
conn->sendPacks(m_sock_udp, m_players);
}
}
}