diff options
| -rw-r--r-- | src/core/hle/service/nwm/nwm_uds.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index e92900d48..51786d172 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp | |||
| @@ -543,6 +543,42 @@ static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { | |||
| 543 | beacon_broadcast_event, 0); | 543 | beacon_broadcast_event, 0); |
| 544 | } | 544 | } |
| 545 | 545 | ||
| 546 | /* | ||
| 547 | * Returns an available index in the nodes array for the | ||
| 548 | * currently-hosted UDS network. | ||
| 549 | */ | ||
| 550 | static u32 GetNextAvailableNodeId() { | ||
| 551 | ASSERT_MSG(connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost), | ||
| 552 | "Can not accept clients if we're not hosting a network"); | ||
| 553 | |||
| 554 | for (unsigned index = 0; index < connection_status.max_nodes; ++index) { | ||
| 555 | if ((connection_status.node_bitmask & (1 << index)) == 0) | ||
| 556 | return index; | ||
| 557 | } | ||
| 558 | |||
| 559 | // Any connection attempts to an already full network should have been refused. | ||
| 560 | ASSERT_MSG(false, "No available connection slots in the network"); | ||
| 561 | } | ||
| 562 | |||
| 563 | /* | ||
| 564 | * Called when a client connects to an UDS network we're hosting, | ||
| 565 | * updates the connection status and signals the update event. | ||
| 566 | * @param network_node_id Network Node Id of the connecting client. | ||
| 567 | */ | ||
| 568 | void OnClientConnected(u16 network_node_id) { | ||
| 569 | ASSERT_MSG(connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost), | ||
| 570 | "Can not accept clients if we're not hosting a network"); | ||
| 571 | ASSERT_MSG(connection_status.total_nodes < connection_status.max_nodes, | ||
| 572 | "Can not accept connections on a full network"); | ||
| 573 | |||
| 574 | u32 node_id = GetNextAvailableNodeId(); | ||
| 575 | connection_status.node_bitmask |= 1 << node_id; | ||
| 576 | connection_status.changed_nodes |= 1 << node_id; | ||
| 577 | connection_status.nodes[node_id] = network_node_id; | ||
| 578 | connection_status.total_nodes++; | ||
| 579 | connection_status_event->Signal(); | ||
| 580 | } | ||
| 581 | |||
| 546 | const Interface::FunctionInfo FunctionTable[] = { | 582 | const Interface::FunctionInfo FunctionTable[] = { |
| 547 | {0x00010442, nullptr, "Initialize (deprecated)"}, | 583 | {0x00010442, nullptr, "Initialize (deprecated)"}, |
| 548 | {0x00020000, nullptr, "Scrap"}, | 584 | {0x00020000, nullptr, "Scrap"}, |