| 101 | } |
| 102 | |
| 103 | void Server::start() |
| 104 | { |
| 105 | int i; |
| 106 | |
| 107 | names.resize(nmachines); |
| 108 | ports.resize(nmachines); |
| 109 | |
| 110 | /* Set up the sockets */ |
| 111 | socket_num.resize(nmachines); |
| 112 | for (i=0; i<nmachines; i++) { socket_num[i]=-1; } |
| 113 | |
| 114 | // port number one lower to avoid conflict with players |
| 115 | server_socket = new ServerSocket(PortnumBase); |
| 116 | auto& server = *server_socket; |
| 117 | server.init(); |
| 118 | |
| 119 | // set up connections |
| 120 | for (i=0; i<nmachines; i++) |
| 121 | { |
| 122 | if (OnlineOptions::singleton.has_option("debug_networking")) |
| 123 | cerr << "Waiting for player " << i << endl; |
| 124 | |
| 125 | socket_num[i] = server.get_connection_socket("P" + to_string(i)); |
| 126 | |
| 127 | if (OnlineOptions::singleton.has_option("debug_networking")) |
| 128 | cerr << "Connected to player " << i << endl; |
| 129 | } |
| 130 | |
| 131 | // get names |
| 132 | for (i=0; i<nmachines; i++) |
| 133 | get_name(i); |
| 134 | |
| 135 | // check setup, party 0 doesn't matter |
| 136 | bool all_on_local = true, none_on_local = true; |
| 137 | for (i = 1; i < nmachines; i++) |
| 138 | { |
| 139 | bool on_local = names[i].compare("127.0.0.1"); |
| 140 | all_on_local &= on_local; |
| 141 | none_on_local &= not on_local; |
| 142 | } |
| 143 | if (not all_on_local and not none_on_local) |
| 144 | { |
| 145 | cout << "You cannot address Server.x by localhost if using different hosts" << endl; |
| 146 | exit(1); |
| 147 | } |
| 148 | |
| 149 | // send names |
| 150 | send_names(); |
| 151 | |
| 152 | for (int i = 0; i < nmachines; i++) |
| 153 | close(socket_num[i]); |
| 154 | } |
| 155 | |
| 156 | void* Server::start_in_thread(void* server) |
| 157 | { |
no test coverage detected