fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fg_list.cxx
Go to the documentation of this file.
1 /**
2  * @file fg_list.cxx
3  * @author Oliver Schroeder
4  */
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U$
19 //
20 // Copyright (C) 2005-2012 Oliver Schroeder
21 //
22 #ifdef HAVE_CONFIG_H
23  #include "config.h"
24 #endif
25 
26 #include <time.h>
28 #include <fg_list.hxx>
29 
30 const size_t FG_ListElement::NONE_EXISTANT = (size_t) -1;
31 
32 //////////////////////////////////////////////////////////////////////
34 (
35  const string& Name
36 )
37 {
38  ID = NONE_EXISTANT; // flag a non existant Element
39  Timeout = 0;
40  this->Name = Name;
41  JoinTime = time (0);
42  LastSeen = JoinTime;
43  LastSent = JoinTime;
44  PktsSent = 0;
45  PktsRcvd = 0;
46  BytesRcvd = 0;
47  BytesSent = 0;
48 }
49 //////////////////////////////////////////////////////////////////////
50 
51 //////////////////////////////////////////////////////////////////////
53 ()
54 {
55  ID = NONE_EXISTANT; // flag a non existant Element
56  Timeout = 0;
57  Name = "";
58  JoinTime = time (0);
59  LastSeen = JoinTime;
60  LastSent = JoinTime;
61  PktsSent = 0;
62  PktsRcvd = 0;
63  BytesRcvd = 0;
64  BytesSent = 0;
65 }
66 //////////////////////////////////////////////////////////////////////
67 
68 //////////////////////////////////////////////////////////////////////
70 (
71  const FG_ListElement& P
72 )
73 {
74  this->assign (P);
75 }
76 //////////////////////////////////////////////////////////////////////
77 
78 //////////////////////////////////////////////////////////////////////
80 ()
81 {
82 }
83 //////////////////////////////////////////////////////////////////////
84 
85 //////////////////////////////////////////////////////////////////////
86 void
87 FG_ListElement::operator =
88 (
89  const FG_ListElement& P
90 )
91 {
92  this->assign (P);
93 }
94 //////////////////////////////////////////////////////////////////////
95 
96 //////////////////////////////////////////////////////////////////////
97 bool
98 FG_ListElement::operator ==
99 (
100  const FG_ListElement& P
101 )
102 {
103  // FIXME: compare the name, too?
104  if (Address == P.Address)
105  return true;
106  return false;
107 }
108 //////////////////////////////////////////////////////////////////////
109 
110 //////////////////////////////////////////////////////////////////////
111 void
113 (
114  const FG_ListElement& P
115 )
116 {
117  ID = P.ID;
118  Timeout = P.Timeout;
119  Name = P.Name.c_str();
120  Address = P.Address;
121  JoinTime = P.JoinTime;
122  LastSeen = P.LastSeen;
123  LastSent = P.LastSent;
124  PktsSent = P.PktsSent;
125  BytesSent = P.BytesSent;
126  PktsRcvd = P.PktsRcvd;
127  BytesRcvd = P.BytesRcvd;
128 }
129 //////////////////////////////////////////////////////////////////////
130 
131 //////////////////////////////////////////////////////////////////////
132 void
134 (
135  size_t bytes
136 )
137 {
138  PktsSent++;
139  BytesSent += bytes;
140  LastSent = time(0);
141 }
142 //////////////////////////////////////////////////////////////////////
143 
144 //////////////////////////////////////////////////////////////////////
145 void
147 (
148  size_t bytes
149 )
150 {
151  PktsRcvd++;
152  BytesRcvd += bytes;
153  LastSeen = time(0);
154 }
155 //////////////////////////////////////////////////////////////////////
156 
157 //////////////////////////////////////////////////////////////////////
159 ()
160 {
161  Name = "";
162  JoinTime = time (0);
163  LastSeen = JoinTime;
164  LastSent = 0;
165  Passwd = "";
166  ModelName = "";
167  Error = "";
168  HasErrors = false;
169  DoUpdate = false;
170  LastRelayedToInactive = 0;
171 }
172 //////////////////////////////////////////////////////////////////////
173 
174 //////////////////////////////////////////////////////////////////////
176 (
177  const string& Name
178 )
179 {
180  this->Name = Name;
181  JoinTime = time (0);
182  LastSeen = JoinTime;
183  LastSent = 0;
184  Passwd = "";
185  ModelName = "";
186  Error = "";
187  HasErrors = false;
188  DoUpdate = false;
189  LastRelayedToInactive = 0;
190 }
191 //////////////////////////////////////////////////////////////////////
192 
193 //////////////////////////////////////////////////////////////////////
195 (
196  const FG_Player& P
197 )
198 {
199  this->assign (P);
200 }
201 //////////////////////////////////////////////////////////////////////
202 
203 //////////////////////////////////////////////////////////////////////
205 ()
206 {
207 }
208 //////////////////////////////////////////////////////////////////////
209 
210 //////////////////////////////////////////////////////////////////////
211 void
212 FG_Player::operator =
213 (
214  const FG_Player& P
215 )
216 {
217  this->assign (P);
218 }
219 //////////////////////////////////////////////////////////////////////
220 
221 //////////////////////////////////////////////////////////////////////
222 bool
223 FG_Player::operator ==
224 (
225  const FG_Player& P
226 )
227 {
228  if ((Address == P.Address) && (Name == P.Name))
229  return true;
230  return false;
231 }
232 //////////////////////////////////////////////////////////////////////
233 
234 //////////////////////////////////////////////////////////////////////
235 void
237 (
238  const FG_Player& P
239 )
240 {
241  //
242  // using str.c_str() here to prevent copy-on-write in std::string!
243  //
245  Origin = P.Origin.c_str();
246  Passwd = P.Passwd.c_str();
247  ModelName = P.ModelName.c_str();
248  JoinTime = P.JoinTime;
249  LastSeen = P.LastSeen ;
250  LastSent = P.LastSent ;
251  LastPos = P.LastPos;
252  IsLocal = P.IsLocal;
253  Error = P.Error.c_str();
254  HasErrors = P.HasErrors;
255  LastOrientation = P.LastOrientation;
256  DoUpdate = P.DoUpdate;
257  LastRelayedToInactive = P.LastRelayedToInactive;
258 }
259 //////////////////////////////////////////////////////////////////////
~FG_Player()
Definition: fg_list.cxx:205
size_t ID
The ID of this entry.
Definition: fg_list.hxx:57
string Name
The callsign (or name)
Definition: fg_list.hxx:61
uint64_t BytesSent
Count of bytes sent to client.
Definition: fg_list.hxx:77
time_t JoinTime
The time this entry was added to the list.
Definition: fg_list.hxx:65
time_t LastRelayedToInactive
Definition: fg_list.hxx:122
bool DoUpdate
Definition: fg_list.hxx:124
string Origin
Definition: fg_list.hxx:100
Stream based logging mechanism.
Represent a Player.
Definition: fg_list.hxx:97
time_t Timeout
The Timeout of this entry.
Definition: fg_list.hxx:59
uint64_t PktsSent
Count of packets sent to client.
Definition: fg_list.hxx:73
bool HasErrors
true if this client has errors
Definition: fg_list.hxx:120
string Error
in case of errors the reason is stored here
Definition: fg_list.hxx:116
static char P[]
Definition: crypt-win.c:209
void UpdateRcvd(size_t bytes)
Definition: fg_list.cxx:147
void UpdateSent(size_t bytes)
Definition: fg_list.cxx:134
void assign(const FG_ListElement &P)
Definition: fg_list.cxx:113
string Passwd
The password.
Definition: fg_list.hxx:104
Point3D LastOrientation
The last recorded orientation.
Definition: fg_list.hxx:110
uint64_t BytesRcvd
Count of bytes recieved from client.
Definition: fg_list.hxx:75
Represent a generic list element.
Definition: fg_list.hxx:47
time_t LastSeen
timestamp of last seen packet from this element
Definition: fg_list.hxx:67
string ModelName
The model name.
Definition: fg_list.hxx:106
bool IsLocal
true is this client is directly connected to this fgms instance
Definition: fg_list.hxx:112
uint64_t PktsRcvd
Count of packets recieved from client.
Definition: fg_list.hxx:71
static const size_t NONE_EXISTANT
Definition: fg_list.hxx:55
netAddress Address
The network address of this element.
Definition: fg_list.hxx:63
time_t LastSent
timestamp of last sent packet to this element
Definition: fg_list.hxx:69
Point3D LastPos
The last recorded position.
Definition: fg_list.hxx:108
void assign(const FG_Player &P)
Definition: fg_list.cxx:237