本文整理汇总了C++中CUnpacker::Error方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnpacker::Error方法的具体用法?C++ CUnpacker::Error怎么用?C++ CUnpacker::Error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnpacker
的用法示例。
在下文中一共展示了CUnpacker::Error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessClientPacket
void CServer::ProcessClientPacket(CNetChunk *pPacket)
{
int ClientID = pPacket->m_ClientID;
CUnpacker Unpacker;
Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize);
// unpack msgid and system flag
int Msg = Unpacker.GetInt();
int Sys = Msg&1;
Msg >>= 1;
if(Unpacker.Error())
return;
if(Sys)
{
// system message
if(Msg == NETMSG_INFO)
{
if(m_aClients[ClientID].m_State == CClient::STATE_AUTH)
{
char aVersion[64];
str_copy(aVersion, Unpacker.GetString(CUnpacker::SANITIZE_CC), 64);
bool CustClt = str_comp(aVersion, GameServer()->NetVersionCust()) == 0;
dbg_msg("es", "%s client connected!", CustClt?"cust":"vanilla");
if(!CustClt && str_comp(aVersion, GameServer()->NetVersion()) != 0)
{
// wrong version
char aReason[256];
str_format(aReason, sizeof(aReason), "Wrong version. Server is running '%s' and client '%s'", GameServer()->NetVersion(), aVersion);
m_NetServer.Drop(ClientID, aReason);
return;
}
const char *pPassword = Unpacker.GetString(CUnpacker::SANITIZE_CC);
if(g_Config.m_Password[0] != 0 && str_comp(g_Config.m_Password, pPassword) != 0)
{
// wrong password
m_NetServer.Drop(ClientID, "Wrong password");
return;
}
m_aClients[ClientID].m_State = CClient::STATE_CONNECTING;
m_aClients[ClientID].m_CustClt = CustClt;
SendMap(ClientID);
}
}
else if(Msg == NETMSG_REQUEST_MAP_DATA)
{
int Chunk = Unpacker.GetInt();
int ChunkSize = 1024-128;
int Offset = Chunk * ChunkSize;
int Last = 0;
// drop faulty map data requests
if(Chunk < 0 || Offset > m_CurrentMapSize)
return;
if(Offset+ChunkSize >= m_CurrentMapSize)
{
ChunkSize = m_CurrentMapSize-Offset;
if(ChunkSize < 0)
ChunkSize = 0;
Last = 1;
}
CMsgPacker Msg(NETMSG_MAP_DATA);
Msg.AddInt(Last);
Msg.AddInt(m_CurrentMapCrc);
Msg.AddInt(Chunk);
Msg.AddInt(ChunkSize);
Msg.AddRaw(&m_pCurrentMapData[Offset], ChunkSize);
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID, true);
if(g_Config.m_Debug)
{
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "sending chunk %d with size %d", Chunk, ChunkSize);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf);
}
}
else if(Msg == NETMSG_READY)
{
if(m_aClients[ClientID].m_State == CClient::STATE_CONNECTING)
{
char aAddrStr[NETADDR_MAXSTRSIZE];
net_addr_str(m_NetServer.ClientAddr(ClientID), aAddrStr, sizeof(aAddrStr), true);
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "player is ready. ClientID=%x addr=%s", ClientID, aAddrStr);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
m_aClients[ClientID].m_State = CClient::STATE_READY;
GameServer()->OnClientConnected(ClientID);
SendConnectionReady(ClientID);
}
}
else if(Msg == NETMSG_ENTERGAME)
{
if(m_aClients[ClientID].m_State == CClient::STATE_READY && GameServer()->IsClientReady(ClientID))
{
//.........这里部分代码省略.........
示例2: ProcessClientPacket
void CServer::ProcessClientPacket(CNetChunk *pPacket)
{
int ClientId = pPacket->m_ClientID;
NETADDR Addr;
CUnpacker Unpacker;
Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize);
// unpack msgid and system flag
int Msg = Unpacker.GetInt();
int Sys = Msg&1;
Msg >>= 1;
if(Unpacker.Error())
return;
if(m_aClients[ClientId].m_State == CClient::STATE_AUTH)
{
if(Sys && Msg == NETMSG_INFO)
{
char aVersion[64];
const char *pPassword;
str_copy(aVersion, Unpacker.GetString(), 64);
if(str_comp(aVersion, GameServer()->NetVersion()) != 0)
{
// OH FUCK! wrong version, drop him
char aReason[256];
str_format(aReason, sizeof(aReason), "wrong version. server is running '%s' and client '%s'.", GameServer()->NetVersion(), aVersion);
m_NetServer.Drop(ClientId, aReason);
return;
}
str_copy(m_aClients[ClientId].m_aName, Unpacker.GetString(), MAX_NAME_LENGTH);
str_copy(m_aClients[ClientId].m_aClan, Unpacker.GetString(), MAX_CLANNAME_LENGTH);
pPassword = Unpacker.GetString();
if(g_Config.m_Password[0] != 0 && str_comp(g_Config.m_Password, pPassword) != 0)
{
// wrong password
m_NetServer.Drop(ClientId, "wrong password");
return;
}
m_aClients[ClientId].m_State = CClient::STATE_CONNECTING;
SendMap(ClientId);
}
}
else
{
if(Sys)
{
// system message
if(Msg == NETMSG_REQUEST_MAP_DATA)
{
int Chunk = Unpacker.GetInt();
int ChunkSize = 1024-128;
int Offset = Chunk * ChunkSize;
int Last = 0;
// drop faulty map data requests
if(Chunk < 0 || Offset > m_CurrentMapSize)
return;
if(Offset+ChunkSize >= m_CurrentMapSize)
{
ChunkSize = m_CurrentMapSize-Offset;
if(ChunkSize < 0)
ChunkSize = 0;
Last = 1;
}
CMsgPacker Msg(NETMSG_MAP_DATA);
Msg.AddInt(Last);
Msg.AddInt(m_CurrentMapSize);
Msg.AddInt(ChunkSize);
Msg.AddRaw(&m_pCurrentMapData[Offset], ChunkSize);
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientId, true);
if(g_Config.m_Debug)
dbg_msg("server", "sending chunk %d with size %d", Chunk, ChunkSize);
}
else if(Msg == NETMSG_READY)
{
if(m_aClients[ClientId].m_State == CClient::STATE_CONNECTING)
{
Addr = m_NetServer.ClientAddr(ClientId);
dbg_msg("server", "player is ready. ClientId=%x ip=%d.%d.%d.%d",
ClientId, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]);
m_aClients[ClientId].m_State = CClient::STATE_READY;
GameServer()->OnClientConnected(ClientId);
}
}
else if(Msg == NETMSG_ENTERGAME)
{
if(m_aClients[ClientId].m_State == CClient::STATE_READY)
{
Addr = m_NetServer.ClientAddr(ClientId);
dbg_msg("server", "player has entered the game. ClientId=%x ip=%d.%d.%d.%d",
ClientId, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3]);
//.........这里部分代码省略.........