à tester
This commit is contained in:
parent
f0bf7d94ce
commit
e2e66f3b6c
@ -189,7 +189,7 @@ void Server::Run() {
|
||||
sync.ammo = 0;
|
||||
sync.timestamp = 0;
|
||||
sync.timer = m_game.countdown;
|
||||
sendPackTo<Sync>(conn->getSock(), &sync, &m_buf, conn->getAddr());
|
||||
sendPack<Sync>(conn->getSock(), &sync, &m_buf);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
@ -56,8 +56,8 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
std::cout << "Échec de la connexion." << std::endl;
|
||||
}
|
||||
|
||||
char* buf = new char[150];
|
||||
uint32_t buflen = 150;
|
||||
char* buf = new char[1500];
|
||||
uint32_t buflen = 1500;
|
||||
netprot::LoginInfo log;
|
||||
memcpy(&log.name, name.c_str(), name.size() + 1);
|
||||
|
||||
@ -72,42 +72,52 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
int errors = 0;
|
||||
netprot::PlayerInfo pinfo{};
|
||||
while (!ready) {
|
||||
recv(m_sock_tcp, buf, buflen, 0);
|
||||
uint32_t bytes = recv(m_sock_tcp, buf, buflen, 0);
|
||||
uint32_t curr = 0;
|
||||
char* currbuf = buf;
|
||||
|
||||
switch (netprot::getType(buf, buflen)) {
|
||||
case netprot::PACKET_TYPE::LOGINF:
|
||||
if (!netprot::Deserialize(&m_loginfo, buf, buflen)) {
|
||||
std::cout << "Packet LoginInfo invalide." << std::endl;
|
||||
return 2;
|
||||
while (bytes > 0) {
|
||||
switch (netprot::getType(currbuf, buflen)) {
|
||||
case netprot::PACKET_TYPE::LOGINF:
|
||||
if (!netprot::Deserialize(&m_loginfo, currbuf, buflen)) {
|
||||
std::cout << "Packet LoginInfo invalide." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
curr = sizeof(netprot::LoginInfo);
|
||||
break;
|
||||
case netprot::PACKET_TYPE::GAMEINFO:
|
||||
if (!netprot::Deserialize(&m_gameinfo, currbuf, buflen)) {
|
||||
std::cout << "Packet GameInfo invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
curr = sizeof(netprot::GameInfo);
|
||||
break;
|
||||
case netprot::PACKET_TYPE::PLAYINF:
|
||||
if (!netprot::Deserialize(&pinfo, currbuf, buflen)) {
|
||||
std::cout << "Packet PlayerInfo invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
m_players[pinfo.id] = pinfo;
|
||||
curr = sizeof(netprot::PlayerInfo);
|
||||
break;
|
||||
case netprot::PACKET_TYPE::SYNC:
|
||||
if (!netprot::Deserialize(&m_origin, currbuf, buflen)) {
|
||||
std::cout << "Packet Sync invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
curr = sizeof(netprot::Sync);
|
||||
ready = true;
|
||||
break;
|
||||
default:
|
||||
++errors;
|
||||
//std::cout << "Packet invalide." << std::endl;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case netprot::PACKET_TYPE::GAMEINFO:
|
||||
if (!netprot::Deserialize(&m_gameinfo, buf, buflen)) {
|
||||
std::cout << "Packet GameInfo invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
break;
|
||||
case netprot::PACKET_TYPE::PLAYINF:
|
||||
if (!netprot::Deserialize(&pinfo, buf, buflen)) {
|
||||
std::cout << "Packet PlayerInfo invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
m_players[pinfo.id] = pinfo;
|
||||
break;
|
||||
case netprot::PACKET_TYPE::SYNC:
|
||||
if (!netprot::Deserialize(&m_origin, buf, buflen)) {
|
||||
std::cout << "Packet Sync invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
ready = true;
|
||||
break;
|
||||
default:
|
||||
++errors;
|
||||
//std::cout << "Packet invalide." << std::endl;
|
||||
break;
|
||||
currbuf = &currbuf[curr];
|
||||
bytes -= curr;
|
||||
if (errors > 100)
|
||||
return 1;
|
||||
}
|
||||
if (errors > 100)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user