#include <simgear/timing/timestamp.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props.hxx>
+#include <simgear/structure/commands.hxx>
#include <AIModel/AIManager.hxx>
#include <AIModel/AIMultiplayer.hxx>
#include <Main/fg_props.hxx>
+#include <Network/RemoteXMLRequest.hxx>
+#include <Network/HTTPClient.hxx>
#include "multiplaymgr.hxx"
#include "mpmessages.hxx"
#include <FDM/flightProperties.hxx>
FGMultiplayMgr* _multiplay;
};
+//////////////////////////////////////////////////////////////////////
+//
+// handle command "multiplayer-connect"
+// args:
+// server: servername to connect (mandatory)
+// txport: outgoing port number (default: 5000)
+// rxport: incoming port number (default: 5000)
+//////////////////////////////////////////////////////////////////////
+static bool do_multiplayer_connect(const SGPropertyNode * arg) {
+ FGMultiplayMgr * self = (FGMultiplayMgr*) globals->get_subsystem("mp");
+ if (!self) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Multiplayer subsystem not available.");
+ return false;
+ }
+
+ string servername = arg->getStringValue("servername", "");
+ if (servername.empty()) {
+ SG_LOG(SG_NETWORK, SG_WARN,
+ "do_multiplayer.connect: no server name given, command ignored.");
+ return false;
+ }
+ int port = arg->getIntValue("rxport", -1);
+ if (port > 0 && port <= 0xffff) {
+ fgSetInt("/sim/multiplay/rxport", port);
+ }
+
+ port = arg->getIntValue("txport", -1);
+ if (port > 0 && port <= 0xffff) {
+ fgSetInt("/sim/multiplay/txport", port);
+ }
+
+ servername = servername.substr(0, servername.find_first_of(' '));
+ fgSetString("/sim/multiplay/txhost", servername);
+ self->reinit();
+ return true;
+}
+
+//////////////////////////////////////////////////////////////////////
+//
+// handle command "multiplayer-disconnect"
+// disconnect args:
+// none
+//////////////////////////////////////////////////////////////////////
+static bool do_multiplayer_disconnect(const SGPropertyNode * arg) {
+ FGMultiplayMgr * self = (FGMultiplayMgr*) globals->get_subsystem("mp");
+ if (!self) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Multiplayer subsystem not available.");
+ return false;
+ }
+
+ fgSetString("/sim/multiplay/txhost", "");
+ self->reinit();
+ return true;
+}
+
+//////////////////////////////////////////////////////////////////////
+//
+// handle command "multiplayer-refreshserverlist"
+// refreshserverlist args:
+// none
+//
+//////////////////////////////////////////////////////////////////////
+static bool do_multiplayer_refreshserverlist(const SGPropertyNode * arg) {
+ FGMultiplayMgr * self = (FGMultiplayMgr*) globals->get_subsystem("mp");
+ if (!self) {
+ SG_LOG(SG_NETWORK, SG_WARN, "Multiplayer subsystem not available.");
+ return false;
+ }
+
+ FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+ if (!http) {
+ SG_LOG(SG_IO, SG_ALERT,
+ "do_multiplayer.refreshserverlist: HTTP client not running");
+ return false;
+ }
+
+ string url(
+ fgGetString("/sim/multiplay/serverlist-url",
+ "http://liveries.flightgear.org/mpstatus/mpservers.xml"));
+
+ if (url.empty()) {
+ SG_LOG(SG_IO, SG_ALERT,
+ "do_multiplayer.refreshserverlist: no URL given");
+ return false;
+ }
+
+ SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
+ SGPropertyNode *completeNode = fgGetNode("/sim/multiplay/got-servers", true);
+ SGPropertyNode *failureNode = fgGetNode("/sim/multiplay/get-servers-failure", true);
+ RemoteXMLRequest* req = new RemoteXMLRequest(url, targetnode);
+ req->setCompletionProp(completeNode);
+ req->setFailedProp(failureNode);
+ completeNode->setBoolValue(false);
+ failureNode->setBoolValue(false);
+ http->makeRequest(req);
+ return true;
+}
+
//////////////////////////////////////////////////////////////////////
//
// MultiplayMgr constructor
mInitialised = false;
mHaveServer = false;
mListener = NULL;
+ globals->get_commands()->addCommand("multiplayer-connect", do_multiplayer_connect);
+ globals->get_commands()->addCommand("multiplayer-disconnect", do_multiplayer_disconnect);
+ globals->get_commands()->addCommand("multiplayer-refreshserverlist", do_multiplayer_refreshserverlist);
} // FGMultiplayMgr::FGMultiplayMgr()
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
FGMultiplayMgr::~FGMultiplayMgr()
{
-
+ globals->get_commands()->removeCommand("multiplayer-connect");
+ globals->get_commands()->removeCommand("multiplayer-disconnect");
+ globals->get_commands()->removeCommand("multiplayer-refreshserverlist");
} // FGMultiplayMgr::~FGMultiplayMgr()
//////////////////////////////////////////////////////////////////////
motionInfo.orientation.getAngleAxis(angleAxis);
for (unsigned i = 0 ; i < 3; ++i)
PosMsg->orientation[i] = XDR_encode_float (angleAxis(i));
- for (unsigned i = 0 ; i < 3; ++i)
- PosMsg->linearVel[i] = XDR_encode_float (motionInfo.linearVel(i));
- for (unsigned i = 0 ; i < 3; ++i)
- PosMsg->angularVel[i] = XDR_encode_float (motionInfo.angularVel(i));
- for (unsigned i = 0 ; i < 3; ++i)
- PosMsg->linearAccel[i] = XDR_encode_float (motionInfo.linearAccel(i));
- for (unsigned i = 0 ; i < 3; ++i)
- PosMsg->angularAccel[i] = XDR_encode_float (motionInfo.angularAccel(i));
-
+ if (fgGetBool("/sim/crashed",true))
+ {
+ for (unsigned i = 0 ; i < 3; ++i)
+ {
+ // no speed or acceleration sent when crashed, for better mp patch
+ PosMsg->linearVel[i] = XDR_encode_float (0.0);
+ PosMsg->angularVel[i] = XDR_encode_float (0.0);
+ PosMsg->linearAccel[i] = XDR_encode_float (0.0);
+ PosMsg->angularAccel[i] = XDR_encode_float (0.0);
+ }
+ }
+ else
+ {
+ //including speed up time in velocity and acceleration
+ double timeAccel = fgGetDouble("/sim/speed-up");
+ for (unsigned i = 0 ; i < 3; ++i)
+ PosMsg->linearVel[i] = XDR_encode_float (motionInfo.linearVel(i) * timeAccel);
+ for (unsigned i = 0 ; i < 3; ++i)
+ PosMsg->angularVel[i] = XDR_encode_float (motionInfo.angularVel(i) * timeAccel);
+ for (unsigned i = 0 ; i < 3; ++i)
+ PosMsg->linearAccel[i] = XDR_encode_float (motionInfo.linearAccel(i) * timeAccel * timeAccel);
+ for (unsigned i = 0 ; i < 3; ++i)
+ PosMsg->angularAccel[i] = XDR_encode_float (motionInfo.angularAccel(i) * timeAccel * timeAccel);
+ }
xdr_data_t* ptr = msgBuf.properties();
std::vector<FGPropertyData*>::const_iterator it;
it = motionInfo.properties.begin();