All pastes #989406 Raw Edit

Untitled

public text v1 · immutable
#989406 ·published 2008-04-19 09:33 UTC
rendered paste body
/// Display info on users currently in the realm
void CliInfo(char*,pPrintf zprintf)
{
    uint32 activeClientsNum = sWorld.GetActiveSessionCount();
    uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
    uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
    uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
    std::string timeStr = secsToTimeString(sWorld.GetUptime(),true);

    zprintf("Online players: %u (max: %u) queued: %u (max: %u) Uptime: %s\r\n",activeClientsNum,maxActiveClientsNum,queuedClientsNum,maxQueuedClientsNum,timeStr.c_str());

    ///- Get the list of accounts ID logged to the realm
    QueryResult *resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0");

    if (!resultDB)
        return;

    int linesize = 1+15+2+20+3+15+2+4+1+5+3;                // see format string
	std::string sInfo;
	sInfo.reserve(resultDB->GetRowCount()*linesize+1);
	sInfo = "";
	char szLine[512];
	///- Circle through accounts
    do
    {
		szLine[0] = '\0';
        Field *fieldsDB = resultDB->Fetch();
        std::string name = fieldsDB[0].GetCppString();
        uint32 account = fieldsDB[1].GetUInt32();

        ///- Get the username, last IP and GM level of each account
        // No SQL injection. account is uint32.
        //                                                      0         1        2        3
        QueryResult *resultLogin = loginDatabase.PQuery("SELECT username, last_ip, gmlevel, tbc FROM account WHERE id = '%u'",account);

        if(resultLogin)
        {
            Field *fieldsLogin = resultLogin->Fetch();
            sprintf(szLine,"|%15s| %20s | %15s |%4d|%5d|\r\n",
                fieldsLogin[0].GetString(),name.c_str(),fieldsLogin[1].GetString(),fieldsLogin[2].GetUInt32(),fieldsLogin[3].GetUInt32());

            delete resultLogin;
        }
        else
            sprintf(szLine, "|<Error>        | %20s |<Error>          |<Er>|<Err>|\r\n",name.c_str());
		sInfo+=szLine;

    }while(resultDB->NextRow());
    sInfo += "\0";

    ///- Display the list of account/characters online
    zprintf("=====================================================================\r\n");
    zprintf("|    Account    |       Character      |       IP        | GM | TBC |\r\n");
    zprintf("=====================================================================\r\n");
    zprintf("%s",sInfo.c_str());
    zprintf("=====================================================================\r\n");
    delete resultDB;
}