SHARE
TWEET

Untitled

a guest Jan 24th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Game::playerModifyVipGroup(uint32_t playerId, VipGroupAction_t type, const std::string& name, uint8_t groupId)
  2. {
  3.     Player* player = getPlayerByID(playerId);
  4.     if (!player) {
  5.         return;
  6.     }
  7.  
  8.     if (type == VIPGROUP_ACTION_ADD) {
  9.         int id = 0;
  10.         auto& vipGroups = player->vipGroups;
  11.         while (std::find_if(vipGroups.begin(), vipGroups.end(), [id](VIPGroup& vipGroup) {
  12.             return vipGroup.id == id;
  13.         }) != vipGroups.end()) {
  14.             id++;
  15.         }
  16.  
  17.         if (id <= 255) {
  18.             player->addVipGroup(id, name);
  19.             player->sendVIPGroupData();
  20.         }
  21.     } else if (type == VIPGROUP_ACTION_EDIT) {
  22.         auto& vipGroups = player->vipGroups;
  23.         auto it = std::find_if(vipGroups.begin(), vipGroups.end(), [groupId](VIPGroup& vipGroup) {
  24.             return vipGroup.id == groupId;
  25.         });
  26.  
  27.         if (it != vipGroups.end()) {
  28.             (*it).name = name;
  29.             player->sendVIPGroupData();
  30.         }
  31.     } else if (type == VIPGROUP_ACTION_REMOVE) {
  32.         auto& vipGroups = player->vipGroups;
  33.         auto it = std::find_if(vipGroups.begin(), vipGroups.end(), [groupId](VIPGroup& vipGroup) {
  34.             return vipGroup.id == groupId;
  35.         });
  36.  
  37.         if (it != vipGroups.end()) {
  38.             vipGroups.erase(it);
  39.             player->sendVIPGroupData();
  40.  
  41.             const std::forward_list<VIPEntry>& vipEntries = IOLoginData::getVIPEntries(player->getAccount());
  42.  
  43.             for (const VIPEntry& entry : vipEntries) {
  44.                 std::vector<int32_t> groups = entry.groups;
  45.                 auto itt = std::find(groups.begin(), groups.end(), static_cast<int32_t>(groupId));
  46.                 if (itt == groups.end()) {
  47.                     continue;
  48.                 }
  49.  
  50.                 groups.erase(itt);
  51.  
  52.                 VipStatus_t vipStatus = VIPSTATUS_ONLINE;
  53.  
  54.                 Player* vipPlayer = g_game.getPlayerByGUID(entry.guid);
  55.  
  56.                 if (!vipPlayer || vipPlayer->isInGhostMode() || player->isAccessPlayer()) {
  57.                     vipStatus = VIPSTATUS_OFFLINE;
  58.                 }
  59.  
  60.                 player->editVIP(entry.guid, entry.description, entry.icon, entry.notify, groups);
  61.                 player->sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus, groups);
  62.             }
  63.         }
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top