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
10 // Copyright (C) 2006 Mathias Froehlich
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of the
15 // License, or (at your option) any later version.
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 //////////////////////////////////////////////////////////////////////
39 #include <simgear/misc/stdint.hxx>
40 #include <simgear/timing/timestamp.hxx>
41 #include <simgear/debug/logstream.hxx>
42 #include <simgear/props/props.hxx>
44 #include <AIModel/AIManager.hxx>
45 #include <AIModel/AIMultiplayer.hxx>
46 #include <Main/fg_props.hxx>
47 #include "multiplaymgr.hxx"
48 #include "mpmessages.hxx"
49 #include <FDM/flightProperties.hxx>
53 #define MAX_PACKET_SIZE 1200
54 #define MAX_TEXT_SIZE 128
56 // These constants are provided so that the ident
57 // command can list file versions
58 const char sMULTIPLAYMGR_BID[] = "$Id$";
59 const char sMULTIPLAYMGR_HID[] = MULTIPLAYTXMGR_HID;
61 struct IdPropertyList {
64 simgear::props::Type type;
67 static const IdPropertyList* findProperty(unsigned id);
69 // A static map of protocol property id values to property paths,
70 // This should be extendable dynamically for every specific aircraft ...
71 // For now only that static list
72 static const IdPropertyList sIdPropertyList[] = {
73 {100, "surface-positions/left-aileron-pos-norm", simgear::props::FLOAT},
74 {101, "surface-positions/right-aileron-pos-norm", simgear::props::FLOAT},
75 {102, "surface-positions/elevator-pos-norm", simgear::props::FLOAT},
76 {103, "surface-positions/rudder-pos-norm", simgear::props::FLOAT},
77 {104, "surface-positions/flap-pos-norm", simgear::props::FLOAT},
78 {105, "surface-positions/speedbrake-pos-norm", simgear::props::FLOAT},
79 {106, "gear/tailhook/position-norm", simgear::props::FLOAT},
80 {107, "gear/launchbar/position-norm", simgear::props::FLOAT},
81 {108, "gear/launchbar/state", simgear::props::STRING},
82 {109, "gear/launchbar/holdback-position-norm", simgear::props::FLOAT},
83 {110, "canopy/position-norm", simgear::props::FLOAT},
84 {111, "surface-positions/wing-pos-norm", simgear::props::FLOAT},
85 {112, "surface-positions/wing-fold-pos-norm", simgear::props::FLOAT},
87 {200, "gear/gear[0]/compression-norm", simgear::props::FLOAT},
88 {201, "gear/gear[0]/position-norm", simgear::props::FLOAT},
89 {210, "gear/gear[1]/compression-norm", simgear::props::FLOAT},
90 {211, "gear/gear[1]/position-norm", simgear::props::FLOAT},
91 {220, "gear/gear[2]/compression-norm", simgear::props::FLOAT},
92 {221, "gear/gear[2]/position-norm", simgear::props::FLOAT},
93 {230, "gear/gear[3]/compression-norm", simgear::props::FLOAT},
94 {231, "gear/gear[3]/position-norm", simgear::props::FLOAT},
95 {240, "gear/gear[4]/compression-norm", simgear::props::FLOAT},
96 {241, "gear/gear[4]/position-norm", simgear::props::FLOAT},
98 {300, "engines/engine[0]/n1", simgear::props::FLOAT},
99 {301, "engines/engine[0]/n2", simgear::props::FLOAT},
100 {302, "engines/engine[0]/rpm", simgear::props::FLOAT},
101 {310, "engines/engine[1]/n1", simgear::props::FLOAT},
102 {311, "engines/engine[1]/n2", simgear::props::FLOAT},
103 {312, "engines/engine[1]/rpm", simgear::props::FLOAT},
104 {320, "engines/engine[2]/n1", simgear::props::FLOAT},
105 {321, "engines/engine[2]/n2", simgear::props::FLOAT},
106 {322, "engines/engine[2]/rpm", simgear::props::FLOAT},
107 {330, "engines/engine[3]/n1", simgear::props::FLOAT},
108 {331, "engines/engine[3]/n2", simgear::props::FLOAT},
109 {332, "engines/engine[3]/rpm", simgear::props::FLOAT},
110 {340, "engines/engine[4]/n1", simgear::props::FLOAT},
111 {341, "engines/engine[4]/n2", simgear::props::FLOAT},
112 {342, "engines/engine[4]/rpm", simgear::props::FLOAT},
113 {350, "engines/engine[5]/n1", simgear::props::FLOAT},
114 {351, "engines/engine[5]/n2", simgear::props::FLOAT},
115 {352, "engines/engine[5]/rpm", simgear::props::FLOAT},
116 {360, "engines/engine[6]/n1", simgear::props::FLOAT},
117 {361, "engines/engine[6]/n2", simgear::props::FLOAT},
118 {362, "engines/engine[6]/rpm", simgear::props::FLOAT},
119 {370, "engines/engine[7]/n1", simgear::props::FLOAT},
120 {371, "engines/engine[7]/n2", simgear::props::FLOAT},
121 {372, "engines/engine[7]/rpm", simgear::props::FLOAT},
122 {380, "engines/engine[8]/n1", simgear::props::FLOAT},
123 {381, "engines/engine[8]/n2", simgear::props::FLOAT},
124 {382, "engines/engine[8]/rpm", simgear::props::FLOAT},
125 {390, "engines/engine[9]/n1", simgear::props::FLOAT},
126 {391, "engines/engine[9]/n2", simgear::props::FLOAT},
127 {392, "engines/engine[9]/rpm", simgear::props::FLOAT},
129 {800, "rotors/main/rpm", simgear::props::FLOAT},
130 {801, "rotors/tail/rpm", simgear::props::FLOAT},
131 {810, "rotors/main/blade[0]/position-deg", simgear::props::FLOAT},
132 {811, "rotors/main/blade[1]/position-deg", simgear::props::FLOAT},
133 {812, "rotors/main/blade[2]/position-deg", simgear::props::FLOAT},
134 {813, "rotors/main/blade[3]/position-deg", simgear::props::FLOAT},
135 {820, "rotors/main/blade[0]/flap-deg", simgear::props::FLOAT},
136 {821, "rotors/main/blade[1]/flap-deg", simgear::props::FLOAT},
137 {822, "rotors/main/blade[2]/flap-deg", simgear::props::FLOAT},
138 {823, "rotors/main/blade[3]/flap-deg", simgear::props::FLOAT},
139 {830, "rotors/tail/blade[0]/position-deg", simgear::props::FLOAT},
140 {831, "rotors/tail/blade[1]/position-deg", simgear::props::FLOAT},
142 {900, "sim/hitches/aerotow/tow/length", simgear::props::FLOAT},
143 {901, "sim/hitches/aerotow/tow/elastic-constant", simgear::props::FLOAT},
144 {902, "sim/hitches/aerotow/tow/weight-per-m-kg-m", simgear::props::FLOAT},
145 {903, "sim/hitches/aerotow/tow/dist", simgear::props::FLOAT},
146 {904, "sim/hitches/aerotow/tow/connected-to-property-node", simgear::props::BOOL},
147 {905, "sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign", simgear::props::STRING},
148 {906, "sim/hitches/aerotow/tow/brake-force", simgear::props::FLOAT},
149 {907, "sim/hitches/aerotow/tow/end-force-x", simgear::props::FLOAT},
150 {908, "sim/hitches/aerotow/tow/end-force-y", simgear::props::FLOAT},
151 {909, "sim/hitches/aerotow/tow/end-force-z", simgear::props::FLOAT},
152 {930, "sim/hitches/aerotow/is-slave", simgear::props::BOOL},
153 {931, "sim/hitches/aerotow/speed-in-tow-direction", simgear::props::FLOAT},
154 {932, "sim/hitches/aerotow/open", simgear::props::BOOL},
155 {933, "sim/hitches/aerotow/local-pos-x", simgear::props::FLOAT},
156 {934, "sim/hitches/aerotow/local-pos-y", simgear::props::FLOAT},
157 {935, "sim/hitches/aerotow/local-pos-z", simgear::props::FLOAT},
159 {1001, "controls/flight/slats", simgear::props::FLOAT},
160 {1002, "controls/flight/speedbrake", simgear::props::FLOAT},
161 {1003, "controls/flight/spoilers", simgear::props::FLOAT},
162 {1004, "controls/gear/gear-down", simgear::props::FLOAT},
163 {1005, "controls/lighting/nav-lights", simgear::props::FLOAT},
164 {1006, "controls/armament/station[0]/jettison-all", simgear::props::BOOL},
166 {1100, "sim/model/variant", simgear::props::INT},
167 {1101, "sim/model/livery/file", simgear::props::STRING},
169 {1200, "environment/wildfire/data", simgear::props::STRING},
170 {1201, "environment/contrail", simgear::props::INT},
172 {1300, "tanker", simgear::props::INT},
174 {1400, "scenery/events", simgear::props::STRING},
176 {10001, "sim/multiplay/transmission-freq-hz", simgear::props::STRING},
177 {10002, "sim/multiplay/chat", simgear::props::STRING},
179 {10100, "sim/multiplay/generic/string[0]", simgear::props::STRING},
180 {10101, "sim/multiplay/generic/string[1]", simgear::props::STRING},
181 {10102, "sim/multiplay/generic/string[2]", simgear::props::STRING},
182 {10103, "sim/multiplay/generic/string[3]", simgear::props::STRING},
183 {10104, "sim/multiplay/generic/string[4]", simgear::props::STRING},
184 {10105, "sim/multiplay/generic/string[5]", simgear::props::STRING},
185 {10106, "sim/multiplay/generic/string[6]", simgear::props::STRING},
186 {10107, "sim/multiplay/generic/string[7]", simgear::props::STRING},
187 {10108, "sim/multiplay/generic/string[8]", simgear::props::STRING},
188 {10109, "sim/multiplay/generic/string[9]", simgear::props::STRING},
189 {10110, "sim/multiplay/generic/string[10]", simgear::props::STRING},
190 {10111, "sim/multiplay/generic/string[11]", simgear::props::STRING},
191 {10112, "sim/multiplay/generic/string[12]", simgear::props::STRING},
192 {10113, "sim/multiplay/generic/string[13]", simgear::props::STRING},
193 {10114, "sim/multiplay/generic/string[14]", simgear::props::STRING},
194 {10115, "sim/multiplay/generic/string[15]", simgear::props::STRING},
195 {10116, "sim/multiplay/generic/string[16]", simgear::props::STRING},
196 {10117, "sim/multiplay/generic/string[17]", simgear::props::STRING},
197 {10118, "sim/multiplay/generic/string[18]", simgear::props::STRING},
198 {10119, "sim/multiplay/generic/string[19]", simgear::props::STRING},
200 {10200, "sim/multiplay/generic/float[0]", simgear::props::FLOAT},
201 {10201, "sim/multiplay/generic/float[1]", simgear::props::FLOAT},
202 {10202, "sim/multiplay/generic/float[2]", simgear::props::FLOAT},
203 {10203, "sim/multiplay/generic/float[3]", simgear::props::FLOAT},
204 {10204, "sim/multiplay/generic/float[4]", simgear::props::FLOAT},
205 {10205, "sim/multiplay/generic/float[5]", simgear::props::FLOAT},
206 {10206, "sim/multiplay/generic/float[6]", simgear::props::FLOAT},
207 {10207, "sim/multiplay/generic/float[7]", simgear::props::FLOAT},
208 {10208, "sim/multiplay/generic/float[8]", simgear::props::FLOAT},
209 {10209, "sim/multiplay/generic/float[9]", simgear::props::FLOAT},
210 {10210, "sim/multiplay/generic/float[10]", simgear::props::FLOAT},
211 {10211, "sim/multiplay/generic/float[11]", simgear::props::FLOAT},
212 {10212, "sim/multiplay/generic/float[12]", simgear::props::FLOAT},
213 {10213, "sim/multiplay/generic/float[13]", simgear::props::FLOAT},
214 {10214, "sim/multiplay/generic/float[14]", simgear::props::FLOAT},
215 {10215, "sim/multiplay/generic/float[15]", simgear::props::FLOAT},
216 {10216, "sim/multiplay/generic/float[16]", simgear::props::FLOAT},
217 {10217, "sim/multiplay/generic/float[17]", simgear::props::FLOAT},
218 {10218, "sim/multiplay/generic/float[18]", simgear::props::FLOAT},
219 {10219, "sim/multiplay/generic/float[19]", simgear::props::FLOAT},
221 {10300, "sim/multiplay/generic/int[0]", simgear::props::INT},
222 {10301, "sim/multiplay/generic/int[1]", simgear::props::INT},
223 {10302, "sim/multiplay/generic/int[2]", simgear::props::INT},
224 {10303, "sim/multiplay/generic/int[3]", simgear::props::INT},
225 {10304, "sim/multiplay/generic/int[4]", simgear::props::INT},
226 {10305, "sim/multiplay/generic/int[5]", simgear::props::INT},
227 {10306, "sim/multiplay/generic/int[6]", simgear::props::INT},
228 {10307, "sim/multiplay/generic/int[7]", simgear::props::INT},
229 {10308, "sim/multiplay/generic/int[8]", simgear::props::INT},
230 {10309, "sim/multiplay/generic/int[9]", simgear::props::INT},
231 {10310, "sim/multiplay/generic/int[10]", simgear::props::INT},
232 {10311, "sim/multiplay/generic/int[11]", simgear::props::INT},
233 {10312, "sim/multiplay/generic/int[12]", simgear::props::INT},
234 {10313, "sim/multiplay/generic/int[13]", simgear::props::INT},
235 {10314, "sim/multiplay/generic/int[14]", simgear::props::INT},
236 {10315, "sim/multiplay/generic/int[15]", simgear::props::INT},
237 {10316, "sim/multiplay/generic/int[16]", simgear::props::INT},
238 {10317, "sim/multiplay/generic/int[17]", simgear::props::INT},
239 {10318, "sim/multiplay/generic/int[18]", simgear::props::INT},
240 {10319, "sim/multiplay/generic/int[19]", simgear::props::INT}
243 const unsigned int numProperties = (sizeof(sIdPropertyList)
244 / sizeof(sIdPropertyList[0]));
246 // Look up a property ID using binary search.
249 struct ComparePropertyId
251 bool operator()(const IdPropertyList& lhs,
252 const IdPropertyList& rhs)
254 return lhs.id < rhs.id;
256 bool operator()(const IdPropertyList& lhs,
261 bool operator()(unsigned id,
262 const IdPropertyList& rhs)
269 const IdPropertyList* findProperty(unsigned id)
271 std::pair<const IdPropertyList*, const IdPropertyList*> result
272 = std::equal_range(sIdPropertyList, sIdPropertyList + numProperties, id,
273 ComparePropertyId());
274 if (result.first == result.second) {
283 bool verifyProperties(const xdr_data_t* data, const xdr_data_t* end)
285 using namespace simgear;
286 const xdr_data_t* xdr = data;
288 unsigned id = XDR_decode_uint32(*xdr);
289 const IdPropertyList* plist = findProperty(id);
293 // How we decode the remainder of the property depends on the type
294 switch (plist->type) {
303 float val = XDR_decode_float(*xdr);
304 if (SGMisc<float>::isNaN(val))
310 case props::UNSPECIFIED:
312 // String is complicated. It consists of
313 // The length of the string
315 // Padding to the nearest 4-bytes.
316 // XXX Yes, each byte is padded out to a word! Too late
318 uint32_t length = XDR_decode_uint32(*xdr);
320 // Old versions truncated the string but left the length
322 if (length > MAX_TEXT_SIZE)
323 length = MAX_TEXT_SIZE;
325 // Now handle the padding
326 while ((length % 4) != 0)
335 // cerr << "Unknown Prop type " << id << " " << type << "\n";
341 // give up; this is a malformed property list.
349 class MPPropertyListener : public SGPropertyChangeListener
352 MPPropertyListener(FGMultiplayMgr* mp) :
357 virtual void childAdded(SGPropertyNode*, SGPropertyNode*)
359 _multiplay->setPropertiesChanged();
363 FGMultiplayMgr* _multiplay;
366 //////////////////////////////////////////////////////////////////////
368 // MultiplayMgr constructor
370 //////////////////////////////////////////////////////////////////////
371 FGMultiplayMgr::FGMultiplayMgr()
373 mInitialised = false;
376 } // FGMultiplayMgr::FGMultiplayMgr()
377 //////////////////////////////////////////////////////////////////////
379 //////////////////////////////////////////////////////////////////////
381 // MultiplayMgr destructor
383 //////////////////////////////////////////////////////////////////////
384 FGMultiplayMgr::~FGMultiplayMgr()
387 } // FGMultiplayMgr::~FGMultiplayMgr()
388 //////////////////////////////////////////////////////////////////////
390 //////////////////////////////////////////////////////////////////////
394 //////////////////////////////////////////////////////////////////////
396 FGMultiplayMgr::init (void)
398 //////////////////////////////////////////////////
399 // Initialise object if not already done
400 //////////////////////////////////////////////////
402 SG_LOG(SG_NETWORK, SG_WARN, "FGMultiplayMgr::init - already initialised");
406 SGPropertyNode* propOnline = fgGetNode("/sim/multiplay/online", true);
407 propOnline->setBoolValue(false);
408 propOnline->setAttribute(SGPropertyNode::PRESERVE, true);
410 //////////////////////////////////////////////////
411 // Set members from property values
412 //////////////////////////////////////////////////
413 short rxPort = fgGetInt("/sim/multiplay/rxport");
414 string rxAddress = fgGetString("/sim/multiplay/rxhost");
415 short txPort = fgGetInt("/sim/multiplay/txport", 5000);
416 string txAddress = fgGetString("/sim/multiplay/txhost");
418 int hz = fgGetInt("/sim/multiplay/tx-rate-hz", 10);
424 mTimeUntilSend = 0.0;
426 mCallsign = fgGetString("/sim/multiplay/callsign");
427 if ((!txAddress.empty()) && (txAddress!="0")) {
428 mServer.set(txAddress.c_str(), txPort);
429 if (strncmp (mServer.getHost(), "0.0.0.0", 8) == 0) {
431 SG_LOG(SG_NETWORK, SG_ALERT,
432 "Cannot enable multiplayer mode: resolving MP server address '"
433 << txAddress << "' failed.");
436 SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - have server");
442 SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - multiplayer mode disabled (no MP server specificed).");
447 SG_LOG(SG_NETWORK, SG_ALERT,
448 "Cannot enable multiplayer mode: No receiver port specified.");
451 if (mCallsign.empty())
452 mCallsign = "JohnDoe"; // FIXME: use getpwuid
453 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-txaddress= "<<txAddress);
454 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-txport= "<<txPort );
455 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-rxaddress="<<rxAddress );
456 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-rxport= "<<rxPort);
457 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-callsign= "<<mCallsign);
459 mSocket.reset(new simgear::Socket());
460 if (!mSocket->open(false)) {
461 SG_LOG( SG_NETWORK, SG_ALERT,
462 "Cannot enable multiplayer mode: creating data socket failed." );
465 mSocket->setBlocking(false);
466 if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) {
467 SG_LOG( SG_NETWORK, SG_ALERT,
468 "Cannot enable multiplayer mode: binding receive socket failed. "
469 << strerror(errno) << "(errno " << errno << ")");
473 mPropertiesChanged = true;
474 mListener = new MPPropertyListener(this);
475 globals->get_props()->addChangeListener(mListener, false);
477 fgSetBool("/sim/multiplay/online", true);
480 SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer mode active!");
482 if (!fgGetBool("/sim/ai/enabled"))
484 // multiplayer depends on AI module
485 fgSetBool("/sim/ai/enabled", true);
487 } // FGMultiplayMgr::init()
488 //////////////////////////////////////////////////////////////////////
490 //////////////////////////////////////////////////////////////////////
492 // Closes and deletes the local player object. Closes
493 // and deletes the tx socket. Resets the object state to unitialised.
495 //////////////////////////////////////////////////////////////////////
497 FGMultiplayMgr::shutdown (void)
499 fgSetBool("/sim/multiplay/online", false);
506 MultiPlayerMap::iterator it = mMultiPlayerMap.begin(),
507 end = mMultiPlayerMap.end();
508 for (; it != end; ++it) {
509 it->second->setDie(true);
511 mMultiPlayerMap.clear();
514 globals->get_props()->removeChangeListener(mListener);
519 mInitialised = false;
520 } // FGMultiplayMgr::Close(void)
521 //////////////////////////////////////////////////////////////////////
524 FGMultiplayMgr::reinit()
530 //////////////////////////////////////////////////////////////////////
532 // Description: Sends the position data for the local position.
534 //////////////////////////////////////////////////////////////////////
537 * The buffer that holds a multi-player message, suitably aligned.
539 union FGMultiplayMgr::MsgBuf
543 memset(&Msg, 0, sizeof(Msg));
551 const T_MsgHdr* msgHdr() const
553 return reinterpret_cast<const T_MsgHdr*>(&Header);
556 T_PositionMsg* posMsg()
558 return reinterpret_cast<T_PositionMsg*>(Msg + sizeof(T_MsgHdr));
561 const T_PositionMsg* posMsg() const
563 return reinterpret_cast<const T_PositionMsg*>(Msg + sizeof(T_MsgHdr));
566 xdr_data_t* properties()
568 return reinterpret_cast<xdr_data_t*>(Msg + sizeof(T_MsgHdr)
569 + sizeof(T_PositionMsg));
572 const xdr_data_t* properties() const
574 return reinterpret_cast<const xdr_data_t*>(Msg + sizeof(T_MsgHdr)
575 + sizeof(T_PositionMsg));
578 * The end of the properties buffer.
580 xdr_data_t* propsEnd()
582 return reinterpret_cast<xdr_data_t*>(Msg + MAX_PACKET_SIZE);
585 const xdr_data_t* propsEnd() const
587 return reinterpret_cast<const xdr_data_t*>(Msg + MAX_PACKET_SIZE);
590 * The end of properties actually in the buffer. This assumes that
591 * the message header is valid.
593 xdr_data_t* propsRecvdEnd()
595 return reinterpret_cast<xdr_data_t*>(Msg + Header.MsgLen);
598 const xdr_data_t* propsRecvdEnd() const
600 return reinterpret_cast<const xdr_data_t*>(Msg + Header.MsgLen);
603 xdr_data2_t double_val;
604 char Msg[MAX_PACKET_SIZE];
609 FGMultiplayMgr::isSane(const FGExternalMotionData& motionInfo)
611 // check for corrupted data (NaNs)
612 bool isCorrupted = false;
613 isCorrupted |= ((SGMisc<double>::isNaN(motionInfo.time )) ||
614 (SGMisc<double>::isNaN(motionInfo.lag )) ||
615 (osg::isNaN(motionInfo.orientation(3) )));
616 for (unsigned i = 0; (i < 3)&&(!isCorrupted); ++i)
618 isCorrupted |= ((osg::isNaN(motionInfo.position(i) ))||
619 (osg::isNaN(motionInfo.orientation(i) ))||
620 (osg::isNaN(motionInfo.linearVel(i)) )||
621 (osg::isNaN(motionInfo.angularVel(i)) )||
622 (osg::isNaN(motionInfo.linearAccel(i)) )||
623 (osg::isNaN(motionInfo.angularAccel(i)) ));
629 FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
631 if ((! mInitialised) || (! mHaveServer))
635 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition - no server");
639 if (!isSane(motionInfo))
641 // Current local data is invalid (NaN), so stop MP transmission.
642 // => Be nice to older FG versions (no NaN checks) and don't waste bandwidth.
643 SG_LOG(SG_NETWORK, SG_ALERT, "FGMultiplayMgr::SendMyPosition - "
644 << "Local data is invalid (NaN). Data not transmitted.");
648 static MsgBuf msgBuf;
649 static unsigned msgLen = 0;
650 T_PositionMsg* PosMsg = msgBuf.posMsg();
652 strncpy(PosMsg->Model, fgGetString("/sim/model/path"), MAX_MODEL_NAME_LEN);
653 PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0';
654 if (fgGetBool("/sim/freeze/replay-state", true)&&
655 fgGetBool("/sim/multiplay/freeze-on-replay",true))
657 // do not send position updates during replay
658 for (unsigned i = 0 ; i < 3; ++i)
660 // no movement during replay
661 PosMsg->linearVel[i] = XDR_encode_float (0.0);
662 PosMsg->angularVel[i] = XDR_encode_float (0.0);
663 PosMsg->linearAccel[i] = XDR_encode_float (0.0);
664 PosMsg->angularAccel[i] = XDR_encode_float (0.0);
666 // all other data remains unchanged (resend last state)
670 PosMsg->time = XDR_encode_double (motionInfo.time);
671 PosMsg->lag = XDR_encode_double (motionInfo.lag);
672 for (unsigned i = 0 ; i < 3; ++i)
673 PosMsg->position[i] = XDR_encode_double (motionInfo.position(i));
675 motionInfo.orientation.getAngleAxis(angleAxis);
676 for (unsigned i = 0 ; i < 3; ++i)
677 PosMsg->orientation[i] = XDR_encode_float (angleAxis(i));
678 for (unsigned i = 0 ; i < 3; ++i)
679 PosMsg->linearVel[i] = XDR_encode_float (motionInfo.linearVel(i));
680 for (unsigned i = 0 ; i < 3; ++i)
681 PosMsg->angularVel[i] = XDR_encode_float (motionInfo.angularVel(i));
682 for (unsigned i = 0 ; i < 3; ++i)
683 PosMsg->linearAccel[i] = XDR_encode_float (motionInfo.linearAccel(i));
684 for (unsigned i = 0 ; i < 3; ++i)
685 PosMsg->angularAccel[i] = XDR_encode_float (motionInfo.angularAccel(i));
687 xdr_data_t* ptr = msgBuf.properties();
688 std::vector<FGPropertyData*>::const_iterator it;
689 it = motionInfo.properties.begin();
690 //cout << "OUTPUT PROPERTIES\n";
691 xdr_data_t* msgEnd = msgBuf.propsEnd();
692 while (it != motionInfo.properties.end() && ptr + 2 < msgEnd) {
694 // First element is the ID. Write it out when we know we have room for
695 // the whole property.
696 xdr_data_t id = XDR_encode_uint32((*it)->id);
697 // The actual data representation depends on the type
698 switch ((*it)->type) {
699 case simgear::props::INT:
700 case simgear::props::BOOL:
701 case simgear::props::LONG:
703 *ptr++ = XDR_encode_uint32((*it)->int_value);
704 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->int_value << "\n";
706 case simgear::props::FLOAT:
707 case simgear::props::DOUBLE:
709 *ptr++ = XDR_encode_float((*it)->float_value);
710 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->float_value << "\n";
712 case simgear::props::STRING:
713 case simgear::props::UNSPECIFIED:
715 // String is complicated. It consists of
716 // The length of the string
718 // Padding to the nearest 4-bytes.
719 const char* lcharptr = (*it)->string_value;
724 ////cout << "String length: " << strlen(lcharptr) << "\n";
725 uint32_t len = strlen(lcharptr);
726 if (len > MAX_TEXT_SIZE)
728 // XXX This should not be using 4 bytes per character!
729 // If there's not enough room for this property, drop it
731 if (ptr + 2 + ((len + 3) & ~3) > msgEnd)
733 //cout << "String length unint32: " << len << "\n";
735 *ptr++ = XDR_encode_uint32(len);
738 // Now the text itself
739 // XXX This should not be using 4 bytes per character!
741 while ((*lcharptr != '\0') && (lcount < MAX_TEXT_SIZE))
743 *ptr++ = XDR_encode_int8(*lcharptr);
748 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " " << len << " " << (*it)->string_value;
750 // Now pad if required
751 while ((lcount % 4) != 0)
753 *ptr++ = XDR_encode_int8(0);
765 *ptr++ = XDR_encode_uint32(0);
766 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " 0\n";
772 //cout << " Unknown Type: " << (*it)->type << "\n";
774 *ptr++ = XDR_encode_float((*it)->float_value);;
775 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->float_value << "\n";
782 msgLen = reinterpret_cast<char*>(ptr) - msgBuf.Msg;
783 FillMsgHdr(msgBuf.msgHdr(), POS_DATA_ID, msgLen);
786 mSocket->sendto(msgBuf.Msg, msgLen, 0, &mServer);
787 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition");
788 } // FGMultiplayMgr::SendMyPosition()
790 //////////////////////////////////////////////////////////////////////
792 //////////////////////////////////////////////////////////////////////
794 // Name: SendTextMessage
795 // Description: Sends a message to the player. The message must
796 // contain a valid and correctly filled out header and optional
799 //////////////////////////////////////////////////////////////////////
801 FGMultiplayMgr::SendTextMessage(const string &MsgText)
803 if (!mInitialised || !mHaveServer)
807 FillMsgHdr(&MsgHdr, CHAT_MSG_ID);
808 //////////////////////////////////////////////////
809 // Divide the text string into blocks that fit
810 // in the message and send the blocks.
811 //////////////////////////////////////////////////
812 unsigned iNextBlockPosition = 0;
815 char Msg[sizeof(T_MsgHdr) + sizeof(T_ChatMsg)];
816 while (iNextBlockPosition < MsgText.length()) {
817 strncpy (ChatMsg.Text,
818 MsgText.substr(iNextBlockPosition, MAX_CHAT_MSG_LEN - 1).c_str(),
820 ChatMsg.Text[MAX_CHAT_MSG_LEN - 1] = '\0';
821 memcpy (Msg, &MsgHdr, sizeof(T_MsgHdr));
822 memcpy (Msg + sizeof(T_MsgHdr), &ChatMsg, sizeof(T_ChatMsg));
823 mSocket->sendto (Msg, sizeof(T_MsgHdr) + sizeof(T_ChatMsg), 0, &mServer);
824 iNextBlockPosition += MAX_CHAT_MSG_LEN - 1;
829 } // FGMultiplayMgr::SendTextMessage ()
830 //////////////////////////////////////////////////////////////////////
832 //////////////////////////////////////////////////////////////////////
835 // Description: Processes data waiting at the receive socket. The
836 // processing ends when there is no more data at the socket.
838 //////////////////////////////////////////////////////////////////////
840 FGMultiplayMgr::update(double dt)
846 long stamp = SGTimeStamp::now().getSeconds();
848 //////////////////////////////////////////////////
850 //////////////////////////////////////////////////
851 mTimeUntilSend -= dt;
852 if (mTimeUntilSend <= 0.0) {
856 //////////////////////////////////////////////////
857 // Read the receive socket and process any data
858 //////////////////////////////////////////////////
862 //////////////////////////////////////////////////
863 // Although the recv call asks for
864 // MAX_PACKET_SIZE of data, the number of bytes
865 // returned will only be that of the next
866 // packet waiting to be processed.
867 //////////////////////////////////////////////////
868 simgear::IPAddress SenderAddress;
869 int RecvStatus = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
871 //////////////////////////////////////////////////
873 //////////////////////////////////////////////////
877 // socket error reported?
878 // errno isn't thread-safe - so only check its value when
879 // socket return status < 0 really indicates a failure.
880 if ((RecvStatus < 0)&&
881 ((errno == EAGAIN) || (errno == 0))) // MSVC output "NoError" otherwise
883 // ignore "normal" errors
889 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - Unable to receive data. "
890 << strerror(errno) << "(errno " << errno << ")");
894 // status is positive: bytes received
895 bytes = (ssize_t) RecvStatus;
896 if (bytes <= static_cast<ssize_t>(sizeof(T_MsgHdr))) {
897 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
898 << "received message with insufficient data" );
901 //////////////////////////////////////////////////
903 //////////////////////////////////////////////////
904 T_MsgHdr* MsgHdr = msgBuf.msgHdr();
905 MsgHdr->Magic = XDR_decode_uint32 (MsgHdr->Magic);
906 MsgHdr->Version = XDR_decode_uint32 (MsgHdr->Version);
907 MsgHdr->MsgId = XDR_decode_uint32 (MsgHdr->MsgId);
908 MsgHdr->MsgLen = XDR_decode_uint32 (MsgHdr->MsgLen);
909 MsgHdr->ReplyPort = XDR_decode_uint32 (MsgHdr->ReplyPort);
910 MsgHdr->Callsign[MAX_CALLSIGN_LEN -1] = '\0';
911 if (MsgHdr->Magic != MSG_MAGIC) {
912 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
913 << "message has invalid magic number!" );
916 if (MsgHdr->Version != PROTO_VER) {
917 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
918 << "message has invalid protocol number!" );
921 if (static_cast<ssize_t>(MsgHdr->MsgLen) != bytes) {
922 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
923 << "message from " << MsgHdr->Callsign << " has invalid length!");
926 //////////////////////////////////////////////////
928 //////////////////////////////////////////////////
929 switch (MsgHdr->MsgId) {
931 ProcessChatMsg(msgBuf, SenderAddress);
934 ProcessPosMsg(msgBuf, SenderAddress, stamp);
936 case UNUSABLE_POS_DATA_ID:
937 case OLD_OLD_POS_DATA_ID:
938 case OLD_PROP_MSG_ID:
939 case OLD_POS_DATA_ID:
942 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
943 << "Unknown message Id received: " << MsgHdr->MsgId );
949 MultiPlayerMap::iterator it = mMultiPlayerMap.begin();
950 while (it != mMultiPlayerMap.end()) {
951 if (it->second->getLastTimestamp() + 10 < stamp) {
952 std::string name = it->first;
953 it->second->setDie(true);
954 mMultiPlayerMap.erase(it);
955 it = mMultiPlayerMap.upper_bound(name);
959 } // FGMultiplayMgr::ProcessData(void)
960 //////////////////////////////////////////////////////////////////////
963 FGMultiplayMgr::Send()
965 using namespace simgear;
969 // smooth the send rate, by adjusting based on the 'remainder' time, which
970 // is how -ve mTimeUntilSend is. Watch for large values and ignore them,
972 if ((mTimeUntilSend < 0.0) && (fabs(mTimeUntilSend) < mDt)) {
973 mTimeUntilSend = mDt + mTimeUntilSend;
975 mTimeUntilSend = mDt;
978 double sim_time = globals->get_sim_time_sec();
979 // static double lastTime = 0.0;
981 // SG_LOG(SG_GENERAL, SG_INFO, "actual dt=" << sim_time - lastTime);
982 // lastTime = sim_time;
984 FlightProperties ifce;
986 // put together a motion info struct, you will get that later
987 // from FGInterface directly ...
988 FGExternalMotionData motionInfo;
990 // The current simulation time we need to update for,
991 // note that the simulation time is updated before calling all the
992 // update methods. Thus it contains the time intervals *end* time.
993 // The FDM is already run, so the states belong to that time.
994 motionInfo.time = sim_time;
995 motionInfo.lag = mDt;
997 // These are for now converted from lat/lon/alt and euler angles.
998 // But this should change in FGInterface ...
999 double lon = ifce.get_Longitude();
1000 double lat = ifce.get_Latitude();
1001 // first the aprioriate structure for the geodetic one
1002 SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce.get_Altitude());
1003 // Convert to cartesion coordinate
1004 motionInfo.position = SGVec3d::fromGeod(geod);
1006 // The quaternion rotating from the earth centered frame to the
1007 // horizontal local frame
1008 SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)lon, (float)lat);
1009 // The orientation wrt the horizontal local frame
1010 float heading = ifce.get_Psi();
1011 float pitch = ifce.get_Theta();
1012 float roll = ifce.get_Phi();
1013 SGQuatf hlOr = SGQuatf::fromYawPitchRoll(heading, pitch, roll);
1014 // The orientation of the vehicle wrt the earth centered frame
1015 motionInfo.orientation = qEc2Hl*hlOr;
1017 if (!globals->get_subsystem("flight")->is_suspended()) {
1019 motionInfo.linearVel = SG_FEET_TO_METER*SGVec3f(ifce.get_uBody(),
1022 motionInfo.angularVel = SGVec3f(ifce.get_P_body(),
1026 // accels, set that to zero for now.
1027 // Angular accelerations are missing from the interface anyway,
1028 // linear accelerations are screwed up at least for JSBSim.
1029 // motionInfo.linearAccel = SG_FEET_TO_METER*SGVec3f(ifce.get_U_dot_body(),
1030 // ifce.get_V_dot_body(),
1031 // ifce.get_W_dot_body());
1032 motionInfo.linearAccel = SGVec3f::zeros();
1033 motionInfo.angularAccel = SGVec3f::zeros();
1035 // if the interface is suspendend, prevent the client from
1036 // wild extrapolations
1037 motionInfo.linearVel = SGVec3f::zeros();
1038 motionInfo.angularVel = SGVec3f::zeros();
1039 motionInfo.linearAccel = SGVec3f::zeros();
1040 motionInfo.angularAccel = SGVec3f::zeros();
1043 // now send the properties
1044 PropertyMap::iterator it;
1045 for (it = mPropertyMap.begin(); it != mPropertyMap.end(); ++it) {
1046 FGPropertyData* pData = new FGPropertyData;
1047 pData->id = it->first;
1048 pData->type = it->second->getType();
1050 switch (pData->type) {
1054 pData->int_value = it->second->getIntValue();
1058 pData->float_value = it->second->getFloatValue();
1061 case props::UNSPECIFIED:
1063 // FIXME: We assume unspecified are strings for the moment.
1065 const char* cstr = it->second->getStringValue();
1066 int len = strlen(cstr);
1070 pData->string_value = new char[len + 1];
1071 strcpy(pData->string_value, cstr);
1076 pData->string_value = 0;
1079 //cout << " Sending property " << pData->id << " " << pData->type << " " << pData->string_value << "\n";
1083 // FIXME Currently default to a float.
1084 //cout << "Unknown type when iterating through props: " << pData->type << "\n";
1085 pData->float_value = it->second->getFloatValue();
1089 motionInfo.properties.push_back(pData);
1092 SendMyPosition(motionInfo);
1096 //////////////////////////////////////////////////////////////////////
1098 // handle a position message
1100 //////////////////////////////////////////////////////////////////////
1102 FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
1103 const simgear::IPAddress& SenderAddress, long stamp)
1105 const T_MsgHdr* MsgHdr = Msg.msgHdr();
1106 if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + sizeof(T_PositionMsg)) {
1107 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
1108 << "Position message received with insufficient data" );
1111 const T_PositionMsg* PosMsg = Msg.posMsg();
1112 FGExternalMotionData motionInfo;
1113 motionInfo.time = XDR_decode_double(PosMsg->time);
1114 motionInfo.lag = XDR_decode_double(PosMsg->lag);
1115 for (unsigned i = 0; i < 3; ++i)
1116 motionInfo.position(i) = XDR_decode_double(PosMsg->position[i]);
1118 for (unsigned i = 0; i < 3; ++i)
1119 angleAxis(i) = XDR_decode_float(PosMsg->orientation[i]);
1120 motionInfo.orientation = SGQuatf::fromAngleAxis(angleAxis);
1121 for (unsigned i = 0; i < 3; ++i)
1122 motionInfo.linearVel(i) = XDR_decode_float(PosMsg->linearVel[i]);
1123 for (unsigned i = 0; i < 3; ++i)
1124 motionInfo.angularVel(i) = XDR_decode_float(PosMsg->angularVel[i]);
1125 for (unsigned i = 0; i < 3; ++i)
1126 motionInfo.linearAccel(i) = XDR_decode_float(PosMsg->linearAccel[i]);
1127 for (unsigned i = 0; i < 3; ++i)
1128 motionInfo.angularAccel(i) = XDR_decode_float(PosMsg->angularAccel[i]);
1130 // sanity check: do not allow injection of corrupted data (NaNs)
1131 if (!isSane(motionInfo))
1133 // drop this message, keep old position until receiving valid data
1134 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::ProcessPosMsg - "
1135 << "Position message with invalid data (NaN) received from "
1136 << MsgHdr->Callsign);
1140 //cout << "INPUT MESSAGE\n";
1142 // There was a bug in 1.9.0 and before: T_PositionMsg was 196 bytes
1143 // on 32 bit architectures and 200 bytes on 64 bit, and this
1144 // structure is put directly on the wire. By looking at the padding,
1145 // we can sort through the mess, mostly:
1146 // If padding is 0 (which is not a valid property type), then the
1147 // message was produced by a new client or an old 64 bit client that
1148 // happened to have 0 on the stack;
1149 // Else if the property list starting with the padding word is
1150 // well-formed, then the client is probably an old 32 bit client and
1151 // we'll go with that;
1152 // Else it is an old 64-bit client and properties start after the
1154 // There is a chance that we could be fooled by garbage in the
1155 // padding looking like a valid property, so verifyProperties() is
1156 // strict about the validity of the property values.
1157 const xdr_data_t* xdr = Msg.properties();
1158 if (PosMsg->pad != 0) {
1159 if (verifyProperties(&PosMsg->pad, Msg.propsRecvdEnd()))
1161 else if (!verifyProperties(xdr, Msg.propsRecvdEnd()))
1164 while (xdr < Msg.propsRecvdEnd()) {
1165 // simgear::props::Type type = simgear::props::UNSPECIFIED;
1167 // First element is always the ID
1168 unsigned id = XDR_decode_uint32(*xdr);
1169 //cout << pData->id << " ";
1172 // Check the ID actually exists and get the type
1173 const IdPropertyList* plist = findProperty(id);
1177 FGPropertyData* pData = new FGPropertyData;
1179 pData->type = plist->type;
1180 // How we decode the remainder of the property depends on the type
1181 switch (pData->type) {
1182 case simgear::props::INT:
1183 case simgear::props::BOOL:
1184 case simgear::props::LONG:
1185 pData->int_value = XDR_decode_uint32(*xdr);
1187 //cout << pData->int_value << "\n";
1189 case simgear::props::FLOAT:
1190 case simgear::props::DOUBLE:
1191 pData->float_value = XDR_decode_float(*xdr);
1193 //cout << pData->float_value << "\n";
1195 case simgear::props::STRING:
1196 case simgear::props::UNSPECIFIED:
1198 // String is complicated. It consists of
1199 // The length of the string
1200 // The string itself
1201 // Padding to the nearest 4-bytes.
1202 uint32_t length = XDR_decode_uint32(*xdr);
1204 //cout << length << " ";
1205 // Old versions truncated the string but left the length unadjusted.
1206 if (length > MAX_TEXT_SIZE)
1207 length = MAX_TEXT_SIZE;
1208 pData->string_value = new char[length + 1];
1209 //cout << " String: ";
1210 for (unsigned i = 0; i < length; i++)
1212 pData->string_value[i] = (char) XDR_decode_int8(*xdr);
1214 //cout << pData->string_value[i];
1217 pData->string_value[length] = '\0';
1219 // Now handle the padding
1220 while ((length % 4) != 0)
1231 pData->float_value = XDR_decode_float(*xdr);
1232 SG_LOG(SG_NETWORK, SG_DEBUG, "Unknown Prop type " << pData->id << " " << pData->type);
1237 motionInfo.properties.push_back(pData);
1241 // We failed to find the property. We'll try the next packet immediately.
1242 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::ProcessPosMsg - "
1243 "message from " << MsgHdr->Callsign << " has unknown property id "
1248 FGAIMultiplayer* mp = getMultiplayer(MsgHdr->Callsign);
1250 mp = addMultiplayer(MsgHdr->Callsign, PosMsg->Model);
1251 mp->addMotionInfo(motionInfo, stamp);
1252 } // FGMultiplayMgr::ProcessPosMsg()
1253 //////////////////////////////////////////////////////////////////////
1255 //////////////////////////////////////////////////////////////////////
1257 // handle a chat message
1258 // FIXME: display chat message within flightgear
1260 //////////////////////////////////////////////////////////////////////
1262 FGMultiplayMgr::ProcessChatMsg(const MsgBuf& Msg,
1263 const simgear::IPAddress& SenderAddress)
1265 const T_MsgHdr* MsgHdr = Msg.msgHdr();
1266 if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + 1) {
1267 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
1268 << "Chat message received with insufficient data" );
1272 char *chatStr = new char[MsgHdr->MsgLen - sizeof(T_MsgHdr)];
1273 const T_ChatMsg* ChatMsg
1274 = reinterpret_cast<const T_ChatMsg *>(Msg.Msg + sizeof(T_MsgHdr));
1275 strncpy(chatStr, ChatMsg->Text,
1276 MsgHdr->MsgLen - sizeof(T_MsgHdr));
1277 chatStr[MsgHdr->MsgLen - sizeof(T_MsgHdr) - 1] = '\0';
1279 SG_LOG (SG_NETWORK, SG_WARN, "Chat [" << MsgHdr->Callsign << "]"
1283 } // FGMultiplayMgr::ProcessChatMsg ()
1284 //////////////////////////////////////////////////////////////////////
1287 FGMultiplayMgr::FillMsgHdr(T_MsgHdr *MsgHdr, int MsgId, unsigned _len)
1292 len = sizeof(T_MsgHdr) + sizeof(T_ChatMsg);
1298 len = sizeof(T_MsgHdr);
1301 MsgHdr->Magic = XDR_encode_uint32(MSG_MAGIC);
1302 MsgHdr->Version = XDR_encode_uint32(PROTO_VER);
1303 MsgHdr->MsgId = XDR_encode_uint32(MsgId);
1304 MsgHdr->MsgLen = XDR_encode_uint32(len);
1305 MsgHdr->ReplyAddress = 0; // Are obsolete, keep them for the server for
1306 MsgHdr->ReplyPort = 0; // now
1307 strncpy(MsgHdr->Callsign, mCallsign.c_str(), MAX_CALLSIGN_LEN);
1308 MsgHdr->Callsign[MAX_CALLSIGN_LEN - 1] = '\0';
1312 FGMultiplayMgr::addMultiplayer(const std::string& callsign,
1313 const std::string& modelName)
1315 if (0 < mMultiPlayerMap.count(callsign))
1316 return mMultiPlayerMap[callsign].get();
1318 FGAIMultiplayer* mp = new FGAIMultiplayer;
1319 mp->setPath(modelName.c_str());
1320 mp->setCallSign(callsign);
1321 mMultiPlayerMap[callsign] = mp;
1323 FGAIManager *aiMgr = (FGAIManager*)globals->get_subsystem("ai-model");
1327 /// FIXME: that must follow the attach ATM ...
1328 for (unsigned i = 0; i < numProperties; ++i)
1329 mp->addPropertyId(sIdPropertyList[i].id, sIdPropertyList[i].name);
1336 FGMultiplayMgr::getMultiplayer(const std::string& callsign)
1338 if (0 < mMultiPlayerMap.count(callsign))
1339 return mMultiPlayerMap[callsign].get();
1345 FGMultiplayMgr::findProperties()
1347 if (!mPropertiesChanged) {
1351 mPropertiesChanged = false;
1353 for (unsigned i = 0; i < numProperties; ++i) {
1354 const char* name = sIdPropertyList[i].name;
1355 SGPropertyNode* pNode = globals->get_props()->getNode(name);
1360 int id = sIdPropertyList[i].id;
1361 if (mPropertyMap.find(id) != mPropertyMap.end()) {
1362 continue; // already activated
1365 mPropertyMap[id] = pNode;
1366 SG_LOG(SG_NETWORK, SG_DEBUG, "activating MP property:" << pNode->getPath());