示例#1
0
/*
 * Unmap a row in a table
 * \param tableIndex is the table to find row
 * \param key is the 64 bits row key
 * Return true if succeded
 */
bool	CDatabase::unmapRow(RY_PDS::TTableIndex tableIndex, uint64 key)
{
	if (!initialised())
	{
		PDS_WARNING("unmapRow(): database not initialised");
		return false;
	}

	CTable	*table = getNonConstTable(tableIndex);

	if (table == NULL || !table->initialised())
	{
		PDS_WARNING("deallocate(): table '%d' is not initialised", tableIndex);
		return false;
	}

	bool	success = table->unmapRow(key);

	if (success)
		PDS_FULL_DEBUG("unmapped '%016"NL_I64"X' successfully", key);

	return success;
}
示例#2
0
// ------------------------------------------------------------------------------------------------
// Recursive function to collect all the combinations of factors
// ------------------------------------------------------------------------------------------------
void CFactorizer::CollectFactorCombinations(const CTable<uintn>& factors, uintn curr, uintn prod,
                                            CTable<uintn>& divisors) {
    uintn numfactors = factors.Count();
    uintn f = factors[curr];

    // -- look for the upper bound of the same factor
    uintn end = curr;
    while(end < numfactors && factors[end] == f)
        ++end;

    // -- figure out if we're the end of the line and so we should be adding into the table
    flagn record = end == numfactors;

    // -- loop over the number of times this factor is repeated and deal with all of them
    for(uintn i = curr; i <= end; ++i) {
        if(record)
            divisors.Grow(prod);
        else
            CollectFactorCombinations(factors, end, prod, divisors);

        prod *= f;
    }
}
示例#3
0
/*
 * Locate a column using a path
 */
CTable::CDataAccessor	CDbManager::locate(CLocatePath &path)
{
	CHECK_DB_MGR_INIT(getDatabase, CTable::CDataAccessor());

	if (path.end())
		return CTable::CDataAccessor();

	TDatabaseId		id;
	NLMISC::fromString(path.node().Name, id);
	if (!path.next())
		return CTable::CDataAccessor();

	CDatabase*		db = getDatabase(id);
	if (db == NULL)
		return CTable::CDataAccessor();

	CTable*	table = const_cast<CTable*>(db->getTable(path.node().Name));
	if (table == NULL)
		return CTable::CDataAccessor();

	path.next();

	return table->getAccessor(path);
}
示例#4
0
文件: email.cpp 项目: stephank/znc
	void ParseEmails(const vector<EmailST> & vEmails)
	{
		if (!m_bInitialized)
		{
			m_bInitialized = true;
			for (u_int a = 0; a < vEmails.size(); a++)
				m_ssUidls.insert(vEmails[a].sUidl);

			stringstream s;
			s << "You have " << vEmails.size() << " emails.";
			PutModule(s.str());
		} else
		{
			set<CString> ssUidls;

			CTable Table;
			Table.AddColumn("From");
			Table.AddColumn("Size");
			Table.AddColumn("Subject");

			for (u_int a = 0; a < vEmails.size(); a++)
			{
				if (m_ssUidls.find(vEmails[a].sUidl) == m_ssUidls.end())
				{
					//PutModule("------------------- New Email -------------------");
					Table.AddRow();
					Table.SetCell("From", vEmails[a].sFrom.Ellipsize(32));
					Table.SetCell("Size", CString(vEmails[a].iSize));
					Table.SetCell("Subject", vEmails[a].sSubject.Ellipsize(64));
				}
				ssUidls.insert(vEmails[a].sUidl);
			}

			m_ssUidls = ssUidls; // keep the list in synch

			if (Table.size()) {
				PutModule(Table);

				stringstream s;
				s << "You have " << vEmails.size() << " emails.";
				PutModule(s.str());
			}
		}
	}
