| 230 | } |
| 231 | |
| 232 | void setupserver(int port, const char *ip = NULL) |
| 233 | { |
| 234 | ENetAddress address; |
| 235 | address.host = ENET_HOST_ANY; |
| 236 | address.port = port; |
| 237 | |
| 238 | if(ip) |
| 239 | { |
| 240 | if(enet_address_set_host(&address, ip)<0) |
| 241 | fatal("failed to resolve server address: %s", ip); |
| 242 | } |
| 243 | serversocket = enet_socket_create(ENET_SOCKET_TYPE_STREAM); |
| 244 | if(serversocket==ENET_SOCKET_NULL || |
| 245 | enet_socket_set_option(serversocket, ENET_SOCKOPT_REUSEADDR, 1) < 0 || |
| 246 | enet_socket_bind(serversocket, &address) < 0 || |
| 247 | enet_socket_listen(serversocket, -1) < 0) |
| 248 | fatal("failed to create server socket"); |
| 249 | if(enet_socket_set_option(serversocket, ENET_SOCKOPT_NONBLOCK, 1)<0) |
| 250 | fatal("failed to make server socket non-blocking"); |
| 251 | if(!setuppingsocket()) |
| 252 | fatal("failed to create ping socket"); |
| 253 | |
| 254 | enet_time_set(0); |
| 255 | |
| 256 | starttime = time(NULL); |
| 257 | char *ct = ctime(&starttime); |
| 258 | if(strchr(ct, '\n')) *strchr(ct, '\n') = '\0'; |
| 259 | conoutf("*** Starting master server on %s %d at %s ***", ip ? ip : "localhost", port, ct); |
| 260 | } |
| 261 | |
| 262 | void genserverlist() |
| 263 | { |
no test coverage detected