eVoter Class Reference

#include <eVoter.h>

Inheritance diagram for eVoter:

Inheritance graph
[legend]
Collaboration diagram for eVoter:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 eVoter (nMachine &machine)
 ~eVoter ()
void PlayerChanged ()
 call when a player changed (logged in or changed name). He'll be blocked from issuing kick votes for a while.
void Spam (int user, REAL spamLevel, tOutput const &message)
bool IsSpamming (int user)
void RemoveFromGame ()
tString Name (int senderID=-1) const
REAL Age () const
 how long does this voter exist?
bool AllowNameChange () const
 determines whether the player belonging to this voter should be allowed to change names
int HarmCount () const
 returns the number of harmful votes against this player

Static Public Member Functions

static void KickMenu ()
static void VotingMenu ()
static eVoterGetVoter (int ID, bool complain=false)
static eVoterGetVoter (nMachine &machine)
static bool VotingPossible ()
static void HandleChat (ePlayerNetID *p, std::istream &message)
 handles player "/vote" command.

Protected Member Functions

virtual void OnDestroy ()
 called when machine gets destroyed

Private Attributes

nMachinemachine_
nSpamProtection votingSpam_
tJUST_CONTROLLED_PTR< eVoterselfReference_
 reference to self
int harmCount_
 counts the number of harmful votes issued against this player
double lastHarmVote_
 the last time a harmful vote was issued for this player
double lastKickVote_
 the last time a kick vote was issued for this player
double lastNameChangePreventor_
 the last time something happened that should prevent the voter from changing names
double lastChange_
 the last time a player assigned to this voter changed

Static Private Attributes

static tList< eVotervoters_

Friends

class eVoteItem
class eVoteItemHarm
class eVoteItemKick


Detailed Description

Definition at line 55 of file eVoter.h.


Constructor & Destructor Documentation

eVoter::eVoter ( nMachine machine  ) 

Definition at line 1653 of file eVoter.cpp.

References tSysTimeFloat(), and eVoteItem::voters_.

01654         : nMachineDecorator( machine ), machine_( machine ), votingSpam_( se_voteSpamProtection )
01655 {
01656     selfReference_ = this;
01657     voters_.Add( this );
01658     harmCount_ = 0;
01659     lastKickVote_ = -1E+40;
01660     lastHarmVote_ = -1E+40;
01661     lastNameChangePreventor_ = -1E+40;
01662     lastChange_ = tSysTimeFloat();
01663 }

Here is the call graph for this function:

eVoter::~eVoter (  ) 

Definition at line 1665 of file eVoter.cpp.

References tList< T, MALLOC, REFERENCE >::Remove(), and voters_.

01666 {
01667     voters_.Remove( this );
01668 }

Here is the call graph for this function:


Member Function Documentation

void eVoter::PlayerChanged ( void   ) 

call when a player changed (logged in or changed name). He'll be blocked from issuing kick votes for a while.

Definition at line 2019 of file eVoter.cpp.

References lastChange_, and tSysTimeFloat().

Referenced by ePlayerNetID::CreateVoter().

