Planeshift
serverpinger.h
Go to the documentation of this file.
1 /*
2  * serverpinger.h - Author: Ondrej Hurt
3  *
4  * Copyright (C) 2004 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef SERVER_PINGER_H
21 #define SERVER_PINGER_H
22 
23 #include <net/connection.h>
24 
29 class psServerPinger
31 {
32 public:
33 
40 
41  psServerPinger(const csString & serverName, const csString& description, const csString & address, int port, iObjectRegistry * objReg);
43 
46  bool Initialize();
47 
50  bool Connect();
51 
53  void Disconnect();
54 
56  void DoYourWork();
57 
59  int GetPing() { return ping; }
60 
62  int GetFlags() { return flags; }
63 
65 
66  float GetLoss() {
67  if(lost == sent - 1 )
68  return 1;
69  else if (lost == 0)
70  return 0;
71  else
72  return (float)lost/sent;
73  }
74 
75  csString GetName() { return name; }
76  csString GetDescription(){ return description; }
77  csString GetAddress() { return address; }
78  int GetPort() { return port; }
79 
80 protected:
81  csString name;
82  csString description;
83  csString address;
84  int port;
85 
88 
89  int ping;
91  unsigned int sent;
92  unsigned int lost;
93  bool waiting;
94  unsigned int pingID;
95  unsigned int flags;
96  iObjectRegistry * objReg;
97 };
98 
101 #endif
csString GetDescription()
Definition: serverpinger.h:76
unsigned int lost
the number of ping messages lost
Definition: serverpinger.h:92
iObjectRegistry * objReg
Definition: serverpinger.h:96
int GetPing()
Returns currently measured ping to server is miliseconds.
Definition: serverpinger.h:59
bool waiting
are we waiting for ping response from server ?
Definition: serverpinger.h:93
csString GetAddress()
Definition: serverpinger.h:77
MsgQueue * queue
Definition: serverpinger.h:87
Client-side UDP handler.
Definition: connection.h:42
csString address
Definition: serverpinger.h:83
SERVERSTATUS GetStatus()
unsigned int pingID
unique identifier of ping message - enables us to ignore ping responses that come after timeout ...
Definition: serverpinger.h:94
unsigned int flags
Last flags returned from server. Should only be used if ping != -1 && ping != 9999.
Definition: serverpinger.h:95
bool Initialize()
Initialize the connection.
psNetConnection * connection
Definition: serverpinger.h:86
csString name
server info
Definition: serverpinger.h:81
int lastPingTime
the time when we sent our last ping to server
Definition: serverpinger.h:90
int ping
last measured ping (-1 means timeout, 9999 means wait)
Definition: serverpinger.h:89
A queue of smart pointers with locking facilties for multi-threading.
Definition: genrefqueue.h:39
unsigned int sent
the number of ping messages sent
Definition: serverpinger.h:91
int GetFlags()
Returns last received flags from server.
Definition: serverpinger.h:62
bool Connect()
Opens connection to server.
Class psServerPinger takes care about sending pings to a server in Login screen.
Definition: serverpinger.h:30
psServerPinger(const csString &serverName, const csString &description, const csString &address, int port, iObjectRegistry *objReg)
void Disconnect()
Sends server disconnection message.
void DoYourWork()
Call this periodically.
csString description
Definition: serverpinger.h:82
csString GetName()
Definition: serverpinger.h:75
float GetLoss()
Definition: serverpinger.h:66