Exemplo n.º 1
0
//初始化
bool __cdecl CTableFrame::InitTableFrame(WORD wTableID, tagTableFrameParameter * pTableFrameParameter)
{
	//效验参数
	ASSERT(pTableFrameParameter!=NULL);

	//设置变量
	m_wTableID=wTableID;
	m_pGameServiceAttrib=pTableFrameParameter->pGameServiceAttrib;
	m_pGameServiceOption=pTableFrameParameter->pGameServiceOption;
	m_wChairCount=pTableFrameParameter->pGameServiceAttrib->wChairCount;

	//查询接口
	m_pIGameServiceFrame=GET_OBJECTPTR_INTERFACE(pTableFrameParameter->pIGameServiceFrame,IGameServiceFrame);
	ASSERT(m_pIGameServiceFrame!=NULL);
	if (m_pIGameServiceFrame==NULL) return false;

	//创建桌子
	IGameServiceManager * pIGameServiceManager=GET_OBJECTPTR_INTERFACE(pTableFrameParameter->pIGameServiceManager,IGameServiceManager);
	m_pITableFrameSink=(ITableFrameSink *)pIGameServiceManager->CreateTableFrameSink(IID_ITableFrameSink,VER_ITableFrameSink);
	ASSERT(m_pITableFrameSink!=NULL);
	if (m_pITableFrameSink==NULL) return false;

	//设置接口
	IUnknownEx * pIUnknownEx=GET_MYSELF_INTERFACE(IUnknownEx);
	if (m_pITableFrameSink->InitTableFrameSink(pIUnknownEx)==false) return false;

	//扩展接口
	m_pITableFrameEvent=GET_OBJECTPTR_INTERFACE(m_pITableFrameSink,ITableFrameEvent);

	return true;
}
Exemplo n.º 2
0
//启动事件
bool __cdecl CCenterSocket::OnAsynchronismEngineStart()
{
	//效验参数
	GT_ASSERT(m_pIEventService!=NULL);
	GT_ASSERT(m_pIQueueService!=NULL);
	GT_ASSERT(m_pIAsynchronismEngine!=NULL);

	//连接对象
	if (m_ClientSocketHelper.GetInterface()==NULL)
	{
		//创建对象
		bool bSuccess=m_ClientSocketHelper.CreateInstance();
		if (bSuccess==false)
		{
			GT_ASSERT(m_pIEventService!=NULL);
			m_pIEventService->ShowEventNotify(TEXT("中心服务器连接对象创建失败"),Level_Exception);
			return false;
		}

		//设置接口
		IClientSocketSink * pIClientSocketSink=GET_MYSELF_INTERFACE(IClientSocketSink);
		GT_ASSERT(pIClientSocketSink!=NULL);
		if (m_ClientSocketHelper->SetSocketSink(pIClientSocketSink)==false)
		{
			GT_ASSERT(m_pIEventService!=NULL);
			m_pIEventService->ShowEventNotify(TEXT("中心服务器连接对象回调接口设置失败"),Level_Exception);
			return false;
		}
	}

	return true;
}
Exemplo n.º 3
0
//启动服务
bool __cdecl CDataBaseEngine::StartService()
{
	//判断状态
	if (m_bService==true) 
	{
		CEventTrace::ShowEventNotify(TEXT("数据库引擎重复启动,启动操作忽略"),Level_Warning);
		return true;
	}

	//外挂接口
	if (m_pIDataBaseSink==NULL)
	{
		CEventTrace::ShowEventNotify(TEXT("数据库引擎外挂服务不存在"),Level_Exception);
		return false;
	}

	//设置队列
	if (m_RequestQueueService.SetQueueServiceSink(GET_MYSELF_INTERFACE(IUnknownEx))==false)
	{
		CEventTrace::ShowEventNotify(TEXT("数据库引擎与队列服务绑定失败"),Level_Exception);
		return false;
	}

	//启动外挂
	if (m_pIDataBaseSink->StartService(GET_MYSELF_INTERFACE(IUnknownEx))==false)
	{
		CEventTrace::ShowEventNotify(TEXT("数据库引擎外挂服务启动失败"),Level_Exception);
		return false;
	}

	//启动队列
	if (m_RequestQueueService.StartService()==false)
	{
		CEventTrace::ShowEventNotify(TEXT("数据库引擎队列服务启动失败"),Level_Exception);
		return false;
	}

	//设置变量
	m_bService=true;

	return true;
}
Exemplo n.º 4
0
//设置错误
void CADOError::SetErrorInfo(enADOErrorType enErrorType, LPCTSTR pszDescribe)
{
	//设置错误
	m_enErrorType=enErrorType;
	m_strErrorDescribe=pszDescribe;

	//抛出错误
	throw GET_MYSELF_INTERFACE(IADOError);

	return;
}
Exemplo n.º 5
0
//构造函数
CChannelService::CChannelService()
{
	//设置变量
	m_hWndServer=NULL;
	m_pIChannelEventSink=NULL;
	m_pIChannelMessageSink=NULL;

	//设置接口
	m_IPCRecvCopyData.SetChannelMessageSink(GET_MYSELF_INTERFACE(IUnknownEx));

	return;
}
Exemplo n.º 6
0
//关闭连接
bool CCenterSocket::CloseSocket(bool bNotify)
{
	//构造数据
	tagReqCloseSocket ReqCloseSocket;
	ReqCloseSocket.bNotify=bNotify;

	//投递请求
	GT_ASSERT(m_pIAsynchronismEngine!=NULL);
	IUnknownEx * pIUnknownEx=GET_MYSELF_INTERFACE(IUnknownEx);
	m_pIAsynchronismEngine->InsertRequest(IREQ_CLOSE_SOCKET,&ReqCloseSocket,sizeof(ReqCloseSocket),pIUnknownEx);

	return true;
}
Exemplo n.º 7
0
//连接服务器
bool CCenterSocket::Connect(DWORD dwServerIP, WORD wPort)
{
	//构造数据
	tagReqConnect ReqConnect;
	ReqConnect.wPort=wPort;
	ReqConnect.dwServerIP=dwServerIP;

	//投递请求
	GT_ASSERT(m_pIAsynchronismEngine!=NULL);
	IUnknownEx * pIUnknownEx=GET_MYSELF_INTERFACE(IUnknownEx);
	m_pIAsynchronismEngine->InsertRequest(IREQ_CONNECT,&ReqConnect,sizeof(ReqConnect),pIUnknownEx);

	return true;
}
Exemplo n.º 8
0
//停止服务
bool __cdecl CDataBaseEngine::StopService()
{
	//设置变量
	m_bService=false;

	//停止请求队列
	m_RequestQueueService.StopService();

	//停止外挂
	if (m_pIDataBaseSink!=NULL)
	{
		m_pIDataBaseSink->StopService(GET_MYSELF_INTERFACE(IUnknownEx));
	}

	return true;
}
Exemplo n.º 9
0
BOOL CGameClientDlg::OnInitDialog()
{
	__super::OnInitDialog();

	//设置属性
	ModifyStyle(WS_CAPTION|WS_BORDER,0,0);

	m_bAllowSound=AfxGetApp()->GetProfileInt(TEXT("GameOption"),TEXT("EnableSound"),TRUE)?true:false;

	//创建游戏视图
	CRect rcGameView;
	m_GameClientView.Create(NULL,NULL,WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,rcGameView,this,10);

	//创建组件
	if (m_UserFaceResHelper.CreateInstance()==false) throw TEXT("头像组件加载失败");
	if (m_ClientKernelHelper.CreateInstance()==false) throw TEXT("游戏框架内核模块加载失败");

	//初始化内核
	CWinApp *p=AfxGetApp();
	LPCTSTR lpszCmdLine=AfxGetApp()->m_lpCmdLine;
	IUnknownEx * pIUnknownEx=GET_MYSELF_INTERFACE(IUnknownEx);
	bool bSuccess=m_ClientKernelHelper->InitClientKernel(lpszCmdLine,pIUnknownEx);
	if (bSuccess==false) throw TEXT("游戏框架逻辑模块初始化失败");

	IUnknownEx * pIMessageProxy = GET_OBJECT_INTERFACE(m_GameClientView.m_MyListView,IUnknownEx);
	bSuccess=m_ClientKernelHelper->SetMessageProxy(pIMessageProxy);
	if (bSuccess==false) throw TEXT("获取消息输出模块失败");

	//初始化游戏
	m_GameClientView.m_MyListView.SetClientKernel(m_ClientKernelHelper.GetInterface());
	if (InitGameFrame()==false) throw TEXT("游戏框架初始化失败");

	//显示窗口
	m_bInitDialog=true;
	m_GameClientView.ShowWindow(SW_SHOW);

	//显示窗口
	if (GetSystemMetrics(SM_CXSCREEN)>1024)
	{
		MoveWindow(0,0,1024,748,FALSE);
		CenterWindow(NULL);
	}
	else MaxSizeWindow();
	ShowWindow(SW_SHOW);

	return TRUE;
}
Exemplo n.º 10
0
//发送函数
bool CCenterSocket::SendData(WORD wMainCmdID, WORD wSubCmdID, void * pData, WORD wDataSize)
{
	//构造数据
	tagReqSendData ReqSendData;
	ReqSendData.wMainCmdID=wMainCmdID;
	ReqSendData.wSubCmdID=wSubCmdID;
	ReqSendData.wDataSize=wDataSize;
	if (wDataSize>0)
	{
		GT_ASSERT(wDataSize<=sizeof(ReqSendData.cbDataBuffer));
		if (wDataSize>sizeof(ReqSendData.cbDataBuffer)) return false;
		CopyMemory(ReqSendData.cbDataBuffer,pData,wDataSize);
	}

	//投递请求
	GT_ASSERT(m_pIAsynchronismEngine!=NULL);
	IUnknownEx * pIUnknownEx=GET_MYSELF_INTERFACE(IUnknownEx);
	WORD wSendSize=sizeof(ReqSendData)-sizeof(ReqSendData.cbDataBuffer)+ReqSendData.wDataSize;
	m_pIAsynchronismEngine->InsertRequest(IREQ_SEND_DATA,&ReqSendData,wSendSize,pIUnknownEx);

	return true;
}
Exemplo n.º 11
0
//连接服务器
bool CRequestSocket::Connect(DWORD dwServerIP, WORD wPort)
{
	CloseSocket(false);

	//连接对象
	if (m_ClientSocketHelper.GetInterface()==NULL)
	{
		//创建对象
		bool bSuccess=m_ClientSocketHelper.CreateInstance();
		if (bSuccess==false)
		{
			GT_ASSERT(m_pIEventService!=NULL);
			TCHAR szDescribe[128]=TEXT("");
			_snprintf(szDescribe,sizeof(szDescribe),TEXT("【服务ID %ld】CenterServer连接对象创建失败"),(LONG)m_pInitParamter->m_wServerID);
			m_pIEventService->ShowEventNotify(szDescribe,Level_Exception);
			return false;
		}

		//设置接口
		IClientSocketSink * pIClientSocketSink=GET_MYSELF_INTERFACE(IClientSocketSink);
		GT_ASSERT(pIClientSocketSink!=NULL);
		if (m_ClientSocketHelper->SetSocketSink(pIClientSocketSink)==false)
		{
			GT_ASSERT(m_pIEventService!=NULL);
			TCHAR szDescribe[128]=TEXT("");
			_snprintf(szDescribe,sizeof(szDescribe),TEXT("【服务ID %ld】CenterServer连接对象回调接口设置失败"),(LONG)m_pInitParamter->m_wServerID);
			m_pIEventService->ShowEventNotify(szDescribe,Level_Exception);
			return false;

		}
	}

	//请求处理
	GT_ASSERT(m_ClientSocketHelper.GetInterface()!=NULL);
	return m_ClientSocketHelper->Connect(dwServerIP,wPort);
}
Exemplo n.º 12
0
//内核配置
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;
}
Exemplo n.º 13
0
//启动服务
bool __cdecl CTCPSocketEngine::StartService()
{
	DWORD i = 0;
	//效验状态
	if (m_bService==true) 
	{
		CEventTrace::ShowEventNotify(TEXT("网络引擎重复启动,启动操作忽略"),Level_Warning);
		return true;
	}

	//判断端口
	if (m_wListenPort==0)
	{
		CEventTrace::ShowEventNotify(TEXT("网络引擎监听端口无效"),Level_Exception);
		return false;
	}

	//绑定对象
	if (m_SendQueueService.SetQueueServiceSink(GET_MYSELF_INTERFACE(IUnknownEx))==false)
	{
		CEventTrace::ShowEventNotify(TEXT("网络引擎与触发服务绑定失败"),Level_Exception);
		return false;
	}

	try
	{
		//获取系统信息
		SYSTEM_INFO SystemInfo;
		GetSystemInfo(&SystemInfo);
		DWORD dwThreadCount=SystemInfo.dwNumberOfProcessors;

		//建立完成端口
		m_hCompletionPort=CreateIoCompletionPort(INVALID_HANDLE_VALUE,NULL,NULL,SystemInfo.dwNumberOfProcessors);
		if (m_hCompletionPort==NULL) throw TEXT("网络引擎完成端口创建失败");

		//建立监听SOCKET
		struct sockaddr_in SocketAddr;
		memset(&SocketAddr,0,sizeof(SocketAddr));
		SocketAddr.sin_addr.s_addr=INADDR_ANY;
		SocketAddr.sin_family=AF_INET;
		SocketAddr.sin_port=htons(m_wListenPort);
		m_hServerSocket=WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,0,WSA_FLAG_OVERLAPPED);
		if (m_hServerSocket==INVALID_SOCKET) throw TEXT("网络引擎监听 SOCKET 创建失败");
		int iErrorCode=bind(m_hServerSocket,(SOCKADDR*)&SocketAddr,sizeof(SocketAddr));
		if (iErrorCode==SOCKET_ERROR) throw TEXT("网络引擎监听端口被占用,端口绑定失败");
		iErrorCode=listen(m_hServerSocket,200);
		if (iErrorCode==SOCKET_ERROR) throw TEXT("网络引擎监听端口被占用,端口监听失败");

		//启动发送队列
		bool bSuccess=m_SendQueueService.StartService();
		if (bSuccess==false) throw TEXT("网络引擎发送队列服务启动失败");

		//建立读写线程
		for (i=0;i<dwThreadCount;i++)
		{
			CServerSocketRSThread * pServerSocketRSThread=new CServerSocketRSThread();
			if (pServerSocketRSThread==NULL) throw TEXT("网络引擎读写线程服务创建失败");
			bSuccess=pServerSocketRSThread->InitThread(m_hCompletionPort);
			if (bSuccess==false) throw TEXT("网络引擎读写线程服务配置失败");
			m_SocketRSThreadArray.Add(pServerSocketRSThread);
		}

		//建立应答线程
		bSuccess=m_SocketAcceptThread.InitThread(m_hCompletionPort,m_hServerSocket,this);
		if (bSuccess==false) throw TEXT("网络引擎网络监听线程服务配置");

		//运行读写线程
		for (i=0;i<dwThreadCount;i++)
		{
			CServerSocketRSThread * pServerSocketRSThread=m_SocketRSThreadArray[i];
			ASSERT(pServerSocketRSThread!=NULL);
			bSuccess=pServerSocketRSThread->StartThead();
			if (bSuccess==false) throw TEXT("网络引擎读写线程服务启动失败");
		}

		//网络检测线程
		m_SocketDetectThread.InitThread(this);
		bSuccess=m_SocketDetectThread.StartThead();
		if (bSuccess==false) throw TEXT("网络引检测线程服务启动失败");

		//运行应答线程
		bSuccess=m_SocketAcceptThread.StartThead();
		if (bSuccess==false) throw TEXT("网络引擎监听线程服务启动失败");

		//设置变量
		m_bService=true;
	}
	catch (LPCTSTR pszError)
	{
		CEventTrace::ShowEventNotify(pszError,Level_Exception);
		return false;
	}

	return true;
}
Exemplo n.º 14
0
//构造函数
CCompanionManager::CCompanionManager(void)
{
	m_bNeedUpdate=false;
	m_DlgCompanionManager.SetCompanionManager(GET_MYSELF_INTERFACE(IUnknownEx));
	return;
}