Planeshift

serverpinger.h

Go to the documentation of this file.
00001 /*
00002  * serverpinger.h - Author: Ondrej Hurt
00003  *
00004  * Copyright (C) 2004 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef SERVER_PINGER_H
00021 #define SERVER_PINGER_H
00022 
00023 #include <net/connection.h>
00024 
00029 
00030 class psServerPinger
00031 {
00032 public:
00033 
00034     enum SERVERSTATUS { INIT,
00035                         FAILED,
00036                         READY, 
00037                         WAIT,
00038                         FULL,
00039                         LOCKED};
00040     
00041     psServerPinger(const csString & serverName, const csString& description, const csString & address, int port, iObjectRegistry * objReg);
00042     ~psServerPinger();
00043 
00046     bool Initialize();
00047 
00050     bool Connect();
00051 
00053     void Disconnect();
00054 
00056     void DoYourWork();
00057 
00059     int GetPing() { return ping; }
00060 
00062     int GetFlags() { return flags; }
00063 
00064     SERVERSTATUS GetStatus();
00065     
00066     float GetLoss() {
00067         if(lost == sent - 1 )
00068             return 1;
00069         else if (lost == 0)
00070             return 0;
00071         else
00072             return (float)lost/sent;
00073     }
00074 
00075     csString GetName()       { return name;        }
00076     csString GetDescription(){ return description; }
00077     csString GetAddress()    { return address;     }
00078     int      GetPort()       { return port;        }
00079 
00080 protected:
00081     csString name;      
00082     csString description;
00083     csString address;
00084     int port;
00085 
00086     psNetConnection * connection;
00087     MsgQueue * queue;
00088 
00089     int ping;           
00090     int lastPingTime;   
00091     unsigned int sent;  
00092     unsigned int lost;  
00093     bool waiting;       
00094     unsigned int pingID;
00095     unsigned int flags; 
00096     iObjectRegistry * objReg;
00097 };
00098 
00101 #endif