📄 guildmanager.cpp
字号:
////////////////////////////////////////////////////////////////////////// Filename : GuildManager.cpp// Written By : 辫己刮// Description : ////////////////////////////////////////////////////////////////////////#include "Guild.h"#include "GuildManager.h"#include "StringStream.h"#include "DB.h"#include "Properties.h"#ifdef __GAME_SERVER__ #include "Zone.h" #include "ZoneInfoManager.h" #include "ZoneGroupManager.h" #include "PlayerCreature.h" #include "CastleInfoManager.h" #include "ZoneUtil.h" #include "war/WarScheduler.h"#endif#ifdef __SHARED_SERVER__ #include "Spackets/SGGuildInfo.h" #include "Spackets/SGExpelGuildMemberOK.h" #include "GameServerManager.h"#endif#include "Gpackets/GCWaitGuildList.h"#include "Gpackets/GCActiveGuildList.h"////////////////////////////////////////////////////////////////////////// global varible initialization////////////////////////////////////////////////////////////////////////GuildManager* g_pGuildManager = NULL;////////////////////////////////////////////////////////////////////////// class GuildManager member methods////////////////////////////////////////////////////////////////////////GuildManager::GuildManager() throw(){ __BEGIN_TRY m_Mutex.setName( "GuildManager" ); __END_CATCH}GuildManager::~GuildManager() throw(){ __BEGIN_TRY __ENTER_CRITICAL_SECTION( m_Mutex ) // 葛电 辨靛 按眉甸阑 皋葛府俊辑 昏力茄促. hash_map<GuildID_t, Guild*>::iterator itr = m_Guilds.begin(); for (; itr != m_Guilds.end(); itr++) { Guild* pGuild = itr->second; SAFE_DELETE(pGuild); } m_Guilds.clear(); __LEAVE_CRITICAL_SECTION( m_Mutex ) __END_CATCH}void GuildManager::init() throw(){#ifdef __SHARED_SERVER__ __BEGIN_TRY Statement* pStmt = NULL; Result* pResult = NULL; __ENTER_CRITICAL_SECTION( m_Mutex ) BEGIN_DB { // 辨靛 ID绰 弥措蔼阑 沥秦初绊, 货肺款 辨靛啊 积扁搁 弥措蔼俊促 // 1阑 歹秦辑 且寸窍绰 规侥栏肺 款康等促. 弊矾骨肺 辨靛 概聪历啊 // 檬扁拳瞪 锭, 泅犁 粮犁窍绰 辨靛 ID狼 弥措蔼阑 佬绢甸咯敌促. pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pResult = pStmt->executeQuery("SELECT COUNT(*) FROM GuildInfo"); // 抛捞喉俊 单捞鸥啊 窍唱档 绝促搁, 老窜 钙胶 酒捞叼绰 1肺 技泼秦霖促. pResult->next(); if (pResult->getInt(1) == 0) { Guild::setMaxGuildID( g_pConfig->getPropertyInt("Dimension") * 10000 + g_pConfig->getPropertyInt("WorldID") * 3000 + 100 ); } else { // get & set MaxGuildID pResult = pStmt->executeQuery("SELECT MAX(GuildID) FROM GuildInfo"); pResult->next(); Guild::setMaxGuildID( pResult->getInt(1) ); } pResult = pStmt->executeQuery( "SELECT COUNT(*) FROM GuildInfo WHERE GuildRace = %d", Guild::GUILD_RACE_SLAYER ); pResult->next(); if ( pResult->getInt(1) == 0 ) { Guild::setMaxSlayerZoneID( Guild::getMaxSlayerZoneID() + 1 ); } else { // get & set MaxSlayerZoneID pResult = pStmt->executeQuery( "SELECT MAX(GuildZoneID) FROM GuildInfo WHERE GuildRace = %d", Guild::GUILD_RACE_SLAYER ); pResult->next(); Guild::setMaxSlayerZoneID( max( pResult->getInt(1), Guild::getMaxSlayerZoneID() + 1 ) ); } pResult = pStmt->executeQuery( "SELECT COUNT(*) FROM GuildInfo WHERE GuildRace = %d", Guild::GUILD_RACE_VAMPIRE ); pResult->next(); if ( pResult->getInt(1) == 0 ) { Guild::setMaxVampireZoneID( Guild::getMaxVampireZoneID() + 1 ); } else { // get & set MaxVampireZoneID pResult = pStmt->executeQuery( "SELECT MAX(GuildZoneID) FROM GuildInfo WHERE GuildRace = %d", Guild::GUILD_RACE_VAMPIRE ); pResult->next(); Guild::setMaxVampireZoneID( max( pResult->getInt(1), Guild::getMaxVampireZoneID() + 1 ) ); } pResult = pStmt->executeQuery( "SELECT COUNT(*) FROM GuildInfo WHERE GuildRace = %d", Guild::GUILD_RACE_OUSTERS ); pResult->next(); if ( pResult->getInt(1) == 0 ) { Guild::setMaxOustersZoneID( Guild::getMaxOustersZoneID() + 1 ); } else { // get & set MaxOustersZoneID pResult = pStmt->executeQuery( "SELECT MAX(GuildZoneID) FROM GuildInfo WHERE GuildRace = %d", Guild::GUILD_RACE_OUSTERS ); pResult->next(); Guild::setMaxOustersZoneID( max( pResult->getInt(1), Guild::getMaxOustersZoneID() + 1 ) ); } SAFE_DELETE(pStmt); } END_DB(pStmt) __LEAVE_CRITICAL_SECTION( m_Mutex ) load(); __END_CATCH#endif}void GuildManager::load() throw(){ __BEGIN_TRY Statement* pStmt = NULL; Result* pResult = NULL; __ENTER_CRITICAL_SECTION( m_Mutex ) BEGIN_DB { // 辨靛 沥焊甫 DB肺 何磐 佬绢柯促. pStmt = g_pDatabaseManager->getConnection( "DARKEDEN" )->createStatement(); pResult = pStmt->executeQuery( "SELECT GuildID, GuildName, GuildType, GuildRace, GuildState, ServerGroupID, GuildZoneID, Master, Date, Intro FROM GuildInfo WHERE GuildState IN ( %d, %d )", Guild::GUILD_STATE_WAIT, Guild::GUILD_STATE_ACTIVE ); while ( pResult->next() ) { GuildState_t state = pResult->getInt(5); // 泅犁 岿靛狼 殿废 措扁吝牢 辨靛客 劝悼 吝牢 辨靛父 眠啊茄促. if ( state == Guild::GUILD_STATE_WAIT || state == Guild::GUILD_STATE_ACTIVE ) { Guild* pGuild = new Guild(); pGuild->setID( pResult->getInt(1) ); pGuild->setName( pResult->getString(2) ); pGuild->setType( pResult->getInt(3) ); pGuild->setRace( pResult->getInt(4) ); pGuild->setState( state ); pGuild->setServerGroupID( pResult->getInt(6) ); pGuild->setZoneID( pResult->getInt(7) ); pGuild->setMaster( pResult->getString(8) ); pGuild->setDate( pResult->getString(9) ); pGuild->setIntro( pResult->getString(10) ); addGuild_NOBLOCKED( pGuild );/*#ifdef __GAME_SERVER__ // 辨靛啊 Active 捞绊 捞 霸烙 辑滚俊 酒瘤飘啊 粮犁茄促搁 酒瘤飘 Zone阑 父电促. if ( pGuild->getServerGroupID() == g_pConfig->getPropertyInt("ServerID") && state == Guild::GUILD_STATE_ACTIVE ) { ////////////// // Zone Info ////////////// ZoneInfo* pZoneInfo = new ZoneInfo(); pZoneInfo->setZoneID( pGuild->getZoneID() ); pZoneInfo->setZoneGroupID( 6 ); pZoneInfo->setZoneType( "NPC_SHOP" ); pZoneInfo->setZoneLevel( 0 ); pZoneInfo->setZoneAccessMode( "PUBLIC" ); pZoneInfo->setZoneOwnerID( "" ); pZoneInfo->setPayPlay( "" ); if ( pGuild->getRace() == Guild::GUILD_RACE_SLAYER ) { pZoneInfo->setSMPFilename( "team_hdqrs.smp" ); pZoneInfo->setSSIFilename( "team_hdqrs.ssi" ); string Name = "team - " + pGuild->getName(); pZoneInfo->setFullName( Name ); pZoneInfo->setShortName( Name ); } else if ( pGuild->getRace() == Guild::GUILD_RACE_VAMPIRE ) { pZoneInfo->setSMPFilename( "clan_hdqrs.smp" ); pZoneInfo->setSSIFilename( "clan_hdqrs.ssi" ); string Name = "clan - " + pGuild->getName(); pZoneInfo->setFullName( Name ); pZoneInfo->setShortName( Name ); } g_pZoneInfoManager->addZoneInfo( pZoneInfo ); ///////// // Zone ///////// Zone* pZone = new Zone( pGuild->getZoneID() ); Assert( pZone != NULL ); ZoneGroup* pZoneGroup = g_pZoneGroupManager->getZoneGroup(6); Assert( pZoneGroup != NULL ); pZone->setZoneGroup( pZoneGroup ); pZoneGroup->addZone( pZone ); pZone->init(); }#endif*/ } } // 辨靛 糕滚 沥焊甫 DB肺 何磐 佬绢柯促. pResult = pStmt->executeQuery( "SELECT GuildID, Name, Rank, RequestDateTime, LogOn FROM GuildMember WHERE Rank IN ( 0, 1, 2, 3 )" ); while ( pResult->next() ) { GuildMember* pMember = new GuildMember(); pMember->setGuildID( pResult->getInt(1) ); pMember->setName( pResult->getString(2) ); pMember->setRank( pResult->getInt(3) ); if ( pMember->getRank() == GuildMember::GUILDMEMBER_RANK_WAIT ) pMember->setRequestDateTime( pResult->getString(4) ); pMember->setLogOn( pResult->getInt(5) ); Guild* pGuild = getGuild_NOBLOCKED( pMember->getGuildID() ); if ( pGuild != NULL ) pGuild->addMember( pMember ); } SAFE_DELETE( pStmt ); } END_DB(pStmt) __LEAVE_CRITICAL_SECTION( m_Mutex ) __END_CATCH}void GuildManager::addGuild(Guild* pGuild) throw (DuplicatedException){ __BEGIN_TRY Assert(pGuild != NULL); __ENTER_CRITICAL_SECTION( m_Mutex ) hash_map<GuildID_t, Guild*>::iterator itr = m_Guilds.find(pGuild->getID()); if (itr != m_Guilds.end()) throw DuplicatedException(); m_Guilds[pGuild->getID()] = pGuild; __LEAVE_CRITICAL_SECTION( m_Mutex ) __END_CATCH}void GuildManager::addGuild_NOBLOCKED(Guild* pGuild) throw (DuplicatedException){ __BEGIN_TRY Assert(pGuild != NULL); hash_map<GuildID_t, Guild*>::iterator itr = m_Guilds.find(pGuild->getID()); if (itr != m_Guilds.end()) throw DuplicatedException(); m_Guilds[pGuild->getID()] = pGuild; __END_CATCH}void GuildManager::deleteGuild(GuildID_t id) throw (NoSuchElementException){ __BEGIN_TRY __ENTER_CRITICAL_SECTION( m_Mutex ) hash_map<GuildID_t, Guild*>::iterator itr = m_Guilds.find(id); if (itr == m_Guilds.end()) throw NoSuchElementException();#ifdef __GAME_SERVER__ list<CastleInfo*> pGuildCastleInfoList = g_pCastleInfoManager->getGuildCastleInfos( id ); if ( !pGuildCastleInfoList.empty() ) { // 己阑 爱绊 乐绰 辨靛促.. 傍侩己栏肺 官层拎具 等促. list<CastleInfo*>::iterator itr = pGuildCastleInfoList.begin(); for ( ; itr != pGuildCastleInfoList.end() ; itr++ ) { if ( (*itr)->getRace() == RACE_SLAYER ) g_pCastleInfoManager->modifyCastleOwner( (*itr)->getZoneID(), RACE_SLAYER, 99 ); else g_pCastleInfoManager->modifyCastleOwner( (*itr)->getZoneID(), RACE_VAMPIRE, 0 ); } } { const hash_map<ZoneID_t, CastleInfo*>& castleInfos = g_pCastleInfoManager->getCastleInfos(); hash_map<ZoneID_t, CastleInfo*>::const_iterator itr = castleInfos.begin(); hash_map<ZoneID_t, CastleInfo*>::const_iterator endItr = castleInfos.end(); for ( ; itr != endItr ; ++itr ) { Zone* pZone = getZoneByZoneID( itr->first ); if ( pZone != NULL ) { WarScheduler* pWarScheduler = pZone->getWarScheduler(); if ( pWarScheduler != NULL && pWarScheduler->hasSchedule( id ) ) { pWarScheduler->load(); } } } }#endif m_Guilds.erase(itr);#ifdef __SHARED_SERVER__ Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); // DB俊辑 GuildInfo甫 瘤款促. pStmt->executeQuery("DELETE FROM GuildInfo WHERE GuildID=%d", id); // GuildMember甫 促 瘤款促. pStmt->executeQuery("DELETE FROM GuildMember WHERE GuildID=%d", id); pStmt->executeQuery("UPDATE WarScheduleInfo SET Status='CANCEL' WHERE AttackGuildID=%d AND Status='WAIT'", id); SAFE_DELETE(pStmt); } END_DB(pStmt)#endif __LEAVE_CRITICAL_SECTION( m_Mutex ) __END_CATCH}Guild* GuildManager::getGuild(GuildID_t id) throw (){ __BEGIN_TRY // 府畔 且 辨靛 器牢磐 Guild* pGuild; __ENTER_CRITICAL_SECTION( m_Mutex ) hash_map<GuildID_t, Guild*>::iterator itr = m_Guilds.find(id); if (itr == m_Guilds.end()) { m_Mutex.unlock(); return NULL; } pGuild = itr->second;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -