예제 #1
0
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;
}
예제 #2
0
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;
}
예제 #3
0
void loadServerMessage()
{
	CStringList fileData;
	if(!fileData.load("servermessage.html"))
		return;

	serverMessage.clear();
	for(int i = 0; i < fileData.count(); i++)
		serverMessage << fileData[i] << " ";
}
예제 #4
0
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 );
	}
}
예제 #5
0
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;
}
예제 #6
0
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;
}
예제 #7
0
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;
					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 );
			} else if(words[0] == "BADDY")
			{
				if(words.count() <= 3)
					continue;
				int x = atoi(words[1].text());
				int y = atoi(words[2].text());
				int type = atoi(words[3].text());

				CBaddy* baddy = new CBaddy(x, y, type);
				int baddyId = createBaddyId(baddy);
				baddy->id = baddyId;
				for(i++; i < levelData.count() && levelData[i] != "BADDYEND"; i++)
					baddy->verses.add(levelData[i].text());
				if(baddies.count() < 50)
					baddies.add(baddy);
				else delete baddy;
			} else if(words[0] == "SIGN")
			{
				if(words.count() <= 2)
					continue;

				CString sign;
				int x = atoi(words[1].text());
				int y = atoi(words[2].text());
				sign.writeChar(x+32);
				sign.writeChar(y+32);

				for (i++; i < levelData.count() && levelData[i] != "SIGNEND"; i++)
					sign << getSignCode(CString() << levelData[i] << "\n");
				signs.add(sign);
			} else if(words[0] == "REPLACENPC")
			{
				int npcId = atoi(words[1].text());
				CNpc* npc = (CNpc*)npcs[npcId];
				if(npc == NULL)
					continue;

				for(i++; i < levelData.count() && levelData[i] != "REPLACENPCEND"; i++)
					npc->setProps((CPacket&)levelData[i]);
			}
		}
	} else return false;

	return true;
}
예제 #8
0
int main(int argc, char *argv[])
{
	#ifdef PSPSDK
		pspDebugScreenInit();
		SetupCallbacks();
	#else
		// Shut down the server if we get a kill signal.
		signal( SIGINT, (sighandler_t) shutdownServer );
		signal( SIGTERM, (sighandler_t) shutdownServer );
	#endif

	/* Setup Data-Directory */
	dataDir = CBuffer(argv[0]).replaceAll("\\", "/");
	dataDir = dataDir.copy(0, dataDir.findl('/') + 1);
	programDir = dataDir;
	dataDir << "world/";

	/* Main Initiating */
	adminNames.load( __admin, sizeof(__admin) / sizeof(const char*) );
	colourNames.load( __colours, sizeof(__colours) / sizeof(const char*) );
	clothCommands.load( __cloths, sizeof(__cloths) / sizeof(const char*) );
	defaultFiles.load( __defaultfiles, sizeof(__defaultfiles) / sizeof(const char*) );
	playerIds.add(0);
	playerIds.add(0);
	npcIds.add(0);
	srand((int)time(NULL));

	/* Load Important Files */
	updateFile("rchelp.txt");
	updateFile("rcmessage.txt");
	updateFile("rules.txt");
	updateFile("serverflags.txt");
	updateFile("servermessage.html");
	updateFile("foldersconfig.txt");

	/* Load Settings */
	if (!loadSettings("serveroptions.txt"))
	{
		errorOut("errorlog.txt", "Unable to load server settings..");
		return 1;
	}

	/* Load Weapons */
	if (!loadWeapons("weapons.txt"))
	{
		errorOut("errorlog.txt", "Unable to load weapons from weapons.txt..");
		return 1;
	}

	/* Initialize Sockets */
	serverSock.setType( SOCKET_TYPE_SERVER );
	serverSock.setProtocol( SOCKET_PROTOCOL_TCP );
	serverSock.setOptions( SOCKET_OPTION_NONBLOCKING );
	serverSock.setDescription( "serverSock" );
	CString empty;
	if ( serverSock.init( empty, serverPort ) )
		return 1;

	// Connect server socket.
	if ( serverSock.connect() )
	{
		errorOut("errorlog.txt", CString() << "SOCK ERROR: Unable to listen on port: " << serverPort);
		return 1;
	}

	/* Server Finished Loading */
	printf("GServer 2 by 39ster\nSpecial thanks to Marlon, Agret, Pac300, 39ster and others for porting the \noriginal 1.39 gserver to 2.1\nServer listening on port: %s\nServer version: Build %s\n\n", serverPort.text(), listServerFields[3].text());
	errorOut("serverlog.txt", "Server started");

	if ( listServerFields[5] == "localhost" )
		errorOut("serverlog.txt", "[DEBUG_LOCALHOSTMODE] Localhost mode is activated.\nListserver communication & account authentication are disabled.", true);

	serverRunning = true;

	if ( !(listServerFields[5] == "localhost") )
		if (!lsConnected)
			ListServer_Connect();

	while (serverRunning)
	{
		long long second = time(NULL);

		while (second == time(NULL))
		{
			acceptNewPlayers(serverSock);
			for (int i = 0; i < newPlayers.count(); i ++)
			{
				CPlayer* player = (CPlayer*)newPlayers[i];
				player->main();
				if (player->deleteMe)
				{
					delete player;
					i--;
				}
			}

			for(int i = 0; i < playerList.count(); i++)
			{
				CPlayer* player = (CPlayer*)playerList[i];
				player->main();
				if(player->deleteMe)
				{
					delete player;
					i--;
				}
			}

			// Was moved so it can process faster. - Joey
			ListServer_Main();
			wait(10);
		}

		doTimer();
		gameTime ++;
		NOLEVEL->reset();

		// Every 30 seconds
		if (gameTime % 30 == 0)
		{
			ListServer_Send(CPacket() << (char)SLSPING << "\n");
		}

		// Every 10 seconds
		if (gameTime % 10 == 0)
		{
			CPacket pPacket;
			CString file;

			for (int i = 0; i < playerList.count(); i++)
			{
				CPlayer *player = (CPlayer *)playerList[i];
				file << player->accountName << "," << player->nickName << "," << player->levelName << "," << toString(player->x) << "," << toString(player->y) << "," << toString(player->ap) << "\n";
			}

			file.save("logs/playerlist.txt");
			serverFlags.save("serverflags.txt");
		}

		//Every 5 seconds?
		int current = getNWTime();
		if (nwTime != current)
		{
			nwTime = current;
			for (int i = 0; i < playerList.count(); i++)
			{
				CPacket out;
				out << (char)NEWWORLDTIME;
				out.writeByte4(current);
				((CPlayer*)playerList[i])->sendPacket(out);
			}
		}
	}
}
예제 #9
0
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 *" ) )
		listServerFields[0] = CBuffer() << "U " << listServerFields[0];

	/* Load Maps */
	for(int i = 0; i < CMap::mapList.count(); i++)
		delete((CMap*)CMap::mapList[i]);
	CMap::mapList.clear();
	for(int i = 0; i < mapNames.count(); i++)
		CMap::openMap(mapNames[i].trim());

	// Now fix all the levels.
	for ( int i = 0; i < levelList.count(); ++i )
	{
		CLevel* level = (CLevel*)levelList[i];

		//Find our map id
		level->map = 0;
		for ( int j = 0; j < CMap::mapList.count(); ++j )
		{
			CMap* m = (CMap*)CMap::mapList[j];
			if ( (level->levelIndex = m->getLevelpos(level->fileName)) >= 0 )
			{
				level->map = m;
				break;
			}
		}
	}

	// In case we turned off folders config, get the new sub dirs.
	getSubDirs();

	return true;
}
예제 #10
0
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;

					case 2: // sword
						player->swordImage = fileName;
						player->updateProp(SWORDPOWER);
					break;

					case 3: // shield
						player->shieldImage = fileName;
						player->updateProp(SHIELDPOWER);
					break;
				}

				break;
			}

			case GSVFILES:
			{
				CString fileData, fileName, newData, shortName;
				shortName = line.readChars(line.readByte1());
				int pos = shortName.find("Revision");

				if (pos >= 0)
				{
					#ifdef WIN32
						fileName = CString() << "GServer-NEW.exe";
					#else
						fileName = CString() << "GServer-NEW";
					#endif
					newData = line.readString("");
				}
				else
				{
					fileName = CString() << dataDir << "global" << fSep << shortName.text();
					newData = line.readString("");
				}

				fileData.load(fileName.text());
				fileData << newData.B64_Decode();
				fileData.save(fileName.text());

				break;
			}

			case GSVPROFILE: /* Unsure if this works, temp */
			{
				CPacket profile;
				CPlayer *player1 = (CPlayer *)playerIds[line.readByte2()];
				CPlayer *player2 = findPlayerId(line.readChars(line.readByte1()));
				if (player1 == NULL || player2 == NULL)
					return;

				profile << (char)player2->accountName.length() << player2->accountName << line.readString("");

				int time = player2->onlineSecs;
				CString line;
				//Online time
				line << toString((int)time/3600) << " hrs ";
				line << toString((int)(time/60)%60) << " mins ";
				line << toString((int)time%60) << " secs";
				profile << (char)line.length() << line;

				for (int i = 0; i < profileList.count(); i++)
				{
					CStringList a;
					a.load(profileList[i].text(), ":=");
					if (a[0].length() < 1)
						continue;

					CString n;

					if (a[1] == "playerkills")
						n = toString(player2->kills);
					else if (a[1] == "playerdeaths")
						n = toString(player2->deaths);
					else if (a[1] == "playerfullhearts")
						n = toString(player2->maxPower);
					else if (a[1] == "playerrating")
						n = toString(player2->rating);
					else if (a[1] == "playerap")
						n = toString(player2->ap);
					else if (a[1] == "playerrupees")
						n = toString(player2->rubins);
					else if (a[1] == "playerswordpower")
						n = toString(player2->swordPower);
					else if (a[1] == "canspin")
						n = (player2->status & 64 ? "true" : "false");
					else if (a[1] == "playerhearts")
						n = toString(player2->power);
					else if (a[1] == "playerdarts")
						n = toString(player2->darts);
					else if (a[1] == "playerbombs")
						n = toString(player2->bombs);
					else if (a[1] == "playermp")
						n = toString(player2->magicPoints);
					else if (a[1] == "playershieldpower")
						n = toString(player2->shieldPower);
					else if (a[1] == "playerglovepower")
						n = toString(player2->glovePower);
					else
					{
						for (int i = 0; i < player2->myFlags.count(); i++)
						{
							CStringList b;
							b.load(player2->myFlags[i].text(), "=");
							if (b[0] == a[1])
							{
								n = b[1];
								break;
							}
						}
					}

					profile << (char)(a[0].length() + n.length() + 2) << a[0] << ":=" << n;
				}

				player1->sendPacket(CPacket() << (char)DPROFILE << profile);

				break;
			}

			case GSVMSG:
				printf("%s\n", line.readString(""));
			break;

			default:
				printf("Invalid List Server Message: %i\n", messageId);
			break;
		}
	}
}
예제 #11
0
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;
}
예제 #12
0
void ListServer_Main()
{
	if ( listServerFields[5] == "localhost" ) return;
    if (!lsConnected) return;

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

	packetBuffer << receiveBuff;

	// Search for a packet.  If none is found, break out of the loop.
	int lineEnd = packetBuffer.findl( '\n' );
	if ( lineEnd == -1 ) return;

	// Copy the packet out and remove the \n
	CBuffer line = packetBuffer.copy( 0, lineEnd + 1 );
	packetBuffer.remove(0, line.length());

	// Process the packet.
	lines.load( line.text(), "\n" );
	//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("[%s] SERVER VERSION CHECK - Current: %i, Latest: %i - Old version, please upgrade.\n", getTimeStr(1).text(), GSERVER_BUILD, line.readByte2());
				break;
			}

			case GSVCURRENT:
			{
				printf("[%s] SERVER VERSION CHECK - Current: %i, Latest: %i - You are up to date :)\n", getTimeStr(1).text(), GSERVER_BUILD, GSERVER_BUILD);
				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());
					CString guild = nick.copy( nick.findl( '(' ) ).remove( ")" );

					if ( globalGuilds == false )
					{
						if ( globalGuildList.find( guild ) != -1 )
							player->setNick(nick, false);
					}
					else
						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;

					case 2: // sword
						player->swordImage = fileName;
						player->updateProp(SWORDPOWER);
					break;

					case 3: // shield
						player->shieldImage = fileName;
						player->updateProp(SHIELDPOWER);
					break;
				}

				break;
			}

			case GSVFILES:
			{
				CString fileData, fileName, newData, shortName;
				shortName = line.readChars(line.readByte1());
				int pos = shortName.find("Revision");

				if (pos >= 0)
				{
					#ifdef WIN32
						fileName = CString() << "GServer-NEW.exe";
					#else
						fileName = CString() << "GServer-NEW";
					#endif
					newData = line.readString("");
				}
				else
				{
					fileName = CString() << dataDir << "global" << fSep << shortName.text();
					newData = line.readString("");
				}

				fileData.load(fileName.text());
				fileData << newData.B64_Decode();
				fileData.save(fileName.text());

				break;
			}

			case GSVPROFILE: /* Unsure if this works, temp */
			{
				CPacket profile;
				CPlayer *player1 = (CPlayer *)playerIds[line.readByte2()];
				CPlayer *player2 = findPlayerId(line.readChars(line.readByte1()));
				if (player1 == NULL || player2 == NULL)
					return;

				profile << (char)player2->accountName.length() << player2->accountName << line.readString("");

				int time = player2->onlineSecs;
				CString line2;
				//Online time
				line2 << toString((int)time/3600) << " hrs ";
				line2 << toString((int)(time/60)%60) << " mins ";
				line2 << toString((int)time%60) << " secs";
				profile << (char)line2.length() << line2;

				for (int i = 0; i < profileList.count(); i++)
				{
					CStringList a;
					a.load(profileList[i].text(), ":=");
					if (a[0].length() < 1)
						continue;

					CString n;

					if (a[1] == "playerkills")
						n = toString(player2->kills);
					else if (a[1] == "playerdeaths")
						n = toString(player2->deaths);
					else if (a[1] == "playerfullhearts")
					{
						if ( (float)(int)player2->maxPower == (float)player2->maxPower )
							n = toString((int)player2->maxPower);
						else
						{
							n = toString(player2->maxPower);
							n = n.copy( 0, n.length() - 1 );
						}
					}
					else if (a[1] == "playerrating")
						n = toString((int)player2->rating) << "/" << toString((int)player2->deviation);
					else if (a[1] == "playerap")
						n = toString(player2->ap);
					else if (a[1] == "playerrupees")
						n = toString(player2->rubins);
					else if (a[1] == "playerswordpower")
						n = toString(player2->swordPower);
					else if (a[1] == "canspin")
						n = (player2->status & 64 ? "true" : "false");
					else if (a[1] == "playerhearts")
					{
						if ( (float)(int)player2->power == (float)player2->power )
							n = toString((int)player2->power);
						else
						{
							n = toString(player2->power);
							n = n.copy( 0, n.length() - 1 );
						}
					}
					else if (a[1] == "playerdarts")
						n = toString(player2->darts);
					else if (a[1] == "playerbombs")
						n = toString(player2->bombs);
					else if (a[1] == "playermp")
						n = toString(player2->magicPoints);
					else if (a[1] == "playershieldpower")
						n = toString(player2->shieldPower);
					else if (a[1] == "playerglovepower")
						n = toString(player2->glovePower);
					else
					{
						for (int i = 0; i < player2->myFlags.count(); i++)
						{
							CStringList b;
							b.load(player2->myFlags[i].text(), "=");
							if (b[0] == a[1])
							{
								n = b[1];
								break;
							}
						}
					}

					profile << (char)(a[0].length() + n.length() + 2) << a[0] << ":=" << n;
				}

				player1->sendPacket(CPacket() << (char)DPROFILE << profile);

				break;
			}

			case GSVMSG:
				printf("[%s] %s\n", getTimeStr(1).text(), line.readString(""));
			break;

			case GSVPING:
				// Sent every 60 seconds, do nothing.
			break;

			default:
				printf("[%s] Invalid List Server Message: %i\n", getTimeStr(1).text(), messageId);
			break;
		}
	}
}
예제 #13
0
void ListServer_Main()
{
	static CBuffer packetBuffer;
	CStringList lines;

	if ( listServerFields[5] == "localhost" ) return;
	if (!lsConnected) return;

	// Read any new data into the socket.
	if ( listServer.getData() == -1 )
	{
		errorOut( "serverlog.txt", "Disconnected from list server." );
		lsConnected = false;
		return;
	}

	// Grab all the data from the socket buffer.
	packetBuffer << listServer.getBuffer();
	listServer.getBuffer().clear();

	// Search for a packet.  If none is found, break out of the loop.
	while (packetBuffer.length() != 0)
	{
		CPacket line;
		if (!nextIsRaw)
		{
			int lineEnd = packetBuffer.find( '\n' );
			if ( lineEnd == -1 ) return;

			// Copy the packet out and remove the \n
			line = packetBuffer.copy( 0, lineEnd + 1 );
			packetBuffer.remove(0, line.length());
			line.remove(line.length() - 1, 1);
		}
		else
		{
			if (packetBuffer.length() < rawPacketSize) return;
			line.writeBytes(packetBuffer.readChars(rawPacketSize), rawPacketSize);
			packetBuffer.remove(0, line.length());
			line.remove(line.length() - 1, 1);
			nextIsRaw = false;
		}
		packetBuffer.setRead(0);

		int messageId = line.readByte1();
		switch (messageId)
		{
			case GSVOLD:
			{
				printf("[%s] SERVER VERSION CHECK - Current: %i, Latest: %i - Old version, please upgrade.\n", getTimeStr(1).text(), GSERVER_BUILD, line.readByte2());
				break;
			}

			case GSVCURRENT:
			{
				printf("[%s] SERVER VERSION CHECK - Current: %i, Latest: %i - You are up to date :)\n", getTimeStr(1).text(), GSERVER_BUILD, GSERVER_BUILD);
				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.comparei(accountName) == 0)
					{
						// The serverlist will return case sensitive account names.
						// This helps case sensitive file systems open/save the correct
						// acount.
						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());
					CString guild = nick.copy( nick.findl( '(' ) ).remove( ")" );

					if ( globalGuilds == false )
					{
						if ( globalGuildList.find( guild ) != -1 )
							player->setNick(nick, false);
					}
					else
						player->setNick(nick, false);
				}

				break;
			}

			case GSVPROFILE: /* Unsure if this works, temp */
			{
				CPacket profile;
				CPlayer *player1 = (CPlayer *)playerIds[line.readByte2()];
				CPlayer *player2 = findPlayerId(line.readChars(line.readByte1()));
				if (player1 == NULL || player2 == NULL)
					return;

				profile << (char)player2->accountName.length() << player2->accountName << line.readString("");

				int time = player2->onlineSecs;
				CString line2;
				//Online time
				line2 << toString((int)time/3600) << " hrs ";
				line2 << toString((int)(time/60)%60) << " mins ";
				line2 << toString((int)time%60) << " secs";
				profile << (char)line2.length() << line2;

				for (int i = 0; i < profileList.count(); i++)
				{
					CStringList a;
					a.load(profileList[i].text(), ":=");
					if (a[0].length() < 1)
						continue;

					CString n;

					if (a[1] == "playerkills")
						n = toString(player2->kills);
					else if (a[1] == "playerdeaths")
						n = toString(player2->deaths);
					else if (a[1] == "playerfullhearts")
					{
						if ( (float)(int)player2->maxPower == (float)player2->maxPower )
							n = toString((int)player2->maxPower);
						else
						{
							n = toString(player2->maxPower);
							n = n.copy( 0, n.length() - 1 );
						}
					}
					else if (a[1] == "playerrating")
						n = toString((int)player2->rating) << "/" << toString((int)player2->deviation);
					else if (a[1] == "playerap")
						n = toString(player2->ap);
					else if (a[1] == "playerrupees")
						n = toString(player2->rubins);
					else if (a[1] == "playerswordpower")
						n = toString(player2->swordPower);
					else if (a[1] == "canspin")
						n = (player2->status & 64 ? "true" : "false");
					else if (a[1] == "playerhearts")
					{
						if ( (float)(int)player2->power == (float)player2->power )
							n = toString((int)player2->power);
						else
						{
							n = toString(player2->power);
							n = n.copy( 0, n.length() - 1 );
						}
					}
					else if (a[1] == "playerdarts")
						n = toString(player2->darts);
					else if (a[1] == "playerbombs")
						n = toString(player2->bombs);
					else if (a[1] == "playermp")
						n = toString(player2->magicPoints);
					else if (a[1] == "playershieldpower")
						n = toString(player2->shieldPower);
					else if (a[1] == "playerglovepower")
						n = toString(player2->glovePower);
					else
					{
						for (int i = 0; i < player2->myFlags.count(); i++)
						{
							CStringList b;
							b.load(player2->myFlags[i].text(), "=");
							if (b[0] == a[1])
							{
								n = b[1];
								break;
							}
						}
					}

					profile << (char)(a[0].length() + n.length() + 2) << a[0] << ":=" << n;
				}

				player1->sendPacket(CPacket() << (char)DPROFILE << profile);
				break;
			}

			case GSVMSG:
				printf("[%s] %s\n", getTimeStr(1).text(), line.readString(""));
			break;

			case GSVFILESTART3:
			{
				unsigned char pTy = (unsigned char)line.readByte1();
				CString fileData, fileName = CString() << dataDir << "global" << fSep;
				switch (pTy)
				{
					case 0: // head
						fileName << "heads" << fSep;
					break;

					case 1: // body
						fileName << "bodies" << fSep;
					break;

					case 2: // sword
						fileName << "swords" << fSep;
					break;

					case 3: // shield
						fileName << "shields" << fSep;
					break;
				}
				fileName << line.readChars(line.readByte1());
				fileData.save(fileName.text());
				break;
			}

			case GSVFILEDATA3:
			{
				unsigned char pTy = (unsigned char)line.readByte1();
				CString fileData, fileName, newData, shortName;
				shortName = line.readChars(line.readByte1());
				fileName = CString() << dataDir << "global" << fSep;
				switch (pTy)
				{
					case 0: // head
						fileName << "heads" << fSep;
					break;

					case 1: // body
						fileName << "bodies" << fSep;
					break;

					case 2: // sword
						fileName << "swords" << fSep;
					break;

					case 3: // shield
						fileName << "shields" << fSep;
					break;
				}
				fileName << shortName.text();
				newData.writeBytes(line.readChars(line.bytesLeft()), line.bytesLeft());

				fileData.load(fileName.text());
				fileData << newData;
				fileData.save(fileName.text());
				break;
			}

			case GSVFILEEND3:
			{
				CPlayer *player = (CPlayer *)playerIds[line.readByte2()];
				int type = line.readByte1();
				char doCompress = line.readByte1();
				time_t modTime = line.readByte5();
				int fileLength = line.readByte5();
				CString shortName = line.readString("");
				CString fileName = CString() << dataDir << "global" << fSep;
				switch (type)
				{
					case 0: // head
						fileName << "heads" << fSep;
					break;

					case 1: // body
						fileName << "bodies" << fSep;
					break;

					case 2: // sword
						fileName << "swords" << fSep;
					break;

					case 3: // shield
						fileName << "shields" << fSep;
					break;
				}
				fileName << shortName.text();

				// If the file was sent compressed, we need to uncompress it.
				if (doCompress == 1)
				{
					// Open the file so we can uncompress it.
					CString fileData;
					fileData.load(fileName.text());

					// Uncompress the file.
					char* buffer = new char[fileLength];
					memset((void*)buffer, 0, fileLength);
					int cLen = fileLength;
					int error = uncompress((Bytef*)buffer,(uLongf*)&cLen,(const Bytef*)fileData.text(), fileData.length());
					if (error != Z_OK) printf("Failed to decompress file: %s\n", shortName.text());

					// Save the file now.
					fileData.clear();
					fileData.writeBytes(buffer, cLen);
					fileData.save(fileName.text());
					delete [] buffer;
				}

				// Set the file mod time.
				if (setFileModTime(fileName.text(), modTime) == false)
					printf("** [WARNING] Could not set modification time on file %s\n", shortName.text());

				if (player)
				{
					player->fileList.add(new COutFile(shortName, 0));
					switch (type)
					{
						case 0: // head
							player->headImage = shortName;
							player->updateProp(HEADGIF);
						break;

						case 1: // body
							player->bodyImage = shortName;
							player->updateProp(BODYIMG);
						break;

						case 2: // sword
							player->swordImage = shortName;
							player->updateProp(SWORDPOWER);
						break;

						case 3: // shield
							player->shieldImage = shortName;
							player->updateProp(SHIELDPOWER);
						break;
					}
				}
				break;
			}

			case GSVPING:
				// Sent every 60 seconds, do nothing.
			break;

			case GSVRAWDATA:
				nextIsRaw = true;
				rawPacketSize = line.readByte3();
			break;

			default:
				printf("[%s] Invalid List Server Message: %i\n", getTimeStr(1).text(), messageId);
			break;
		}
	}
}