From 875d46f9b5d0bf435bc560152c1d561c3d689c25 Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Mon, 18 Jul 2011 19:37:59 +0200 Subject: [PATCH] Changed: #1304: Implementation of the cbClientGroupAbandonMission for the guilds --HG-- branch : gsoc2011-guildmissions --- .../guild_manager/guild.cpp | 17 +++ .../guild_manager/guild.h | 1 + .../mission_client_callbacks.cpp | 127 +++++++++++++----- 3 files changed, 112 insertions(+), 33 deletions(-) diff --git a/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp b/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp index 158508202..3a05ef309 100644 --- a/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp +++ b/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp @@ -35,6 +35,7 @@ #include "primitives_parser.h" #include "modules/shard_unifier_client.h" #include "mission_manager/mission_manager.h" +#include "phrase_manager/phrase_utilities_functions.h" /// todo guild remove entity id translator #include "nel/misc/eid_translator.h" @@ -745,6 +746,22 @@ void CGuild::updateMissionHistories(TAIAlias missionAlias, uint32 result) } } +//---------------------------------------------------------------------------- +void CGuild::sendDynamicMessageToMembers(const string &msgName, const TVectorParamCheck ¶ms, const set &excluded) const +{ + for ( std::map::const_iterator it = getMembersBegin(); + it != getMembersEnd();++it ) + { + CCharacter * user = PlayerManager.getChar( it->first ); + + if ( excluded.find(it->first) == excluded.end()) + { + const uint32 stringId = STRING_MANAGER::sendStringToClient(TheDataset.getDataSetRow(it->first), msgName, params ); + PHRASE_UTILITIES::sendDynamicSystemMessage(TheDataset.getDataSetRow(it->first), stringId); + } + } +} + //---------------------------------------------------------------------------- bool CGuild::processMissionEvent( CMissionEvent & event, TAIAlias alias) { diff --git a/code/ryzom/server/src/entities_game_service/guild_manager/guild.h b/code/ryzom/server/src/entities_game_service/guild_manager/guild.h index 61dc97dd2..64378b717 100644 --- a/code/ryzom/server/src/entities_game_service/guild_manager/guild.h +++ b/code/ryzom/server/src/entities_game_service/guild_manager/guild.h @@ -200,6 +200,7 @@ public: bool processGuildMissionStepEvent(std::list< CMissionEvent* > & eventList, TAIAlias missionAlias, uint32 stepIndex); CMissionGuild* getMissionByAlias( TAIAlias missionAlias ); bool isMissionSuccessfull(TAIAlias alias); + void sendDynamicMessageToMembers(const std::string &msgName, const TVectorParamCheck ¶ms, const std::set &excluded) const; ///\return the mission inline std::vector & getMissions() { diff --git a/code/ryzom/server/src/entities_game_service/mission_client_callbacks.cpp b/code/ryzom/server/src/entities_game_service/mission_client_callbacks.cpp index f0205ed95..52fd214f9 100644 --- a/code/ryzom/server/src/entities_game_service/mission_client_callbacks.cpp +++ b/code/ryzom/server/src/entities_game_service/mission_client_callbacks.cpp @@ -26,6 +26,9 @@ #include "team_manager/team_manager.h" #include "mission_manager/mission_team.h" #include "mission_manager/mission_log.h" +#include "guild_manager/guild_manager.h" +#include "guild_manager/guild.h" +#include "guild_manager/guild_member.h" using namespace std; @@ -222,50 +225,108 @@ void cbClientGroupAbandonMission( NLNET::CMessage& msgin, const std::string &ser CCharacter * user = PlayerManager.getChar( userId ); user->setAfkState(false); - CTeam * team = TeamManager.getRealTeam( user->getTeamId() ); - if ( !team ) - { - MISLOG("user:%s cbClientGroupAbandonMission : Invalid team", userId.toString().c_str()); - return; - } - if ( team->getLeader() != userId ) - { - CCharacter::sendDynamicSystemMessage( user->getEntityRowId(), "REQ_LEADER_TO_ABANDON_MISSION" ); - return; - } - if ( index >= team->getMissions().size() ) + // We check if it's a guild or team mission + if (index < MaxGroupMissionCount) { - MISLOG("user:%s cbClientGroupAbandonMission : Invalid group mission %u ( count %u )", - userId.toString().c_str(), index, team->getMissions().size()); - return; - } - + // Team - CMissionTeam* mission = team->getMissions()[index]; - nlassert(mission); - - if ( mission->getFinished() == false ) - { - CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( mission->getTemplateId() ); - if ( !templ ) + CTeam * team = TeamManager.getRealTeam( user->getTeamId() ); + if ( !team ) { - MISLOG("user:%s cbClientGroupAbandonMission : invalid group mission alias %u", - userId.toString().c_str(), mission->getTemplateId()); + MISLOG("user:%s cbClientGroupAbandonMission : Invalid team", userId.toString().c_str()); return; } - if ( templ->Tags.NonAbandonnable ) + if ( team->getLeader() != userId ) { - MISLOG("user:%s cbClientGroupAbandonMission : group mission alias %u is not abandonnable but user tries to abandon it", - userId.toString().c_str(), mission->getTemplateId()); + CCharacter::sendDynamicSystemMessage( user->getEntityRowId(), "REQ_LEADER_TO_ABANDON_MISSION" ); + return; + } + + if ( index >= team->getMissions().size() ) + { + MISLOG("user:%s cbClientGroupAbandonMission : Invalid group mission %u ( count %u )", + userId.toString().c_str(), index, team->getMissions().size()); return; } - set excluded; - excluded.insert( userId ); - team->sendDynamicMessageToMembers( "ABANDON_GROUP_MISSION",TVectorParamCheck(), excluded ); + + CMissionTeam* mission = team->getMissions()[index]; + nlassert(mission); + + if ( mission->getFinished() == false ) + { + CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( mission->getTemplateId() ); + if ( !templ ) + { + MISLOG("user:%s cbClientGroupAbandonMission : invalid group mission alias %u", + userId.toString().c_str(), mission->getTemplateId()); + return; + } + if ( templ->Tags.NonAbandonnable ) + { + MISLOG("user:%s cbClientGroupAbandonMission : group mission alias %u is not abandonnable but user tries to abandon it", + userId.toString().c_str(), mission->getTemplateId()); + return; + } + set excluded; + excluded.insert( userId ); + + team->sendDynamicMessageToMembers( "ABANDON_GROUP_MISSION",TVectorParamCheck(), excluded ); + } + team->removeMission( index, mr_abandon ); + } + else + { + // Guild + // We set the correct index + index = MaxGroupMissionCount - index; + + CGuild * guild = CGuildManager::getInstance()->getGuildFromId( user->getGuildId() ); + if ( !guild ) + { + MISLOG("user:%s cbClientGroupAbandonMission : Invalid team", userId.toString().c_str()); + return; + } + if ( guild->getLeader()->getIngameEId() != userId ) + { + CCharacter::sendDynamicSystemMessage( user->getEntityRowId(), "REQ_LEADER_TO_ABANDON_MISSION" ); + return; + } + + if ( index >= guild->getMissions().size() ) + { + MISLOG("user:%s cbClientGroupAbandonMission : Invalid group mission %u ( count %u )", + userId.toString().c_str(), index, guild->getMissions().size()); + return; + } + + + CMissionGuild* mission = guild->getMissions()[index]; + nlassert(mission); + + if ( mission->getFinished() == false ) + { + CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( mission->getTemplateId() ); + if ( !templ ) + { + MISLOG("user:%s cbClientGroupAbandonMission : invalid group mission alias %u", + userId.toString().c_str(), mission->getTemplateId()); + return; + } + if ( templ->Tags.NonAbandonnable ) + { + MISLOG("user:%s cbClientGroupAbandonMission : group mission alias %u is not abandonnable but user tries to abandon it", + userId.toString().c_str(), mission->getTemplateId()); + return; + } + set excluded; + excluded.insert( userId ); + + guild->sendDynamicMessageToMembers( "ABANDON_GROUP_MISSION",TVectorParamCheck(), excluded ); + } + guild->removeMission( index, mr_abandon ); } - team->removeMission( index, mr_abandon ); } //----------------------------------------------------------------------------