void GroupManager::leaveGroup(ManagedReference<GroupObject*> group, CreatureObject* player) { // Pre: player locked // Post: player locked if (group == NULL) return; try { Locker clocker(group, player); ChatRoom* groupChannel = group->getGroupChannel(); if (groupChannel != NULL && player->isPlayerCreature()) { CreatureObject* playerCreature = cast<CreatureObject*>( player); groupChannel->removePlayer(playerCreature, false); groupChannel->sendDestroyTo(playerCreature); ChatRoom* room = groupChannel->getParent(); room->sendDestroyTo(playerCreature); } if (!group->isOtherMemberPlayingMusic(player)) group->setBandSong(""); player->updateGroup(NULL); //if (player != NULL && player->isOnline() && !player->isLoggingOut()) if (player->isPlayerCreature()) player->sendSystemMessage("@group:removed"); player->unlock(); group->removeMember(player); if (player->isPlayerCreature()) group->sendDestroyTo(player); player->info("leaving group"); if (group->getGroupSize() < 2) { group->disband(); } } catch (Exception& e) { System::out << e.getMessage(); e.printStackTrace(); } catch (...) { player->wlock(); throw; } player->wlock(); }
void GroupManager::disbandGroup(ManagedReference<GroupObject*> group, CreatureObject* player) { //Pre: player locked //Post: player locked player->unlock(); try { group->wlock(); //The following should never happen, as a check is made in //ObjectControlMessage.cpp and removes the player from the group //if he's not the leader. Remove? //After Fix 13 feb 2009 - Bankler if (group->getLeader() != player) { player->sendSystemMessage("@group:must_be_leader"); group->unlock(); player->wlock(); return; } for (int i = 0; i < group->getGroupSize(); i++) { Reference<CreatureObject*> play = ( group->getGroupMember(i)).castTo<CreatureObject*>(); if (play->isPlayerCreature()) { play->sendSystemMessage("@group:disbanded"); //"The group has been disbanded." //Close any open Group SUIs. ManagedReference<PlayerObject*> ghost = play->getPlayerObject(); if (ghost != NULL) { ghost->closeSuiWindowType(SuiWindowType::GROUP_LOOT_RULE); ghost->closeSuiWindowType(SuiWindowType::GROUP_LOOT_CHANGED); ghost->closeSuiWindowType(SuiWindowType::GROUP_LOOT_PICK_LOOTER); } } } group->disband(); group->unlock(); } catch (...) { group->unlock(); player->wlock(); throw; } player->wlock(); }
void GroupManager::kickFromGroup(ManagedReference<GroupObject*> group, CreatureObject* player, CreatureObject* memberToKick) { // Pre: player is locked, group != NULL // Post: memberToKick kicked from group player->unlock(); bool disbanded = false; try { group->wlock(); if (!group->hasMember(memberToKick)) { group->unlock(); player->wlock(); return; } Reference<CreatureObject*> leader = ( group->getLeader()).castTo<CreatureObject*>(); if (player != leader) { player->sendSystemMessage("@group:must_be_leader"); group->unlock(); player->wlock(); return; } if (group->getGroupSize() - 1 < 2) { for (int i = 0; i < group->getGroupSize(); i++) { Reference<CreatureObject*> play = ( group->getGroupMember(i)).castTo<CreatureObject*>(); play->sendSystemMessage("@group:disbanded"); } group->disband(); disbanded = true; } else { group->removeMember(memberToKick); if (memberToKick->isPlayerCreature()) memberToKick->sendSystemMessage("@group:removed"); memberToKick->info("kicking from group"); } group->unlock(); } catch (...) { group->unlock(); player->wlock(); throw; } if (!disbanded) { try { memberToKick->wlock(); if (memberToKick->isPlayerCreature()) { CreatureObject* pl = cast<CreatureObject*>( memberToKick); ManagedReference<ChatRoom*> groupChannel = group->getGroupChannel(); groupChannel->removePlayer(pl, false); groupChannel->sendDestroyTo(pl); ManagedReference<ChatRoom*> room = groupChannel->getParent(); room->sendDestroyTo(pl); } memberToKick->updateGroup(NULL); if (memberToKick->isPlayerCreature()) group->sendDestroyTo(memberToKick); memberToKick->unlock(); } catch (...) { memberToKick->unlock(); player->wlock(); throw; } } player->wlock(); }