Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

client.h

00001 /***************************************************************************
00002  * The contents of this file are subject to the Mozilla Public             *
00003  * License Version 1.1 (the "License"); you may not use this file          *
00004  * except in compliance with the License. You may obtain a copy of         *
00005  * the License at http://www.mozilla.org/MPL/                              *
00006  *                                                                         *
00007  * Software distributed under the License is distributed on an "AS         *
00008  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or              *
00009  * implied. See the License for the specific language governing            *
00010  * rights and limitations under the License.                               *
00011  *                                                                         *
00012  * The Original Code is Game Network Framework (GaNeF).                    *
00013  *                                                                         *
00014  * The Initial Developers of the Original Code are                         *
00015  * Lars Langer and Emanuel Greisen                                         *
00016  * Copyright (C) 2005. Lars Langer & Emanuel Greisen                       *
00017  * All Rights Reserved.                                                    *
00018  *                                                                         *
00019  * Contributor(s):                                                         *
00020  *   none yet....                                                          *
00021  *                                                                         *
00022  ***************************************************************************/
00023 #ifndef CLIENT_H
00024 #define CLIENT_H
00025 
00026 #include <pinet.h>
00027 USING_PTYPES
00028 
00029 #include "../common/averagetimecalculator.h"
00030 #include "../common/frameworkseqnolist.h"
00031 
00032 class ServerPacket;
00033 class ServerFramework;
00034 /**
00035  * @ingroup Server
00036  * @brief An object of this class represents a client currently connected to the server.
00037  * You should create your own class inheriting from this one so you can associate any data you wish with a client/player in the game.
00038  *
00039  * @author Lars Langer and Emanuel Greisen
00040  */
00041 class Client
00042 {
00043 friend bool operator== (const Client &c1, const Client &c2);
00044 
00045 private:
00046    static unsigned int next_uid;
00047 
00048 private:
00049    ServerFramework * server_framework;
00050    unsigned int uid;
00051    ipaddress addr;
00052    int port;
00053    AverageTimeCalculator<8,50,1,1000> rtt_time;
00054    /// These are held for each priority, and one for pre-send-chains(plugins).
00055    FrameworkSeqNoList<ServerPacket,ipmsgserver> sequencenumbers;
00056    bool has_called_on_connect;
00057    bool has_called_on_disconnect;
00058    unsigned int last_packet_received;
00059 
00060 public:
00061    enum ClientState
00062    {
00063       NEWCLIENT            = 0,
00064       CONNECTED            = 1,
00065       CONNECTION_ABORTED   = 2,
00066       DICONNECTED          = 3,
00067    };
00068    inline const ClientState getState() const { return state; };
00069    inline void setState(const ClientState & _s ) { state = _s; };
00070 
00071 private:
00072    ClientState state;
00073 
00074 public:
00075    Client(ServerFramework * fw, const ipaddress &addr, int port);
00076    ~Client();
00077 
00078 public:
00079    const ipaddress &getAddress(){ return addr; };
00080    const int         getPort()   { return port; };
00081    const unsigned int getId() const { return uid; };
00082 
00083 public:
00084    inline void registerRTT( unsigned int ms ){ rtt_time.registerValue(ms); };
00085    inline void registerLastPacketReceivedTime( unsigned int time ){ last_packet_received = time; };
00086    inline unsigned int getLastPacketReceivedTime() const { return last_packet_received; };
00087    inline unsigned int getRTT() const { return rtt_time.getAvg(); };
00088    inline unsigned int getNextOutgoingSeqNo( ServerPacket * packet ) { return sequencenumbers.getNextOutgoingSeqNo(packet); };
00089    inline bool hasCalledOnConnect() const { return has_called_on_connect; };
00090    inline void setCalledOnConnect(bool b){ has_called_on_connect = b; };
00091    inline bool hasCalledOnDisconnect() const { return has_called_on_disconnect; };
00092    inline void setCalledOnDisconnect(bool b){ has_called_on_disconnect = b; };
00093    bool isPacketReadyForDelivery(ServerPacket * packet);
00094    ServerPacket * incrementNextIngoingSeqNo( ServerPacket * packet );
00095    inline unsigned int bufferedPackets( ) const { return sequencenumbers.bufferePacketsTotal(); };
00096    unsigned int getNextOutgoingPacketSeqNumber(ServerPacket * packet);
00097 };
00098 
00099 /// Used when clients connect to see if its a reconnect.
00100 bool operator== (const Client &c1, const Client &c2);
00101 
00102 std::ostream & operator<<(std::ostream & o, Client & client);
00103 
00104 
00105 #endif

Generated on Mon Feb 6 12:24:50 2006 for Ganef by  doxygen 1.4.4