本文整理汇总了C++中CNetClient::Recv方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetClient::Recv方法的具体用法?C++ CNetClient::Recv怎么用?C++ CNetClient::Recv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNetClient
的用法示例。
在下文中一共展示了CNetClient::Recv方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) // ignore_convention
{
NETADDR BindAddr;
dbg_logger_stdout();
net_init();
mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.port = VERSIONSRV_PORT;
g_NetOp.Open(BindAddr, 0);
dbg_msg("versionsrv", "started");
while(1)
{
g_NetOp.Update();
// process packets
CNetChunk Packet;
while(g_NetOp.Recv(&Packet))
{
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETVERSION) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETVERSION, sizeof(VERSIONSRV_GETVERSION)) == 0)
{
SendVer(&Packet.m_Address);
}
}
// be nice to the CPU
thread_sleep(1);
}
return 0;
}
示例2: main
int main(int argc, char **argv) // ignore_convention
{
NETADDR BindAddr;
dbg_logger_stdout();
net_init();
mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.type = NETTYPE_ALL;
BindAddr.port = VERSIONSRV_PORT;
if(!g_NetOp.Open(BindAddr, 0))
{
dbg_msg("mastersrv", "couldn't start network");
return -1;
}
BuildPackets();
dbg_msg("versionsrv", "started");
while(1)
{
g_NetOp.Update();
// process packets
CNetChunk Packet;
while(g_NetOp.Recv(&Packet))
{
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETVERSION) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETVERSION, sizeof(VERSIONSRV_GETVERSION)) == 0)
{
SendVer(&Packet.m_Address);
}
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETMAPLIST) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETMAPLIST, sizeof(VERSIONSRV_GETMAPLIST)) == 0)
{
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = Packet.m_Address;
p.m_Flags = NETSENDFLAG_CONNLESS;
for(int i = 0; i < m_NumPackets; i++)
{
p.m_DataSize = m_aPackets[i].m_Size;
p.m_pData = &m_aPackets[i].m_Data;
g_NetOp.Send(&p);
}
}
}
// be nice to the CPU
thread_sleep(1);
}
return 0;
}
示例3: main
int main(int argc, const char **argv) // ignore_convention
{
int64 LastUpdate = time_get();
dbg_logger_stdout();
net_init();
IKernel *pKernel = IKernel::Create();
IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention
m_pConsole = CreateConsole(CFGFLAG_BANMASTER);
m_pConsole->RegisterPrintCallback(StandardOutput, 0);
m_pConsole->Register("ban", "s?r", CFGFLAG_BANMASTER, ConBan, 0, "Bans the specified ip", 0);
m_pConsole->Register("unban_all", "", CFGFLAG_BANMASTER, ConUnbanAll, 0, "Unbans all ips", 0);
m_pConsole->Register("bind", "s", CFGFLAG_BANMASTER, ConSetBindAddr, 0, "Binds to the specified address", 0);
{
bool RegisterFail = false;
RegisterFail = RegisterFail || !pKernel->RegisterInterface(m_pConsole);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
if(RegisterFail)
return -1;
}
m_pConsole->ExecuteFile(BANMASTER_BANFILE);
NETADDR BindAddr;
if(m_aBindAddr[0] && net_host_lookup(m_aBindAddr, &BindAddr, NETTYPE_IPV4) == 0)
{
if(BindAddr.port == 0)
BindAddr.port = BANMASTER_PORT;
}
else
{
mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.port = BANMASTER_PORT;
}
m_Net.Open(BindAddr, 0);
// TODO: DDRace: heinrich5991: check socket for errors
dbg_msg("banmaster", "started");
while(1)
{
m_Net.Update();
// process m_aPackets
CNetChunk p;
while(m_Net.Recv(&p))
{
if(p.m_DataSize >= (int)sizeof(BANMASTER_IPCHECK) &&
!mem_comp(p.m_pData, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK)))
{
char *pAddr = (char*)p.m_pData + sizeof(BANMASTER_IPCHECK);
NETADDR CheckAddr;
if(net_addr_from_str(&CheckAddr, pAddr))
{
dbg_msg("banmaster", "dropped weird message ip=%d.%d.%d.%d checkaddr='%s'",
p.m_Address.ip[0], p.m_Address.ip[1], p.m_Address.ip[2], p.m_Address.ip[3], pAddr);
}
else
{
int Banned = SendResponse(&p.m_Address, &CheckAddr);
dbg_msg("banmaster", "responded to checkmsg ip=%d.%d.%d.%d checkaddr=%d.%d.%d.%d result=%s",
p.m_Address.ip[0], p.m_Address.ip[1], p.m_Address.ip[2], p.m_Address.ip[3],
CheckAddr.ip[0], CheckAddr.ip[1], CheckAddr.ip[2], CheckAddr.ip[3], (Banned) ? "ban" : "ok");
}
}
}
if(time_get() - LastUpdate > time_freq() * BAN_REREAD_TIME)
{
ClearBans();
LastUpdate = time_get();
m_pConsole->ExecuteFile(BANMASTER_BANFILE);
}
// be nice to the CPU
thread_sleep(1);
}
return 0;
}
示例4: main
int main(int argc, char **argv) // ignore_convention
{
NETADDR BindAddr;
dbg_logger_stdout();
net_init();
mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.type = NETTYPE_ALL;
BindAddr.port = VERSIONSRV_PORT;
if(!g_NetOp.Open(BindAddr, 0))
{
dbg_msg("mastersrv", "couldn't start network");
return -1;
}
BuildPackets();
ReadNews();
ReadServerList();
dbg_msg("versionsrv", "started");
while(1)
{
g_NetOp.Update();
// process packets
CNetChunk Packet;
while(g_NetOp.Recv(&Packet))
{
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETVERSION) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETVERSION, sizeof(VERSIONSRV_GETVERSION)) == 0)
{
SendVer(&Packet.m_Address);
char aAddrStr[NETADDR_MAXSTRSIZE];
net_addr_str(&Packet.m_Address, aAddrStr, sizeof(aAddrStr), false);
dbg_msg("versionsrv", "version request by %s", aAddrStr);
}
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETNEWS) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETNEWS, sizeof(VERSIONSRV_GETNEWS)) == 0)
{
SendNews(&Packet.m_Address);
}
if(Packet.m_DataSize == sizeof(VERSIONSRV_GETMAPLIST) &&
mem_comp(Packet.m_pData, VERSIONSRV_GETMAPLIST, sizeof(VERSIONSRV_GETMAPLIST)) == 0)
{
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = Packet.m_Address;
p.m_Flags = NETSENDFLAG_CONNLESS;
for(int i = 0; i < m_NumPackets; i++)
{
p.m_DataSize = m_aPackets[i].m_Size;
p.m_pData = &m_aPackets[i].m_Data;
g_NetOp.Send(&p);
}
}
if(m_ServerListLoaded &&
Packet.m_DataSize == sizeof(VERSIONSRV_GETDDNETLIST) + 4 &&
mem_comp(Packet.m_pData, VERSIONSRV_GETDDNETLIST, sizeof(VERSIONSRV_GETDDNETLIST)) == 0)
{
char aToken[4];
mem_copy(aToken, (char*)Packet.m_pData+sizeof(VERSIONSRV_GETDDNETLIST), 4);
SendServerList(&Packet.m_Address, aToken);
}
}
// wait for input
net_socket_read_wait(g_NetOp.m_Socket, 1000000);
}
return 0;
}
示例5: main
int main(int argc, char **argv) // ignore_convention
{
int64 LastBuild = 0;
NETADDR BindAddr;
dbg_logger_stdout();
net_init();
mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.port = MASTERSERVER_PORT;
m_NetOp.Open(BindAddr, 0);
BindAddr.port = MASTERSERVER_PORT+1;
m_NetChecker.Open(BindAddr, 0);
// TODO: check socket for errors
//mem_copy(data.header, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST));
mem_copy(m_CountData.m_Header, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT));
dbg_msg("mastersrv", "started");
while(1)
{
m_NetOp.Update();
m_NetChecker.Update();
// process m_aPackets
CNetChunk Packet;
while(m_NetOp.Recv(&Packet))
{
if(Packet.m_DataSize == sizeof(SERVERBROWSE_HEARTBEAT)+2 &&
mem_comp(Packet.m_pData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT)) == 0)
{
NETADDR Alt;
unsigned char *d = (unsigned char *)Packet.m_pData;
Alt = Packet.m_Address;
Alt.port =
(d[sizeof(SERVERBROWSE_HEARTBEAT)]<<8) |
d[sizeof(SERVERBROWSE_HEARTBEAT)+1];
// add it
AddCheckserver(&Packet.m_Address, &Alt);
}
else if(Packet.m_DataSize == sizeof(SERVERBROWSE_GETCOUNT) &&
mem_comp(Packet.m_pData, SERVERBROWSE_GETCOUNT, sizeof(SERVERBROWSE_GETCOUNT)) == 0)
{
dbg_msg("mastersrv", "count requested, responding with %d", m_NumServers);
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = Packet.m_Address;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_DataSize = sizeof(m_CountData);
p.m_pData = &m_CountData;
m_CountData.m_High = (m_NumServers>>8)&0xff;
m_CountData.m_Low = m_NumServers&0xff;
m_NetOp.Send(&p);
}
else if(Packet.m_DataSize == sizeof(SERVERBROWSE_GETLIST) &&
mem_comp(Packet.m_pData, SERVERBROWSE_GETLIST, sizeof(SERVERBROWSE_GETLIST)) == 0)
{
// someone requested the list
dbg_msg("mastersrv", "requested, responding with %d m_aServers", m_NumServers);
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = Packet.m_Address;
p.m_Flags = NETSENDFLAG_CONNLESS;
for(int i = 0; i < m_NumPackets; i++)
{
p.m_DataSize = m_aPackets[i].m_Size;
p.m_pData = &m_aPackets[i].m_Data;
m_NetOp.Send(&p);
}
}
}