示例#5
0
int main(){
	//打开表接口
	CMysql mysql;
	CTable* pTable = mysql.OpenTableInterface("test",1);
	CString xxx = (*pTable)[0]["name"].toValue();

	//增
	//设置记录
	CRecord rec(pTable);
	rec["name"] = "e";
	rec["number"] = 5;
	//pTable->Add(&rec);

	//定义条件
	CCondition con;
	//条件and
	con && (CTableField("test","name") == "d");
	con || (CTableField("test","name") == "e");
	con && (CTableField("test","number") <= 5);
	con(0,4);
	con["test.name"]--;
	//条件or,左联合
	//con || (CTableField("User","ID") <= CTableField("Department","UserID"));
	//条件not
	//!con;

	//删
	//int x = pTable->Delete(&con);

	//改
	CUpdate upd;
	upd["ID"] = 10005;
	pTable->UpdateRecord(&upd,&con);

	//查
	CSelect sel;
	sel("test")["name"];
	sel("test")["ID"];
	sel("Depart")["name"];
	CTable table = pTable->SelectRecord(&sel,&con);
	CTable *pTable1 = mysql.OpenTableInterface("Depart");
	CString strr = (*pTable1)[0]["depart.name"].toValue();
	int xxxx = table.size();
	CString strDepartName = table[0]["depart.name"].toValue();
	int nUserID = table[0]["User.ID"].toValue();
	
	//rec["User"].pTable->mapAttri["User"].Name = "123456";
	//修改字段属性
	rec["User"]->nLength = 256;
	pTable->Add(&rec);

	return 0;
}
示例#6
0
void CIdentServerMod::OnModCommand(const CString& sLine)
{
	CString sCommand = sLine.Token(0);

	if(sCommand.Equals("HELP"))
	{
		CTable Table;
		Table.AddColumn("Command");
		Table.AddColumn("Description");

		Table.AddRow();
		Table.SetCell("Command", "Status");
		Table.SetCell("Description", "Displays status information about IdentServer");

		PutModule(Table);
		return;
	}
	else if(sCommand.Equals("STATUS"))
	{
		if(m_identServer)
		{
			PutModule("IdentServer is listening on: " + m_identServer->GetLocalIP() + ":" + CString(m_serverPort));

			if(m_pUser->IsAdmin())
			{
				PutModule("List of active users/networks:");

				for(CIRCNetwork* pNetwork : m_identServer->GetActiveUsers())
				{
					PutModule("* " + pNetwork->GetUser()->GetCleanUserName() + "/" + pNetwork->GetName());
				}
			}
		}
		else
		{
			if(m_listenFailed)
			{
				PutModule("WARNING: Opening the listening socket failed!");
			}
			PutModule("IdentServer isn't listening.");
		}
		if(m_pUser->IsAdmin())
		{
			PutModule("Last IDENT request: " + m_sLastRequest);
			PutModule("Last IDENT reply: " + m_sLastReply);
		}
	}
	else
	{
		PutModule("Unknown command [" + sCommand + "] try 'Help'");
	}
}
示例#7
0
	void HandleList(const CString& sLine) {
		CTable Table;
		Table.AddColumn("Neg");
		Table.AddColumn("Chan");
		Table.AddColumn("Host");

		VAttachIter it = m_vMatches.begin();
		for (; it != m_vMatches.end(); ++it) {
			Table.AddRow();
			Table.SetCell("Neg", it->IsNegated() ? "!" : "");
			Table.SetCell("Chan", it->GetChans());
			Table.SetCell("Host", it->GetHostMask());
		}

		if (Table.size()) {
			PutModule(Table);
		} else {
			PutModule("You have no entries.");
		}
	}
示例#8
0
文件: log.cpp 项目: Adam-/znc
void CLogMod::ListRulesCmd(const CString& sLine) {
    CTable Table;
    Table.AddColumn("Rule");
    Table.AddColumn("Logging enabled");

    for (const CLogRule& Rule : m_vRules) {
        Table.AddRow();
        Table.SetCell("Rule", Rule.GetRule());
        Table.SetCell("Logging enabled", CString(Rule.IsEnabled()));
    }

    if (Table.empty()) {
        PutModule("No logging rules. Everything is logged.");
    } else {
        PutModule(Table);
    }
}
示例#9
0
文件: crypt.cpp 项目: jpnurmi/znc
	void OnListKeysCommand(const CString& sCommand) {
		if (BeginNV() == EndNV()) {
			PutModule("You have no encryption keys set.");
		} else {
			CTable Table;
			Table.AddColumn("Target");
			Table.AddColumn("Key");

			for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
				Table.AddRow();
				Table.SetCell("Target", it->first);
				Table.SetCell("Key", it->second);
			}

			MCString::iterator it = FindNV(NICK_PREFIX_KEY);
			if (it == EndNV()) {
				Table.AddRow();
				Table.SetCell("Target", NICK_PREFIX_KEY);
				Table.SetCell("Key", NickPrefix());
			}

			PutModule(Table);
		}
	}
示例#10
0
	void ListCommand(const CString &sLine) {
		CTable Table;
		Table.AddColumn("Host");
		Table.AddColumn("Network");
		Table.AddColumn("Away");

		const vector<CClient*> vClients = m_pUser->GetAllClients();

		for (vector<CClient*>::const_iterator it = vClients.begin(); it != vClients.end(); ++it) {
			CClient *pClient = *it;

			Table.AddRow();
			Table.SetCell("Host", pClient->GetRemoteIP());
			if (pClient->GetNetwork()) {
				Table.SetCell("Network", pClient->GetNetwork()->GetName());
			}
			Table.SetCell("Away", CString(pClient->IsAway()));
		}

		PutModule(Table);
	}
示例#11
0
文件: crypt.cpp 项目: bpcampbe/znc
	virtual void OnModCommand(const CString& sCommand) {
		CString sCmd = sCommand.Token(0);

		if (sCmd.Equals("DELKEY")) {
			CString sTarget = sCommand.Token(1);

			if (!sTarget.empty()) {
				if (DelNV(sTarget.AsLower())) {
					PutModule("Target [" + sTarget + "] deleted");
				} else {
					PutModule("Target [" + sTarget + "] not found");
				}
			} else {
				PutModule("Usage DelKey <#chan|Nick>");
			}
		} else if (sCmd.Equals("SETKEY")) {
			CString sTarget = sCommand.Token(1);
			CString sKey = sCommand.Token(2, true);

			// Strip "cbc:" from beginning of string incase someone pastes directly from mircryption
			sKey.TrimPrefix("cbc:");

			if (!sKey.empty()) {
				SetNV(sTarget.AsLower(), sKey);
				PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
			} else {
				PutModule("Usage: SetKey <#chan|Nick> <Key>");
			}
		} else if (sCmd.Equals("LISTKEYS")) {
			if (BeginNV() == EndNV()) {
				PutModule("You have no encryption keys set.");
			} else {
				CTable Table;
				Table.AddColumn("Target");
				Table.AddColumn("Key");

				for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
					Table.AddRow();
					Table.SetCell("Target", it->first);
					Table.SetCell("Key", it->second);
				}

				PutModule(Table);
			}
		} else if (sCmd.Equals("HELP")) {
			PutModule("Try: SetKey, DelKey, ListKeys");
		} else {
			PutModule("Unknown command, try 'Help'");
		}
	}
示例#12
0
文件: sasl.cpp 项目: ConorOG/znc
	void PrintHelp(const CString& sLine) {
		HandleHelpCommand(sLine);

		CTable Mechanisms;
		Mechanisms.AddColumn("Mechanism");
		Mechanisms.AddColumn("Description");

		for (size_t i = 0; SupportedMechanisms[i].szName != NULL; i++) {
			Mechanisms.AddRow();
			Mechanisms.SetCell("Mechanism",   SupportedMechanisms[i].szName);
			Mechanisms.SetCell("Description", SupportedMechanisms[i].szDescription);
		}

		PutModule("The following mechanisms are available:");
		PutModule(Mechanisms);
	}
示例#13
0
文件: sasl.cpp 项目: DreamBNC/znc
    void PrintHelp(const CString& sLine) {
        HandleHelpCommand(sLine);

        CTable Mechanisms;
        Mechanisms.AddColumn("Mechanism");
        Mechanisms.AddColumn("Description");

        for (const auto& it : SupportedMechanisms) {
            Mechanisms.AddRow();
            Mechanisms.SetCell("Mechanism", it.szName);
            Mechanisms.SetCell("Description", it.szDescription);
        }

        PutModule("The following mechanisms are available:");
        PutModule(Mechanisms);
    }
示例#14
0
	void List(const CString& sCommand) {
		CTable Table;
		unsigned int index = 1;

		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);

			CString sExpanded = ExpandString(*it);

			if (sExpanded != *it) {
				Table.SetCell("Expanded", sExpanded);
			}
		}

		if (PutModule(Table) == 0) {
			PutModule("No commands in your perform list.");
		}
	}
示例#15
0
文件: perform.cpp 项目: GLolol/znc
    void List(const CString& sCommand) {
        CTable Table;
        unsigned int index = 1;

        Table.AddColumn(t_s("Id", "list"));
        Table.AddColumn(t_s("Perform", "list"));
        Table.AddColumn(t_s("Expanded", "list"));

        for (const CString& sPerf : m_vPerform) {
            Table.AddRow();
            Table.SetCell(t_s("Id", "list"), CString(index++));
            Table.SetCell(t_s("Perform", "list"), sPerf);

            CString sExpanded = ExpandString(sPerf);

            if (sExpanded != sPerf) {
                Table.SetCell(t_s("Expanded", "list"), sExpanded);
            }
        }

        if (PutModule(Table) == 0) {
            PutModule(t_s("No commands in your perform list."));
        }
    }
示例#16
0
文件: ignore.cpp 项目: Xe/dotfiles
	void HandleListCommand(const CString& sLine) {
		CTable Table;
		Table.AddColumn("Hostmask");
		Table.AddColumn("Type");

		for (vector<CIgnore>::const_iterator it = m_vIgnores.begin(); it != m_vIgnores.end(); ++it) {
			const CIgnore& Ignore = *it;

			Table.AddRow();
			Table.SetCell("Hostmask", Ignore.GetHostmask());
			Table.SetCell("Type",     Ignore.GetType());
		}

		if (!PutModule(Table)) {
			PutModule("You are not ignoring anyone");
		}
	}
