⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guild.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////////// Filename		: Guild.cpp// Written by	: bezz// Description	://////////////////////////////////////////////////////////////////////////////#include <algorithm>#include "Guild.h"#include "StringStream.h"#include "DB.h"#ifdef __SHARED_SERVER__	#include "GuildInfo2.h"	#include "GuildMemberInfo2.h"#endif#include "GuildInfo.h"#include "Gpackets/GCGuildMemberList.h"#include "GuildMemberInfo.h"#include <stdio.h>//////////////////////////////////////////////////////////////////////////////// class GuildMember member methods//////////////////////////////////////////////////////////////////////////////GuildMember::GuildMember()	throw(){	m_bLogOn = false;}void GuildMember::create()	throw(){	__BEGIN_TRY	Statement* pStmt = NULL;	Result* pResult = NULL;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pResult = pStmt->executeQuery( "SELECT GuildID FROM GuildMember WHERE Name = '%s'", m_Name.c_str() );		if ( pResult->getRowCount() != 0 )		{			// 捞固 叼厚俊 粮犁窍骨肺 单捞磐父 绊媚霖促.(溜, 傈俊 促弗 辨靛俊 加茄 利捞 乐促)			if ( m_Rank == GUILDMEMBER_RANK_WAIT )			{				pStmt->executeQuery( "UPDATE GuildMember SET GuildID = %d, Rank = %d, ExpireDate = '', RequestDateTime = '%s' WHERE Name = '%s'",										m_GuildID, m_Rank, getRequestDateTime().c_str(), m_Name.c_str() );			}			else			{				pStmt->executeQuery( "UPDATE GuildMember SET GuildID = %d, Rank = %d, ExpireDate = '' WHERE Name = '%s'",										m_GuildID, m_Rank, m_Name.c_str() );			}		}		else		{			if ( m_Rank == GUILDMEMBER_RANK_WAIT )			{				pStmt->executeQuery( "INSERT INTO GuildMember( GuildID, Name, Rank, RequestDateTime ) VALUES ( %d, '%s', %d, '%s' )",										m_GuildID, m_Name.c_str(),  m_Rank, getRequestDateTime().c_str() );			}			else			{				pStmt->executeQuery( "INSERT INTO GuildMember( GuildID, Name, Rank ) VALUES ( %d, '%s', %d )",										m_GuildID, m_Name.c_str(),  m_Rank );			}		}		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__END_CATCH	}bool GuildMember::load()	throw(){	__BEGIN_TRY		Statement* pStmt = NULL;	Result* pResult = NULL;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pResult = pStmt->executeQuery( "SELECT GuildID, Name, Rank, LogOn FROM GuildMember WHERE Name = '%s'", m_Name.c_str() );		if ( pResult->getRowCount() != 1 )		{			SAFE_DELETE( pStmt );			return false;		}		pResult->next();		m_GuildID	= pResult->getInt(1);		m_Name		= pResult->getString(2);		m_Rank		= pResult->getInt(3);		m_bLogOn	= pResult->getInt(4);		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	return true;	__END_CATCH}void GuildMember::save()	throw(){	__BEGIN_TRY	Statement* pStmt = NULL;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();				pStmt->executeQuery( "UPDATE GuildMember SET GuildID = %d, Rank = %d WHERE Name = '%s'",								m_GuildID, m_Rank, m_Name.c_str() );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__END_CATCH}void GuildMember::destroy()	throw(){	__BEGIN_TRY	Statement* pStmt;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt->executeQuery( "DELETE FROM GuildMember WHERE Name = '%s'", m_Name.c_str() );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__END_CATCH}void GuildMember::expire()	throw(){	__BEGIN_TRY	Statement* pStmt;	BEGIN_DB	{		// 泅犁 角矫埃 朝楼甫 备茄促.		time_t daytime = time(0);		tm Timec;		localtime_r( &daytime, &Timec );		char ExpireDate[8];		sprintf( ExpireDate, "%03d%02d%02d", Timec.tm_year, Timec.tm_mon, Timec.tm_mday );		pStmt = g_pDatabaseManager->getConnection( "DARKEDEN" )->createStatement();		pStmt->executeQuery( "UPDATE GuildMember SET Rank = %d, ExpireDate = '%s' WHERE Name = '%s'", GUILDMEMBER_RANK_DENY, ExpireDate, m_Name.c_str() );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__END_CATCH}void GuildMember::leave()	throw(){	__BEGIN_TRY	Statement* pStmt;	BEGIN_DB	{		// 泅犁 角矫埃 朝楼甫 备茄促.		time_t daytime = time(0);		tm Timec;		localtime_r( &daytime, &Timec );		char ExpireDate[8];		sprintf( ExpireDate, "%03d%02d%02d", Timec.tm_year, Timec.tm_mon, Timec.tm_mday );		pStmt = g_pDatabaseManager->getConnection( "DARKEDEN" )->createStatement();		pStmt->executeQuery( "UPDATE GuildMember SET Rank = %d, ExpireDate = '%s' WHERE Name = '%s'", GUILDMEMBER_RANK_LEAVE, ExpireDate, m_Name.c_str() );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__END_CATCH}void GuildMember::saveIntro( const string& intro )	throw(){	__BEGIN_TRY	Statement* pStmt;	string modifyIntro = Guild::correctString( intro );	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection( "DARKEDEN" )->createStatement();		pStmt->executeQuery( "UPDATE GuildMember SET Intro = '%s' WHERE Name = '%s'", modifyIntro.c_str(), m_Name.c_str() );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__END_CATCH}string GuildMember::getIntro() const	throw(){	__BEGIN_TRY	Statement* pStmt;	Result* pResult;	string intro = "";	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection( "DARKEDEN" )->createStatement();		pResult = pStmt->executeQuery( "SELECT Intro FROM GuildMember WHERE Name = '%s'", m_Name.c_str() );		if ( pResult->next() )		{			intro = pResult->getString(1);		}		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	return intro;	__END_CATCH}string GuildMember::toString() const	throw(){	__BEGIN_TRY		StringStream msg;	msg << "GuildID = " << (int)m_GuildID << " Name = " << m_Name << " Rank = " << (int)m_Rank << endl;	return msg.toString();	__END_CATCH}GuildMember& GuildMember::operator=( GuildMember& Member ){	m_GuildID		= Member.m_GuildID;	m_Name			= Member.m_Name;	m_Rank			= Member.m_Rank;	return *this;}string GuildMember::getRequestDateTime() const	throw(){	__BEGIN_TRY	char buf[20];	sprintf( buf, "%4d-%02d-%02d %02d:%02d:%02d",			m_RequestDateTime.date().year(), m_RequestDateTime.date().month(), m_RequestDateTime.date().day(),			m_RequestDateTime.time().hour(), m_RequestDateTime.time().minute(), m_RequestDateTime.time().second() );	cout << buf << endl;	return string(buf);	__END_CATCH}void GuildMember::setRank(GuildMemberRank_t rank)	throw(){	__BEGIN_TRY	m_Rank = rank;	__END_CATCH}void GuildMember::setRequestDateTime( const string& rtime )	throw(){	__BEGIN_TRY	// 0123456789012345678	// YYYY-MM-DD HH:MM:SS	if ( rtime.size() == 19 )	{		int year	= atoi( rtime.substr(0,4).c_str() );		int month	= atoi( rtime.substr(5,2).c_str() );		int day		= atoi( rtime.substr(8,2).c_str() );		int hour	= atoi( rtime.substr(11,2).c_str() );		int min		= atoi( rtime.substr(14,2).c_str() );		int second	= atoi( rtime.substr(17,2).c_str() );		m_RequestDateTime.setDate( VSDate( year, month, day ) );		m_RequestDateTime.setTime( VSTime( hour, min, second ) );	}	else	{		m_RequestDateTime.setDate( VSDate( 2000, 1, 1 ) );		m_RequestDateTime.setTime( VSTime( 0, 0, 0 ) );	}	__END_CATCH}bool GuildMember::isRequestDateTimeOut( const VSDateTime& currentDateTime ) const	throw(){	__BEGIN_TRY	VSDateTime limitDateTime = m_RequestDateTime.addDays(7);	return currentDateTime > limitDateTime;	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// global variable initialization//////////////////////////////////////////////////////////////////////////////GuildID_t Guild::m_MaxGuildID = 0;ZoneID_t Guild::m_MaxSlayerZoneID = 10000;ZoneID_t Guild::m_MaxVampireZoneID = 20000;ZoneID_t Guild::m_MaxOustersZoneID = 30000;//////////////////////////////////////////////////////////////////////////////// class Guild member methods//////////////////////////////////////////////////////////////////////////////Guild::Guild()	throw(){	m_ID			= 0;	m_Name			= "";	m_Type			= 0;	m_State			= 0;	m_ServerGroupID	= 0;	m_ZoneID		= 0;	m_Master		= "";	m_Date			= "";	m_Intro			= "";	m_ActiveMemberCount = 0;	m_WaitMemberCount = 0;	__BEGIN_TRY		m_Mutex.setName( "Guild" );	__END_CATCH}Guild::~Guild()	throw(){	__BEGIN_TRY	__ENTER_CRITICAL_SECTION( m_Mutex )	HashMapGuildMemberItor itr = m_Members.begin();	for ( ; itr != m_Members.end(); itr++ )	{		SAFE_DELETE( itr->second );	}	m_Members.clear();#ifdef __GAME_SERVER__	m_CurrentMembers.clear();#endif	__LEAVE_CRITICAL_SECTION( m_Mutex )	__END_CATCH}void Guild::create()	throw(){	__BEGIN_TRY	Statement* pStmt = NULL;	__ENTER_CRITICAL_SECTION(m_Mutex)	string correctIntro = correctString( m_Intro );	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt->executeQuery( "INSERT INTO GuildInfo ( GuildID, GuildName, GuildType, GuildRace, GuildState, ServerGroupID, GuildZoneID, Master, Date, Intro ) VALUES ( %d, '%s', %d, %d, %d, %d, %d, '%s', '%s', '%s' )",				m_ID, m_Name.c_str(), m_Type, m_Race, m_State, m_ServerGroupID, m_ZoneID, m_Master.c_str(), m_Date.c_str(), correctIntro.c_str() );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__LEAVE_CRITICAL_SECTION(m_Mutex)	__END_CATCH}bool Guild::load()	throw(){	__BEGIN_TRY	Statement*	pStmt	= NULL;	Result*		pResult	= NULL;		__ENTER_CRITICAL_SECTION(m_Mutex)	BEGIN_DB	{		pStmt	= g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pResult	= pStmt->executeQuery( "SELECT GuildName, GuildType, GuildRace, GuildState, ServerGroupID, GuildZoneID, Master, Date FROM GuildInfo WHERE GuildID = %d", m_ID );		if ( pResult->getRowCount() != 1 )		{			SAFE_DELETE( pStmt );			m_Mutex.unlock();			return false;		}		pResult->next();		m_Name			= pResult->getString( 1 );		m_Type			= pResult->getInt( 2 );		m_Race			= pResult->getInt( 3 );		m_State			= pResult->getInt( 4 );		m_ServerGroupID	= pResult->getInt( 5 );		m_ZoneID		= pResult->getInt( 6 );		m_Master		= pResult->getString( 7 );		m_Date			= pResult->getString( 8 );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__LEAVE_CRITICAL_SECTION(m_Mutex)	return true;	__END_CATCH}void Guild::save()	throw(){	__BEGIN_TRY	Statement* pStmt = NULL;	__ENTER_CRITICAL_SECTION(m_Mutex)	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt->executeQuery( "UPDATE GuildInfo SET GuildName = '%s', GuildType = %d, GuildRace = %d, GuildState = %d, ServerGroupID = %d, GuildZoneID = %d, Master = '%s', Date = '%s' WHERE GuildID = %d",								m_Name.c_str(), m_Type, m_Race, m_State, m_ServerGroupID, m_ZoneID, m_Master.c_str(), m_Date.c_str(), m_ID );		SAFE_DELETE( pStmt );	}	END_DB(pStmt)	__LEAVE_CRITICAL_SECTION(m_Mutex)	__END_CATCH}void Guild::destroy()	throw(){	__BEGIN_TRY	Statement* pStmt = NULL;	__ENTER_CRITICAL_SECTION(m_Mutex)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -