Example #1
0
CString gs2ToGameMonkey(CString gs2Code)
{
	CString prefix;
	CString parsedCode;
	std::vector<CString> clean = gs2Code.tokenize("\xa7");
	int bracketCount = 0;
	for (std::vector<CString>::iterator i = clean.begin(); i != clean.end(); ++i)
	{
		CString line = *i;

		//Functions
		if (line.readChars(CString("function").length()) == "function")
		{
			CString fullFunction = line.subString(CString("function").length()+1);
			CString functionName = fullFunction.readString("(");
			CString prefix; 
			//this. or global?
			prefix << "." << functionName << " = function" << fullFunction.subString(functionName.length());
			parsedCode << prefix;
			bracketCount = 1;
		}
		else if (line.find("{") >= 0)
		{
			bracketCount++;
			parsedCode << line;
		}
		//Make sure this is ; on the end of }
		else if (line.find("}") >= 0)
		{
			bracketCount--;

			if (bracketCount > 1) 
			{
				parsedCode << line;
				continue;
			}

			CString semi;
			while(line.subString(line.find("}")+1,1) != ";")
			{
				if (line.subString(line.find("}")+1,1) != ";")
				{
					semi << line.subString(0,line.find("}")+1) << ";" << line.subString(line.find("}")+1);
					line = semi;
				}
			}
			if (semi.isEmpty()) 
				parsedCode << "};";
			else 
				parsedCode << semi;
		}
		else if(line.find("SPC") >= 0)
		{
			line.replaceAllI("SPC"," + \" \" + ");
			parsedCode << line;
		}
		else parsedCode << line;
	}
	return parsedCode;
}
Example #2
0
bool CSettings::loadFile(const CString& pStr)
{
    boost::recursive_mutex::scoped_lock lock(*m_preventChange);

    // definitions
    CString fileData;

    // Clear Keys
    clear();

    // Load File
    if (!fileData.load(pStr))
    {
        opened = false;
        return false;
    }

    // Parse Data
    fileData.removeAllI("\r");
    strList = fileData.tokenize("\n");
    for (unsigned int i = 0; i < strList.size(); i++)
    {
        // Strip out comments.
        int comment_pos = strList[i].find("#");
        if (comment_pos != -1)
            strList[i].removeI(comment_pos);

        // Skip invalid or blank lines.
        if (strList[i].isEmpty() || strList[i].find(strSep) == -1)
            continue;

        // Tokenize Line && Trim && Lowercase Key Name
        std::vector<CString> line = strList[i].tokenize(strSep);
        line[0].toLowerI();
        if (line.size() == 1) continue;

        // Fix problem involving settings with an = in the value.
        if (line.size() > 2)
        {
            for (unsigned int j = 2; j < line.size(); ++j)
                line[1] << "=" << line[j];
        }

        // Trim
        for (unsigned int j = 0; j < line.size(); j++)
            line[j].trimI();

        // Create Key
        CKey *key;
        if ((key = getKey(line[0])) == 0)
            keys.push_back(new CKey(line[0], line[1]));
        else
            key->value << "," << line[1];
    }

    opened = true;
    return true;
}
Example #3
0
bool TMap::loadBigMap(const CString& pFileName, TServer* pServer)
{
	// Get the appropriate filesystem.
	CFileSystem* fileSystem = pServer->getFileSystem();
	if (pServer->getSettings()->getBool("nofoldersconfig", false) == false)
		fileSystem = pServer->getFileSystem(FS_FILE);

	CString fileName = fileSystem->find(pFileName);
	modTime = fileSystem->getModTime(pFileName);
	mapName = pFileName;

	// Make sure the file exists.
	if (fileName.length() == 0) return false;

	// Load the gmap.
	std::vector<CString> fileData = CString::loadToken(fileName);

	// Parse it.
	std::vector<CString>::iterator i = fileData.begin();
	levels.clear();

	int bmapx = 0;
	int bmapy = 0;
	while (i != fileData.end())
	{
		CString line = i->removeAll("\r").trim();
		if (line.length() == 0) { ++i; continue; }

		// Untokenize the level names and put them into a vector for easy loading.
		line.guntokenizeI();
		std::vector<CString> names = line.tokenize("\n");
		for (std::vector<CString>::iterator j = names.begin(); j != names.end(); ++j)
		{
			// Check for blank levels.
			if (*j == "\r")
			{
				++bmapx;
				continue;
			}

			// Save the level into the map.
			SMapLevel lvl(bmapx++, bmapy);
			levels[*j] = lvl;
		}

		if (bmapx > width) width = bmapx;
		bmapx = 0;
		++bmapy;
		++i;
	}
	height = bmapy;

	return true;
}
Example #4
0
bool TAccount::loadAccount(const CString& pAccount, bool ignoreNickname)
{
	// Just in case this account was loaded offline through RC.
	accountName = pAccount;

	bool loadedFromDefault = false;
	CFileSystem* accfs = server->getAccountsFileSystem();
	std::vector<CString> fileData;

	CString accountText = server->getPluginManager().LoadAccount(pAccount);
	if (!accountText.isEmpty())
		fileData = accountText.tokenize("\n");
	else
	{
		// Find the account in the file system.
		CString accpath(accfs->findi(CString() << pAccount << ".txt"));
		if (accpath.length() == 0)
		{
			accpath = CString() << server->getServerPath() << "accounts/defaultaccount.txt";
			CFileSystem::fixPathSeparators(&accpath);
			loadedFromDefault = true;
		}

		// Load file.
		fileData = CString::loadToken(accpath, "\n");
		if (fileData.size() == 0 || fileData[0].trim() != "GRACC001")
			return false;
	}

	// Clear Lists
	for (int i = 0; i < 30; ++i) attrList[i].clear();
	chestList.clear();
	mFlagList.clear();
	folderList.clear();
	weaponList.clear();

	// Parse File
	for (unsigned int i = 0; i < fileData.size(); i++)
	{
		// Trim Line
		fileData[i].trimI();

		// Declare Variables;
		CString section, val;
		int sep;

		// Seperate Section & Value
		sep = fileData[i].find(' ');
		section = fileData[i].subString(0, sep);
		if (sep != -1)
			val = fileData[i].subString(sep + 1);

		if (section == "NAME") continue;
		else if (section == "NICK") { if (!ignoreNickname) nickName = val; }
		else if (section == "COMMUNITYNAME") communityName = val;
		else if (section == "LEVEL") levelName = val;
		else if (section == "X") { x = (float)strtofloat(val); x2 = (int)(x * 16); }
		else if (section == "Y") { y = (float)strtofloat(val); y2 = (int)(y * 16); }
		else if (section == "Z") { z = (float)strtofloat(val); z2 = (int)(z * 16); }
		else if (section == "MAXHP") maxPower = (int)strtoint(val);
		else if (section == "HP") power = (float)strtofloat(val);
		else if (section == "RUPEES") gralatc = strtoint(val);
		else if (section == "ANI") gani = val;
		else if (section == "ARROWS") arrowc = strtoint(val);
		else if (section == "BOMBS") bombc = strtoint(val);
		else if (section == "GLOVEP") glovePower = strtoint(val);
		else if (section == "SHIELDP") shieldPower = strtoint(val);
		else if (section == "SWORDP") swordPower = strtoint(val);
		else if (section == "BOWP") bowPower = strtoint(val);
		else if (section == "BOW") bowImage = val;
		else if (section == "HEAD") headImg = val;
		else if (section == "BODY") bodyImg = val;
		else if (section == "SWORD") swordImg = val;
		else if (section == "SHIELD") shieldImg = val;
		else if (section == "COLORS") { std::vector<CString> t = val.tokenize(","); for (int i = 0; i < (int)t.size() && i < 5; i++) colors[i] = (unsigned char)strtoint(t[i]); }
		else if (section == "SPRITE") sprite = strtoint(val);
		else if (section == "STATUS") status = strtoint(val);
		else if (section == "MP") mp = strtoint(val);
		else if (section == "AP") ap = strtoint(val);
		else if (section == "APCOUNTER") apCounter = strtoint(val);
		else if (section == "ONSECS") onlineTime = strtoint(val);
		else if (section == "IP") { if (accountIp == 0) accountIp = strtolong(val); }
		else if (section == "LANGUAGE") { language = val; if (language.isEmpty()) language = "English"; }
		else if (section == "KILLS") kills = strtoint(val);
		else if (section == "DEATHS") deaths = strtoint(val);
		else if (section == "RATING") rating = (float)strtofloat(val);
		else if (section == "DEVIATION") deviation = (float)strtofloat(val);
		else if (section == "OLDDEVIATION") oldDeviation = (float)strtofloat(val);
		else if (section == "LASTSPARTIME") lastSparTime = strtolong(val);
		else if (section == "FLAG") setFlag(val);
		else if (section == "ATTR1") attrList[0] = val;
		else if (section == "ATTR2") attrList[1] = val;
		else if (section == "ATTR3") attrList[2] = val;
		else if (section == "ATTR4") attrList[3] = val;
		else if (section == "ATTR5") attrList[4] = val;
		else if (section == "ATTR6") attrList[5] = val;
		else if (section == "ATTR7") attrList[6] = val;
		else if (section == "ATTR8") attrList[7] = val;
		else if (section == "ATTR9") attrList[8] = val;
		else if (section == "ATTR10") attrList[9] = val;
		else if (section == "ATTR11") attrList[10] = val;
		else if (section == "ATTR12") attrList[11] = val;
		else if (section == "ATTR13") attrList[12] = val;
		else if (section == "ATTR14") attrList[13] = val;
		else if (section == "ATTR15") attrList[14] = val;
		else if (section == "ATTR16") attrList[15] = val;
		else if (section == "ATTR17") attrList[16] = val;
		else if (section == "ATTR18") attrList[17] = val;
		else if (section == "ATTR19") attrList[18] = val;
		else if (section == "ATTR20") attrList[19] = val;
		else if (section == "ATTR21") attrList[20] = val;
		else if (section == "ATTR22") attrList[21] = val;
		else if (section == "ATTR23") attrList[22] = val;
		else if (section == "ATTR24") attrList[23] = val;
		else if (section == "ATTR25") attrList[24] = val;
		else if (section == "ATTR26") attrList[25] = val;
		else if (section == "ATTR27") attrList[26] = val;
		else if (section == "ATTR28") attrList[27] = val;
		else if (section == "ATTR29") attrList[28] = val;
		else if (section == "ATTR30") attrList[29] = val;
		else if (section == "WEAPON") weaponList.push_back(val);
		else if (section == "CHEST") chestList.push_back(val);
		else if (section == "BANNED") isBanned = (strtoint(val) == 0 ? false : true);
		else if (section == "BANREASON") banReason = val;
		else if (section == "BANLENGTH") banLength = val;
		else if (section == "COMMENTS") accountComments = val;
		else if (section == "EMAIL") email = val;
		else if (section == "LOCALRIGHTS") adminRights = strtoint(val);
		else if (section == "IPRANGE") adminIp = val;
		else if (section == "FOLDERRIGHT") folderList.push_back(val);
		else if (section == "LASTFOLDER") lastFolder = val;
	}

	// Comment out this line if you are actually going to use community names.
	communityName = accountName;

	// If we loaded from the default account, save our account now and add it to the file system.
	if (loadedFromDefault)
	{
		saveAccount();
		accfs->addFile(CString() << "accounts/" << pAccount << ".txt");
	}

	return true;
}
Example #5
0
/*
	TAccount: Account Management
*/
bool TAccount::meetsConditions( CString fileName, CString conditions )
{
	const char* conditional[] = { ">=", "<=", "!=", "=", ">", "<" };

	// Load and check if the file is valid.
	std::vector<CString> file;
	file = CString::loadToken(fileName, "\n", true);
	if (file.size() == 0 || (file.size() != 0 && file[0] != "GRACC001"))
		return false;

	// Load the conditions into a string list.
	std::vector<CString> cond;
	conditions.removeAllI("'");
	conditions.replaceAllI("%", "*");
	cond = conditions.tokenize(",");
	bool* conditionsMet = new bool[cond.size()];
	memset((void*)conditionsMet, 0, sizeof(bool) * cond.size());

	// Go through each line of the loaded file.
	for (std::vector<CString>::iterator i = file.begin(); i != file.end(); ++i)
	{
		int sep = (*i).find(' ');
		CString section = (*i).subString(0, sep);
		CString val = (*i).subString(sep + 1).removeAll("\r");
		section.trimI();
		val.trimI();

		// Check each line against the conditions specified.
		for (unsigned int j = 0; j < cond.size(); ++j)
		{
			int cond_num = -1;

			// Read out the name and value.
			cond[j].setRead(0);

			// Find out what conditional we are using.
			for (int k = 0; k < 6; ++k)
			{
				if (cond[j].find(conditional[k]) != -1)
				{
					cond_num = k;
					k = 6;
				}
			}
			if (cond_num == -1) continue;

			CString cname = cond[j].readString(conditional[cond_num]);
			CString cvalue = cond[j].readString("");
			cname.trimI();
			cvalue.trimI();
			cond[j].setRead(0);

			// Now, do a case-insensitive comparison of the section name.
#ifdef WIN32
			if (_stricmp(section.text(), cname.text()) == 0)
#else
			if (strcasecmp(section.text(), cname.text()) == 0)
#endif
			{
				switch (cond_num)
				{
					case 0:
					case 1:
					{
						// 0: >=
						// 1: <=
						// Check if it is a number.  If so, do a number comparison.
						bool condmet = false;
						if (val.isNumber())
						{
							double vNum[2] = { atof(val.text()), atof(cvalue.text()) };
							if (((cond_num == 1) ? (vNum[0] <= vNum[1]) : (vNum[0] >= vNum[1])))
							{
								conditionsMet[j] = true;
								condmet = true;
							}
						}
						else
						{
							// If not a number, do a string comparison.
							int ret = strcmp(val.text(), cvalue.text());
							if (((cond_num == 1) ? (ret <= 0) : (ret >= 0)))
							{
								conditionsMet[j] = true;
								condmet = true;
							}
						}

						// No conditions met means we see if we can fail.
						if (condmet == false)
						{
							CString cnameUp = cname.toUpper();
							if (!(cnameUp == "CHEST" || cnameUp == "WEAPON" ||
								cnameUp == "FLAG" || cnameUp == "FOLDERRIGHT"))
								goto condAbort;
						}
						break;
					}

					case 4:
					case 5:
					{
						// 4: >
						// 5: <
						bool condmet = false;
						if (val.isNumber())
						{
							double vNum[2] = { atof(val.text()), atof(cvalue.text()) };
							if (((cond_num == 5) ? (vNum[0] < vNum[1]) : (vNum[0] > vNum[1])))
							{
								conditionsMet[j] = true;
								condmet = true;
							}
						}
						else
						{
							int ret = strcmp(val.text(), cvalue.text());
							if (((cond_num == 5) ? (ret < 0) : (ret > 0)))
							{
								conditionsMet[j] = true;
								condmet = true;
							}
						}

						if (condmet == false)
						{
							CString cnameUp = cname.toUpper();
							if (!(cnameUp == "CHEST" || cnameUp == "WEAPON" ||
								cnameUp == "FLAG" || cnameUp == "FOLDERRIGHT"))
								goto condAbort;
						}
						break;
					}

					case 2:
					{
						// 2: !=
						// If we find a match, return false.
						if (val.isNumber())
						{
							double vNum[2] = { atof(val.text()), atof(cvalue.text()) };
							if (vNum[0] == vNum[1]) goto condAbort;
							conditionsMet[j] = true;
						}
						else
						{
							if (val.match(cvalue.text()) == true) goto condAbort;
							conditionsMet[j] = true;
						}
						break;
					}

					case 3:
					default:
					{
						// 0 - equals
						// If it returns false, don't include this account in the search.
						bool condmet = false;
						if (val.isNumber())
						{
							double vNum[2] = { atof(val.text()), atof(cvalue.text()) };
							if (vNum[0] == vNum[1])
							{
								conditionsMet[j] = true;
								condmet = true;
							}
						}
						else
						{
							if (val.match(cvalue.text()) == true)
							{
								conditionsMet[j] = true;
								condmet = true;
							}
						}

						if (condmet == false)
						{
							CString cnameUp = cname.toUpper();
							if (!(cnameUp == "CHEST" || cnameUp == "WEAPON" ||
								cnameUp == "FLAG" || cnameUp == "FOLDERRIGHT"))
								goto condAbort;
						}
						break;
					}
				}
			}
		}
	}

	// Check if all the conditions were met.
	for (unsigned int i = 0; i < cond.size(); ++i)
		if (conditionsMet[i] == false) goto condAbort;

	// Clean up.
	delete [] conditionsMet;
	return true;

condAbort:
	delete [] conditionsMet;
	return false;
}
Example #6
0
// -- Function: Load Weapon -- //
TWeapon * TWeapon::loadWeapon(const CString& pWeapon, TServer *server)
{
	// File Path
	CString fileName = server->getServerPath() << "weapons/" << pWeapon;

	// Load File
	CString fileData;
	fileData.load(fileName);
	fileData.removeAllI("\r");

	// Grab some information.
	bool has_script = (fileData.find("SCRIPT") != -1 ? true : false);
	bool has_scriptend = (fileData.find("SCRIPTEND") != -1 ? true : false);
	bool found_scriptend = false;

	// Parse into lines.
	std::vector<CString> fileLines = fileData.tokenize("\n");
	if (fileLines.size() == 0 || fileLines[0].trim() != "GRAWP001")
		return 0;

	// Definitions
	CString weaponImage, weaponName, weaponScript;
	std::vector<std::pair<CString, CString> > byteCode;

	// Parse File
	std::vector<CString>::iterator i = fileLines.begin();
	while (i != fileLines.end())
	{
		// Find Command
		CString curCommand = i->readString();

		// Parse Line
		if (curCommand == "REALNAME")
			weaponName = i->readString("");
		else if (curCommand == "IMAGE")
			weaponImage = i->readString("");
		else if (curCommand == "BYTECODE")
		{
			CString fname = i->readString("");
			CString bytecode;
			bytecode.load(server->getServerPath() << "weapon_bytecode/" << fname);

			if (!bytecode.isEmpty())
				byteCode.push_back(std::pair<CString, CString>(fname, bytecode));
		}
		else if (curCommand == "SCRIPT")
		{
			++i;
			while (i != fileLines.end())
			{
				if (*i == "SCRIPTEND")
				{
					found_scriptend = true;
					break;
				}
				weaponScript << *i << "\xa7";
				++i;
			}
		}
		if (i != fileLines.end()) ++i;
	}

	// Valid Weapon Name?
	if (weaponName.isEmpty())
		return 0;

	// Give a warning if our weapon was malformed.
	if (has_scriptend && !found_scriptend)
	{
		server->getServerLog().out("[%s] WARNING: Weapon %s is malformed.\n", server->getName().text(), weaponName.text());
		server->getServerLog().out("[%s] SCRIPTEND needs to be on its own line.\n", server->getName().text());
	}

	// Give a warning if both a script and a bytecode was found.
	if (!weaponScript.isEmpty() && !byteCode.empty())
		server->getServerLog().out("[%s] WARNING: Weapon %s includes both script and bytecode.  Using bytecode.\n", server->getName().text(), weaponName.text());

	TWeapon* ret = new TWeapon(server, weaponName, weaponImage, weaponScript, 0);
	if (byteCode.size() != 0)
		ret->mByteCode = byteCode;

	return ret;
}
Example #7
0
bool TMap::loadGMap(const CString& pFileName, TServer* pServer)
{
	// Get the appropriate filesystem.
	CFileSystem* fileSystem = pServer->getFileSystem();
	if (pServer->getSettings()->getBool("nofoldersconfig", false) == false)
		fileSystem = pServer->getFileSystem(FS_LEVEL);

	CString fileName = fileSystem->find(pFileName);
	modTime = fileSystem->getModTime(pFileName);
	mapName = pFileName;

	// Make sure the file exists.
	if (fileName.length() == 0) return false;

	// Load the gmap.
	std::vector<CString> fileData = CString::loadToken(fileName);

	// Parse it.
	for (std::vector<CString>::iterator i = fileData.begin(); i != fileData.end(); ++i)
	{
		// Tokenize
		std::vector<CString> curLine = i->removeAll("\r").tokenize();
		if (curLine.size() < 1)
			continue;

		// Parse Each Type
		if (curLine[0] == "WIDTH")
		{
			if (curLine.size() != 2)
				continue;

			width = strtoint(curLine[1]);
		}
		else if (curLine[0] == "HEIGHT")
		{
			if (curLine.size() != 2)
				continue;

			height = strtoint(curLine[1]);
		}
		else if (curLine[0] == "GENERATED")
		{
			if (curLine.size() != 2)
				continue;

			// Not really needed.
		}
		else if (curLine[0] == "LEVELNAMES")
		{
			levels.clear();

			++i;
			int gmapx = 0;
			int gmapy = 0;
			while (i != fileData.end())
			{
				CString line = i->removeAll("\r").trim();
				if (line.length() == 0) { ++i; continue; }
				if (line == "LEVELNAMESEND") break;

				// Untokenize the level names and put them into a vector for easy loading.
				line.guntokenizeI();
				std::vector<CString> names = line.tokenize("\n");
				for (std::vector<CString>::iterator j = names.begin(); j != names.end(); ++j)
				{
					// Check for blank levels.
					if (*j == "\r")
					{
						++gmapx;
						continue;
					}

					// Save the level into the map.
					SMapLevel lvl(gmapx++, gmapy);
					levels[*j] = lvl;
				}

				gmapx = 0;
				++gmapy;
				++i;
			}
		}
		else if (curLine[0] == "MAPIMG")
		{
			if (curLine.size() != 2)
				continue;
			
			mapImage = curLine[1];
		}
		else if (curLine[0] == "MINIMAPIMG")
		{
			if (curLine.size() != 2)
				continue;

			miniMapImage = curLine[1];
		}
		else if (curLine[0] == "NOAUTOMAPPING")
		{
			// Clientside only.
		}
		else if (curLine[0] == "LOADFULLMAP")
		{
			// Not supported currently.
		}
		else if (curLine[0] == "LOADATSTART")
		{
			// Not supported currently.
			++i;
			while (i != fileData.end())
			{
				CString line = i->removeAll("\r");
				if (line == "LOADATSTARTEND") break;
			}
		}
		// TODO: 3D settings maybe?
	}

	return true;
}