示例#17
0
	void OnListUsersCommand(const CString& sLine) {
		if (m_msUsers.empty()) {
			PutModule("There are no users defined");
			return;
		}

		CTable Table;

		Table.AddColumn("User");
		Table.AddColumn("Hostmask");
		Table.AddColumn("Channels");

		for (const auto& it : m_msUsers) {
			Table.AddRow();
			Table.SetCell("User", it.second->GetUsername());
			Table.SetCell("Hostmask", it.second->GetHostmask());
			Table.SetCell("Channels", it.second->GetChannels());
		}

		PutModule(Table);
	}
示例#18
0
	void OnListUsersCommand(const CString& sLine) {
		if (m_msUsers.empty()) {
			PutModule("There are no users defined");
			return;
		}

		CTable Table;

		Table.AddColumn("User");
		Table.AddColumn("Hostmask");
		Table.AddColumn("Channels");

		for (map<CString, CAutoVoiceUser*>::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) {
			Table.AddRow();
			Table.SetCell("User", it->second->GetUsername());
			Table.SetCell("Hostmask", it->second->GetHostmask());
			Table.SetCell("Channels", it->second->GetChannels());
		}

		PutModule(Table);
	}
示例#19
0
	void ShowCommand(const CString &sLine) {
		if (!GetUser()->IsAdmin()) {
			PutModule("Access denied");
			return;
		}

		const MUsers& mUsers = CZNC::Get().GetUserMap();
		MUsers::const_iterator it;
		CTable Table;

		Table.AddColumn("User");
		Table.AddColumn("Last Seen");

		for (it = mUsers.begin(); it != mUsers.end(); ++it) {
			Table.AddRow();
			Table.SetCell("User", it->first);
			Table.SetCell("Last Seen", FormatLastSeen(it->second, "never"));
		}

		PutModule(Table);
	}
示例#20
0
void CModule::ListSockets() {
	if (m_sSockets.empty()) {
		PutModule("You have no open sockets.");
		return;
	}

	CTable Table;
	Table.AddColumn("Name");
	Table.AddColumn("State");
	Table.AddColumn("LocalPort");
	Table.AddColumn("SSL");
	Table.AddColumn("RemoteIP");
	Table.AddColumn("RemotePort");

	set<CSocket*>::iterator it;
	for (it = m_sSockets.begin(); it != m_sSockets.end(); ++it) {
		CSocket* pSocket = *it;

		Table.AddRow();
		Table.SetCell("Name", pSocket->GetSockName());

		if (pSocket->GetType() == CSocket::LISTENER) {
			Table.SetCell("State", "Listening");
		} else {
			Table.SetCell("State", (pSocket->IsConnected() ? "Connected" : ""));
		}

		Table.SetCell("LocalPort", CString(pSocket->GetLocalPort()));
		Table.SetCell("SSL", (pSocket->GetSSL() ? "yes" : "no"));
		Table.SetCell("RemoteIP", pSocket->GetRemoteIP());
		Table.SetCell("RemotePort", (pSocket->GetRemotePort()) ? CString(pSocket->GetRemotePort()) : CString(""));
	}

	PutModule(Table);
}
示例#21
0
文件: autocycle.cpp 项目: jimloco/znc
	virtual void OnModCommand(const CString& sLine) {
		CString sCommand = sLine.Token(0);

		if (sCommand.Equals("ADD")) {
			CString sChan = sLine.Token(1);

			if (AlreadyAdded(sChan)) {
				PutModule(sChan + " is already added");
			} else if (Add(sChan)) {
				PutModule("Added " + sChan + " to list");
			} else {
				PutModule("Usage: Add [!]<#chan>");
			}
		} else if (sCommand.Equals("DEL")) {
			CString sChan = sLine.Token(1);

			if (Del(sChan))
				PutModule("Removed " + sChan + " from list");
			else
				PutModule("Usage: Del [!]<#chan>");
		} else if (sCommand.Equals("LIST")) {
			CTable Table;
			Table.AddColumn("Chan");

			for (unsigned int a = 0; a < m_vsChans.size(); a++) {
				Table.AddRow();
				Table.SetCell("Chan", m_vsChans[a]);
			}

			for (unsigned int b = 0; b < m_vsNegChans.size(); b++) {
				Table.AddRow();
				Table.SetCell("Chan", "!" + m_vsNegChans[b]);
			}

			if (Table.size()) {
				PutModule(Table);
			} else {
				PutModule("You have no entries.");
			}
		} else if (sCommand.Equals("HELP")) {
			CTable Table;
			Table.AddColumn("Command");
			Table.AddColumn("Description");

			Table.AddRow();
			Table.SetCell("Command", "Add");
			Table.SetCell("Description", "Add an entry, use !#chan to negate and * for wildcards");

			Table.AddRow();
			Table.SetCell("Command", "Del");
			Table.SetCell("Description", "Remove an entry, needs to be an exact match");

			Table.AddRow();
			Table.SetCell("Command", "List");
			Table.SetCell("Description", "List all entries");

			if (Table.size()) {
				PutModule(Table);
			} else {
				PutModule("You have no entries.");
			}
		}
	}
