Пример #1
0
//停止服务
bool CLogonService::StopService()
{
	try
	{
		if (m_ServiceEngine.GetInterface()!=NULL) 
		{
			//停止服务
			m_ServiceEngine->StopService();
		
			//获取异步引擎
			IAsynchronismEngine * pIAsynchronismEngine=(IAsynchronismEngine *)m_ServiceEngine->GetAsynchronismEngine(IID_IAsynchronismEngine,VER_IAsynchronismEngine);
			ASSERT(pIAsynchronismEngine!=NULL);
			if (pIAsynchronismEngine==NULL) return false;

			//注销组件
			IAsynchronismEngineSink * pIAsynchronismEngineSink=GET_OBJECT_INTERFACE(m_CenterSocket,IAsynchronismEngineSink);
			pIAsynchronismEngine->UnRegisterAsynchronismEngineSink(pIAsynchronismEngineSink);
		}

		return true;
	}
	catch (LPCTSTR pszErrorMsg)
	{
		TraceEventString(pszErrorMsg,Level_Exception); 
		TraceEventString(TEXT("登录服务停止失败"),Level_Exception); 
	}
	catch (...)
	{ 
		TraceEventString(TEXT("登录服务停止失败"),Level_Exception); 
	}

	return false;
}
Пример #2
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;
}
Пример #3
0
//启动服务
bool __cdecl CServiceEngine::StartService(BYTE cbDBThreadCount,
										  BYTE cbAttemperThreadCount)
{
	//判断状态
	if (m_bService==true)
	{
		CEventTrace::ShowEventNotify(TEXT("服务引擎重复启动,启动操作忽略"),Level_Warning);
		return true;
	}

	//接口查询
	IUnknownEx * pISocketEngine=GET_OBJECT_INTERFACE(m_TCPSocketEngine,IUnknownEx);
	IUnknownEx * pIAttemperEngine=(IUnknownEx *)m_AttemperEngine.GetQueueService(IID_IUnknownEx,VER_IUnknownEx);

	//绑定组件
	if (m_AttemperEngine.SetSocketEngine(pISocketEngine)==false)
	{
		CEventTrace::ShowEventNotify(TEXT("网络引擎与调度引擎绑定失败"),Level_Exception);
		return false;
	}
	if (m_TimerEngine.SetTimerEngineSink(pIAttemperEngine)==false)
	{
		CEventTrace::ShowEventNotify(TEXT("定时器引擎与调度引擎绑定失败"),Level_Exception);
		return false;
	}
	if (m_TCPSocketEngine.SetSocketEngineSink(pIAttemperEngine)==false)
	{
		CEventTrace::ShowEventNotify(TEXT("网络引擎与调度引擎绑定失败"),Level_Exception);
		return false;
	}

	//启动引擎服务
	if (m_TimerEngine.StartService()==false) return false;
	if (m_DataBaseEngine.StartService(cbDBThreadCount)==false) return false;
	if (m_AsynchronismEngine.StartService()==false) return false;
	if (m_AttemperEngine.StartService(cbAttemperThreadCount)==false) return false;
	if (m_TCPSocketEngine.StartService()==false) return false;

	//设置变量
	m_bService=true;

	return true;
}
Пример #4
0
//开始服务
bool CCenterService::BeginService()
{
	try
	{
		//变量定义
		bool bSuccess=false;

		//创建服务对象
		if (m_ServiceEngine.IsValid()==false)
		{
			if (m_ServiceEngine.CreateInstance()==false) 
			{
				throw m_ServiceEngine.GetErrorMessage();
			}
			if (m_pIEventService!=NULL) 
			{
				m_ServiceEngine->SetEventService(m_pIEventService);
			}

			//注册调度外挂服务
			IUnknownEx * pIAttemperEngine=GET_OBJECT_INTERFACE(m_AttemperSink,IUnknownEx);
			if (m_ServiceEngine->SetAttemperEngineSink(pIAttemperEngine)==false) 
			{
				TraceEventString(TEXT("注册调度外挂服务失败"),Level_Exception); 
				throw 0;
			}

			//注册数据库外挂服务
			IUnknownEx * pIDataBaseSink=GET_OBJECT_INTERFACE(m_DataBaseSink,IUnknownEx);
			if (m_ServiceEngine->SetDataBaseSink(pIDataBaseSink)==false) 
			{
				TraceEventString(TEXT("注册数据库外挂服务失败"),Level_Exception); 
				throw 0;
			}
		}

		//判断状态
		if (m_ServiceEngine->IsService()==true)
		{
			TraceEventString(TEXT("中心服务已经了启动了"),Level_Warning);
			return true;
		}

		//配置服务
		m_InitParamter.LoadInitParamter();
		if (m_DataBaseSink.InitDataBaseSink(&m_InitParamter,m_ServiceEngine.GetInterface())==false) 
		{
			throw 0;
		}
		if (m_AttemperSink.InitAttemperSink(&m_InitParamter,m_ServiceEngine.GetInterface())==false) 
		{
			throw 0;
		}
		if (m_ServiceEngine->InitServiceEngine(m_InitParamter.m_wListenPort,m_InitParamter.m_wMaxConnect)==false) 
		{
			throw 0;
		}

		//启动服务
		if (m_ServiceEngine->BeginService()==false) 
		{
			throw 0;
		}

		return true;
	}
	catch (LPCTSTR pszErrorMsg)
	{
		TraceEventString(pszErrorMsg,Level_Exception); 
		TraceEventString(TEXT("中心服务启动失败"),Level_Exception); 
		EndService();
	}
	catch (...)
	{ 
		TraceEventString(TEXT("中心服务启动失败"),Level_Exception); 
		EndService();
	}

	return false;
}
Пример #5
0
//初始化函数
BOOL CGamePlazaApp::InitInstance()
{
	__super::InitInstance();

	//判断是否重入
#ifndef ADMIN_PLAZA
#ifndef _DEBUG
	bool bExistIGame=false;
	CMutex Mutex(FALSE,MAIN_DLG_CLASSNAME,NULL);
	if (Mutex.Lock(0)==FALSE) bExistIGame=true;
	CWnd * pIGameWnd=CWnd::FindWindow(MAIN_DLG_CLASSNAME,NULL);
	if (pIGameWnd!=NULL) 
	{
		bExistIGame=true;
		if (pIGameWnd->IsIconic()) pIGameWnd->ShowWindow(SW_RESTORE);
		pIGameWnd->SetActiveWindow();
		pIGameWnd->BringWindowToTop();
		pIGameWnd->SetForegroundWindow();
	}
	if (bExistIGame==true) return FALSE;
#endif
#endif

	//程序初始化
	AfxOleInit();
	AfxInitRichEdit();
	AfxInitRichEdit2();
	InitCommonControls();
	AfxEnableControlContainer();

	//设置注册表
	SetRegistryKey(szSystemRegKey);

	//加载界面库
	CSkinAttribute::LoadSkinAttribute(GET_OBJECT_INTERFACE(m_SkinRecordFile,IUnknownEx));

	//加载配置
	g_GlobalOption.LoadOptionParameter();

	//全局信息
	if (g_GlobalUnits.InitGlobalUnits()==false)
	{
		AfxMessageBox(TEXT("游戏广场初始化失败,程序即将退出!"),MB_ICONSTOP);
		return FALSE;
	}

	//变量定义
	WNDCLASS WndClasss;
	ZeroMemory(&WndClasss,sizeof(WndClasss));

	//注册窗口
	WndClasss.style=CS_DBLCLKS;
	WndClasss.lpfnWndProc=DefWindowProc;
	WndClasss.lpszClassName=MAIN_DLG_CLASSNAME;
	WndClasss.hInstance=AfxGetInstanceHandle();
	WndClasss.hIcon=LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME));
	WndClasss.hCursor=LoadStandardCursor(MAKEINTRESOURCE(IDC_ARROW));
	if (AfxRegisterClass(&WndClasss)==FALSE) AfxThrowResourceException();

	//建立窗口
	CGameFrame * pMainFrame=new CGameFrame();
	pMainFrame->Create(MAIN_DLG_CLASSNAME,TEXT(""),WS_MINIMIZEBOX|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,CRect(0,0,0,0));
	m_pMainWnd=pMainFrame;

	return TRUE;
}
Пример #6
0
//初始化函数
BOOL CGamePlazaApp::InitInstance()
{
    __super::InitInstance();

    //判断是否重入
#ifndef ADMIN_PLAZA
#ifndef _DEBUG
    bool bExistIGame=false;
    CMutex Mutex(FALSE,MAIN_DLG_CLASSNAME,NULL);
    if (Mutex.Lock(0)==FALSE) bExistIGame=true;
    CWnd * pIGameWnd=CWnd::FindWindow(MAIN_DLG_CLASSNAME,NULL);
    if (pIGameWnd!=NULL)
    {
        bExistIGame=true;
        if (pIGameWnd->IsIconic()) pIGameWnd->ShowWindow(SW_RESTORE);
        pIGameWnd->SetActiveWindow();
        pIGameWnd->BringWindowToTop();
        pIGameWnd->SetForegroundWindow();
    }
    if (bExistIGame==true) return FALSE;
#endif
#endif

    DWORD d=MAKELONG(MAKEWORD(6,0),MAKEWORD(1,0));

    //程序初始化
    AfxOleInit();
    AfxInitRichEdit();
    AfxInitRichEdit2();
    InitCommonControls();
    AfxEnableControlContainer();

    //设置注册表
    SetRegistryKey(szSystemRegKey);

    //加载界面库
    CSkinAttribute::LoadSkinAttribute(GET_OBJECT_INTERFACE(m_SkinRecordFile,IUnknownEx));

    //加载配置
    g_GlobalOption.LoadOptionParameter();

    //全局信息
    if (g_GlobalUnits.InitGlobalUnits()==false)
    {
        AfxMessageBox(TEXT("游戏广场初始化失败,程序即将退出!"),MB_ICONSTOP);
        return FALSE;
    }

    //注册窗口类
    WNDCLASS WndClasss;
    memset(&WndClasss,0,sizeof(WndClasss));
    WndClasss.lpfnWndProc=::DefWindowProc;
    WndClasss.hInstance=AfxGetInstanceHandle();
    WndClasss.lpszClassName=MAIN_DLG_CLASSNAME;
    if (!AfxRegisterClass(&WndClasss)) AfxThrowResourceException();

    //建立窗口
    const DWORD dwStyte=WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED|WS_CLIPCHILDREN;
    CGameFrame * pMainFrame=new CGameFrame();
    pMainFrame->Create(MAIN_DLG_CLASSNAME,TEXT(""),dwStyte,CRect(0,0,0,0));
    m_pMainWnd=pMainFrame;

    return TRUE;
}
Пример #7
0
//开始服务
bool CLogonService::StartService()
{
	try
	{
		//变量定义
		bool bSuccess=false;

		//创建服务对象
		if (m_ServiceEngine.GetInterface()==false)
		{
			if (m_ServiceEngine.CreateInstance()==false) throw m_ServiceEngine.GetErrorMessage();
			if (m_pIEventService!=NULL) m_ServiceEngine->SetEventService(m_pIEventService);

			//注册调度外挂服务
			IUnknownEx * pIAttemperEngine=GET_OBJECT_INTERFACE(m_AttemperSink,IUnknownEx);
			if (m_ServiceEngine->SetAttemperEngineSink(pIAttemperEngine)==false) throw 0;

			//注册数据库外挂服务
			IUnknownEx * pIDataBaseSink=GET_OBJECT_INTERFACE(m_DataBaseSink,IUnknownEx);
			if (m_ServiceEngine->SetDataBaseSink(pIDataBaseSink)==false) throw 0;
		}

		//判断状态
		if (m_ServiceEngine->IsService()==true)
		{
			TraceEventString(TEXT("登录服务已经了启动了"),Level_Warning);
			return true;
		}

		//配置服务
		m_InitParamter.LoadInitParamter();
		if (m_DataBaseSink.InitDataBaseSink(&m_InitParamter,m_ServiceEngine.GetInterface())==false) throw 0;
		if (m_AttemperSink.InitAttemperSink(&m_InitParamter,&m_CenterSocket,m_ServiceEngine.GetInterface())==false) throw 0;
		if (m_ServiceEngine->InitServiceEngine(m_InitParamter.m_wListenPort,m_InitParamter.m_wMaxConnect)==false) throw 0;

		//获取调度引擎
		IAttemperEngine * pIAttemperEngine=(IAttemperEngine *)m_ServiceEngine->GetAttemperEngine(IID_IAttemperEngine,VER_IAttemperEngine);
		ASSERT(pIAttemperEngine!=NULL);
		if (pIAttemperEngine==NULL) throw TEXT("调度引擎接口查询失败");

		//获取调度队列
		IQueueService * pIQueueService=(IQueueService *)pIAttemperEngine->GetQueueService(IID_IQueueService,VER_IQueueService);
		ASSERT(pIQueueService!=NULL);
		if (pIQueueService==NULL) throw TEXT("调度引擎队列服务接口查询失败");

		//获取异步引擎
		IAsynchronismEngine * pIAsynchronismEngine=(IAsynchronismEngine *)m_ServiceEngine->GetAsynchronismEngine(IID_IAsynchronismEngine,VER_IAsynchronismEngine);
		ASSERT(pIAsynchronismEngine!=NULL);
		if (pIAsynchronismEngine==NULL) throw TEXT("异步引擎队务接口查询失败");

		//中心连接
		if (m_CenterSocket.SetQueueService(pIQueueService)==false) throw 0;
		if (m_CenterSocket.SetAsynchronismEngine(pIAsynchronismEngine)==false) throw 0;

		//注册对象
		IAsynchronismEngineSink * pIAsynchronismEngineSink=GET_OBJECT_INTERFACE(m_CenterSocket,IAsynchronismEngineSink);
		if (pIAsynchronismEngine->RegisterAsynchronismEngineSink(pIAsynchronismEngineSink)==false) throw TEXT("中心连接异步对象注册失败");

		//启动服务
		if (m_ServiceEngine->StartService()==false) throw 0;

		return true;
	}
	catch (LPCTSTR pszErrorMsg)
	{
		TraceEventString(pszErrorMsg,Level_Exception); 
		TraceEventString(TEXT("登录服务启动失败"),Level_Exception); 
		StopService();
	}
	catch (...)
	{ 
		TraceEventString(TEXT("登录服务启动失败"),Level_Exception); 
		StopService();
	}

	return false;
}