1 //////////////////////////////////////////////////////////////////////
5 // Written by Duncan McCreanor, started February 2003.
6 // duncan.mccreanor@airservicesaustralia.com
8 // Copyright (C) 2003 Airservices Australia
9 // Copyright (C) 2005 Oliver Schroeder
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 //////////////////////////////////////////////////////////////////////
29 #ifndef MULTIPLAYMGR_H
30 #define MULTIPLAYMGR_H
32 #define MULTIPLAYTXMGR_HID "$Id$"
38 #include <simgear/compiler.h>
39 #include <simgear/props/props.hxx>
40 #include <simgear/io/raw_socket.hxx>
41 #include <simgear/structure/subsystem_mgr.hxx>
43 struct FGExternalMotionData;
44 class MPPropertyListener;
46 class FGAIMultiplayer;
48 class FGMultiplayMgr : public SGSubsystem
54 virtual void init(void);
55 virtual void update(double dt);
57 virtual void shutdown(void);
58 virtual void reinit();
62 void SendTextMessage(const string &sMsgText);
66 friend class MPPropertyListener;
68 void setPropertiesChanged()
70 mPropertiesChanged = true;
73 void findProperties();
76 void SendMyPosition(const FGExternalMotionData& motionInfo);
79 FGAIMultiplayer* addMultiplayer(const std::string& callsign,
80 const std::string& modelName);
81 FGAIMultiplayer* getMultiplayer(const std::string& callsign);
82 void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
83 void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
85 void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
86 bool isSane(const FGExternalMotionData& motionInfo);
88 /// maps from the callsign string to the FGAIMultiplayer
89 typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
90 MultiPlayerMap mMultiPlayerMap;
92 std::auto_ptr<simgear::Socket> mSocket;
93 simgear::IPAddress mServer;
96 std::string mCallsign;
98 // Map between the property id's from the multiplayers network packets
99 // and the property nodes
100 typedef std::map<unsigned int, SGSharedPtr<SGPropertyNode> > PropertyMap;
101 PropertyMap mPropertyMap;
103 bool mPropertiesChanged;
104 MPPropertyListener* mListener;
106 double mDt; // reciprocal of /sim/multiplay/tx-rate-hz
107 double mTimeUntilSend;