示例#22
0
    void ShowSocks(bool bShowHosts) {
        if (CZNC::Get().GetManager().empty()) {
            PutStatus("You have no open sockets.");
            return;
        }

        std::priority_queue<CSocketSorter> socks = GetSockets();

        CTable Table;
        Table.AddColumn("Name");
        Table.AddColumn("Created");
        Table.AddColumn("State");
#ifdef HAVE_LIBSSL
        Table.AddColumn("SSL");
#endif
        Table.AddColumn("Local");
        Table.AddColumn("Remote");
        Table.AddColumn("In");
        Table.AddColumn("Out");

        while (!socks.empty()) {
            Csock* pSocket = socks.top().GetSock();
            socks.pop();

            Table.AddRow();
            Table.SetCell("Name", pSocket->GetSockName());
            Table.SetCell("Created", GetCreatedTime(pSocket));
            Table.SetCell("State", GetSocketState(pSocket));

#ifdef HAVE_LIBSSL
            Table.SetCell("SSL", pSocket->GetSSL() ? "Yes" : "No");
#endif

            Table.SetCell("Local", GetLocalHost(pSocket, bShowHosts));
            Table.SetCell("Remote", GetRemoteHost(pSocket, bShowHosts));
            Table.SetCell("In", CString::ToByteStr(pSocket->GetBytesRead()));
            Table.SetCell("Out",
                          CString::ToByteStr(pSocket->GetBytesWritten()));
        }

        PutModule(Table);
        return;
    }
示例#23
0
文件: Client.cpp 项目: evilnet/znc
unsigned int CClient::PutStatus(const CTable& table) {
    unsigned int idx = 0;
    CString sLine;
    while (table.GetLine(idx++, sLine)) PutStatus(sLine);
    return idx - 1;
}
示例#24
0
void CModCommand::AddHelp(CTable& Table) const {
    Table.AddRow();
    Table.SetCell("Command", GetCommand());
    Table.SetCell("Arguments", GetArgs());
    Table.SetCell("Description", GetDescription());
}
示例#25
0
void CModCommand::InitHelp(CTable& Table) {
    Table.AddColumn("Command");
    Table.AddColumn("Arguments");
    Table.AddColumn("Description");
}
示例#26
0
文件: dcc.cpp 项目: aszrul/znc
    void ListTransfersCommand(const CString& sLine) {
        CTable Table;
        Table.AddColumn(t_s("Type", "list"));
        Table.AddColumn(t_s("State", "list"));
        Table.AddColumn(t_s("Speed", "list"));
        Table.AddColumn(t_s("Nick", "list"));
        Table.AddColumn(t_s("IP", "list"));
        Table.AddColumn(t_s("File", "list"));

        set<CSocket*>::const_iterator it;
        for (it = BeginSockets(); it != EndSockets(); ++it) {
            CDCCSock* pSock = (CDCCSock*)*it;

            Table.AddRow();
            Table.SetCell(t_s("Nick", "list"), pSock->GetRemoteNick());
            Table.SetCell(t_s("IP", "list"), pSock->GetRemoteIP());
            Table.SetCell(t_s("File", "list"), pSock->GetFileName());

            if (pSock->IsSend()) {
                Table.SetCell(t_s("Type", "list"), t_s("Sending", "list-type"));
            } else {
                Table.SetCell(t_s("Type", "list"), t_s("Getting", "list-type"));
            }

            if (pSock->GetType() == Csock::LISTENER) {
                Table.SetCell(t_s("State", "list"),
                              t_s("Waiting", "list-state"));
            } else {
                Table.SetCell(t_s("State", "list"),
                              CString::ToPercent(pSock->GetProgress()));
                Table.SetCell(t_s("Speed", "list"),
                              t_f("{1} KiB/s")(static_cast<int>(
                                  pSock->GetAvgRead() / 1024.0)));
            }
        }

        if (PutModule(Table) == 0) {
            PutModule(t_s("You have no active DCC transfers."));
        }
    }
