当前位置: 首页>>代码示例>>C++>>正文


C++ CStringList::count方法代码示例

本文整理汇总了C++中CStringList::count方法的典型用法代码示例。如果您正苦于以下问题:C++ CStringList::count方法的具体用法?C++ CStringList::count怎么用?C++ CStringList::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CStringList的用法示例。


在下文中一共展示了CStringList::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadWeapons

bool loadWeapons(char* pFile)
{
	CStringList weaponData;
	if(!weaponData.load(pFile))
		return false;

	weaponList.clear();
	for(int i = 0; i < weaponData.count(); i++)
	{
		CString word = weaponData[i].readString(" ");
		if(word == "NEWWEAPON")
		{
			CStringList parameters;
			parameters.load(weaponData[i].text() + word.length() + 1, ",");
			if(parameters.count() <= 2)
				continue;

			CWeapon* weapon = new CWeapon;
			weapon->name = parameters[0].trim();

			// Special case with the weapon image.
			if ( parameters[1].trim() == "-" ) weapon->image = CString();
			else weapon->image = parameters[1].trim();

			weapon->modTime = (long long)atol(parameters[2].trim().text());
			weapon->code = "";
			for(i++; i < weaponData.count() && weaponData[i] != "ENDWEAPON"; i++)
				weapon->code << weaponData[i] << "\xa7";
			weaponList.add(weapon);
		}
	}
	return true;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:33,代码来源:main.cpp

示例2: addNewNpc

int CLevel::addNewNpc(CString& pImage, CString& pCodeFile, float pX, float pY)
{
	CStringList codeData;
	CString code;
	char* dataFile = getDataFile(pCodeFile.text());
	if(!strlen(dataFile))
		return 0;
	if(!codeData.load(dataFile))
		return 0;
	for(int i = 0; i < codeData.count(); i++)
		code << codeData[i] << "\xa7";

	// Create the new NPC.  Do this before parsing the join commands.
	// The CNpc constructor will remove all comments.
	CString code2;
	CNpc* npc = new CNpc( pImage, code, pX, pY, this, false );

	// Now filter out the join commands.
	CStringList npcData;
	npcData.load( npc->clientCode.text(), "\xa7" );
	for ( int j = 0; j < npcData.count(); ++j )
		code2 << processNpcLine( npcData[j] ) << "\xa7";
	npc->clientCode = code2;

	// Now, add all the joined files to the code.
	if ( joinList.count() > 0 )
	{
		CString* file = 0;
		while ( (file = (CString*)joinList[0]) != 0 )
		{
			// Load the source file into memory.
			CString dataFile = getDataFile(file->text());
			if(dataFile.length())
			{
				// Append to the end of the script.
				CString retVal;
				retVal.load(dataFile.text());
				retVal.replaceAll("\r\n", "\xa7");
				retVal.replaceAll("\n", "\xa7");
				npc->clientCode << retVal << "\xa7";
			}
			delete (CString*)joinList[0];
			joinList.remove(0);
		}
	}
	joinList.clear();
	npcs.add(npc);

	for(int i = 0; i < players.count(); i++)
	{
		CPlayer* player = (CPlayer*)players[i];
		player->sendPacket(CPacket() << (char)SNPCPROPS << (int)npc->id <<
			npc->getPropertyList(0));
	}

	return npc->id;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:57,代码来源:CLevel.cpp

示例3: isValidFile

bool isValidFile(CBuffer& file, int type)
{
	for ( int i = 0; i < folderConfig.count(); ++i )
	{
		folderConfig[i].setRead(0);
		CString ftype( folderConfig[i].readString( " " ) );
		CString fmask = CBuffer() << dataDir <<
			CBuffer(folderConfig[i].readString( "" )).trim().text();
		folderConfig[i].setRead(0);

		switch ( type )
		{
			case 11:	// HEADGIF
				if ( ftype == "head" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 35:	// BODYIMG
				if ( ftype == "body" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 8:		// SWORDPOWER
				if ( ftype == "sword" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 9:		// SHIELDPOWER
				if ( ftype == "shield" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case 1:		// level
				if ( ftype == "level" )
					if ( file.match( fmask.text() ) )
						return true;
			break;

			case -1:	// Any
				if ( file.match( fmask.text() ) )
					return true;
			break;

			default:
			case 0:		// file
				if ( ftype == "file" )
					if ( file.match( fmask.text() ) )
						return true;
			break;
		}
	}

	return false;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:58,代码来源:main.cpp

示例4: loadServerMessage

void loadServerMessage()
{
	CStringList fileData;
	if(!fileData.load("servermessage.html"))
		return;

	serverMessage.clear();
	for(int i = 0; i < fileData.count(); i++)
		serverMessage << fileData[i] << " ";
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:10,代码来源:main.cpp

示例5: loadNpcs

void CLevel::loadNpcs(CPacket& levelData)
{
	while(levelData.bytesLeft())
	{
		CPacket line;
		line << levelData.readLine();
		if(line.length() < 1 || line == "#")
			break;

		float x = line.readByte1();
		float y = line.readByte1();
		CString image = line.readString("#");
		CString code = line.readChars(line.bytesLeft());

		// Create the new NPC.  Do this before parsing the join commands.
		// The CNpc constructor will remove all comments.
		CString code2;
		CNpc* jnpc = new CNpc( image, code, x, y, this, true );

		// Now filter out the join commands.
		CStringList npcData;
		npcData.load( jnpc->clientCode.text(), "\xa7" );
		for ( int j = 0; j < npcData.count(); ++j )
			code2 << processNpcLine( npcData[j] ) << "\xa7";
		jnpc->clientCode = code2;

		// Now, add all the joined files to the code.
		if ( joinList.count() > 0 )
		{
			CString* file = 0;
			while ( (file = (CString*)joinList[0]) != 0 )
			{
				// Load the source file into memory.
				CString dataFile = getDataFile(file->text());
				if(dataFile.length())
				{
					// Append to the end of the script.
					CString retVal;
					retVal.load(dataFile.text());
					retVal.replaceAll("\r\n", "\xa7");
					retVal.replaceAll("\n", "\xa7");
					jnpc->clientCode << retVal << "\xa7";
				}
				delete (CString*)joinList[0];
				joinList.remove(0);
			}
		}
		joinList.clear();
		npcs.add( jnpc );
	}
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:51,代码来源:CLevel.cpp

示例6: isIpBanned

bool isIpBanned(CString& pIp)
{
	CStringList ipList;
	if(!ipList.load("ipbans.txt"))
		return false;

	for(int i = 0; i < ipList.count(); i++)
	{
		if(!ipList[i].length() || ipList[i][0] == '#')
			continue;
		if(pIp.match(ipList[i].text()))
			return true;
	}
	return false;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:15,代码来源:main.cpp

示例7: getSubDirs

void getSubDirs()
{
	// If foldersconfig.txt is turned off, use the old style.
	if ( noFoldersConfig )
	{
		subDirs.clear();
		getSubDirs_os( dataDir.text() );
		if ( shareFolder.length() > 1 )
			getSubDirs_os( shareFolder.text() );
	}
	else
	{
		subDirs.clear();
		subDirs.add(dataDir);
		for (int i = 0; i < folderConfig.count(); i++)
		{
			if (folderConfig[i][0] == '#')
				continue;

			CBuffer fmask, fname;

			// Get rid of all \t and replace with ' '.
			// Also, trim.
			folderConfig[i].replaceAll( "\t", " " );

			// Read past the identifier.
			folderConfig[i].setRead(folderConfig[i].find(' '));

			// Read the mask
			CBuffer temp = folderConfig[i].readString( "" );
			temp.trim();

			// If it starts with ./, use . instead of world/ as the search dir.
			if ( temp.find( "./" ) == 0 )
				fmask = CBuffer() << programDir << temp;
			else
				fmask = CBuffer() << dataDir << temp;

			// Pull off the file mask and only save the directory.
			fname = CBuffer() << fmask.readChars(fmask.findl(fSep[0])) << fSep;
			if (subDirs.find(fname) == -1)
				subDirs.add(fname);
		}
	}
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:45,代码来源:main.cpp

示例8: getDataFile

char* getDataFile(char* pFile)
{
	static char path[260];
	FILE* file;
	for(int i = 0; i < subDirs.count(); i++)
	{
		strncpy(path, subDirs[i].text(), sizeof(path));
		strncat(path, pFile, sizeof(path));
		if((file = fopen(path, "r")) != 0)
		{
			fclose(file);
			return path;
		}
	}

	path[0] = 0;
	return path;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:18,代码来源:main.cpp

示例9: listFiles

CPacket listFiles(char *pDir, char *pRights)
{
	CPacket retVal;
	CStringList files;
	struct stat fileStat;
	getSubFiles(pDir, files);

	for (int i = 0; i < files.count(); i++)
	{
		CPacket dir;
		CString fullName;
		fullName << pDir << files[i];
		stat(fullName.text(), &fileStat);
		dir << (char)files[i].length() << files[i] << (char)strlen(pRights) << pRights << (long long)fileStat.st_size << (long long)fileStat.st_mtime;
		retVal << " " << (char)dir.length() << dir;
	}

	return retVal;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:19,代码来源:main.cpp

示例10: updateFile

bool updateFile(char *pFile)
{
	char *ext = strrchr(pFile, '.');
	CString file = pFile;

	if (strcmp(ext, ".graal") == 0 || strcmp(ext, ".nw") == 0 || strcmp(ext, ".zelda") == 0)
		CLevel::updateLevel(file);
	else if (strcmp(pFile, "rchelp.txt") == 0)
		RCHelpMessage.load(pFile);
	else if (strcmp(pFile, "rcmessage.txt") == 0)
		RCMessage.load(pFile);
	else if (strcmp(pFile, "serverflags.txt") == 0)
		serverFlags.load(pFile);
	else if (strcmp(pFile, "servermessage.html") == 0)
		loadServerMessage();
	else if (strcmp(pFile, "rules.txt") == 0)
		WordFilter.load("rules.txt");
	else if ( strcmp(pFile, "foldersconfig.txt") == 0 )
	{
		folderConfig.load( "foldersconfig.txt" );

		// Don't allow .. in the folder path.
		for ( int i = 0; i < folderConfig.count(); ++i )
		{
			if ( ((CBuffer)folderConfig[i]).find( ".." ) != -1 )
			{
				folderConfig.remove(i);
				--i;
			}
		}

		getSubDirs();
	}
	else
		return false;

	return true;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:38,代码来源:main.cpp

示例11: loadNW

bool CLevel::loadNW(CString& pFileName)
{
	CStringList levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;

	if(!levelData.load(dataFile))
		return false;

	if(levelData.count() < 1)
		return false;

	version = levelData[0];
	modTime = getFileModTime(dataFile);
	fileName = pFileName;
	if(version == "GLEVNW01" || version == "GSERVL01")
	{
		for(int i = 1; i < levelData.count(); i ++)
		{
			CStringList words;
			words.load(levelData[i].text(), " ");
			if(words.count() <= 0)
				continue;
			if(words[0] == "BOARD")
			{
				if(words.count() <= 5)
					continue;

				int x = atoi(words[1].text());
				int y = atoi(words[2].text());
				int w = atoi(words[3].text());
				CString& data = words[5];
				if(x >= 0 && x <= 64 && y >= 0 && y <= 64 && w > 0 && x + w <= 64)
				{
					if(data.length() >= w*2)
					{
						for(int ii = x; ii < x + w; ii++)
						{
							char left = data.readChar();
							char top = data.readChar();
							short tile = base64.find(left) << 6;
							tile += base64.find(top);
							tiles[ii + y*64] = tile;
						}
					}
				}
			} else if(words[0] == "LINK")
			{
				if(words.count() <= 7)
					continue;
				if(strlen(getDataFile(words[1].text())))
				{
					links.add(new CLink(words[1], atoi(words[2].text()), atoi(words[3].text()),
						atoi(words[4].text()), atoi(words[5].text()), words[6], words[7]));
				}
			} else if(words[0] == "CHEST")
			{
				if(words.count() <= 4)
					continue;
				for(int ii = 0; ii < itemcount; ii++)
				{
					if(words[3] == itemNames[ii])
					{
						chests.add(new CChest(atoi(words[1].text()), atoi(words[2].text()),
							atoi(words[4].text()), ii));
						break;
					}
				}

			} else if(words[0] == "NPC")
			{
				if(words.count() <= 3)
					continue;
				CString image, code, code2;
				float x, y;
				if(words[1] != "-")
					image = words[1];

				x = (float)atof(words[2].text());
				y = (float)atof(words[3].text());
				for(i++; i < levelData.count() && levelData[i] != "NPCEND"; i++)
					code << levelData[i] << "\xa7";

				// Create the new NPC.  Do this before parsing the join commands.
				// The CNpc constructor will remove all comments.
				CNpc* jnpc = new CNpc( image, code, x, y, this, true );

				// Now filter out the join commands.
				CStringList npcData;
				npcData.load( jnpc->clientCode.text(), "\xa7" );
				for ( int j = 0; j < npcData.count(); ++j )
					code2 << processNpcLine( npcData[j] ) << "\xa7";
				jnpc->clientCode = code2;

				// Now, add all the joined files to the code.
				if ( joinList.count() > 0 )
				{
					CString* file = 0;
//.........这里部分代码省略.........
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:101,代码来源:CLevel.cpp

示例12: loadSettings

bool loadSettings(char* pFile)
{
	CStringList settings;
	if (!settings.load(pFile))
		return false;

	for (int i = 0; i < settingList.count(); i++)
	{
		delete (SettingKey *)settingList[i];
		i--;
	}
	settingList.clear();

	for (int i = 0; i < settings.count(); i++)
	{
		if (settings[i][0] == '#' || settings[i][0] == '\'')
			continue;

		SettingKey *key = new SettingKey();
		key->name = settings[i].copy(0, settings[i].find('=')).trim();
		key->value = settings[i].copy(settings[i].find('=') + 1).trim();
	}

	/* ARRAY Server-Options */
	globalGuildList.load(findKey("allowedglobalguilds"), ",");
	cheatwindows.load(findKey("cheatwindows"), ",");
	jailLevels.load(findKey("jaillevels"), ",");
	mapNames.load(findKey("maps"), ",");
	profileList.load(findKey("profilevars", "Kills:=playerkills,Deaths:=playerdeaths,Maxpower:=playerfullhearts,Rating:=playerrating,Alignment:=playerap,Gralat:=playerrupees,Swordpower:=playerswordpower,Spin Attack:=canspin"), ",");
	staffGuilds.load(findKey("staffguilds", "Server,Manager,Owner,Admin,FAQ,LAT,NAT,GAT,GP,GP Chief,Bugs Admin,NPC Admin,Gani Team,GFX Admin,Events Team,Events Admin,Guild Admin"), ",");
	staffList.load(findKey("staff"), ",");
	statusList.load(findKey("playerlisticons", "Online,Away,DND"), ",");

	/* BOOL Server-Options */
	apSystem = CHECK_BOOL(findKey("apsystem", "true"));
	baddyDropItems = CHECK_BOOL(findKey("baddyitems", "false"));
	bushesDrop = CHECK_BOOL(findKey("bushitems", "true"));
	cheatwindowsban = CHECK_BOOL(findKey("cheatwindowsban", "false"));
	clientsidePushPull = CHECK_BOOL(findKey("clientsidepushpull", "true"));
	defaultweapons = CHECK_BOOL(findKey("defaultweapons", "true"));
	detailedconsole = CHECK_BOOL(findKey("detailedconsole", "false"));
	dontaddserverflags = CHECK_BOOL(findKey("dontaddserverflags", "false"));
	dontchangekills = CHECK_BOOL(findKey("dontchangekills", "false"));
	dropItemsDead = CHECK_BOOL(findKey("dropitemsdead", "true"));
	globalGuilds = CHECK_BOOL(findKey("globalguilds", "true"));
	healswords = CHECK_BOOL(findKey("healswords", "false"));
	idleDisconnect = CHECK_BOOL(findKey("disconnectifnotmoved", "true"));
	noExplosions = CHECK_BOOL(findKey("noexplosions", "false"));
	noFoldersConfig = CHECK_BOOL(findKey("nofoldersconfig", "false"));
	putnpcenabled = CHECK_BOOL(findKey("putnpcenabled", "true"));
	adminCanChangeGralat = CHECK_BOOL(findKey("normaladminscanchangegralats", "true"));
	setbodyallowed = CHECK_BOOL(findKey("setbodyallowed", "true"));
	setheadallowed = CHECK_BOOL(findKey("setheadallowed", "true"));
	setswordallowed = CHECK_BOOL(findKey("setswordallowed", "true"));
	setshieldallowed = CHECK_BOOL(findKey("setshieldallowed", "true"));
	showConsolePackets = CHECK_BOOL(findKey("showconsolepackets", "false"));
	staffOnly = CHECK_BOOL(findKey("onlystaff", "false"));
	underconstruction = CHECK_BOOL(findKey("underconstruction", "false"));
	vasesDrop = CHECK_BOOL(findKey("vasesdrop", "true"));
	warptoforall  = CHECK_BOOL(findKey("warptoforall", "false"));

	/* INT Server-Options */
	aptime[0] = atoi(findKey("aptime0", "30"));
	aptime[1] = atoi(findKey("aptime1", "90"));
	aptime[2] = atoi(findKey("aptime2", "300"));
	aptime[3] = atoi(findKey("aptime3", "600"));
	aptime[4] = atoi(findKey("aptime4", "1200"));
	baddyRespawn = atoi(findKey("baddyrespawntime"));
	cheatwindowstime = atoi(findKey("cheatwindowstime", "60"));
	heartLimit = atoi(findKey("heartlimit", "20"));
	horseLife = atoi(findKey("horselifetime"));
	listServerFields[3] = toString(GSERVER_BUILD);
	listServerPort = atoi(findKey("listport", "14900"));
	maxNoMovement = atoi(findKey("maxnomovement", "1200"));
	maxPlayers = atoi(findKey("maxplayers", "128"));
	mindeathgralats = atoi(findKey("mindeathgralats","1"));
	maxdeathgralats = atoi(findKey("maxdeathgralats","50"));
	shieldLimit = atoi(findKey("shieldlimit", "3"));
	swordLimit = CLIP(atoi(findKey("swordlimit", "4")), -25, 25);
	tiledroprate = CLIP(atoi(findKey("tiledroprate", "50")), 0, 100);
	tileRespawn = atoi(findKey("respawntime"));
	unstickmeX = (float)atof(findKey("unstickmex", "30"));
	unstickmeY = (float)atof(findKey("unstickmey", "30.5"));

	/* TEXT Server-Options */
	unstickmeLevel = findKey("unstickmelevel", "onlinestartlocal.nw");
	listServerIp = findKey("listip", "listserver.graal.in");
	listServerFields[0] = findKey("name", "My Server");
	listServerFields[1] = findKey("description", "My Server");
	listServerFields[2] = findKey("language", "English");
	listServerFields[4] = findKey("url", "http://www.graal.in");
	listServerFields[5] = findKey("myip", "AUTO");
	serverPort = findKey("serverport", "14802");
	shareFolder = findKey("sharefolder");
	staffHead = findKey("staffhead", "head25.png");
	worldName = findKey("worldname", "main");

	// If the server is flagged as under construction, prepend the
	// Under Construction value to the name.
	if ( underconstruction && !listServerFields[0].match( "U *" ) )
//.........这里部分代码省略.........
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:101,代码来源:main.cpp

示例13: ListServer_Main

void ListServer_Main()
{
	if (!lsConnected)
		return;

	CBuffer receiveBuff;
	if (listServer.receiveBytes(receiveBuff, 65536) < 0)
	{
		errorOut("rclog.txt", "Disconnected from list server");
		lsConnected = false;
		return;
	}

	CStringList lines;
	lines.load(receiveBuff.text(), "\n");
	for (int i = 0; i < lines.count(); i++)
	{
		CPacket line = CPacket() << lines[i];
		int messageId = line.readByte1();

		switch (messageId)
		{
			case GSVOLD:
			{
				printf("*** SERVER VERSION CHECK ***\nYou're running an old version of the GServer.\nYou're running GServer Revision %i while GServer Revision %i is the latest.\n*** SERVER VERSION CHECK ***\n", GSERVER_BUILD, line.readByte2());
				break;
			}

			case GSVCURRENT:
			{
				 printf("*** SERVER VERSION CHECK ***\nYou're running an up-to-date server. :)\n*** SERVER VERSION CHECK ***\n");
				 break;
			}

			case GSVACCOUNT:
			{
				CString accountName = line.readChars(line.readByte1());
				CString errorMsg = line.readString("");

				for (int i = 0; i < newPlayers.count(); i++)
				{
					CPlayer *player = (CPlayer *)newPlayers[i];

					if (player->accountName == accountName)
					{
						if (errorMsg == "SUCCESS")
						{
							player->sendAccount();
						}
							else
						{
							player->sendPacket(CPacket() << (char)DISMESSAGE << errorMsg);
							player->deleteMe = true;
						}

						break;
					}
				}

				break;
			}

			case GSVGUILD:
			{
				int playerId = line.readByte2();
				CPlayer *player = (CPlayer *)playerIds[playerId];

				if (player != NULL)
				{
					CString nick = line.readChars((unsigned char)line.readByte1());
					player->setNick(nick, false);
				}

				break;
			}

			case GSVFILEC:
			{
				CString fileData, fileName = CString() << dataDir << "global" << fSep << line.readChars(line.readByte1());
				fileData.save(fileName.text());

				break;
			}

			case GSVFILED:
			{
				CString fileName = line.readChars(line.readByte1());
				CPlayer *player = (CPlayer *)playerIds[line.readByte2()];

				switch (line.readByte1())
				{
					case 0: // head
						player->headImage = fileName;
						player->updateProp(HEADGIF);
					break;

					case 1: // body
						player->bodyImage = fileName;
						player->updateProp(BODYIMG);
					break;
//.........这里部分代码省略.........
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:101,代码来源:CListServer.cpp

示例14: load

bool CWordFilter::load(char *pFile)
{
	for (int i = 0; i < WordList.count(); i++)
		delete (WordMatch *)WordList[i];
	WordList.clear();
	CStringList lines;
	lines.load(pFile);
	if(lines.count() < 1)
		return false;

	for (int i = 0; i < lines.count(); i++)
	{
		CStringList words;
		words.load(lines[i].text(), " ");
		if (words.count() <= 0)
			continue;

		if (words[0] == "WARNMESSAGE")
		{
			words.remove(0);
			warnmessage = words.join(" ");
		}
			else if (words[0] == "SHOWWORDSTORC")
		{
			showtorc = CHECK_BOOL(words[1].text());
		}
			else if (words[0] == "RULE")
		{
			WordMatch *word = new WordMatch();
			memset(word->check, false, sizeof(word->check));
			memset(word->action, false, sizeof(word->action));

			for (i++; i < lines.count() && lines[i] != "RULEEND"; i++)
			{
				words.load(lines[i].text(), " ");
				if (words.count() <= 0)
					continue;

				if (words[0] == "ACTION" && words.count() >= 2)
				{
					for (int ii = 1; ii < words.count(); ii++)
					{
						if (words[ii] == "ban") word->action[FILTERA_BAN] = true;
						else if (words[ii] == "jail") word->action[FILTERA_JAIL] = true;
						else if (words[ii] == "log") word->action[FILTERA_LOG] = true;
						else if (words[ii] == "replace") word->action[FILTERA_REPLACE] = true;
						else if (words[ii] == "tellrc") word->action[FILTERA_TELLRC] = true;
						else if (words[ii] == "warn") word->action[FILTERA_WARN] = true;
					}
				}
					else if (words[0] == "CHECK" && words.count() >= 2)
				{
					for (int ii = 1; ii < words.count(); ii++)
					{
						if (words[ii] == "chat") word->check[FILTERC_CHAT] = true;
						else if (words[ii] == "nick") word->check[FILTERC_NICK] = true;
						else if (words[ii] == "pm") word->check[FILTERC_PM] = true;
						else if (words[ii] == "toall") word->check[FILTERC_TOALL] = true;
					}
				}
					else if (words[0] == "MATCH" && words.count() >= 2)
				{
					words.remove(0);
					word->match = words.join(" ");
				}
					else if (words[0] == "PRECISION" && words.count() == 2)
				{
					word->precision = (words[1].find('%') >= 0 ? word->match.length() * atoi(words[1].text()) / 100 : atoi(words[1].text()));
				}
					else if (words[0] == "WORDPOSITION" && words.count() == 2)
				{
					if (words[1] == "full") word->position = FILTERP_FULL;
					else if (words[1] == "part") word->position = FILTERP_PART;
					else if (words[1] == "start") word->position = FILTERP_START;
				}
					else if (words[0] == "WARNMESSAGE" && words.count() >= 2)
				{
					words.remove(0);
					word->warnmessage = words.join(" ");
				}
			}

			if (word->precision <= 0)
				word->precision = word->match.length();

			WordList.add(word);
		}
	}

	return true;
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:91,代码来源:CWordFilter.cpp

示例15: apply

/* Never was great formulating =P */
bool CWordFilter::apply(CPlayer *pPlayer, CBuffer &pBuffer, int pCheck)
{
	bool logsave = false, rctell = false;
	CBuffer start;
	CStringList found;
	int pos = 0, wc = 0;

	for (int i = 0; i < WordList.count(); i++)
	{
		WordMatch *word = (WordMatch *)WordList[i];
		if (!word->check[pCheck])
			continue;

		for (int j = 0; j < pBuffer.length(); j++)
		{
			for (int k = 0; k < word->match.length(); k++)
			{
				char c1 = pBuffer[j + k];
				char c2 = word->match[k];
				if (c2 != '?' && (isUpper(c2) && c2 != c1) || (isLower(c2) && toLower(c2) != toLower(c1)))
				{
					if (wc >= word->precision)
					{
						found.add(start);

						for (int l = 0; l < (int)sizeof(word->action); l++)
						{
							if (!word->action[l])
								continue;

							switch (l)
							{
								case FILTERA_LOG:
									if (logsave)
										break;

									logsave = true;
									if (pPlayer != NULL)
										errorOut("wordfilter.txt", CBuffer() << pPlayer->accountName << " has used rude words while chatting: " << start);
								break;

								case FILTERA_REPLACE:
									pos = pBuffer.find(' ', j);
									pos = (pos == -1 ? start.length() : pos-j+1);
									for (int m = 0; m < pos; m++)
										pBuffer.replace(j + m, '*');
								break;

								case FILTERA_TELLRC:
									if (rctell)
										break;

									rctell = true;
									if (pPlayer != NULL)
										sendRCPacket(CPacket() << (char)DRCLOG << pPlayer->accountName << " has used rude words while chatting: " << start);
								break;

								case FILTERA_WARN:
									pBuffer = (word->warnmessage.length() > 0 ? word->warnmessage : warnmessage);
								break;

								case FILTERA_JAIL: // kinda useless...?
								break;

								case FILTERA_BAN:
									if (pPlayer != NULL)
									{
										CBuffer pLog = CBuffer() << "\n" << getTimeStr(0) << "\n" << pPlayer->accountName << " has used rude words while chatting: " << start;
										pPlayer->setBan(pLog, true);
									}
								break;
							}
						}
					}

					start.clear();
					wc = 0;
					break;
				}

				start.writeChar(c1);
				wc++;
			}
		}
	}

	return (found.count() > 0);
}
开发者ID:Guthius,项目名称:gs2emu-googlecode,代码行数:89,代码来源:CWordFilter.cpp


注:本文中的CStringList::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。