Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void RoomBroadcastMessage(RoomData* room, MessageData* message)
- {
- //Send the message to the player and targets first
- CharacterData* details = ((CharacterData*)(message->ownerEntity->data));
- ConnectionSendString(details->connection, &message->ownerMessage);
- uint16* targetIds = (message->targetData != nullptr) ? uint16[message->targetData->targetCount] : nullptr;
- if (targetIds != nullptr)
- {
- for (uint16 i = 0; i < message->targetData->targetCount; i++)
- {
- targetIds[i] = message->targetData->targetedEntities[i]->entityID;
- details = ((CharacterData*)(message->targetData->targetedEntities[i]->data));
- ConnectionSendString(details->connection, &message->targetMessage);
- }
- }
- int playerCount = 0;
- //Go through all players in the room besides the owner and target and send the message
- for (uint32 i = 0; i < room->playersInRoom.capacity; i++)
- {
- if (playerCount == room->playersInRoom.count)
- break;
- EntityData* player = room->playersInRoom[i];
- if (player != NULL)
- {
- //Increment counter since we found something regardless if it is being ignored.
- playerCount++;
- //Check if player is owner or target
- if (message->ownerEntity->entityID == player->entityID)
- continue;
- if (targetIds != nullptr)
- {
- bool skip = false;
- for (uint16 i = 0; i < message->targetData->targetCount; i++)
- {
- if (targetIds[i] == player->entityID)
- {
- skip = true;
- break;
- }
- }
- if (skip)
- continue;
- }
- details = ((CharacterData*)(player->data));
- ConnectionSendString(details->connection, &message->otherMessage);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement