src/engine/ePlayer.h

Go to the documentation of this file.
00001 /*
00002  
00003 *************************************************************************
00004  
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007  
00008 **************************************************************************
00009  
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014  
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019  
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025  
00026 */
00027 
00028 #ifndef ArmageTron_PLAYER_H
00029 #define ArmageTron_PLAYER_H
00030 
00031 #ifndef MAX_INSTANT_CHAT
00032 #define MAX_INSTANT_CHAT 26
00033 #endif
00034 
00035 #define MAX_PLAYERS 4
00036 
00037 #include "rSDL.h"
00038 
00039 #include "uInput.h"
00040 #include "tList.h"
00041 #include "tString.h"
00042 #include "eCamera.h"
00043 #include "eNetGameObject.h"
00044 #include "tCallbackString.h"
00045 #include "nSpamProtection.h"
00046 
00047 #include <set>
00048 
00049 #define PLAYER_CONFITEMS (30+MAX_INSTANT_CHAT)
00050 
00051 class tConfItemBase;
00052 class uAction;
00053 class tOutput;
00054 class eTeam;
00055 class eVoter;
00056 
00057 class eCockpitPrototype : public tReferencable<eCockpitPrototype> {
00058 public:
00059     virtual ~eCockpitPrototype(){};
00060 };
00061 
00062 class ePlayer: public uPlayerPrototype{
00063     friend class eMenuItemChat;
00064     static uActionPlayer s_chat;
00065 
00066     tConfItemBase *configuration[PLAYER_CONFITEMS];
00067     int            CurrentConfitem;
00068     void   StoreConfitem(tConfItemBase *c);
00069     void   DeleteConfitems();
00070 public:
00071     tString    name;                 // the player's screen name
00072     tString    globalID;             // the global ID of the player in user@authority form
00073     // REAL        rubberstatus;
00074     tString     teamname;
00075     bool       centerIncamOnTurn;
00076     bool       wobbleIncam;
00077     bool       autoSwitchIncam;
00078 
00079     bool       spectate;              // shall this player always spectate?
00080     bool       stealth;               // does this player wish to hide his/her identity?
00081     bool       autoLogin;             // should the player always request authentication on servers?
00082 
00083     bool                nameTeamAfterMe; // player prefers to call his team after his name
00084     int                 favoriteNumberOfPlayersPerTeam;
00085 
00086     eCamMode startCamera;
00087     bool     allowCam[CAMERA_COUNT];
00088     int      startFOV;
00089     bool     smartCustomGlance; 
00090 
00091     tCHECKED_PTR(eCamera)           cam;
00092     tCONTROLLED_PTR(ePlayerNetID) netPlayer;
00093     tJUST_CONTROLLED_PTR<eCockpitPrototype>     cockpit;
00094 
00095     int rgb[3]; // our color
00096 
00097     tString instantChatString[MAX_INSTANT_CHAT];
00098     // instant chat macros
00099 
00100     static uActionPlayer *se_instantChatAction[MAX_INSTANT_CHAT];
00101 
00102     ePlayer();
00103     virtual ~ePlayer();
00104 
00105     virtual const char *Name() const{return name;}
00106     virtual const char *Teamname() const{return teamname;}
00107 
00108     virtual bool Act(uAction *act,REAL x);
00109 
00110     int ID() const {return id;};
00111 #ifndef DEDICATED
00112     void Render();
00113 #endif
00114 
00115     static ePlayer * PlayerConfig(int p);
00116 
00117     static bool PlayerIsInGame(int p);
00118 
00119     static rViewport * PlayerViewport(int p);
00120 
00121     static void LogIn();          
00122     static void SendAuthNames();  
00123 
00124     static void Init();
00125     static void Exit();
00126 };
00127 
00129 class eAccessLevelHolder
00130 {
00131 public:
00132     eAccessLevelHolder();
00133 
00134     tAccessLevel GetAccessLevel() const { return accessLevel; }
00135     void SetAccessLevel( tAccessLevel level );
00136 
00137 private:
00138     tAccessLevel     accessLevel;    
00139 };
00140 
00141 // the class that identifies players across the network
00142 class ePlayerNetID: public nNetObject, public eAccessLevelHolder{
00143     friend class ePlayer;
00144     friend class eTeam;
00145     friend class eNetGameObject;
00146     friend class tControlledPTR< ePlayerNetID >;
00147     // access level. lower numeric values are better.
00148 public:
00149     typedef std::set< eTeam * > eTeamSet;
00150 private:
00151 
00152     int listID;                          // ID in the list of all players
00153     int teamListID;                      // ID in the list of the team
00154 
00155     bool                                                        silenced_;              // flag indicating whether the player has been silenced
00156     int                             suspended_;     
00157 
00158     nTimeAbsolute                                       timeJoinedTeam; // the time the player joined the team he is in now
00159     tCONTROLLED_PTR(eTeam)                      nextTeam;               // the team we're in ( logically )
00160     tCONTROLLED_PTR(eTeam)                      currentTeam;    // the team we currently are spawned for
00161     eTeamSet                        invitations_;   // teams this player is invited to
00162     tCONTROLLED_PTR(eVoter)                     voter_;                 // voter assigned to this player
00163 
00164     tCHECKED_PTR(eNetGameObject) object; // the object this player is
00165     // controlling
00166 
00167     int score; // points made so far
00168     int lastScore_; // last saved score
00169 
00170     int favoriteNumberOfPlayersPerTeam;         // join team if number of players on it is less than this; create new team otherwise
00171     bool nameTeamAfterMe;                                       // player prefers to call his team after his name
00172     bool greeted;                                               // did the server already greet him?
00173     bool disconnected;                                          // did he disconnect from the game?
00174 
00175     static void SwapPlayersNo(int a,int b); // swaps the players a and b
00176 
00177     ePlayerNetID& operator= (const ePlayerNetID&); // forbid copy constructor
00178 
00179     bool                        spectating_; 
00180     bool                        stealth_; 
00181     bool                        chatting_;   
00182     int                         chatFlags_;  
00183     bool                        allowTeamChange_; 
00184 
00185     //For improved remoteadmin
00186     tAccessLevel     lastAccessLevel;
00187 
00188     nMachine *      registeredMachine_; 
00189     void RegisterWithMachine();         
00190     void UnregisterWithMachine();       
00191 public:
00192     enum                        ChatFlags
00193     {
00194         ChatFlags_Chat = 1,
00195         ChatFlags_Away = 2,
00196         ChatFlags_Menu = 4,
00197         ChatFlags_Console = 4
00198     };
00199 
00200     int    pID;
00201     tString teamname;
00202     // REAL     rubberstatus;
00203     tArray<tString> lastSaid;
00204     tArray<nTimeRolling> lastSaidTimes;
00205     //  void SetLastSaid(tString ls);
00206     unsigned short r,g,b; // our color
00207 
00208     unsigned short pingCharity; // max ping you are willing to take over
00209 
00210     REAL ping;
00211 
00212     double lastSync;         
00213     double lastActivity_;    
00214 
00215     bool loginWanted;        
00216 
00217     nSpamProtection chatSpam_;
00218 
00219     ePlayerNetID(int p=-1);
00220     ePlayerNetID(nMessage &m);
00221     virtual ~ePlayerNetID();
00222 
00223     virtual bool ActionOnQuit();
00224     virtual void ActionOnDelete();
00225 
00226     // chatting
00227     bool IsChatting() const { return chatting_; }
00228     void SetChatting ( ChatFlags flag, bool chatting );
00229 
00230     // spectating
00231     bool IsSpectating() const { return spectating_; }
00232 
00233     bool StealthMode() const { return stealth_; }
00234 
00235     // team management
00236     bool TeamChangeAllowed( bool informPlayer = false ) const; 
00237     void SetTeamChangeAllowed(bool allowed) {allowTeamChange_ = allowed;} 
00238 
00239     eTeam* NextTeam()    const { return nextTeam; }             // return the team I will be next round
00240     eTeam* CurrentTeam() const { return currentTeam; }  // return the team I am in
00241     int  TeamListID() const { return teamListID; }              // return my position in the team
00242     eTeam* FindDefaultTeam();                                   // find a good default team for us
00243     void SetDefaultTeam();                                              // register me in a good default team
00244     void SetTeamForce(eTeam* team );            // register me in the given team without checks
00245     void SetTeam(eTeam* team);                          // register me in the given team (callable on the server)
00246     void SetTeamWish(eTeam* team);                              // express the wish to be part of the given team (always callable)
00247     void SetTeamname(const char *);                             // set teamname to be used for my own team
00248     void UpdateTeamForce();                                             // update team membership without checks
00249     void UpdateTeam();                                                  // update team membership
00250 
00251     eTeamSet const & GetInvitations() const ;   
00252 
00253     void CreateNewTeam();                                       // create a new team and join it (on the server)
00254     void CreateNewTeamWish();                                   // express the wish to create a new team and join it
00255     virtual void ReceiveControlNet(nMessage &m);// receive the team control wish
00256 
00257     static bool Enemies( ePlayerNetID const * a, ePlayerNetID const * b ); 
00258 
00259     // print out an understandable name in to s
00260     virtual void                        PrintName(tString &s) const;
00261 
00262     virtual bool                        AcceptClientSync() const;
00263     virtual void                        WriteSync(nMessage &m);
00264     virtual void                        ReadSync(nMessage &m);
00265     virtual nDescriptor&        CreatorDescriptor() const;
00266     virtual void                        InitAfterCreation();
00267     virtual bool                        ClearToTransmit(int user) const;
00268 
00269     virtual void                        NewObject(){}                                   // called when we control a new object
00270     virtual void                        RightBeforeDeath(int triesLeft){}       // is called right before the vehicle gets destroyed.
00271 
00272 
00273     void RemoveFromGame();
00274     virtual void ControlObject(eNetGameObject *c);
00275     virtual void ClearObject();
00276 
00277     void Greet();
00278 
00279     // suspend the player from playing, forcing him to spectate
00280     void Suspend( int rounds = 5 );
00281 #ifdef KRAWALL_SERVER
00282     void Authenticate( tString const & authName, 
00283                        tAccessLevel accessLevel = tAccessLevel_Authenticated,
00284                        ePlayerNetID const * admin = 0 );    
00285     void DeAuthenticate( ePlayerNetID const * admin = 0 );  
00286     bool IsAuthenticated() const;                     
00287 #endif
00288 
00289     static void RequestScheduledLogins();  
00290 
00291     bool IsActive() const { return !disconnected; }
00292 
00293     bool IsSilenced( void ) const { return silenced_; }
00294     void SetSilenced( bool silenced ) { silenced_ = silenced; }
00295     bool& AccessSilenced( void ) { return silenced_; }
00296 
00297     eVoter * GetVoter() const {return voter_;}     // returns our voter
00298     void CreateVoter();                                         // create our voter or find it
00299     static void SilenceMenu();                          // menu where you can silence players
00300     static void PoliceMenu();                           // menu where you can silence and kick players
00301 
00302     virtual bool IsHuman() const { return true; }
00303 
00304     void Activity(); // call it if this player just showed some activity.
00305     REAL LastActivity() const; 
00306 
00307     eNetGameObject *Object() const;
00308 
00309     // void SetRubber(REAL rubber2);
00310     void AddScore(int points, const tOutput& reasonwin, const tOutput& reasonlose);
00311     int Score()const {return score;}
00312     int TotalScore() const;
00313     static void ResetScoreDifferences(); //<! Resets the last stored score so ScoreDifferences takes this as a reference time
00314     static void LogScoreDifferences();   //<! Logs accumulated scores of all players since the last call to ResetScoreDifferences() to ladderlog.txt
00315     void LogScoreDifference();           //<! Logs accumulated scores since the last call to ResetScoreDifferences() to ladderlog.txt
00316 
00317     static void SortByScore(); // brings the players into the right order
00318     static tString Ranking( int MAX=12, bool cut = true );     // returns a ranking list
00319 
00320     static float RankingGraph( float y, int MAX );     // prints a ranking list
00321 
00322     static void RankingLadderLog();     // writes a small ranking list to ladderlog
00323 
00324     static void  ResetScore();  // resets the ranking list
00325 
00326     static void DisplayScores(); // display scores on the screen
00327 
00328     void GreetHighscores(tString &s); // tell him his positions in the
00329     // highscore lists (defined in game.cpp)
00330 
00331     static void Update();           // creates ePlayerNetIDs for new players
00332     // and destroys those of players that have left
00333 
00334 #ifdef KRAWALL_SERVER
00335     static tAccessLevel AccessLevelRequiredToPlay(); // is authentication required to play on this server?
00336 #endif
00337 
00338     static bool WaitToLeaveChat(); 
00339 
00340     static void RemoveChatbots(); 
00341 
00342     static void CompleteRebuild(); // same as above, but rebuilds every ePlayerNetID.
00343     static void ClearAll(); // deletes all ePlayerNetIDs.
00344     static void SpectateAll( bool spectate=true ); // puts all players into spectator mode.
00345 
00346     static void ThrowOutDisconnected(); // get rid of everyone that disconnected from the game
00347 
00348     void GetScoreFromDisconnectedCopy(); // get the player's data from the previous login
00349 
00350     void Chat(const tString &s);
00351 
00352     virtual void Color( REAL&r, REAL&g, REAL&b ) const;
00353     virtual void TrailColor( REAL&r, REAL&g, REAL&b ) const;
00354 
00355     //Remote Admin add-ins...
00356     bool IsLoggedIn() const { return GetAccessLevel() < tAccessLevel_Moderator; }
00357     void BeLoggedIn() { SetAccessLevel( tAccessLevel_Admin ); }
00358     void BeNotLoggedIn() { SetAccessLevel( tAccessLevel_Program ); }
00359     tAccessLevel GetLastAccessLevel() const { return lastAccessLevel; }
00360 
00361     static ePlayerNetID * FindPlayerByName( tString const & name, ePlayerNetID * requester = 0 ); 
00362 
00363     void UpdateName();                                           
00364     static void FilterName( tString const & in, tString & out ); 
00365     static tString FilterName( tString const & in );             
00366 private:
00367     tColoredString  nameFromClient_;        
00368     tColoredString  nameFromServer_;        
00369     tColoredString  coloredName_;           
00370     tString         name_;                  
00371     tString         userName_;              
00372 
00373 #ifdef KRAWALL_SERVER
00374     tString         rawAuthenticatedName_;  
00375 #endif
00376 
00377     REAL            wait_;                  
00378 
00379     void                        MyInitAfterCreation();
00380 
00381 protected:
00382     virtual nMachine & DoGetMachine() const;  
00383 
00384     // private:
00385     //  virtual void AddRef();
00386     //  virtual void Release();
00387 
00388     // accessors
00389 public:
00390     inline tColoredString const & GetNameFromClient( void ) const;      
00391     inline ePlayerNetID const & GetNameFromClient( tColoredString & nameFromClient ) const;     
00392     inline tColoredString const & GetColoredName( void ) const; 
00393     inline ePlayerNetID const & GetColoredName( tColoredString & coloredName ) const;   
00394     inline tString const & GetName( void ) const;       
00395     inline ePlayerNetID const & GetName( tString & name ) const;        
00396 
00397     inline tString const & GetUserName( void ) const;   
00398     inline ePlayerNetID const & GetUserName( tString & userName ) const;        
00399 
00400     tString const & GetLogName( void ) const{ return GetUserName(); }   
00401     tString GetFilteredAuthenticatedName( void ) const; 
00402 #ifdef KRAWALL_SERVER
00403     tString const & GetRawAuthenticatedName( void ) const{ return rawAuthenticatedName_; }      
00404     void SetRawAuthenticatedName( tString const & name ){ if ( !IsAuthenticated()) rawAuthenticatedName_ = name; }      
00405 #endif
00406 
00407     ePlayerNetID & SetName( tString const & name ); 
00408     ePlayerNetID & SetName( char    const * name ); 
00409     inline ePlayerNetID & SetUserName( tString const & userName );  
00410 private:
00411     inline ePlayerNetID & SetNameFromClient( tColoredString const & nameFromClient );   
00412     inline ePlayerNetID & SetColoredName( tColoredString const & coloredName ); 
00413 
00415     int & AccessSuspended();
00416 
00418     int GetSuspended() const;
00419 };
00420 
00421 extern tList<ePlayerNetID> se_PlayerNetIDs;
00422 extern int    sr_viewportBelongsToPlayer[MAX_VIEWPORTS];
00423 extern bool se_assignTeamAutomatically;
00424 
00425 void se_ChatState( ePlayerNetID::ChatFlags flag, bool cs);
00426 
00427 void se_SaveToScoreFile( tOutput const & out );  
00428 void se_SaveToLadderLog( tOutput const & out );  
00429 
00430 tColoredString & operator << (tColoredString &s,const ePlayer &p);
00431 tColoredString & operator << (tColoredString &s,const ePlayerNetID &p);
00432 
00433 extern int pingCharity;
00434 
00435 void se_AutoShowScores(); // show scores based on automated decision
00436 void se_UserShowScores(bool show); // show scores based on user input
00437 void se_SetShowScoresAuto(bool a); // disable/enable auto show scores
00438 
00439 //Password stuff
00440 void se_DeletePasswords();
00441 extern int se_PasswordStorageMode; // 0: store in memory, -1: don't store, 1: store on file
00442 
00443 tOutput& operator << (tOutput& o, const ePlayerNetID& p);
00444 
00445 // greeting callback
00446 class eCallbackGreeting: public tCallbackString
00447 {
00448     static tCallbackString *anchor;
00449     static ePlayerNetID* greeted;
00450 
00451 public:
00452     static tString Greet(ePlayerNetID* player);
00453     static ePlayerNetID* Greeted(){return greeted;}
00454 
00455     eCallbackGreeting(STRINGRETFUNC* f);
00456 };
00457 
00458 extern int se_SpamMaxLen;       // maximal length of chat message
00459 
00460 
00461 // ******************************************************************************************
00462 // *
00463 // *    GetNameFromClient
00464 // *
00465 // ******************************************************************************************
00469 // ******************************************************************************************
00470 
00471 tColoredString const & ePlayerNetID::GetNameFromClient( void ) const
00472 {
00473     return this->nameFromClient_;
00474 }
00475 
00476 // ******************************************************************************************
00477 // *
00478 // *    GetNameFromClient
00479 // *
00480 // ******************************************************************************************
00485 // ******************************************************************************************
00486 
00487 ePlayerNetID const & ePlayerNetID::GetNameFromClient( tColoredString & nameFromClient ) const
00488 {
00489     nameFromClient = this->nameFromClient_;
00490     return *this;
00491 }
00492 
00493 // ******************************************************************************************
00494 // *
00495 // *    SetNameFromClient
00496 // *
00497 // ******************************************************************************************
00502 // ******************************************************************************************
00503 
00504 ePlayerNetID & ePlayerNetID::SetNameFromClient( tColoredString const & nameFromClient )
00505 {
00506     this->nameFromClient_ = nameFromClient;
00507     return *this;
00508 }
00509 
00510 // ******************************************************************************************
00511 // *
00512 // *    GetColoredName
00513 // *
00514 // ******************************************************************************************
00518 // ******************************************************************************************
00519 
00520 tColoredString const & ePlayerNetID::GetColoredName( void ) const
00521 {
00522     return this->coloredName_;
00523 }
00524 
00525 // ******************************************************************************************
00526 // *
00527 // *    GetColoredName
00528 // *
00529 // ******************************************************************************************
00534 // ******************************************************************************************
00535 
00536 ePlayerNetID const & ePlayerNetID::GetColoredName( tColoredString & coloredName ) const
00537 {
00538     coloredName = this->coloredName_;
00539     return *this;
00540 }
00541 
00542 // ******************************************************************************************
00543 // *
00544 // *    SetColoredName
00545 // *
00546 // ******************************************************************************************
00551 // ******************************************************************************************
00552 
00553 ePlayerNetID & ePlayerNetID::SetColoredName( tColoredString const & coloredName )
00554 {
00555     this->coloredName_ = coloredName;
00556     return *this;
00557 }
00558 
00559 // ******************************************************************************************
00560 // *
00561 // *    GetName
00562 // *
00563 // ******************************************************************************************
00567 // ******************************************************************************************
00568 
00569 tString const & ePlayerNetID::GetName( void ) const
00570 {
00571     return this->name_;
00572 }
00573 
00574 // ******************************************************************************************
00575 // *
00576 // *    GetName
00577 // *
00578 // ******************************************************************************************
00583 // ******************************************************************************************
00584 
00585 ePlayerNetID const & ePlayerNetID::GetName( tString & name ) const
00586 {
00587     name = this->name_;
00588     return *this;
00589 }
00590 
00591 // ******************************************************************************************
00592 // *
00593 // *    GetUserName
00594 // *
00595 // ******************************************************************************************
00599 // ******************************************************************************************
00600 
00601 tString const & ePlayerNetID::GetUserName( void ) const
00602 {
00603     return this->userName_;
00604 }
00605 
00606 // ******************************************************************************************
00607 // *
00608 // *    GetUserName
00609 // *
00610 // ******************************************************************************************
00615 // ******************************************************************************************
00616 
00617 ePlayerNetID const & ePlayerNetID::GetUserName( tString & userName ) const
00618 {
00619     userName = this->userName_;
00620     return *this;
00621 }
00622 
00623 // ******************************************************************************************
00624 // *
00625 // *    SetUserName
00626 // *
00627 // ******************************************************************************************
00632 // ******************************************************************************************
00633 
00634 ePlayerNetID & ePlayerNetID::SetUserName( tString const & userName )
00635 {
00636     this->userName_ = userName;
00637     return *this;
00638 }
00639 
00640 #endif
00641 

Generated on Sat Mar 15 22:55:46 2008 for Armagetron Advanced by  doxygen 1.5.4