This function gets called when a game is started, so Direcplay knows the title, and to listen
| 282 | |
| 283 | // This function gets called when a game is started, so Direcplay knows the title, and to listen |
| 284 | int dp_StartGame(char *gamename) { |
| 285 | HRESULT hres; |
| 286 | DPNAME server_player; |
| 287 | DPSESSIONDESC2 sessionDesc; |
| 288 | |
| 289 | mprintf(0, "Starting DirectPlay game: %s\n", gamename); |
| 290 | |
| 291 | if ((!DP_active) || (!lpDirectPlay4A)) { |
| 292 | mprintf(0, "Can't start game because DirectPlay isn't initialized!\n"); |
| 293 | return 0; |
| 294 | } |
| 295 | // Host a new session. |
| 296 | ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC2)); |
| 297 | sessionDesc.dwSize = sizeof(DPSESSIONDESC2); |
| 298 | sessionDesc.dwFlags = |
| 299 | DPSESSION_CLIENTSERVER | DPSESSION_KEEPALIVE | DPSESSION_OPTIMIZELATENCY | DPSESSION_DIRECTPLAYPROTOCOL; |
| 300 | sessionDesc.guidApplication = DPD3_GUID; |
| 301 | sessionDesc.dwMaxPlayers = MAX_NET_PLAYERS; |
| 302 | sessionDesc.dwCurrentPlayers = 1; // The server is a player |
| 303 | sessionDesc.lpszSessionNameA = gamename; |
| 304 | |
| 305 | ZeroMemory(&server_player, sizeof(DPNAME)); |
| 306 | server_player.dwSize = sizeof(DPNAME); |
| 307 | server_player.lpszShortNameA = Players[Player_num].callsign; |
| 308 | server_player.lpszLongNameA = NULL; |
| 309 | |
| 310 | // if(lpAddress) |
| 311 | //{ |
| 312 | // hres = lpDirectPlay4A->Open((DPSESSIONDESC2 *)lpAddress, DPOPEN_CREATE | DPOPEN_RETURNSTATUS); |
| 313 | //} |
| 314 | // else |
| 315 | //{ |
| 316 | hres = lpDirectPlay4A->Open(&sessionDesc, DPOPEN_CREATE | DPOPEN_RETURNSTATUS); |
| 317 | //} |
| 318 | |
| 319 | if (SUCCEEDED(hres)) { |
| 320 | NetPlayers[Player_num].hPlayerEvent = CreateEvent(NULL, // no security |
| 321 | FALSE, // auto reset |
| 322 | FALSE, // initial event reset |
| 323 | NULL); // no name |
| 324 | if (NetPlayers[Player_num].hPlayerEvent == NULL) { |
| 325 | mprintf(0, "Failed to create directplay notification event!\n"); |
| 326 | dp_EndGame(); |
| 327 | DP_active = false; |
| 328 | return 0; |
| 329 | } |
| 330 | hres = lpDirectPlay4A->CreatePlayer(&NetPlayers[Player_num].dpidPlayer, &server_player, |
| 331 | NetPlayers[Player_num].hPlayerEvent, NULL, 0, DPPLAYER_SERVERPLAYER); |
| 332 | if (FAILED(hres)) { |
| 333 | mprintf(0, "Failed to create directplay player in dp_StartGame()\n"); |
| 334 | switch (hres) { |
| 335 | case DPERR_CANTADDPLAYER: |
| 336 | mprintf(0, "Unable to create player. Error code: DPERR_CANTADDPLAYER\n"); |
| 337 | break; |
| 338 | case DPERR_CANTCREATEPLAYER: |
| 339 | mprintf(0, "Unable to create player. Error code: DPERR_CANTCREATEPLAYER\n"); |
| 340 | break; |
| 341 | case DPERR_CONNECTIONLOST: |
no test coverage detected