void CPagePlayers::LoadFromRegistry()
{
  // Open/create the registry key
  CRegKey key;
  key.Create(HKEY_LOCAL_MACHINE, HKLM_AllSrvUI);

  // PlayerListColumnOrder
  CComBSTR bstrColumnOrder;
  LoadRegString(key, TEXT("PlayerListColumnOrder"), bstrColumnOrder);
  m_spStrings->RemoveAll();
  m_spStrings->AddDelimited(CComBSTR(L","), bstrColumnOrder);
  long cOrderedColumns = 0;
  m_spStrings->get_Count(&cOrderedColumns);
  if (c_cColumns == cOrderedColumns)
  {
    int vecOrder[c_cColumns];
    for (CComVariant i(0L); V_I4(&i) < c_cColumns; ++V_I4(&i))
    { 
      bstrColumnOrder.Empty();
      m_spStrings->get_Item(&i, &bstrColumnOrder);
      vecOrder[V_I4(&i)] = _wtoi(bstrColumnOrder);
    }
    m_listPlayers.SetColumnOrderArray(c_cColumns, vecOrder);
  }

  // PlayerListColumnWidths
  CComBSTR bstrColumnWidths;
  LoadRegString(key, TEXT("PlayerListColumnWidths"), bstrColumnWidths);
  m_spStrings->RemoveAll();
  m_spStrings->AddDelimited(CComBSTR(L","), bstrColumnWidths);
  long cWidthColumns = 0;
  m_spStrings->get_Count(&cWidthColumns);
  if (c_cColumns == cWidthColumns)
  {
    for (CComVariant i(0L); V_I4(&i) < c_cColumns; ++V_I4(&i))
    { 
      bstrColumnWidths.Empty();
      m_spStrings->get_Item(&i, &bstrColumnWidths);
      m_listPlayers.SetColumnWidth(V_I4(&i), _wtoi(bstrColumnWidths));
    }
  }
  else
  {
    for (int i = 0; i < c_cColumns; ++i)
    {
      TCHAR szColumn[_MAX_PATH];
      LVCOLUMN lvc = {LVCF_TEXT, 0, 0, szColumn, sizeofArray(szColumn)};
      m_listPlayers.GetColumn(i, &lvc);
      int cx = m_listPlayers.GetStringWidth(CString(szColumn) + TEXT("    "));
      m_listPlayers.SetColumnWidth(i, cx);
    }
  }

  // SendChatMRU
  m_comboSendChat.ResetContent();
  CRegKey keyMRU;
  if (ERROR_SUCCESS == keyMRU.Create(key, TEXT("SendChatMRU")))
  {
    // Read the count of strings
    DWORD cStrings = 0;
	// mdvalley: Former QueryDWORDValue(cStr, TEXT);
    keyMRU.QueryValue(cStrings, TEXT(".Count"));

    // Read each string and add it to the combo box
    for (DWORD i = 0; i < cStrings; ++i)
    {
      TCHAR szInt[16];
      CString strMRUItem;
      LoadRegString(keyMRU, _itot(i, szInt, 10), strMRUItem);
      strMRUItem.TrimLeft();
      strMRUItem.TrimRight();
      if (!strMRUItem.IsEmpty())
        m_comboSendChat.InsertString(i, strMRUItem);
    }
  }
}
Example #2
0
HRESULT CPigEngine::Construct()
{
  // Get the path name of the module
  TCHAR szModule[_MAX_PATH];
  _VERIFYE(GetModuleFileName(_Module.GetModuleInstance(), szModule,
    sizeofArray(szModule)));

  // Break the path name of the module into pieces
  TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szName[_MAX_FNAME];
  _tsplitpath(szModule, szDrive, szDir, szName, NULL);

  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key, KEY_READ));

  // Create the event logger object
  RETURN_FAILED(m_spEventLogger.CreateInstance("AGC.EventLogger"));

  // Initialize the event logger object
  CComBSTR bstrEventSource(L"PigSrv");
  CComBSTR bstrRegKey(L"HKCR\\AppID\\{F132B4E3-C6EF-11D2-85C9-00C04F68DEB0}");
  IAGCEventLoggerPrivatePtr spPrivate(m_spEventLogger);
  RETURN_FAILED(spPrivate->Initialize(bstrEventSource, bstrRegKey));

  // Load the MissionServer registry value
  LoadRegString(key, TEXT("MissionServer"), m_bstrMissionServer);

  // Load the AccountServer registry value
  LoadRegString(key, TEXT("AccountServer"), m_bstrAccountServer);

  // Load the ZoneAuthServer registry value
  LoadRegString(key, TEXT("ZoneAuthServer"), m_bstrZoneAuthServer);

  // Load the ZoneAuthTimeout registry value
  DWORD dwZoneAuthTimeout;
  if (ERROR_SUCCESS == key.QueryValue(dwZoneAuthTimeout, TEXT("ZoneAuthTimeout")))
    m_nZoneAuthTimeout = static_cast<long>(dwZoneAuthTimeout);

  // Load the LobbyMode registry value
  DWORD dwLobbyMode;
  if (ERROR_SUCCESS == key.QueryValue(dwLobbyMode, TEXT("LobbyMode")))
    m_eLobbyMode =
      (PigLobbyMode_Club <= dwLobbyMode && dwLobbyMode <= PigLobbyMode_Free) ?
        static_cast<PigLobbyMode>(dwLobbyMode) : PigLobbyMode_Club;

  // Attempt to read the ScriptDir value from the registry
  ZString strScriptDir;
  LoadRegString(key, TEXT("ScriptDir"), strScriptDir);

  // Create a directory name from the root directory, by default
  if (strScriptDir.IsEmpty())
  {
    TCHAR szScriptDir[_MAX_PATH + 1];
    _tmakepath(szScriptDir, szDrive, szDir, TEXT("Scripts"), NULL);
    strScriptDir = szScriptDir;
  }

  // Ensure that m_bstrScriptDir ends with a whack
  int nLastChar = strScriptDir.GetLength() - 1;
  if (TEXT('\\') != strScriptDir[nLastChar])
    strScriptDir += ZString("\\");

  // Save the directory name
  m_bstrScriptDir = strScriptDir;

  // Create the pigs collection object with a ref count
  assert(!m_pPigs);
  CComObject<CPigs>* pPigs = NULL;
  RETURN_FAILED(pPigs->CreateInstance(&pPigs));
  (m_pPigs = pPigs)->AddRef();

  // Indicate success
  return S_OK;
}
CLobbyApp::CLobbyApp(ILobbyAppSite * plas) :
  m_plas(plas),
  m_fmServers(&m_psiteServer),
  m_fmClients(&m_psiteClient),
  m_cReportServers(0),
  m_sGameInfoInterval(30), // doesn't really matter, but...
  m_fProtocol(true),
  m_cStaticCoreInfo(0),
  m_vStaticCoreInfo(NULL)
