SQC-15_online #1
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user