void FtpClient_OnCmdAppe(FtpClient *pClient, const char *pFile) { assert(pClient); if (FileSystem_OpenFile(&pClient->m_kContext, pFile, FM_WRITE, -1) < 0) { FtpClient_Send(pClient, 500, pClient->m_pMessages[FTPMSG_COULD_NOT_CREATE_FILE]); return; } pClient->m_eDataAction = DATAACTION_APPE; FtpClient_HandleDataConnect(pClient); }
void FtpClient_OnCmdStor(FtpClient *pClient, const char *pFile) { int iMarker = pClient->m_iRestartMarker; pClient->m_iRestartMarker = 0; if (FileSystem_OpenFile(&pClient->m_kContext, pFile, FM_WRITE, iMarker) < 0) { FtpClient_Send(pClient, 500, pClient->m_pMessages[FTPMSG_COULD_NOT_CREATE_FILE]); return; } pClient->m_eDataAction = DATAACTION_STOR; FtpClient_HandleDataConnect(pClient); }
void FtpClient_OnCmdRetr(FtpClient *pClient, const char *pFile) { int iMarker = pClient->m_iRestartMarker; pClient->m_iRestartMarker = 0; if (FileSystem_OpenFile(&pClient->m_kContext, pFile, FM_READ, iMarker) < 0) { FtpClient_Send(pClient, 500, pClient->m_pMessages[FTPMSG_FILE_NOT_FOUND]); return; } pClient->m_eDataAction = DATAACTION_RETR; FtpClient_HandleDataConnect(pClient); }
void Scripts_LoadStringsFile(const char *stringsFilePath) { std::string line; size_t pos; filehandle_t *hnd; stringTable.clear(); // Matchings std::smatch matchings; // string line pattern: $Key "$Value" std::regex stringLinePattern("^\\s*([^[:space:]]+)\\s+[\"](.+)[\"]$"); if (NULL == (hnd = FileSystem_OpenFile(stringsFilePath, 0))) { hdPrintf("Could not load strings file: %s\n", stringsFilePath); return; } std::istringstream iss((char *)hnd->filedata); if (!iss.good()) { hdPrintf("Could not load strings file: %s\n", stringsFilePath); return; } // Parse line by line while(!iss.eof()) { getline(iss, line); if (std::regex_match(line, matchings, stringLinePattern)) { hdAssert(line == matchings[0]); hdAssert(3 == matchings.size()); // New line hack std::string s(matchings[2]); while((pos = s.find("\\n")) != std::string::npos) { s.replace(pos, 2, 1, '\n'); } stringTable[matchings[1]] = s; } } FileSystem_CloseFile(hnd); stringsFileWasLoaded = true; }
void FtpClient_OnCmdRnfr(FtpClient *pClient, const char *name) { int iMarker = pClient->m_iRestartMarker; pClient->m_iRestartMarker = 0; // check if file/dir exists that is to be renamed if ((FileSystem_OpenFile(&pClient->m_kContext, name, FM_READ, iMarker)) && (FileSystem_OpenDir(&pClient->m_kContext, name)) < 0) FtpClient_Send(pClient, 550, pClient->m_pMessages[FTPMSG_COMMAND_FAILED]); else { // get just the name not the path FileSystem_BuildPath(buffer, pClient->m_kContext.m_Path, name); if (NULL != (name = FileSystem_ClassifyPath(&pClient->m_kContext, buffer))) strcpy(buffer, name); FtpClient_Send(pClient, 350, pClient->m_pMessages[FTPMSG_COMMAND_SUCCESSFUL]); } }
// Buggy poor implentation of half of a packrat parser void ParseWorldMessageScript(const char* scriptfilepath) { std::string line; bool contextOpened; int currContextID; size_t pos; hdMessage msg; filehandle_t *hnd; contextOpened = false; if (NULL == (hnd = FileSystem_OpenFile(scriptfilepath, 0))) { hdPrintf("Could not load strings file: %s\n", scriptfilepath); return; } std::istringstream iss((char *)hnd->filedata); if (!iss.good()) { hdPrintf("Could not load scripts file: %s\n", scriptfilepath); return; } // ("LEVEL")(Spaces)(Digits)(Optional Scaces) std::regex contextLinePattern("^(LEVEL)\\s+(\\d+)\\s*$"); // ("TEXT")(Spaces)(Digits)(Spaces)("Anything") std::regex textLinePattern("^(TEXT)\\s+(\\d+)\\s+(.+)$"); // ("IMAGE")(Spaces)(Digits)(Spaces)("Anything") std::regex imageLinePattern("^(IMAGE)\\s+(\\d+)\\s+(.+)$"); // ("CUSTOMTEXT")(Spaces)(Digits)(Spaces)(@ImageTextureName)(Scaces)(@Message) std::regex customTextLinePattern("^(CUSTOMTEXT)\\s+(\\d+)\\s+([^[:space:]]+)\\s+[\"](.+)[\"]$"); // ("CUSTOMTEXT")(Spaces)(Digits)(Spaces)(@ImageTextureName)(Scaces)(@Message) std::regex avatarTextLinePattern("^(AVATARMESSAGE)\\s+(\\d+)\\s+([^[:space:]]+)\\s+[\"](.+)[\"]$"); // Matchings std::smatch matchings; // Parse line by line while(!iss.eof()) { getline(iss, line); if (std::regex_match(line, matchings, contextLinePattern)) { contextOpened = true; hdAssert(line == matchings[0]); hdAssert(matchings.size() == 3); std::string s(matchings[2]); currContextID = (int)strtol(s.c_str(), NULL, 0); } else if (std::regex_match(line, matchings, textLinePattern)) { if (!contextOpened) { hdPrintf("Scripts file malformed, bailing out: %s\n", scriptfilepath); break; } hdAssert(line == matchings[0]); hdAssert(4 == matchings.size()); msg.contextId = currContextID; msg.targetId = (int)strtol(std::string(matchings[2]).c_str(), NULL, 0); // New line hack std::string s(matchings[3]); while((pos = s.find("\\n")) != std::string::npos) { s.replace(pos, 2, 1, '\n'); } snprintf(msg.message, 256, "%s", s.c_str()); msg.messageType = e_hdMessageTypeText; if (HD_COLLECTIONS_ERROR_FULL == currentCache->Add(msg)) { hdPrintf("Script cache full, bailing out: %s\n", scriptfilepath); break; } } else if (std::regex_match(line, matchings, imageLinePattern)) { if (!contextOpened) { hdPrintf("Scripts file malformed, bailing out: %s\n", scriptfilepath); break; } hdAssert(line == matchings[0]); hdAssert(4 == matchings.size()); msg.contextId = currContextID; msg.targetId = (int)strtol(std::string(matchings[2]).c_str(), NULL, 0); snprintf(msg.texture, 256, "%s", std::string(matchings[3]).c_str()); msg.messageType = e_hdMessageTypeImage; if (HD_COLLECTIONS_ERROR_FULL == currentCache->Add(msg)) { hdPrintf("Script cache full, bailing out: %s\n", scriptfilepath); break; } } else if (std::regex_match(line, matchings, customTextLinePattern)) { if (!contextOpened) { hdPrintf("Scripts file malformed, bailing out: %s\n", scriptfilepath); break; } hdAssert(line == matchings[0]); hdAssert(5 == matchings.size()); msg.contextId = currContextID; msg.targetId = (int)strtol(std::string(matchings[2]).c_str(), NULL, 0); snprintf(msg.texture, 256, "%s", std::string(matchings[3]).c_str()); // New line hack std::string s(matchings[4]); while((pos = s.find("\\n")) != std::string::npos) { s.replace(pos, 2, 1, '\n'); } snprintf(msg.message, 256, "%s", s.c_str()); msg.messageType = e_hdMessageTypeCustomImageText; if (HD_COLLECTIONS_ERROR_FULL == currentCache->Add(msg)) { hdPrintf("Script cache full, bailing out: %s\n", scriptfilepath); break; } } else if (std::regex_match(line, matchings, avatarTextLinePattern)) { if (!contextOpened) { hdPrintf("Scripts file malformed, bailing out: %s\n", scriptfilepath); break; } hdAssert(line == matchings[0]); hdAssert(5 == matchings.size()); msg.contextId = currContextID; msg.targetId = (int)strtol(std::string(matchings[2]).c_str(), NULL, 0); snprintf(msg.texture, 256, "%s", std::string(matchings[3]).c_str()); // New line hack std::string s(matchings[4]); while((pos = s.find("\\n")) != std::string::npos) { s.replace(pos, 2, 1, '\n'); } snprintf(msg.message, 256, "%s", s.c_str()); msg.messageType = e_hdMessageTypeAvatar; if (HD_COLLECTIONS_ERROR_FULL == currentCache->Add(msg)) { hdPrintf("Script cache full, bailing out: %s\n", scriptfilepath); break; } } } FileSystem_CloseFile(hnd); }