本文整理汇总了C++中CBuffer::find方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::find方法的具体用法?C++ CBuffer::find怎么用?C++ CBuffer::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSubDirs
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);
}
}
}
示例2: ParseResponseHeader
bool ParseResponseHeader(CBuffer& buffer,bool &bGZip,bool &bChunked,int &nContentLen,int& nError)
{
const int pos = buffer.find((uint8*)("\r\n\r\n"),4);
if(-1 == pos) return false;
static const char HTTP_OK_FLAG[] ="200 OK";
static const char GZIP[] ="gzip";
static const char CONTENT_ENCOD[] ="Content-Encoding:";
static const char CHUNKED[] ="chunked";
static const char TRANSFER_ENCOD[] ="Transfer-Encoding:";
static const char CONTENT_LENGTH[] ="Content-Length: ";
if(-1 == buffer.find((uint8*)HTTP_OK_FLAG,strlen(HTTP_OK_FLAG)))
{
*(buffer[pos]) = '\0';
if(0 == sscanf_s((char*)(buffer)[buffer.rpos()],"HTTP/1.1 %d",&nError))
sscanf_s((char*)(buffer)[buffer.rpos()],"HTTP/1.0 %d",&nError);
assert(200 == nError);
assert(false);
return false;
}
bGZip =
(-1 != buffer.find((uint8*)GZIP,strlen(GZIP)) &&
-1 != buffer.find((uint8*)CONTENT_ENCOD,strlen(CONTENT_ENCOD)));
bChunked =
(-1 != buffer.find((uint8*)CHUNKED,strlen(CHUNKED)) &&
-1 != buffer.find((uint8*)TRANSFER_ENCOD,strlen(TRANSFER_ENCOD)));
nContentLen = -1;
int i = buffer.find((uint8*)CONTENT_LENGTH,strlen(CONTENT_LENGTH));
if(-1 != i)
{
*(buffer[pos]) = '\0';
sscanf_s((char*)(buffer)[i+strlen(CONTENT_LENGTH)],"%d\r\n",&nContentLen);
}
// assert(0 != nContentLen);
buffer.rpos(pos+4);
// assert('{' == *(char*)buffer[buffer.rpos()] && !bChunked);
return true;
}
示例3: apply
/* 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);
}
示例4: isValidFile
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" )
{
int j = 0;
while ( j < defaultSwordNames.count() &&
file.find( defaultSwordNames[j].text() ) == -1 ) ++j;
if ( j != defaultSwordNames.count() ) return false;
if ( file.match( fmask.text() ) )
return true;
}
break;
case 9: // SHIELDPOWER
if ( ftype == "shield" )
{
int j = 0;
while ( j < defaultShieldNames.count() &&
file.find( defaultShieldNames[j].text() ) == -1 ) ++j;
if ( j != defaultShieldNames.count() ) return false;
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;
}
示例5: ListServer_Main
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( ")" );
//.........这里部分代码省略.........