コード例 #1
0
ファイル: remote_call.cpp プロジェクト: jcon321/Server
void handle_rc_relay(const std::string &method, const std::string &connection_id, const std::string &request_id, const std::vector<std::string> &params) {
	std::string error;
	std::map<std::string, std::string> res;
	uint32 zone_id = 0;
	uint32 instance_id = 0;
	ZoneServer *zs = nullptr;
	
	if(params.size() < 2) {
		error = "Missing zone relay params";
		RemoteCallResponse(connection_id, request_id, res, error);
		return;
	}
	
	zone_id = (uint32)atoi(params[0].c_str());
	instance_id = (uint32)atoi(params[1].c_str());
	if(!zone_id && !instance_id) {
		error = "Zone not booted";
		RemoteCallResponse(connection_id, request_id, res, error);
		return;
	}
	
	
	if(instance_id) {
		zs = zoneserver_list.FindByInstanceID(instance_id);
	} else {
		zs = zoneserver_list.FindByZoneID(zone_id);
	}
	
	if(!zs) {
		error = "Zone server not found";
		RemoteCallResponse(connection_id, request_id, res, error);
		return;
	}
	
	uint32 sz = (uint32)(request_id.size() + connection_id.size() + method.size() + 3 + 16);
	uint32 p_sz = (uint32)params.size() - 2;
	for(uint32 i = 0; i < p_sz; ++i) {
		auto &param = params[i + 2];
		sz += (uint32)param.size();
		sz += 5;
	}
	
	ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCall, sz);
	pack->WriteUInt32((uint32)request_id.size());
	pack->WriteString(request_id.c_str());
	pack->WriteUInt32((uint32)connection_id.size());
	pack->WriteString(connection_id.c_str());
	pack->WriteUInt32((uint32)method.size());
	pack->WriteString(method.c_str());
	pack->WriteUInt32(p_sz);
	
	for(uint32 i = 0; i < p_sz; ++i) {
		auto &param = params[i + 2];
		pack->WriteUInt32((uint32)param.size());
		pack->WriteString(param.c_str());
	}
	
	zs->SendPacket(pack);
	safe_delete(pack);
}
コード例 #2
0
ファイル: lfguild.cpp プロジェクト: Lord-Ptolemy/projecteqemu
void LFGuildManager::SendPlayerStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From)
{

	std::list<PlayerLookingForGuild>::iterator it;

	for(it = Players.begin(); it != Players.end(); ++it)
	{
		if(!strcasecmp((*it).Name.c_str(), From))
		{
			ServerPacket *pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + (*it).Comments.length() + 30);

			pack->WriteUInt32(FromZoneID);
			pack->WriteUInt32(FromInstanceID);
			pack->WriteString(From);
			pack->WriteUInt32(QSG_LFGuild);
			pack->WriteUInt32(QSG_LFGuild_RequestPlayerInfo);
			pack->WriteString((*it).Comments.c_str());
			pack->WriteUInt32((*it).TimeZone);
			pack->WriteUInt32((*it).TimePosted);
			pack->WriteUInt32(1);
			
			worldserver->SendPacket(pack);
			safe_delete(pack);
			break;
		}
	}
}
コード例 #3
0
void RemoteCallSubscriptionHandler::Process() {
	//create a check for all these connection ids packet
	uint32 sz = 12;
	auto iter = connection_ids.begin();
	while(iter != connection_ids.end()) {
		sz += (uint32)iter->first.size();
		sz += 5;
		++iter;
	}

	if (!zone)
		return;

	ServerPacket *pack = new ServerPacket(ServerOP_WIClientSession, sz);
	pack->WriteUInt32((uint32)zone->GetZoneID());
	pack->WriteUInt32((uint32)zone->GetInstanceID());
	pack->WriteUInt32((uint32)connection_ids.size());

	iter = connection_ids.begin();
	while(iter != connection_ids.end()) {
		pack->WriteUInt32((uint32)iter->first.size());
		pack->WriteString(iter->first.c_str());
		++iter;
	}

	worldserver.SendPacket(pack);
	safe_delete(pack);
}
コード例 #4
0
ファイル: zoneserver.cpp プロジェクト: Vaion/Server
void ZoneServer::SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message) {
	if (!message)
		return;
	ServerPacket* pack = new ServerPacket;

	pack->opcode = ServerOP_EmoteMessage;
	pack->size = sizeof(ServerEmoteMessage_Struct)+strlen(message)+1;
	pack->pBuffer = new uchar[pack->size];
	memset(pack->pBuffer, 0, pack->size);
	ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*) pack->pBuffer;
	
	if (to != 0) {
		strcpy((char *) sem->to, to);
	}
	else {
		sem->to[0] = 0;
	}

	sem->guilddbid = to_guilddbid;
	sem->minstatus = to_minstatus;
	sem->type = type;
	strcpy(&sem->message[0], message);
	
	pack->Deflate();
	SendPacket(pack);
	delete pack;
}
コード例 #5
0
ファイル: queryserv.cpp プロジェクト: Kiddinglife/Server
void QueryServ::SendQuery(std::string Query)
{
	ServerPacket* pack = new ServerPacket(ServerOP_QSSendQuery, Query.length() + 5);
	pack->WriteUInt32(Query.length()); /* Pack Query String Size so it can be dynamically broken out at queryserv */
	pack->WriteString(Query.c_str()); /* Query */
	worldserver.SendPacket(pack);
	safe_delete(pack);
}
コード例 #6
0
ファイル: lfguild.cpp プロジェクト: Lord-Ptolemy/projecteqemu
void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Class, uint32 Level, uint32 AAPoints, char *Comments, uint32 Toggle, uint32 TimeZone)
{
	char errbuf[MYSQL_ERRMSG_SIZE];
	char* query = 0;

	std::list<PlayerLookingForGuild>::iterator it;

	for(it = Players.begin(); it != Players.end(); ++it)
	{
		if(!strcasecmp((*it).Name.c_str(), From))
		{
			Players.erase(it);

			break;
		}
	}

	if(!database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM `lfguild` WHERE `type` = 0 AND `name` = '%s'", From), errbuf, 0, 0))
		_log(QUERYSERV__ERROR, "Error removing player from LFGuild table,  query was %s, %s", query, errbuf);

	safe_delete_array(query);

	uint32 Now = time(NULL);

	if(Toggle == 1)
	{
		PlayerLookingForGuild p(From, Comments, Level, Class, AAPoints, TimeZone, Now);
		Players.push_back(p);
		if(!database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO `lfguild` (`type`, `name`, `comment`, `fromlevel`, `tolevel`, `classes`, `aacount`, `timezone`, `timeposted`) VALUES(0, '%s', '%s', %u, 0, %u, %u, %u, %u)", From, Comments, Level, Class, AAPoints, TimeZone, Now), errbuf, 0, 0))
			_log(QUERYSERV__ERROR, "Error inserting player into LFGuild table, query was %s, %s", query, errbuf);

		safe_delete_array(query);

	}

	ServerPacket *pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + strlen(Comments) + 30);

	pack->WriteUInt32(FromZoneID);
	pack->WriteUInt32(FromInstanceID);
	pack->WriteString(From);
	pack->WriteUInt32(QSG_LFGuild);
	pack->WriteUInt32(QSG_LFGuild_RequestPlayerInfo);
	pack->WriteString(Comments);
	pack->WriteUInt32(TimeZone);
	pack->WriteUInt32(Now);
	pack->WriteUInt32(Toggle);

	worldserver->SendPacket(pack);
	safe_delete(pack);
	
}
コード例 #7
0
ファイル: zonelist.cpp プロジェクト: Corysia/Server
void ZSList::SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message) {
	if (!message)
		return;
	ServerPacket* pack = new ServerPacket;

	pack->opcode = ServerOP_EmoteMessage;
	pack->size = sizeof(ServerEmoteMessage_Struct)+strlen(message)+1;
	pack->pBuffer = new uchar[pack->size];
	memset(pack->pBuffer, 0, pack->size);
	ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*) pack->pBuffer;

	if (to) {
		if (to[0] == '*') {
			Console* con = console_list.FindByAccountName(&to[1]);
			if (con)
				con->SendEmoteMessageRaw(to, to_guilddbid, to_minstatus, type, message);
			delete pack;
			return;
		}
		strcpy((char *) sem->to, to);
	}
	else {
		sem->to[0] = 0;
	}

	sem->guilddbid = to_guilddbid;
	sem->minstatus = to_minstatus;
	sem->type = type;
	strcpy(&sem->message[0], message);
	char tempto[64]={0};
	if(to)
		strn0cpy(tempto,to,64);
	pack->Deflate();
	if (tempto[0] == 0) {
		SendPacket(pack);
		if (to_guilddbid == 0)
			console_list.SendEmoteMessageRaw(type, message);
	}
	else {
		ZoneServer* zs = FindByName(to);

		if (zs != 0)
			zs->SendPacket(pack);
		else
			SendPacket(pack);
	}
	delete pack;
}
コード例 #8
0
ファイル: cliententry.cpp プロジェクト: Leere/Server
void ClientListEntry::ProcessTellQueue()
{
	if (!Server())
		return;

	ServerPacket *pack;
	auto it = tell_queue.begin();
	while (it != tell_queue.end()) {
		pack = new ServerPacket(ServerOP_ChannelMessage, sizeof(ServerChannelMessage_Struct) + strlen((*it)->message) + 1);
		memcpy(pack->pBuffer, *it, pack->size);
		pack->Deflate();
		Server()->SendPacket(pack);
		safe_delete(pack);
		it = tell_queue.erase(it);
	}
	return;
}
コード例 #9
0
ファイル: lfguild.cpp プロジェクト: Lord-Ptolemy/projecteqemu
void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char *From, char* GuildName, char *Comments, uint32 FromLevel, uint32 ToLevel, uint32 Classes, uint32 AACount, uint32 Toggle, uint32 TimeZone)
{
	char errbuf[MYSQL_ERRMSG_SIZE];
	char* query = 0;

	std::list<GuildLookingForPlayers>::iterator it;

	for(it = Guilds.begin(); it != Guilds.end(); ++it)
	{
		if(!strcasecmp((*it).Name.c_str(), GuildName))
		{
			Guilds.erase(it);
			break;
		}
	}

	if(!database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM `lfguild` WHERE `type` = 1 AND `name` = '%s'", GuildName), errbuf, 0, 0))
		_log(QUERYSERV__ERROR, "Error removing guild from LFGuild table, query was %s, %s", query, errbuf);

	safe_delete_array(query);

	uint32 Now = time(NULL);

	if(Toggle == 1)
	{
		GuildLookingForPlayers g(GuildName, Comments, FromLevel, ToLevel, Classes, AACount, TimeZone, Now);
		Guilds.push_back(g);
		if(!database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO `lfguild` (`type`, `name`, `comment`, `fromlevel`, `tolevel`, `classes`, `aacount`, `timezone`, `timeposted`) VALUES(1, '%s', '%s', %u, %u, %u, %u, %u, %u)", GuildName, Comments, FromLevel, ToLevel, Classes, AACount, TimeZone, Now), errbuf, 0, 0))
			_log(QUERYSERV__ERROR, "Error inserting guild into LFGuild table, query was %s, %s", query, errbuf);

		safe_delete_array(query);

	}
	ServerPacket *pack = new ServerPacket(ServerOP_LFGuildUpdate, strlen(GuildName) + strlen(Comments) + 30);

	pack->WriteString(GuildName);
	pack->WriteString(Comments);
	pack->WriteUInt32(FromLevel);
	pack->WriteUInt32(ToLevel);
	pack->WriteUInt32(Classes);
	pack->WriteUInt32(AACount);
	pack->WriteUInt32(TimeZone);
	pack->WriteUInt32(Now);
	pack->WriteUInt32(Toggle);
	
	worldserver->SendPacket(pack);
	safe_delete(pack);
}
コード例 #10
0
ファイル: Adventure.cpp プロジェクト: Vaion/Server
void Adventure::SetStatus(AdventureStatus new_status)
{
	if(new_status == AS_WaitingForPrimaryEndTime)
	{
		status = new_status;
		safe_delete(current_timer);
		current_timer = new Timer(adventure_template->duration * 1000);
		database.SetInstanceDuration(instance_id, adventure_template->duration + 60);
		ServerPacket *pack = new ServerPacket(ServerOP_InstanceUpdateTime, sizeof(ServerInstanceUpdateTime_Struct));
		ServerInstanceUpdateTime_Struct *ut = (ServerInstanceUpdateTime_Struct*)pack->pBuffer;
		ut->instance_id = instance_id;
		ut->new_duration = adventure_template->duration + 60;

		pack->Deflate();
		zoneserver_list.SendPacket(0, instance_id, pack);
		safe_delete(pack);
	}
	else if(new_status == AS_WaitingForSecondaryEndTime)
	{
		status = new_status;
		safe_delete(current_timer);
		current_timer = new Timer(1800000);
		database.SetInstanceDuration(instance_id, 1860);
		ServerPacket *pack = new ServerPacket(ServerOP_InstanceUpdateTime, sizeof(ServerInstanceUpdateTime_Struct));
		ServerInstanceUpdateTime_Struct *ut = (ServerInstanceUpdateTime_Struct*)pack->pBuffer;
		ut->instance_id = instance_id;
		ut->new_duration = 1860;

		pack->Deflate();
		zoneserver_list.SendPacket(0, instance_id, pack);
		safe_delete(pack);
	}
	else if(new_status == AS_Finished)
	{
		status = new_status;
		safe_delete(current_timer);
		current_timer = new Timer(1800000);
		database.SetInstanceDuration(instance_id, 1800);
		ServerPacket *pack = new ServerPacket(ServerOP_InstanceUpdateTime, sizeof(ServerInstanceUpdateTime_Struct));
		ServerInstanceUpdateTime_Struct *ut = (ServerInstanceUpdateTime_Struct*)pack->pBuffer;
		ut->instance_id = instance_id;
		ut->new_duration = 1860;

		pack->Deflate();
		zoneserver_list.SendPacket(0, instance_id, pack);
		safe_delete(pack);
	}
	else
	{
		return;
	}

	list<string>::iterator iter = players.begin();
	while(iter != players.end())
	{
		adventure_manager.GetAdventureData((*iter).c_str());
		iter++;
	}
}
コード例 #11
0
ファイル: zonelist.cpp プロジェクト: Corysia/Server
void ZSList::SendChannelMessageRaw(const char* from, const char* to, uint8 chan_num, uint8 language, const char* message) {
	if (!message)
		return;
	ServerPacket* pack = new ServerPacket;

	pack->opcode = ServerOP_ChannelMessage;
	pack->size = sizeof(ServerChannelMessage_Struct)+strlen(message)+1;
	pack->pBuffer = new uchar[pack->size];
	memset(pack->pBuffer, 0, pack->size);
	ServerChannelMessage_Struct* scm = (ServerChannelMessage_Struct*) pack->pBuffer;
	if (from == 0) {
		strcpy(scm->from, "WServer");
		scm->noreply = true;
	}
	else if (from[0] == 0) {
		strcpy(scm->from, "WServer");
		scm->noreply = true;
	}
	else
		strcpy(scm->from, from);
	if (to != 0) {
		strcpy((char *) scm->to, to);
		strcpy((char *) scm->deliverto, to);
	}
	else {
		scm->to[0] = 0;
		scm->deliverto[0] = 0;
	}

	scm->language = language;
	scm->chan_num = chan_num;
	strcpy(&scm->message[0], message);
	if (scm->chan_num == 5 || scm->chan_num == 6 || scm->chan_num == 11) {
		console_list.SendChannelMessage(scm);
	}
	pack->Deflate();
	SendPacket(pack);
	delete pack;
}
コード例 #12
0
void handle_method_world_to_client(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method) {
	CheckParams(5, "[zone_id, instance_id, opcode, size, data]");
	VerifyID();
	CalculateSize();
	ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteOpcodeFromClient, sz);
	pack->WriteUInt32((uint32)id.size()); \
	pack->WriteString(id.c_str()); \
	pack->WriteUInt32((uint32)session->uuid.size()); \
	pack->WriteString(session->uuid.c_str()); \
	pack->WriteUInt32((uint32)method.size()); \
	pack->WriteString(method.c_str()); \
	auto &params = document["params"]; \
	auto params_sz = params.Size(); \
	pack->WriteUInt32(params_sz); \
	for(rapidjson::SizeType i = 0; i < params_sz; ++i) { \
		auto &param = params[(rapidjson::SizeType)i]; \
		pack->WriteUInt32((uint32)strlen(param.GetString())); \
		pack->WriteString(param.GetString()); \
	} \
	worldserver->SendPacket(pack); \
	safe_delete(pack); \
}
コード例 #13
0
ファイル: lfguild.cpp プロジェクト: Lord-Ptolemy/projecteqemu
void LFGuildManager::SendGuildMatches(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Level, uint32 AAPoints, uint32 TimeZone, uint32 Class)
{
	std::list<GuildLookingForPlayers>::iterator it;
	std::list<GuildLookingForPlayers> Matches;

	uint32 bitmask = 1 << Class ;

	uint32 PacketSize = strlen(From) + 21, NumberOfMatches = 0;

	for(it = Guilds.begin(); it != Guilds.end(); ++it)
	{
		if((Level >= (*it).FromLevel) && (Level <= (*it).ToLevel) && (AAPoints >= (*it).AACount) && (bitmask & (*it).Classes) && (((*it).TimeZone == 0xFFFFFFFF) || (TimeZone == 0xFFFFFFFF) || (TimeZone == (*it).TimeZone)))
		{
			++NumberOfMatches;
			Matches.push_back(*it);
			PacketSize += (*it).Name.length() + (*it).Comments.length() + 6;
		}

	}

	ServerPacket *pack = new ServerPacket(ServerOP_QueryServGeneric, PacketSize);

	pack->WriteUInt32(FromZoneID);
	pack->WriteUInt32(FromInstanceID);
	pack->WriteString(From);
	pack->WriteUInt32(QSG_LFGuild);
	pack->WriteUInt32(QSG_LFGuild_GuildMatches);
	pack->WriteUInt32(NumberOfMatches);

	for(it = Matches.begin(); it != Matches.end(); ++it)
	{
		pack->WriteString((*it).Name.c_str());
		pack->WriteUInt32((*it).TimeZone);
		pack->WriteString((*it).Comments.c_str());
	}
	worldserver->SendPacket(pack);
	safe_delete(pack);
}
コード例 #14
0
ファイル: basicpcktflow.cpp プロジェクト: muromec/qtopia-ezx
ServerPacket*
BasicPacketFlow::HXPacketToServerPacket(IHXPacket* pPacket)
{
    ServerPacket* pServerPacket;

    // This is a travesty of justice, but it's REALLY fast
    if (pPacket->QueryInterface(IID_ServerPacket,(void **)0xffffd00d) == HXR_OK)
    {
	pServerPacket = (ServerPacket *)pPacket;
    }
    else
    {
	IHXRTPPacket *pRTPPacket;

	PANIC(("Old-Style IHXPacket Wrapping Used\n"));
	if (pPacket->QueryInterface(IID_IHXRTPPacket, 
				    (void**) &pRTPPacket) == HXR_OK)
	{
	    pServerPacket = new ServerRTPPacket();
	    pRTPPacket->Release();
	}
	else
	{
	    pServerPacket = new (m_pProc->pc->mem_cache) ServerPacket();
	}

	pServerPacket->SetPacket(pPacket);
    }

    // set the TSD flag
    UINT16 unRule = pPacket->GetASMRuleNumber();
    PacketStream* pStream = &m_pStreams[pPacket->GetStreamNumber()];
    BOOL bIsTSD = pStream->m_pRules[unRule].m_bTimeStampDelivery;
    pServerPacket->SetTSD(bIsTSD);
    
    return pServerPacket;
}
コード例 #15
0
ファイル: worldserver.cpp プロジェクト: Vaion/Server
void WorldServer::Process()
{
	WorldConnection::Process();
	
	if (!Connected())
		return;

	ServerPacket *pack = 0;

	while((pack = tcpc.PopPacket()))
	{
		_log(QUERYSERV__TRACE, "Received Opcode: %4X", pack->opcode);

		switch(pack->opcode)
		{
			case 0: {
				break;
			}
			case ServerOP_KeepAlive:
			{
				break;
			}
			case ServerOP_Speech:
			{
				Server_Speech_Struct *SSS = (Server_Speech_Struct*)pack->pBuffer;

				string tmp1 = SSS->from;
				string tmp2 = SSS->to;

				database.AddSpeech(tmp1.c_str(), tmp2.c_str(), SSS->message, SSS->minstatus, SSS->guilddbid, SSS->type);
				break;
			}
			case ServerOP_QSPlayerLogTrades:
			{
				QSPlayerLogTrade_Struct *QS = (QSPlayerLogTrade_Struct*)pack->pBuffer;
				uint32 Items = QS->char1_count + QS->char2_count;
				database.LogPlayerTrade(QS, Items);
				break;
			}
			case ServerOP_QSPlayerLogHandins:
			{
				QSPlayerLogHandin_Struct *QS = (QSPlayerLogHandin_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count + QS->npc_count;
				database.LogPlayerHandin(QS, Items);
				break;
			}
			case ServerOP_QSPlayerLogNPCKills:
			{
				QSPlayerLogNPCKill_Struct *QS = (QSPlayerLogNPCKill_Struct*)pack->pBuffer;
				uint32 Members = pack->size - sizeof(QSPlayerLogNPCKill_Struct);
				if (Members > 0) Members = Members / sizeof(QSPlayerLogNPCKillsPlayers_Struct);
				database.LogPlayerNPCKill(QS, Members);
				break;
			}
			case ServerOP_QSPlayerLogDeletes:
			{
				QSPlayerLogDelete_Struct *QS = (QSPlayerLogDelete_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count;
				database.LogPlayerDelete(QS, Items);
				break;
			}
			case ServerOP_QSPlayerLogMoves:
			{
				QSPlayerLogMove_Struct *QS = (QSPlayerLogMove_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count;
				database.LogPlayerMove(QS, Items);
				break;
			}
			case ServerOP_QSMerchantLogTransactions:
			{
				QSMerchantLogTransaction_Struct *QS = (QSMerchantLogTransaction_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count + QS->merchant_count;
				database.LogMerchantTransaction(QS, Items);
				break;
			}
			case ServerOP_QueryServGeneric:
			{
				// The purpose of ServerOP_QueryServerGeneric is so that we don't have to add code to world just to relay packets
				// each time we add functionality to queryserv.
				//
				// A ServerOP_QueryServGeneric packet has the following format:
				//
				// uint32 SourceZoneID
				// uint32 SourceInstanceID
				// char OriginatingCharacterName[0] // Null terminated name of the character this packet came from. This could be just
				//				    // an empty string if it has no meaning in the context of a particular packet.
				// uint32 Type
				//
				// The 'Type' field is a 'sub-opcode'. A value of 0 is used for the LFGuild packets. The next feature to be added
				// to queryserv would use 1, etc.
				//
				// Obviously, any fields in the packet following the 'Type' will be unique to the particular type of packet. The 
				// 'Generic' in the name of this ServerOP code relates to the four header fields.
				char From[64];
				pack->SetReadPosition(8);
				pack->ReadString(From);
				uint32 Type = pack->ReadUInt32();
				
				switch(Type)
				{
					case QSG_LFGuild:
					{
						lfguildmanager.HandlePacket(pack);
						break;
					}

					default:
						_log(QUERYSERV__ERROR, "Received unhandled ServerOP_QueryServGeneric", Type);
						break;
				}	

				break;
			}


		}
	}

	safe_delete(pack);
	return;
}
コード例 #16
0
ファイル: worldserver.cpp プロジェクト: bwilliams1/Server
void WorldServer::Process()
{
	WorldConnection::Process(); 
	if (!Connected())
		return;

	ServerPacket *pack = 0; 
	while((pack = tcpc.PopPacket()))
	{
		_log(QUERYSERV__TRACE, "Received Opcode: %4X", pack->opcode); 
		switch(pack->opcode) {
			case 0: {
				break;
			}
			case ServerOP_KeepAlive: {
				break;
			}
			case ServerOP_QSPlayerLogTrades: {
				QSPlayerLogTrade_Struct *QS = (QSPlayerLogTrade_Struct*)pack->pBuffer;
				database.LogPlayerTrade(QS, QS->_detail_count);
				break;
			}
			case ServerOP_QSPlayerLogHandins: {
				QSPlayerLogHandin_Struct *QS = (QSPlayerLogHandin_Struct*)pack->pBuffer;
				database.LogPlayerHandin(QS, QS->_detail_count);
				break;
			}
			case ServerOP_QSPlayerLogNPCKills: {
				QSPlayerLogNPCKill_Struct *QS = (QSPlayerLogNPCKill_Struct*)pack->pBuffer;
				uint32 Members = pack->size - sizeof(QSPlayerLogNPCKill_Struct);
				if (Members > 0) Members = Members / sizeof(QSPlayerLogNPCKillsPlayers_Struct);
				database.LogPlayerNPCKill(QS, Members);
				break;
			}
			case ServerOP_QSPlayerLogDeletes: {
				QSPlayerLogDelete_Struct *QS = (QSPlayerLogDelete_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count;
				database.LogPlayerDelete(QS, Items);
				break;
			}
			case ServerOP_QSPlayerLogMoves: {
				QSPlayerLogMove_Struct *QS = (QSPlayerLogMove_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count;
				database.LogPlayerMove(QS, Items);
				break;
			}
			case ServerOP_QSPlayerLogMerchantTransactions: {
				QSMerchantLogTransaction_Struct *QS = (QSMerchantLogTransaction_Struct*)pack->pBuffer;
				uint32 Items = QS->char_count + QS->merchant_count;
				database.LogMerchantTransaction(QS, Items);
				break; 
			}
			case ServerOP_QueryServGeneric: {
				/* 
					The purpose of ServerOP_QueryServerGeneric is so that we don't have to add code to world just to relay packets
					each time we add functionality to queryserv.
				
					A ServerOP_QueryServGeneric packet has the following format:
				
					uint32 SourceZoneID
					uint32 SourceInstanceID
					char OriginatingCharacterName[0] 
						- Null terminated name of the character this packet came from. This could be just
						- an empty string if it has no meaning in the context of a particular packet.
					uint32 Type
				
					The 'Type' field is a 'sub-opcode'. A value of 0 is used for the LFGuild packets. The next feature to be added
					to queryserv would use 1, etc.
				
					Obviously, any fields in the packet following the 'Type' will be unique to the particular type of packet. The
					'Generic' in the name of this ServerOP code relates to the four header fields.
				*/

				char From[64];
				pack->SetReadPosition(8);
				pack->ReadString(From);
				uint32 Type = pack->ReadUInt32();

				switch(Type)
				{
					default:
						_log(QUERYSERV__ERROR, "Received unhandled ServerOP_QueryServGeneric", Type);
						break;
				}
				break;
			}
			case ServerOP_QSSendQuery: {
				/* Process all packets here */
				database.GeneralQueryReceive(pack);  
				break;
			}
		}
	} 
	safe_delete(pack);
	return;
}
コード例 #17
0
ファイル: clientlist.cpp プロジェクト: epicemu/Server
void ClientList::SendLFGMatches(ServerLFGMatchesRequest_Struct *smrs) {

	// Send back matches when someone searches player's Looking For A Group.

	LinkedListIterator<ClientListEntry*> Iterator(clientlist);
	ClientListEntry* CLE = 0;
	int Matches = 0;

	Iterator.Reset();

	// We run the ClientList twice. The first time is to determine how big the outgoing packet needs to be.
	while(Iterator.MoreElements()) {
		CLE = Iterator.GetData();
		if(CLE->LFG()) {
			unsigned int BitMask = 1 << CLE->class_();
			// First we check that the player meets the level and class criteria of the person
			// doing the search.
			if((CLE->level() >= smrs->FromLevel) && (CLE->level() <= smrs->ToLevel) &&
			   (BitMask & smrs->Classes))
			   	// Then we check if if the player doing the search meets the level criteria specified
				// by the player who is LFG.
				//
				// GetLFGMatchFilter returns the setting of the 'Only players who match my posted filters
				//						 can query me' checkbox.
				//
				// FromLevel and ToLevel are the settings of the 'Want group levels:' boxes.
			   	if(!CLE->GetLFGMatchFilter() || ((smrs->QuerierLevel >= CLE->GetLFGFromLevel()) &&
								 (smrs->QuerierLevel <= CLE->GetLFGToLevel())))
					Matches++;
		}
		Iterator.Advance();
	}
	ServerPacket* Pack = new ServerPacket(ServerOP_LFGMatches, (sizeof(ServerLFGMatchesResponse_Struct) * Matches) + 4);

	char *Buf = (char *)Pack->pBuffer;
	// FromID is the Entity ID of the player doing the search.
	VARSTRUCT_ENCODE_TYPE(int32, Buf, smrs->FromID);

	ServerLFGMatchesResponse_Struct* Buffer = (ServerLFGMatchesResponse_Struct*)Buf;

	Iterator.Reset();

	if(Matches) {
		while(Iterator.MoreElements() && (Matches > 0)) {
			CLE = Iterator.GetData();
			if(CLE->LFG()) {
				unsigned int BitMask = 1 << CLE->class_();
				if((CLE->level() >= smrs->FromLevel) && (CLE->level() <= smrs->ToLevel) &&
				   (BitMask & smrs->Classes)) {
					Matches--;
					strcpy(Buffer->Name, CLE->name());
					Buffer->Class_ = CLE->class_();
					Buffer->Level = CLE->level();
					Buffer->Zone = CLE->zone();
					// If the LFG player is anon, level and class are still displayed, but
					// zone shows as UNAVAILABLE.
					Buffer->Anon = (CLE->Anon() != 0);
					// The client can filter on Guildname
					Buffer->GuildID = CLE->GuildID();
					strcpy(Buffer->Comments, CLE->GetLFGComments());
					Buffer++;
				}
			}
			Iterator.Advance();
		}
		Pack->Deflate();
	}
	SendPacket(smrs->FromName,Pack);
	safe_delete(Pack);
}
コード例 #18
0
ファイル: worldserver.cpp プロジェクト: UnityEQ/UnityEQServer
void WorldServer::Process(){
	WorldConnection::Process();
	if (!Connected())
		return;

	ServerPacket *pack = nullptr;
	while((pack = tcpc.PopPacket())){
		Log.Out(Logs::General, Logs::Netcode, "Received Opcode: %4X", pack->opcode);
		//DumpPacket(pack);
		switch(pack->opcode) {
			case 0: { break; }
			case ServerOP_KeepAlive: { break; }
			case ServerOP_WIRemoteCallResponse: {
				char *id = nullptr;
				char *session_id = nullptr;
				char *error = nullptr;

				id = new char[pack->ReadUInt32() + 1];
				pack->ReadString(id);

				session_id = new char[pack->ReadUInt32() + 1];
				pack->ReadString(session_id);

				error = new char[pack->ReadUInt32() + 1];
				pack->ReadString(error);

				uint32 param_count = pack->ReadUInt32();
				std::map<std::string, std::string> params;
				for(uint32 i = 0; i < param_count; ++i) {
					char *first = new char[pack->ReadUInt32() + 1];
					pack->ReadString(first);

					char *second = new char[pack->ReadUInt32() + 1];
					pack->ReadString(second);

					params[first] = second;

					safe_delete_array(first);
					safe_delete_array(second);
				}

				//send the response to client...
				rapidjson::StringBuffer s;
				rapidjson::Writer<rapidjson::StringBuffer> writer(s);

				writer.StartObject();
				writer.String("id");
				if(strlen(id) == 0) {
					writer.Null();
				} else {
					writer.String(id);
				}

				if(strlen(error) != 0) {
					writer.String("error");
					writer.Bool(true);

					writer.String("result");
					writer.String(error);
				} else {
					writer.String("error");
					writer.Null();
					writer.String("result");
					writer.StartObject();
					auto iter = params.begin();
					while(iter != params.end()) {
						writer.String(iter->first.c_str());
						writer.String(iter->second.c_str());
						++iter;
					}
					writer.EndObject();
				}
				writer.EndObject();

				if(sessions.count(session_id) != 0) {
					per_session_data_eqemu *session = sessions[session_id];
					session->send_queue->push_back(s.GetString());
				}

				safe_delete_array(id);
				safe_delete_array(session_id);
				safe_delete_array(error);
				break;
			}

			case ServerOP_WIRemoteCallToClient:
			{
				char *session_id = nullptr;
				char *method = nullptr;

				session_id = new char[pack->ReadUInt32() + 1];
				pack->ReadString(session_id);

				method = new char[pack->ReadUInt32() + 1];
				pack->ReadString(method);

				uint32 param_count = pack->ReadUInt32();
				std::vector<std::string> params(param_count);
				for(uint32 i = 0; i < param_count; ++i) {
					char *p = new char[pack->ReadUInt32() + 1];
					pack->ReadString(p);
					params[i] = p;

					safe_delete_array(p);
				}

				rapidjson::StringBuffer s;
				rapidjson::Writer<rapidjson::StringBuffer> writer(s);

				writer.StartObject();
				writer.String("id");
				writer.Null();

				writer.String("method");
				writer.String(method);

				writer.String("params");
				writer.StartArray();

				for(uint32 i = 0; i < param_count; ++i) {
					writer.String(params[i].c_str());
				}

				writer.EndArray();
				
				writer.EndObject();

				if(sessions.count(session_id) != 0) {
					per_session_data_eqemu *session = sessions[session_id];
					session->send_queue->push_back(s.GetString());
				}

				safe_delete_array(session_id);
				safe_delete_array(method);
				break;
			}

			case ServerOP_WIRemoteOpcodeToClient:
			{
				char *session_id = nullptr;
				session_id = new char[pack->ReadUInt32() + 1];
				pack->ReadString(session_id);

				char *method = nullptr;
				method = new char[pack->ReadUInt32() + 1];
				pack->ReadString(method);


				uint32 zone_id = pack->ReadUInt32();
				uint32 instance_id = pack->ReadUInt32();
				uint32 opcode = pack->ReadUInt32();
				uint32 datasize = pack->ReadUInt32();
				char *p = new char[datasize];
				pack->ReadData(p, datasize);
				rapidjson::StringBuffer s;
				rapidjson::Writer<rapidjson::StringBuffer> writer(s);

				writer.StartObject();
				writer.String("id");
				writer.Null();

				writer.String("method");
				writer.String(method);

				writer.String("zoneid");
				writer.Uint(zone_id);

				writer.String("instance_id");
				writer.Uint(instance_id);

				writer.String("opcode");
				writer.Uint(opcode);
				writer.String("datasize");
				writer.Uint(datasize);

				std::string enc;
				Base64::encode(p, datasize, enc, false);


				writer.String("data");
				writer.String(enc.c_str());

				writer.EndObject();

				if(sessions.count(session_id) != 0) {
					per_session_data_eqemu *session = sessions[session_id];
					session->send_queue->push_back(s.GetString());
				}

				safe_delete_array(session_id);
				safe_delete_array(method);
				safe_delete_array(p);

				break;
			}
		}
	}

	safe_delete(pack);
	return;
}
コード例 #19
0
ファイル: Adventure.cpp プロジェクト: Vaion/Server
void Adventure::Finished(AdventureWinStatus ws)
{
	list<string>::iterator iter = players.begin();
	while(iter != players.end())
	{
		ClientListEntry *current = client_list.FindCharacter((*iter).c_str());
		if(current)
		{
			if(current->Online() == CLE_Status_InZone)
			{
				//We can send our packets only.
				ServerPacket *pack = new ServerPacket(ServerOP_AdventureFinish, sizeof(ServerAdventureFinish_Struct));
				ServerAdventureFinish_Struct *af = (ServerAdventureFinish_Struct*)pack->pBuffer;
				strcpy(af->player, (*iter).c_str());
				af->theme = GetTemplate()->theme;
				if(ws == AWS_Win)
				{
					af->win = true;
					af->points = GetTemplate()->win_points;
				}
				else if(ws == AWS_SecondPlace)
				{
					af->win = true;
					af->points = GetTemplate()->lose_points;
				}
				else
				{
					af->win = false;
					af->points = 0;
				}
				pack->Deflate();
				zoneserver_list.SendPacket(current->zone(), current->instance(), pack);
				database.UpdateAdventureStatsEntry(database.GetCharacterID((*iter).c_str()), GetTemplate()->theme, (ws != AWS_Lose) ? true : false);
				delete pack;
			}
			else
			{
				AdventureFinishEvent afe;
				afe.name = (*iter);
				if(ws == AWS_Win)
				{
					afe.theme = GetTemplate()->theme;
					afe.points = GetTemplate()->win_points;
					afe.win = true;
				}
				else if(ws == AWS_SecondPlace)
				{
					afe.theme = GetTemplate()->theme;
					afe.points = GetTemplate()->lose_points;
					afe.win = true;
				}
				else
				{
					afe.win = false;
					afe.points = 0;
				}
				adventure_manager.AddFinishedEvent(afe);
				database.UpdateAdventureStatsEntry(database.GetCharacterID((*iter).c_str()), GetTemplate()->theme, (ws != AWS_Lose) ? true : false);
			}
		}
		else
		{
			AdventureFinishEvent afe;
			afe.name = (*iter);
			if(ws == AWS_Win)
			{
				afe.theme = GetTemplate()->theme;
				afe.points = GetTemplate()->win_points;
				afe.win = true;
			}
			else if(ws == AWS_SecondPlace)
			{
				afe.theme = GetTemplate()->theme;
				afe.points = GetTemplate()->lose_points;
				afe.win = true;
			}
			else
			{
				afe.win = false;
				afe.points = 0;
			}
			adventure_manager.AddFinishedEvent(afe);
			database.UpdateAdventureStatsEntry(database.GetCharacterID((*iter).c_str()), GetTemplate()->theme, (ws != AWS_Lose) ? true : false);
		}
		iter++;
	}
	adventure_manager.GetAdventureData(this);
}
コード例 #20
0
ファイル: lfguild.cpp プロジェクト: Lord-Ptolemy/projecteqemu
void LFGuildManager::SendGuildStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From, char *GuildName)
{
	std::list<GuildLookingForPlayers>::iterator it;

	for(it = Guilds.begin(); it != Guilds.end(); ++it)
	{
		if(!strcasecmp((*it).Name.c_str(), GuildName))
		{
			ServerPacket *pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(From) + (*it).Comments.length() + 42);

			pack->WriteUInt32(FromZoneID);
			pack->WriteUInt32(FromInstanceID);
			pack->WriteString(From);
			pack->WriteUInt32(QSG_LFGuild);
			pack->WriteUInt32(QSG_LFGuild_RequestGuildInfo);
			pack->WriteString((*it).Comments.c_str());
			pack->WriteUInt32((*it).FromLevel);
			pack->WriteUInt32((*it).ToLevel);
			pack->WriteUInt32((*it).Classes);
			pack->WriteUInt32((*it).AACount);
			pack->WriteUInt32((*it).TimeZone);
			pack->WriteUInt32((*it).TimePosted);

			worldserver->SendPacket(pack);
			safe_delete(pack);
			break;
		}
	}
}
コード例 #21
0
ファイル: queryserv.cpp プロジェクト: Rabbit9159/Server
bool QueryServConnection::Process()
{
    if (!Stream || !Stream->Connected())
        return false;

    ServerPacket *pack = 0;

    while((pack = Stream->PopPacket()))
    {
        if (!authenticated)
        {
            if (WorldConfig::get()->SharedKey.length() > 0)
            {
                if (pack->opcode == ServerOP_ZAAuth && pack->size == 16)
                {
                    uint8 tmppass[16];

                    MD5::Generate((const uchar*) WorldConfig::get()->SharedKey.c_str(), WorldConfig::get()->SharedKey.length(), tmppass);

                    if (memcmp(pack->pBuffer, tmppass, 16) == 0)
                        authenticated = true;
                    else
                    {
                        struct in_addr in;
                        in.s_addr = GetIP();
                        _log(QUERYSERV__ERROR, "QueryServ authorization failed.");
                        ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
                        SendPacket(pack);
                        delete pack;
                        Disconnect();
                        return false;
                    }
                }
                else
                {
                    struct in_addr in;
                    in.s_addr = GetIP();
                    _log(QUERYSERV__ERROR, "QueryServ authorization failed.");
                    ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
                    SendPacket(pack);
                    delete pack;
                    Disconnect();
                    return false;
                }
            }
            else
            {
                _log(QUERYSERV__ERROR,"**WARNING** You have not configured a world shared key in your config file. You should add a <key>STRING</key> element to your <world> element to prevent unauthroized zone access.");
                authenticated = true;
            }
            delete pack;
            continue;
        }
        switch(pack->opcode)
        {
        case 0:
            break;

        case ServerOP_KeepAlive:
        {
            // ignore this
            break;
        }
        case ServerOP_ZAAuth:
        {
            _log(QUERYSERV__ERROR, "Got authentication from QueryServ when they are already authenticated.");
            break;
        }
        case ServerOP_QueryServGeneric:
        {
            uint32 ZoneID = pack->ReadUInt32();
            uint16 InstanceID = pack->ReadUInt32();
            zoneserver_list.SendPacket(ZoneID, InstanceID, pack);
            break;
        }
        case ServerOP_LFGuildUpdate:
        {
            zoneserver_list.SendPacket(pack);
            break;
        }
        default:
        {
            _log(QUERYSERV__ERROR, "Unknown ServerOPcode from QueryServ 0x%04x, size %d", pack->opcode, pack->size);
            DumpPacket(pack->pBuffer, pack->size);
            break;
        }
        }

        delete pack;
    }
    return(true);
}
コード例 #22
0
ファイル: web_interface.cpp プロジェクト: bwilliams1/Server
bool WebInterfaceConnection::Process()
{
	if (!stream || !stream->Connected())
		return false;

	ServerPacket *pack = 0;

	while((pack = stream->PopPacket()))
	{
		if (!authenticated)
		{
			if (WorldConfig::get()->SharedKey.length() > 0)
			{
				if (pack->opcode == ServerOP_ZAAuth && pack->size == 16)
				{
					uint8 tmppass[16];

					MD5::Generate((const uchar*) WorldConfig::get()->SharedKey.c_str(), WorldConfig::get()->SharedKey.length(), tmppass);

					if (memcmp(pack->pBuffer, tmppass, 16) == 0)
						authenticated = true;
					else
					{
						struct in_addr in;
						in.s_addr = GetIP();
						_log(WEB_INTERFACE__ERROR, "WebInterface authorization failed.");
						ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
						SendPacket(pack);
						delete pack;
						Disconnect();
						return false;
					}
				}
				else
				{
					struct in_addr in;
					in.s_addr = GetIP();
					_log(WEB_INTERFACE__ERROR, "WebInterface authorization failed.");
					ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
					SendPacket(pack);
					delete pack;
					Disconnect();
					return false;
				}
			}
			else
			{
				_log(WEB_INTERFACE__ERROR, "**WARNING** You have not configured a world shared key in your config file. You should add a <key>STRING</key> element to your <world> element to prevent unauthorized zone access.");
				authenticated = true;
			}
			delete pack;
			continue;
		}
		switch(pack->opcode)
		{
			case 0:
				break;

			case ServerOP_KeepAlive:
			{
				// ignore this
				break;
			}
			case ServerOP_ZAAuth:
			{
				_log(WEB_INTERFACE__ERROR, "Got authentication from WebInterface when they are already authenticated.");
				break;
			}
			case ServerOP_WIRemoteCall:
			{
				char *id = nullptr;
				char *session_id = nullptr;
				char *method = nullptr;

				id = new char[pack->ReadUInt32() + 1];
				pack->ReadString(id);

				session_id = new char[pack->ReadUInt32() + 1];
				pack->ReadString(session_id);

				method = new char[pack->ReadUInt32() + 1];
				pack->ReadString(method);

				uint32 param_count = pack->ReadUInt32();
				std::vector<std::string> params;
				for(uint32 i = 0; i < param_count; ++i) {
					char *p = new char[pack->ReadUInt32() + 1];
					pack->ReadString(p);
					params.push_back(p);
					safe_delete_array(p);
				}

				if (remote_call_methods.count(method) != 0) {
					auto f = remote_call_methods[method];
					f(method, session_id, id, params);
				}

				safe_delete_array(id);
				safe_delete_array(session_id);
				safe_delete_array(method);
				break;
			}
			case ServerOP_WIClientSessionResponse: {
				uint32 zone_id = pack->ReadUInt32();
				uint32 instance_id = pack->ReadUInt32();
				
				ZoneServer *zs = nullptr;
				if(instance_id != 0) {
					zs = zoneserver_list.FindByInstanceID(instance_id);
				} else {
					zs = zoneserver_list.FindByZoneID(zone_id);
				}

				if(zs) {
					ServerPacket *npack = new ServerPacket(ServerOP_WIClientSessionResponse, pack->size - 8);
					memcpy(npack->pBuffer, pack->pBuffer + 8, pack->size - 8);

					zs->SendPacket(npack);
					safe_delete(npack);
				}

				break;
			}
			default:
			{
				_log(WEB_INTERFACE__ERROR, "Unknown ServerOPcode from WebInterface 0x%04x, size %d", pack->opcode, pack->size);
				DumpPacket(pack->pBuffer, pack->size);
				break;
			}
		}

		delete pack;
	}
	return(true);
}
コード例 #23
0
ファイル: remote_call.cpp プロジェクト: jcon321/Server
void RemoteCallResponse(const std::string &connection_id, const std::string &request_id, const std::map<std::string, std::string> &res, const std::string &error) {
	uint32 sz = (uint32)(connection_id.size() + request_id.size() + error.size() + 3 + 16);
	auto iter = res.begin();
	while(iter != res.end()) {
		sz += (uint32)iter->first.size() + (uint32)iter->second.size() + 10;
		++iter;
	}

	ServerPacket *pack = new ServerPacket(ServerOP_WIRemoteCallResponse, sz);
	pack->WriteUInt32((uint32)request_id.size());
	pack->WriteString(request_id.c_str());
	pack->WriteUInt32((uint32)connection_id.size());
	pack->WriteString(connection_id.c_str());
	pack->WriteUInt32((uint32)error.size());
	pack->WriteString(error.c_str());
	pack->WriteUInt32((uint32)res.size());
	iter = res.begin();
	while(iter != res.end()) {
		pack->WriteUInt32((uint32)iter->first.size());
		pack->WriteString(iter->first.c_str());
		pack->WriteUInt32((uint32)iter->second.size());
		pack->WriteString(iter->second.c_str());
		++iter;
	}

	WILink.SendPacket(pack);
	safe_delete(pack);
}