本文整理汇总了C++中CNetClient::Send方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetClient::Send方法的具体用法?C++ CNetClient::Send怎么用?C++ CNetClient::Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNetClient
的用法示例。
在下文中一共展示了CNetClient::Send方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendResponse
int SendResponse(NETADDR *pAddr, NETADDR *pCheck)
{
static char aIpBan[sizeof(BANMASTER_IPBAN) + 32 + 256] = { 0 };
static char *pIpBanContent = aIpBan + sizeof(BANMASTER_IPBAN);
if (!aIpBan[0])
mem_copy(aIpBan, BANMASTER_IPBAN, sizeof(BANMASTER_IPBAN));
static CNetChunk p;
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
CBan* pBan = CheckBan(pCheck);
if(pBan)
{
str_format(pIpBanContent, 32, "%d.%d.%d.%d", pCheck->ip[0], pCheck->ip[1], pCheck->ip[2], pCheck->ip[3]);
char *pIpBanReason = pIpBanContent + (str_length(pIpBanContent) + 1);
str_copy(pIpBanReason, pBan->m_aReason, 256);
p.m_pData = aIpBan;
p.m_DataSize = sizeof(BANMASTER_IPBAN) + str_length(pIpBanContent) + 1 + str_length(pIpBanReason) + 1;
m_Net.Send(&p);
return 1;
}
else
{
p.m_DataSize = sizeof(BANMASTER_IPOK);
p.m_pData = BANMASTER_IPOK;
m_Net.Send(&p);
return 0;
}
}
示例2: SendOk
void SendOk(NETADDR *pAddr)
{
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_DataSize = sizeof(SERVERBROWSE_FWOK);
p.m_pData = SERVERBROWSE_FWOK;
// send on both to be sure
m_NetChecker.Send(&p);
m_NetOp.Send(&p);
}
示例3: 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;
}
示例4: SendCheck
void SendCheck(NETADDR *pAddr)
{
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_DataSize = sizeof(SERVERBROWSE_FWCHECK);
p.m_pData = SERVERBROWSE_FWCHECK;
m_NetChecker.Send(&p);
}
示例5: SendError
void SendError(NETADDR *pAddr)
{
CNetChunk p;
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_DataSize = sizeof(SERVERBROWSE_FWERROR);
p.m_pData = SERVERBROWSE_FWERROR;
m_NetOp.Send(&p);
}
示例6: SendNews
void SendNews(NETADDR *pAddr)
{
CNetChunk p;
unsigned char aData[NEWS_SIZE + sizeof(VERSIONSRV_NEWS)];
mem_copy(aData, VERSIONSRV_NEWS, sizeof(VERSIONSRV_NEWS));
mem_copy(aData + sizeof(VERSIONSRV_NEWS), m_aNews, NEWS_SIZE);
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_pData = aData;
p.m_DataSize = sizeof(aData);
g_NetOp.Send(&p);
}
示例7: SendVer
void SendVer(NETADDR *pAddr)
{
CNetChunk p;
unsigned char aData[sizeof(VERSIONSRV_VERSION) + sizeof(GAME_RELEASE_VERSION)];
mem_copy(aData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION));
mem_copy(aData + sizeof(VERSIONSRV_VERSION), GAME_RELEASE_VERSION, sizeof(GAME_RELEASE_VERSION));
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_pData = aData;
p.m_DataSize = sizeof(aData);
g_NetOp.Send(&p);
}
示例8: SendServerList
// Packet: VERSIONSRV_DDNETLIST + char[4] Token + int16 comp_length + int16 plain_length + char[comp_length]
void SendServerList(NETADDR *pAddr, const char *Token)
{
CNetChunk p;
unsigned char aData[16384];
short WordCompLength = m_ServerListCompLength;
short WordPlainLength = m_ServerListPlainLength;
mem_copy(aData, VERSIONSRV_DDNETLIST, sizeof(VERSIONSRV_DDNETLIST));
mem_copy(aData + sizeof(VERSIONSRV_DDNETLIST), Token, 4); // send back token
mem_copy(aData + sizeof(VERSIONSRV_DDNETLIST)+4, &WordCompLength, 2); // compressed length
mem_copy(aData + sizeof(VERSIONSRV_DDNETLIST)+6, &WordPlainLength, 2); // plain length
mem_copy(aData + sizeof(VERSIONSRV_DDNETLIST)+8, m_aServerList, m_ServerListCompLength);
p.m_ClientID = -1;
p.m_Address = *pAddr;
p.m_Flags = NETSENDFLAG_CONNLESS;
p.m_pData = aData;
p.m_DataSize = sizeof(VERSIONSRV_DDNETLIST) + 4 + 2 + 2 + m_ServerListCompLength;
g_NetOp.Send(&p);
}
示例9: 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;
}
示例10: 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);
}
}
}