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; }
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; }
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; }
void loadServerMessage() { CStringList fileData; if(!fileData.load("servermessage.html")) return; serverMessage.clear(); for(int i = 0; i < fileData.count(); i++) serverMessage << fileData[i] << " "; }
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 ); } }
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; }
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); } } }
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; }
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; }
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; }
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; }
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; }
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; } } }
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; }
/* 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); }
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; } } }