00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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;
00072 tString globalID;
00073
00074 tString teamname;
00075 bool centerIncamOnTurn;
00076 bool wobbleIncam;
00077 bool autoSwitchIncam;
00078
00079 bool spectate;
00080 bool stealth;
00081 bool autoLogin;
00082
00083 bool nameTeamAfterMe;
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];
00096
00097 tString instantChatString[MAX_INSTANT_CHAT];
00098
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
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
00148 public:
00149 typedef std::set< eTeam * > eTeamSet;
00150 private:
00151
00152 int listID;
00153 int teamListID;
00154
00155 bool silenced_;
00156 int suspended_;
00157
00158 nTimeAbsolute timeJoinedTeam;
00159 tCONTROLLED_PTR(eTeam) nextTeam;
00160 tCONTROLLED_PTR(eTeam) currentTeam;
00161 eTeamSet invitations_;
00162 tCONTROLLED_PTR(eVoter) voter_;
00163
00164 tCHECKED_PTR(eNetGameObject) object;
00165
00166
00167 int score;
00168 int lastScore_;
00169
00170 int favoriteNumberOfPlayersPerTeam;
00171 bool nameTeamAfterMe;
00172 bool greeted;
00173 bool disconnected;
00174
00175 static void SwapPlayersNo(int a,int b);
00176
00177 ePlayerNetID& operator= (const ePlayerNetID&);
00178
00179 bool spectating_;
00180 bool stealth_;
00181 bool chatting_;
00182 int chatFlags_;
00183 bool allowTeamChange_;
00184
00185
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
00203 tArray<tString> lastSaid;
00204 tArray<nTimeRolling> lastSaidTimes;
00205
00206 unsigned short r,g,b;
00207
00208 unsigned short pingCharity;
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
00227 bool IsChatting() const { return chatting_; }
00228 void SetChatting ( ChatFlags flag, bool chatting );
00229
00230
00231 bool IsSpectating() const { return spectating_; }
00232
00233 bool StealthMode() const { return stealth_; }
00234
00235
00236 bool TeamChangeAllowed( bool informPlayer = false ) const;
00237 void SetTeamChangeAllowed(bool allowed) {allowTeamChange_ = allowed;}
00238
00239 eTeam* NextTeam() const { return nextTeam; }
00240 eTeam* CurrentTeam() const { return currentTeam; }
00241 int TeamListID() const { return teamListID; }
00242 eTeam* FindDefaultTeam();
00243 void SetDefaultTeam();
00244 void SetTeamForce(eTeam* team );
00245 void SetTeam(eTeam* team);
00246 void SetTeamWish(eTeam* team);
00247 void SetTeamname(const char *);
00248 void UpdateTeamForce();
00249 void UpdateTeam();
00250
00251 eTeamSet const & GetInvitations() const ;
00252
00253 void CreateNewTeam();
00254 void CreateNewTeamWish();
00255 virtual void ReceiveControlNet(nMessage &m);
00256
00257 static bool Enemies( ePlayerNetID const * a, ePlayerNetID const * b );
00258
00259
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(){}
00270 virtual void RightBeforeDeath(int triesLeft){}
00271
00272
00273 void RemoveFromGame();
00274 virtual void ControlObject(eNetGameObject *c);
00275 virtual void ClearObject();
00276
00277 void Greet();
00278
00279
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_;}
00298 void CreateVoter();
00299 static void SilenceMenu();
00300 static void PoliceMenu();
00301
00302 virtual bool IsHuman() const { return true; }
00303
00304 void Activity();
00305 REAL LastActivity() const;
00306
00307 eNetGameObject *Object() const;
00308
00309
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();
00314 static void LogScoreDifferences();
00315 void LogScoreDifference();
00316
00317 static void SortByScore();
00318 static tString Ranking( int MAX=12, bool cut = true );
00319
00320 static float RankingGraph( float y, int MAX );
00321
00322 static void RankingLadderLog();
00323
00324 static void ResetScore();
00325
00326 static void DisplayScores();
00327
00328 void GreetHighscores(tString &s);
00329
00330
00331 static void Update();
00332
00333
00334 #ifdef KRAWALL_SERVER
00335 static tAccessLevel AccessLevelRequiredToPlay();
00336 #endif
00337
00338 static bool WaitToLeaveChat();
00339
00340 static void RemoveChatbots();
00341
00342 static void CompleteRebuild();
00343 static void ClearAll();
00344 static void SpectateAll( bool spectate=true );
00345
00346 static void ThrowOutDisconnected();
00347
00348 void GetScoreFromDisconnectedCopy();
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
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
00385
00386
00387
00388
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();
00436 void se_UserShowScores(bool show);
00437 void se_SetShowScoresAuto(bool a);
00438
00439
00440 void se_DeletePasswords();
00441 extern int se_PasswordStorageMode;
00442
00443 tOutput& operator << (tOutput& o, const ePlayerNetID& p);
00444
00445
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;
00459
00460
00461
00462
00463
00464
00465
00469
00470
00471 tColoredString const & ePlayerNetID::GetNameFromClient( void ) const
00472 {
00473 return this->nameFromClient_;
00474 }
00475
00476
00477
00478
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
00496
00497
00502
00503
00504 ePlayerNetID & ePlayerNetID::SetNameFromClient( tColoredString const & nameFromClient )
00505 {
00506 this->nameFromClient_ = nameFromClient;
00507 return *this;
00508 }
00509
00510
00511
00512
00513
00514
00518
00519
00520 tColoredString const & ePlayerNetID::GetColoredName( void ) const
00521 {
00522 return this->coloredName_;
00523 }
00524
00525
00526
00527
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
00545
00546
00551
00552
00553 ePlayerNetID & ePlayerNetID::SetColoredName( tColoredString const & coloredName )
00554 {
00555 this->coloredName_ = coloredName;
00556 return *this;
00557 }
00558
00559
00560
00561
00562
00563
00567
00568
00569 tString const & ePlayerNetID::GetName( void ) const
00570 {
00571 return this->name_;
00572 }
00573
00574
00575
00576
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
00594
00595
00599
00600
00601 tString const & ePlayerNetID::GetUserName( void ) const
00602 {
00603 return this->userName_;
00604 }
00605
00606
00607
00608
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
00626
00627
00632
00633
00634 ePlayerNetID & ePlayerNetID::SetUserName( tString const & userName )
00635 {
00636 this->userName_ = userName;
00637 return *this;
00638 }
00639
00640 #endif
00641