#ifdef USECLUB
  ,
  m_csqlSilentThreads(0),
  m_csqlNotifyThreads(0),
  m_sql(this)
#endif
{
  assert(m_plas);
  m_plas->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_Creating);
  m_logonCS = new CRITICAL_SECTION;
#ifdef USECLUB
  m_strSQLConfig.Empty();
#endif
  // see if we're setup to report to any web servers
  HKEY  hk;
  if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, HKLM_AllLobby, 0, L"", REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hk, NULL) == ERROR_SUCCESS)
  {
    // read AutoUpdate portion of registry
    char szServers[c_cReportServersMax * 17];
    bool bSuccess = _Module.ReadFromRegistry(hk, true, "GameInfoServers", szServers, 0, true);
    if(bSuccess)
    {
      char * token;
      token = strtok((char *) szServers, " ");
      while(token)
      {
        unsigned long ip = inet_addr(token);
        if (INADDR_NONE == ip) // then try to resolve by name
        {
          HOSTENT * phe = gethostbyname(token);
          if (phe)
            ip = * (unsigned long *) phe->h_addr_list[0];
        }
        
        if (INADDR_NONE != ip)
          m_rgulIP[m_cReportServers++] = ip;
        else
          m_plas->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_BadGameInfoSrv, token);
          
        token = strtok(NULL, " ");
      }
      bSuccess = _Module.ReadFromRegistry(hk, false, "GameInfoInterval", &m_sGameInfoInterval, 25);
    }

    DWORD dwPort;
	bSuccess = _Module.ReadFromRegistry(hk, false, "ClientPort", &dwPort, 2302);		// Mdvalley: defaults to port 2302
	m_sPort = dwPort;

    m_szToken[0] = '\0';
    bSuccess = _Module.ReadFromRegistry(hk, true, "Token", m_szToken, NULL);

    DWORD dwProtocol;
    bSuccess = _Module.ReadFromRegistry(hk, false, "fProtocol", &dwProtocol, (unsigned long) true);
    m_fProtocol = !!dwProtocol;

    DWORD dwFreeLobby;
    bSuccess = _Module.ReadFromRegistry(hk, false, "fFreeLobby", &dwFreeLobby, (unsigned long) 

#ifdef USECLUB
    false
#else    
    true
#endif    
    );
    m_fFreeLobby = !!dwFreeLobby;

	// BT - 7/15 - CSS Service integration
	m_szCssServerDomain[0] = '\0';
	bSuccess = _Module.ReadFromRegistry(hk, true, "CssServerDomain", m_szCssServerDomain, NULL);

	m_szCssClientServicePath[0] = '\0';
	bSuccess = _Module.ReadFromRegistry(hk, true, "CssClientServicePath", m_szCssClientServicePath, NULL);

	m_szCssLobbyServicePath[0] = '\0';
	bSuccess = _Module.ReadFromRegistry(hk, true, "CssLobbyServicePath", m_szCssLobbyServicePath, NULL);

	m_szCssGameDataServicePath[0] = '\0';
	bSuccess = _Module.ReadFromRegistry(hk, true, "CssGameDataServicePath", m_szCssGameDataServicePath, NULL);

	m_dwCssAuthenticationEnabled = 0;
	bSuccess = _Module.ReadFromRegistry(hk, true, "CssAuthenticationEnabled", &m_dwCssAuthenticationEnabled, 0);

	// BT - 7/15 - Send currently connected players to the CSS webservice.
	m_bCssGameInfoEnabled = false;
	DWORD dwCssGameInfoEnabled = 0;
	bSuccess = _Module.ReadFromRegistry(hk, false, "CssGameInfoEnabled", &dwCssGameInfoEnabled, 0);

	if (bSuccess == true)
		m_bCssGameInfoEnabled = dwCssGameInfoEnabled > 0;

	// BT - 7/15 - Backwards compatibility for AZ.
	m_bAzGameInfoEnabled = true;
	DWORD dwAzGameInfoEnabled = 0;
	bSuccess = _Module.ReadFromRegistry(hk, false, "AzGameInfoEnabled", &dwAzGameInfoEnabled, 0);

	if (bSuccess == true && dwAzGameInfoEnabled == 0)
		m_bAzGameInfoEnabled = false;

    DWORD dwCheckKey;
    bSuccess = _Module.ReadFromRegistry(hk, false, "fCheckCDKey", &dwCheckKey, (unsigned long) 
#ifdef USECLUB
      true
#else      
      false
#endif
    );
    m_fCheckCDKey = !!dwCheckKey;

#ifdef USECLUB
    bSuccess = _Module.ReadFromRegistry(hk, false, "SQLThreadsNotify", &m_csqlNotifyThreads, (unsigned long) 5);
    bSuccess = _Module.ReadFromRegistry(hk, false, "SQLThreadsSilent", &m_csqlSilentThreads, (unsigned long) 1);

    if (FAILED(LoadRegString(hk, "SQLConfig", m_strSQLConfig)))
    {
      m_strSQLConfig.Empty(); 
      _Module.LogEvent(EVENTLOG_ERROR_TYPE, LE_RegStrMissingNoDef, "SQLConfig");
    }
#endif

  }

  g_pLobbyApp = this;

  // stuff for reporting population to zone
  //imago, only if we have gameinfoservers to report to
  if (m_cReportServers) {
	  WSAData data;
	  WSAStartup(MAKEWORD(1,0),&data);
	  //initialize UDP send API
	  ZGameInfoInit(0);
	  //initialize structure
	  SetConstantGameInfo();
  }

  // if zone club lobby
#ifdef USEAUTH  
  m_pzas = CreateZoneAuthServer();
#endif
}