diff --git a/source/client/server.cpp b/source/client/server.cpp index 7c291b1..89cef9e 100644 --- a/source/client/server.cpp +++ b/source/client/server.cpp @@ -28,6 +28,23 @@ struct ClientInfo int clientsockfd; }; +void SendGameInfoToClients(std::vector &myClients, const 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(); + } +} + int waitForOrdersFromClient(const ClientInfo info, std::mutex& mut, CTTRTSGame& game ) { char buffer[1028]; // buffer for orders @@ -156,28 +173,31 @@ int runServer(int argc, char* argv[]) // Wait for orders from clients std::cout<<"Waiting for client orders"< clientThreads; - for(auto client : myClients) - { - std::thread clientThread(waitForOrdersFromClient, client, std::ref(gameMutex), std::ref(game)); - clientThreads.push_back(std::move(clientThread)); - } - - // Join up all the threads - for ( std::thread& thread : clientThreads ) - { - thread.join(); - } + SendGameInfoToClients(myClients, game, gameMutex); std::cout<<"Orders recieved, simulating turn"<