1 /* 2 * server/ServerPlayer.hpp 3 * 4 * This file is part of Leges Motus, a networked, 2D shooter set in zero gravity. 5 * 6 * Copyright 2009-2010 Andrew Ayer, Nathan Partlan, Jeffrey Pfau 7 * 8 * Leges Motus is free and open source software. You may redistribute it and/or 9 * modify it under the terms of version 2, or (at your option) version 3, of the 10 * GNU General Public License (GPL), as published by the Free Software Foundation. 11 * 12 * Leges Motus is distributed in the hope that it will be useful, but WITHOUT ANY 13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 * PARTICULAR PURPOSE. See the full text of the GNU General Public License for 15 * further detail. 16 * 17 * For a full copy of the GNU General Public License, please see the COPYING file 18 * in the root of the source code tree. You may also retrieve a copy from 19 * <http://www.gnu.org/licenses/gpl-2.0.txt>, or request a copy by writing to the 20 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 21 * 02111-1307 USA 22 * 23 */ 24 25 #ifndef LM_SERVER_SERVERPLAYER_HPP 26 #define LM_SERVER_SERVERPLAYER_HPP 27 28 #include "common/Player.hpp" 29 #include "common/IPAddress.hpp" 30 #include <stdint.h> 31 #include <list> 32 33 namespace LM { 34 class Spawnpoint; 35 36 class ServerPlayer : public Player { 37 public: 38 typedef std::list<ServerPlayer*> Queue; 39 40 private: 41 IPAddress m_address; // The address from which the player is connecting. 42 int m_client_version; // The protocol version of the player's client. 43 44 bool m_is_op; // This player has been authenticated with op status 45 46 const Spawnpoint* m_spawnpoint; // Where the player was spawned, if anywhere yet 47 48 uint64_t m_join_time; // The tick time at which the player joined the game 49 uint64_t m_last_seen_time; // The tick time at which this player was last seen (i.e. last had a packet from) 50 uint64_t m_team_change_time; // The tick time at which this player last changed teams 51 52 // Iterator into a list which keeps track of when players were last seen: 53 Queue::iterator m_timeout_queue_position; 54 55 public: 56 ServerPlayer(); 57 58 // Standard getters get_address() const59 const IPAddress& get_address() const { return m_address; } get_client_version() const60 int get_client_version() const { return m_client_version; } 61 is_op() const62 bool is_op() const { return m_is_op; } set_is_op(bool isop)63 void set_is_op(bool isop) { m_is_op = isop; } 64 65 // Remembering spawn points has_spawnpoint() const66 bool has_spawnpoint() const { return m_spawnpoint != NULL; } get_spawnpoint() const67 const Spawnpoint* get_spawnpoint() const { return m_spawnpoint; } set_spawnpoint(const Spawnpoint * p)68 void set_spawnpoint(const Spawnpoint* p) { m_spawnpoint = p; } 69 70 // For spawning 71 void reset_join_time(); 72 uint64_t time_until_spawn(uint64_t spawn_delay) const; // How many milliseconds until this player can spawn? is_ready_to_spawn(uint64_t spawn_delay) const73 bool is_ready_to_spawn(uint64_t spawn_delay) const { return time_until_spawn(spawn_delay) == 0; } 74 75 // For team changing cooldown (Ticket #63) 76 void set_team_change_time(); // Set the time to now get_team_change_time() const77 uint64_t get_team_change_time() const { return m_team_change_time; } 78 79 // For time out handling 80 void seen(Queue& timeout_queue); // Update last seen time 81 bool has_timed_out() const; // True if this player has timed out get_timeout_queue_position() const82 Queue::iterator get_timeout_queue_position() const { return m_timeout_queue_position; } 83 84 // Initialize the player 85 ServerPlayer& init(uint32_t player_id, const IPAddress& address, int client_version, const char* name, char team, Queue& timeout_queue); 86 87 }; 88 } 89 90 #endif 91