示例#27
0
    void ShowSocks(bool bShowHosts) {
        CSockManager& m = CZNC::Get().GetManager();
        if (!m.size()) {
            PutStatus("You have no open sockets.");
            return;
        }

        std::priority_queue<CSocketSorter> socks;

        for (unsigned int a = 0; a < m.size(); a++) {
            socks.push(m[a]);
        }

        CTable Table;
        Table.AddColumn("Name");
        Table.AddColumn("Created");
        Table.AddColumn("State");
#ifdef HAVE_LIBSSL
        Table.AddColumn("SSL");
#endif
        Table.AddColumn("Local");
        Table.AddColumn("Remote");

        while (!socks.empty()) {
            Csock* pSocket = socks.top().GetSock();
            socks.pop();

            Table.AddRow();

            switch (pSocket->GetType()) {
            case Csock::LISTENER:
                Table.SetCell("State", "Listen");
                break;
            case Csock::INBOUND:
                Table.SetCell("State", "Inbound");
                break;
            case Csock::OUTBOUND:
                if (pSocket->IsConnected())
                    Table.SetCell("State", "Outbound");
                else
                    Table.SetCell("State", "Connecting");
                break;
            default:
                Table.SetCell("State", "UNKNOWN");
                break;
            }

            unsigned long long iStartTime = pSocket->GetStartTime();
            time_t iTime = iStartTime / 1000;
            Table.SetCell("Created", FormatTime("%Y-%m-%d %H:%M:%S", iTime));

#ifdef HAVE_LIBSSL
            if (pSocket->GetSSL()) {
                Table.SetCell("SSL", "Yes");
            } else {
                Table.SetCell("SSL", "No");
            }
#endif


            Table.SetCell("Name", pSocket->GetSockName());
            CString sVHost;
            if (bShowHosts) {
                sVHost = pSocket->GetBindHost();
            }
            if (sVHost.empty()) {
                sVHost = pSocket->GetLocalIP();
            }
            Table.SetCell("Local", sVHost + " " + CString(pSocket->GetLocalPort()));

            CString sHost;
            if (!bShowHosts) {
                sHost = pSocket->GetRemoteIP();
            }
            // While connecting, there might be no ip available
            if (sHost.empty()) {
                sHost = pSocket->GetHostName();
            }

            u_short uPort;
            // While connecting, GetRemotePort() would return 0
            if (pSocket->GetType() == Csock::OUTBOUND) {
                uPort = pSocket->GetPort();
            } else {
                uPort = pSocket->GetRemotePort();
            }
            if (uPort != 0) {
                Table.SetCell("Remote", sHost + " " + CString(uPort));
            } else {
                Table.SetCell("Remote", sHost);
            }
        }

        PutModule(Table);
        return;
    }
示例#28
0
文件: schat.cpp 项目: johnfb/znc
	virtual void OnModCommand(const CString& sCommand)
	{
		CString sCom = sCommand.Token(0);
		CString sArgs = sCommand.Token(1, true);

		if (sCom.Equals("chat") && !sArgs.empty()) {
			CString sNick = "(s)" + sArgs;
			set<CSocket*>::const_iterator it;
			for (it = BeginSockets(); it != EndSockets(); ++it) {
				CSChatSock *pSock = (CSChatSock*) *it;

				if (pSock->GetChatNick().Equals(sNick)) {
					PutModule("Already Connected to [" + sArgs + "]");
					return;
				}
			}

			CSChatSock *pSock = new CSChatSock(this, sNick);
			pSock->SetCipher("HIGH");
			pSock->SetPemLocation(m_sPemFile);

			u_short iPort = m_pManager->ListenRand(pSock->GetSockName() + "::LISTENER",
					m_pUser->GetLocalDCCIP(), true, SOMAXCONN, pSock, 60);

			if (iPort == 0) {
				PutModule("Failed to start chat!");
				return;
			}

			stringstream s;
			s << "PRIVMSG " << sArgs << " :\001";
			s << "DCC SCHAT chat ";
			s << CUtils::GetLongIP(m_pUser->GetLocalDCCIP());
			s << " " << iPort << "\001";

			PutIRC(s.str());

		} else if (sCom.Equals("list")) {
			CTable Table;
			Table.AddColumn("Nick");
			Table.AddColumn("Created");
			Table.AddColumn("Host");
			Table.AddColumn("Port");
			Table.AddColumn("Status");
			Table.AddColumn("Cipher");

			set<CSocket*>::const_iterator it;
			for (it = BeginSockets(); it != EndSockets(); ++it) {
				Table.AddRow();

				CSChatSock *pSock = (CSChatSock*) *it;
				Table.SetCell("Nick", pSock->GetChatNick());
				unsigned long long iStartTime = pSock->GetStartTime();
				time_t iTime = iStartTime / 1000;
				char *pTime = ctime(&iTime);
				if (pTime) {
					CString sTime = pTime;
					sTime.Trim();
					Table.SetCell("Created", sTime);
				}

				if (pSock->GetType() != CSChatSock::LISTENER) {
					Table.SetCell("Status", "Established");
					Table.SetCell("Host", pSock->GetRemoteIP());
					Table.SetCell("Port", CString(pSock->GetRemotePort()));
					SSL_SESSION *pSession = pSock->GetSSLSession();
					if (pSession && pSession->cipher && pSession->cipher->name)
						Table.SetCell("Cipher", pSession->cipher->name);

				} else {
					Table.SetCell("Status", "Waiting");
					Table.SetCell("Port", CString(pSock->GetLocalPort()));
				}
			}
			if (Table.size()) {
				PutModule(Table);
			} else
				PutModule("No SDCCs currently in session");

		} else if (sCom.Equals("close")) {
			if (!sArgs.Equals("(s)", false, 3))
				sArgs = "(s)" + sArgs;

			set<CSocket*>::const_iterator it;
			for (it = BeginSockets(); it != EndSockets(); ++it) {
				CSChatSock *pSock = (CSChatSock*) *it;

				if (sArgs.Equals(pSock->GetChatNick())) {
					pSock->Close();
					return;
				}
			}
			PutModule("No Such Chat [" + sArgs + "]");
		} else if (sCom.Equals("showsocks") && m_pUser->IsAdmin()) {
			CTable Table;
			Table.AddColumn("SockName");
			Table.AddColumn("Created");
			Table.AddColumn("LocalIP:Port");
			Table.AddColumn("RemoteIP:Port");
			Table.AddColumn("Type");
			Table.AddColumn("Cipher");

			set<CSocket*>::const_iterator it;
			for (it = BeginSockets(); it != EndSockets(); ++it) {
				Table.AddRow();
				Csock *pSock = *it;
				Table.SetCell("SockName", pSock->GetSockName());
				unsigned long long iStartTime = pSock->GetStartTime();
				time_t iTime = iStartTime / 1000;
				char *pTime = ctime(&iTime);
				if (pTime) {
					CString sTime = pTime;
					sTime.Trim();
					Table.SetCell("Created", sTime);
				}

				if (pSock->GetType() != Csock::LISTENER) {
					if (pSock->GetType() == Csock::OUTBOUND)
						Table.SetCell("Type", "Outbound");
					else
						Table.SetCell("Type", "Inbound");
					Table.SetCell("LocalIP:Port", pSock->GetLocalIP() + ":" +
							CString(pSock->GetLocalPort()));
					Table.SetCell("RemoteIP:Port", pSock->GetRemoteIP() + ":" +
							CString(pSock->GetRemotePort()));
					SSL_SESSION *pSession = pSock->GetSSLSession();
					if (pSession && pSession->cipher && pSession->cipher->name)
						Table.SetCell("Cipher", pSession->cipher->name);
					else
						Table.SetCell("Cipher", "None");

				} else {
					Table.SetCell("Type", "Listener");
					Table.SetCell("LocalIP:Port", pSock->GetLocalIP() +
							":" + CString(pSock->GetLocalPort()));
					Table.SetCell("RemoteIP:Port", "0.0.0.0:0");
				}
			}
			if (Table.size())
				PutModule(Table);
			else
				PutModule("Error Finding Sockets");

		} else if (sCom.Equals("help")) {
			PutModule("Commands are:");
			PutModule("    help           - This text.");
			PutModule("    chat <nick>    - Chat a nick.");
			PutModule("    list           - List current chats.");
			PutModule("    close <nick>   - Close a chat to a nick.");
			PutModule("    timers         - Shows related timers.");
			if (m_pUser->IsAdmin()) {
				PutModule("    showsocks      - Shows all socket connections.");
			}
		} else if (sCom.Equals("timers"))
			ListTimers();
		else
			PutModule("Unknown command [" + sCom + "] [" + sArgs + "]");
	}
