void CFileSystem::removeFile(const CString& file) { boost::recursive_mutex::scoped_lock lock(*m_preventChange); // Grab the file name and directory. CString filename(file.subString(file.findl(fSep) + 1)); CString directory(file.subString(0, file.find(filename))); // Fix directory path separators. CFileSystem::fixPathSeparators(&directory); // Remove it from the map. fileList.erase(filename); }
CString removeExtension(const CString& file) { int ePos = file.findl('.'); if (ePos == -1) return file; return file.subString(0, ePos); }
void CFileSystem::addFile(CString file) { boost::recursive_mutex::scoped_lock lock(*m_preventChange); // Grab the file name and directory. CFileSystem::fixPathSeparators(&file); CString filename(file.subString(file.findl(fSep) + 1)); CString directory(file.subString(0, file.find(filename))); // Fix directory path separators. if (directory.find(server->getServerPath()) != -1) directory.removeI(0, server->getServerPath().length()); // Add to the map. fileList[filename] = CString() << server->getServerPath() << directory << filename; }
CString CEncryption::encrypt(CString pBuf) { // If we don't have anything, just return. if (pBuf.isEmpty()) return pBuf; switch (m_gen) { // No encryption. case ENCRYPT_GEN_1: case ENCRYPT_GEN_2: break; // Single byte insertion. case ENCRYPT_GEN_3: { m_iterator *= 0x8088405; m_iterator += m_key; int pos = ((m_iterator & 0x0FFFF) % pBuf.length()); return CString() << pBuf.subString(0, pos) << ")" << pBuf.subString(pos); break; } // Partial packet encryption/none, zlib, bz2 compression methods. // Gen 4 is only bz2. case ENCRYPT_GEN_4: case ENCRYPT_GEN_5: { const uint8_t* iterator = reinterpret_cast<const uint8_t*>(&m_iterator); for (int32_t i = 0; i < pBuf.length(); ++i) { if (i % 4 == 0) { if (m_limit == 0) return pBuf; m_iterator *= 0x8088405; m_iterator += m_key; if (m_limit > 0) m_limit--; } pBuf[i] ^= iterator[i%4]; } return pBuf; break; } } return pBuf; }
TNPC::TNPC(const CString& pImage, const CString& pScript, float pX, float pY, TLevel* pLevel, bool pLevelNPC, bool trimCode) : levelNPC(pLevelNPC), x(pX), y(pY), hurtX(32.0f), hurtY(32.0f), x2((int)(pX*16)), y2((int)(pY*16)), gmaplevelx(0), gmaplevely(0), id(0), rupees(0), darts(0), bombs(0), glovePower(0), bombPower(0), swordPower(0), shieldPower(0), visFlags(1), blockFlags(0), sprite(2), power(0), ap(50), image(pImage), gani("idle"), level(pLevel) { memset((void*)colors, 0, sizeof(colors)); memset((void*)saves, 0, sizeof(saves)); memset((void*)modTime, 0, sizeof(modTime)); // imagePart needs to be Graal-packed. for (int i = 0; i < 6; i++) imagePart.writeGChar(0); // Set the gmap levels. TMap* gmap = level->getMap(); if (gmap && gmap->getType() == MAPTYPE_GMAP) { gmaplevelx = (unsigned char)gmap->getLevelX(level->getLevelName()); gmaplevely = (unsigned char)gmap->getLevelY(level->getLevelName()); } // We need to alter the modTime of the following props as they should be always sent. // If we don't, they won't be sent until the prop gets modified. modTime[NPCPROP_IMAGE] = modTime[NPCPROP_SCRIPT] = modTime[NPCPROP_X] = modTime[NPCPROP_Y] = modTime[NPCPROP_VISFLAGS] = modTime[NPCPROP_ID] = modTime[NPCPROP_SPRITE] = modTime[NPCPROP_GMAPLEVELX] = modTime[NPCPROP_GMAPLEVELY] = modTime[NPCPROP_X2] = modTime[NPCPROP_Y2] = time(0); // Search if the NPC is a sparringzone NPC. if (pScript.subString(0, 12) == "sparringzone") pLevel->setSparringZone(true); // Remove comments and separate clientside and serverside scripts. std::vector<CString> parsedCode = TNPC::removeComments(pScript, trimCode); if (parsedCode.size() == 1) clientScript = CString("//#CLIENTSIDE\xa7") << parsedCode[0]; else if (parsedCode.size() > 1) { serverScript = parsedCode[0]; clientScript = "//#CLIENTSIDE\xa7"; for (unsigned int i = 1; i < parsedCode.size(); ++i) clientScript << parsedCode[i]; } // Search for toweapons in the clientside code and extract the name of the weapon. weaponName = toWeaponName(clientScript); // Just a little warning for people who don't know. if (clientScript.length() > 0x3FFF) printf("WARNING: Clientside script of NPC (%s) exceeds the limit of 16383 bytes.\n", (weaponName.length() != 0 ? weaponName.text() : image.text())); // TODO: Create plugin hook so NPCServer can acquire/format code. }
void TAccount::setFlag(const CString& pFlagName, const CString& pFlagValue) { if (server->getSettings()->getBool("cropflags", true)) { int totalLength = pFlagName.length() + 1 + pFlagValue.length(); int fixedLength = 223 - 1 - pFlagName.length(); mFlagList[pFlagName] = pFlagValue.subString(0, fixedLength); } else mFlagList[pFlagName] = pFlagValue; }
CString gs2ToGameMonkey(CString gs2Code) { CString prefix; CString parsedCode; std::vector<CString> clean = gs2Code.tokenize("\xa7"); int bracketCount = 0; for (std::vector<CString>::iterator i = clean.begin(); i != clean.end(); ++i) { CString line = *i; //Functions if (line.readChars(CString("function").length()) == "function") { CString fullFunction = line.subString(CString("function").length()+1); CString functionName = fullFunction.readString("("); CString prefix; //this. or global? prefix << "." << functionName << " = function" << fullFunction.subString(functionName.length()); parsedCode << prefix; bracketCount = 1; } else if (line.find("{") >= 0) { bracketCount++; parsedCode << line; } //Make sure this is ; on the end of } else if (line.find("}") >= 0) { bracketCount--; if (bracketCount > 1) { parsedCode << line; continue; } CString semi; while(line.subString(line.find("}")+1,1) != ";") { if (line.subString(line.find("}")+1,1) != ";") { semi << line.subString(0,line.find("}")+1) << ";" << line.subString(line.find("}")+1); line = semi; } } if (semi.isEmpty()) parsedCode << "};"; else parsedCode << semi; } else if(line.find("SPC") >= 0) { line.replaceAllI("SPC"," + \" \" + "); parsedCode << line; } else parsedCode << line; } return parsedCode; }
void CApplication::sendArgs(int argc, char * argv[]) { // Liste des arguments m_args.reserve(argc); for (int i = 0; i < argc; ++i) { m_args.push_back(argv[i]); } // On indique au système de fichier le répertoire courant CString path = m_args[0]; std::ptrdiff_t pos = path.lastIndexOf(CFileSystem::separator); if (pos != -1) { CFileSystem::Instance().addDirectory(path.subString(0, pos + 1)); } }
void CFileSystem::loadAllDirectories(const CString& directory, bool recursive) { CString path = CString() << directory.remove(directory.findl(fSep)) << fSep; CString wildcard = directory.subString(directory.findl(fSep) + 1); DIR *dir; struct stat statx; struct dirent *ent; // Try to open the directory. if ((dir = opendir(path.text())) == 0) return; // Read everything in it now. while ((ent = readdir(dir)) != 0) { if (ent->d_name[0] != '.') { CString dircheck = CString() << path << ent->d_name; stat(dircheck.text(), &statx); if ((statx.st_mode & S_IFDIR)) { if (recursive) { // We need to add the directory to the directory list. CString newDir = CString() << path << ent->d_name << fSep; newDir.removeI(0, server->getServerPath().length()); addDir(newDir, "*", true); } continue; } } else continue; // Grab the file name. CString file(ent->d_name); if (file.match(wildcard)) fileList[file] = CString(path) << file; } closedir(dir); }
TKey CApplication::getKeyCode(const CString& keycode) { // Ça commence mal... if (!keycode.startsWith("Key_")) { return Key_Unknown; } CString str = keycode.subString(4); // Chiffres if (str == "0") return Key_0; if (str == "1") return Key_1; if (str == "2") return Key_2; if (str == "3") return Key_3; if (str == "4") return Key_4; if (str == "5") return Key_5; if (str == "6") return Key_6; if (str == "7") return Key_7; if (str == "8") return Key_8; if (str == "9") return Key_9; // Chiffres (pavé numérique) if (str == "Num0") return Key_Num0; if (str == "Num1") return Key_Num1; if (str == "Num2") return Key_Num2; if (str == "Num3") return Key_Num3; if (str == "Num4") return Key_Num4; if (str == "Num5") return Key_Num5; if (str == "Num6") return Key_Num6; if (str == "Num7") return Key_Num7; if (str == "Num8") return Key_Num8; if (str == "Num9") return Key_Num9; // Lettres if (str == "A") return Key_A; if (str == "B") return Key_B; if (str == "C") return Key_C; if (str == "D") return Key_D; if (str == "E") return Key_E; if (str == "F") return Key_F; if (str == "G") return Key_G; if (str == "H") return Key_H; if (str == "I") return Key_I; if (str == "J") return Key_J; if (str == "K") return Key_K; if (str == "L") return Key_L; if (str == "M") return Key_M; if (str == "N") return Key_N; if (str == "O") return Key_O; if (str == "P") return Key_P; if (str == "Q") return Key_Q; if (str == "R") return Key_R; if (str == "S") return Key_S; if (str == "T") return Key_T; if (str == "U") return Key_U; if (str == "V") return Key_V; if (str == "W") return Key_W; if (str == "X") return Key_X; if (str == "Y") return Key_Y; if (str == "Z") return Key_Z; // Autres caractères ASCII if (str == "Space" ) return Key_Space; if (str == "Exclam" ) return Key_Exclam; if (str == "Paragraph" ) return Key_Paragraph; if (str == "BracketRight") return Key_BracketRight; if (str == "ParenRight" ) return Key_ParenRight; if (str == "Degree" ) return Key_Degree; if (str == "Comma" ) return Key_Comma; if (str == "Question" ) return Key_Question; if (str == "Colon" ) return Key_Colon; if (str == "Slash" ) return Key_Slash; if (str == "Semicolon" ) return Key_Semicolon; if (str == "Less" ) return Key_Less; if (str == "Greater" ) return Key_Greater; if (str == "Equal" ) return Key_Equal; if (str == "Plus" ) return Key_Plus; if (str == "BraceRight" ) return Key_BraceRight; if (str == "Euro" ) return Key_Euro; if (str == "TwoSuperior" ) return Key_TwoSuperior; if (str == "At" ) return Key_At; if (str == "Ampersand" ) return Key_Ampersand; if (str == "Tilde" ) return Key_Tilde; if (str == "QuoteDbl" ) return Key_QuoteDbl; if (str == "Apostrophe" ) return Key_Apostrophe; if (str == "BraceLeft" ) return Key_BraceLeft; if (str == "ParenLeft" ) return Key_ParenLeft; if (str == "BracketLeft" ) return Key_BracketLeft; if (str == "Minus" ) return Key_Minus; if (str == "Bar" ) return Key_Bar; if (str == "Quote" ) return Key_Quote; if (str == "Underscore" ) return Key_Underscore; if (str == "Backslash" ) return Key_Backslash; if (str == "Dollar" ) return Key_Dollar; if (str == "Sterling" ) return Key_Sterling; if (str == "Circum" ) return Key_Circum; if (str == "Asterisk" ) return Key_Asterisk; if (str == "Mu" ) return Key_Mu; if (str == "Percent" ) return Key_Percent; if (str == "Add" ) return Key_Add; if (str == "Subtract" ) return Key_Subtract; if (str == "Divide" ) return Key_Divide; if (str == "Multiply" ) return Key_Multiply; // Touches spéciales if (str == "LAlt" ) return Key_LAlt; if (str == "RAlt" ) return Key_RAlt; if (str == "LControl") return Key_LControl; if (str == "RControl") return Key_RControl; if (str == "LShift" ) return Key_LShift; if (str == "RShift" ) return Key_RShift; if (str == "LMeta" ) return Key_LMeta; if (str == "RMeta" ) return Key_RMeta; if (str == "Menu" ) return Key_Menu; if (str == "Print" ) return Key_Print; if (str == "Pause" ) return Key_Pause; if (str == "Tab" ) return Key_Tab; if (str == "Backspace" ) return Key_Backspace; if (str == "Enter" ) return Key_Enter; if (str == "NumEnter" ) return Key_NumEnter; if (str == "Insert" ) return Key_Insert; if (str == "Delete" ) return Key_Delete; if (str == "Home" ) return Key_Home; if (str == "End" ) return Key_End; if (str == "PageUp" ) return Key_PageUp; if (str == "PageDown" ) return Key_PageDown; if (str == "Left" ) return Key_Left; if (str == "Up" ) return Key_Up; if (str == "Right" ) return Key_Right; if (str == "Down" ) return Key_Down; if (str == "CapsLock" ) return Key_CapsLock; if (str == "NumLock" ) return Key_NumLock; if (str == "ScrollLock") return Key_ScrollLock; if (str == "Function" ) return Key_Function; if (str == "Escape" ) return Key_Escape; // Fonctions if (str == "F1" ) return Key_F1; if (str == "F2" ) return Key_F2; if (str == "F3" ) return Key_F3; if (str == "F4" ) return Key_F4; if (str == "F5" ) return Key_F5; if (str == "F6" ) return Key_F6; if (str == "F7" ) return Key_F7; if (str == "F8" ) return Key_F8; if (str == "F9" ) return Key_F9; if (str == "F10") return Key_F10; if (str == "F11") return Key_F11; if (str == "F12") return Key_F12; if (str == "F13") return Key_F13; if (str == "F14") return Key_F14; if (str == "F15") return Key_F15; return Key_Unknown; }
TNPC::TNPC(const CString& pImage, const CString& pScript, float pX, float pY, TServer* pServer, TLevel* pLevel, bool pLevelNPC, bool trimCode) : levelNPC(pLevelNPC), x(pX), y(pY), hurtX(32.0f), hurtY(32.0f), x2((int)(pX*16)), y2((int)(pY*16)), gmaplevelx(0), gmaplevely(0), id(0), rupees(0), darts(0), bombs(0), glovePower(0), bombPower(0), swordPower(0), shieldPower(0), visFlags(1), blockFlags(0), sprite(2), power(0), ap(50), image(pImage), gani("idle"), level(pLevel), server(pServer) { memset((void*)colors, 0, sizeof(colors)); memset((void*)saves, 0, sizeof(saves)); memset((void*)modTime, 0, sizeof(modTime)); // bowImage for pre-2.x clients. bowImage >> (char)0; // imagePart needs to be Graal-packed. for (int i = 0; i < 6; i++) imagePart.writeGChar(0); // Set the gmap levels. TMap* gmap = level->getMap(); if (gmap && gmap->getType() == MAPTYPE_GMAP) { gmaplevelx = (unsigned char)gmap->getLevelX(level->getLevelName()); gmaplevely = (unsigned char)gmap->getLevelY(level->getLevelName()); } // We need to alter the modTime of the following props as they should be always sent. // If we don't, they won't be sent until the prop gets modified. modTime[NPCPROP_IMAGE] = modTime[NPCPROP_SCRIPT] = modTime[NPCPROP_X] = modTime[NPCPROP_Y] = modTime[NPCPROP_VISFLAGS] = modTime[NPCPROP_ID] = modTime[NPCPROP_SPRITE] = modTime[NPCPROP_GMAPLEVELX] = modTime[NPCPROP_GMAPLEVELY] = modTime[NPCPROP_X2] = modTime[NPCPROP_Y2] = time(0); // See if the NPC sets the level as a sparring zone. if (pScript.subString(0, 12) == "sparringzone") pLevel->setSparringZone(true); // See if the NPC sets the level as singleplayer. if (pScript.subString(0, 12) == "singleplayer") pLevel->setSingleplayer(true); // Remove comments and separate clientside and serverside scripts. CString nocomments = removeComments(pScript, "\xa7"); if (server->hasNPCServer() && nocomments.find("//#CLIENTSIDE") != -1) { serverScript = nocomments.readString("//#CLIENTSIDE"); clientScript = CString("//#CLIENTSIDE\xa7") << nocomments.readString(""); } else clientScript = nocomments; // Trim the code if specified. if (trimCode) { if (!serverScript.isEmpty()) { std::vector<CString> code = serverScript.tokenize("\xa7"); serverScript.clear(); for (std::vector<CString>::iterator i = code.begin(); i != code.end(); ++i) serverScript << (*i).trim() << "\xa7"; } if (!clientScript.isEmpty()) { std::vector<CString> code = clientScript.tokenize("\xa7"); clientScript.clear(); for (std::vector<CString>::iterator i = code.begin(); i != code.end(); ++i) clientScript << (*i).trim() << "\xa7"; } } // Do joins. if (!serverScript.isEmpty()) serverScript = doJoins(serverScript, server->getFileSystem()); if (!clientScript.isEmpty()) clientScript = doJoins(clientScript, server->getFileSystem()); // Search for toweapons in the clientside code and extract the name of the weapon. weaponName = toWeaponName(clientScript); // Just a little warning for people who don't know. if (clientScript.length() > 0x2FDF) printf("WARNING: Clientside script of NPC (%s) exceeds the limit of 12255 bytes.\n", (weaponName.length() != 0 ? weaponName.text() : image.text())); // TODO: Create plugin hook so NPCServer can acquire/format code. }