void MessageRouter::_loadMessageProcessMap(void)
{
    MessageRoute route;

    // We need to populate our message map.
    // setup our databinding parameters.
    DataBinding* binding = mDatabase->createDataBinding(2);
    binding->addField(DFT_uint32, offsetof(MessageRoute, mMessageId), 4);
    binding->addField(DFT_uint32, offsetof(MessageRoute, mProcessId), 4);

    // Execute our statement
    DatabaseResult* result = mDatabase->executeSynchSql("SELECT messageId, processId FROM %s.config_message_routes;",mDatabase->galaxy());
    
    uint32 count = static_cast<uint32>(result->getRowCount());

    // Retrieve our routes and add them to the map.
    for(uint32 i = 0; i < count; i++)
    {
        result->getNextRow(binding, &route);
        mMessageRouteMap.insert(std::make_pair(route.mMessageId, route.mProcessId));
    }

    // Delete our DB objects.
    mDatabase->destroyDataBinding(binding);
    mDatabase->destroyResult(result);
}
Beispiel #2
0
void BuffManager::LoadBuffAttributesFromResult(buffAsyncContainer* asyncContainer, DatabaseResult* result)
{

    DataBinding*	buffBinding = mDatabase->createDataBinding(4);
    buffBinding->addField(DFT_uint64,offsetof(BuffAttributeDBItem,mType),8,0);
    buffBinding->addField(DFT_int32,offsetof(BuffAttributeDBItem,mInitialValue),4,1);
    buffBinding->addField(DFT_int32,offsetof(BuffAttributeDBItem,mTickValue),4,2);
    buffBinding->addField(DFT_int32,offsetof(BuffAttributeDBItem,mFinalValue),4,3);

    uint64 rowCount = result->getRowCount();

    BuffAttributeDBItem* tmp = new BuffAttributeDBItem();
    for(uint64 i = 0; i < rowCount; i++)
    {
        result->getNextRow(buffBinding,tmp);
        asyncContainer->buff->AddAttribute(BuffAttribute::FromDB(tmp));
    }

    asyncContainer->buff->SetInit(true);
    SAFE_DELETE(tmp);
    mDatabase->destroyDataBinding(buffBinding);

    //Start the buff later on - we want to avoid racing conditions with the knownplayer map
    //asyncContainer->buff->ReInit();
    asyncContainer->player->DecBuffAsyncCount();
    asyncContainer->mQueryType=BMQuery_Delete;
    int8 sql2[550];
    sprintf(sql2, "delete from %s.character_buff_attributes where character_id = %" PRIu64 " and buff_id = %" PRIu64 ";",mDatabase->galaxy(), asyncContainer->player->getId(), asyncContainer->buff->GetDBID());

    mDatabase->executeSqlAsync(this,asyncContainer,sql2);

    //we use the asyncContainer again the line above
}
void StructureManager::_HandleUpdateAdminPermission(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	HouseObject*	house = dynamic_cast<HouseObject*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	struct adminStruct
	{
		uint64 playerID;
	};

	adminStruct adminData;

	DataBinding*	adminBinding = mDatabase->CreateDataBinding(1);
	adminBinding->addField(DFT_uint64,offsetof(adminStruct,playerID),8,0);

	uint64 count = result->getRowCount();
	house->resetHousingAdminList();

	for(uint32 j = 0;j < count;j++)
	{
		result->GetNextRow(adminBinding,&adminData);
		house->addHousingAdminEntry(adminData.playerID);

		//now that we added it to the list we need to update the players delta
	}

	mDatabase->DestroyDataBinding(adminBinding);

}
Beispiel #4
0
//======================================================================================================================
void ClientManager::handleDatabaseJobComplete(void* ref, DatabaseResult* result)
{
    // This assumes only authentication calls are async right now.  Will change as needed.
    ConnectionClient* client = reinterpret_cast<ConnectionClient*>(ref);

    switch (client->getState())
    {
    case CCSTATE_QueryAuth:
    {
        _handleQueryAuth(client, result);
        break;
    }
    case CCSTATE_AllowedChars:
    {
        struct charsCurrentAllowed {
            uint32  currentChars;
            uint32	charsAllowed;
        } charsStruct;

        DataBinding* binding = mDatabase->createDataBinding(2);
        binding->addField(DFT_int32,offsetof(charsCurrentAllowed, currentChars), 4, 0);
        binding->addField(DFT_int32,offsetof(charsCurrentAllowed, charsAllowed), 4, 1);

        result->getNextRow(binding,&charsStruct);
        client->setCharsAllowed(charsStruct.charsAllowed);
        client->setCurrentChars(charsStruct.currentChars);

        client->setState(CCSTATE_QueryAuth);
        mDatabase->destroyDataBinding(binding);
        break;
    }
    default:
        break;
    }
}
//==================================================================================================
// 
// updates the characters lots
//
void StructureManager::_HandleUpdateCharacterLots(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));

	uint8 lotCount;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint8,0,1);

	uint64 count;
	count = result->getRowCount();

	if (!count)
	{
		gLogger->logMsgLoadFailure("StructureManager::add Permission no return value...",MSG_NORMAL);
		return;
	}
	result->GetNextRow(binding,&lotCount);

	if(player)
	{
		//update the lots
		uint8 maxLots = gWorldConfig->getConfiguration("Player_Max_Lots",(uint8)10);

		maxLots -= static_cast<uint8>(lotCount);
		player->setLots((uint8)maxLots);
		
		//mmmmh a bit of a hack ... maybe it works ?
		gMessageLib->sendCharacterSheetResponse(player);

		
	}
	mDatabase->DestroyDataBinding(binding);
	
}
//==================================================================================================
// handles the admin permission list
// it will be read in for the list to display when the player displays it to make changes
// please note that the list is purely db based and *not* kept in memory
// it will be cleared once the changes are made
//
void StructureManager::_HandleQueryEntryPermissionData(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{

	PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	string playerName;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_bstring,0,64);

	uint64 count;
	count = result->getRowCount();
	structure->resetStructureEntryList();
	for(uint64 i = 0;i < count;i++)
	{
		result->GetNextRow(binding,&playerName);

		structure->addStructureEntryListEntry(playerName);

	}

	structure->sendStructureEntryList(asynContainer->mPlayerId);

	mDatabase->DestroyDataBinding(binding);
	
}
void StructureManager::_HandleStructureTransferLotsRecipient(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	PlayerObject* donor = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));
	PlayerObject* recipient = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mTargetId));

	uint8 lots;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint8,0,1);

	uint64 count;
	count = result->getRowCount();
	if(!count)
	{
		gLogger->logMsgF("StructureManager::Transfer Structure Admin List Callback couldnt get recipients lots",MSG_HIGH);
		mDatabase->DestroyDataBinding(binding);			
		return;
	}

	
	//thats lots in use
	result->GetNextRow(binding,&lots);

	uint8 requiredLots = structure->getLotCount();

	uint8 freelots = gWorldConfig->getConfiguration("Player_Max_Lots",(uint8)10) - lots;
	if(freelots >= requiredLots)
	{
		//yay we were succesful
		structure->setOwner(asynContainer->mTargetId);
		mDatabase->ExecuteSqlAsync(0,0,"UPDATE structures SET structures.owner = %I64u WHERE structures.id = %I64u",asynContainer->mTargetId,asynContainer->mStructureId);
		mDatabase->ExecuteSqlAsync(0,0,"DELETE FROM structure_admin_data where playerId = %I64u AND StructureID = %I64u",asynContainer->mPlayerId,asynContainer->mStructureId);
		mDatabase->ExecuteSqlAsync(0,0,"INSERT INTO structure_admin_data VALUES (NULL,%I64u,%I64u,'ADMIN')",asynContainer->mStructureId, asynContainer->mTargetId);
		        

		//update the administration list

		if(donor)
		{
			gMessageLib->sendSystemMessage(donor,L"","player_structure","ownership_transferred_out","",asynContainer->name);
		}
		if(recipient)
		{
			gMessageLib->sendSystemMessage(recipient,L"","player_structure","ownership_transferred_in","",donor->getFirstName().getAnsi());
		}
		

	}
	else
	{
		//say something
	}
	
	mDatabase->DestroyDataBinding(binding);												   	
}
Beispiel #8
0
//======================================================================================================================
void LoginManager::_sendCharacterList(LoginClient* client, DatabaseResult* result)
{
    CharacterInfo data;
    memset(&data, 0, sizeof(CharacterInfo));

    // This DataBinding code I'm not sure where to put atm.  I've thought about a base class for any objects that want
    // DataBinding, but I don't want to go overboard on abstraction.  Any suggestions would be appreciated.  :)
    DataBinding* binding = mDatabase->createDataBinding(5);
    binding->addField(DFT_uint64, offsetof(CharacterInfo, mCharacterId), 8);
    binding->addField(DFT_bstring, offsetof(CharacterInfo, mFirstName), 64);
    binding->addField(DFT_bstring, offsetof(CharacterInfo, mLastName), 64);
    binding->addField(DFT_uint32, offsetof(CharacterInfo, mServerId), 4);
    binding->addField(DFT_bstring, offsetof(CharacterInfo, mBaseModel), 64);

    uint32 charCount = static_cast<uint32>(result->getRowCount());

    // Create our server list message
    gMessageFactory->StartMessage();                                 // Opcode group number
    gMessageFactory->addUint32(opEnumerateCharacterId);
    gMessageFactory->addUint32(charCount);                            // Character count
    for (uint32 i = 0; i < charCount; i++)
    {
        result->getNextRow(binding, &data);

        // Append first and last names
        BString fullName, baseModel;

        fullName << data.mFirstName.getAnsi();

        if(data.mLastName.getLength())
        {
            fullName << " ";
        //    fullName << data.mLastName.getAnsi();
        }

        fullName.convert(BSTRType_Unicode16);

        gMessageFactory->addString(fullName);                           // Characters full name

        baseModel = data.mBaseModel;
        gMessageFactory->addUint32(baseModel.getCrc());                 // Base model
        gMessageFactory->addUint64(data.mCharacterId);                  // Character Id
        gMessageFactory->addUint32(data.mServerId);                     // Server Id
        gMessageFactory->addUint32(1);                                  // Uknown
    }
    Message* message = gMessageFactory->EndMessage();
    client->SendChannelA(message, 2, false);

    // Destroy our data binding
    mDatabase->destroyDataBinding(binding);
}
Beispiel #9
0
//======================================================================================================================
void ClientManager::_processSelectCharacter(ConnectionClient* client, Message* message)
{
    uint64 characterId = message->getUint64();

    DatabaseResult* result = mDatabase->executeSynchSql("SELECT planet_id FROM %s.characters WHERE id=%"PRIu64";",mDatabase->galaxy(), characterId);

    uint32 serverId;
    DataBinding* binding = mDatabase->createDataBinding(1);
    binding->addField(DFT_uint32, 0, 4);
    result->getNextRow(binding, &serverId);

    client->setServerId(serverId + 8);  // server ids for zones are planetId + 8;

    mDatabase->destroyDataBinding(binding);
    mDatabase->destroyResult(result);

    // send an opClusterClientConnect message to zone server.
    gMessageFactory->StartMessage();
    gMessageFactory->addUint32(opClusterClientConnect);
    gMessageFactory->addUint64(characterId);
    Message* zoneMessage = gMessageFactory->EndMessage();

    // This one goes to the ZoneServer the client is currently on.
    zoneMessage->setAccountId(client->getAccountId());
    zoneMessage->setDestinationId(static_cast<uint8>(serverId + 8));
    zoneMessage->setRouted(true);
    mMessageRouter->RouteMessage(zoneMessage, client);

    // send an opClusterClientConnect message to chat server.
    gMessageFactory->StartMessage();
    gMessageFactory->addUint32(opClusterClientConnect);
    gMessageFactory->addUint64(characterId);
    gMessageFactory->addUint32(serverId);
    Message* chatMessage = gMessageFactory->EndMessage();

    // This one goes to the ChatServer
    chatMessage->setAccountId(client->getAccountId());
    chatMessage->setDestinationId(CR_Chat);
    chatMessage->setRouted(true);
    mMessageRouter->RouteMessage(chatMessage, client);

    // Now send the SelectCharacter message off to the zone server.
    gMessageFactory->StartMessage();
    gMessageFactory->addData(message->getData(), message->getSize());
    Message* selectMessage = gMessageFactory->EndMessage();

    selectMessage->setAccountId(client->getAccountId());
    selectMessage->setDestinationId(static_cast<uint8>(serverId + 8));
    selectMessage->setRouted(true);
    mMessageRouter->RouteMessage(selectMessage, client);
}
Beispiel #10
0
//======================================================================================================================
void LoginManager::_getLauncherSessionKey(LoginClient* client, DatabaseResult* result)
{
    AccountData data;
    DataBinding* binding = mDatabase->createDataBinding(1);
    binding->addField(DFT_int64, offsetof(AccountData, mId), 8);

    if (result->getRowCount())
    {
        //we have the account id
        result->getNextRow(binding, (void*)&data);
        client->setAccountId(data.mId);

        //log it
        DLOG(info) << "void LoginManager::_sendLauncherSessionKey Login: AccountId: " << data.mId<< " Name: " << client->getUsername().getAnsi();

        //get the session_key made and returned
        int8 sql[512];
        sprintf(sql,"CALL %s.sp_AccountSessionKeyGenerate(%" PRIu64 ");",mDatabase->galaxy(), data.mId);

        client->setState(LCSTATE_RetrieveSessionKey);
        mDatabase->executeProcedureAsync(this, client, sql);
    
    }
    else
    {
        Message* newMessage;

        BString errType, errMsg;
        errType = "@cpt_login_fail";
        errMsg = "@msg_login_fail";

        DLOG(info) << " Login failed for username: "******", password: ********" << client->getPassword().getAnsi();

        gMessageFactory->StartMessage();
        gMessageFactory->addUint32(opErrorMessage);
        gMessageFactory->addString(errType);
        gMessageFactory->addString(errMsg);
        gMessageFactory->addUint8(0);

        newMessage = gMessageFactory->EndMessage();

        client->SendChannelA(newMessage, 3,false);
        client->Disconnect(6);
    }

    // Destroy our database object
    mDatabase->destroyDataBinding(binding);
}
Beispiel #11
0
void NpcManager::handleDatabaseJobComplete(void* ref, DatabaseResult* result)
{
    NpcAsyncContainer* asyncContainer = reinterpret_cast<NpcAsyncContainer*>(ref);
    switch(asyncContainer->mQuery)
    {
    case NpcQuery_Lairs:
    {
        // warning... this assumes that someone has called the Init()-function before we execute the line below.
        // For now, it's done at ZoneServer::Startup().
        NonPersistentNpcFactory* nonPersistentNpcFactory = NonPersistentNpcFactory::Instance();

        NpcLairEntity lair;

        // Here we will get the lair type.
        DataBinding* lairSpawnBinding = mDatabase->createDataBinding(3);
        lairSpawnBinding->addField(DFT_uint64,offsetof(NpcLairEntity,mLairsId),8,0);
        lairSpawnBinding->addField(DFT_uint64,offsetof(NpcLairEntity,mLairTemplateId),8,1);
        lairSpawnBinding->addField(DFT_uint32,offsetof(NpcLairEntity,mNumberOfLairs),4,2);

        uint64 count = result->getRowCount();

        for (uint64 i = 0; i < count; i++)
        {
            result->getNextRow(lairSpawnBinding,&lair);

            for (uint64 lairs = 0; lairs < lair.mNumberOfLairs; lairs++)
            {
                // We need two id's in sequence, since nps'c have an inventory.
                uint64 npcNewId = gWorldManager->getRandomNpNpcIdSequence();

                if (npcNewId != 0)
                {
                    nonPersistentNpcFactory->requestLairObject(this, lair.mLairsId, npcNewId);
                }
            }
        }
        mDatabase->destroyDataBinding(lairSpawnBinding);
    }
    break;

    default:
    {
    }
    break;
    }

}
void StructureManager::_HandleStructureDestruction(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	struct structData
	{
		uint64 id;
		uint32 condition;
	};

	structData sd;

	DataBinding* binding = mDatabase->CreateDataBinding(2);
	binding->addField(DFT_uint64,offsetof(structData,id),8,0);
	binding->addField(DFT_uint32,offsetof(structData,condition),4,1);

	uint64 count;
	count = result->getRowCount();

	for(uint64 i = 0;i < count;i++)
	{
		result->GetNextRow(binding,&sd);

		PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(sd.id));
		if(structure)
		{
			gLogger->logMsgF("StructureManager::delete structure due to zero condition %I64u",MSG_NORMAL,structure->getId());
			//delete the deed in the db
			//the parent is the structure and the item family is 15
			int8 sql[100];
			sprintf(sql,"DELETE FROM items WHERE parent_id = %"PRIu64" AND item_family = 15",structure->getId());
			mDatabase->ExecuteSqlAsync(NULL,NULL,sql);

			//delete harvester db side with all power and all resources
			gObjectFactory->deleteObjectFromDB(structure);
			UpdateCharacterLots(structure->getOwner());

			//delete it in the world
			gMessageLib->sendDestroyObject_InRangeofObject(structure);
			gWorldManager->destroyObject(structure);


								
		}
	}

	mDatabase->DestroyDataBinding(binding);
}
Beispiel #13
0
void WorldManager::LoadCurrentGlobalTick()
{
    uint64 Tick;
    DatabaseResult* temp = mDatabase->executeSynchSql("SELECT Global_Tick_Count FROM %s.galaxy WHERE galaxy_id = '2'",mDatabase->galaxy());


    DataBinding*	tickbinding = mDatabase->createDataBinding(1);
    tickbinding->addField(DFT_uint64,0,8,0);

    temp->getNextRow(tickbinding,&Tick);
    mDatabase->destroyDataBinding(tickbinding);
    mDatabase->destroyResult(temp);


    LOG(info) << "Current global tick count [" << Tick << "]";
    mTick = Tick;
    mSubsystemScheduler->addTask(fastdelegate::MakeDelegate(this,&WorldManager::_handleTick),7,1000,NULL);
}
void StructureManager::_HandleGetInactiveHarvesters(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{

	struct structData
	{
		uint64 id;
		uint32 condition;
	};

	structData sd;

	DataBinding* binding = mDatabase->CreateDataBinding(2);
	binding->addField(DFT_uint64,offsetof(structData,id),8,0);
	binding->addField(DFT_uint32,offsetof(structData,condition),4,1);

	uint64 count;
	count = result->getRowCount();

	for(uint64 i = 0;i < count;i++)
	{
		result->GetNextRow(binding,&sd);

		HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(gWorldManager->getObjectById(sd.id));
		if(harvester)
		{
			//if the harvesters status is changed we need to alter it
			if(harvester->getActive())
			{
				harvester->setActive(false);
				harvester->setDamage(sd.condition);
				
				gMessageLib->sendHarvesterActive(harvester);

			}
			//Now update the condition
			gMessageLib->sendHarvesterCurrentConditionUpdate(harvester);
		}

	}

	mDatabase->DestroyDataBinding(binding);
}
Beispiel #15
0
void ZoneServer::_connectToConnectionServer(void)
{
	ProcessAddress processAddress;
	memset(&processAddress, 0, sizeof(ProcessAddress));

	// Query the DB to find out who this is.
	// setup our databinding parameters.
	DataBinding* binding = mDatabase->CreateDataBinding(5);
	binding->addField(DFT_uint32, offsetof(ProcessAddress, mType), 4);
	binding->addField(DFT_string, offsetof(ProcessAddress, mAddress), 16);
	binding->addField(DFT_uint16, offsetof(ProcessAddress, mPort), 2);
	binding->addField(DFT_uint32, offsetof(ProcessAddress, mStatus), 4);
	binding->addField(DFT_uint32, offsetof(ProcessAddress, mActive), 4);

	// Execute our statement
	DatabaseResult* result = mDatabase->ExecuteSynchSql("SELECT id, address, port, status, active FROM config_process_list WHERE name='connection';");
	uint32 count = static_cast<uint32>(result->getRowCount());

	// If we found them
	if (count == 1)
	{
		// Retrieve our routes and add them to the map.
		result->GetNextRow(binding, &processAddress);
	}

	// Delete our DB objects.
	mDatabase->DestroyDataBinding(binding);
	mDatabase->DestroyResult(result);

	// Now connect to the ConnectionServer
	DispatchClient* client = new DispatchClient();
	mRouterService->Connect(client, processAddress.mAddress, processAddress.mPort);

	// Send our registration message
	gMessageFactory->StartMessage();
	gMessageFactory->addUint32(opClusterRegisterServer);
	gMessageFactory->addString(mZoneName);

	Message* message = gMessageFactory->EndMessage();
	client->SendChannelA(message, 0, CR_Connection, 1);
}
Beispiel #16
0
//======================================================================================================================
void LoginManager::_sendLauncherSessionKey(LoginClient* client, DatabaseResult* result)
{
    SessionKeyData data;
    DataBinding* binding = mDatabase->createDataBinding(1);
    binding->addField(DFT_bstring, offsetof(SessionKeyData, mSessionKey),32);

    result->getNextRow(binding, (void*)&data);

    //start the message
    gMessageFactory->StartMessage();
    gMessageFactory->addUint32(opLauncherSessionCreated);
    gMessageFactory->addUint32(32);
    gMessageFactory->addString(data.mSessionKey);

    //and send it
    Message* message = gMessageFactory->EndMessage();
    client->SendChannelA(message,4,false);

    //disconnect this client now
    client->Disconnect(6);
}
Beispiel #17
0
//======================================================================================================================
void LoginManager::_authenticateClient(LoginClient* client, DatabaseResult* result)
{
    AccountData data;
    
    // This DataBinding code I'm not sure where to put atm.  I've thought about a base class for any objects that want
    // DataBinding, but I don't want to go overboard on abstraction.  Any suggestions would be appreciated.  :)
    DataBinding* binding = mDatabase->createDataBinding(8);
    binding->addField(DFT_int64, offsetof(AccountData, mId), 8);
    binding->addField(DFT_string, offsetof(AccountData, mUsername), 32);
    binding->addField(DFT_string, offsetof(AccountData, mPassword), 32);
    binding->addField(DFT_uint32, offsetof(AccountData, mAccountId), 4);
    binding->addField(DFT_uint8, offsetof(AccountData, mBanned), 1);
    binding->addField(DFT_uint8, offsetof(AccountData, mActive), 1);
    binding->addField(DFT_uint32,offsetof(AccountData, mCharsAllowed), 4);
    binding->addField(DFT_uint8, offsetof(AccountData, mCsr), 1);
        
    if (result->getRowCount())
    {
        result->getNextRow(binding, (void*)&data);
        client->setAccountId(data.mId);
        client->setCharsAllowed(data.mCharsAllowed);
        client->setCsr(data.mCsr);
        
        LOG(info) << "Login: AccountId: " << data.mId << " Name: " << data.mUsername;

        _sendAuthSucceeded(client);
    }
    else
    {
        Message* newMessage;

        BString errType, errMsg;
        errType = "@cpt_login_fail";
        errMsg = "@msg_login_fail";

        LOG(warning) << " Login failed for username: "******" password: ********" << client->getPassword().getAnsi();

        gMessageFactory->StartMessage();
        gMessageFactory->addUint32(opErrorMessage);
        gMessageFactory->addString(errType);
        gMessageFactory->addString(errMsg);
        gMessageFactory->addUint8(0);

        newMessage = gMessageFactory->EndMessage();

        client->SendChannelA(newMessage, 3,false);
        client->Disconnect(6);
    }

    // Destroy our database object
    mDatabase->destroyDataBinding(binding);
}
Beispiel #18
0
void WorldConfig::buildAttributeMap(DatabaseResult* result)
{
    Configuration_QueryContainer	attribute;
    uint64							count = result->getRowCount();
    BStringVector					dataElements;

    DataBinding*					mConfigurationBinding;

    mConfigurationBinding = mDatabase->createDataBinding(2);
    mConfigurationBinding->addField(DFT_bstring,offsetof(Configuration_QueryContainer,mKey),64,0);
    mConfigurationBinding->addField(DFT_bstring,offsetof(Configuration_QueryContainer,mValue),128,1);

    //gLogger->log(LogManager::DEBUG,"Adding Attribute Configuration");

    for(uint64 i = 0; i < count; i++)
    {
        result->getNextRow(mConfigurationBinding,(void*)&attribute);
        //gLogger->logCont(LogManager::DEBUG,"Adding Attribute %s: %s ",attribute.mKey.getAnsi(),attribute.mValue.getAnsi());


        if(hasConfiguration(attribute.mKey))
        {
            setConfiguration(attribute.mKey,std::string(attribute.mValue.getAnsi()));
        }
        else
        {
            addConfiguration(attribute.mKey,std::string(attribute.mValue.getAnsi()));
        }
    }

    if (count)
    {
        LOG(INFO) << "Mapped attributes mapped: [" << count << "]";
    }

}
Beispiel #19
0
//======================================================================================================================
void LoginManager::_sendServerList(LoginClient* client, DatabaseResult* result)
{
  uint32 serverCount = 1;

  ServerData data;
  memset(&data, 0, sizeof(ServerData));

  // This DataBinding code I'm not sure where to put atm.
  DataBinding* binding = mDatabase->CreateDataBinding(7);
  binding->addField(DFT_uint32, offsetof(ServerData, mId), 4);
  binding->addField(DFT_bstring, offsetof(ServerData, mName), 50);
  binding->addField(DFT_bstring, offsetof(ServerData, mAddress), 100);
  binding->addField(DFT_uint16, offsetof(ServerData, mConnectionPort), 2);
  binding->addField(DFT_uint16, offsetof(ServerData, mPingPort), 2);
  binding->addField(DFT_uint32, offsetof(ServerData, mPopulation), 4);
  binding->addField(DFT_uint32, offsetof(ServerData, mStatus), 4);

  serverCount = static_cast<uint32>(result->getRowCount());

  // Create our server list message
  gMessageFactory->StartMessage();                           // Group number
  gMessageFactory->addUint32(opLoginEnumCluster);
  gMessageFactory->addUint32(serverCount);                      // Number of servers in the list.
  for (uint32 i = 0; i < serverCount; i++)
  {
    result->GetNextRow(binding, (void*)&data);
    gMessageFactory->addUint32(data.mId);                       // Server Id.
    gMessageFactory->addString(data.mName);                     // Server name
    gMessageFactory->addUint32(0xffff8f80);
  }
  gMessageFactory->addUint32(client->getCharsAllowed());

  // Send our message;
  Message* message = gMessageFactory->EndMessage();
  client->SendChannelA(message, 3, false);

  // Now send the current status.
  _sendServerStatus(client);

  // Destroy our database object stuff thigns
  mDatabase->DestroyDataBinding(binding);
}
Beispiel #20
0
void BuildingFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result)
{
    QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref);

    switch(asyncContainer->mQueryType)
    {
    case BFQuery_MainData:
    {
        BuildingObject* building = _createBuilding(result);

        QueryContainerBase* asContainer;

        // if its a cloning facility, query its spawn points
        if(building->getBuildingFamily() == BuildingFamily_Cloning_Facility)
        {
            asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,BFQuery_CloneData,asyncContainer->mClient);
            asContainer->mObject = building;

            mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT spawn_clone.parentId,spawn_clone.oX,spawn_clone.oY,spawn_clone.oZ,spawn_clone.oW,"
                                       "spawn_clone.cell_x,spawn_clone.cell_y,spawn_clone.cell_z,spawn_clone.city "
                                       "FROM  spawn_clone "
                                       "INNER JOIN cells ON spawn_clone.parentid = cells.id "
                                       "INNER JOIN buildings ON cells.parent_id = buildings.id "
                                       "WHERE buildings.id = %"PRIu64";",building->getId());
           
        }
        else
        {
            asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,BFQuery_Cells,asyncContainer->mClient);
            asContainer->mObject = building;

            mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT id FROM cells WHERE parent_id = %"PRIu64";",building->getId());
            
        }
    }
    break;

    case BFQuery_CloneData:
    {
        BuildingObject*	building = dynamic_cast<BuildingObject*>(asyncContainer->mObject);

        uint64 spawnCount = result->getRowCount();

        if(!spawnCount)
        {
            gLogger->log(LogManager::DEBUG,"BuildingFactory: Cloning facility %"PRIu64" has no spawn points",building->getId());
        }

        for(uint64 i = 0; i < spawnCount; i++)
        {
            SpawnPoint* spawnPoint = new SpawnPoint();

            result->GetNextRow(mSpawnBinding,spawnPoint);

            building->addSpawnPoint(spawnPoint);
        }

        // load cells
        QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,BFQuery_Cells,asyncContainer->mClient);
        asContainer->mObject = building;

        mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT id FROM cells WHERE parent_id = %"PRIu64";",building->getId());
        
    }
    break;

    case BFQuery_Cells:
    {
        BuildingObject*	building = dynamic_cast<BuildingObject*>(asyncContainer->mObject);
        uint32			cellCount;
        uint64			cellId;

        DataBinding*	cellBinding = mDatabase->CreateDataBinding(1);
        cellBinding->addField(DFT_int64,0,8);

        // store us for later lookup
        mObjectLoadMap.insert(std::make_pair(building->getId(),new(mILCPool.ordered_malloc()) InLoadingContainer(building,asyncContainer->mOfCallback,asyncContainer->mClient)));

        cellCount = static_cast<uint32>(result->getRowCount());

        building->setLoadCount(cellCount);

        for(uint32 j = 0; j < cellCount; j++)
        {
            result->GetNextRow(cellBinding,&cellId);

            mCellFactory->requestObject(this,cellId,0,0,asyncContainer->mClient);
        }

        mDatabase->DestroyDataBinding(cellBinding);
    }
    break;

    default:
        break;
    }

    mQueryContainerPool.free(asyncContainer);
}
Beispiel #21
0
void HarvesterFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result)
{
    QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref);

    switch(asyncContainer->mQueryType)
    {
    case HFQuery_ResourceData:
    {

        uint32 count = (uint32)result->getRowCount();

        HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject);

        if(count)
        {
            DataBinding* binding = mDatabase->createDataBinding(2);
            binding->addField(DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0);
            binding->addField(DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1);

            HResourceList*	hRList = harvester->getResourceList();
            hRList->resize(hRList->size()+count);

            HarvesterHopperItem hopperTemp;
            for(uint64 i=0; i <count; i++)
            {
                result->getNextRow(binding,&hopperTemp);
                hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity));
            }

        }

        QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AttributeData,asyncContainer->mClient,asyncContainer->mId);
        asynContainer->mId		= harvester->getId();
        asynContainer->mObject	= harvester;

        mDatabase->executeSqlAsync(this,asynContainer,"SELECT attributes.name,sa.value,attributes.internal"
                                   " FROM %s.structure_attributes sa"
                                   " INNER JOIN %s.attributes ON (sa.attribute_id = attributes.id)"
                                   " WHERE sa.structure_id = %" PRIu64 " ORDER BY sa.order",
                                   mDatabase->galaxy(),mDatabase->galaxy(),harvester->getId());
       
    }
    break;

    case HFQuery_AttributeData:
    {
        HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject);
        //_buildAttributeMap(harvester,result);

        Attribute_QueryContainer	attribute;
        uint64						count = result->getRowCount();
        //int8						str[256];
        //BStringVector				dataElements;

        for(uint64 i = 0; i < count; i++)
        {
            result->getNextRow(mAttributeBinding,(void*)&attribute);
            harvester->addInternalAttribute(attribute.mKey,std::string(attribute.mValue.getAnsi()));
        }

        harvester->setLoadState(LoadState_Loaded);

        LOG(info) << "Loaded harvester with id [" << harvester->getId() << "]";
        asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient);

    }
    break;

    case HFQuery_MainData:
    {
        QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_ResourceData,asyncContainer->mClient,asyncContainer->mId);

        HarvesterObject* harvester = new(HarvesterObject);
        _createHarvester(result,harvester);

        asynContainer->mObject = harvester;
        asynContainer->mClient = asyncContainer->mClient;

        //asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient);

        //now request the associated resource container count

        int8 sql[250];
        sprintf(sql,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%" PRIu64 "' ",mDatabase->galaxy(),harvester->getId());
        mDatabase->executeSqlAsync(this,asynContainer,sql);
     

    }
    break;

    default:
        break;
    }

    mQueryContainerPool.free(asyncContainer);
}
void StructureManager::_HandleUpdateAttributes(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	BString value;
	Type_QueryContainer container;

	DataBinding*	binding = mDatabase->CreateDataBinding(2);
	binding->addField(DFT_bstring,offsetof(Type_QueryContainer,mString),128,0);
	binding->addField(DFT_bstring,offsetof(Type_QueryContainer,mValue),128,1);
	
	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));
	
	PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	uint64 count;
	count = result->getRowCount();

	for(uint64 i = 0;i < count;i++)
	{
		result->GetNextRow(binding,&container);

		if(strcmp(container.mString.getAnsi(),"schematicCustom") == 0)
		{	
			FactoryObject* factory = dynamic_cast<FactoryObject*>(structure);
			if(factory)
				factory->setSchematicCustomName(container.mValue);
			gLogger->logMsgF("StructureManager::GetCustomName : %s",MSG_HIGH, container.mValue.getAnsi());
		}

		if(strcmp(container.mString.getAnsi(),"schematicName") == 0)
		{	
			FactoryObject* factory = dynamic_cast<FactoryObject*>(structure);
			if(factory)
				factory->setSchematicName(container.mValue);
			gLogger->logMsgF("StructureManager::GetName : %s",MSG_HIGH, container.mValue.getAnsi());
		}

		if(strcmp(container.mString.getAnsi(),"schematicFile") == 0)
		{	
			FactoryObject* factory = dynamic_cast<FactoryObject*>(structure);
			if(factory)
				factory->setSchematicFile(container.mValue);
			gLogger->logMsgF("StructureManager::GetNameFile : %s",MSG_HIGH, container.mValue.getAnsi());
		}

		if(strcmp(container.mString.getAnsi(),"maintenance") == 0)
		{

			if(structure->hasAttribute("examine_maintenance"))
			{
				structure->setAttribute("examine_maintenance",container.mValue.getAnsi());
			}
			else
			{
				structure->addAttribute("examine_maintenance",container.mValue.getAnsi());
			}
		}

		if(strcmp(container.mString.getAnsi(),"power") == 0)
		{

			if(structure->hasAttribute("examine_power"))
			{
				structure->setAttribute("examine_power",container.mValue.getAnsi());
			}
			else
			{
				structure->addAttribute("examine_power",container.mValue.getAnsi());
			}

		}

		if(strcmp(container.mString.getAnsi(),"condition") == 0)
		{

			
			container.mValue.setLength(4);
			structure->setDamage(boost::lexical_cast<uint32>(container.mValue.getAnsi()));
			gLogger->logMsgF("StructureManager::GetConditionData : %u",MSG_HIGH, structure->getDamage());
		}

		if(strcmp(container.mString.getAnsi(),"name") == 0)
		{

			structure->setOwnersName(container.mValue);
			
		}
	}

	switch(asynContainer->command.Command)
	{
		case Structure_Command_AccessSchem:
		{
			FactoryObject* factory = dynamic_cast<FactoryObject*>(structure);
			if(factory)
				createNewFactorySchematicBox(player, factory);
		}
		break;

		case Structure_Command_Destroy:
		{
			structure->deleteStructureDBDataRead(player->getId());
		}
		break;

		case Structure_Command_DepositPower:
		{
			createPowerTransferBox(player,structure);
		}
		break;

		case Structure_Command_PayMaintenance:
		{
			createPayMaintenanceTransferBox(player,structure);
		}
		break;

		case Structure_Command_ViewStatus:
		{
			createNewStructureStatusBox(player, structure);
		}
		break;

		default:
			break;
	}		
	
	mDatabase->DestroyDataBinding(binding);												   	


}
void StructureManager::_HandleCheckPermission(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));

	uint32 returnValue;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint32,0,4);

	uint64 count;
	count = result->getRowCount();

	if (!count)
	{
		gLogger->logMsgLoadFailure("StructureManager::check Permission no return value...",MSG_NORMAL);
		mDatabase->DestroyDataBinding(binding);
		return;
	}
	result->GetNextRow(binding,&returnValue);
	// 0 is on List
	// 1 name doesnt exist
	// 2 name not on list
	// 3 owner

	if((returnValue == 0)||(returnValue == 3))
	{
		// call processing handler
		// 3 means structure Owner
		processVerification(asynContainer->command,(returnValue == 3));
		
	}

	if(returnValue == 1)
	{
		string name;
		name = asynContainer->name;
		name.convert(BSTRType_ANSI);
		
		gLogger->logMsgF("StructurManager check Permission name %s doesnt exist ", MSG_HIGH,name.getAnsi());
		
	}

	if(returnValue == 2)
	{
		if(asynContainer->command.Command == Structure_Command_CellEnter )
		{
			//the structure is private - we are not on the access list :(
			if(BuildingObject* building = dynamic_cast<BuildingObject*>(gWorldManager->getObjectById(asynContainer->command.StructureId)))
				building->updateCellPermissions(player,false);
		}
		else
		if(asynContainer->command.Command == Structure_Command_CellEnterDenial)
		{
			//in case the structure was private before we are now be allowed to enter
			//as we are not banned
			if(BuildingObject* building = dynamic_cast<BuildingObject*>(gWorldManager->getObjectById(asynContainer->command.StructureId)))
				building->updateCellPermissions(player,true);
		}
		else
			gMessageLib->sendSystemMessage(player,L"You are not an admin of this structure");
	}

	mDatabase->DestroyDataBinding(binding);
}
void StructureManager::_HandleNonPersistantLoadStructureItem(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	StructureItemTemplate* itemTemplate;

	DataBinding* binding = mDatabase->CreateDataBinding(14);
	binding->addField(DFT_uint32,offsetof(StructureItemTemplate,structure_id),4,0);
	binding->addField(DFT_uint32,offsetof(StructureItemTemplate,CellNr),4,1);
	binding->addField(DFT_uint32,offsetof(StructureItemTemplate,item_type),4,2);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mPosition.x),4,3);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mPosition.y),4,4);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mPosition.z),4,5);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mDirection.x),4,6);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mDirection.y),4,7);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mDirection.z),4,8);
	binding->addField(DFT_float,offsetof(StructureItemTemplate,mDirection.w),4,9);
	binding->addField(DFT_uint32,offsetof(StructureItemTemplate,tanType),4,10);

	binding->addField(DFT_bstring,offsetof(StructureItemTemplate,structureObjectString),128,11);
	binding->addField(DFT_bstring,offsetof(StructureItemTemplate,name),32,12);
	binding->addField(DFT_bstring,offsetof(StructureItemTemplate,file),32,13);

	uint64 count;
	count = result->getRowCount();

	for(uint64 i = 0;i < count;i++)
	{
		itemTemplate = new(StructureItemTemplate);
		result->GetNextRow(binding,itemTemplate);
		mItemTemplate.push_back(itemTemplate);
	}

	if(result->getRowCount())
		gLogger->logMsgLoadSuccess("StructureManager::Loading %u Structure Items...",MSG_NORMAL,result->getRowCount());
	else
		gLogger->logMsgLoadFailure("StructureManager::Loading Structure Items...",MSG_NORMAL);

	mDatabase->DestroyDataBinding(binding);

}
void StructureManager::_HandleAddPermission(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));

	uint32 returnValue;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint32,0,4);

	uint64 count;
	count = result->getRowCount();

	if (!count)
	{
		gLogger->logMsgLoadFailure("StructureManager::add Permission no return value...",MSG_NORMAL);
	}
	result->GetNextRow(binding,&returnValue);
	// 0 is sucess
	// 1 name doesnt exist
	// 2 name already on list
	// 3 list is full (more than 36 entries)
	// 4 owner tried to add him/herselve to the ban list

	if(returnValue == 0)
	{
		string name;
		name = asynContainer->name;
		//gMessageLib->sendSystemMessage(player,L"","player_structure","player_added","",name.getAnsi());
		name.convert(BSTRType_Unicode16);
		gMessageLib->sendSystemMessage(player,L"","player_structure","player_added","","",name.getUnicode16());
		
		//now read in the (admin) list again if its a playerHouse
		//we need to keep them in memory to handle drop/pickup in cells
		if(HouseObject*	house = dynamic_cast<HouseObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)))
		{
			updateKownPlayerPermissions(house);
			StructureManagerAsyncContainer* asContainer = new StructureManagerAsyncContainer(Structure_Query_UpdateAdminPermission,NULL);
			asContainer->mStructureId = asynContainer->mStructureId;

			gWorldManager->getDatabase()->ExecuteSqlAsync(this,asContainer,"SELECT PlayerID FROM structure_admin_data WHERE StructureID = %"PRIu64" AND AdminType like 'ADMIN';",asContainer->mStructureId);
		}
	}

	//no valid name
	if(returnValue == 1)
	{
		string name;
		name = asynContainer->name;
		name.convert(BSTRType_ANSI);
		gLogger->logMsgF("StructurManager add %s failed ", MSG_HIGH,name.getAnsi());
		name.convert(BSTRType_Unicode16);
		
		gMessageLib->sendSystemMessage(player,L"","player_structure","modify_list_invalid_player","","",name.getUnicode16());
	}

	//name already on the list
	if(returnValue == 2)
	{
		string name;
		name = asynContainer->name;
		name.convert(BSTRType_ANSI);
		name << " is already on the list";
		name.convert(BSTRType_Unicode16);
		gMessageLib->sendSystemMessage(player,name.getUnicode16());
	}

	//no more than 36 entries on the list
	if(returnValue == 3)
	{
		gMessageLib->sendSystemMessage(player,L"","player_structure","too_many_entries");
	}

	//dont ban the owner
	if(returnValue == 4)
	{
		gMessageLib->sendSystemMessage(player,L"You cannot Ban the structure's Owner");
	}

	mDatabase->DestroyDataBinding(binding);

}
void StructureManager::_HandleRemovePermission(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	//PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));

	uint32 returnValue;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint32,0,4);

	uint64 count;
	count = result->getRowCount();

	if (!count)
	{
		gLogger->logMsgLoadFailure("StructureManager::Structure_Query_Remove_Permission no return value...",MSG_NORMAL);
	}
	result->GetNextRow(binding,&returnValue);
	// 0 is sucess
	// 1 name doesnt exist
	// 2 name not on list
	// 3 Owner cannot be removed

	if(returnValue == 0)
	{
		string name;
		name = asynContainer->name;
		name.convert(BSTRType_Unicode16);
		gMessageLib->sendSystemMessage(player,L"","player_structure","player_removed","","",name.getUnicode16());

		if(HouseObject*	house = dynamic_cast<HouseObject*>(gWorldManager->getObjectById(asynContainer->mStructureId)))
		{
			updateKownPlayerPermissions(house);
			StructureManagerAsyncContainer* asContainer = new StructureManagerAsyncContainer(Structure_Query_UpdateAdminPermission,NULL);
			asContainer->mStructureId = asynContainer->mStructureId;

			gWorldManager->getDatabase()->ExecuteSqlAsync(this,asContainer,"SELECT PlayerID FROM structure_admin_data WHERE StructureID = %"PRIu64" AND AdminType like 'ADMIN';",asContainer->mStructureId);
		}
	}

	if(returnValue == 1)
	{
		string name;
		name = asynContainer->name;
		name.convert(BSTRType_Unicode16);

		gMessageLib->sendSystemMessage(player,L"","player_structure","modify_list_invalid_player","","",name.getUnicode16());
	}

	if(returnValue == 2)
	{
		string name;
		name = asynContainer->name;
		//name.convert(BSTRType_Unicode16);
		name.convert(BSTRType_ANSI);
		name << " is not on the list";
		name.convert(BSTRType_Unicode16);
		gMessageLib->sendSystemMessage(player,name.getUnicode16());
	}

	if(returnValue == 3)
	{
		string name;
		name = asynContainer->name;
		name.convert(BSTRType_Unicode16);

		gMessageLib->sendSystemMessage(player,L"","player_structure","cannot_remove_owner","","",name.getUnicode16());
	}


	//sendStructureAdminList(asynContainer->mPlayerId);

	mDatabase->DestroyDataBinding(binding);
}
void StructureManager::_HandleQueryLoadDeedData(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	StructureDeedLink* deedLink;

	DataBinding* binding = mDatabase->CreateDataBinding(12);
	binding->addField(DFT_uint32,offsetof(StructureDeedLink,structure_type),4,0);
	binding->addField(DFT_uint32,offsetof(StructureDeedLink,item_type),4,1);
	binding->addField(DFT_uint32,offsetof(StructureDeedLink,skill_Requirement),4,2);
	binding->addField(DFT_bstring,offsetof(StructureDeedLink,structureObjectString),128,3);
	binding->addField(DFT_uint8,offsetof(StructureDeedLink,requiredLots),1,4);
	binding->addField(DFT_bstring,offsetof(StructureDeedLink,stf_name),64,5);
	binding->addField(DFT_bstring,offsetof(StructureDeedLink,stf_file),64,6);
	binding->addField(DFT_float,offsetof(StructureDeedLink,healing_modifier),4,7);
	binding->addField(DFT_uint32,offsetof(StructureDeedLink,repair_cost),4,8);
	binding->addField(DFT_uint32,offsetof(StructureDeedLink,length), 4, 9);
	binding->addField(DFT_uint32,offsetof(StructureDeedLink,width), 4, 10);
	binding->addField(DFT_uint64,offsetof(StructureDeedLink,placementMask), 8, 11);

	uint64 count;
	count = result->getRowCount();

	for(uint64 i = 0;i < count;i++)
	{
		deedLink	= new(StructureDeedLink);
		result->GetNextRow(binding,deedLink);
		mDeedLinkList.push_back(deedLink);
	}

	if(result->getRowCount())
		gLogger->logMsgLoadSuccess("StructureManager::Loading %u Structures...",MSG_NORMAL,result->getRowCount());
	else
		gLogger->logMsgLoadFailure("StructureManager::Loading Structures...",MSG_NORMAL);

	mDatabase->DestroyDataBinding(binding);
}
void MissionManager::handleDatabaseJobComplete(void* ref,DatabaseResult* result)
{
    MissionManagerAsyncContainer* asynContainer = (MissionManagerAsyncContainer*)ref;

    switch(asynContainer->mQueryType)
    {

		case MissionQuery_Load_Names_File:
		{
			// m_t.mission_type, m_t.mission_name, m_t.mission_text FROM swganh.mission_text m_t INNER JOIN swganh.mission_types mty ON mty.id = m_t.mission_type WHERE mission_name like 'm%o' AND (mty.type NOT like 'mission_npc_%')", zone);

			DataBinding* binding = mDatabase->CreateDataBinding(3);
			binding->addField(DFT_uint32,offsetof(Mission_Names,type),4,0);
			binding->addField(DFT_bstring,offsetof(Mission_Names,mission_name),64,1);
			binding->addField(DFT_bstring,offsetof(Mission_Names,name),64,2);


			uint64 count;
			count = result->getRowCount();
			Mission_Names* names;

			MissionMap::iterator it;
			for(uint64 i = 0;i < count;i++)
			{
				names = new(Mission_Names);
				result->GetNextRow(binding,names);

				if(names->name.getLength() > 2)
				{
					names->id = names->mission_name.getCrc();

					it = mMissionMap.find(names->type);
					if(it != mMissionMap.end())
					{
						(*it).second->names.insert(std::make_pair(names->id,names));
					}
					else
					{
						failed=true;
					}
				}
				//mNameMap.insert(std::make_pair(i,names));
			}

			// not all missions have associated names ...
			if(result->getRowCount())
				gLogger->logMsgLoadSuccess("MissionManager::Loading %u Mission stfs...",MSG_NORMAL,count);
			else
				gLogger->logMsgLoadFailure("MissionManager::Loading Mission stfs...",MSG_NORMAL);

		}
		break;

		case MissionQuery_Load_Names:
		{
			DataBinding* binding = mDatabase->CreateDataBinding(1);
			binding->addField(DFT_bstring,offsetof(Mission_Names,name),64,0);


			uint64 count;
			count = result->getRowCount();
			Mission_Names* names;

			for(uint64 i = 0;i < count;i++)
			{
				names = new(Mission_Names);
				result->GetNextRow(binding,names);
				names->id = static_cast<uint32>(i);
				mNameMap.insert(std::make_pair(static_cast<uint32>(i),names));
			}

			if(result->getRowCount())
				gLogger->logMsgLoadSuccess("MissionManager::Loading %u Mission Names...",MSG_NORMAL,count);
			else
				gLogger->logMsgLoadFailure("MissionManager::Loading Mission Names...",MSG_NORMAL);

		}
		break;

		case MissionQuery_Load_Types:
		{
			//these is the list of the stf files together with the amount of entries they have

			DataBinding* binding = mDatabase->CreateDataBinding(4);
			binding->addField(DFT_uint32,offsetof(Mission_Types,id),4,0);
			binding->addField(DFT_bstring,offsetof(Mission_Types,stf),128,1);
			binding->addField(DFT_uint32,offsetof(Mission_Types,content),4,2);
			binding->addField(DFT_uint32,offsetof(Mission_Types,nameprovided),4,3);

			uint64 count;
			count = result->getRowCount();
			Mission_Types* mission;

			for(uint64 i = 0;i < count;i++)
			{
				mission = new(Mission_Types);
				result->GetNextRow(binding,mission);
				mMissionMap.insert(std::make_pair(static_cast<uint32>(mission->id),mission));
			}

			MissionManagerAsyncContainer*  asyncContainer = new MissionManagerAsyncContainer(MissionQuery_Load_Terminal_Type, 0);
			mDatabase->ExecuteSqlAsync(this,asyncContainer,"SELECT mtmt.id, mtmt.terminal, mtmt.mission_type,mt.content, mt.name FROM swganh.mission_terminal_mission_types mtmt INNER JOIN swganh.mission_types mt ON (mt.id = mtmt.mission_type)");

			asyncContainer = new MissionManagerAsyncContainer(MissionQuery_Load_Names_File, 0);
			mDatabase->ExecuteSqlAsyncNoArguments(this,asyncContainer,"SELECT m_t.mission_type, m_t.mission_name, m_t.mission_text FROM swganh.mission_text m_t INNER JOIN swganh.mission_types mty ON mty.id = m_t.mission_type WHERE mission_name like 'm%o' AND (mty.type NOT like 'mission_npc_%')");

			if(result->getRowCount())
				gLogger->logMsgLoadSuccess("MissionManager::Loading %u Mission Types...",MSG_NORMAL,result->getRowCount());
			else
				gLogger->logMsgLoadFailure("MissionManager::Loading Mission Types...",MSG_NORMAL);

		}
		break;

		case MissionQuery_Load_Terminal_Type:
		{
			//this links the stffiles for missions to the respective missionterminals
			DataBinding* binding = mDatabase->CreateDataBinding(5);
			binding->addField(DFT_uint32,offsetof(Terminal_Mission_Link,id),4,0);
			binding->addField(DFT_uint64,offsetof(Terminal_Mission_Link,terminal),8,1);
			binding->addField(DFT_uint32,offsetof(Terminal_Mission_Link,mission_type),4,2);
			binding->addField(DFT_uint32,offsetof(Terminal_Mission_Link,content),4,3);
			binding->addField(DFT_uint32,offsetof(Terminal_Mission_Link,name),4,4);

			uint64 count;
			count = result->getRowCount();
			Terminal_Mission_Link* terminalMissionLink;

			for(uint64 i = 0;i < count;i++)
			{
				terminalMissionLink = new(Terminal_Mission_Link);
				result->GetNextRow(binding,terminalMissionLink);

				MissionMap::iterator it = mMissionMap.find(terminalMissionLink->mission_type);

				if(it != mMissionMap.end())
					terminalMissionLink->missiontype = (*it).second;
				else
				{
					continue;
				}

				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"creature")!= NULL)
				{
					terminalMissionLink->target= MissionTarget_Creature;
				}
				else
					terminalMissionLink->target= MissionTarget_NPC;

				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"from_npc")!= NULL)
				{
					terminalMissionLink->giver= MissionGiver_NPC;
				}
				else
					terminalMissionLink->giver = MissionGiver_NameProvided;



				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"destroy")!= NULL)
				{
					terminalMissionLink->type = MissionTypeDestroy;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"bounty")!= NULL)
				{
					terminalMissionLink->type = MissionTypeBounty;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"deliver")!= NULL)
				{
					terminalMissionLink->type = MissionTypeDeliver;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"dancer")!= NULL)
				{
					terminalMissionLink->type = MissionTypeDancer;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"escorttocreator")!= NULL)
				{
					terminalMissionLink->type = MissionTypeEscorttoCreator;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"escort")!= NULL)
				{
					terminalMissionLink->type = MissionTypeEscort;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"musician")!= NULL)
				{
					terminalMissionLink->type = MissionTypeMusician;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"hunting")!= NULL)
				{
					terminalMissionLink->type = MissionTypeHunting;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"recon")!= NULL)
				{
					terminalMissionLink->type = MissionTypeRecon;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"survey")!= NULL)
				{
					terminalMissionLink->type = MissionTypeSurvey;
				}


				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"easy")!= NULL)
				{
					terminalMissionLink->difficulty = MissionDifficulty_Easy;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"medium")!= NULL)
				{
					terminalMissionLink->difficulty = MissionDifficulty_Medium;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"hard")!= NULL)
				{
					terminalMissionLink->difficulty = MissionDifficulty_Hard;
				}


				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"rebel")!= NULL)
				{
					terminalMissionLink->faction = MissionFaction_Rebel;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"neutral")!= NULL)
				{
					terminalMissionLink->faction = MissionFaction_Neutral;
				}
				else
				if(strstr(terminalMissionLink->missiontype->stf.getAnsi(),"imperial")!= NULL)
				{
					terminalMissionLink->faction = MissionFaction_Imperial;
				}


				//do we have the terminal already in our list?

				TerminalMap::iterator terminalMapIt = mTerminalMap.find(terminalMissionLink->terminal);
				if(terminalMapIt != mTerminalMap.end())
				{
					Terminal_Type* terminal = (*terminalMapIt).second;
					terminal->list.push_back(terminalMissionLink);

				}
				else
				{
					Terminal_Type* terminal = new(Terminal_Type);
					mTerminalMap.insert(std::make_pair(terminalMissionLink->terminal,terminal));
					terminal->id = terminalMissionLink->terminal;
					terminal->list.push_back(terminalMissionLink);

				}
			}

			if(result->getRowCount())
				gLogger->logMsgLoadSuccess("MissionManager::Loading %u Mission Terminal Links...",MSG_NORMAL,result->getRowCount());
			else
				gLogger->logMsgLoadFailure("MissionManager::Loading Mission Terminal Links...",MSG_NORMAL);

		}
		break;

        default:
            break;
    }

    delete(asynContainer);
}
Beispiel #29
0
void BuffManager::LoadBuffsFromResult(buffAsyncContainer* asyncContainer, DatabaseResult* result)
{
    DataBinding*	buffBinding = mDatabase->createDataBinding(9);
    buffBinding->addField(DFT_uint64,offsetof(BuffDBItem,mBuffId),8,0);
    buffBinding->addField(DFT_uint64,offsetof(BuffDBItem,mTargetId),8,1);
    buffBinding->addField(DFT_uint64,offsetof(BuffDBItem,mInstigatorId),8,2);
    buffBinding->addField(DFT_uint32,offsetof(BuffDBItem,mMaxTicks),4,3);
    buffBinding->addField(DFT_uint64,offsetof(BuffDBItem,mTickLength),8,4);
    buffBinding->addField(DFT_uint32,offsetof(BuffDBItem,mCurrentTick),4,5);
    buffBinding->addField(DFT_uint32,offsetof(BuffDBItem,mIconCRC),4,6);
    buffBinding->addField(DFT_uint64,offsetof(BuffDBItem,mPausedGlobalTick),8,7);
    buffBinding->addField(DFT_uint64,offsetof(BuffDBItem,mStartGlobalTick),8,8);

    uint64 rowCount = result->getRowCount();

    if(rowCount == 0)
    {
        SAFE_DELETE(asyncContainer);
        mDatabase->destroyDataBinding(buffBinding);
        return;
    }

    PlayerObject*	player			= asyncContainer->player;

    BuffDBItem* tmp = new BuffDBItem();
    for(uint64 i = 0; i < rowCount; i++)
    {
        result->getNextRow(buffBinding,tmp);

        //Check player hasn't been logged out for more than 10mins
        if((asyncContainer->currentTime - tmp->mPausedGlobalTick) < 600000)
        {
            Buff* buffTemp = Buff::FromDB(tmp, asyncContainer->currentTime);
            //Check there is time left
            if(buffTemp->GetRemainingTime(asyncContainer->currentTime) >0)
            {
                buffTemp->setTarget(player);
                player->AddBuff(buffTemp);
                player->IncBuffAsyncCount();
            } else {
                SAFE_DELETE(buffTemp);
            }
        }
    }
    SAFE_DELETE(tmp);
    mDatabase->destroyDataBinding(buffBinding);


    BuffList::iterator it = player->GetBuffList()->begin();

    while(it != player->GetBuffList()->end())
    {
        asyncContainer->buff = *it;
        LoadBuffAttributes(asyncContainer);
        it++;
    }


    asyncContainer->mQueryType = BMQuery_Delete;

    int8 sql2[550];
    sprintf(sql2, "delete from %s.character_buffs where character_id = %" PRIu64 ";",mDatabase->galaxy(), player->getId());
    mDatabase->executeSqlAsync(this,asyncContainer,sql2);

}
void StructureManager::_HandleStructureRedeedCallBack(StructureManagerAsyncContainer* asynContainer,DatabaseResult* result)
{
	PlayerStructure* structure = dynamic_cast<PlayerStructure*>(gWorldManager->getObjectById(asynContainer->mStructureId));

	//if its a playerstructure boot all players and pets inside
	HouseObject* house = dynamic_cast<HouseObject*>(structure);
	if(house)
	{
		house->prepareDestruction();
	}
	

	//destroy the structure here so the sf can still access the relevant data
	gObjectFactory->deleteObjectFromDB(structure);
	gMessageLib->sendDestroyObject_InRangeofObject(structure);

	gWorldManager->destroyObject(structure);
	

	PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(asynContainer->mPlayerId));

	uint64 deedId;
	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint64,0,8);

	uint64 count;
	count = result->getRowCount();

	if (!count)
	{
		gLogger->logMsgLoadFailure("StructureManager::create deed no result...",MSG_NORMAL);
		mDatabase->DestroyDataBinding(binding);
		return;
	}
	result->GetNextRow(binding,&deedId);

	//return value of 0 means something wasnt found
	if(!deedId)
	{
		gLogger->logMsgF("StructureManager::create deed no valid return value...",MSG_NORMAL);
		mDatabase->DestroyDataBinding(binding);
		return;
	}
	//returnvalue of 1 means that there wasnt enough money on the deed
	if(deedId == 1)
	{
		gLogger->logMsgF("StructureManager::create deed with not enough maintenance...",MSG_NORMAL);
		gMessageLib->sendSysMsg(player, "player_structure","structure_destroyed ");	
		mDatabase->DestroyDataBinding(binding);
		return;
	}

	if(player)
	{
		//load the deed into the inventory
		Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory));
		if(inventory)
		{
			//15 is itemfamily for deeds
			gObjectFactory->createIteminInventory(inventory,deedId,TanGroup_Item);
		}
	}

	UpdateCharacterLots(asynContainer->mPlayerId);

	mDatabase->DestroyDataBinding(binding);
}