-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
71 lines (65 loc) · 2.24 KB
/
server.cpp
File metadata and controls
71 lines (65 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <network.h>
#include <plog/Appenders/ConsoleAppender.h>
#include <plog/Init.h>
#include <plog/Formatters/TxtFormatter.h>
#include <SceneLoader.hpp>
#include <MainLoop.hpp>
#include <iostream>
int main(int argc, char** argv) {
// Uncomment to see logs. Know that it slows execution time
// static plog::ConsoleAppender<plog::TxtFormatter> consoleAppender;
// plog::init(plog::debug, &consoleAppender);
if (argc > 2) {
std::cerr << "Provide 1 arg to load exact scene or no args to interact" << std::endl;
exit(424242);
}
null::MainLoop::serverArbiter = new ServerArbiter([]() {
null::MainLoop::attachWindow = true;
null::MainLoop::run();
});
null::MainLoop::serverArbiter->listen(5002);
if (argc == 2) {
std::cout << "You chose" << argv[1] << std::endl;
std::string levelToLoad = argv[1];
try {
null::SceneLoader::loadSceneFromFile(levelToLoad);
} catch (const null::UnknownSceneException& ignored) {
std::cerr << "Unknown scene, try again" << std::endl;
exit(30);
}
std::cout << "Server is up. Type 'exit' to stop." << std::endl;
null::MainLoop::serverArbiter->launch();
while (true) {
std::string oper;
std::cin >> oper;
if (oper == "exit") {
break;
}
}
}
const std::string defaultLevel = "/network-demo-server";
std::string levelToLoad;
bool sceneIsLoaded = false;
std::cout << "Type level uri to load. Empty string for default /network-demo-server" << std::endl;
while (!sceneIsLoaded) {
std::getline(std::cin, levelToLoad);
if (levelToLoad.empty()) {
levelToLoad = defaultLevel;
}
try {
null::SceneLoader::loadSceneFromFile(levelToLoad);
sceneIsLoaded = true;
} catch (const null::UnknownSceneException& e) {
std::cout << "Unknown scene, try again" << std::endl;
}
}
null::MainLoop::serverArbiter->launch();
std::cout << "Server is up. Type 'exit' to stop." << std::endl;
while (true) {
std::string oper;
std::cin >> oper;
if (oper == "exit") {
break;
}
}
}