| 78 | } |
| 79 | |
| 80 | void processRequests() |
| 81 | { |
| 82 | while (true) |
| 83 | { |
| 84 | int new_socket; |
| 85 | ssize_t valread; |
| 86 | int addrlen = sizeof(address); |
| 87 | char buffer[1024] = { 0 }; |
| 88 | |
| 89 | if ((new_socket = accept(server_fd, (struct sockaddr *)&address, |
| 90 | (socklen_t*)&addrlen))<0) |
| 91 | { |
| 92 | perror("accept"); |
| 93 | exit(EXIT_FAILURE); |
| 94 | } |
| 95 | valread = read(new_socket, buffer, 1024); |
| 96 | printf("HTTP:Received %.*s\n", valread, buffer); |
| 97 | |
| 98 | // For each request, "add" a connected player |
| 99 | players.push_back(Microsoft::Azure::Gaming::ConnectedPlayer("gamer" + std::to_string(requestCount))); |
| 100 | requestCount++; |
| 101 | Microsoft::Azure::Gaming::GSDK::updateConnectedPlayers(players); |
| 102 | |
| 103 | std::unordered_map<std::string, std::string> config = Microsoft::Azure::Gaming::GSDK::getConfigSettings(); |
| 104 | |
| 105 | // First, check if we need to delay shutdown for testing |
| 106 | auto it = config.find(Microsoft::Azure::Gaming::GSDK::SESSION_COOKIE_KEY); |
| 107 | |
| 108 | if (it != config.end() && strcmp(it->second.c_str(), "delayshutdown") == 0) |
| 109 | { |
| 110 | delayShutdown = true; |
| 111 | } |
| 112 | |
| 113 | if (isActivated) |
| 114 | { |
| 115 | std::string playersJoinedAsString = ""; |
| 116 | for (auto player : Microsoft::Azure::Gaming::GSDK::getInitialPlayers()) |
| 117 | { |
| 118 | playersJoinedAsString += (playersJoinedAsString.empty() ? "" : ",") + player; |
| 119 | } |
| 120 | |
| 121 | config["initialPlayers"] = playersJoinedAsString; |
| 122 | } |
| 123 | |
| 124 | config["isActivated"] = isActivated? "true" : "false"; |
| 125 | config["isShutdown"] = isShutdown? "true" : "false"; |
| 126 | config["assetFileText"] = assetFileText; |
| 127 | config["assetFileTar"] = assetFileTar; |
| 128 | config["assetFileTarGz"] = assetFileTarGz; |
| 129 | config["testCertificate"] = testCertificate; |
| 130 | |
| 131 | if (isMaintenancedScheduled) |
| 132 | { |
| 133 | std::string timeStr(asctime(localtime(&nextMaintenance))); |
| 134 | timeStr.erase(std::remove(timeStr.begin(), timeStr.end(), '\n'), timeStr.end()); |
| 135 | config["nextMaintenance"] = timeStr; |
| 136 | } |
| 137 | |