SQC-15_online #1

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

View File

@ -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);

View File

@ -30,6 +30,7 @@ public:
Sync getSync(Timestamp time);
SOCKET getSock() const;
PlayerInfo* getInfo() const;
sockaddr_in* getAddr() const;
void CleanInputManifest(Timestamp time);
private:
@ -43,4 +44,4 @@ private:
PlayerInfo m_playinfo;
};
#endif
#endif

View File

@ -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();

Binary file not shown.