Erratum VI: The Final Chapter
This commit is contained in:
parent
05f9658f55
commit
60cc69a407
@ -45,6 +45,8 @@ SOCKET Connection::getSock() const { return m_sock; }
|
||||
|
||||
PlayerInfo* Connection::getInfo() const { return (PlayerInfo*)&m_playinfo; }
|
||||
|
||||
sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; }
|
||||
|
||||
void Connection::CleanInputManifest(Timestamp time) {
|
||||
auto wat = m_input_manifest.find(time);
|
||||
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
Sync getSync(Timestamp time);
|
||||
SOCKET getSock() const;
|
||||
PlayerInfo* getInfo() const;
|
||||
sockaddr_in* getAddr() const;
|
||||
|
||||
void CleanInputManifest(Timestamp time);
|
||||
private:
|
||||
|
@ -77,7 +77,7 @@ int Server::Ready() {
|
||||
bool readystart = false;
|
||||
|
||||
do {
|
||||
Log("Entrez la durée de la partie: ", false, false);
|
||||
Log("Entrez la dur<EFBFBD>e de la partie: ", false, false);
|
||||
std::cin >> m_game.countdown;
|
||||
std::cout << std::endl;
|
||||
} while (m_game.countdown < 1);
|
||||
@ -95,13 +95,13 @@ int Server::Ready() {
|
||||
m_game.gameType = 1;
|
||||
|
||||
if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
|
||||
Log("Écoute sur le port TCP.", true, true);
|
||||
Log("Ecoute sur le port TCP.", true, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buildIdList(ID_LIST_SIZE);
|
||||
|
||||
Log("À l'écoute sur le port: " + std::to_string(SRV_PORT), false, false);
|
||||
Log("A l'ecoute sur le port: " + std::to_string(SRV_PORT), false, false);
|
||||
|
||||
while (!readystart) {
|
||||
sockaddr_in sockad;
|
||||
@ -111,7 +111,7 @@ int Server::Ready() {
|
||||
if (sock < 0)
|
||||
Log("Erreur de connexion", true, false);
|
||||
else if (sock > 0) {
|
||||
std::string str = "Nouvelle connection provenant de: ";
|
||||
std::string str = "Nouvelle connexion provenant de: ";
|
||||
str.append(inet_ntop(AF_INET, &sockad.sin_addr, strbuf, strbuflen)).append(": ").append(std::to_string(sockad.sin_port));
|
||||
|
||||
if (recv(sock, buf, buflen, 0) > 0) {
|
||||
@ -146,7 +146,7 @@ int Server::Ready() {
|
||||
Connection* conn = new Connection(sock, sockad, *log, play);
|
||||
|
||||
for (auto& [key, player] : m_players) {
|
||||
sendPack<PlayerInfo>(player->getSock(), &play, &buf, &buflen); // Envoyer les infos de joueur distant aux joueurs déjà connectés
|
||||
sendPack<PlayerInfo>(player->getSock(), &play, &buf, &buflen); // Envoyer les infos de joueur distant aux joueurs d<EFBFBD>j<EFBFBD> connect<63>s
|
||||
buflen = BUFFER_LENGTH;
|
||||
sendPack<PlayerInfo>(sock, player->getInfo(), &buf, &buflen); // et envoyer les infos des joueurs distants au nouveau joueur.
|
||||
buflen = BUFFER_LENGTH;
|
||||
@ -169,16 +169,24 @@ int Server::Ready() {
|
||||
void Server::Run() {
|
||||
char* buf = new char[BUFFER_LENGTH];
|
||||
uint32_t buflen = BUFFER_LENGTH;
|
||||
netprot::Input in;
|
||||
Input in;
|
||||
sockaddr_in sockad;
|
||||
addrlen_t socklen = sizeof(sockad);
|
||||
|
||||
Log("Debut de la partie...", false, false);
|
||||
|
||||
for (auto& [key, conn]: m_players) // Gérer le point de spawn des joueurs.
|
||||
for (auto& [key, conn]: m_players) { // Creation des instances de joueurs et premier sync.
|
||||
conn->player = new Player(Vector3f(64., 128., 64.));
|
||||
|
||||
// TODO: Faire un premier sync pour que les joueurs partent à la bonne place.
|
||||
Player *player = conn->player;
|
||||
Sync sync;
|
||||
sync.position = player->GetPosition();
|
||||
sync.hp = player->GetHP();
|
||||
sync.sid = key;
|
||||
sync.ammo = 0;
|
||||
sync.timestamp = 0;
|
||||
sync.timer = m_game.countdown;
|
||||
sendPackTo<Sync>(conn->getSock(), &sync, &buf, &buflen, conn->getAddr());
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (recvfrom(m_sock_udp, buf, BUFFER_LENGTH, 0, (sockaddr*)&sockad, &socklen) > 0) {
|
||||
@ -228,8 +236,10 @@ void Server::Log(std::string str, bool is_error = false, bool is_fatal = false)
|
||||
closesocket(m_sock_udp);
|
||||
if (m_sock_tcp)
|
||||
closesocket(m_sock_tcp);
|
||||
for (const auto& [key, player] : m_players)
|
||||
for (const auto& [key, player] : m_players) {
|
||||
delete player->player;
|
||||
closesocket(player->getSock());
|
||||
}
|
||||
m_players.clear();
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
|
BIN
SQCSim2021/media/audio/whitenoise.ogg
Normal file
BIN
SQCSim2021/media/audio/whitenoise.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user