Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1.     void RoomBroadcastMessage(RoomData* room, MessageData* message)
  2.     {
  3.         //Send the message to the player and targets first
  4.         CharacterData* details = ((CharacterData*)(message->ownerEntity->data));
  5.         ConnectionSendString(details->connection, &message->ownerMessage);
  6.        
  7.         uint16* targetIds = (message->targetData != nullptr) ? uint16[message->targetData->targetCount] : nullptr;
  8.         if (targetIds != nullptr)
  9.         {
  10.             for (uint16 i = 0; i < message->targetData->targetCount; i++)
  11.             {
  12.                 targetIds[i] = message->targetData->targetedEntities[i]->entityID;
  13.                 details = ((CharacterData*)(message->targetData->targetedEntities[i]->data));
  14.                 ConnectionSendString(details->connection, &message->targetMessage);
  15.             }
  16.         }
  17.  
  18.         int playerCount = 0;
  19.         //Go through all players in the room besides the owner and target and send the message
  20.         for (uint32 i = 0; i < room->playersInRoom.capacity; i++)
  21.         {
  22.             if (playerCount == room->playersInRoom.count)
  23.                 break;
  24.  
  25.             EntityData* player = room->playersInRoom[i];
  26.  
  27.             if (player != NULL)
  28.             {
  29.                 //Increment counter since we found something regardless if it is being ignored.
  30.                 playerCount++;
  31.  
  32.                 //Check if player is owner or target
  33.                 if (message->ownerEntity->entityID == player->entityID)
  34.                     continue;
  35.  
  36.                 if (targetIds != nullptr)
  37.                 {
  38.                     bool skip = false;
  39.                     for (uint16 i = 0; i < message->targetData->targetCount; i++)
  40.                     {
  41.                         if (targetIds[i] == player->entityID)
  42.                         {
  43.                             skip = true;
  44.                             break;
  45.                         }
  46.                     }
  47.                     if (skip)
  48.                         continue;
  49.                 }
  50.  
  51.                 details = ((CharacterData*)(player->data));
  52.                 ConnectionSendString(details->connection, &message->otherMessage);
  53.             }
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement