void Battle::FixColours() { if ( !IsFounderMe() )return; std::vector<wxColour> &palette = GetFixColoursPalette( m_teams_sizes.size() + 1 ); std::vector<int> palette_use( palette.size(), 0 ); wxColour my_col = GetMe().BattleStatus().colour; // Never changes color of founder (me) :-) int my_diff = 0; int my_col_i = GetClosestFixColour( my_col, palette_use,my_diff ); palette_use[my_col_i]++; std::set<int> parsed_teams; for ( user_map_t::size_type i = 0; i < GetNumUsers(); i++ ) { User &user=GetUser(i); if ( &user == &GetMe() ) continue; // skip founder ( yourself ) UserBattleStatus& status = user.BattleStatus(); if ( status.spectator ) continue; if ( parsed_teams.find( status.team ) != parsed_teams.end() ) continue; // skip duplicates parsed_teams.insert( status.team ); wxColour &user_col=status.colour; int user_col_i=GetClosestFixColour(user_col,palette_use, 60); palette_use[user_col_i]++; for ( user_map_t::size_type j = 0; j < GetNumUsers(); j++ ) { User &usr=GetUser(j); if ( usr.BattleStatus().team == status.team ) { ForceColour( usr, palette[user_col_i]); } } } }
bool PeerIdentity::Equals(const nsAString& aOtherString) const { nsString user; GetUser(mPeerIdentity, user); nsString otherUser; GetUser(aOtherString, otherUser); if (user != otherUser) { return false; } nsString host; GetHost(mPeerIdentity, host); nsString otherHost; GetHost(aOtherString, otherHost); nsresult rv; nsCOMPtr<nsIIDNService> idnService = do_GetService("@mozilla.org/network/idn-service;1", &rv); if (NS_WARN_IF(NS_FAILED(rv))) { return host == otherHost; } nsCString normHost; GetNormalizedHost(idnService, host, normHost); nsCString normOtherHost; GetNormalizedHost(idnService, otherHost, normOtherHost); return normHost == normOtherHost; }
bool IsOnlineModNick(const CString& sNick) { const CString& sPrefix = GetUser()->GetStatusPrefix(); if (!sNick.StartsWith(sPrefix)) return false; CString sModNick = sNick.substr(sPrefix.length()); if (sModNick.Equals("status") || GetNetwork()->GetModules().FindModule(sModNick) || GetUser()->GetModules().FindModule(sModNick) || CZNC::Get().GetModules().FindModule(sModNick)) return true; return false; }
virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg) { if (!GetUser()) { return CONTINUE; } PyObject* pyFunc = PyObject_GetAttrString(m_PyZNCModule, "load_module"); if (!pyFunc) { sRetMsg = GetPyExceptionStr(); DEBUG("modpython: " << sRetMsg); bSuccess = false; return HALT; } PyObject* pyRes = PyObject_CallFunction(pyFunc, const_cast<char*>("ssNNN"), sModName.c_str(), sArgs.c_str(), SWIG_NewInstanceObj(GetUser(), SWIG_TypeQuery("CUser*"), 0), CPyRetString::wrap(sRetMsg), SWIG_NewInstanceObj(reinterpret_cast<CGlobalModule*>(this), SWIG_TypeQuery("CGlobalModule*"), 0)); if (!pyRes) { sRetMsg = GetPyExceptionStr(); DEBUG("modpython: " << sRetMsg); bSuccess = false; Py_CLEAR(pyFunc); return HALT; } Py_CLEAR(pyFunc); long int ret = PyLong_AsLong(pyRes); if (PyErr_Occurred()) { sRetMsg = GetPyExceptionStr(); DEBUG("modpython: " << sRetMsg); Py_CLEAR(pyRes); return HALT; } Py_CLEAR(pyRes); switch (ret) { case 0: // Not found return CONTINUE; case 1: // Error bSuccess = false; return HALT; case 2: // Success bSuccess = true; return HALT; } bSuccess = false; sRetMsg += " unknown value returned by modperl.load_module"; return HALT; }
void Battle::StartHostedBattle() { if ( UserExists( GetMe().GetNick() ) ) { if ( IsFounderMe() ) { if ( sett().GetBattleLastAutoControlState() ) { FixTeamIDs( (IBattle::BalanceType)sett().GetFixIDMethod(), sett().GetFixIDClans(), sett().GetFixIDStrongClans(), sett().GetFixIDGrouping() ); Autobalance( (IBattle::BalanceType)sett().GetBalanceMethod(), sett().GetBalanceClans(), sett().GetBalanceStrongClans(), sett().GetBalanceGrouping() ); FixColours(); } if ( IsProxy() ) { if ( UserExists( GetProxy()) && !GetUser(GetProxy()).Status().in_game ) { // DON'T set m_generating_script here, it will trick the script generating code to think we're the host wxString hostscript = spring().WriteScriptTxt( *this ); try { wxString path = TowxString(SlPaths::GetDataDir()) + _T("relayhost_script.txt"); if ( !wxFile::Access( path, wxFile::write ) ) { wxLogError( _T("Access denied to script.txt.") ); } wxFile f( path, wxFile::write ); f.Write( hostscript ); f.Close(); } catch (...) {} m_serv.SendScriptToProxy( hostscript ); } } if( GetAutoLockOnStart() ) { SetIsLocked( true ); SendHostInfo( IBattle::HI_Locked ); } sett().SetLastHostMap(TowxString(GetServer().GetCurrentBattle()->GetHostMapName())); sett().SaveSettings(); if ( !IsProxy() ) GetServer().StartHostedBattle(); else if ( UserExists( GetProxy() ) && GetUser(GetProxy()).Status().in_game ) // relayhost is already ingame, let's try to join it { StartSpring(); } } } }
wxString CServer::FormatServer(const bool always_include_prefix /*=false*/) const { wxString server = FormatHost(); if (m_logonType != ANONYMOUS) server = GetUser() + _T("@") + server; switch (m_protocol) { default: { wxString prefix = GetPrefixFromProtocol(m_protocol); if (prefix != _T("")) server = prefix + _T("://") + server; else if (always_include_prefix) server = prefix + _T("://") + server; } break; case FTP: if (always_include_prefix || (GetProtocolFromPort(m_port) != FTP && GetProtocolFromPort(m_port) != UNKNOWN)) server = _T("ftp://") + server; break; } return server; }
void Cloak() { if (m_bCloaked) return; PutModule("Cloak: Trying to cloak your hostname, setting +x..."); PutIRC("MODE " + GetUser()->GetIRCSock()->GetNick() + " +x"); }
virtual bool OnLoad(const CString& sArgs, CString& sMessage) { if (!sArgs.empty()) { SetUsername(sArgs.Token(0)); SetPassword(sArgs.Token(1)); } else { m_sUsername = GetNV("Username"); m_sPassword = GetNV("Password"); } CString sTmp; m_bUseCloakedHost = (sTmp = GetNV("UseCloakedHost")).empty() ? true : sTmp.ToBool(); m_bUseChallenge = (sTmp = GetNV("UseChallenge")).empty() ? true : sTmp.ToBool(); m_bRequestPerms = GetNV("RequestPerms").ToBool(); OnIRCDisconnected(); // reset module's state if (IsIRCConnected()) { // check for usermode +x if we are already connected set<unsigned char> scUserModes = GetUser()->GetIRCSock()->GetUserModes(); if (scUserModes.find('x') != scUserModes.end()) m_bCloaked = true; OnIRCConnected(); } return true; }
// 检测离线车辆 bool CVechileMgr::CheckOfflineUser( void ) { list<_stVechile*> lst ; int nsize = GetUser( lst, OFF_LINE ) ; if ( nsize == 0 ) { return false ; } time_t now = share::Util::currentTimeUsec() ; list<_stVechile*>::iterator it ; for ( it = lst.begin(); it != lst.end(); ++ it ) { // 简单遍历算法 _stVechile *temp = *it ; if ( now - temp->last_conn_ < MAX_USECOND ){ continue ; } temp->last_conn_ = now ; // 如果登陆不服务器就直接返回了 if ( ! LoginServer( temp ) ) { return false ; } } return true ; }
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) { user = GetUser(); HighScore = sArgs.Token(0).ToInt(); PutModule("HighScore: "+CString(HighScore)); lastturn = false; return true; }
static int SSLSRPServerParamCallback(SSL *s, int *ad, void *arg) { const char* userName = SSL_get_srp_username(s); LOG(INFO) << "User " << userName; const User* user = GetUser(userName); if (!user) { LOG(ERROR) << "User " << userName << " doesn't exist"; *ad = SSL_AD_UNKNOWN_PSK_IDENTITY; return SSL3_AL_FATAL; } SRP_gN *GN = SRP_get_default_gN(FLAGS_srp_default_gN.c_str()); if(GN == NULL) { *ad = SSL_AD_INTERNAL_ERROR; return SSL3_AL_FATAL; } if (!SSL_set_srp_server_param(s, GN->N, GN->g, user->GetSalt(), user->GetVerifier(), NULL)) { *ad = SSL_AD_INTERNAL_ERROR; return SSL3_AL_FATAL; } return SSL_ERROR_NONE; }
EModRet OnUserNotice(CString& sTarget, CString& sMessage) override { sTarget.TrimPrefix(NickPrefix()); if (sMessage.TrimPrefix("``")) { return CONTINUE; } MCString::iterator it = FindNV(sTarget.AsLower()); if (it != EndNV()) { CChan* pChan = GetNetwork()->FindChan(sTarget); CString sNickMask = GetNetwork()->GetIRCNick().GetNickMask(); if (pChan) { if (!pChan->AutoClearChanBuffer()) pChan->AddBuffer(":" + NickPrefix() + _NAMEDFMT(sNickMask) + " NOTICE " + _NAMEDFMT(sTarget) + " :{text}", sMessage); GetUser()->PutUser(":" + NickPrefix() + sNickMask + " NOTICE " + sTarget + " :" + sMessage, NULL, GetClient()); } CString sMsg = MakeIvec() + sMessage; sMsg.Encrypt(it->second); sMsg.Base64Encode(); sMsg = "+OK *" + sMsg; PutIRC("NOTICE " + sTarget + " :" + sMsg); return HALTCORE; } return CONTINUE; }
// Get users list with info. void meth::GetOnlineUsers(LogicalConnections::iterator conn, String &response) { OnlineUsersList online_users = ::GetOnlineUsers(); bool first_user = true; User user; response = "["; for (OnlineUsersList::iterator online_user = online_users.begin(); online_user != online_users.end(); online_user++) { // Add comma before each user except first. if (!first_user) { response += ","; } else { first_user = false; } response += "{"; user = GetUser(online_user->user_ref); AddPair(response, "name", user.name, true, true); AddPair(response, "sex", (int) user.sex, false, true); AddPair(response, "ip", (user.hidden_ip) ? String("N/A") : user.ip, true, true); AddPair(response, "state", online_user->state, true, false); response += "}"; } response += "]"; }
bool BFCPFloorControlServer::SetChair(int userId) { if (this->ending) { return false; } BFCPUser* user = GetUser(userId); if (! user) { ::Error("BFCPFloorControlServer::SetChair() | user '%d' does not exist\n", userId); return false; } //As we are setting also the chair, lock for writting users.WaitUnusedAndLock(); // Unset the current chair. for (BFCPFloorControlServer::Users::iterator it=this->users.begin(); it!=this->users.end(); ++it) { BFCPUser* otherUser = it->second; otherUser->UnsetChair(); } ::Log("BFCPFloorControlServer::SetChair() | user '%d' becomes chair\n", userId); user->SetChair(); //Unlock after chair is set users.Unlock(); return true; }
apidl_t PidlFixture::directory_pidl(const wpath& directory) { return swish_pidl() + create_host_itemid( Utf8StringToWideString(GetHost()), Utf8StringToWideString(GetUser()), directory, GetPort()); }
void IBattle::OnSelfLeftBattle() { GetMe().BattleStatus().spectator = false; // always reset back yourself to player when rejoining if ( m_timer ) m_timer->Stop(); delete m_timer; m_timer = 0; m_is_self_in = false; for( size_t j = 0; j < GetNumUsers(); ++j ) { User& u = GetUser( j ); if ( u.GetBattleStatus().IsBot() ) { OnUserRemoved( u ); ui().OnUserLeftBattle( *this, u, true ); j--; } } ClearStartRects(); m_teams_sizes.clear(); m_ally_sizes.clear(); m_players_ready = 0; m_players_sync = 0; m_players_ok = 0; usync().UnSetCurrentMod(); //left battle }
void List(const CString& sCommand) { CTable Table; unsigned int index = 1; CString sExpanded; Table.AddColumn("Id"); Table.AddColumn("Perform"); Table.AddColumn("Expanded"); for (VCString::const_iterator it = m_vPerform.begin(); it != m_vPerform.end(); it++, index++) { Table.AddRow(); Table.SetCell("Id", CString(index)); Table.SetCell("Perform", *it); if (m_pNetwork) { sExpanded = m_pNetwork->ExpandString(*it); } else { sExpanded = GetUser()->ExpandString(*it); } if (sExpanded != *it) { Table.SetCell("Expanded", sExpanded); } } if (PutModule(Table) == 0) { PutModule("No commands in your perform list."); } }
void OnModCommand(const CString& sCommand) override { if (!GetUser()->IsAdmin()) { PutModule("Access denied"); } else { HandleCommand(sCommand); } }
virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg) { if (!GetUser()) { return CONTINUE; } EModRet result = HALT; PSTART; PUSH_STR(sModName); PUSH_STR(sArgs); PUSH_PTR(CUser*, GetUser()); PCALL("ZNC::Core::LoadModule"); if (SvTRUE(ERRSV)) { sRetMsg = PString(ERRSV); bSuccess = false; result = HALT; DEBUG("Perl ZNC::Core::LoadModule died: " << sRetMsg); } else if (ret < 1 || 2 < ret) { sRetMsg = "Error: Perl ZNC::Core::LoadModule returned " + CString(ret) + " values."; bSuccess = false; result = HALT; } else { ELoadPerlMod eLPM = static_cast<ELoadPerlMod>(SvUV(ST(0))); if (Perl_NotFound == eLPM) { result = CONTINUE; // Not a Perl module } else { sRetMsg = PString(ST(1)); result = HALT; bSuccess = eLPM == Perl_Loaded; } } PEND; return result; }
UserPosition IBattle::GetFreePosition() { UserPosition ret; LSL::UnitsyncMap map = LoadMap(); for ( int i = 0; i < int(map.info.positions.size()); i++ ) { bool taken = false; for ( unsigned int bi = 0; bi < GetNumUsers(); bi++ ) { User& user = GetUser( bi ); UserBattleStatus& status = user.BattleStatus(); if ( status.spectator ) continue; if ( ( map.info.positions[i].x == status.pos.x ) && ( map.info.positions[i].y == status.pos.y ) ) { taken = true; break; } } if ( !taken ) { ret.x = LSL::Util::Clamp(map.info.positions[i].x, 0, map.info.width); ret.y = LSL::Util::Clamp(map.info.positions[i].y, 0, map.info.height); return ret; } } ret.x = map.info.width / 2; ret.y = map.info.height / 2; return ret; }
//-------------------------------------------------------------------------------------------------- static tu_UserRef_t GetUserInfo ( le_msg_SessionRef_t currentSession, ///< [IN] Get the user information for this message ///< session. bool* wasCreated ///< [OUT] Was the user info created for this request? ///< Pass NULL if you don't need this. ) //-------------------------------------------------------------------------------------------------- { LE_FATAL_IF(currentSession == NULL, "Bad user message session reference."); // Look up the user id of the requesting connection... uid_t userId; LE_FATAL_IF(le_msg_GetClientUserId(currentSession, &userId) == LE_CLOSED, "tu_GetUserInfo must be called within an active connection."); // Now that we have a user ID, let's see if we can look them up. tu_UserRef_t userRef = GetUser(userId, wasCreated); LE_ASSERT(userRef != NULL); LE_DEBUG("** Found user <%p>: '%s', %u with default tree, '%s'.", userRef, userRef->userName, userRef->userId, userRef->treeName); return userRef; }
void CWebSock::SetVars() { m_Template["SessionUser"] = GetUser(); m_Template["SessionIP"] = GetRemoteIP(); m_Template["Tag"] = CZNC::GetTag(GetSession()->GetUser() != NULL); m_Template["SkinName"] = GetSkinName(); m_Template["_CSRF_Check"] = GetCSRFCheck(); if (GetSession()->IsAdmin()) { m_Template["IsAdmin"] = "true"; } GetSession()->FillMessageLoops(m_Template); GetSession()->ClearMessageLoops(); // Global Mods CGlobalModules& vgMods = CZNC::Get().GetModules(); for (unsigned int a = 0; a < vgMods.size(); a++) { AddModLoop("GlobalModLoop", *vgMods[a]); } // User Mods if (IsLoggedIn()) { CModules& vMods = GetSession()->GetUser()->GetModules(); for (unsigned int a = 0; a < vMods.size(); a++) { AddModLoop("UserModLoop", *vMods[a]); } } if (IsLoggedIn()) { m_Template["LoggedIn"] = "true"; } }
bool CCardVideoSystem::AddRecordingToCardNumber(LPCTSTR strCardNumber, LPCTSTR strRecordingName, LONG iVideoStorageServerId, LONG iStreamingEncoderId, LPCTSTR strSessionId, LPCTSTR strSessionName, LPCTSTR strDisplayName) { ASSERT(0 != m_pSystem); CardVideoObjects::_UserPtr pUser; IDispatchPtr pDispatch; pUser = GetUser(strCardNumber); if (pUser) { CString sError; bool b = false; try { // b = (VARIANT_TRUE == pUser->CreateMeARecording(_bstr_t(strRecordingName),iVideoStorageServerId)); b = (VARIANT_TRUE == pUser->CreateMeARecording(_bstr_t(strRecordingName),iVideoStorageServerId, iStreamingEncoderId,_bstr_t(strSessionId),_bstr_t(strSessionName),_bstr_t(strDisplayName))); } catch (_com_error ce) { sError = (LPCTSTR)ce.Description(); } catch (...) { sError = "Uncaught exception."; } return b; } return false; }
bool pgConn::IsSuperuser() { wxString res = ExecuteScalar( wxT("SELECT rolsuper FROM pg_roles ") wxT("WHERE rolname='") + qtIdent(GetUser()) + wxT("'")); return StrToBool(res); }
virtual EModRet OnPrivMsg(CNick &Nick, CString &sMessage) { if(Nick.GetNick() == GetUser()->GetIRCNick().GetNick() && sMessage == "\xAE") return HALT; return CONTINUE; }
int IBattle::GetPlayerNum( const User& user ) const { for (user_map_t::size_type i = 0; i < GetNumUsers(); i++) { if ( &GetUser(i) == &user ) return i; } ASSERT_EXCEPTION(false, _T("The player is not in this game.") ); return -1; }
void ClearAllBuffers() { const vector<CChan*>& vChans = GetUser()->GetChans(); vector<CChan*>::const_iterator it; for (it = vChans.begin(); it != vChans.end(); ++it) { (*it)->ClearBuffer(); } }
virtual void OnClientDisconnect() { if (!m_pUser->GetAllClients().empty()) return; for (VCString::iterator it = m_vPerform.begin(); it != m_vPerform.end(); it++) { PutIRC(GetUser()->ExpandString(*it)); } }
virtual void OnModCommand(const CString& sCommand) { if (!GetUser()->IsAdmin()) { PutModule("Access denied"); return; } CString sCmd = sCommand.Token(0); if (sCmd.Equals("target")) { CString sArg = sCommand.Token(1, true); CString sTarget; CString sMessage; LogMode mode; if (sArg.Equals("file")) { sTarget = "file"; sMessage = "Now only logging to file"; mode = LOG_TO_FILE; } else if (sArg.Equals("syslog")) { sTarget = "syslog"; sMessage = "Now only logging to syslog"; mode = LOG_TO_SYSLOG; } else if (sArg.Equals("both")) { sTarget = "both"; sMessage = "Now logging to file and syslog"; mode = LOG_TO_BOTH; } else { PutModule("Unknown target"); return; } Log(sMessage); SetNV("target", sTarget); m_eLogMode = mode; PutModule(sMessage); } else if (sCmd.Equals("show")) { CString sTarget; switch (m_eLogMode) { case LOG_TO_FILE: sTarget = "file"; break; case LOG_TO_SYSLOG: sTarget = "syslog"; break; case LOG_TO_BOTH: sTarget = "both, file and syslog"; break; } PutModule("Logging is enabled for " + sTarget); if (m_eLogMode != LOG_TO_SYSLOG) PutModule("Log file will be written to [" + m_sLogFile + "]"); } else PutModule("Commands: show, target <file|syslog|both>"); }
/* * Lwt_LsaOpenSession * * Check that LsaEnumUsers, LsaBeginEnumUsers, LsaEndEnumUsers behave * as expected, mostly by matching information against pUsersCsv. */ DWORD Lwt_LsaOpenSession( HANDLE hLsaConnection, PTESTDATA pTestData ) { DWORD dwError = LW_ERROR_SUCCESS; DWORD dwLocalError = LW_ERROR_SUCCESS; size_t nCurrentUser; PLWTUSER pUser = NULL; if ( ! pTestData) { dwError = LW_ERROR_TEST_SKIPPED; goto error; } /* For each user (line), verify the information is correct. */ for ( nCurrentUser = 0; nCurrentUser < pTestData->dwNumUsers; nCurrentUser++) { dwLocalError = GetUser(pTestData, nCurrentUser, &pUser); BAIL_ON_TEST_BROKE(dwLocalError); if ( !IsNullOrEmpty(pUser->pszNTName) ) { dwLocalError = CheckLsaOpenSession( hLsaConnection, pUser->pszNTName, pUser); BAIL_ON_TEST_BROKE(dwLocalError); } if ( !IsNullOrEmpty(pUser->pszUserPrincipalName) ) { dwLocalError = CheckLsaOpenSession( hLsaConnection, pUser->pszUserPrincipalName, pUser); BAIL_ON_TEST_BROKE(dwLocalError); } FreeUser(&pUser); } dwLocalError = VerifyNullHandling(hLsaConnection); BAIL_ON_TEST_BROKE(dwLocalError); cleanup: return dwError; error: goto cleanup; }