Initial Commit
This commit is contained in:
commit
6088fc29ed
978 changed files with 353647 additions and 0 deletions
55
src/Server/servermain.cpp
Normal file
55
src/Server/servermain.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "MainServer.hpp"
|
||||
#include "steam/steamnetworkingsockets.h"
|
||||
#include "steam/steamnetworkingtypes.h"
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
std::mutex inputMutex;
|
||||
std::queue<std::string> inputQueue;
|
||||
|
||||
std::unique_ptr<std::thread> inputThread;
|
||||
|
||||
void user_input_init() {
|
||||
inputThread = std::make_unique<std::thread>([&]() {
|
||||
for(;;) {
|
||||
std::string newMessage;
|
||||
std::cin >> newMessage;
|
||||
inputMutex.lock();
|
||||
inputQueue.emplace(newMessage);
|
||||
inputMutex.unlock();
|
||||
if(newMessage == "stop")
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
SteamDatagramErrMsg errMsg;
|
||||
if(!GameNetworkingSockets_Init(nullptr, errMsg))
|
||||
std::cout << "[GameNetworkingSockets_Init] Failed to initialize network sockets " << errMsg << std::endl;
|
||||
|
||||
MainServer server("");
|
||||
user_input_init();
|
||||
for(;;) {
|
||||
server.update();
|
||||
inputMutex.lock();
|
||||
bool isQuitting = false;
|
||||
while(!inputQueue.empty()) {
|
||||
std::string newMessage = inputQueue.front();
|
||||
inputQueue.pop();
|
||||
if(newMessage == "stop") {
|
||||
isQuitting = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
std::cout << "Unknown command: " << newMessage << std::endl;
|
||||
}
|
||||
}
|
||||
inputMutex.unlock();
|
||||
if(isQuitting)
|
||||
break;
|
||||
}
|
||||
inputThread->join();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue