Ejemplo n.º 1
0
void QuestActionContainer :: AddLine(const char *statement)
{
	STRINGLIST commands;
	Util::Split(statement, ";", commands);
	for(size_t i = 0; i < commands.size(); i++)
		AddCommand(commands[i]);
}
Ejemplo n.º 2
0
void AINutPlayer::PlaySound(const char *name) {
	STRINGLIST sub;
	Util::Split(name, "|", sub);
	while (sub.size() < 2) {
		sub.push_back("");
	}
	attachedCreature->SendPlaySound(sub[0].c_str(), sub[1].c_str());
}
Ejemplo n.º 3
0
bool ExtendedQuestAction :: InitCommand(const STRINGLIST &tokenList)
{
	if(tokenList.size() < 1)
		return false;
	const QuestScriptCommandDef *cmd = GetCommandDef(tokenList[0]);
	if(cmd == 0)
	{
		g_Logs.data->warn("Quest command not recognized [%v]", tokenList[0].c_str());
		return false;
	}
	size_t tokenCount = tokenList.size();
	if(tokenCount != cmd->numParams + 1)  //First token is command itself
	{
		g_Logs.data->warn("Expected [%v] arguments for command [%v]", cmd->numParams, cmd->name);
		return false;
	}

	opCode = cmd->opCode;
	for(int i = 0; i < cmd->numParams; i++)
	{
		bool valid = false;
		int result = 0;
		valid = ResolveOperand(tokenList[1 + i], cmd->paramType[i], result);
		if(valid == false)
			return false;
		param[i] = result;
	}
	return true;

	/*
	int opCode = GetCondition(tokenList[0]);
	size_t tokenCount = tokenList.size();
	int p1 = 0;
	int p2 = 0;
	int p3 = 0;
	switch(opCode)
	{
	case CONDITION_HASSTAT:
		if(ExpectTokens(tokenCount, 4) == false) return false;
		p1 = GetStatIDByName(tokenList[1]);
		p2 = GetComparator(tokenList[2]);
		p3 = Util::GetFloat(tokenList[3]);
		if(p1 == -1 || p2 == COMP_NONE)
			return false;
		break;
	case CONDITION_HASITEM:
		if(ExpectTokens(tokenCount, 3) == false) return false;
		p1 = Util::GetInteger(tokenList[1]);
		p2 = Util::GetInteger(tokenList[2]);
		break;
	}
	commandType = opCode;
	param1 = p1;
	param2 = p2;
	param3 = p3;
	return true;
	*/
}
Ejemplo n.º 4
0
void IGFManager :: EnumCategoryList(int parentID, MULTISTRING &output)
{
	STRINGLIST entry;
	CATEGORYPAGE::iterator it;
	IGFCategoryPage::CATEGORYENTRY::iterator eit;
	for(it = mCategoryPages.begin(); it != mCategoryPages.end(); ++it)
	{
		for(eit = it->second.mEntries.begin(); eit != it->second.mEntries.end(); ++eit)
		{
			if(eit->second.mParentCategory == parentID)
			{
				entry.push_back(ConvertInteger(TYPE_CATEGORY));
				entry.push_back(ConvertInteger(eit->second.mID));
				entry.push_back(ConvertInteger(eit->second.mLocked));
				entry.push_back(ConvertInteger(0)); //Stickied.  Categories don't have this.
				entry.push_back(eit->second.mTitle);
				entry.push_back(ConvertInteger(eit->second.mThreadList.size()));
				entry.push_back(ConvertInteger(GetTimeOffset(eit->second.mLastUpdateTime)));

				output.push_back(entry);
				entry.clear();
			}
		}
	}
}
Ejemplo n.º 5
0
const char * Platform::Filename(const char *path)
{
	STRINGLIST v;
	const std::string p = path;
	const std::string d(1, PLATFORM_FOLDERVALID);
	Util::Split(p, d.c_str(), v);
	if(v.size() == 0)
		return "";
	else
		return v[v.size() - 1].c_str();
}
Ejemplo n.º 6
0
//Break a comma-delimited string into tokens, then loading the converted values into a raw array of floats.
void AssignFloatArrayFromStringSplit(float *arrayDest, size_t arraySize, const std::string &strData)
{
	STRINGLIST strArray;
	Split(strData, ",", strArray);
	for(size_t i = 0; i < strArray.size(); i++)
	{
		if(i >= arraySize)
			return;
		arrayDest[i] = static_cast<float>(atof(strArray[i].c_str()));
	}
}
Ejemplo n.º 7
0
const char * Platform::Extension(const char *path)
{
	STRINGLIST v;
	const std::string p = Filename(path);
	const std::string d(1, PLATFORM_FOLDERVALID);
	Util::Split(p, ".", v);
	if(v.size() == 0)
		return "";
	else if(v.size() == 1)
		return v[0].c_str();
	else
		return v[v.size() - 1].c_str();
}
Ejemplo n.º 8
0
void IGFManager :: EnumThreadList(int parentID, MULTISTRING &output)
{
	IGFCategory* category = GetPagedCategoryPtr(parentID);
	if(category == NULL)
		return;

	//Pregenerate a list of threads
	std::vector<IGFThread*> results;
	for(size_t i = 0; i < category->mThreadList.size(); i++)
	{
		IGFThread* thread = GetPagedThreadPtr(category->mThreadList[i]);
		if(thread != NULL)
			results.push_back(thread);
	}

	if(category->mFlags.hasFlag(IGFFlags::FLAG_SORTALPHABETICAL))
		std::sort(results.begin(), results.end(), ThreadSortAlphabetical);

	STRINGLIST entry;
	for(size_t i = 0; i < results.size(); i++)
	{
		IGFThread* thread = results[i];
		entry.push_back(ConvertInteger(TYPE_THREAD));
		entry.push_back(ConvertInteger(thread->mID));
		entry.push_back(ConvertInteger(thread->mLocked));
		entry.push_back(ConvertInteger(thread->mStickied));
		entry.push_back(thread->mTitle);
		entry.push_back(ConvertInteger(thread->mPostList.size()));
		entry.push_back(ConvertInteger(GetTimeOffset(thread->mLastUpdateTime)));

		output.push_back(entry);
		entry.clear();
	}
}
Ejemplo n.º 9
0
void CServerDefinitions::LoadDFNCategory( DEFINITIONCATEGORIES toLoad )
{
	CleanPriorityMap();
	defaultPriority = 0;
	UI08 wasPriod = 2;
	BuildPriorityMap( toLoad, wasPriod );

	cDirectoryListing fileList( toLoad, defExt );
	fileList.Flatten( true );
	STRINGLIST *shortListing	= fileList.FlattenedShortList();
	STRINGLIST *longListing		= fileList.FlattenedList();

	std::vector< PrioScan >	mSort;
	for( size_t i = 0; i < shortListing->size(); ++i )
	{
		mSort.push_back( PrioScan( (*longListing)[i].c_str(), GetPriority( (*shortListing)[i].c_str() ) ) );
	}
	if( !mSort.empty() )
	{
		std::sort( mSort.begin(), mSort.end() );
		Console.Print( "Section %20s : %6i", dirnames[toLoad].c_str(), 0 );
		size_t iTotal = 0;
		Console.TurnYellow();

		std::vector< PrioScan >::const_iterator mIter;
		for( mIter = mSort.begin(); mIter != mSort.end(); ++mIter )
		{
			Console.Print( "\b\b\b\b\b\b" );
			ScriptListings[toLoad].push_back( new Script( (*mIter).filename, toLoad, false ) );
			iTotal += ScriptListings[toLoad].back()->NumEntries();
			Console.Print( "%6i", iTotal );
		}

		Console.Print( "\b\b\b\b\b\b%6i", CountOfEntries( toLoad ) );
		Console.TurnNormal();
		Console.Print( " entries" );
		switch( wasPriod )
		{
			case 0:	Console.PrintSpecial( CGREEN,	"prioritized" );					break;	// prioritized
			case 1:	
				Console.PrintSpecial( CGREEN,		"done" );		
				break;	// file exist, no section
			default:
			case 2:	
				Console.PrintSpecial( CBLUE,	"done" );		
				break;	// no file
		};
	}
}
Ejemplo n.º 10
0
const char * Platform::Basename(const char *path)
{
	STRINGLIST v;
	const std::string p = Filename(path);
	const std::string d(1, PLATFORM_FOLDERVALID);
	Util::Split(p, ".", v);
	if(v.size() == 0)
		return "";
	else {
		std::string t;
		v.erase(v.end() - 1);
		Util::Join(v, d.c_str(), t);
		return t.c_str();
	}
}
Ejemplo n.º 11
0
void IGFManager :: GetCategory(int id, MULTISTRING &output)
{
	IGFCategory *category = GetPagedCategoryPtr(id);
	if(category == NULL)
		return;

	STRINGLIST header;

	header.push_back(ConvertInteger(id));
	header.push_back(category->mTitle);
	output.push_back(header);

	EnumCategoryList(id, output);
	EnumThreadList(id, output);
}
Ejemplo n.º 12
0
void CServerDefinitions::BuildPriorityMap( DEFINITIONCATEGORIES category, UI08& wasPrioritized )
{
	cDirectoryListing priorityFile( category, "priority.nfo", false );
	STRINGLIST *longList = priorityFile.List();
	if( longList->size() > 0 )
	{
		std::string filename = (*longList)[0];
		//	Do we have any priority informat?
		if( FileExists( filename ) )	// the file exists, so perhaps we do
		{
			Script *prio = new Script( filename, category, false );	// generate a script for it
			if( prio != NULL )	// successfully made a script
			{
				UString tag;
				UString data;
				ScriptSection *prioInfo = prio->FindEntry( "PRIORITY" );	// find the priority entry
				if( prioInfo != NULL )
				{
					for( tag = prioInfo->First(); !prioInfo->AtEnd(); tag = prioInfo->Next() )	// keep grabbing priority info
					{
						data = prioInfo->GrabData();
						if( tag.upper() == "DEFAULTPRIORITY" )
							defaultPriority = data.toShort();
						else
						{
							std::string filenametemp = tag.lower();
							priorityMap[filenametemp] = data.toShort();
						}
					}
					wasPrioritized = 0;
				}
				else
					wasPrioritized = 1;
				delete prio;	// remove script
				prio = NULL;
			}
			else
				wasPrioritized = 2;
			return;
		}
	}
#if defined( UOX_DEBUG_MODE )
//	Console.Warning( "Failed to open priority.nfo for reading in %s DFN", dirnames[category].c_str() );
#endif
	wasPrioritized = 2;
}
Ejemplo n.º 13
0
// Tokenize a string using whitespace as separators, but including string quotations.
void TokenizeByWhitespace(const std::string &input, STRINGLIST &output)
{
	std::string str = input;
	output.clear();
	size_t len = str.size();
	int first = -1;
	int last = -1;
	bool quote = false;
	bool terminate = false;
	for(size_t i = 0; i < len; i++)
	{
		switch(input[i])
		{
		case '"':
			terminate = true;  //Treat opening quote as a block start
			quote = !quote;
			break;

		case ' ':
		case '\t':
		case '\n':
		case '\r':
			if(quote == false)
				terminate = true;
			break;
		default:
			if(first == -1)
				first = i;
			last = i;
		}
		if(terminate == true)
		{
			if(first >= 0 && last >= 0)
			{
				std::string t = str.substr(first, last - first + 1);
				output.push_back(str.substr(first, last - first + 1));
				first = -1;
				last = -1;
			}
			terminate = false;
		}
	}
	if(first != -1 && first < (int)len)
		output.push_back(str.substr(first, len - first + 1));
}
Ejemplo n.º 14
0
void QuestActionContainer :: AddCommand(const std::string &command)
{
	STRINGLIST tokens;
	//Util::Split(command, " ", tokens);
	Util::TokenizeByWhitespace(command, tokens);
	if(tokens.size() == 0)
	{
		g_Logs.data->warn("No tokens in command.");
		return;
	}
	ExtendedQuestAction inst;
	if(inst.InitCommand(tokens) == true)
	{
		//Debug disassembly
		//g_Log.AddMessageFormat("%s = [%d]=%d,%d,%d", command.c_str(), inst.opCode, inst.param[0], inst.param[1], inst.param[2]);

		mInstList.push_back(inst);
	}
}
Ejemplo n.º 15
0
void IGFManager :: OpenCategory(int type, int id, MULTISTRING &output)
{
	//Expand an object.  If it's a category, enumerate a list of subcategories.
	if(type == TYPE_CATEGORY)
	{
		IGFCategory *category = GetPagedCategoryPtr(id);
		if(category != NULL)
		{
			STRINGLIST header;
			header.push_back(ConvertInteger(id));
			header.push_back(category->mTitle);

			output.push_back(header);

			int searchID = category->mID;
			EnumCategoryList(searchID, output);
			EnumThreadList(searchID, output);
		}
	}
}
Ejemplo n.º 16
0
void cDirectoryListing::Flatten( bool isParent )
{
	ClearFlatten();
	std::string temp;
	STRINGLIST_ITERATOR sIter;
	for( sIter = filenameList.begin(); sIter != filenameList.end(); ++sIter )
	{
		flattenedFull.push_back( (*sIter) );
		if( isParent )
			temp = "";
		else
		{
			temp = shortCurrentDir;
			temp += "/";
		}
		temp += (*sIter);
		flattenedShort.push_back( temp );
	}
	DIRLIST_ITERATOR dIter;
	for( dIter = subdirectories.begin(); dIter != subdirectories.end(); ++dIter )
	{
		(*dIter).Flatten( false );
		STRINGLIST *shortFlat	= (*dIter).FlattenedShortList();
		STRINGLIST *longFlat	= (*dIter).FlattenedList();
		for( size_t k = 0; k < longFlat->size(); ++k )
		{
			flattenedFull.push_back( (*longFlat)[k] );
			if( isParent )
				temp = "";
			else
			{
				temp = shortCurrentDir;
				temp += "/";
			}
			temp += (*shortFlat)[k];
			flattenedShort.push_back( temp );
		}
		(*dIter).ClearFlatten();
	}
}
Ejemplo n.º 17
0
std::vector<std::string> InfoManager::GetLoadingAnnouncments() {
	STRINGLIST l = g_ClusterManager.GetList(LISTPREFIX_LOADING_ANNOUNCMENTS);
	STRINGLIST s;
	if(l.size() == 0) {
		s.push_back(StringUtil::Format(ReplaceBrandingPatterns("Welcome to ${GameName} - ${Edition}. You can set your own <b>Loading Announcements</b> by creating and adding multiple elements to the list <b>'%s'</b> in the Redis database."), LISTPREFIX_LOADING_ANNOUNCMENTS.c_str()));
	}
	else {
		for(auto it = l.begin(); it != l.end(); ++it) {
			s.push_back(ReplaceBrandingPatterns(*it));
		}
	}
	return s;

}
Ejemplo n.º 18
0
int PrepExt_QueryResponseStringList(char *buffer, int queryIndex, const STRINGLIST &strData)
{
	int wpos = 0;
	wpos += PutByte(&buffer[wpos], 1);              //_handleQueryResultMsg
	wpos += PutShort(&buffer[wpos], 0);             //Placeholder for message size
	wpos += PutInteger(&buffer[wpos], queryIndex);  //Query response index
	wpos += PutShort(&buffer[wpos], 1);             //Row count

	int count = strData.size();
	if(count > 255)
	{
		g_Logs.server->warn("PrepExt_QueryResponseStringList too many strings: %v", count);
		count = 255;
	}
	wpos += PutByte(&buffer[wpos], count); //String count
	for(int a = 0; a < count; a++)
		wpos += PutStringUTF(&buffer[wpos], strData[a].c_str());   //String data
	PutShort(&buffer[1], wpos - 3);                 //Message size
	return wpos;
}
Ejemplo n.º 19
0
bool LoadConfig(std::string filename) {
	bool oauthSet = false;

	//Loads the configuration options from the target file.  These are core options
	//required for the server to operate.

	FileReader lfr;
	if (lfr.OpenText(filename.c_str()) != Err_OK) {
		return false;
	}
	static char Delimiter[] = { '=', 13, 10 };
	lfr.Delimiter = Delimiter;
	lfr.CommentStyle = Comment_Semi;

	while (lfr.FileOpen() == true) {
		int r = lfr.ReadLine();
		if (r > 0) {
			lfr.SingleBreak("=");
			char *NameBlock = lfr.BlockToString(0);
			if (strcmp(NameBlock, "ProtocolVersion") == 0) {
				g_ProtocolVersion = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "AuthMode") == 0) {
				g_AuthMode = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "AuthKey") == 0) {
				strncpy(g_AuthKey, lfr.BlockToString(1), sizeof(g_AuthKey) - 1);
			} else if (strcmp(NameBlock, "RouterPort") == 0) {
				g_RouterPort = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "SimulatorAddress") == 0) {
				strncpy(g_SimulatorAddress, lfr.BlockToString(1),
						sizeof(g_SimulatorAddress) - 1);
			} else if (strcmp(NameBlock, "BindAddress") == 0) {
				strncpy(g_BindAddress, lfr.BlockToString(1),
						sizeof(g_BindAddress) - 1);
			} else if (strcmp(NameBlock, "SimulatorPort") == 0) {
				g_SimulatorPort = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "ThreadSleep") == 0) {
				g_ThreadSleep = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "ErrorSleep") == 0) {
				g_ErrorSleep = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "MainSleep") == 0) {
				g_MainSleep = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "DefX") == 0) {
				g_Config.DefX = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "DefY") == 0) {
				g_Config.DefY = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "DefZ") == 0) {
				g_Config.DefZ = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "DefZone") == 0) {
				g_Config.DefZone = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "DefRotation") == 0) {
				g_Config.DefRotation = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "HTTPBaseFolder") == 0) {
				g_Config.HTTPBaseFolder = lfr.BlockToString(1);
			} else if (strcmp(NameBlock, "HTTPCARFolder") == 0) {
				g_Config.HTTPCARFolder = lfr.BlockToString(1);
			} else if (strcmp(NameBlock, "HTTPListenPort") == 0) {
				g_HTTPListenPort = lfr.BlockToInt(1);
			}
#ifndef NO_SSL
			else if(strcmp(NameBlock, "HTTPSListenPort") == 0)
			{
				g_HTTPSListenPort = lfr.BlockToInt(1);
			}
			else if(strcmp(NameBlock, "SSLCertificate") == 0)
			{
				AppendString(g_SSLCertificate, lfr.BlockToStringC(1, 0));
			}
#endif
			else if (strcmp(NameBlock, "RebroadcastDelay") == 0) {
				g_RebroadcastDelay = lfr.BlockToULongC(1);
			} else if (strcmp(NameBlock, "SceneryAutosaveTime") == 0) {
				g_SceneryAutosaveTime = lfr.BlockToULongC(1);
			} else if (strcmp(NameBlock, "ForceUpdateTime") == 0) {
				g_ForceUpdateTime = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "ItemBindingTypeOverride") == 0) {
				g_ItemBindingTypeOverride = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "ItemArmorTypeOverride") == 0) {
				g_ItemArmorTypeOverride = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "ItemWeaponTypeOverride") == 0) {
				g_ItemWeaponTypeOverride = lfr.BlockToInt(1);
			} else if (strcmp(NameBlock, "MOTD_Name") == 0) {
				g_MOTD_Name = lfr.BlockToStringC(1, 0);
			} else if (strcmp(NameBlock, "MOTD_Channel") == 0) {
				g_MOTD_Channel = lfr.BlockToStringC(1, 0);
			} else if (strcmp(NameBlock, "RemoteAuthenticationPassword") == 0) {
				g_Config.RemoteAuthenticationPassword = lfr.BlockToStringC(1,
						0);
			} else if (strcmp(NameBlock, "ProperSceneryList") == 0) {
				g_Config.ProperSceneryList = lfr.BlockToIntC(1);
			} else if (strcmp(NameBlock, "BuybackLimit") == 0) {
				g_Config.BuybackLimit = lfr.BlockToIntC(1);
			} else if (strcmp(NameBlock, "Upgrade") == 0)
				g_Config.Upgrade = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HeartbeatIntervalMS") == 0)
				g_Config.HeartbeatIntervalMS = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HeartbeatAbortCount") == 0)
				g_Config.HeartbeatAbortCount = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "WarpMovementBlockTime") == 0)
				g_Config.WarpMovementBlockTime = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "IdleCheckVerification") == 0)
				g_Config.IdleCheckVerification = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "IdleCheckFrequency") == 0)
				g_Config.IdleCheckFrequency = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "IdleCheckDistance") == 0)
				g_Config.IdleCheckDistance = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "IdleCheckCast") == 0)
				g_Config.IdleCheckCast = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "IdleCheckCastInterval") == 0)
				g_Config.IdleCheckCastInterval = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "IdleCheckDistanceTolerance") == 0)
				g_Config.IdleCheckDistanceTolerance = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "EnvironmentCycle") == 0)
				g_Config.EnvironmentCycle = lfr.BlockToString(1);
			else if (strcmp(NameBlock, "SendLobbyHeartbeat") == 0)
				g_Config.SendLobbyHeartbeat = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "CapExperienceLevel") == 0)
				g_Config.CapExperienceLevel = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "CapExperienceAmount") == 0)
				g_Config.CapExperienceAmount = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "CustomAbilityMechanics") == 0)
				g_Config.CustomAbilityMechanics = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "DebugPingServer") == 0)
				g_Config.DebugPingServer = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "DebugPingClient") == 0)
				g_Config.DebugPingClient = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "DebugPingFrequency") == 0)
				g_Config.DebugPingFrequency = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "DebugPingClientPollInterval") == 0)
				g_Config.DebugPingClientPollInterval = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "DebugPingServerLogThreshold") == 0)
				g_Config.DebugPingServerLogThreshold = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HTTPDeleteConnectedTime") == 0)
				g_Config.HTTPDeleteConnectedTime = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HTTPDeleteDisconnectedTime") == 0)
				g_Config.HTTPDeleteDisconnectedTime = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HTTPDeleteRecheckDelay") == 0)
				g_Config.HTTPDeleteRecheckDelay = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "PartyPositionSendInterval") == 0)
				g_Config.PartyPositionSendInterval = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "VaultDefaultSize") == 0)
				g_Config.VaultDefaultSize = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "VaultInitialPurchaseSize") == 0)
				g_Config.VaultInitialPurchaseSize = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "DebugPacketSendTrigger") == 0)
				g_Config.DebugPacketSendTrigger = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "DebugPacketSendDelay") == 0)
				g_Config.DebugPacketSendDelay = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "DebugPacketSendMessage") == 0)
				g_Config.DebugPacketSendMessage = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "GlobalMovementBonus") == 0)
				g_Config.GlobalMovementBonus = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "AllowEliteMob") == 0)
				g_Config.AllowEliteMob = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "DexBlockDivisor") == 0)
				g_Config.DexBlockDivisor = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "DexParryDivisor") == 0)
				g_Config.DexParryDivisor = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "DexDodgeDivisor") == 0)
				g_Config.DexDodgeDivisor = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "SpiResistDivisor") == 0)
				g_Config.SpiResistDivisor = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "PsyResistDivisor") == 0)
				g_Config.PsyResistDivisor = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "ForceMaxPacketSize") == 0)
				g_Config.ForceMaxPacketSize = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "SceneryAuditDelay") == 0)
				g_Config.SceneryAuditDelay = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "SceneryAuditAllow") == 0)
				g_Config.SceneryAuditAllow = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "MegaLootParty") == 0)
				g_Config.MegaLootParty = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "LootMaxRandomizedLevel") == 0)
				g_Config.LootMaxRandomizedLevel = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "LootMaxRandomizedSpecialLevel") == 0)
				g_Config.LootMaxRandomizedSpecialLevel = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "LootNamedMobSpecial") == 0)
				g_Config.LootNamedMobSpecial = lfr.BlockToBoolC(1);
			else if (strcmp(NameBlock, "LootMinimumMobRaritySpecial") == 0)
				g_Config.LootMinimumMobRaritySpecial = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HeroismQuestLevelTolerance") == 0)
				g_Config.HeroismQuestLevelTolerance = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "HeroismQuestLevelPenalty") == 0)
				g_Config.HeroismQuestLevelPenalty = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "NamedMobDropMultiplier") == 0)
				g_Config.NamedMobDropMultiplier =
						static_cast<float>(lfr.BlockToDblC(1));
			else if (strcmp(NameBlock, "NamedMobCreditDrops") == 0)
				g_Config.NamedMobCreditDrops = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "ProgressiveDropRateBonusMult") == 0)
				Util::AssignFloatArrayFromStringSplit(
						g_Config.ProgressiveDropRateBonusMult,
						COUNT_ARRAY_ELEMENTS(
								g_Config.ProgressiveDropRateBonusMult),
						lfr.BlockToStringC(1, 0));
			else if (strcmp(NameBlock, "ProgressiveDropRateBonusMultMax") == 0)
				g_Config.ProgressiveDropRateBonusMultMax = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "DropRateBonusMultMax") == 0)
				g_Config.DropRateBonusMultMax = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "UseIntegerHealth") == 0) {
				g_Config.UseIntegerHealth = lfr.BlockToBool(1);
				StatManager::SetHealthToInteger(g_Config.UseIntegerHealth);
			} else if (strcmp(NameBlock, "UseMessageBox") == 0)
				g_Config.UseMessageBox = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "UseStopSwim") == 0)
				g_Config.UseStopSwim = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "UseWeather") == 0)
				g_Config.UseWeather = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "UseReagents") == 0)
				g_Config.UseReagents = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "UseUserAgentProtection") == 0)
				g_Config.UseUserAgentProtection = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "InvalidLoginMessage") == 0)
				g_Config.InvalidLoginMessage = lfr.BlockToStringC(1, 0);
			else if(strcmp(NameBlock, "MaintenanceMessage") == 0)
				g_Config.MaintenanceMessage = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "GitHubToken") == 0)
				g_Config.GitHubToken = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "ServiceAuthURL") == 0)
				g_Config.ServiceAuthURL = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "VerifyMovement") == 0)
				g_Config.VerifyMovement = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "DebugLogAIScriptUse") == 0)
				g_Config.DebugLogAIScriptUse = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "SquirrelGCCallCount") == 0)
				g_Config.SquirrelGCCallCount = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "SquirrelGCDelay") == 0)
				g_Config.SquirrelGCDelay = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "SquirrelGCMaxDelay") == 0)
				g_Config.SquirrelGCMaxDelay = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "SquirrelVMStackSize") == 0)
				g_Config.SquirrelVMStackSize = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "SquirrelQueueSpeed") == 0)
				g_Config.SquirrelQueueSpeed = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "PersistentBuffs") == 0)
				g_Config.PersistentBuffs = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "FallDamage") == 0)
				g_Config.FallDamage = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "PartyLoot") == 0)
				g_Config.PartyLoot = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "AccountCredits") == 0)
				g_Config.AccountCredits = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "MinPVPPlayerLootItems") == 0)
				g_Config.MinPVPPlayerLootItems = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "MaxPVPPlayerLootItems") == 0)
				g_Config.MaxPVPPlayerLootItems = lfr.BlockToIntC(1);
			else if (strcmp(NameBlock, "NameChangeCost") == 0)
				g_Config.NameChangeCost = lfr.BlockToInt(1);
			else if (strcmp(NameBlock, "SSLVerifyPeer") == 0)
				g_Config.SSLVerifyPeer = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "SSLVerifyHostname") == 0)
				g_Config.SSLVerifyHostname = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "SMTPHost") == 0)
				g_Config.SMTPHost = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "SMTPUsername") == 0)
				g_Config.SMTPUsername = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "SMTPPassword") == 0)
				g_Config.SMTPPassword = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "SMTPPort") == 0)
				g_Config.SMTPPort = lfr.BlockToInt(1);
			else if (strcmp(NameBlock, "SMTPSSL") == 0)
				g_Config.SMTPSSL = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "SMTPSender") == 0)
				g_Config.SMTPSender = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "LegacyAccounts") == 0)
				g_Config.LegacyAccounts = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "PublicAPI") == 0)
				g_Config.PublicAPI = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "DirectoryListing") == 0)
				g_Config.DirectoryListing = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "HTTPKeepAlive") == 0)
				g_Config.HTTPKeepAlive = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "HTTPServeAssets") == 0)
				g_Config.HTTPServeAssets = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "LegacyServer") == 0)
				g_Config.LegacyServer = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "SiteServiceUsername") == 0)
				g_Config.SiteServiceUsername = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "SiteServicePassword") == 0)
				g_Config.SiteServicePassword = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "APIAuthentication") == 0)
				g_Config.APIAuthentication = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "OAuth2Client") == 0) {
				if(!oauthSet) {
					oauthSet = true;
					g_Config.OAuth2Clients.clear();
				}
				STRINGLIST output;
				Util::Split(lfr.BlockToString(1), "|", output);
				if (output.size() == 3) {
					OAuth2Client *c = new OAuth2Client();
					c->ClientId = output[0];
					c->ClientSecret = output[1];
					c->RedirectURL = output[2];
					g_Config.OAuth2Clients.push_back(c);
				} else {
					g_Logs.data->error("Invalid OAuth2Client string [%v] in config file [%v]",
							lfr.BlockToString(0), filename);
				}
			} else if (strcmp(NameBlock, "Clans") == 0)
				g_Config.Clans = lfr.BlockToBool(1);
			else if (strcmp(NameBlock, "ClanCost") == 0)
				g_Config.ClanCost = lfr.BlockToInt(1);
			else if (strcmp(NameBlock, "MaxAuctionHours") == 0)
				g_Config.MaxAuctionHours = lfr.BlockToInt(1);
			else if (strcmp(NameBlock, "MinAuctionHours") == 0)
				g_Config.MinAuctionHours = lfr.BlockToInt(1);
			else if (strcmp(NameBlock, "MinAuctionHours") == 0)
				g_Config.PercentageCommisionPerHour = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "MaxAuctionExpiredHours") == 0)
				g_Config.MaxAuctionExpiredHours = lfr.BlockToInt(1);
			else if (strcmp(NameBlock, "ShutdownHandlerScript") == 0)
				g_Config.ShutdownHandlerScript = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "MaxNewCreditShopItemDays") == 0)
				g_Config.MaxNewCreditShopItemDays = lfr.BlockToFloatC(1);
			else if (strcmp(NameBlock, "StaticDataPath") == 0)
				g_Config.StaticDataPath = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "VariableDataPath") == 0)
				g_Config.VariableDataPath = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "TmpDataPath") == 0)
				g_Config.TmpDataPath = lfr.BlockToStringC(1, 0);
			else if (strcmp(NameBlock, "LogPath") == 0)
				g_Config.LogPath = lfr.BlockToStringC(1, 0);
			else {
				g_Logs.data->error("Unknown identifier [%v] in config file [%v]",
						lfr.BlockToString(0), filename);
			}
		}
	}
	lfr.CloseCurrent();
	return true;
}
Ejemplo n.º 20
0
void IGFManager :: OpenThread(int threadID, int startPost, int requestedCount, MULTISTRING &output)
{
	IGFThread *thread = GetPagedThreadPtr(threadID);
	if(thread == NULL)
		return;

	startPost = Util::ClipInt(startPost, 0, thread->mPostList.size() - 1);

	STRINGLIST row;

	//We retrieve the time offset since the first session since the client uses
	//4 byte integers which theoretically may not be large enough to hold the time data.
	unsigned long timeOffset = g_PlatformTime.getAbsoluteMinutes();

	//Prepare the header
	row.push_back(ConvertInteger(threadID));  //[0]
	row.push_back(thread->mTitle);   //[1]
	row.push_back(ConvertInteger(startPost));  //[2]
	row.push_back(ConvertInteger(thread->mPostList.size()));  //[3]
	row.push_back(ConvertInteger(timeOffset - thread->mLastUpdateTime));  //[4]
	output.push_back(row);
	row.clear();

	//Append the post data.
	int count = 0;
	for(size_t i = startPost; i < thread->mPostList.size(); i++)
	{
		IGFPost *post = GetPagedPostPtr(thread->mPostList[i]);
		if(post == NULL)
		{
			g_Logs.data->error("OpenThread: unable to find post: %v", thread->mPostList[i]);
			continue;
		}

		row.push_back(ConvertInteger(post->mID));  //[0]
		row.push_back(post->mCreatorName.c_str());  //[1]
		row.push_back(post->mCreationTime.c_str());  //[2]
		row.push_back(ConvertInteger(timeOffset - post->mPostedTime)); //[3]
		row.push_back(post->mBodyText.c_str());  //[4]
		row.push_back(ConvertInteger(post->mEditCount)); //[5]
		row.push_back(ConvertInteger(timeOffset - post->mLastUpdateTime)); //[6]

		output.push_back(row);
		row.clear();

		if(++count >= requestedCount)
			break;
	}
}
Ejemplo n.º 21
0
float GetFloat(const STRINGLIST &strList, size_t index)
{
	if(index >= strList.size())
		return 0.0F;
	return static_cast<float>(atof(strList[index].c_str()));
}
Ejemplo n.º 22
0
int CreditShopEditHandler::handleQuery(SimulatorThread *sim,
		CharacterServerData *pld, SimulatorQuery *query,
		CreatureInstance *creatureInstance) {
	if (query->args.size() < 1)
		return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
				"Invalid query.");

	if (!sim->CheckPermissionSimple(Perm_Account, Permission_Sage))
		return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
				"Permission denied.");

	if (strcmp(query->GetString(0), "DELETE") == 0 && query->args.size() > 1) {
		int id = query->GetInteger(1);
		CS::CreditShopItem *item = g_CreditShopManager.GetItem(id);
		if (item == NULL)
			return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
					"Invalid item.");
		else {
			// TODO remove
			if (g_CreditShopManager.RemoveItem(id)) {
				g_Logs.event->info("[CS] Removed credit shop item %v",
						item->mId);
				return PrepExt_QueryResponseString(sim->SendBuf, query->ID,
						"OK");
			}
			return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
					"Failed to remove.");
		}
	} else if (query->args.size() > 22) {
		CS::CreditShopItem * csItem;
		bool isNew = strcmp(query->GetString(0), "NEW") == 0;
		if (isNew) {
			csItem = new CS::CreditShopItem();
			csItem->mId = g_CreditShopManager.nextMarketItemID++;
			csItem->mCreatedDate = g_ServerTime / 1000;
			SessionVarsChangeData.AddChange();
			Util::SafeFormat(sim->Aux3, sizeof(sim->Aux3),
					"Created market csItem %d", csItem->mId);

			g_Logs.cs->info("%v (%v) created %v (%v)", pld->accPtr->Name, pld->charPtr->cdef.css.display_name,
					csItem->mId, csItem->mItemId);
		} else {
			csItem = g_CreditShopManager.GetItem(query->GetInteger(0));
			if (csItem == NULL)
				return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
						"Invalid item.");
			Util::SafeFormat(sim->Aux3, sizeof(sim->Aux3),
					"Save market csItem %d", csItem->mId);

			g_Logs.cs->info("%v (%v) updated %v (%v)", pld->accPtr->Name, pld->charPtr->cdef.css.display_name,
								csItem->mId, csItem->mItemId);
		}

		int currency = query->GetInteger(16);
		unsigned long priceCopper = 0;
		unsigned long priceCredits = 0;
		STRINGLIST priceElements;
		Util::Split(query->GetString(14), "+", priceElements);
		if (currency == Currency::COPPER) {
			priceCopper = atoi(priceElements[0].c_str());
		} else if (currency == Currency::CREDITS) {
			priceCredits = atoi(priceElements[0].c_str());
		} else if (currency == Currency::COPPER_CREDITS) {
			if (priceElements.size() != 2) {
				return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
						"COPPER+CREDITS require two costs, <copperCost>+<creditCost>.");
			}
			priceCopper = atoi(priceElements[0].c_str());
			priceCredits = atoi(priceElements[1].c_str());
		}

		csItem->mTitle = query->GetString(2);
		csItem->mDescription = query->GetString(4);
		csItem->mCategory = Category::GetIDByName(query->GetString(6));
		csItem->mStatus = Status::GetIDByName(query->GetString(8));
		Util::ParseDate(query->GetString(10), csItem->mStartDate);
		Util::ParseDate(query->GetString(12), csItem->mEndDate);
		csItem->mPriceCopper = priceCopper;
		csItem->mPriceCredits = priceCredits;
		csItem->mPriceCurrency = currency;
		csItem->mQuantityLimit = query->GetInteger(18);
		csItem->mQuantitySold = query->GetInteger(20);
		csItem->ParseItemProto(query->GetString(22));

		// Check the item
		ItemDef * item = g_ItemManager.GetSafePointerByID(csItem->mItemId);
		if (item == NULL) {
			if (isNew)
				delete csItem;
			return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
					"No such item!");
		}
		if (csItem->mTitle.compare(item->mDisplayName) == 0)
			csItem->mTitle = "";

		g_CreditShopManager.SaveItem(csItem);
		g_CreditShopManager.cs.Enter(
				"SimulatorThread :: handle_query_item_market_edit");
		g_CreditShopManager.mItems[csItem->mId] = csItem;
		g_CreditShopManager.cs.Leave();

		g_Logs.cs->info("Updated Credit shop item %v '%v'", csItem->mId,
				csItem->mTitle.c_str());
		return PrepExt_QueryResponseString(sim->SendBuf, query->ID, sim->Aux3);
	}
	return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
			"Invalid sub-query.");
}
Ejemplo n.º 23
0
bool InfoManager::Init() {

	TextFileEntityReader ter(Platform::JoinPath(Platform::JoinPath(g_Config.ResolveStaticDataPath(), "Data"), "Tips.txt" ), Case_None, Comment_Semi);
	ter.Start();
	if (!ter.Exists())
		return false;

	ter.Key("", "", true);
	ter.Index("ENTRY");
	STRINGLIST sections = ter.Sections();
	int i = 0;
	for (auto a = sections.begin(); a != sections.end(); ++a) {
		ter.PushSection(*a);
		Tip t;
		t.mID = ++i;
		if (!t.EntityKeys(&ter) || !t.ReadEntity(&ter))
			return false;
		mTips.push_back(t);
		ter.PopSection();
	}
	ter.End();

	std::string filename = Platform::JoinPath(Platform::JoinPath(g_Config.ResolveStaticDataPath(), "Data"), "Game.txt" );
	FileReader lfr;
	if (lfr.OpenText(filename.c_str()) != Err_OK) {
		g_Logs.data->error("Could not open configuration file: %v", filename);
		return false;
	}
	else {
		static char Delimiter[] = { '=', 13, 10 };
		lfr.Delimiter = Delimiter;
		lfr.CommentStyle = Comment_Semi;

		while (lfr.FileOpen() == true) {
			int r = lfr.ReadLine();
			if (r > 0) {
				lfr.SingleBreak("=");
				char *NameBlock = lfr.BlockToString(0);
				if (strcmp(NameBlock, "GameName") == 0) {
					mGameName = lfr.BlockToStringC(1, 0);
				} else if (strcmp(NameBlock, "Edition") == 0) {
					mEdition = lfr.BlockToStringC(1, 0);
				} else if (strcmp(NameBlock, "StartZone") == 0) {
					mStartZone = lfr.BlockToInt(1);
				} else if (strcmp(NameBlock, "StartX") == 0) {
					mStartX = lfr.BlockToInt(1);
				} else if (strcmp(NameBlock, "StartY") == 0) {
					mStartY = lfr.BlockToInt(1);
				} else if (strcmp(NameBlock, "StartZ") == 0) {
					mStartZ = lfr.BlockToInt(1);
				} else if (strcmp(NameBlock, "StartRotation") == 0) {
					mStartRotation = lfr.BlockToInt(1);
				}
				else {
					g_Logs.data->error("Unknown identifier [%v] in config file [%v]",
							lfr.BlockToString(0), filename);
				}
			}
		}
		lfr.CloseCurrent();
	}

	return true;

}
Ejemplo n.º 24
0
void AIScriptPlayer :: RunImplementationCommands(int opcode)
{
	ScriptCore::OpData *in = &def->instr[curInst];
	switch(opcode)
	{
	case OP_USE:
		if(attachedCreature->ab[0].bPending == false)
		{
			//DEBUG OUTPUT
			if(g_Config.DebugLogAIScriptUse == true)
			{
				const Ability2::AbilityEntry2* abptr = g_AbilityManager.GetAbilityPtrByID(in->param1);
				g_Logs.script->debug("Using: %v", abptr->GetRowAsCString(Ability2::ABROW::NAME));
			}
			//END DEBUG OUTPUT

			int r = attachedCreature->CallAbilityEvent(in->param1, EventType::onRequest);
			if(r != 0)
			{
				//Notify the creature we failed, may need a distance check.
				//The script should wait and retry soon.
				attachedCreature->AICheckAbilityFailure(r);
				nextFire = g_ServerTime + USE_FAIL_DELAY;


				if(g_Config.DebugLogAIScriptUse == true)
				{
					const Ability2::AbilityEntry2* abptr = g_AbilityManager.GetAbilityPtrByID(in->param1);
					g_Logs.script->debug("Using: %v   Failed: %v", abptr->GetRowAsCString(Ability2::ABROW::NAME), g_AbilityManager.GetAbilityErrorCode(r));
				}

				if(attachedCreature->AIAbilityFailureAllowRetry(r) == true)
				{
					advance = 0;  //Don't advance the instruction so that we can retry this command.
				}
			}
		}
		else
		{
			advance = 0;
			nextFire = g_ServerTime + USE_FAIL_DELAY;
		}
		break;
	case OP_GETWILL:
		SetVar(def->instr[curInst].param1, attachedCreature->css.will);
		break;
	case OP_GETWILLCHARGE:
		SetVar(def->instr[curInst].param1, attachedCreature->css.will_charges);
		break;
	case OP_GETMIGHT:
		SetVar(def->instr[curInst].param1, attachedCreature->css.might);
		break;
	case OP_GETMIGHTCHARGE:
		SetVar(def->instr[curInst].param1, attachedCreature->css.might_charges);
		break;
	case OP_HASTARGET:
		SetVar(def->instr[curInst].param1, (attachedCreature->CurrentTarget.targ != NULL) ? 1 : 0);
		break;
	case OP_GETLEVEL:
		SetVar(def->instr[curInst].param1, attachedCreature->css.level);
		break;
	case OP_DEBUGPRINT:
		g_Logs.script->debug("[DEBUGPRINT] (%v) %v", def->scriptName, def->stringList[def->instr[curInst].param1].c_str());
		break;
	case OP_GETCOOLDOWN:
		{
			const char *cooldownName = GetStringTableEntry(def->instr[curInst].param1);
			int cooldownID = g_AbilityManager.ResolveCooldownCategoryID(cooldownName);
			int result = (attachedCreature->HasCooldown(cooldownID) == true) ? 1 : 0;
			SetVar(in->param2, result);
		}
		break;
	case OP_ISBUSY:
		{
			int result = (attachedCreature->AICheckIfAbilityBusy() == true) ? 1 : 0;
			SetVar(in->param1, result);
		}
		break;
	case OP_COUNTENEMYNEAR:
		{
			float x = (float)attachedCreature->CurrentX;
			float z = (float)attachedCreature->CurrentZ;
			SetVar(in->param2, attachedCreature->AICountEnemyNear(in->param1, x, z));
		}
		break;
	case OP_COUNTENEMYAT:
		{
			float x = (float)attachedCreature->CurrentX;
			float z = (float)attachedCreature->CurrentZ;
			if(attachedCreature->CurrentTarget.targ != NULL)
			{
				x = (float)attachedCreature->CurrentTarget.targ->CurrentX;
				z = (float)attachedCreature->CurrentTarget.targ->CurrentZ;
			}
			SetVar(in->param2, attachedCreature->AICountEnemyNear(in->param1, x, z));
		}
		break;
	case OP_HEALTHPERCENT:
		SetVar(in->param1, static_cast<int>(attachedCreature->GetHealthRatio() * 100.0F));
		break;
	case OP_TARGETHEALTHPERCENT:
		{
			int health = 0;
			if(attachedCreature->CurrentTarget.targ != NULL)
				health = static_cast<int>(attachedCreature->CurrentTarget.targ->GetHealthRatio() * 100.0F);
			SetVar(in->param1, health);
		}
		break;
	case OP_SETELAPSEDTIME:
		SetVar(in->param1, static_cast<int>(g_PlatformTime.getElapsedMilliseconds()));
		break;
	case OP_TIMEOFFSET:
		{
			unsigned long offset = g_PlatformTime.getElapsedMilliseconds() - static_cast<unsigned long>(GetVarValue(in->param1));
			SetVar(in->param2, static_cast<int>(offset));
		}
		break;
	case OP_VISUALEFFECT:
		attachedCreature->SendEffect(GetStringTableEntry(in->param1), 0);
		break;
	case OP_VISUALEFFECTT:
		{
		int targID = 0;
		if(attachedCreature->CurrentTarget.targ != NULL)
			targID = attachedCreature->CurrentTarget.targ->CreatureID;
		attachedCreature->SendEffect(GetStringTableEntry(in->param1), targID);
		}
		break;
	case OP_SAY:
		attachedCreature->SendSay(GetStringTableEntry(in->param1));
		break;
	case OP_INSTANCECALL:
		attachedCreature->actInst->ScriptCall(GetStringTableEntry(in->param1));
		break;
	case OP_GETIDLEMOB:
		{
			int creatureDefID = in->param1;
			int creatureID = attachedCreature->AIGetIdleMob(creatureDefID);
			SetVar(in->param2, creatureID);
		}
		break;
	case OP_GETTARGET:
		{
			int creatureID = 0;
			if(attachedCreature->CurrentTarget.targ != NULL)
				creatureID = attachedCreature->CurrentTarget.targ->CreatureID;
			SetVar(in->param1, creatureID);
		}
		break;
	case OP_GETSELF:
		SetVar(in->param1, attachedCreature->CreatureID);
		break;
	case OP_SETOTHERTARGET:
		{
			int creatureID = GetVarValue(in->param1);
			int creatureIDTarg = GetVarValue(in->param2);
			attachedCreature->AIOtherSetTarget(creatureID, creatureIDTarg);
		}
		break;
	case OP_AISCRIPTCALL:
		{
			int creatureID = GetVarValue(in->param1);
			attachedCreature->AIOtherCallLabel(creatureID, GetStringTableEntry(in->param2));
		}
		break;
	case OP_ISTARGETENEMY:
		{
			int result = (attachedCreature->AIIsTargetEnemy() == true) ? 1 : 0;
			SetVar(in->param1, result);
		}
		break;
	case OP_ISTARGETFRIENDLY:
		{
			int result = (attachedCreature->AIIsTargetFriend() == true) ? 1 : 0;
			SetVar(in->param1, result);
		}
		break;
	case OP_SETSPEED:
		attachedCreature->Speed = in->param1;
		break;
	case OP_GETTARGETCDEF:
		{
			int targCDef = 0;
			if(attachedCreature->CurrentTarget.targ != NULL)
				targCDef = attachedCreature->CurrentTarget.targ->CreatureDefID;
			SetVar(in->param1, targCDef);
		}
		break;
	case OP_GETPROPERTY:
		{
			const char *propName = GetStringTableEntry(in->param1);
			SetVar(in->param2, static_cast<int>(attachedCreature->AIGetProperty(propName, false)));
		}
		break;
	case OP_GETTARGETPROPERTY:
		{
			const char *propName = GetStringTableEntry(in->param1);
			SetVar(in->param2, static_cast<int>(attachedCreature->AIGetProperty(propName, true)));
		}
		break;
	case OP_DISPELTARGETPROPERTY:
		{
			const char *propName = GetStringTableEntry(in->param1);
			int sign = in->param2;
			attachedCreature->AIDispelTargetProperty(propName, sign);
		}
		break;
	case OP_RANDOMIZE:
		SetVar(in->param2, randint(1, in->param1));
		break;
	case OP_FINDCDEF:
		{
			int creatureID = 0;
			CreatureInstance *targ = attachedCreature->actInst->GetNPCInstanceByCDefID(in->param1);
			if(targ != NULL)
				creatureID = targ->CreatureID;
			SetVar(in->param2, creatureID);
		}
		break;
	case OP_PLAYSOUND:
		{
			STRINGLIST sub;
			Util::Split(GetStringTableEntry(in->param1), "|", sub);
			while(sub.size() < 2)
			{
				sub.push_back("");
			}
			attachedCreature->SendPlaySound(sub[0].c_str(), sub[1].c_str());
		}
		break;
	case OP_GETBUFFTIER:
		SetVar(in->param2, attachedCreature->AIGetBuffTier(in->param1, false));
		break;
	case OP_GETTARGETBUFFTIER:
		SetVar(in->param2, attachedCreature->AIGetBuffTier(in->param1, true));
		break;
	case OP_TARGETINRANGE:
		SetVar(in->param2, (attachedCreature->InRange_Target((float)in->param1) == true) ? 1 : 0);
		break;
	case OP_GETTARGETRANGE:
		SetVar(in->param1, attachedCreature->AIGetTargetRange());
		break;
	case OP_SETGTAE:
		attachedCreature->AISetGTAE();
		break;
	case OP_GETSPEED:
		{
			int result = 0;
			int creatureID = GetVarValue(in->param1);
			CreatureInstance *targ = ResolveCreatureInstance(creatureID);
			if(targ != NULL)
			{
				result = targ->Speed;
			}
			SetVar(in->param2, result);
		}
		break;
	case OP_CIDISBUSY:
		{
			int result = 0;
			CreatureInstance *targ = ResolveCreatureInstance(GetVarValue(in->param1));
			if(targ != NULL)
			{
				result = (targ->AICheckIfAbilityBusy() == true) ? 1 : 0;
			}
			SetVar(in->param2, result);
		}
		break;
	default:
		g_Logs.script->error("Unidentified op type: %v", in->opCode);
		break;
	}
}
Ejemplo n.º 25
0
int TradeEssenceHandler::handleQuery(SimulatorThread *sim,
		CharacterServerData *pld, SimulatorQuery *query,
		CreatureInstance *creatureInstance) {

	/*  Query: trade.essence
	 Sent when an item is purchased from a chest using tokens or
	 essences, instead of gold.
	 Args : [0] = Creature Instance ID
	 [1] = Item proto of the player's selection.
	 */

	// [0] = Creature Instance ID
	// [1] = Item Proto that was selected ex: "item143548:0:0:0"
	if (query->argCount < 2)
		return 0;

	int CID = atoi(query->args[0].c_str());
	int CDef = sim->ResolveCreatureDef(CID);

	//Since the Essence Shop scanning functions modify the string while searching
	//for tokens, copy it to a buffer here.
	Util::SafeCopy(sim->Aux1, query->args[1].c_str(), sizeof(sim->Aux1));

	EssenceShopItem *iptr = NULL;
	EssenceShop *esptr =
			creatureInstance->actInst->essenceShopList.GetEssenceShopPtr(CDef, sim->Aux1,
					&iptr);
	if (esptr == NULL || iptr == NULL) {
		g_Logs.simulator->error(
				"[%d] Failed to process EssenceShop item [%s] for CreatureDef [%d]",
				sim->InternalID, sim->Aux1, CDef);
		return PrepExt_QueryResponseError(sim->SendBuf, query->ID,
				"Failed to determine item selection.");
	}

	InventoryManager &inv = pld->charPtr->inventory;
	int currentItemCount = inv.GetItemCount(INV_CONTAINER, esptr->EssenceID);
	if (currentItemCount < iptr->EssenceCost) {
		g_Logs.simulator->warn("[%v] Essence requirement for item %v: %v / %v",
				sim->InternalID, esptr->EssenceID, currentItemCount,
				iptr->EssenceCost);
		return PrepExt_QueryResponseString(sim->SendBuf, query->ID,
				"You do not have enough essences.");
	}

	InventorySlot *newItem = pld->charPtr->inventory.AddItem_Ex(INV_CONTAINER,
			iptr->ItemID, 1);
	if (newItem == NULL) {
		pld->charPtr->pendingChanges++;
		int err = pld->charPtr->inventory.LastError;
		if (err == InventoryManager::ERROR_ITEM)
			return PrepExt_QueryResponseString(sim->SendBuf, query->ID,
					"Server error: item does not exist.");
		else if (err == InventoryManager::ERROR_SPACE)
			return PrepExt_QueryResponseString(sim->SendBuf, query->ID,
					"You do not have any free inventory space.");
		else if (err == InventoryManager::ERROR_LIMIT)
			return PrepExt_QueryResponseString(sim->SendBuf, query->ID,
					"You already the maximum amount of these items.");
		else
			return PrepExt_QueryResponseString(sim->SendBuf, query->ID,
					"Server error: undefined error.");
	}

	sim->ActivateActionAbilities(newItem);

	STRINGLIST result;
	result.push_back("OK");
	sprintf(sim->Aux3, "%d", iptr->EssenceCost);
	result.push_back(sim->Aux3);
	int wpos = PrepExt_QueryResponseStringList(sim->SendBuf, query->ID, result);
	wpos += AddItemUpdate(&sim->SendBuf[wpos], sim->Aux3, newItem);

	wpos += inv.RemoveItemsAndUpdate(INV_CONTAINER, esptr->EssenceID,
			iptr->EssenceCost, &sim->SendBuf[wpos]);
	pld->charPtr->pendingChanges++;
	return wpos;
}
Ejemplo n.º 26
0
void SceneryManager::SendPageRequest(const SceneryPageRequest& request, std::list<PacketManager::PACKET_PAIR>& outgoingPackets)
{
	TimeObject to("SceneryManager::SendPageRequest");

	STRINGLIST queryRows;
	Packet data;
	int wpos = 0;
	char idBuf[32];

	GetThread("SceneryManager::HandlePageRequests[page]");

	SceneryPage *page = GetOrCreatePage(request.zone, request.x, request.y);

	if(page == NULL)
	{
		g_Log.AddMessageFormat("[ERROR] SendPageRequest retrieved NULL page");
		
		wpos = PrepExt_QueryResponseNull(prepBuf, request.queryID);
		data.Assign(prepBuf, wpos);
		outgoingPackets.push_back(PacketManager::PACKET_PAIR(request.socket, data));

		ReleaseThread();
		return;
	}

	SceneryPage::SCENERY_IT it;
	for(it = page->mSceneryList.begin(); it != page->mSceneryList.end(); ++it)
	{
		//Build the list of scenery ID strings to form the response to the scenery.list query.
		//No need to save row data unless the query is required.
		if(request.skipQuery == false)
		{
			sprintf(idBuf, "%d", it->second.ID);
			queryRows.push_back(idBuf);
		}
		
		wpos += PrepExt_UpdateScenery(&prepBuf[wpos], &it->second);
		if(wpos > Global::MAX_SEND_CHUNK_SIZE)
		{
			data.Assign(prepBuf, wpos);
			outgoingPackets.push_back(PacketManager::PACKET_PAIR(request.socket, data));
			wpos = 0;
		}
	}
	if(wpos > 0)
	{
		data.Assign(prepBuf, wpos);
		outgoingPackets.push_back(PacketManager::PACKET_PAIR(request.socket, data));
	}

	//Done accessing the scenery data itself, no need to hold the thread any longer.
	//All the remaining stuff is using a resident list of query IDs to form into a response
	//packet.
	ReleaseThread();

	//Now build the query response if the client has requested it.
	if(request.skipQuery == true)
		return;

	//Reset the packet buffer and data.
	wpos = 0;
	data.Clear();

	//Get the size of the response
	int sizeReq = 6;  //Query ID (4 bytes) + row count (2 bytes)
	for(size_t s = 0; s < queryRows.size(); s++)
	{
		sizeReq++;  //1 string per row
		sizeReq += PutStringReq(queryRows[s].c_str());
	}

	wpos += PutByte(&prepBuf[wpos], 1);         //_handleQueryResultMsg
	wpos += PutShort(&prepBuf[wpos], sizeReq);  //Message size

	wpos += PutInteger(&prepBuf[wpos], request.queryID);
	wpos += PutShort(&prepBuf[wpos], queryRows.size());
	for(size_t s = 0; s < queryRows.size(); s++)
	{
		wpos += PutByte(&prepBuf[wpos], 1);
		wpos += PutStringUTF(&prepBuf[wpos], queryRows[s].c_str());
		if(wpos > Global::MAX_SEND_CHUNK_SIZE)
		{
			data.Append(prepBuf, wpos);
			wpos = 0;
		}
	}
	if(wpos > 0)
		data.Append(prepBuf, wpos);

	outgoingPackets.push_back(PacketManager::PACKET_PAIR(request.socket, data));
}
Ejemplo n.º 27
0
int GetInteger(const STRINGLIST &strList, size_t index)
{
	if(index >= strList.size())
		return 0;
	return atoi(strList[index].c_str());
}
Ejemplo n.º 28
0
int QuestActionContainer :: ExecuteSingleCommand(SimulatorThread *caller, ExtendedQuestAction &e)
{
	CreatureInstance *cInst = caller->creatureInst;
	switch(e.opCode)
	{
	case COMMAND_NONE: return 0;
	case CONDITION_HEROISM:
		{
			int value = cInst->css.heroism;
			if(Compare(value, e.param[0], e.param[1]) == true)
				return 0;
			caller->SendInfoMessage("You don't meet the heroism requirement.", INFOMSG_ERROR);
			return -1;
		}
		break;
	case CONDITION_HAS_ITEM:
		{
			int itemID = e.param[0];
			int itemCount = e.param[1];
			int count = caller->pld.charPtr->inventory.GetItemCount(INV_CONTAINER, itemID);
			if(count >= itemCount)
				return 0;
			caller->SendInfoMessage("You don't have the required items in your backpack inventory.", INFOMSG_ERROR);
			return -1;
		}
		break;
	case CONDITION_HAS_QUEST:
		{
			int questID = e.param[0];
			if(caller->pld.charPtr->questJournal.activeQuests.HasQuestID(questID) > -1)
				return 0;
			return -1;
		}
		break;
	case CONDITION_BELOW_LEVEL:
		{
			int maxLevel = e.param[0];
			if(caller->pld.charPtr->cdef.css.level < maxLevel)
				return 0;
			caller->SendInfoMessage("You are too high a level to accept this quest.", INFOMSG_ERROR);
			return -1;
		}
		break;
	case CONDITION_TRANSFORMED:
		{
			int creatureDefID = e.param[0];
			if(cInst->IsTransformed() && cInst->transformCreatureId == creatureDefID)
				return 0;
			CreatureDefinition *def = CreatureDef.GetPointerByCDef(creatureDefID);
			char buffer[128];
			Util::SafeFormat(buffer, sizeof(buffer), "You must be transformed into %s to continue with this quest.", def->css.display_name);
			caller->SendInfoMessage(buffer, INFOMSG_INFO);
			return -1;

		}
	case CONDITION_UNTRANSFORMED:
		{
			if(!cInst->IsTransformed())
				return 0;
			CreatureDefinition *def = CreatureDef.GetPointerByCDef(cInst->transformCreatureId);
			char buffer[128];
			Util::SafeFormat(buffer, sizeof(buffer), "You cannot be transformed into %s to continue with this quest.", def->css.display_name);
			caller->SendInfoMessage(buffer, INFOMSG_INFO);
			return -1;
		}
		break;
	case ACTION_CHANGE_HEROISM:
		cInst->css.heroism += e.param[0];
		cInst->OnHeroismChange();
		break;
	case ACTION_REMOVE_ITEM:
		{
			int itemID = e.param[0];
			int itemCount = e.param[1];
			char buffer[2048];
			int len = caller->pld.charPtr->inventory.RemoveItemsAndUpdate(INV_CONTAINER, itemID, itemCount, buffer);
			if(len > 0)
				caller->AttemptSend(buffer, len);
		}
		break;
	case ACTION_SEND_TEXT:
		caller->SendInfoMessage(e.paramStr.c_str(), INFOMSG_INFO);
		break;
	case ACTION_PLAY_SOUND:
		{
			STRINGLIST sub;
			Util::Split(e.paramStr, "|", sub);
			while(sub.size() < 2)
			{
				sub.push_back("");
			}
			caller->SendPlaySound(sub[0].c_str(), sub[1].c_str());
		}
		break;
	case ACTION_BROADCAST:
		{
			char buffer[128];
			Util::SafeFormat(buffer, sizeof(buffer), e.paramStr.c_str(), cInst->css.display_name);
			g_SimulatorManager.BroadcastMessage(buffer);
		}
		break;
	case ACTION_JOIN_GUILD:
		{
			int guildDefID = e.param[0];
			GuildDefinition *gDef = g_GuildManager.GetGuildDefinition(guildDefID);
			if(gDef == NULL)
				caller->SendInfoMessage("Hrmph. This guild does not exist, please report a bug!", INFOMSG_INFO);
			else {
				caller->SendInfoMessage("Joining guild ..", INFOMSG_INFO);
				caller->JoinGuild(gDef, 0);
				char buffer[64];
				Util::SafeFormat(buffer, sizeof(buffer), "You have joined %s", gDef->defName.c_str());
				caller->SendInfoMessage(buffer, INFOMSG_INFO);
			}
		}
		break;
	case ACTION_TRANSFORM:
		{
			int creatureDefID = e.param[0];
			g_Logs.data->debug("Transform: %v", creatureDefID);
			cInst->CAF_Transform(creatureDefID, 0, -1);
		}
		break;
	case ACTION_UNTRANSFORM:
		{
			g_Logs.data->debug("Untransform");
			cInst->CAF_Untransform();
		}
		break;
	default:
		return -1;
	}
	return 0;
}
Ejemplo n.º 29
0
void ItemDef :: ProcessParams(void)
{
	if(Params.size() == 0)
		return;
	
	std::string newFlavorText;
	char buffer[256];

	STRINGLIST datapairs;
	STRINGLIST keyvalue;
	Util::Split(Params, "&", datapairs);
	for(size_t i = 0; i < datapairs.size(); i++)
	{
		Util::Split(datapairs[i], "=", keyvalue);
		if(keyvalue.size() >= 2)
		{
			int index = GetStatIndexByName(keyvalue[0].c_str());
			if(index >= 0)
			{
				int statID = StatList[index].ID;
				float value = static_cast<float>(atof(keyvalue[1].c_str()));

				const char *formatStr = NULL;
				switch(statID)
				{
				case STAT::MOD_MELEE_TO_CRIT: formatStr = "+%g%% Physical Critical Chance"; value /= 10.0F; break;
				case STAT::MOD_MAGIC_TO_CRIT: formatStr = "+%g%% Magic Critical Chance"; value /= 10.0F; break;
				case STAT::BASE_BLOCK: formatStr = "+%g%% Block Chance", value /= 10.0F; break;
				case STAT::BASE_PARRY: formatStr = "+%g%% Parry Chance", value /= 10.0F; break;
				case STAT::BASE_DODGE: formatStr = "+%g%% Dodge Chance", value /= 10.0F; break;
				case STAT::MOD_MOVEMENT: formatStr = "+%g%% Movement Speed"; break;  //INT
				case STAT::EXPERIENCE_GAIN_RATE: formatStr = "+%g%% Experience Gain"; break;  //INT
				case STAT::MELEE_ATTACK_SPEED: formatStr = "+%g%% Increased Attack Speed", value /= 10.0F; break;
				case STAT::MAGIC_ATTACK_SPEED: formatStr = "+%g%% Increased Cast Rate", value /= 10.0F; break;
				case STAT::DMG_MOD_FIRE: formatStr = "+%g%% Fire Specialization", value /= 10.0F; break;
				case STAT::DMG_MOD_FROST: formatStr = "+%g%% Frost Specialization", value /= 10.0F; break;
				case STAT::DMG_MOD_MYSTIC: formatStr = "+%g%% Mystic Specialization", value /= 10.0F; break;
				case STAT::DMG_MOD_DEATH: formatStr = "+%g%% Death Specialization", value /= 10.0F; break;
				case STAT::BASE_HEALING: formatStr = "+%g%% Healing Specialization", value /= 10.0F; break;
				case STAT::CASTING_SETBACK_CHANCE: formatStr = "%g%% Casting Setback Chance", value /= 10.0F; break;
				case STAT::CHANNELING_BREAK_CHANCE: formatStr = "%g%% Channel Break Chance", value /= 10.0F; break;
				case STAT::MOD_HEALTH_REGEN: formatStr = "+%g Hitpoint Regeneration", value;  break;  //INT
				}
				if(formatStr != NULL)
				{
					Util::SafeFormat(buffer, sizeof(buffer), formatStr, value);
					if(newFlavorText.size() > 0)
						newFlavorText.append("<br>");
					newFlavorText.append(buffer);
				}
			}
		}
	}
	if(newFlavorText.size() > 0)
	{
		if(mFlavorText.size() > 0)
			mFlavorText.append("<br>");

		mFlavorText.append("</i>");
		mFlavorText.append(newFlavorText);
	}
}