void CUIMultiPlayer::LoadProfile(IPlayerProfile* pProfile) { pProfile->GetAttribute( "mp_username", m_LocalPlayerName); pProfile->GetAttribute( "mp_server", m_ServerName); // override if setup in system cfg ICVar* pServerVar = gEnv->pConsole->GetCVar("cl_serveraddr"); if (pServerVar && pServerVar->GetString() != "") m_ServerName = pServerVar->GetString(); }
void CGameStats::SubmitServerStats() { SStatsTrackHelper hlp(this); string mode; if(IEntity* pGRE = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRulesEntity()) { mode = pGRE->GetClass()->GetName(); } else mode = gEnv->pConsole->GetCVar("sv_gamerules")->GetString(); char strProductVersion[256]; gEnv->pSystem->GetProductVersion().ToString(strProductVersion); string name; ICVar* pName = gEnv->pConsole->GetCVar("sv_servername"); if(pName) name = pName->GetString(); if(name.empty()) name = gEnv->pNetwork->GetHostName(); string levelname; GetLevelName(levelname); hlp.ServerValue("mapname",levelname); hlp.ServerValue("gametype",mode); hlp.ServerValue("hostname",name); hlp.ServerValue("gamever",strProductVersion); }
void CGameStats::ReportGame() { string mode; if(IEntity* pGRE = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRulesEntity()) { mode = pGRE->GetClass()->GetName(); } else mode = gEnv->pConsole->GetCVar("sv_gamerules")->GetString(); string name; ICVar* pName = gEnv->pConsole->GetCVar("sv_servername"); if(pName) name = pName->GetString(); string timelimit; static ICVar* pVar = gEnv->pConsole->GetCVar("g_timelimit"); timelimit = pVar?pVar->GetString():"0"; if(m_serverReport) { string levelname; if(GetLevelName(levelname)) m_serverReport->SetServerValue("mapname",levelname.c_str()); m_serverReport->SetServerValue("gametype",mode); m_serverReport->SetServerValue("timelimit",pVar?pVar->GetString():"0"); } Report(); }
void CGameStats::ReportSession() { if(!m_serverReport) return; string name; ICVar* pName = gEnv->pConsole->GetCVar("sv_servername"); if(pName) name = pName->GetString(); if(name.empty()) name = gEnv->pNetwork->GetHostName(); CCryAction::GetCryAction()->OnActionEvent(SActionEvent(eAE_serverName, 0, name)); if(gEnv->pConsole->GetCVar("sv_lanonly")->GetIVal())//we're on LAN so report our name { string ip = gEnv->pNetwork->GetHostName(); ip += ":"; ip += gEnv->pConsole->GetCVar("sv_port")->GetString(); CCryAction::GetCryAction()->OnActionEvent(SActionEvent(eAE_serverIp, 0, ip)); } if(m_serverReport) { m_serverReport->SetServerValue("hostname",name); m_serverReport->SetServerValue("hostport",gEnv->pConsole->GetCVar("sv_port")->GetString()); char strProductVersion[256]; gEnv->pSystem->GetProductVersion().ToString(strProductVersion); m_serverReport->SetServerValue("gamever", strProductVersion); m_serverReport->SetServerValue("maxplayers",gEnv->pConsole->GetCVar("sv_maxplayers")->GetString()); ICVar* pFF = gEnv->pConsole->GetCVar("g_friendlyfireratio"); m_serverReport->SetServerValue("friendlyfire",pFF?((pFF->GetFVal()!=0)?"1":"0"):0); m_serverReport->SetServerValue("dx10",CCryAction::GetCryAction()->GetGameContext()->HasContextFlag(eGSF_ImmersiveMultiplayer)?"1":"0"); } ReportGame(); if((CCryAction::GetCryAction()->GetILevelSystem()->IsLevelLoaded() && CCryAction::GetCryAction()->IsGameStarted()) || m_startReportNeeded)//otherwise, OnLoadingStart will report it { if(m_serverReport && !m_reportStarted)//report now { m_serverReport->StartReporting(gEnv->pGame->GetIGameFramework()->GetServerNetNub(), m_pListener); m_reportStarted = true; } m_startReportNeeded = false; } m_startReportNeeded = !m_reportStarted; }
SCreateChannelResult CGameClientNub::CreateChannel(INetChannel* pChannel, const char* pRequest) { if (pRequest && !gEnv->pNetwork->IsRebroadcasterEnabled()) { GameWarning("CGameClientNub::CreateChannel: pRequest is non-null, it should not be"); CRY_ASSERT(false); SCreateChannelResult res(eDC_GameError); cry_strcpy(res.errorMsg, "CGameClientNub::CreateChannel: pRequest is non-null, it should not be"); return res; } if (m_pClientChannel) { if (gEnv->pNetwork->IsRebroadcasterEnabled()) { // A client channel has already been set up so this must be a rebroadcaster (peer to peer) channel pChannel->SetPeer(m_pGameContext->GetNetContext()); SCreateChannelResult res(reinterpret_cast<IGameChannel*>(pChannel)); return res; } else { GameWarning("CGameClientNub::CreateChannel: m_pClientChannel is non-null, it should not be"); CRY_ASSERT(false); SCreateChannelResult res(eDC_GameError); cry_strcpy(res.errorMsg, "CGameClientNub::CreateChannel: m_pClientChannel is non-null, it should not be"); return res; } } if (CCryAction::GetCryAction()->IsGameSessionMigrating()) { pChannel->SetMigratingChannel(true); } m_pClientChannel = new CGameClientChannel(pChannel, m_pGameContext, this); ICVar* pPass = gEnv->pConsole->GetCVar("sv_password"); if (pPass && gEnv->bMultiplayer) pChannel->SetPassword(pPass->GetString()); return SCreateChannelResult(m_pClientChannel); }
void CWorldState::Init() { if( gEnv->bServer && !gEnv->IsEditor()) { CryLog("CWorldState::Init()"); pPak = gEnv->pCryPak; pLevel = gEnv->pGame->GetIGameFramework()->GetILevelSystem()->GetCurrentLevel(); ICVar* pName = gEnv->pConsole->GetCVar("sv_servername"); worldStateXml==NULL; if (pLevel) szSavePath = pLevel->GetLevelInfo()->GetPath(); if(pName) serverName = pName->GetString(); szSaveFile = PathUtil::Make(szSavePath.c_str(), serverName, ".xml"); ReadWorldStateFile((char*)serverName); } }
void COptionsManager::UpdateToProfile() { std::map<string,SOptionEntry>::const_iterator it = m_profileOptions.begin(); std::map<string,SOptionEntry>::const_iterator end = m_profileOptions.end(); for(;it!=end;++it) { const SOptionEntry& entry = it->second; if(!strcmp(it->first.c_str(),"pb_client")) { SaveValueToProfile(entry.name.c_str(), m_pbEnabled?1:0); } else if(!strcmp(it->first.c_str(), "fsaa_mode")) { string value(""); if(g_pGame->GetMenu()) { if(gEnv->pConsole->GetCVar("r_FSAA")->GetIVal()) { int samples = gEnv->pConsole->GetCVar("r_FSAA_samples")->GetIVal(); int quality = gEnv->pConsole->GetCVar("r_FSAA_quality")->GetIVal(); value = g_pGame->GetMenu()->GetFSAAMode(samples, quality); } } SaveValueToProfile(entry.name.c_str(), value); } else { ICVar *pCVAR = gEnv->pConsole->GetCVar(it->first); if(pCVAR) { string value(pCVAR->GetString()); SaveValueToProfile(entry.name.c_str(), value); } } } SaveProfile(); }
//------------------------------------------------------------------------ SCreateChannelResult CGameServerNub::CreateChannel(INetChannel *pChannel, const char *pRequest) { CRY_ASSERT(m_maxPlayers); CGameServerChannel *pNewChannel; if (!pRequest) { CRY_ASSERT(false); SCreateChannelResult res(eDC_GameError); return res; } SParsedConnectionInfo info = m_pGameContext->ParseConnectionInfo(pRequest); if (!info.allowConnect) { GameWarning( "Not allowed to connect to server: %s", info.errmsg.c_str() ); SCreateChannelResult res(info.cause); cry_strcpy(res.errorMsg, info.errmsg.c_str()); return res; } if (int(m_channels.size()) >= m_maxPlayers) { SCreateChannelResult res(eDC_ServerFull); cry_strcpy(res.errorMsg, string().Format("Disallowing more than %d players",m_maxPlayers).c_str()); return res; } if (info.isMigrating && CCryAction::GetCryAction()->IsGameSessionMigrating()) { pChannel->SetMigratingChannel(true); } pNewChannel = GetOnHoldChannelFor(pChannel); if (!pNewChannel) { pNewChannel = new CGameServerChannel(pChannel, m_pGameContext, this); if (pChannel->GetSession() != CrySessionInvalidHandle) { // There is a valid CrySessionHandle created by the lobby so use this as the channel id // as it contains information that can identify the connection in the lobby. pNewChannel->SetChannelId(pChannel->GetSession()); } else { // No valid CrySessionHandle so create an id here. pNewChannel->SetChannelId(++m_genId); } if (m_channels.find(pNewChannel->GetChannelId()) != m_channels.end()) { CryFatalError("CGameServerNub::CreateChannel: Trying to create channel with duplicate id %d", pNewChannel->GetChannelId()); } m_channels.insert(TServerChannelMap::value_type(pNewChannel->GetChannelId(), pNewChannel)); } else { pNewChannel->SetNetChannel(pChannel); #if !NEW_BANDWIDTH_MANAGEMENT pNewChannel->SetupNetChannel(pChannel); #endif // NEW_BANDWIDTH_MANAGEMENT } ICVar* pPass = gEnv->pConsole->GetCVar("sv_password"); if (pPass && gEnv->bMultiplayer) { pChannel->SetPassword(pPass->GetString()); } pChannel->SetNickname(info.playerName.c_str()); // Host migration if (info.isMigrating && CCryAction::GetCryAction()->IsGameSessionMigrating()) { // Enable the game rules to find the migrating player details by channel id IGameFramework *pGameFramework = gEnv->pGame->GetIGameFramework(); IGameRules *pGameRules = pGameFramework->GetIGameRulesSystem()->GetCurrentGameRules(); if(pGameRules) { EntityId playerID = pGameRules->SetChannelForMigratingPlayer(info.playerName.c_str(), pNewChannel->GetChannelId()); if (playerID) { CryLog("CGameServerNub::CreateChannel() assigning actor %d '%s' to channel %d", playerID, info.playerName.c_str(), pNewChannel->GetChannelId()); pNewChannel->SetPlayerId(playerID); } else { CryLog("CGameServerNub::CreateChannel() failed to assign actor '%s' to channel %d", info.playerName.c_str(), pNewChannel->GetChannelId()); } } else { CryLog("[host migration] terminating because game rules is NULL, game session migrating %d session 0x%08x", CCryAction::GetCryAction()->IsGameSessionMigrating(), pChannel->GetSession()); gEnv->pNetwork->TerminateHostMigration(pChannel->GetSession()); } } m_netchannels.insert(TNetServerChannelMap::value_type(pChannel, pNewChannel->GetChannelId())); return SCreateChannelResult(pNewChannel); }
void CUIMultiPlayer::InitEventSystem() { if (!gEnv->pFlashUI) return; ICVar* pServerVar = gEnv->pConsole->GetCVar("cl_serveraddr"); m_ServerName = pServerVar ? pServerVar->GetString() : ""; if (m_ServerName == "") m_ServerName = "localhost"; // events to send from this class to UI flowgraphs m_pUIFunctions = gEnv->pFlashUI->CreateEventSystem("MP", IUIEventSystem::eEST_SYSTEM_TO_UI); m_eventSender.Init(m_pUIFunctions); { SUIEventDesc evtDesc("EnteredGame", "Triggered once the local player enters the game"); m_eventSender.RegisterEvent<eUIE_EnteredGame>(evtDesc); } { SUIEventDesc evtDesc("ChatMessageReceived", "Triggered when chatmessages is received"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Player", "Name of the player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Message", "Message"); m_eventSender.RegisterEvent<eUIE_ChatMsgReceived>(evtDesc); } { SUIEventDesc evtDesc("PlayerJoined", "Triggered if a player joins the game"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("ID", "ID of player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Name", "Name of the player"); m_eventSender.RegisterEvent<eUIE_PlayerJoined>(evtDesc); } { SUIEventDesc evtDesc("UpdateOrAddScoreBoardItem", "Triggered to update an item on the scoreboard"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("ID", "ID of player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Name", "Name of the player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("Kills", "amount of kills this player has"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("Deaths", "amount of deaths this player had"); m_eventSender.RegisterEvent<eUIE_UpdateScoreBoardItem>(evtDesc); } { SUIEventDesc evtDesc("PlayerLeft", "Triggered if a player left the game"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("ID", "ID of player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Name", "Name of the player"); m_eventSender.RegisterEvent<eUIE_PlayerLeft>(evtDesc); } { SUIEventDesc evtDesc("PlayerKilled", "Triggered if a player gets killed"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("ID", "ID of player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Name", "Name of the player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("ShooterID", "ID of the shooter"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("ShooterName", "Name of the shooter"); m_eventSender.RegisterEvent<eUIE_PlayerKilled>(evtDesc); } { SUIEventDesc evtDesc("PlayerRenamed", "Triggered if a player was renamed"); evtDesc.AddParam<SUIParameterDesc::eUIPT_Int>("ID", "ID of player"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("NewName", "New name of the player"); m_eventSender.RegisterEvent<eUIE_PlayerRenamed>(evtDesc); } { SUIEventDesc evtDesc("OnGetName", "Triggers once the \"GetPlayerName\" node was called"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Name", "Name of the local player"); m_eventSender.RegisterEvent<eUIE_SendName>(evtDesc); } { SUIEventDesc evtDesc("OnGetServerName", "Triggers once the \"GetLastServer\" node was called"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Address", "Last server address"); m_eventSender.RegisterEvent<eUIE_SendServer>(evtDesc); } // events that can be sent from UI flowgraphs to this class m_pUIEvents = gEnv->pFlashUI->CreateEventSystem("MP", IUIEventSystem::eEST_UI_TO_SYSTEM); m_eventDispatcher.Init(m_pUIEvents, this, "CUIMultiPlayer"); { SUIEventDesc evtDesc("GetPlayers", "Request all players (will trigger the \"PlayerJoined\" node for each player)"); m_eventDispatcher.RegisterEvent(evtDesc, &CUIMultiPlayer::RequestPlayers); } { SUIEventDesc evtDesc("GetPlayerName", "Get the name of the local player in mp (will trigger the \"OnGetName\" node)"); m_eventDispatcher.RegisterEvent(evtDesc, &CUIMultiPlayer::GetPlayerName); } { SUIEventDesc evtDesc("ConnectToServer", "Connect to a server"); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Address", "server address"); m_eventDispatcher.RegisterEvent(evtDesc, &CUIMultiPlayer::ConnectToServer); } { SUIEventDesc evtDesc("GetLastServer", "Get the server name that was last used"); m_eventDispatcher.RegisterEvent(evtDesc, &CUIMultiPlayer::GetServerName); } { SUIEventDesc evtDesc("SendChatMessage", ""); evtDesc.AddParam<SUIParameterDesc::eUIPT_String>("Message", ""); m_eventDispatcher.RegisterEvent(evtDesc, &CUIMultiPlayer::OnSendChatMessage); } gEnv->pFlashUI->RegisterModule(this, "CUIMultiPlayer"); }
string CTweakMetadataCVAR::GetValue(void) { string result = "Not found"; ICVar *cVar = GetCVar(); if (cVar) result = cVar->GetString(); return result; }
void COptionsManager::UpdateFlashOptions() { std::map<string,SOptionEntry>::const_iterator it = m_profileOptions.begin(); std::map<string,SOptionEntry>::const_iterator end = m_profileOptions.end(); CFlashMenuScreen *pMainMenu = SAFE_MENU_FUNC_RET(GetMenuScreen(CFlashMenuObject::MENUSCREEN_FRONTENDSTART)); CFlashMenuScreen *pInGameMenu = SAFE_MENU_FUNC_RET(GetMenuScreen(CFlashMenuObject::MENUSCREEN_FRONTENDINGAME)); CFlashMenuScreen *pCurrentMenu = NULL; if(pMainMenu && pMainMenu->IsLoaded()) pCurrentMenu = pMainMenu; else if(pInGameMenu && pInGameMenu->IsLoaded()) pCurrentMenu = pInGameMenu; if(!pCurrentMenu) return; for(;it!=end;++it) { if(!strcmp(it->first.c_str(),"pb_client")) { SFlashVarValue option[3] = {"pb_client", m_pbEnabled, true}; pCurrentMenu->Invoke("Root.MainMenu.Options.SetOption", option, 3); } else if(!stricmp(it->first.c_str(), "fsaa_mode")) { if(g_pGame->GetMenu()) { if(!gEnv->pConsole->GetCVar("r_FSAA")->GetIVal()) { SFlashVarValue option[3] = {"fsaa_mode", "0", true}; pCurrentMenu->Invoke("Root.MainMenu.Options.SetOption", option, 3); } else { int samples = gEnv->pConsole->GetCVar("r_FSAA_samples")->GetIVal(); int quality = gEnv->pConsole->GetCVar("r_FSAA_quality")->GetIVal(); SFlashVarValue option[3] = {"fsaa_mode", g_pGame->GetMenu()->GetFSAAMode(samples, quality).c_str(), true}; pCurrentMenu->Invoke("Root.MainMenu.Options.SetOption", option, 3); } } } else { ICVar *pCVar = gEnv->pConsole->GetCVar(it->first); if(pCVar) { const char* name = pCVar->GetName(); const char* value = pCVar->GetString(); bool bIsValid = pCVar->GetIVal()==pCVar->GetRealIVal(); if(!stricmp(name, "r_fsaa_samples")) //fsaa workaround for RnD { ICVar *pFSAA = gEnv->pConsole->GetCVar("r_fsaa"); if(pFSAA && pFSAA->GetIVal() == 0) value = pFSAA->GetString(); } SFlashVarValue option[3] = {name, value, bIsValid}; pCurrentMenu->Invoke("Root.MainMenu.Options.SetOption", option, 3); } } } pCurrentMenu->CheckedInvoke("_root.Root.MainMenu.Options.updateOptions"); }
void COptionsManager::InitProfileOptions(bool switchProfiles) { if(!m_pPlayerProfileManager) return; if(g_pGameCVars->g_useProfile==0) return; if(g_pGameCVars->g_startFirstTime==1) { ICVar *pCVar = gEnv->pConsole->GetCVar("g_startFirstTime"); if(pCVar && pCVar->GetIVal()==1) { pCVar->Set(0); m_firstStart = true; } switchProfiles=true; } const char* user = m_pPlayerProfileManager->GetCurrentUser(); IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(user); if(!pProfile) return; IAttributeEnumeratorPtr attribEnum = pProfile->CreateAttributeEnumerator(); IAttributeEnumerator::SAttributeDescription attrib; m_profileOptions.clear(); while(attribEnum->Next(attrib)) { bool bWriteToCfg = false; const char* attribCVar = ""; const bool bIsOption = IsOption(attrib.name, attribCVar, bWriteToCfg); if (bIsOption) { SOptionEntry entry (attrib.name, bWriteToCfg); m_profileOptions[attribCVar] = entry; if(!bWriteToCfg || switchProfiles) { string value; if(!strcmp(attribCVar, "pb_client")) { GetProfileValue(attrib.name, value); if(atoi(value)==0) { m_pbEnabled = false; gEnv->pConsole->ExecuteString("net_pb_cl_enable false"); } else { m_pbEnabled = true; gEnv->pConsole->ExecuteString("net_pb_cl_enable true"); } continue; } else if(!strcmp(attribCVar, "fsaa_mode")) { GetProfileValue(attrib.name, value); SetAntiAliasingMode(value.c_str()); } else if(!strcmp(attribCVar, "g_difficultyLevel")) { GetProfileValue(attrib.name, value); SetDifficulty(value); } ICVar *pCVar = gEnv->pConsole->GetCVar(attribCVar); if(pCVar && GetProfileValue(attrib.name, value)) { if(stricmp(pCVar->GetString(), value.c_str())) { //CryLogAlways("Inited, loaded and changed: %s = %s (was %s)", attrib.name, value, pCVar->GetString()); pCVar->Set(value.c_str()); } else { //CryLogAlways("Inited, loaded, but not changed: %s = %s", attrib.name, value); } if(!stricmp(attrib.name,"Option.hud_colorLine")) { SetCrysisProfileColor(value.c_str()); } } } } } WriteGameCfg(); }
void CRevertibleConfigLoader::ApplyAndStoreCVar( const char *szKey, const char *szValue ) { ICVar * var = gEnv->pConsole->GetCVar(szKey); if (var == NULL) { GameWarning("Variable \"%s\" not found (trying to set it to '%s')", szKey, szValue); return; } const char * oldValue = var->GetString(); if (oldValue!=0 && 0 == strcmp(szValue, oldValue)) { CryLog("No need to change \"%s\" to '%s' as that's also its current value", szKey, szValue ); return; } if (m_allowCheatCVars || (var->GetFlags() & VF_CHEAT) == 0) { const int numStoredCvars = (int)m_savedCVars.size(); #ifndef _RELEASE const char* savedValue = NULL; for (int i=0; i<numStoredCvars; i++) { if (stricmp(m_savedCVars[i].m_name, szKey) == 0) { savedValue = m_savedCVars[i].m_value; break; } } if (savedValue) { GameWarning("Already got an old value for cvar \"%s\" (currently '%s'), about to add another entry...", szKey, savedValue); } #endif SSavedCVar savedCvar; savedCvar.m_name = m_cvarsTextBlock.StoreText(szKey); savedCvar.m_value = m_cvarsTextBlock.StoreText(var->GetString()); if (savedCvar.m_name && savedCvar.m_value) { m_savedCVars.push_back(savedCvar); CryLog("Changing \"%s\" cvar from '%s' to '%s' (now got %" PRISIZE_T " %s to revert when switching game type)", szKey, oldValue, szValue, m_savedCVars.size(), (m_savedCVars.size() == 1) ? "cvar" : "cvars"); } else { GameWarning("!Ran out of room in cvar array.\nPlease increase maxTextBufferSize - current value is %" PRISIZE_T ".\nFor now, game won't remember to undo \"%s = %s\".", m_cvarsTextBlock.GetSizeNeeded(), szKey, var->GetString()); } } else { GameWarning("!Can't change \"%s\" cvar from '%s' to '%s' because it is a cheat var and cannot be changed in release mode", szKey, oldValue, szValue); return; } CryFixedStringT<128> cmd; cmd.Format("%s %s", szKey, szValue); IConsole * pConsole = gEnv->pConsole; pConsole->ExecuteString(cmd.c_str(), true); }