|
From: Bernt H. <bth...@us...> - 2007-02-25 22:26:22
|
Update of /cvsroot/bzflag/bzflag/plugins/logDetail In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2014/plugins/logDetail Modified Files: Tag: v2_0branch logDetail.cpp Log Message: Add bzID and server status Index: logDetail.cpp =================================================================== RCS file: /cvsroot/bzflag/bzflag/plugins/logDetail/logDetail.cpp,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -w -u -r1.1.2.8 -r1.1.2.9 --- logDetail.cpp 18 Feb 2007 21:38:14 -0000 1.1.2.8 +++ logDetail.cpp 25 Feb 2007 22:26:22 -0000 1.1.2.9 @@ -14,23 +14,28 @@ // #include <iostream> +#include <sstream> #include "bzfsAPI.h" BZ_GET_PLUGIN_VERSION using namespace std; +enum action { join , auth , part }; + class LogDetail : public bz_EventHandler { public: - LogDetail() {}; - virtual ~LogDetail() {}; + LogDetail(); + virtual ~LogDetail(); virtual void process( bz_EventData *eventData ); private: void displayPlayerPrivs( int playerID ); void displayCallsign( bzApiString callsign ); void displayCallsign( int playerID ); + void displayBZid( int playerID ); void displayTeam( bz_eTeamType team ); + virtual void listPlayers( action act, bz_PlayerJoinPartEventData *data ); }; LogDetail logDetailHandler; @@ -59,6 +64,18 @@ return 0; } +LogDetail::LogDetail() +{ + cout << "SERVER-STATUS Running" << endl; + listPlayers( join , NULL ); +} + +LogDetail::~LogDetail() +{ + listPlayers( part , NULL ); + cout << "SERVER-STATUS Stopped" << endl; +} + void LogDetail::process( bz_EventData *eventData ) { bz_ChatEventData *chatData = (bz_ChatEventData *) eventData; @@ -139,9 +156,11 @@ cout << "PLAYER-JOIN "; displayCallsign( player->callsign ); cout << " #" << joinPartData->playerID; + displayBZid( joinPartData->playerID ); displayTeam( joinPartData->team ); displayPlayerPrivs( joinPartData->playerID ); cout << endl; + listPlayers( join, joinPartData); } } break; @@ -149,14 +168,17 @@ cout << "PLAYER-PART "; displayCallsign( joinPartData->playerID ); cout << " #" << joinPartData->playerID; + displayBZid( joinPartData->playerID ); cout << " " << joinPartData->reason.c_str(); cout << endl; + listPlayers( part, joinPartData); break; case bz_ePlayerAuthEvent: cout << "PLAYER-AUTH "; displayCallsign( authData->playerID ); displayPlayerPrivs( authData->playerID ); cout << endl; + listPlayers( join, joinPartData); break; default : break; @@ -164,6 +186,13 @@ } } +void LogDetail::displayBZid( int playerID ) +{ + bz_PlayerRecord *player = bz_getPlayerByIndex( playerID ); + if (player && player->globalUser) + cout << " BZid:" << player->bzID.c_str(); +} + void LogDetail::displayPlayerPrivs( int playerID ) { bz_PlayerRecord *player = bz_getPlayerByIndex( playerID ); @@ -230,6 +259,72 @@ } } +void LogDetail::listPlayers( action act , bz_PlayerJoinPartEventData *data ) +{ + bzAPIIntList *playerList = bz_newIntList(); + bz_PlayerRecord *player; + ostringstream msg; + string str; + char playerStatus; + int numPlayers; + + bz_getPlayerIndexList( playerList ); + + bz_debugMessage( 4 , "Players:" ); + // + // Count number of players + // + numPlayers = 0; + for ( unsigned int i = 0; i < playerList->size(); i++ ) { + player = bz_getPlayerByIndex( playerList->get(i)); + if (player) { + if ((player->callsign != "") && (act == join || act == auth || (data && (player->playerID != data->playerID)))) + numPlayers++; + bz_freePlayerRecord( player ); + } + } + + // + // Display number of players, callsign, and email string in the following format: + // + // PLAYERS (nn) [G]cc:callsign(ee:emailstring) + // nn - number of players + // G - global auth identifier (+|-| |@) + // cc - count of characters in player callsign + // callsign - player callsign + // ee - count of characters in email string + // emailstring - player email string + // + // eg. + // PLAYERS (2) [@]7:Thumper(16:me...@so...) [ ]3:xxx() + // + msg.str(""); + msg << "PLAYERS (" << numPlayers << ") "; + for ( unsigned int i = 0; i < playerList->size(); i++ ) { + player = bz_getPlayerByIndex( playerList->get(i)); + if (player) { + if ((player->callsign != "") && (act == join || act == auth || (data && (player->playerID != data->playerID)))) { + playerStatus = ' '; + if (player->globalUser) playerStatus = '+'; + if (player->verified) playerStatus = '+'; + if (player->admin and !bz_hasPerm(player->playerID, bz_perm_hideAdmin)) playerStatus = '@'; + msg << "[" << playerStatus << "]"; + msg << player->callsign.size() << ':'; + msg << player->callsign.c_str(); + msg << "("; + if (player->email != "") + msg << player->email.size() << ":" << player->email.c_str(); + msg << ") "; + } + bz_freePlayerRecord( player ); + } + } + str = msg.str(); + cout << str << endl; + + bz_deleteIntList(playerList); +} + // Local Variables: *** // mode:C++ *** // tab-width: 8 *** |