123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #include "stdafx.h"
- #include "AllSrvUI.h"
- #include "AllSrvUISheet.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CAllSrvUIApp theApp;
- BEGIN_MESSAGE_MAP(CAllSrvUIApp, CWinApp)
-
-
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- CAllSrvUIApp::CAllSrvUIApp() :
- m_hrCoInit(E_FAIL)
- {
- }
- void CAllSrvUIApp::GetArtPath(char * szArtPath)
- {
- strcpy(szArtPath, ".\\Artwork\\");
- CRegKey key;
- if (ERROR_SUCCESS == key.Open(HKEY_LOCAL_MACHINE, HKLM_FedSrv, KEY_READ))
- {
- ZString strArtPath;
- if (SUCCEEDED(LoadRegString(key, "Artpath", strArtPath)))
- {
-
- strncpy(szArtPath, PCC(strArtPath), MAX_PATH);
- }
-
- int nLast = max(0, strlen(szArtPath)-1);
- if (szArtPath[nLast] != '\\' || szArtPath[nLast] != '/')
- szArtPath[nLast+1] = '\\';
- szArtPath[nLast+2] = 0;
- }
- }
- BOOL CAllSrvUIApp::InitInstance()
- {
-
- HANDLE hEvent = GetAllSrvUIEvent();
- if (hEvent)
- {
-
- ::SetEvent(hEvent);
-
- ::CloseHandle(hEvent);
- return false;
- }
-
- HRESULT hr = FirstRunEula();
- if (E_FAIL == hr)
- {
- ::MessageBox(0, "Error while loading loading ebueula.dll", "Allegiance Server", 0);
- return false;
- }
- else if (S_FALSE == hr)
- {
- ::MessageBox(0, "You must accept the End User License Agreement before running the Allegiance Server", "Allegiance Server", 0);
- return false;
- }
- else
- {
- assert(S_OK == hr);
- }
-
- CreateAllSrvUIEvent();
-
- m_hrCoInit = CoInitialize(NULL);
-
- CAllSrvUISheet* pps = new CAllSrvUISheet;
-
- if (pps->Create())
- m_pMainWnd = pps;
-
- return true;
- }
- int CAllSrvUIApp::ExitInstance()
- {
-
- if (SUCCEEDED(m_hrCoInit))
- CoUninitialize();
-
- return CWinApp::ExitInstance();
- }
- BOOL CAllSrvUIApp::OnIdle(LONG lCount)
- {
- HANDLE hEvents[] = {m_shEventSync};
- DWORD dwWait = ::MsgWaitForMultipleObjects(sizeofArray(hEvents), hEvents,
- false, INFINITE, QS_ALLINPUT);
- if (WAIT_OBJECT_0 == dwWait)
- {
- ::ResetEvent(m_shEventSync);
- m_pMainWnd->SetForegroundWindow();
- m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
- }
- return true;
- }
- HANDLE CAllSrvUIApp::GetAllSrvUIEvent()
- {
-
- DWORD dwAccess = EVENT_MODIFY_STATE | SYNCHRONIZE;
- HANDLE hEvent = ::OpenEvent(dwAccess, false, szAllSrvUIRunningGlobal);
- if (!hEvent)
- hEvent = ::OpenEvent(dwAccess, false, szAllSrvUIRunning);
- return hEvent;
- }
- void CAllSrvUIApp::CreateAllSrvUIEvent()
- {
-
- SECURITY_ATTRIBUTES* psa = NULL;
- SECURITY_DESCRIPTOR sd;
- SECURITY_ATTRIBUTES sa = {sizeof(sa), &sd, false};
- if (IsWinNT())
- {
- InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(&sd, true, NULL, FALSE);
- psa = &sa;
- }
-
- HANDLE hEvent = ::CreateEvent(psa, true, false, szAllSrvUIRunningGlobal);
- if (!hEvent)
- hEvent = ::CreateEvent(psa, true, false, szAllSrvUIRunning);
- m_shEventSync = hEvent;
- }
- HRESULT CAllSrvUIApp::FirstRunEula()
- {
- TCHAR szArtpath[MAX_PATH];
- GetArtPath(szArtpath);
- PathString strArtPath = szArtpath;
- PathString strEulaRTF = strArtPath + "eula.rtf";
- {
- ZFile file(strEulaRTF);
- int n = file.GetLength();
- if (n == -1)
- return E_FAIL;
- }
-
- strArtPath = strArtPath + "EBUEula.dll";
- HINSTANCE hMod = LoadLibrary(PCC(strArtPath));
- if (NULL == hMod)
- {
-
- hMod = LoadLibrary("EBUEula.dll");
- if (NULL == hMod)
- return E_FAIL;
- }
- EBUPROC pfnEBUEula = (EBUPROC) GetProcAddress(hMod, "EBUEula");
- if (NULL == pfnEBUEula)
- {
- FreeLibrary(hMod);
- return E_FAIL;
- }
-
- bool bAllowGameToRun = pfnEBUEula(HKLM_AllSrvUI, PCC(strEulaRTF), NULL, TRUE) != 0;
- FreeLibrary(hMod);
- return (bAllowGameToRun ? S_OK : S_FALSE);
- }
|