MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / dp_DirectPlayDispatch

Function dp_DirectPlayDispatch

networking/directplay.cpp:500–587  ·  view source on GitHub ↗

This function will look for incoming messages, and dispatch them accordingly

Source from the content-addressed store, hash-verified

498
499// This function will look for incoming messages, and dispatch them accordingly
500void dp_DirectPlayDispatch() {
501 HRESULT hr;
502 uint8_t packet_data[32000]; // MAX_PACKET_SIZE+1];
503 DWORD dwMsgBufferSize = 32000; // MAX_PACKET_SIZE;
504 DPID idFrom = 0;
505 DPID idTo = 0;
506 network_address from_addr;
507 LPDPMSG_CREATEPLAYERORGROUP new_player_msg;
508 // Put messages in the buffers
509 if ((!DP_active) || (!lpDirectPlay4A)) {
510 mprintf(0, "Can't dispatch DirectPlay message because DirectPlay isn't active!\n");
511 return;
512 }
513
514 hr = lpDirectPlay4A->Receive(&idFrom, &idTo, DPRECEIVE_ALL, packet_data, &dwMsgBufferSize);
515 if (FAILED(hr)) {
516 switch (hr) {
517 case DPERR_BUFFERTOOSMALL:
518 mprintf(0, "Error: lpDirectPlay4A->Receive() returned DPERR_BUFFERTOOSMALL -- needs %d\n", dwMsgBufferSize);
519 break;
520 case DPERR_GENERIC:
521 mprintf(0, "Error: lpDirectPlay4A->Receive() returned DPERR_GENERIC\n");
522 break;
523 case DPERR_INVALIDOBJECT:
524 mprintf(0, "Error: lpDirectPlay4A->Receive() returned DPERR_INVALIDOBJECT\n");
525 break;
526 case DPERR_INVALIDPARAMS:
527 mprintf(0, "Error: lpDirectPlay4A->Receive() returned DPERR_INVALIDPARAMS\n");
528 break;
529 case DPERR_INVALIDPLAYER:
530 mprintf(0, "Error: lpDirectPlay4A->Receive() returned DPERR_INVALIDPLAYER\n");
531 break;
532 case DPERR_NOMESSAGES:
533 // Not really an error....
534 // mprintf(0,"Error: lpDirectPlay4A->Receive() returned DPERR_NOMESSAGES\n");
535 break;
536 default:
537 mprintf(0, "Unknown error code from DirectPlay::Receive() -- %x\n", hr);
538 }
539 } else {
540 // Now we have actual data -- do something with it.
541 if (idFrom == DPID_SYSMSG) {
542 // This is a system message
543 LPDPMSG_GENERIC lpMsg = (LPDPMSG_GENERIC)packet_data;
544 switch (lpMsg->dwType) {
545 case DPSYS_CREATEPLAYERORGROUP:
546 // New player joined the game
547 {
548 mprintf(0, "Got a DPSYS_CREATEPLAYERORGROUP packet!\n");
549 new_player_msg = (LPDPMSG_CREATEPLAYERORGROUP)lpMsg;
550 // Store this player's info
551 for (int i = 0; i < MAX_PENDING_NEW_CONNECTIONS; i++) {
552 if (Pending_dp_conn[i] == DPID_UNKNOWN) {
553 // new connection slot
554 Pending_dp_conn[i] = new_player_msg->dpId;
555 break;
556 }
557 }

Callers 2

nw_ReceiveFunction · 0.85
nw_ReceiveReliableFunction · 0.85

Calls 2

FAILEDFunction · 0.85
nw_psnet_buffer_packetFunction · 0.85

Tested by

no test coverage detected