fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fg_server.hxx
Go to the documentation of this file.
1 //
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License as
4 // published by the Free Software Foundation; either version 2 of the
5 // License, or (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful, but
8 // WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U$
15 //
16 
17 // Copyright (C) 2005-2010 Oliver Schroeder
18 //
19 
20 //////////////////////////////////////////////////////////////////////
21 //
22 // server for FlightGear
23 //
24 //////////////////////////////////////////////////////////////////////
25 
26 #if !defined FG_SERVER_HXX
27 #define FG_SERVER_HXX
28 
29 #include <iostream>
30 #include <fstream>
31 #include <map>
32 #include <string>
33 #include <string.h>
34 #include <errno.h>
35 #include <time.h>
36 #include <stdint.h>
37 #include <unistd.h>
38 #include <pthread.h>
39 #include <plib/netSocket.h>
43 #include "daemon.hxx"
44 #include "fg_geometry.hxx"
45 #include "fg_list.hxx"
46 #include "fg_tracker.hxx"
47 
48 using namespace std;
49 
50 //////////////////////////////////////////////////////////////////////
51 /**
52  * @class FG_SERVER
53  * @brief The Main fgms Class
54  */
55 class FG_SERVER
56 {
57 public:
58 
59  friend class FG_CLI;
60  friend void* admin_helper ( void* context );
61 
62  /** @brief Internal Constants */
64  {
65  // return values
66  SUCCESS = 0,
67  ERROR_COMMANDLINE = 1,
68  ERROR_CREATE_SOCKET = 2,
69  ERROR_COULDNT_BIND = 3,
70  ERROR_NOT_LISTENING = 4,
71  ERROR_COULDNT_LISTEN = 5,
72 
73  // other constants
74  MAX_PACKET_SIZE = 1200, // to agree with FG multiplayermgr.cxx (since before 2008)
75  UPDATE_INACTIVE_PERIOD = 1,
76  MAX_TELNETS = 5,
77  RELAY_MAGIC = 0x53464746 // GSGF
78  };
79  //////////////////////////////////////////////////
80  //
81  // constructors
82  //
83  //////////////////////////////////////////////////
84  FG_SERVER ();
85  ~FG_SERVER ();
86 
87  //////////////////////////////////////////////////
88  //
89  // public methods
90  //
91  //////////////////////////////////////////////////
92  int Init ();
93  int Loop ();
94  void Done ();
95 
96  void PrepareInit ();
97  void SetDataPort ( int Port );
98  void SetTelnetPort ( int Port );
99  void SetAdminPort ( int Port );
100  void SetAdminUser ( string User );
101  void SetAdminPass ( string Pass );
102  void SetAdminEnable ( string Enable );
103  void SetPlayerExpires ( int Seconds );
104  void SetOutOfReach ( int OutOfReach );
105  void SetHub ( bool IamHUB );
106  void SetLog ( int Facility, int Priority );
107  void SetLogfile ( const std::string& LogfileName );
108  void SetServerName ( const std::string& ServerName );
109  void SetBindAddress ( const std::string& BindAddress );
110  void AddRelay ( const string& Server, int Port );
111  void AddCrossfeed ( const string& Server, int Port );
112  int AddTracker ( const string& Server, int Port, bool IsTracked );
113  void AddBlacklist ( const string& DottedIP, const string& Reason, time_t Timeout = 10 );
114  void CloseTracker ();
115  int check_files();
116  void Show_Stats ( void );
117  void* HandleTelnet ( int Fd );
118  void* HandleAdmin ( int Fd );
119 
120  //////////////////////////////////////////////////
121  //
122  // public variables
123  //
124  //////////////////////////////////////////////////
125  string ConfigFile;
126 
127 protected:
128 
129  //////////////////////////////////////////////////
130  //
131  // private variables
132  //
133  //////////////////////////////////////////////////
134  typedef std::map<uint32_t,string> mT_IP2Relay;
135  typedef std::map<uint32_t,string>::iterator mT_RelayMapIt;
147  string m_AdminUser;
148  string m_AdminPass;
150  ofstream m_LogFile;
160  string m_ServerName;
165  mT_IP2Relay m_RelayMap;
170  int m_ipcid;
173  bool m_IamHUB;
176  //////////////////////////////////////////////////
177  //
178  // statistics
179  //
180  //////////////////////////////////////////////////
181  size_t m_PacketsReceived; // rw data packet received
182  size_t m_BlackRejected; // in black list
183  size_t m_PacketsInvalid; // invalid packet
184  size_t m_UnknownRelay; // unknown relay
185  size_t m_RelayMagic; // known relay packet
186  size_t m_PositionData; // position data packet
187  size_t m_NotPosData; // packet NOT pos data
190  size_t mT_PacketsReceived, mT_BlackRejected, mT_PacketsInvalid;
191  size_t mT_UnknownRelay, mT_PositionData, mT_TelnetReceived;
192  size_t mT_RelayMagic, mT_NotPosData;
193  size_t m_CrossFeedFailed, m_CrossFeedSent;
194  size_t mT_CrossFeedFailed, mT_CrossFeedSent;
195  size_t m_TrackerConnect, m_TrackerDisconnect,m_TrackerPosition;
196  time_t m_Uptime;
197 
198  //////////////////////////////////////////////////
199  //
200  // private methods
201  //
202  //////////////////////////////////////////////////
203  void AddClient ( const netAddress& Sender, char* Msg );
204  void AddBadClient ( const netAddress& Sender, string& ErrorMsg,
205  bool IsLocal, int Bytes );
206  bool IsKnownRelay ( const netAddress& SenderAddress, size_t Bytes );
207  bool PacketIsValid ( int Bytes, T_MsgHdr* MsgHdr,
208  const netAddress& SenderAddress );
209  void HandlePacket ( char* sMsg, int Bytes,
210  const netAddress& SenderAdress );
211  int UpdateTracker ( const string& callsign, const string& passwd, const string& modelname,
212  const time_t time, const int type );
213  void DropClient ( PlayerIt& CurrentPlayer );
214  bool IsInRange ( FG_ListElement& Relay, FG_Player& SendingPlayer );
215  void SendToCrossfeed ( char* Msg, int Bytes, const netAddress& SenderAddress );
216  void SendToRelays ( char* Msg, int Bytes, FG_Player& SendingPlayer );
217  void WantExit ();
218 }; // FG_SERVER
219 
220 typedef struct st_telnet
221 {
223  int Fd;
224 } st_telnet;
225 #endif
226 
std::map< uint32_t, string >::iterator mT_RelayMapIt
Definition: fg_server.hxx:135
mT_IP2Relay m_RelayMap
Definition: fg_server.hxx:165
int16_t m_ProtoMajorVersion
Definition: fg_server.hxx:157
size_t m_NumMaxClients
Definition: fg_server.hxx:153
The header sent as the first part of all mp message packets.
Definition: mpmessages.hxx:80
Socket type.
Definition: netSocket.h:125
FG_TRACKER * m_Tracker
Definition: fg_server.hxx:172
string ConfigFile
Definition: fg_server.hxx:125
time_t m_Uptime
Definition: fg_server.hxx:196
string m_AdminUser
Definition: fg_server.hxx:147
Tiny XDR implementation for flightgear.
The tracker class.
Definition: fg_tracker.hxx:47
int m_PlayerIsOutOfReach
Definition: fg_server.hxx:146
size_t m_CrossFeedSent
Definition: fg_server.hxx:193
size_t m_TelnetReceived
Definition: fg_server.hxx:188
bool m_Listening
Definition: fg_server.hxx:140
FG_List m_BlackList
Definition: fg_server.hxx:167
string m_ServerName
Definition: fg_server.hxx:160
Message definitions for multiplayer communications within multiplayer Flightgear. ...
Stream based logging mechanism.
bool m_IsTracked
Definition: fg_server.hxx:159
size_t mT_UnknownRelay
Definition: fg_server.hxx:191
size_t m_RemoteClients
Definition: fg_server.hxx:155
FG_SERVER * Instance
Definition: fg_server.hxx:222
Represent a Player.
Definition: fg_list.hxx:97
size_t m_PositionData
Definition: fg_server.hxx:186
string m_AdminEnable
Definition: fg_server.hxx:149
size_t m_PacketsReceived
Definition: fg_server.hxx:181
int m_TelnetPort
Definition: fg_server.hxx:142
void * admin_helper(void *context)
Definition: fg_server.cxx:261
string m_BindAddress
Definition: fg_server.hxx:152
FG_List m_CrossfeedList
Definition: fg_server.hxx:166
string m_TrackerServer
Definition: fg_server.hxx:161
FG_List m_RelayList
Definition: fg_server.hxx:168
size_t mT_RelayMagic
Definition: fg_server.hxx:192
bool m_ReinitTelnet
Definition: fg_server.hxx:138
bool m_ReinitData
Definition: fg_server.hxx:137
vector< FG_Player >::iterator PlayerIt
Definition: fg_list.hxx:209
int m_AdminPort
Definition: fg_server.hxx:143
cisco like command line interface
Definition: fg_cli.hxx:44
size_t m_RelayMagic
Definition: fg_server.hxx:185
bool m_IamHUB
Definition: fg_server.hxx:173
struct st_telnet st_telnet
int m_childpid
Definition: fg_server.hxx:171
netSocket * m_TelnetSocket
Definition: fg_server.hxx:163
time_t m_UpdateTrackerFreq
Definition: fg_server.hxx:174
bool m_ReinitAdmin
Definition: fg_server.hxx:139
int m_PlayerExpires
Definition: fg_server.hxx:145
Represent a generic list element.
Definition: fg_list.hxx:47
size_t m_LocalClients
Definition: fg_server.hxx:154
size_t m_TrackerPosition
Definition: fg_server.hxx:195
Socket address, internet style.
Definition: netSocket.h:87
FG_SERVER_CONSTANTS
Internal Constants.
Definition: fg_server.hxx:63
int16_t m_ProtoMinorVersion
Definition: fg_server.hxx:156
netSocket * m_DataSocket
Definition: fg_server.hxx:162
The Main fgms Class.
Definition: fg_server.hxx:55
bool m_Initialized
Definition: fg_server.hxx:136
string m_LogFileName
Definition: fg_server.hxx:151
size_t m_BlackRejected
Definition: fg_server.hxx:182
size_t mT_PacketsReceived
Definition: fg_server.hxx:190
netSocket is a thin C++ wrapper over bsd sockets to facilitate porting to other platforms. Part of PLIB - A Suite of Portable Game Libraries
netSocket * m_AdminSocket
Definition: fg_server.hxx:164
size_t mT_CrossFeedSent
Definition: fg_server.hxx:194
size_t m_AdminReceived
Definition: fg_server.hxx:189
size_t m_UnknownRelay
Definition: fg_server.hxx:184
int m_TrackingPort
Definition: fg_server.hxx:144
int m_ListenPort
Definition: fg_server.hxx:141
bool m_IsParent
Definition: fg_server.hxx:158
size_t m_NotPosData
Definition: fg_server.hxx:187
size_t m_PacketsInvalid
Definition: fg_server.hxx:183
string m_AdminPass
Definition: fg_server.hxx:148
PlayerList m_PlayerList
Definition: fg_server.hxx:169
std::map< uint32_t, string > mT_IP2Relay
Definition: fg_server.hxx:134
ofstream m_LogFile
Definition: fg_server.hxx:150
bool m_WantExit
Definition: fg_server.hxx:175