1 /*
2 
3 *************************************************************************
4 
5 ArmageTron -- Just another Tron Lightcycle Game in 3D.
6 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7 
8 **************************************************************************
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 
24 ***************************************************************************
25 
26 */
27 
28 #ifndef ArmageTron_VOTER_H
29 #define ArmageTron_VOTER_H
30 
31 class ePlayerNetID;
32 class eMenuItemVote;
33 //class eVoteItem;
34 
35 #include "tSafePTR.h"
36 #include "tList.h"
37 #include "tString.h"
38 
39 #include "nNetObject.h"
40 
41 #include "nSpamProtection.h"
42 
43 // information in eVoter accessible for ePlayer only
44 class eVoterPlayerInfo
45 {
46 public:
47     friend class ePlayerNetID;
48 
49     eVoterPlayerInfo();
50 private:
51     int             suspended_;  //! number of rounds the player is currently suspended from playing
52     bool	    silenced_; //! is he silenced?
53 };
54 
55 // class identifying a voter; all players coming from the same IP share the same voter.
56 class eVoter: public tReferencable< eVoter >, public tListMember, public nMachineDecorator, public eVoterPlayerInfo
57 {
58     friend class eVoteItem;
59     friend class eVoteItemHarm;
60     friend class eVoteItemKick;
61 public:
62     eVoter( nMachine & machine );
63     ~eVoter();
64 
65     void PlayerChanged();                                       //!< call when a player changed (logged in or changed name). He'll be blocked from issuing kick votes for a while.
66 
67     void Spam( int user, REAL spamLevel, tOutput const & message );	// trigger spam guard
68     bool IsSpamming( int user );								// check if user has been found spamming
69     void RemoveFromGame();										// remove from game
70 
71     static void KickMenu();										// activate player kick menu
72     static void VotingMenu();									// activate voting menu ( you can vote about suggestions there )
73     static eVoter* GetVoter ( int ID, bool complain = false );	// find or create the voter for the specified user ID
74     static eVoter* GetVoter ( nMachine & machine );	            // find or create the voter for the specified machine
75     static bool VotingPossible();								// returns whether voting is currently possible
76 
77     static void HandleChat( ePlayerNetID * p, std::istream & message ); //!< handles player "/vote" command.
78 
79     tString Name(int senderID = -1) const;						// returns the name of the voter
80 
81     REAL Age() const;                                           //!< how long does this voter exist?
82 
83     bool AllowNameChange() const;  //!< determines whether the player belonging to this voter should be allowed to change names
84 
85     //! returns the number of harmful votes against this player
HarmCount()86     int HarmCount() const
87     {
88         return harmCount_;
89     }
90 protected:
91     virtual void OnDestroy();      //!< called when machine gets destroyed
92 
93 private:
94     //    static eVoter* GetVoterFromIP( tString IP );	// find or create the voter for the specified IP
95     //    const tString IP_;								// IP address of voter
96     nMachine & machine_;                            // the machine this voter comes from
97     static tList< eVoter > voters_;					// list of all voters
98     nSpamProtection votingSpam_;					// spam control
99     tJUST_CONTROLLED_PTR< eVoter > selfReference_;  //!< reference to self
100     int harmCount_;                                 //!< counts the number of harmful votes issued against this player
101     double lastHarmVote_;                           //!< the last time a harmful vote was issued for this player
102     double lastKickVote_;                           //!< the last time a kick vote was issued for this player
103     double lastNameChangePreventor_;                //!< the last time something happened that should prevent the voter from changing names
104     double lastChange_;                             //!< the last time a player assigned to this voter changed
105 };
106 
107 
108 #endif	// ArmageTron_VOTER_H
109 
110