Files
bloubloulespoissons/Network/networking.h
Félix MARQUET 1343fe01e7 fix: corrige la visibilité des autres joueurs en multijoueur
- Ajout de la méthode `getPlayerId` const dans `player.cpp` et `player.h`.
- Ajout de la fonction `receivePlayerListFromServer` et `addPlayerToGame` dans `networking_client.cpp` et `networking_client.h`.
- Correction de la fonction `sendPlayerListToNewClient` et `getAllPlayers` dans `networking.cpp` et `networking.h`.
- Ajout de l'affichage des joueurs proches en mode multijoueur dans `utility.cpp` et `utility.h`.
2024-12-18 15:31:51 +01:00

37 lines
947 B
C++

#ifndef NETWORKING_H
#define NETWORKING_H
#include <SDL2/SDL_net.h>
#include <vector>
#include <iostream>
#include <thread>
#include <unordered_map>
#include <chrono>
#include "../Utility/env.h"
#include "networking_client.h"
#include "../Entities/player.h"
#include "../Entities/shark.h"
inline IPaddress ip;
inline TCPsocket server;
inline std::vector<TCPsocket> clients;
bool initServer();
void acceptClients();
std::pair<int, int> updatePlayerPosition(int clientId, const std::string& direction);
void createNewPlayer(int clientId);
void updateKeepAlive(int clientId);
void checkClientAlive();
void closeServer();
void handleServerMessages();
void sendSharkPosition(TCPsocket socket, int sharkId, int x, int y);
std::string processReceivedData(const std::string& data);
struct PlayerInfo {
int id;
int x;
int y;
};
std::vector<PlayerInfo> getAllPlayers();
void sendPlayerListToNewClient(int clientSocket);
#endif //NETWORKING_H