Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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);
}
Пример #4
0
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);
}
Пример #5
0
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;
}