]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/multiplaymgr.hxx
Merge commit 'refs/merge-requests/13' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / MultiPlayer / multiplaymgr.hxx
1 //////////////////////////////////////////////////////////////////////
2 //
3 // multiplaymgr.hpp
4 //
5 // Written by Duncan McCreanor, started February 2003.
6 // duncan.mccreanor@airservicesaustralia.com
7 //
8 // Copyright (C) 2003  Airservices Australia
9 // Copyright (C) 2005  Oliver Schroeder
10 //
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.
15 //
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.
20 //
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.
24 //
25 // $Id$
26 //  
27 //////////////////////////////////////////////////////////////////////
28
29 #ifndef MULTIPLAYMGR_H
30 #define MULTIPLAYMGR_H
31
32 #define MULTIPLAYTXMGR_HID "$Id$"
33
34 #include "mpmessages.hxx"
35
36 #include <string>
37 #include <vector>
38
39 #include <simgear/compiler.h>
40 #include <simgear/props/props.hxx>
41 #include <Main/globals.hxx>
42 #include <simgear/io/raw_socket.hxx>
43 #include <simgear/structure/subsystem_mgr.hxx>
44
45 #include <AIModel/AIMultiplayer.hxx>
46
47 struct FGExternalMotionInfo;
48
49 class FGMultiplayMgr : public SGSubsystem
50 {
51 public:
52
53   struct IdPropertyList {
54     unsigned id;
55     const char* name;
56     simgear::props::Type type;
57   };
58   static const IdPropertyList sIdPropertyList[];
59   static const unsigned numProperties;
60
61   static const IdPropertyList* findProperty(unsigned id);
62   
63   FGMultiplayMgr();
64   ~FGMultiplayMgr();
65   
66   virtual void init(void);
67   virtual void update(double dt);
68   
69   void Close(void);
70   // transmitter
71   void SendMyPosition(const FGExternalMotionData& motionInfo);
72   void SendTextMessage(const string &sMsgText);
73   // receiver
74   
75 private:
76   union MsgBuf;
77   FGAIMultiplayer* addMultiplayer(const std::string& callsign,
78                                   const std::string& modelName);
79   FGAIMultiplayer* getMultiplayer(const std::string& callsign);
80   void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
81   void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
82                      long stamp);
83   void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
84
85   /// maps from the callsign string to the FGAIMultiplayer
86   typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
87   MultiPlayerMap mMultiPlayerMap;
88
89   simgear::Socket* mSocket;
90   simgear::IPAddress mServer;
91   bool mHaveServer;
92   bool mInitialised;
93   std::string mCallsign;
94 };
95
96 #endif
97