Opens a TCP socket on localhost, port 45659 If a socket has been successfully opened, it connects to the effect client (CrowdControl or RSMods GUI) NULL. Loops while the game is open
| 145 | /// </summary> |
| 146 | /// <returns>NULL. Loops while the game is open</returns> |
| 147 | unsigned WINAPI CrowdControlThread() { |
| 148 | while (!GameState::GameLoaded) |
| 149 | Sleep(5000); |
| 150 | |
| 151 | LOG_INFO("Crowd control server starting" << std::endl); |
| 152 | |
| 153 | //Create server address struct |
| 154 | struct sockaddr_in server_address = {}; |
| 155 | |
| 156 | server_address.sin_family = AF_INET; |
| 157 | server_address.sin_port = htons(45659); |
| 158 | |
| 159 | //Resolve and convert ip address |
| 160 | if (inet_pton(AF_INET, "127.0.0.1", &server_address.sin_addr) <= 0) { |
| 161 | LOG_ERROR("Invalid address" << std::endl); |
| 162 | return -1; |
| 163 | } |
| 164 | |
| 165 | while (!GameState::GameClosing) { |
| 166 | LOG_INFO("Trying to connect to crowd control" << std::endl); |
| 167 | |
| 168 | //Open socket |
| 169 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
| 170 | LOG_ERROR("Unable to open socket for crowd control" << std::endl); |
| 171 | return -1; |
| 172 | } |
| 173 | |
| 174 | //Connect |
| 175 | int connectErr = connect(sock, (struct sockaddr*)&server_address, sizeof(server_address)); |
| 176 | if (connectErr < 0) { |
| 177 | LOG_ERROR("Unable to connect to crowd control - " << connectErr << std::endl); |
| 178 | return -1; |
| 179 | } |
| 180 | else |
| 181 | serverStarted = true; |
| 182 | |
| 183 | LOG_INFO("Connected to crowd control" << std::endl); |
| 184 | |
| 185 | //Do client loop |
| 186 | ClientLoop(); |
| 187 | |
| 188 | LOG_INFO("Disconnected from crowd control" << std::endl); |
| 189 | } |
| 190 | |
| 191 | LOG_INFO("Crowd control stopping" << std::endl); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | /// <summary> |
| 197 | /// Continously keep the effects running by calling the Run() method in their classes |
nothing calls this directly
no test coverage detected