本文整理汇总了C++中CNetClient类的典型用法代码示例。如果您正苦于以下问题:C++ CNetClient类的具体用法?C++ CNetClient怎么用?C++ CNetClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CNetClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ENSURE
bool CNetClient::OnGameStart(void* context, CFsmEvent* event)
{
ENSURE(event->GetType() == (uint)NMT_GAME_START);
CNetClient* client = (CNetClient*)context;
JSContext* cx = client->GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
// Find the player assigned to our GUID
int player = -1;
if (client->m_PlayerAssignments.find(client->m_GUID) != client->m_PlayerAssignments.end())
player = client->m_PlayerAssignments[client->m_GUID].m_PlayerID;
client->m_ClientTurnManager = new CNetClientTurnManager(
*client->m_Game->GetSimulation2(), *client, client->m_HostID, client->m_Game->GetReplayLogger());
client->m_Game->SetPlayerID(player);
client->m_Game->StartGame(&client->m_GameAttributes, "");
JS::RootedValue msg(cx);
client->GetScriptInterface().Eval("({'type':'start'})", &msg);
client->PushGuiMessage(msg);
return true;
}
示例2: LinkedGameServer
void LoginLayerUC::LinkedGameServer(const Server& server)
{
CNetClient *tcp = CNetClient::getShareInstance();
tcp->setAddress(server.server_host().c_str(), server.server_port(),true);
if (!tcp->isConnected()&&!tcp->getIsCloseConn())
{
tcp->connect();
}
}
示例3: SocketEventCB
INT32 CNetClient::SocketEventCB(ISocketChannel* pChn, void* pCaller, enumNetEventType iEvent, void* pData, UINT32 iDataLen)
{
CNetClient* pCli;
pCli = (CNetClient*)pCaller;
if(NULL == pCli)
{
return -1;
}
return pCli->OnSocketEvent(pChn, iEvent, pData, iDataLen);
}
示例4: directConnectGameServer
//连接网关服务器,连接成功后,网关服务器会自动推送服务器列表的消息过来
void LoginLayerUC::LinkedServerListNet()
{
#if DIRECT_CONNECT_GAMESERVER
directConnectGameServer();
return;
#endif
GateServer gateServer = LoginScene::getGateServer();
CNetClient *tcp = CNetClient::getShareInstance();
tcp->setAddress(gateServer.sHost.c_str(), gateServer.iPort,false);
if (!tcp->isConnected())
{
tcp->connect();
}
}
示例5:
CTcpConnection* CNetServer::ConnectNew(CTcpContext* pContext)
{
if (!pContext)
return nullptr;
CNetClient* pClient = m_mapClient.allocate(pContext);
if (pClient)
{
pClient->initialize();
pClient->bindContext(pContext);
}
return pClient;
}
示例6: PlayEffectSound
void LoginLayerUC::selectServer( CCObject* pObj )
{
PlayEffectSound(SFX_Button);
CImageView* pImageView = (CImageView*)pObj;
if(m_iSelectServerIndex != pImageView->getParent()->getTag())
{
m_iSelectServerIndex = pImageView->getParent()->getTag();
CNetClient *tcp = CNetClient::getShareInstance();
if (tcp->isConnected())
{
tcp->close();
}
}
updateSelectServer();
hideServerList();
}
示例7: ClientThread
DWORD CNetClient::ClientThread(LPVOID pParam){
CNetClient * pThis = (CNetClient *)pParam;
BOOL bRet = TRUE;
while (bRet)
{
//首先接收数据包的包头
VODHEADER header = { 0 };
bRet = pThis->RecvData( &header,sizeof(header));
//根据ID判断,应该执行何种操作
switch (header.dwCmd)
{
case VODNETCMD_LOGIN://处理登录
bRet = pThis->OnLogin();
break;
case VODNETCMD_MEDIADATA://处理影片文件下载的
bRet = pThis->OnMediaData();
break;
case VODNETCMD_TYPES://处理返回所有媒体类型
bRet=pThis->OnAllVideoTypes();
break;
case VODNETCMD_GETVIDES://处理返回指定类型所有影片的
bRet=pThis->OnVideosByTypeID();
default:
break;
}
}
closesocket(pThis->m_hClientSocket);
return 0;
}
示例8: 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;
}
}
示例9: 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;
}
示例10: 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;
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}