#include "net.h" #include #include #include #include #include #include int WaitForOrdersFromClient(const ClientInfo info, std::mutex &mut, CTTRTSGame &game) { char buffer[1028]; // buffer for orders std::cout<<"Waiting for "< &myClients, CTTRTSGame &game, std::mutex &gameMutex) { // Spawn threads std::vector clientThreads; for(auto client : myClients) { std::thread clientThread(WaitForOrdersFromClient, client, ref(gameMutex), std::ref(game)); clientThreads.push_back(move(clientThread)); } // Join up all the threads for ( std::thread& thread : clientThreads ) { thread.join(); } } void SendGameInfoToClients(std::vector &myClients, const CTTRTSGame &game, std::mutex &gameMutex) { gameMutex.lock(); std::string gamestate_string = GetStringFromGame(game); gameMutex.unlock(); for (auto client : myClients) { // Write to the socket with the buffer if ( write( client.clientsockfd, gamestate_string.c_str(), gamestate_string.length() ) < 0 ) error("ERROR sending to client"); } }