02020 {
02021     this->lastChange_ = tSysTimeFloat();
02022 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eVoter::Spam ( int  user,
REAL  spamLevel,
tOutput const &  message 
)

Definition at line 1670 of file eVoter.cpp.

References nSpamProtection::CheckSpam(), nSERVER, sn_GetNetState(), and votingSpam_.

Referenced by eVoteItem::AcceptNewVote().

01671 {
01672     if ( sn_GetNetState() == nSERVER )
01673         votingSpam_.CheckSpam( spamLevel, user, message );
01674 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool eVoter::IsSpamming ( int  user  ) 

Definition at line 1676 of file eVoter.cpp.

References nSpamProtection::CheckSpam(), nSpamProtection::Level_Ok, nSERVER, sn_GetNetState(), and votingSpam_.

Referenced by eVoteItem::AcceptNewVote().

01677 {
01678     if ( sn_GetNetState() == nSERVER )
01679     {
01680         return nSpamProtection::Level_Ok != votingSpam_.CheckSpam( 0.0f, user, tOutput("$spam_vote_kick_issue") );
01681     }
01682 
01683     return false;
01684 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eVoter::RemoveFromGame ( void   ) 

Definition at line 1733 of file eVoter.cpp.

References eVoteItem::GetItems(), tListItemBase::Len(), tList< T, MALLOC, REFERENCE >::Remove(), tCONTROLLED_PTR, and voters_.

01734 {
01735     tCONTROLLED_PTR( eVoter ) keeper( this );
01736 
01737     voters_.Remove( this );
01738 
01739     // remove from items
01740     for ( int i = eVoteItem::GetItems().Len()-1; i>=0; --i )
01741     {
01742         eVoteItem::GetItems()( i )->RemoveVoterCompletely( this );
01743     }
01744 }

Here is the call graph for this function:

void eVoter::KickMenu (  )  [static]

Definition at line 1746 of file eVoter.cpp.

References uMenu::Enter(), ePlayerNetID::IsHuman(), GrowingArrayBase::Len(), se_PlayerNetIDs, and tNEW.

Referenced by ePlayerNetID::PoliceMenu().

01747 {
01748     uMenu menu( "$player_police_kick_text" );
01749 
01750     int size = se_PlayerNetIDs.Len();
01751     eMenuItemKick** items = tNEW( eMenuItemKick* )[ size ];
01752 
01753     int i;
01754     for ( i = size-1; i>=0; --i )
01755     {
01756         ePlayerNetID* player = se_PlayerNetIDs[ i ];
01757         if ( player->IsHuman() )
01758         {
01759             items[i] = tNEW( eMenuItemKick )( &menu, player );
01760         }
01761         else
01762         {
01763             items[i] = 0;
01764         }
01765     }
01766 
01767     menu.Enter();
01768 
01769     for ( i = size - 1; i>=0; --i )
01770     {
01771         if( items[i] )
01772             delete items[i];
01773     }
01774     delete[] items;
01775 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eVoter::VotingMenu (  )  [static]

Definition at line 1786 of file eVoter.cpp.

References uMenu::Enter(), eVoteItem::GetItems(), GrowingArrayBase::Len(), se_KeepConsoleSmall(), tNEW, votingMenu, and VotingPossible().

Referenced by MainMenu(), and sg_VoteMenuIdle().

01787 {
01788     static bool recursion = false;
01789     if ( ! recursion )
01790     {
01791 
01792         // expire old items
01793         if ( !VotingPossible() )
01794             return;
01795 
01796 #ifndef DEDICATED
01797         rSmallConsoleCallback SmallConsole( se_KeepConsoleSmall );
01798 
01799         // count items
01800         int size = eVoteItem::GetItems().Len();
01801         if ( size == 0 )
01802             return;
01803 
01804         // fill menu
01805         uMenu menu( "$voting_menu_text" );
01806 
01807         eMenuItemVote** items = tNEW( eMenuItemVote* )[ size ];
01808 
01809         int i;
01810         for ( i = size-1; i>=0; --i )
01811         {
01812             items[i] = tNEW( eMenuItemVote )( &menu, eVoteItem::GetItems()( i ) );
01813         }
01814 
01815         // enter menu
01816         recursion = true;
01817         votingMenu = &menu;
01818         menu.Enter();
01819         votingMenu = 0;
01820         recursion = false;
01821 
01822         for ( i = size - 1; i>=0; --i )
01823         {
01824             delete items[i];
01825         }
01826         delete[] items;
01827 
01828         // expire old items
01829         VotingPossible();
01830 #endif
01831     }
01832 }

Here is the call graph for this function:

Here is the caller graph for this function:

eVoter * eVoter::GetVoter ( int  ID,
bool  complain = false 
) [static]

Definition at line 1850 of file eVoter.cpp.

References nMachine::GetMachine(), ePlayerNetID::IsSpectating(), GrowingArrayBase::Len(), NULL, nNetObject::Owner(), se_allowVotingSpectator, se_PlayerNetIDs, and sn_ConsoleOut().

Referenced by eVoteItem::AcceptNewVote(), eVoteItem::CheckValid(), ePlayerNetID::CreateVoter(), eVoteItemKick::DoCheckValid(), eVoteItemHarm::DoCheckValid(), Name(), eVoteItem::ReBroadcast(), and se_GetVoter().

01851 {
01852     // the server has no voter
01853 #ifdef DEDICATED
01854     if ( ID == 0 )
01855         return NULL;
01856 #endif
01857 
01858     // see if there is a real player on the specified ID
01859     if ( !se_allowVotingSpectator )
01860     {
01861         bool player = false;
01862         for ( int i = se_PlayerNetIDs.Len()-1; i>=0; --i )
01863         {
01864             ePlayerNetID* p = se_PlayerNetIDs(i);
01865             if ( p->Owner() == ID && !p->IsSpectating() )
01866                 player = true;
01867         }
01868         if (!player)
01869         {
01870             if ( complain )
01871             {
01872                 tOutput message("$vote_disabled_spectator");
01873                 sn_ConsoleOut( message, ID );
01874             }
01875             return NULL;
01876         }
01877     }
01878 
01879     // get machine from network subsystem
01880     nMachine & machine = nMachine::GetMachine( ID );
01881 
01882     return GetVoter( machine );
01883 }

Here is the call graph for this function:

Here is the caller graph for this function:

eVoter * eVoter::GetVoter ( nMachine machine  )  [static]

Definition at line 1885 of file eVoter.cpp.

References tList< T, MALLOC, REFERENCE >::Add(), nMachine::GetDecorators(), lastKickVote_, lastNameChangePreventor_, tListMember::ListID(), tListItem< T >::Next(), tNEW, and voters_.

01886 {
01887     // iterate through the machine's decorators, find a voter
01888     nMachineDecorator * run = machine.GetDecorators();
01889     while ( run )
01890     {
01891         eVoter * voter = dynamic_cast< eVoter * >( run );
01892         if ( voter )
01893         {
01894             // reinsert voter into lists
01895             if ( voter->ListID() < 0 )
01896             {
01897                 voters_.Add( voter );
01898                 voter->lastKickVote_ = -1E30;
01899                 voter->lastNameChangePreventor_ = -1E30;
01900             }
01901 
01902             // return result
01903             return voter;
01904         }
01905 
01906         run = run->Next();
01907     }
01908 
01909     // create new voter
01910     return tNEW(eVoter)( machine );
01911 }

Here is the call graph for this function:

bool eVoter::VotingPossible (  )  [static]

Definition at line 1834 of file eVoter.cpp.

References eVoteItem::GetItems(), GrowingArrayBase::Len(), tListItemBase::Len(), nCLIENT, and sn_GetNetState().

Referenced by MainMenu(), and VotingMenu().

01835 {
01836     // expire old items
01837     for ( int i = eVoteItem::GetItems().Len()-1; i>=0; --i )
01838     {
01839         eVoteItem::GetItems()( i )->Evaluate();
01840     }
01841 
01842     if ( sn_GetNetState() != nCLIENT )
01843     {
01844         return false;
01845     }
01846 
01847     return eVoteItem::GetItems().Len() > 0;
01848 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eVoter::HandleChat ( ePlayerNetID p,
std::istream &  message 
) [static]

handles player "/vote" command.

Parameters:
p the player chatting
message the rest of the message after "/vote"
Parameters:
message  handles player "/vote" command.

Definition at line 2033 of file eVoter.cpp.

References eVoteItem::AcceptNewVote(), eVoteItem::CheckValid(), ePlayerNetID::FindPlayerByName(), eAccessLevelHolder::GetAccessLevel(), ePlayerNetID::GetVoter(), nNetObject::Owner(), tString::ReadLine(), eVoteItem::ReBroadcast(), se_votingPrivacy, nCurrentSenderID::SetID(), sn_ConsoleOut(), tNEW, tToLower(), and eVoteItem::Update().

02034 {
02035     // cloak the ID of the sener for privacy
02036     nCurrentSenderID cloak;
02037     if ( se_votingPrivacy > 1 )
02038         cloak.SetID(0);
02039 
02040     if ( !p )
02041     {
02042         return;
02043     }
02044 
02045     // read command part (kick, remove, include)
02046     tString command;
02047     message >> command;
02048     tToLower( command );
02049 
02050     eVoter * voter = p->GetVoter();
02051     if ( !eVoteItem::AcceptNewVote( voter, p->Owner() ) )
02052     {
02053         return;
02054     }
02055 
02056     eVoteItem * item = 0;
02057 
02058     if ( command == "kick" )
02059     {
02060         tString name;
02061         name.ReadLine( message );
02062         ePlayerNetID * toKick = ePlayerNetID::FindPlayerByName( name, p );
02063         if ( toKick )
02064         {
02065             // accept message
02066             item = tNEW( eVoteItemKickServerControlled )( false, toKick );
02067         }
02068     }
02069     else if ( command == "suspend" )
02070     {
02071         tString name;
02072         name.ReadLine( message );
02073         ePlayerNetID * toSuspend = ePlayerNetID::FindPlayerByName( name, p );
02074         if ( toSuspend )
02075         {
02076             // accept message
02077             item = tNEW( eVoteItemSuspend )( toSuspend );
02078         }
02079     }
02080 #ifdef KRAWALL_SERVER
02081     else if ( command == "include" )
02082     {
02083         tString file;
02084         file.ReadLine( message );
02085         {
02086             // accept message
02087             item = tNEW( eVoteItemInclude )( file, p->GetAccessLevel() );
02088         }
02089     }
02090     else if ( command == "command" )
02091     {
02092         tString console;
02093         console.ReadLine( message );
02094         {
02095             // accept message
02096             item = tNEW( eVoteItemCommand )( console, p->GetAccessLevel() );
02097         }
02098     }
02099 #endif
02100     else
02101     {
02102 #ifdef KRAWALL_SERVER
02103         sn_ConsoleOut( tOutput("$vote_unknown_command", command, "suspend, kick, include, command" ), p->Owner() );
02104 #else
02105         sn_ConsoleOut( tOutput("$vote_unknown_command", command, "suspend, kick" ), p->Owner() );
02106 #endif
02107     }
02108 
02109     // nothing created
02110     if ( !item )
02111     {
02112         return;
02113     }
02114 
02115     // let item check its validity
02116     if ( !item->CheckValid( p->Owner() ) )
02117     {
02118         delete item;
02119         return;
02120     }
02121 
02122     // no objection? Broadcast it to everyone.
02123     item->Update();
02124     item->ReBroadcast( p->Owner() );
02125 }

Here is the call graph for this function:

tString eVoter::Name ( int  senderID = -1  )  const

Parameters:
senderID the ID of the network user ( default: take any )
Returns:
the name of the voter ( all players of that IP )

Definition at line 1988 of file eVoter.cpp.

References nMachine::GetIP(), ePlayerNetID::GetName(), GetVoter(), tString::Len(), GrowingArrayBase::Len(), machine_, nNetObject::Owner(), and se_PlayerNetIDs.

01989 {
01990     tString name;
01991 
01992     // collect the names of all players associated with this voter
01993     for ( int i = se_PlayerNetIDs.Len()-1; i>=0; --i )
01994     {
01995         ePlayerNetID* p = se_PlayerNetIDs(i);
01996         if ( eVoter::GetVoter( p->Owner() ) == this && ( senderID < 0 || p->Owner() == senderID ) )
01997         {
01998             if ( name.Len() > 1 )
01999                 name << ", ";
02000             name << p->GetName();
02001         }
02002     }
02003 
02004     if ( name.Len() < 2 )
02005         name = machine_.GetIP();
02006 
02007     return name;
02008 }

Here is the call graph for this function:

REAL eVoter::Age (  )  const

how long does this voter exist?

Returns:
the last change to players on this voter in seconds

Definition at line 1712 of file eVoter.cpp.

References lastChange_, and tSysTimeFloat().

01713 {
01714     return tSysTimeFloat() - lastChange_;
01715 }

Here is the call graph for this function:

bool eVoter::AllowNameChange ( void   )  const

determines whether the player belonging to this voter should be allowed to change names

Returns:
true if the players belonging to this voter should be allowed to rename

Definition at line 1728 of file eVoter.cpp.

References lastNameChangePreventor_, se_minTimeBetweenKicks, and tSysTimeFloat().

01729 {
01730     return tSysTimeFloat() > this->lastNameChangePreventor_ + se_minTimeBetweenKicks;
01731 }

Here is the call graph for this function:

int eVoter::HarmCount (  )  const [inline]

returns the number of harmful votes against this player

Definition at line 85 of file eVoter.h.

References harmCount_.

Referenced by eVoteItemKickServerControlled::DoCheckValid().

00086     {
00087         return harmCount_;
00088     }

Here is the caller graph for this function:

void eVoter::OnDestroy ( void   )  [protected, virtual]

called when machine gets destroyed

Reimplemented from nMachineDecorator.

Definition at line 1695 of file eVoter.cpp.

References selfReference_.

01696 {
01697     tJUST_CONTROLLED_PTR< eVoter > keepAlive( this );
01698     selfReference_ = 0;
01699 }


Friends And Related Function Documentation

friend class eVoteItem [friend]

Definition at line 57 of file eVoter.h.

friend class eVoteItemHarm [friend]

Definition at line 58 of file eVoter.h.

friend class eVoteItemKick [friend]

Definition at line 59 of file eVoter.h.


Member Data Documentation

nMachine& eVoter::machine_ [private]

Definition at line 95 of file eVoter.h.

Referenced by eVoteItemHarm::DoCheckValid(), and Name().

tList< eVoter > eVoter::voters_ [static, private]

Definition at line 96 of file eVoter.h.

Referenced by eVoteItem::AcceptNewVote(), eVoteItem::Evaluate(), eVoteItem::GetStats(), GetVoter(), RemoveFromGame(), and ~eVoter().

nSpamProtection eVoter::votingSpam_ [private]

Definition at line 97 of file eVoter.h.

Referenced by IsSpamming(), and Spam().

tJUST_CONTROLLED_PTR< eVoter > eVoter::selfReference_ [private]

reference to self

Definition at line 98 of file eVoter.h.

Referenced by OnDestroy().

int eVoter::harmCount_ [private]

counts the number of harmful votes issued against this player

Definition at line 99 of file eVoter.h.

Referenced by eVoteItemHarm::DoCheckValid(), and HarmCount().

double eVoter::lastHarmVote_ [private]

the last time a harmful vote was issued for this player

Definition at line 100 of file eVoter.h.

Referenced by eVoteItemHarm::DoCheckValid().

double eVoter::lastKickVote_ [private]

the last time a kick vote was issued for this player

Definition at line 101 of file eVoter.h.

Referenced by eVoteItemKick::DoCheckValid(), and GetVoter().

double eVoter::lastNameChangePreventor_ [private]

the last time something happened that should prevent the voter from changing names

Definition at line 102 of file eVoter.h.

Referenced by AllowNameChange(), eVoteItemKick::DoCheckValid(), eVoteItemHarm::DoCheckValid(), and GetVoter().

double eVoter::lastChange_ [private]

the last time a player assigned to this voter changed

Definition at line 103 of file eVoter.h.

Referenced by Age(), eVoteItemHarm::DoCheckValid(), and PlayerChanged().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:31:39 2008 for Armagetron Advanced by  doxygen 1.5.4