//配置信息 bool CClientKernel::OnIPCConfig(const IPC_Head * pHead, const void * pIPCBuffer, WORD wDataSize, HWND hWndSend) { switch (pHead->wSubCmdID) { case IPC_SUB_SERVER_INFO: //房间信息 { //效验参数 if (wDataSize<sizeof(IPC_GF_ServerInfo)) return false; //处理数据 IPC_GF_ServerInfo * pServerInfo=(IPC_GF_ServerInfo *)pIPCBuffer; m_wTableID=pServerInfo->wTableID; m_wChairID=pServerInfo->wChairID; m_dwUserID=pServerInfo->dwUserID; m_ServerAttribute.wKindID=pServerInfo->wKindID; m_ServerAttribute.wServerID=pServerInfo->wServerID; m_ServerAttribute.wGameGenre=pServerInfo->wGameGenre; m_ServerAttribute.wChairCount=pServerInfo->wChairCount; m_ServerAttribute.dwVideoAddr=pServerInfo->dwVideoAddr; m_ServerAttribute.cbHideUserInfo=pServerInfo->cbHideUserInfo; lstrcpyn(m_ServerAttribute.szKindName,pServerInfo->szKindName,KIND_LEN); lstrcpyn(m_ServerAttribute.szServerName,pServerInfo->szServerName,SERVER_LEN); //更新标题 UpdateGameTitle(); return true; } } return false; }
//配置信息 bool CClientKernel::OnIPCConfig(const IPC_Head * pHead, const void * pIPCBuffer, WORD wDataSize, HWND hWndSend) { ASSERT(pHead->wMainCmdID==IPC_MAIN_CONFIG); switch (pHead->wSubCmdID) { case IPC_SUB_SERVER_INFO: //房间信息 { //效验参数 ASSERT(wDataSize>=sizeof(IPC_GF_ServerInfo)); if (wDataSize<sizeof(IPC_GF_ServerInfo)) return false; //处理数据 IPC_GF_ServerInfo * pServerInfo=(IPC_GF_ServerInfo *)pIPCBuffer; m_wTableID=pServerInfo->wTableID; m_wChairID=pServerInfo->wChairID; m_dwUserID=pServerInfo->dwUserID; m_ServerAttribute.wKindID=pServerInfo->wKindID; m_ServerAttribute.wServerID=pServerInfo->wServerID; m_ServerAttribute.wGameGenre=pServerInfo->wGameGenre; m_ServerAttribute.wChairCount=pServerInfo->wChairCount; m_ServerAttribute.dwVideoAddr=pServerInfo->dwVideoAddr; m_ServerAttribute.cbHideUserInfo=pServerInfo->cbHideUserInfo; lstrcpyn(m_ServerAttribute.szKindName,pServerInfo->szKindName,CountArray(m_ServerAttribute.szKindName)); lstrcpyn(m_ServerAttribute.szServerName,pServerInfo->szServerName,CountArray(m_ServerAttribute.szServerName)); //设置视频 CVideoServiceManager * pVideoServiceManager=CVideoServiceManager::GetInstance(); if ( pVideoServiceManager!=NULL) pVideoServiceManager->SetVideoServiceInfo(pServerInfo->dwUserID,htonl(pServerInfo->dwVideoAddr),PORT_VIDEO_SERVER); //更新标题 UpdateGameTitle(); return true; } } return false; }
//内核配置 bool __cdecl CClientKernel::InitClientKernel(LPCTSTR lpszComLine, IUnknownEx * pIUnknownEx) { //效验参数 ASSERT(lpszComLine!=NULL); if (lpszComLine==NULL) return false; //创建窗口 if (m_hWnd==NULL) { CRect rcCreate(0,0,0,0); Create(NULL,NULL,WS_CHILD,rcCreate,GetDesktopWindow(),100); } //获取框架 m_pIClientKernelSink=GET_OBJECTPTR_INTERFACE(pIUnknownEx,IClientKernelSink); if (m_pIClientKernelSink==NULL) return false; m_hWndGameFrame=m_pIClientKernelSink->GetFrameWnd(); //读取配置 m_bAllowUserLookon=AfxGetApp()->GetProfileInt(TEXT("GameOption"),TEXT("AllowLookon"),FALSE)?true:false; //视频设置 CVideoServiceManager * pVideoServiceManager=CVideoServiceManager::GetInstance(); if (pVideoServiceManager!=NULL) pVideoServiceManager->SetClientKernel(GET_OBJECTPTR_INTERFACE(this,IUnknownEx)); //命令行处理 if (lpszComLine[0]!=0) { //提出 TOKEN int nStringLength=0; CString strRoomToken; LPCTSTR pszRoomToken=TEXT("/RoomToken:"); LPCTSTR lpszBeginString=lpszComLine; while (true) { LPCTSTR lpszEndString=_tcschr(lpszBeginString,TEXT(' ')); nStringLength=(lpszEndString==NULL)?lstrlen(lpszBeginString):(int)(lpszEndString-lpszBeginString); //判断标识 const int nTokenLength=lstrlen(pszRoomToken); if ((nStringLength>=nTokenLength)&&(memcmp(lpszBeginString,pszRoomToken,nTokenLength*sizeof(TCHAR))==0)) { CopyMemory(strRoomToken.GetBufferSetLength(nStringLength-nTokenLength),lpszBeginString+nTokenLength, (nStringLength-nTokenLength)*sizeof(TCHAR)); strRoomToken.ReleaseBuffer(); break; } //设置变量 if (lpszEndString==NULL) break; lpszBeginString=(lpszEndString+1); } //共享内存 if (strRoomToken.GetLength()>0) { m_hShareMemory=OpenFileMapping(FILE_MAP_ALL_ACCESS,FALSE,strRoomToken); if (m_hShareMemory==NULL) return false; m_pShareMemory=(tagShareMemory *)MapViewOfFile(m_hShareMemory,FILE_MAP_ALL_ACCESS,0,0,0); if (m_pShareMemory==NULL) return false; if (m_pShareMemory->wDataSize<sizeof(tagShareMemory)) return false; m_pShareMemory->hWndGameFrame=m_hWndGameFrame; } //信道模块 if (m_hShareMemory!=NULL) { ASSERT(m_pShareMemory->hWndGameServer!=NULL); IUnknownEx * pIUnknownEx=GET_MYSELF_INTERFACE(IUnknownEx); if (m_ChannelServiceHelper.CreateInstance()==false) return false; if (m_ChannelServiceHelper->SetChannelMessageSink(pIUnknownEx)==false) return false; if (m_ChannelServiceHelper->CreateChannel(m_pShareMemory->hWndGameServer)==false) return false; } } //更新标题 UpdateGameTitle(); return true; }
//内核配置 bool CClientKernel::InitClientKernel(HWND hWnd, const std::string &CmdLine, CClientKernelSink* pIUnknownEx) { if (CmdLine.empty()) return false; //获取框架 m_hWndGameFrame=hWnd; m_pIClientKernelSink = pIUnknownEx; //创建窗口 if (m_hWndChannel==NULL) { WNDCLASS wc = { CS_HREDRAW | CS_VREDRAW, CClientKernel::ChannelWndProc, 0, 0, GetModuleHandle(0), LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "ChannelWND"}; RegisterClass(&wc); //创建窗口 m_hWndChannel = CreateWindowEx(0, "ChannelWND","ChannelWND",WS_CHILD,0,0,0,0,GetDesktopWindow(),0,GetModuleHandle(0),0); } //命令行处理 if (CmdLine.empty()!=true) { std::string::size_type pos1; std::string::size_type pos2; std::string szRoomToken; std::string szComLine(CmdLine); pos1 = szComLine.find("/RoomToken:"); if (pos1 != std::string::npos) { pos2 = szComLine.find_first_of("/", pos1+10); szRoomToken = szComLine.substr(pos1+11, pos2-pos1-12); } //共享内存 if (!szRoomToken.empty()) { m_hShareMemory=OpenFileMapping(FILE_MAP_ALL_ACCESS,FALSE,szRoomToken.c_str()); if (m_hShareMemory==NULL) return false; m_pShareMemory=(tagShareMemory *)MapViewOfFile(m_hShareMemory,FILE_MAP_ALL_ACCESS,0,0,0); if (m_pShareMemory==NULL) return false; if (m_pShareMemory->wDataSize<sizeof(tagShareMemory)) return false; m_pShareMemory->hWndGameFrame=m_hWndGameFrame; m_hWndGameServer = m_pShareMemory->hWndGameServer; SendData(IPC_MIAN_IPC_KERNEL,IPC_SUB_IPC_CLIENT_CONNECT); } } //更新标题 UpdateGameTitle(); return true; }