示例#29
0
void CLounge::processLogouts(long /*now*/)
{
    bool sendUpdate = false;

    //
    // Process logging out players
    //
    list<PlayerPtr>::iterator i = loggingOut_.begin();

    while (i != loggingOut_.end())
    {
        sendUpdate = true;

        string username = (*i).player_->name();
        SOCKET sd = (*i).player_->getSocket();

        printf("Logging out player %s socket %d.\n",
               username.c_str(), sd);

        // Forget ip address
        UnregisterIPAddress((*i).player_->getIpAddress());

        // Erase the player from the main list.
        tolower(username);

        if (players_.erase(username) == 0)
        {   // player was not in main list - erase from
            // logging in list
            LoginPlayers::iterator it = find_if(loggingIn_.begin(),
                                                loggingIn_.end(),
                                                same_socket(sd));
            if (it != loggingIn_.end())
                loggingIn_.erase(it);
        }

        // Terminate the connection
        CPoller::Inst()->removePlayerSocket(sd);
        Sys_CloseSocket(sd);

        // Notify Load Balancer and/or lounges
        notifyOthers(RemovePlayer, username.c_str());


        // Remove it from logging out list
        i = loggingOut_.erase(i);
    }

    //
    // Process logging out tables
    //
    list<TablePtr>::iterator ti = loggingOutTables_.begin();

    while (ti != loggingOutTables_.end())
    {
        sendUpdate = true;

        CTable* table = (*ti).table_;
        printf("*** Removing table %d socket %d.\n",
               table->getNumber(), table->getSocket());

        removeTable(table);

        // NOTE: after removeTable 'table' points to destroyed data

        // Remove it from logging out list
        ti = loggingOutTables_.erase(ti);
    }

    if (sendUpdate)
    {
        // Send login stats update if something was removed
        CpduLoungeStats pduStats;
        pduStats.sendStats(players_.size(), tables_.size());
    }
}
示例#30
0
文件: SSTop.C 项目: fgolf/pac
void PrintSystematics(const std::string& filename, const unsigned int sr_num, const float scale_den = 1.0)
{
    const std::string sr = GetSRLabel(static_cast<ss::SignalRegion::value_type>(sr_num)); 

    // acceptance and systematic plots
    rt::TH1Container hc(filename);

    const float den = rt::Integral(hc[sr+"nGenerated"])*(scale_den);
    value_t num     = IntegralAndError(hc[sr+"nPassing"]);
    value_t eff(num.value/den, num.value/den * (rt::Integral(hc[sr+"effErrStat"])/num.value));
/*     eff.error       = eff.value * (rt::Integral(hc[sr+"effErrStat"])/num.value); */
/*     eff.error       = sqrt(eff.value*(1.0 - eff.value)/den); */
    value_t eff_per = eff;
    eff_per.value   *= 100;
    eff_per.error   *= 100;

    // systematics (percentage) 
    const float jer     = GetSyst(rt::Integral(hc[sr+"nJER"      ]), num.value);
    const float jes     = GetSyst(rt::Integral(hc[sr+"nJESUP"    ]), rt::Integral(hc[sr+"nJESDN"    ]), num.value);
    const float jes_up  = GetSyst(rt::Integral(hc[sr+"nJESUP"    ]), num.value);
    const float jes_dn  = GetSyst(rt::Integral(hc[sr+"nJESDN"    ]), num.value);
    const float beff    = GetSyst(rt::Integral(hc[sr+"nBTAUP"    ]), rt::Integral(hc[sr+"nBTADN"    ]), num.value);
    const float beff_up = GetSyst(rt::Integral(hc[sr+"nBTAUP"    ]), num.value);
    const float beff_dn = GetSyst(rt::Integral(hc[sr+"nBTADN"    ]), num.value);
    const float met     = GetSyst(rt::Integral(hc[sr+"nMETUP"    ]), rt::Integral(hc[sr+"nMETDN"    ]), num.value);
    const float met_up  = GetSyst(rt::Integral(hc[sr+"nMETUP"    ]), num.value);
    const float met_dn  = GetSyst(rt::Integral(hc[sr+"nMETDN"    ]), num.value);
    const float lep     = GetSyst(rt::Integral(hc[sr+"nLepEffUP" ]), rt::Integral(hc[sr+"nLepEffDN" ]), num.value);
    const float trig    = GetSyst(rt::Integral(hc[sr+"nTrigEffUP"]), rt::Integral(hc[sr+"nTrigEffDN"]), num.value);
    const float lumi    = 4.4;
    const float pdf     = 2.0;
    const float stat    = eff.error;
    const float total   = sqrt(pow(jes,2) + pow(jer,2) + pow(beff,2) + pow(met,2) + pow(lep,2) + pow(trig,2) + pow(lumi,2) + pow(pdf,2) + pow(stat,2));

    CTable t;
    t.useTitle();
    t.setTitle(Form("TTBar Acceptance SR %d", sr_num));
    t.setTable() (                    "value"  , "rel unc (1 + dx)"  )
        ("# generated"    , int(den)           , "NA"               )
        ("# passing"      , pm(num, "1.0f")    , "NA"               )
        ("acceptance"     , pm(eff, "1.5f")    , "NA"               )
        ("acceptance"     , pm(eff    , "1.2e"), "NA"               )
        ("acceptance (%)" , pm(eff_per, "1.5f"), "NA"               )
        ("JES        (%)" , jes                , 1.0 + 0.01*jes     )
        ("JES+       (%)" , jes_up             , 1.0 + 0.01*jes_up  )
        ("JES-       (%)" , jes_dn             , 1.0 + 0.01*jes_dn  )
        ("JER        (%)" , jer                , 1.0 + 0.01*jer     )
        ("Btag       (%)" , beff               , 1.0 + 0.01*beff    )
        ("Btag+      (%)" , beff_up            , 1.0 + 0.01*beff_up )
        ("Btag-      (%)" , beff_dn            , 1.0 + 0.01*beff_dn )
        ("MET        (%)" , met                , 1.0 + 0.01*met     )
        ("MET+       (%)" , met_up             , 1.0 + 0.01*met_up  )
        ("MET-       (%)" , met_dn             , 1.0 + 0.01*met_dn  )
        ("Trig       (%)" , trig               , 1.0 + 0.01*trig    )
        ("Lep        (%)" , lep                , 1.0 + 0.01*lep     )
        ("Lumi       (%)" , lumi               , 1.0 + 0.01*lumi    )
        ("Pdf        (%)" , pdf                , 1.0 + 0.01*pdf     )
        ("Stat       (%)" , Form("%1.2e", stat), Form("%1.2e", stat))
        ("Total      (%)" , total              , 1.0 + 0.01*total   )
        ;
    t.print();
    cout << endl;
}