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 //////////////////////////////////////////////////////////////////////
38 #include <osg/Math> // isNaN
40 #include <simgear/misc/stdint.hxx>
41 #include <simgear/timing/timestamp.hxx>
42 #include <simgear/debug/logstream.hxx>
43 #include <simgear/props/props.hxx>
45 #include <AIModel/AIManager.hxx>
46 #include <AIModel/AIMultiplayer.hxx>
47 #include <Main/fg_props.hxx>
48 #include "multiplaymgr.hxx"
49 #include "mpmessages.hxx"
50 #include <FDM/flightProperties.hxx>
54 #define MAX_PACKET_SIZE 1200
55 #define MAX_TEXT_SIZE 128
57 // These constants are provided so that the ident
58 // command can list file versions
59 const char sMULTIPLAYMGR_BID[] = "$Id$";
60 const char sMULTIPLAYMGR_HID[] = MULTIPLAYTXMGR_HID;
62 struct IdPropertyList {
65 simgear::props::Type type;
68 static const IdPropertyList* findProperty(unsigned id);
70 // A static map of protocol property id values to property paths,
71 // This should be extendable dynamically for every specific aircraft ...
72 // For now only that static list
73 static const IdPropertyList sIdPropertyList[] = {
74 {100, "surface-positions/left-aileron-pos-norm", simgear::props::FLOAT},
75 {101, "surface-positions/right-aileron-pos-norm", simgear::props::FLOAT},
76 {102, "surface-positions/elevator-pos-norm", simgear::props::FLOAT},
77 {103, "surface-positions/rudder-pos-norm", simgear::props::FLOAT},
78 {104, "surface-positions/flap-pos-norm", simgear::props::FLOAT},
79 {105, "surface-positions/speedbrake-pos-norm", simgear::props::FLOAT},
80 {106, "gear/tailhook/position-norm", simgear::props::FLOAT},
81 {107, "gear/launchbar/position-norm", simgear::props::FLOAT},
82 {108, "gear/launchbar/state", simgear::props::STRING},
83 {109, "gear/launchbar/holdback-position-norm", simgear::props::FLOAT},
84 {110, "canopy/position-norm", simgear::props::FLOAT},
85 {111, "surface-positions/wing-pos-norm", simgear::props::FLOAT},
86 {112, "surface-positions/wing-fold-pos-norm", simgear::props::FLOAT},
88 {200, "gear/gear[0]/compression-norm", simgear::props::FLOAT},
89 {201, "gear/gear[0]/position-norm", simgear::props::FLOAT},
90 {210, "gear/gear[1]/compression-norm", simgear::props::FLOAT},
91 {211, "gear/gear[1]/position-norm", simgear::props::FLOAT},
92 {220, "gear/gear[2]/compression-norm", simgear::props::FLOAT},
93 {221, "gear/gear[2]/position-norm", simgear::props::FLOAT},
94 {230, "gear/gear[3]/compression-norm", simgear::props::FLOAT},
95 {231, "gear/gear[3]/position-norm", simgear::props::FLOAT},
96 {240, "gear/gear[4]/compression-norm", simgear::props::FLOAT},
97 {241, "gear/gear[4]/position-norm", simgear::props::FLOAT},
99 {300, "engines/engine[0]/n1", simgear::props::FLOAT},
100 {301, "engines/engine[0]/n2", simgear::props::FLOAT},
101 {302, "engines/engine[0]/rpm", simgear::props::FLOAT},
102 {310, "engines/engine[1]/n1", simgear::props::FLOAT},
103 {311, "engines/engine[1]/n2", simgear::props::FLOAT},
104 {312, "engines/engine[1]/rpm", simgear::props::FLOAT},
105 {320, "engines/engine[2]/n1", simgear::props::FLOAT},
106 {321, "engines/engine[2]/n2", simgear::props::FLOAT},
107 {322, "engines/engine[2]/rpm", simgear::props::FLOAT},
108 {330, "engines/engine[3]/n1", simgear::props::FLOAT},
109 {331, "engines/engine[3]/n2", simgear::props::FLOAT},
110 {332, "engines/engine[3]/rpm", simgear::props::FLOAT},
111 {340, "engines/engine[4]/n1", simgear::props::FLOAT},
112 {341, "engines/engine[4]/n2", simgear::props::FLOAT},
113 {342, "engines/engine[4]/rpm", simgear::props::FLOAT},
114 {350, "engines/engine[5]/n1", simgear::props::FLOAT},
115 {351, "engines/engine[5]/n2", simgear::props::FLOAT},
116 {352, "engines/engine[5]/rpm", simgear::props::FLOAT},
117 {360, "engines/engine[6]/n1", simgear::props::FLOAT},
118 {361, "engines/engine[6]/n2", simgear::props::FLOAT},
119 {362, "engines/engine[6]/rpm", simgear::props::FLOAT},
120 {370, "engines/engine[7]/n1", simgear::props::FLOAT},
121 {371, "engines/engine[7]/n2", simgear::props::FLOAT},
122 {372, "engines/engine[7]/rpm", simgear::props::FLOAT},
123 {380, "engines/engine[8]/n1", simgear::props::FLOAT},
124 {381, "engines/engine[8]/n2", simgear::props::FLOAT},
125 {382, "engines/engine[8]/rpm", simgear::props::FLOAT},
126 {390, "engines/engine[9]/n1", simgear::props::FLOAT},
127 {391, "engines/engine[9]/n2", simgear::props::FLOAT},
128 {392, "engines/engine[9]/rpm", simgear::props::FLOAT},
130 {800, "rotors/main/rpm", simgear::props::FLOAT},
131 {801, "rotors/tail/rpm", simgear::props::FLOAT},
132 {810, "rotors/main/blade[0]/position-deg", simgear::props::FLOAT},
133 {811, "rotors/main/blade[1]/position-deg", simgear::props::FLOAT},
134 {812, "rotors/main/blade[2]/position-deg", simgear::props::FLOAT},
135 {813, "rotors/main/blade[3]/position-deg", simgear::props::FLOAT},
136 {820, "rotors/main/blade[0]/flap-deg", simgear::props::FLOAT},
137 {821, "rotors/main/blade[1]/flap-deg", simgear::props::FLOAT},
138 {822, "rotors/main/blade[2]/flap-deg", simgear::props::FLOAT},
139 {823, "rotors/main/blade[3]/flap-deg", simgear::props::FLOAT},
140 {830, "rotors/tail/blade[0]/position-deg", simgear::props::FLOAT},
141 {831, "rotors/tail/blade[1]/position-deg", simgear::props::FLOAT},
143 {900, "sim/hitches/aerotow/tow/length", simgear::props::FLOAT},
144 {901, "sim/hitches/aerotow/tow/elastic-constant", simgear::props::FLOAT},
145 {902, "sim/hitches/aerotow/tow/weight-per-m-kg-m", simgear::props::FLOAT},
146 {903, "sim/hitches/aerotow/tow/dist", simgear::props::FLOAT},
147 {904, "sim/hitches/aerotow/tow/connected-to-property-node", simgear::props::BOOL},
148 {905, "sim/hitches/aerotow/tow/connected-to-ai-or-mp-callsign", simgear::props::STRING},
149 {906, "sim/hitches/aerotow/tow/brake-force", simgear::props::FLOAT},
150 {907, "sim/hitches/aerotow/tow/end-force-x", simgear::props::FLOAT},
151 {908, "sim/hitches/aerotow/tow/end-force-y", simgear::props::FLOAT},
152 {909, "sim/hitches/aerotow/tow/end-force-z", simgear::props::FLOAT},
153 {930, "sim/hitches/aerotow/is-slave", simgear::props::BOOL},
154 {931, "sim/hitches/aerotow/speed-in-tow-direction", simgear::props::FLOAT},
155 {932, "sim/hitches/aerotow/open", simgear::props::BOOL},
156 {933, "sim/hitches/aerotow/local-pos-x", simgear::props::FLOAT},
157 {934, "sim/hitches/aerotow/local-pos-y", simgear::props::FLOAT},
158 {935, "sim/hitches/aerotow/local-pos-z", simgear::props::FLOAT},
160 {1001, "controls/flight/slats", simgear::props::FLOAT},
161 {1002, "controls/flight/speedbrake", simgear::props::FLOAT},
162 {1003, "controls/flight/spoilers", simgear::props::FLOAT},
163 {1004, "controls/gear/gear-down", simgear::props::FLOAT},
164 {1005, "controls/lighting/nav-lights", simgear::props::FLOAT},
165 {1006, "controls/armament/station[0]/jettison-all", simgear::props::BOOL},
167 {1100, "sim/model/variant", simgear::props::INT},
168 {1101, "sim/model/livery/file", simgear::props::STRING},
170 {1200, "environment/wildfire/data", simgear::props::STRING},
171 {1201, "environment/contrail", simgear::props::INT},
173 {1300, "tanker", simgear::props::INT},
175 {1400, "scenery/events", simgear::props::STRING},
177 {10001, "sim/multiplay/transmission-freq-hz", simgear::props::STRING},
178 {10002, "sim/multiplay/chat", simgear::props::STRING},
180 {10100, "sim/multiplay/generic/string[0]", simgear::props::STRING},
181 {10101, "sim/multiplay/generic/string[1]", simgear::props::STRING},
182 {10102, "sim/multiplay/generic/string[2]", simgear::props::STRING},
183 {10103, "sim/multiplay/generic/string[3]", simgear::props::STRING},
184 {10104, "sim/multiplay/generic/string[4]", simgear::props::STRING},
185 {10105, "sim/multiplay/generic/string[5]", simgear::props::STRING},
186 {10106, "sim/multiplay/generic/string[6]", simgear::props::STRING},
187 {10107, "sim/multiplay/generic/string[7]", simgear::props::STRING},
188 {10108, "sim/multiplay/generic/string[8]", simgear::props::STRING},
189 {10109, "sim/multiplay/generic/string[9]", simgear::props::STRING},
190 {10110, "sim/multiplay/generic/string[10]", simgear::props::STRING},
191 {10111, "sim/multiplay/generic/string[11]", simgear::props::STRING},
192 {10112, "sim/multiplay/generic/string[12]", simgear::props::STRING},
193 {10113, "sim/multiplay/generic/string[13]", simgear::props::STRING},
194 {10114, "sim/multiplay/generic/string[14]", simgear::props::STRING},
195 {10115, "sim/multiplay/generic/string[15]", simgear::props::STRING},
196 {10116, "sim/multiplay/generic/string[16]", simgear::props::STRING},
197 {10117, "sim/multiplay/generic/string[17]", simgear::props::STRING},
198 {10118, "sim/multiplay/generic/string[18]", simgear::props::STRING},
199 {10119, "sim/multiplay/generic/string[19]", simgear::props::STRING},
201 {10200, "sim/multiplay/generic/float[0]", simgear::props::FLOAT},
202 {10201, "sim/multiplay/generic/float[1]", simgear::props::FLOAT},
203 {10202, "sim/multiplay/generic/float[2]", simgear::props::FLOAT},
204 {10203, "sim/multiplay/generic/float[3]", simgear::props::FLOAT},
205 {10204, "sim/multiplay/generic/float[4]", simgear::props::FLOAT},
206 {10205, "sim/multiplay/generic/float[5]", simgear::props::FLOAT},
207 {10206, "sim/multiplay/generic/float[6]", simgear::props::FLOAT},
208 {10207, "sim/multiplay/generic/float[7]", simgear::props::FLOAT},
209 {10208, "sim/multiplay/generic/float[8]", simgear::props::FLOAT},
210 {10209, "sim/multiplay/generic/float[9]", simgear::props::FLOAT},
211 {10210, "sim/multiplay/generic/float[10]", simgear::props::FLOAT},
212 {10211, "sim/multiplay/generic/float[11]", simgear::props::FLOAT},
213 {10212, "sim/multiplay/generic/float[12]", simgear::props::FLOAT},
214 {10213, "sim/multiplay/generic/float[13]", simgear::props::FLOAT},
215 {10214, "sim/multiplay/generic/float[14]", simgear::props::FLOAT},
216 {10215, "sim/multiplay/generic/float[15]", simgear::props::FLOAT},
217 {10216, "sim/multiplay/generic/float[16]", simgear::props::FLOAT},
218 {10217, "sim/multiplay/generic/float[17]", simgear::props::FLOAT},
219 {10218, "sim/multiplay/generic/float[18]", simgear::props::FLOAT},
220 {10219, "sim/multiplay/generic/float[19]", simgear::props::FLOAT},
222 {10300, "sim/multiplay/generic/int[0]", simgear::props::INT},
223 {10301, "sim/multiplay/generic/int[1]", simgear::props::INT},
224 {10302, "sim/multiplay/generic/int[2]", simgear::props::INT},
225 {10303, "sim/multiplay/generic/int[3]", simgear::props::INT},
226 {10304, "sim/multiplay/generic/int[4]", simgear::props::INT},
227 {10305, "sim/multiplay/generic/int[5]", simgear::props::INT},
228 {10306, "sim/multiplay/generic/int[6]", simgear::props::INT},
229 {10307, "sim/multiplay/generic/int[7]", simgear::props::INT},
230 {10308, "sim/multiplay/generic/int[8]", simgear::props::INT},
231 {10309, "sim/multiplay/generic/int[9]", simgear::props::INT},
232 {10310, "sim/multiplay/generic/int[10]", simgear::props::INT},
233 {10311, "sim/multiplay/generic/int[11]", simgear::props::INT},
234 {10312, "sim/multiplay/generic/int[12]", simgear::props::INT},
235 {10313, "sim/multiplay/generic/int[13]", simgear::props::INT},
236 {10314, "sim/multiplay/generic/int[14]", simgear::props::INT},
237 {10315, "sim/multiplay/generic/int[15]", simgear::props::INT},
238 {10316, "sim/multiplay/generic/int[16]", simgear::props::INT},
239 {10317, "sim/multiplay/generic/int[17]", simgear::props::INT},
240 {10318, "sim/multiplay/generic/int[18]", simgear::props::INT},
241 {10319, "sim/multiplay/generic/int[19]", simgear::props::INT}
244 const unsigned int numProperties = (sizeof(sIdPropertyList)
245 / sizeof(sIdPropertyList[0]));
247 // Look up a property ID using binary search.
250 struct ComparePropertyId
252 bool operator()(const IdPropertyList& lhs,
253 const IdPropertyList& rhs)
255 return lhs.id < rhs.id;
257 bool operator()(const IdPropertyList& lhs,
262 bool operator()(unsigned id,
263 const IdPropertyList& rhs)
270 const IdPropertyList* findProperty(unsigned id)
272 std::pair<const IdPropertyList*, const IdPropertyList*> result
273 = std::equal_range(sIdPropertyList, sIdPropertyList + numProperties, id,
274 ComparePropertyId());
275 if (result.first == result.second) {
284 bool verifyProperties(const xdr_data_t* data, const xdr_data_t* end)
286 using namespace simgear;
287 const xdr_data_t* xdr = data;
289 unsigned id = XDR_decode_uint32(*xdr);
290 const IdPropertyList* plist = findProperty(id);
294 // How we decode the remainder of the property depends on the type
295 switch (plist->type) {
304 float val = XDR_decode_float(*xdr);
311 case props::UNSPECIFIED:
313 // String is complicated. It consists of
314 // The length of the string
316 // Padding to the nearest 4-bytes.
317 // XXX Yes, each byte is padded out to a word! Too late
319 uint32_t length = XDR_decode_uint32(*xdr);
321 // Old versions truncated the string but left the length
323 if (length > MAX_TEXT_SIZE)
324 length = MAX_TEXT_SIZE;
326 // Now handle the padding
327 while ((length % 4) != 0)
336 // cerr << "Unknown Prop type " << id << " " << type << "\n";
342 // give up; this is a malformed property list.
350 class MPPropertyListener : public SGPropertyChangeListener
353 MPPropertyListener(FGMultiplayMgr* mp) :
358 virtual void childAdded(SGPropertyNode*, SGPropertyNode*)
360 _multiplay->setPropertiesChanged();
364 FGMultiplayMgr* _multiplay;
367 //////////////////////////////////////////////////////////////////////
369 // MultiplayMgr constructor
371 //////////////////////////////////////////////////////////////////////
372 FGMultiplayMgr::FGMultiplayMgr()
374 mInitialised = false;
377 } // FGMultiplayMgr::FGMultiplayMgr()
378 //////////////////////////////////////////////////////////////////////
380 //////////////////////////////////////////////////////////////////////
382 // MultiplayMgr destructor
384 //////////////////////////////////////////////////////////////////////
385 FGMultiplayMgr::~FGMultiplayMgr()
388 } // FGMultiplayMgr::~FGMultiplayMgr()
389 //////////////////////////////////////////////////////////////////////
391 //////////////////////////////////////////////////////////////////////
395 //////////////////////////////////////////////////////////////////////
397 FGMultiplayMgr::init (void)
399 //////////////////////////////////////////////////
400 // Initialise object if not already done
401 //////////////////////////////////////////////////
403 SG_LOG(SG_NETWORK, SG_WARN, "FGMultiplayMgr::init - already initialised");
407 fgSetBool("/sim/multiplay/online", false);
409 //////////////////////////////////////////////////
410 // Set members from property values
411 //////////////////////////////////////////////////
412 short rxPort = fgGetInt("/sim/multiplay/rxport");
413 string rxAddress = fgGetString("/sim/multiplay/rxhost");
414 short txPort = fgGetInt("/sim/multiplay/txport", 5000);
415 string txAddress = fgGetString("/sim/multiplay/txhost");
417 int hz = fgGetInt("/sim/multiplay/tx-rate-hz", 10);
423 mTimeUntilSend = 0.0;
425 mCallsign = fgGetString("/sim/multiplay/callsign");
426 if ((!txAddress.empty()) && (txAddress!="0")) {
427 mServer.set(txAddress.c_str(), txPort);
428 if (strncmp (mServer.getHost(), "0.0.0.0", 8) == 0) {
430 SG_LOG(SG_NETWORK, SG_ALERT,
431 "Cannot enable multiplayer mode: resolving MP server address '"
432 << txAddress << "' failed.");
435 SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - have server");
441 SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - multiplayer mode disabled (no MP server specificed).");
446 SG_LOG(SG_NETWORK, SG_ALERT,
447 "Cannot enable multiplayer mode: No receiver port specified.");
450 if (mCallsign.empty())
451 mCallsign = "JohnDoe"; // FIXME: use getpwuid
452 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-txaddress= "<<txAddress);
453 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-txport= "<<txPort );
454 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-rxaddress="<<rxAddress );
455 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-rxport= "<<rxPort);
456 SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-callsign= "<<mCallsign);
458 mSocket.reset(new simgear::Socket());
459 if (!mSocket->open(false)) {
460 SG_LOG( SG_NETWORK, SG_ALERT,
461 "Cannot enable multiplayer mode: creating data socket failed." );
464 mSocket->setBlocking(false);
465 if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) {
466 SG_LOG( SG_NETWORK, SG_ALERT,
467 "Cannot enable multiplayer mode: binding receive socket failed. "
468 << strerror(errno) << "(errno " << errno << ")");
472 mPropertiesChanged = true;
473 mListener = new MPPropertyListener(this);
474 globals->get_props()->addChangeListener(mListener, false);
476 fgSetBool("/sim/multiplay/online", true);
479 SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer mode active!");
481 if (!fgGetBool("/sim/ai/enabled"))
483 // multiplayer depends on AI module
484 fgSetBool("/sim/ai/enabled", true);
486 } // FGMultiplayMgr::init()
487 //////////////////////////////////////////////////////////////////////
489 //////////////////////////////////////////////////////////////////////
491 // Closes and deletes the local player object. Closes
492 // and deletes the tx socket. Resets the object state to unitialised.
494 //////////////////////////////////////////////////////////////////////
496 FGMultiplayMgr::shutdown (void)
498 fgSetBool("/sim/multiplay/online", false);
505 MultiPlayerMap::iterator it = mMultiPlayerMap.begin(),
506 end = mMultiPlayerMap.end();
507 for (; it != end; ++it) {
508 it->second->setDie(true);
510 mMultiPlayerMap.clear();
513 globals->get_props()->removeChangeListener(mListener);
518 mInitialised = false;
519 } // FGMultiplayMgr::Close(void)
520 //////////////////////////////////////////////////////////////////////
523 FGMultiplayMgr::reinit()
529 //////////////////////////////////////////////////////////////////////
531 // Description: Sends the position data for the local position.
533 //////////////////////////////////////////////////////////////////////
536 * The buffer that holds a multi-player message, suitably aligned.
538 union FGMultiplayMgr::MsgBuf
542 memset(&Msg, 0, sizeof(Msg));
550 const T_MsgHdr* msgHdr() const
552 return reinterpret_cast<const T_MsgHdr*>(&Header);
555 T_PositionMsg* posMsg()
557 return reinterpret_cast<T_PositionMsg*>(Msg + sizeof(T_MsgHdr));
560 const T_PositionMsg* posMsg() const
562 return reinterpret_cast<const T_PositionMsg*>(Msg + sizeof(T_MsgHdr));
565 xdr_data_t* properties()
567 return reinterpret_cast<xdr_data_t*>(Msg + sizeof(T_MsgHdr)
568 + sizeof(T_PositionMsg));
571 const xdr_data_t* properties() const
573 return reinterpret_cast<const xdr_data_t*>(Msg + sizeof(T_MsgHdr)
574 + sizeof(T_PositionMsg));
577 * The end of the properties buffer.
579 xdr_data_t* propsEnd()
581 return reinterpret_cast<xdr_data_t*>(Msg + MAX_PACKET_SIZE);
584 const xdr_data_t* propsEnd() const
586 return reinterpret_cast<const xdr_data_t*>(Msg + MAX_PACKET_SIZE);
589 * The end of properties actually in the buffer. This assumes that
590 * the message header is valid.
592 xdr_data_t* propsRecvdEnd()
594 return reinterpret_cast<xdr_data_t*>(Msg + Header.MsgLen);
597 const xdr_data_t* propsRecvdEnd() const
599 return reinterpret_cast<const xdr_data_t*>(Msg + Header.MsgLen);
602 xdr_data2_t double_val;
603 char Msg[MAX_PACKET_SIZE];
608 FGMultiplayMgr::isSane(const FGExternalMotionData& motionInfo)
610 // check for corrupted data (NaNs)
611 bool isCorrupted = false;
612 isCorrupted |= ((osg::isNaN(motionInfo.time )) ||
613 (osg::isNaN(motionInfo.lag )) ||
614 (osg::isNaN(motionInfo.orientation(3) )));
615 for (unsigned i = 0; (i < 3)&&(!isCorrupted); ++i)
617 isCorrupted |= ((osg::isNaN(motionInfo.position(i) ))||
618 (osg::isNaN(motionInfo.orientation(i) ))||
619 (osg::isNaN(motionInfo.linearVel(i)) )||
620 (osg::isNaN(motionInfo.angularVel(i)) )||
621 (osg::isNaN(motionInfo.linearAccel(i)) )||
622 (osg::isNaN(motionInfo.angularAccel(i)) ));
628 FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
630 if ((! mInitialised) || (! mHaveServer))
634 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition - no server");
638 if (!isSane(motionInfo))
640 // Current local data is invalid (NaN), so stop MP transmission.
641 // => Be nice to older FG versions (no NaN checks) and don't waste bandwidth.
642 SG_LOG(SG_NETWORK, SG_ALERT, "FGMultiplayMgr::SendMyPosition - "
643 << "Local data is invalid (NaN). Data not transmitted.");
647 static MsgBuf msgBuf;
648 static unsigned msgLen = 0;
649 T_PositionMsg* PosMsg = msgBuf.posMsg();
651 strncpy(PosMsg->Model, fgGetString("/sim/model/path"), MAX_MODEL_NAME_LEN);
652 PosMsg->Model[MAX_MODEL_NAME_LEN - 1] = '\0';
653 if (fgGetBool("/sim/freeze/replay-state", true)&&
654 fgGetBool("/sim/multiplay/freeze-on-replay",true))
656 // do not send position updates during replay
657 for (unsigned i = 0 ; i < 3; ++i)
659 // no movement during replay
660 PosMsg->linearVel[i] = XDR_encode_float (0.0);
661 PosMsg->angularVel[i] = XDR_encode_float (0.0);
662 PosMsg->linearAccel[i] = XDR_encode_float (0.0);
663 PosMsg->angularAccel[i] = XDR_encode_float (0.0);
665 // all other data remains unchanged (resend last state)
669 PosMsg->time = XDR_encode_double (motionInfo.time);
670 PosMsg->lag = XDR_encode_double (motionInfo.lag);
671 for (unsigned i = 0 ; i < 3; ++i)
672 PosMsg->position[i] = XDR_encode_double (motionInfo.position(i));
674 motionInfo.orientation.getAngleAxis(angleAxis);
675 for (unsigned i = 0 ; i < 3; ++i)
676 PosMsg->orientation[i] = XDR_encode_float (angleAxis(i));
677 for (unsigned i = 0 ; i < 3; ++i)
678 PosMsg->linearVel[i] = XDR_encode_float (motionInfo.linearVel(i));
679 for (unsigned i = 0 ; i < 3; ++i)
680 PosMsg->angularVel[i] = XDR_encode_float (motionInfo.angularVel(i));
681 for (unsigned i = 0 ; i < 3; ++i)
682 PosMsg->linearAccel[i] = XDR_encode_float (motionInfo.linearAccel(i));
683 for (unsigned i = 0 ; i < 3; ++i)
684 PosMsg->angularAccel[i] = XDR_encode_float (motionInfo.angularAccel(i));
686 xdr_data_t* ptr = msgBuf.properties();
687 std::vector<FGPropertyData*>::const_iterator it;
688 it = motionInfo.properties.begin();
689 //cout << "OUTPUT PROPERTIES\n";
690 xdr_data_t* msgEnd = msgBuf.propsEnd();
691 while (it != motionInfo.properties.end() && ptr + 2 < msgEnd) {
693 // First element is the ID. Write it out when we know we have room for
694 // the whole property.
695 xdr_data_t id = XDR_encode_uint32((*it)->id);
696 // The actual data representation depends on the type
697 switch ((*it)->type) {
698 case simgear::props::INT:
699 case simgear::props::BOOL:
700 case simgear::props::LONG:
702 *ptr++ = XDR_encode_uint32((*it)->int_value);
703 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->int_value << "\n";
705 case simgear::props::FLOAT:
706 case simgear::props::DOUBLE:
708 *ptr++ = XDR_encode_float((*it)->float_value);
709 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->float_value << "\n";
711 case simgear::props::STRING:
712 case simgear::props::UNSPECIFIED:
714 // String is complicated. It consists of
715 // The length of the string
717 // Padding to the nearest 4-bytes.
718 const char* lcharptr = (*it)->string_value;
723 ////cout << "String length: " << strlen(lcharptr) << "\n";
724 uint32_t len = strlen(lcharptr);
725 if (len > MAX_TEXT_SIZE)
727 // XXX This should not be using 4 bytes per character!
728 // If there's not enough room for this property, drop it
730 if (ptr + 2 + ((len + 3) & ~3) > msgEnd)
732 //cout << "String length unint32: " << len << "\n";
734 *ptr++ = XDR_encode_uint32(len);
737 // Now the text itself
738 // XXX This should not be using 4 bytes per character!
740 while ((*lcharptr != '\0') && (lcount < MAX_TEXT_SIZE))
742 *ptr++ = XDR_encode_int8(*lcharptr);
747 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " " << len << " " << (*it)->string_value;
749 // Now pad if required
750 while ((lcount % 4) != 0)
752 *ptr++ = XDR_encode_int8(0);
764 *ptr++ = XDR_encode_uint32(0);
765 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " 0\n";
771 //cout << " Unknown Type: " << (*it)->type << "\n";
773 *ptr++ = XDR_encode_float((*it)->float_value);;
774 //cout << "Prop:" << (*it)->id << " " << (*it)->type << " "<< (*it)->float_value << "\n";
781 msgLen = reinterpret_cast<char*>(ptr) - msgBuf.Msg;
782 FillMsgHdr(msgBuf.msgHdr(), POS_DATA_ID, msgLen);
785 mSocket->sendto(msgBuf.Msg, msgLen, 0, &mServer);
786 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::SendMyPosition");
787 } // FGMultiplayMgr::SendMyPosition()
789 //////////////////////////////////////////////////////////////////////
791 //////////////////////////////////////////////////////////////////////
793 // Name: SendTextMessage
794 // Description: Sends a message to the player. The message must
795 // contain a valid and correctly filled out header and optional
798 //////////////////////////////////////////////////////////////////////
800 FGMultiplayMgr::SendTextMessage(const string &MsgText)
802 if (!mInitialised || !mHaveServer)
806 FillMsgHdr(&MsgHdr, CHAT_MSG_ID);
807 //////////////////////////////////////////////////
808 // Divide the text string into blocks that fit
809 // in the message and send the blocks.
810 //////////////////////////////////////////////////
811 unsigned iNextBlockPosition = 0;
814 char Msg[sizeof(T_MsgHdr) + sizeof(T_ChatMsg)];
815 while (iNextBlockPosition < MsgText.length()) {
816 strncpy (ChatMsg.Text,
817 MsgText.substr(iNextBlockPosition, MAX_CHAT_MSG_LEN - 1).c_str(),
819 ChatMsg.Text[MAX_CHAT_MSG_LEN - 1] = '\0';
820 memcpy (Msg, &MsgHdr, sizeof(T_MsgHdr));
821 memcpy (Msg + sizeof(T_MsgHdr), &ChatMsg, sizeof(T_ChatMsg));
822 mSocket->sendto (Msg, sizeof(T_MsgHdr) + sizeof(T_ChatMsg), 0, &mServer);
823 iNextBlockPosition += MAX_CHAT_MSG_LEN - 1;
828 } // FGMultiplayMgr::SendTextMessage ()
829 //////////////////////////////////////////////////////////////////////
831 //////////////////////////////////////////////////////////////////////
834 // Description: Processes data waiting at the receive socket. The
835 // processing ends when there is no more data at the socket.
837 //////////////////////////////////////////////////////////////////////
839 FGMultiplayMgr::update(double dt)
845 long stamp = SGTimeStamp::now().getSeconds();
847 //////////////////////////////////////////////////
849 //////////////////////////////////////////////////
850 mTimeUntilSend -= dt;
851 if (mTimeUntilSend <= 0.0) {
855 //////////////////////////////////////////////////
856 // Read the receive socket and process any data
857 //////////////////////////////////////////////////
861 //////////////////////////////////////////////////
862 // Although the recv call asks for
863 // MAX_PACKET_SIZE of data, the number of bytes
864 // returned will only be that of the next
865 // packet waiting to be processed.
866 //////////////////////////////////////////////////
867 simgear::IPAddress SenderAddress;
868 int RecvStatus = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
870 //////////////////////////////////////////////////
872 //////////////////////////////////////////////////
876 // socket error reported?
877 // errno isn't thread-safe - so only check its value when
878 // socket return status < 0 really indicates a failure.
879 if ((RecvStatus < 0)&&
880 ((errno == EAGAIN) || (errno == 0))) // MSVC output "NoError" otherwise
882 // ignore "normal" errors
888 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - Unable to receive data. "
889 << strerror(errno) << "(errno " << errno << ")");
893 // status is positive: bytes received
894 bytes = (ssize_t) RecvStatus;
895 if (bytes <= static_cast<ssize_t>(sizeof(T_MsgHdr))) {
896 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
897 << "received message with insufficient data" );
900 //////////////////////////////////////////////////
902 //////////////////////////////////////////////////
903 T_MsgHdr* MsgHdr = msgBuf.msgHdr();
904 MsgHdr->Magic = XDR_decode_uint32 (MsgHdr->Magic);
905 MsgHdr->Version = XDR_decode_uint32 (MsgHdr->Version);
906 MsgHdr->MsgId = XDR_decode_uint32 (MsgHdr->MsgId);
907 MsgHdr->MsgLen = XDR_decode_uint32 (MsgHdr->MsgLen);
908 MsgHdr->ReplyPort = XDR_decode_uint32 (MsgHdr->ReplyPort);
909 MsgHdr->Callsign[MAX_CALLSIGN_LEN -1] = '\0';
910 if (MsgHdr->Magic != MSG_MAGIC) {
911 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
912 << "message has invalid magic number!" );
915 if (MsgHdr->Version != PROTO_VER) {
916 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
917 << "message has invalid protocol number!" );
920 if (static_cast<ssize_t>(MsgHdr->MsgLen) != bytes) {
921 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
922 << "message from " << MsgHdr->Callsign << " has invalid length!");
925 //////////////////////////////////////////////////
927 //////////////////////////////////////////////////
928 switch (MsgHdr->MsgId) {
930 ProcessChatMsg(msgBuf, SenderAddress);
933 ProcessPosMsg(msgBuf, SenderAddress, stamp);
935 case UNUSABLE_POS_DATA_ID:
936 case OLD_OLD_POS_DATA_ID:
937 case OLD_PROP_MSG_ID:
938 case OLD_POS_DATA_ID:
941 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
942 << "Unknown message Id received: " << MsgHdr->MsgId );
948 MultiPlayerMap::iterator it = mMultiPlayerMap.begin();
949 while (it != mMultiPlayerMap.end()) {
950 if (it->second->getLastTimestamp() + 10 < stamp) {
951 std::string name = it->first;
952 it->second->setDie(true);
953 mMultiPlayerMap.erase(it);
954 it = mMultiPlayerMap.upper_bound(name);
958 } // FGMultiplayMgr::ProcessData(void)
959 //////////////////////////////////////////////////////////////////////
962 FGMultiplayMgr::Send()
964 using namespace simgear;
968 // smooth the send rate, by adjusting based on the 'remainder' time, which
969 // is how -ve mTimeUntilSend is. Watch for large values and ignore them,
971 if ((mTimeUntilSend < 0.0) && (fabs(mTimeUntilSend) < mDt)) {
972 mTimeUntilSend = mDt + mTimeUntilSend;
974 mTimeUntilSend = mDt;
977 double sim_time = globals->get_sim_time_sec();
978 // static double lastTime = 0.0;
980 // SG_LOG(SG_GENERAL, SG_INFO, "actual dt=" << sim_time - lastTime);
981 // lastTime = sim_time;
983 FlightProperties ifce;
985 // put together a motion info struct, you will get that later
986 // from FGInterface directly ...
987 FGExternalMotionData motionInfo;
989 // The current simulation time we need to update for,
990 // note that the simulation time is updated before calling all the
991 // update methods. Thus it contains the time intervals *end* time.
992 // The FDM is already run, so the states belong to that time.
993 motionInfo.time = sim_time;
994 motionInfo.lag = mDt;
996 // These are for now converted from lat/lon/alt and euler angles.
997 // But this should change in FGInterface ...
998 double lon = ifce.get_Longitude();
999 double lat = ifce.get_Latitude();
1000 // first the aprioriate structure for the geodetic one
1001 SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce.get_Altitude());
1002 // Convert to cartesion coordinate
1003 motionInfo.position = SGVec3d::fromGeod(geod);
1005 // The quaternion rotating from the earth centered frame to the
1006 // horizontal local frame
1007 SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)lon, (float)lat);
1008 // The orientation wrt the horizontal local frame
1009 float heading = ifce.get_Psi();
1010 float pitch = ifce.get_Theta();
1011 float roll = ifce.get_Phi();
1012 SGQuatf hlOr = SGQuatf::fromYawPitchRoll(heading, pitch, roll);
1013 // The orientation of the vehicle wrt the earth centered frame
1014 motionInfo.orientation = qEc2Hl*hlOr;
1016 if (!globals->get_subsystem("flight")->is_suspended()) {
1018 motionInfo.linearVel = SG_FEET_TO_METER*SGVec3f(ifce.get_uBody(),
1021 motionInfo.angularVel = SGVec3f(ifce.get_P_body(),
1025 // accels, set that to zero for now.
1026 // Angular accelerations are missing from the interface anyway,
1027 // linear accelerations are screwed up at least for JSBSim.
1028 // motionInfo.linearAccel = SG_FEET_TO_METER*SGVec3f(ifce.get_U_dot_body(),
1029 // ifce.get_V_dot_body(),
1030 // ifce.get_W_dot_body());
1031 motionInfo.linearAccel = SGVec3f::zeros();
1032 motionInfo.angularAccel = SGVec3f::zeros();
1034 // if the interface is suspendend, prevent the client from
1035 // wild extrapolations
1036 motionInfo.linearVel = SGVec3f::zeros();
1037 motionInfo.angularVel = SGVec3f::zeros();
1038 motionInfo.linearAccel = SGVec3f::zeros();
1039 motionInfo.angularAccel = SGVec3f::zeros();
1042 // now send the properties
1043 PropertyMap::iterator it;
1044 for (it = mPropertyMap.begin(); it != mPropertyMap.end(); ++it) {
1045 FGPropertyData* pData = new FGPropertyData;
1046 pData->id = it->first;
1047 pData->type = it->second->getType();
1049 switch (pData->type) {
1053 pData->int_value = it->second->getIntValue();
1057 pData->float_value = it->second->getFloatValue();
1060 case props::UNSPECIFIED:
1062 // FIXME: We assume unspecified are strings for the moment.
1064 const char* cstr = it->second->getStringValue();
1065 int len = strlen(cstr);
1069 pData->string_value = new char[len + 1];
1070 strcpy(pData->string_value, cstr);
1075 pData->string_value = 0;
1078 //cout << " Sending property " << pData->id << " " << pData->type << " " << pData->string_value << "\n";
1082 // FIXME Currently default to a float.
1083 //cout << "Unknown type when iterating through props: " << pData->type << "\n";
1084 pData->float_value = it->second->getFloatValue();
1088 motionInfo.properties.push_back(pData);
1091 SendMyPosition(motionInfo);
1095 //////////////////////////////////////////////////////////////////////
1097 // handle a position message
1099 //////////////////////////////////////////////////////////////////////
1101 FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
1102 const simgear::IPAddress& SenderAddress, long stamp)
1104 const T_MsgHdr* MsgHdr = Msg.msgHdr();
1105 if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + sizeof(T_PositionMsg)) {
1106 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
1107 << "Position message received with insufficient data" );
1110 const T_PositionMsg* PosMsg = Msg.posMsg();
1111 FGExternalMotionData motionInfo;
1112 motionInfo.time = XDR_decode_double(PosMsg->time);
1113 motionInfo.lag = XDR_decode_double(PosMsg->lag);
1114 for (unsigned i = 0; i < 3; ++i)
1115 motionInfo.position(i) = XDR_decode_double(PosMsg->position[i]);
1117 for (unsigned i = 0; i < 3; ++i)
1118 angleAxis(i) = XDR_decode_float(PosMsg->orientation[i]);
1119 motionInfo.orientation = SGQuatf::fromAngleAxis(angleAxis);
1120 for (unsigned i = 0; i < 3; ++i)
1121 motionInfo.linearVel(i) = XDR_decode_float(PosMsg->linearVel[i]);
1122 for (unsigned i = 0; i < 3; ++i)
1123 motionInfo.angularVel(i) = XDR_decode_float(PosMsg->angularVel[i]);
1124 for (unsigned i = 0; i < 3; ++i)
1125 motionInfo.linearAccel(i) = XDR_decode_float(PosMsg->linearAccel[i]);
1126 for (unsigned i = 0; i < 3; ++i)
1127 motionInfo.angularAccel(i) = XDR_decode_float(PosMsg->angularAccel[i]);
1129 // sanity check: do not allow injection of corrupted data (NaNs)
1130 if (!isSane(motionInfo))
1132 // drop this message, keep old position until receiving valid data
1133 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::ProcessPosMsg - "
1134 << "Position message with invalid data (NaN) received from "
1135 << MsgHdr->Callsign);
1139 //cout << "INPUT MESSAGE\n";
1141 // There was a bug in 1.9.0 and before: T_PositionMsg was 196 bytes
1142 // on 32 bit architectures and 200 bytes on 64 bit, and this
1143 // structure is put directly on the wire. By looking at the padding,
1144 // we can sort through the mess, mostly:
1145 // If padding is 0 (which is not a valid property type), then the
1146 // message was produced by a new client or an old 64 bit client that
1147 // happened to have 0 on the stack;
1148 // Else if the property list starting with the padding word is
1149 // well-formed, then the client is probably an old 32 bit client and
1150 // we'll go with that;
1151 // Else it is an old 64-bit client and properties start after the
1153 // There is a chance that we could be fooled by garbage in the
1154 // padding looking like a valid property, so verifyProperties() is
1155 // strict about the validity of the property values.
1156 const xdr_data_t* xdr = Msg.properties();
1157 if (PosMsg->pad != 0) {
1158 if (verifyProperties(&PosMsg->pad, Msg.propsRecvdEnd()))
1160 else if (!verifyProperties(xdr, Msg.propsRecvdEnd()))
1163 while (xdr < Msg.propsRecvdEnd()) {
1164 // simgear::props::Type type = simgear::props::UNSPECIFIED;
1166 // First element is always the ID
1167 unsigned id = XDR_decode_uint32(*xdr);
1168 //cout << pData->id << " ";
1171 // Check the ID actually exists and get the type
1172 const IdPropertyList* plist = findProperty(id);
1176 FGPropertyData* pData = new FGPropertyData;
1178 pData->type = plist->type;
1179 // How we decode the remainder of the property depends on the type
1180 switch (pData->type) {
1181 case simgear::props::INT:
1182 case simgear::props::BOOL:
1183 case simgear::props::LONG:
1184 pData->int_value = XDR_decode_uint32(*xdr);
1186 //cout << pData->int_value << "\n";
1188 case simgear::props::FLOAT:
1189 case simgear::props::DOUBLE:
1190 pData->float_value = XDR_decode_float(*xdr);
1192 //cout << pData->float_value << "\n";
1194 case simgear::props::STRING:
1195 case simgear::props::UNSPECIFIED:
1197 // String is complicated. It consists of
1198 // The length of the string
1199 // The string itself
1200 // Padding to the nearest 4-bytes.
1201 uint32_t length = XDR_decode_uint32(*xdr);
1203 //cout << length << " ";
1204 // Old versions truncated the string but left the length unadjusted.
1205 if (length > MAX_TEXT_SIZE)
1206 length = MAX_TEXT_SIZE;
1207 pData->string_value = new char[length + 1];
1208 //cout << " String: ";
1209 for (unsigned i = 0; i < length; i++)
1211 pData->string_value[i] = (char) XDR_decode_int8(*xdr);
1213 //cout << pData->string_value[i];
1216 pData->string_value[length] = '\0';
1218 // Now handle the padding
1219 while ((length % 4) != 0)
1230 pData->float_value = XDR_decode_float(*xdr);
1231 SG_LOG(SG_NETWORK, SG_DEBUG, "Unknown Prop type " << pData->id << " " << pData->type);
1236 motionInfo.properties.push_back(pData);
1240 // We failed to find the property. We'll try the next packet immediately.
1241 SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::ProcessPosMsg - "
1242 "message from " << MsgHdr->Callsign << " has unknown property id "
1247 FGAIMultiplayer* mp = getMultiplayer(MsgHdr->Callsign);
1249 mp = addMultiplayer(MsgHdr->Callsign, PosMsg->Model);
1250 mp->addMotionInfo(motionInfo, stamp);
1251 } // FGMultiplayMgr::ProcessPosMsg()
1252 //////////////////////////////////////////////////////////////////////
1254 //////////////////////////////////////////////////////////////////////
1256 // handle a chat message
1257 // FIXME: display chat message within flightgear
1259 //////////////////////////////////////////////////////////////////////
1261 FGMultiplayMgr::ProcessChatMsg(const MsgBuf& Msg,
1262 const simgear::IPAddress& SenderAddress)
1264 const T_MsgHdr* MsgHdr = Msg.msgHdr();
1265 if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + 1) {
1266 SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - "
1267 << "Chat message received with insufficient data" );
1271 char *chatStr = new char[MsgHdr->MsgLen - sizeof(T_MsgHdr)];
1272 const T_ChatMsg* ChatMsg
1273 = reinterpret_cast<const T_ChatMsg *>(Msg.Msg + sizeof(T_MsgHdr));
1274 strncpy(chatStr, ChatMsg->Text,
1275 MsgHdr->MsgLen - sizeof(T_MsgHdr));
1276 chatStr[MsgHdr->MsgLen - sizeof(T_MsgHdr) - 1] = '\0';
1278 SG_LOG (SG_NETWORK, SG_WARN, "Chat [" << MsgHdr->Callsign << "]"
1282 } // FGMultiplayMgr::ProcessChatMsg ()
1283 //////////////////////////////////////////////////////////////////////
1286 FGMultiplayMgr::FillMsgHdr(T_MsgHdr *MsgHdr, int MsgId, unsigned _len)
1291 len = sizeof(T_MsgHdr) + sizeof(T_ChatMsg);
1297 len = sizeof(T_MsgHdr);
1300 MsgHdr->Magic = XDR_encode_uint32(MSG_MAGIC);
1301 MsgHdr->Version = XDR_encode_uint32(PROTO_VER);
1302 MsgHdr->MsgId = XDR_encode_uint32(MsgId);
1303 MsgHdr->MsgLen = XDR_encode_uint32(len);
1304 MsgHdr->ReplyAddress = 0; // Are obsolete, keep them for the server for
1305 MsgHdr->ReplyPort = 0; // now
1306 strncpy(MsgHdr->Callsign, mCallsign.c_str(), MAX_CALLSIGN_LEN);
1307 MsgHdr->Callsign[MAX_CALLSIGN_LEN - 1] = '\0';
1311 FGMultiplayMgr::addMultiplayer(const std::string& callsign,
1312 const std::string& modelName)
1314 if (0 < mMultiPlayerMap.count(callsign))
1315 return mMultiPlayerMap[callsign].get();
1317 FGAIMultiplayer* mp = new FGAIMultiplayer;
1318 mp->setPath(modelName.c_str());
1319 mp->setCallSign(callsign);
1320 mMultiPlayerMap[callsign] = mp;
1322 FGAIManager *aiMgr = (FGAIManager*)globals->get_subsystem("ai-model");
1326 /// FIXME: that must follow the attach ATM ...
1327 for (unsigned i = 0; i < numProperties; ++i)
1328 mp->addPropertyId(sIdPropertyList[i].id, sIdPropertyList[i].name);
1335 FGMultiplayMgr::getMultiplayer(const std::string& callsign)
1337 if (0 < mMultiPlayerMap.count(callsign))
1338 return mMultiPlayerMap[callsign].get();
1344 FGMultiplayMgr::findProperties()
1346 if (!mPropertiesChanged) {
1350 mPropertiesChanged = false;
1352 for (unsigned i = 0; i < numProperties; ++i) {
1353 const char* name = sIdPropertyList[i].name;
1354 SGPropertyNode* pNode = globals->get_props()->getNode(name);
1359 int id = sIdPropertyList[i].id;
1360 if (mPropertyMap.find(id) != mPropertyMap.end()) {
1361 continue; // already activated
1364 mPropertyMap[id] = pNode;
1365 SG_LOG(SG_NETWORK, SG_DEBUG, "activating MP property:" << pNode->getPath());