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; }
bool CClientDFF::LoadDFF(const SString& strFile, bool bIsRawData) { // Should only be called once, directly after construction m_bIsRawData = bIsRawData; if (!m_bIsRawData) // If we have actual file { assert(m_strDffFilename.empty()); m_strDffFilename = strFile; if (m_strDffFilename.empty()) return false; if (!FileExists(m_strDffFilename)) return false; if (!g_pCore->GetNetwork()->CheckFile("dff", m_strDffFilename)) return false; } else { m_RawDataBuffer = CBuffer(strFile, strFile.length()); if (!g_pCore->GetNetwork()->CheckFile("dff", "", m_RawDataBuffer.GetData(), m_RawDataBuffer.GetSize())) return false; } // Do actual load later (in ReplaceModel) return true; }
// Get a clump which has been loaded to replace the specified model id RpClump* CClientDFF::GetLoadedClump(ushort usModelId) { if (usModelId == 0) return NULL; SLoadedClumpInfo& info = MapGet(m_LoadedClumpInfoMap, usModelId); if (!info.bTriedLoad) { info.bTriedLoad = true; // Make sure previous model+collision is loaded m_pManager->GetModelRequestManager()->RequestBlocking(usModelId, "CClientDFF::LoadDFF"); // Attempt loading it if (!m_bIsRawData) // We have file { if (g_pCore->GetNetwork()->CheckFile("dff", m_strDffFilename)) { g_pClientGame->GetResourceManager()->ValidateResourceFile(m_strDffFilename, CBuffer()); info.pClump = g_pGame->GetRenderWare()->ReadDFF(m_strDffFilename, CBuffer(), usModelId, CClientVehicleManager::IsValidModel(usModelId)); } } else // We have raw data { info.pClump = g_pGame->GetRenderWare()->ReadDFF(NULL, m_RawDataBuffer, usModelId, CClientVehicleManager::IsValidModel(usModelId)); // Remove raw data from memory (can only do one replace when using raw data) m_RawDataBuffer.Clear(); } } return info.pClump; }
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); } } }
/////////////////////////////////////////////////////////////// // // JpegEncode // // XRGB to jpeg // /////////////////////////////////////////////////////////////// bool JpegEncode ( uint uiWidth, uint uiHeight, uint uiQuality, const void* pData, uint uiDataSize, CBuffer& outBuffer ) { // Validate if ( uiDataSize == 0 || uiDataSize != uiWidth * uiHeight * 4 ) return false; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); unsigned long memlen = 0; unsigned char *membuffer = NULL; jpeg_mem_dest (&cinfo,&membuffer,&memlen ); cinfo.image_width = uiWidth; /* image width and height, in pixels */ cinfo.image_height = uiHeight; cinfo.input_components = 3; /* # of color components per pixel */ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ jpeg_set_defaults(&cinfo); jpeg_set_quality (&cinfo, uiQuality, true); cinfo.dct_method = JDCT_IFAST; /* Start compressor */ jpeg_start_compress(&cinfo, TRUE); /* Process data */ CBuffer rowBuffer; rowBuffer.SetSize ( uiWidth * 3 ); char* pRowTemp = rowBuffer.GetData (); JSAMPROW row_pointer[1]; while (cinfo.next_scanline < cinfo.image_height) { BYTE* pRowSrc = (BYTE*)pData + cinfo.next_scanline * uiWidth * 4; for ( uint i = 0 ; i < uiWidth ; i++ ) { pRowTemp[i*3+0] = pRowSrc[i*4+2]; pRowTemp[i*3+1] = pRowSrc[i*4+1]; pRowTemp[i*3+2] = pRowSrc[i*4+0]; } row_pointer[0] = (JSAMPROW)pRowTemp; (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } /* Finish compression and release memory */ jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); // Copy out data and free memory outBuffer = CBuffer ( membuffer, memlen ); free ( membuffer ); return true; }
/////////////////////////////////////////////////////////////// // // CRemoteMasterServer::DownloadFinished // // Callback during ProcessQueuedFiles // /////////////////////////////////////////////////////////////// void CRemoteMasterServer::DownloadFinished( char* pCompletedData, size_t completedLength, bool bSuccess, int iErrorCode ) { if ( bSuccess ) { if ( m_strStage == "waitingreply" ) { m_strStage = "hasdata"; m_Data = CBuffer ( pCompletedData, completedLength ); if ( !CheckParsable() ) m_strStage = "nogood"; } } }
void ListServer_Connect() { if ((lsConnected = listServer.connectSock(findKey("listip"), atoi(findKey("listport")))) == false) { errorOut("errorlog.txt", CBuffer() << "Unable to connect to list server.", true); return; } errorOut("serverlog.txt", CBuffer() << "Connected to the list server successfully.", true); listServer.setSync(false); // send gserver info to listserver ListServer_Send(CPacket() << (char)SLSNAME << listServerFields[0] << "\n" << (char)SLSDESC << listServerFields[1] << "\n" << (char)SLSLANG << listServerFields[2] << "\n" << (char)SLSVER << listServerFields[3] << "\n" << (char)SLSURL << listServerFields[4] << "\n" << (char)SLSIP << listServerFields[5] << "\n" << (char)SLSPORT << toString(serverPort) << "\n"); // send players to listserver CPacket pPacket; for (int i = 0; i < playerList.count(); i++) { CPlayer *player = (CPlayer *)playerList[i]; pPacket << (char)player->accountName.length() << player->accountName << player->getProp(NICKNAME) << player->getProp(CURLEVEL) << player->getProp(PLAYERX) << player->getProp(PLAYERY) << player->getProp(PALIGNMENT) << (char)player->type; } ListServer_Send(CPacket() << (char)SLSCOUNT << (char)playerList.count() << pPacket << "\n"); }
void CRawMediaType::EncodeContent (EContentEncodingTypes iEncoding) // EncodeContent // // Encode content { // If we're already encoded, we're done if (iEncoding == m_iEncoding) return; // We don't support re-encoding to some other format (for now) if (m_iEncoding != http_encodingIdentity) { ASSERT(false); return; } // Encode the content CStringBuffer Encoded; switch (iEncoding) { case http_encodingGzip: { compCompress(CBuffer(m_sBody), compressionGzip, &Encoded); break; } default: ASSERT(false); return; } // Done m_iEncoding = iEncoding; m_sBody = CString::CreateFromHandoff(Encoded); }
bool CClientTXD::LoadTXD ( const SString& strFile, bool bFilteringEnabled, bool bIsRawData ) { // Do load here to check for errors. m_bFilteringEnabled = bFilteringEnabled; m_bIsRawData = bIsRawData; if( !m_bIsRawData ) { m_strFilename = strFile; CBuffer buffer; if ( !LoadFileData( buffer ) ) return false; return g_pGame->GetRenderWare()->ModelInfoTXDLoadTextures( &m_ReplacementTextures, buffer, m_bFilteringEnabled ); } else { m_FileData = CBuffer( strFile, strFile.length() ); if ( !g_pCore->GetNetwork()->CheckFile( "txd", "", m_FileData ) ) return false; return g_pGame->GetRenderWare()->ModelInfoTXDLoadTextures( &m_ReplacementTextures, m_FileData, m_bFilteringEnabled ); } }
void ListServer_Connect() { if ( serverRunning == false ) return; if ( setSock == false ) { setSock = true; listServer.setDescription( "listserver" ); listServer.setProtocol( SOCKET_PROTOCOL_TCP ); listServer.setType( SOCKET_TYPE_CLIENT ); listServer.setOptions( SOCKET_OPTION_NONBLOCKING ); } CString ip(findKey("listip")), port(findKey("listport")); listServer.init( ip, port ); int val = listServer.connect(); if (val == 0 || val == SOCKET_ALREADY_CONNECTED) lsConnected = true; else lsConnected = false; if ( !lsConnected ) { errorOut("errorlog.txt", CBuffer() << "Unable to connect to list server.", true); listServer.disconnect(); return; } errorOut("serverlog.txt", CBuffer() << "Connected to the list server successfully.", true); // Send the ServerHQ password. CPacket pack; pack << (char)SLSSERVERHQPASS << serverhq_pass << "\n"; // assemble server packet. pack << (char)SLSNEWSERVER << (char)listServerFields[0].length() << listServerFields[0]; pack << (char)listServerFields[1].length() << listServerFields[1]; pack << (char)listServerFields[2].length() << listServerFields[2]; pack << (char)listServerFields[3].length() << listServerFields[3]; pack << (char)listServerFields[4].length() << listServerFields[4]; pack << (char)listServerFields[5].length() << listServerFields[5]; pack << (char)serverPort.length() << serverPort; if (localip == CString("AUTO")) { CString slocalip(listServer.getLocalIp()); if (slocalip == CString("127.0.1.1") || slocalip == CString("127.0.0.1")) { errorOut("serverlog.txt", CBuffer() << "[WARNING] Socket returned " << slocalip << " for its local ip! Not sending local ip to serverlist.", true); pack << (char)0; } else pack << (char)slocalip.length() << slocalip; } else pack << (char)localip.length() << localip; pack << "\n"; // Send the ServerHQ level. pack << (char)SLSSERVERHQLEVEL << (char)serverhq_level << "\n"; // send gserver info to listserver ListServer_Send(pack); // send players to listserver CPacket pPacket; for (int i = 0; i < playerList.count(); i++) { CPlayer *player = (CPlayer *)playerList[i]; pPacket << (char)player->accountName.length() << player->accountName << player->getProp(NICKNAME) << player->getProp(CURLEVEL) << player->getProp(PLAYERX) << player->getProp(PLAYERY) << player->getProp(PALIGNMENT) << (char)(1 << player->type); } ListServer_Send(CPacket() << (char)SLSCOUNT << (char)playerList.count() << pPacket << "\n"); }
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); } } } }
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; }
CBuffer CBufferManager::getBuffer() { mBufferMutex.lock(); return CBuffer(mBuffer, BUFFER_SIZE, this); }
/* 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 CAeonEngine::MsgFileUpload (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx) // MsgFileUpload // // Aeon.fileUpload {filePath} {fileUploadDesc} {data} { AEONERR error; CMsgProcessCtx Ctx(*GetProcessCtx(), Msg, pSecurityCtx); // Get the filePath CString sError; CString sTable; CString sFilePath; if (!CAeonTable::ParseFilePathForCreate(Msg.dPayload.GetElement(0), &sTable, &sFilePath, &sError)) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_PARSING_FILE_PATH, sError), Msg); return; } // Make sure we are allowed access to this table if (!ValidateTableAccess(Msg, pSecurityCtx, sTable)) return; // Get other parameters CDatum dUploadDesc = Msg.dPayload.GetElement(1); CDatum dData = Msg.dPayload.GetElement(2); // Lock while we find or create a table CSmartLock Lock(m_cs); // If the table doesn't exist, then we create a new one inside the lock CAeonTable *pTable; if (!m_Tables.Find(sTable, &pTable)) { // Compose a table descriptor CDatum dTableDesc; if (!CDatum::Deserialize(CDatum::formatAEONScript, CBuffer(strPattern(STR_FILE_TABLE_DESC_PATTERN, sTable)), &dTableDesc)) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_INVALID_TABLE_NAME, sTable), Msg); return; } // Create the table if (!CreateTable(dTableDesc, &pTable, NULL, &sError)) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg); return; } } // Unlock Lock.Unlock(); // Generate a unique session ID from the message CString sSessionID = strPattern("%s/%x%s", Msg.sReplyAddr, Msg.dwTicket, sFilePath); #ifdef DEBUG_FILE_UPLOAD DWORD dwStart = ::sysGetTickCount(); Log(MSG_LOG_INFO, strPattern("Aeon.fileUpload %s [%d bytes]", sFilePath, dData.GetBinarySize())); #endif // Let the table handle the rest int iComplete; if (error = pTable->UploadFile(Ctx, sSessionID, sFilePath, dUploadDesc, dData, &iComplete, &sError)) { if (error == AEONERR_OUT_OF_DATE) SendMessageReplyError(MSG_ERROR_OUT_OF_DATE, sError, Msg); else SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg); return; } #ifdef DEBUG_FILE_UPLOAD Log(MSG_LOG_INFO, strPattern("Aeon.fileUpload complete: %d seconds.", ::sysGetTicksElapsed(dwStart) / 1000)); #endif // Reply if (iComplete == 100) SendMessageReply(MSG_OK, CDatum(), Msg); else { CDatum dReceipt; // LATER: Fill in receipt SendMessageReply(MSG_AEON_FILE_UPLOAD_PROGRESS, dReceipt, Msg); } }
bool CDplusProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer) { uint8 tag[] = { 0x03,0x60,0x00 }; return (Buffer == CBuffer(tag, sizeof(tag))); }
bool CDplusProtocol::IsValidDisconnectPacket(const CBuffer &Buffer) { uint8 tag[] = { 0x05,0x00,0x18,0x00,0x00 }; return (Buffer == CBuffer(tag, sizeof(tag))); }