本文整理汇总了C++中CSocket::getBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::getBuffer方法的具体用法?C++ CSocket::getBuffer怎么用?C++ CSocket::getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSocket
的用法示例。
在下文中一共展示了CSocket::getBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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( ")" );
//.........这里部分代码省略.........