]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/multiplaymgr.hxx
Modified Files:
[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 #ifdef HAVE_CONFIG_H
37 #  include <config.h>
38 #endif
39
40 #include STL_STRING
41 SG_USING_STD(string);
42 #include <vector>
43 SG_USING_STD(vector);
44
45 #include <simgear/compiler.h>
46 #include <simgear/props/props.hxx>
47 #include <plib/netSocket.h>
48 #include <Main/globals.hxx>
49
50 #include <AIModel/AIMultiplayer.hxx>
51
52 struct FGExternalMotionInfo;
53
54 class FGMultiplayMgr 
55 {
56 public:
57
58   struct IdPropertyList {
59     unsigned id;
60     const char* name;
61     SGPropertyNode::Type type;
62   };
63   static IdPropertyList sIdPropertyList[];
64
65   FGMultiplayMgr();
66   ~FGMultiplayMgr();
67   bool init(void);
68   void Close(void);
69   // transmitter
70   void SendMyPosition(const FGExternalMotionData& motionInfo);
71   void SendTextMessage(const string &sMsgText);
72   void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
73   
74   // receiver
75   void ProcessPosMsg(const char *Msg, netAddress & SenderAddress,
76                      unsigned len, long stamp);
77   void ProcessChatMsg(const char *Msg, netAddress & SenderAddress);
78   void Update(void);
79   
80 private:
81   FGAIMultiplayer* addMultiplayer(const std::string& callsign,
82                                   const std::string& modelName);
83   FGAIMultiplayer* getMultiplayer(const std::string& callsign);
84
85   /// maps from the callsign string to the FGAIMultiplayer
86   typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
87   MultiPlayerMap mMultiPlayerMap;
88
89   netSocket* mSocket;
90   netAddress mServer;
91   bool mHaveServer;
92   bool mInitialised;
93   string mCallsign;
94 };
95
96 #endif
97