]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/multiplaymgr.hxx
new FSF address
[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   struct IdPropertyList {
58     unsigned id;
59     const char* name;
60   };
61   static IdPropertyList sIdPropertyList[];
62
63   FGMultiplayMgr();
64   ~FGMultiplayMgr();
65   bool init(void);
66   void Close(void);
67   // transmitter
68   void SendMyPosition(const FGExternalMotionData& motionInfo);
69   void SendTextMessage(const string &sMsgText);
70   void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
71   
72   // receiver
73   void ProcessPosMsg(const char *Msg, netAddress & SenderAddress,
74                      unsigned len, long stamp);
75   void ProcessChatMsg(const char *Msg, netAddress & SenderAddress);
76   void Update(void);
77   
78 private:
79   FGAIMultiplayer* addMultiplayer(const std::string& callsign,
80                                   const std::string& modelName);
81   FGAIMultiplayer* getMultiplayer(const std::string& callsign);
82
83   /// maps from the callsign string to the FGAIMultiplayer
84   typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
85   MultiPlayerMap mMultiPlayerMap;
86
87   netSocket* mSocket;
88   netAddress mServer;
89   bool mHaveServer;
90   bool mInitialised;
91   string mCallsign;
92 };
93
94 #endif
95