2005-10-30 18:01:51 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-01-23 15:07:09 +01:00
|
|
|
// multiplaymgr.hxx
|
2005-10-30 18:01:51 +00:00
|
|
|
//
|
|
|
|
// Written by Duncan McCreanor, started February 2003.
|
|
|
|
// duncan.mccreanor@airservicesaustralia.com
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 Airservices Australia
|
|
|
|
// Copyright (C) 2005 Oliver Schroeder
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-10-30 18:01:51 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef MULTIPLAYMGR_H
|
|
|
|
#define MULTIPLAYMGR_H
|
|
|
|
|
|
|
|
#define MULTIPLAYTXMGR_HID "$Id$"
|
|
|
|
|
2017-02-12 16:57:24 +01:00
|
|
|
const int MIN_MP_PROTOCOL_VERSION = 1;
|
|
|
|
const int MAX_MP_PROTOCOL_VERSION = 2;
|
2005-10-30 18:01:51 +00:00
|
|
|
|
2008-07-25 18:38:29 +00:00
|
|
|
#include <string>
|
2005-10-30 18:01:51 +00:00
|
|
|
#include <vector>
|
2011-05-29 09:34:56 +02:00
|
|
|
#include <memory>
|
2005-10-30 18:01:51 +00:00
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
2006-02-09 12:29:05 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
2010-10-23 20:37:26 +01:00
|
|
|
#include <simgear/io/raw_socket.hxx>
|
2010-10-02 23:40:38 +01:00
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
2005-10-30 18:01:51 +00:00
|
|
|
|
2010-11-13 14:38:35 +00:00
|
|
|
struct FGExternalMotionData;
|
|
|
|
class MPPropertyListener;
|
|
|
|
struct T_MsgHdr;
|
|
|
|
class FGAIMultiplayer;
|
2005-10-30 18:01:51 +00:00
|
|
|
|
2010-10-02 23:40:38 +01:00
|
|
|
class FGMultiplayMgr : public SGSubsystem
|
2005-10-30 18:01:51 +00:00
|
|
|
{
|
2010-11-13 14:38:35 +00:00
|
|
|
public:
|
2006-02-17 09:43:33 +00:00
|
|
|
FGMultiplayMgr();
|
|
|
|
~FGMultiplayMgr();
|
2010-10-02 23:40:38 +01:00
|
|
|
|
|
|
|
virtual void init(void);
|
|
|
|
virtual void update(double dt);
|
|
|
|
|
2010-11-13 14:38:35 +00:00
|
|
|
virtual void shutdown(void);
|
|
|
|
virtual void reinit();
|
|
|
|
|
2006-02-17 09:43:33 +00:00
|
|
|
// transmitter
|
2010-11-13 14:38:35 +00:00
|
|
|
|
2012-11-20 17:09:09 +00:00
|
|
|
void SendTextMessage(const std::string &sMsgText);
|
2006-02-17 09:43:33 +00:00
|
|
|
// receiver
|
|
|
|
|
2005-10-30 18:01:51 +00:00
|
|
|
private:
|
2010-11-13 14:38:35 +00:00
|
|
|
friend class MPPropertyListener;
|
|
|
|
|
|
|
|
void setPropertiesChanged()
|
|
|
|
{
|
|
|
|
mPropertiesChanged = true;
|
|
|
|
}
|
2017-02-12 16:57:24 +01:00
|
|
|
int getProtocolToUse()
|
|
|
|
{
|
2017-02-23 00:46:01 +01:00
|
|
|
int protocolVersion = pProtocolVersion->getIntValue();
|
|
|
|
if (protocolVersion >= MIN_MP_PROTOCOL_VERSION && protocolVersion <= MAX_MP_PROTOCOL_VERSION)
|
|
|
|
return protocolVersion;
|
|
|
|
else
|
|
|
|
return MIN_MP_PROTOCOL_VERSION;
|
2017-02-12 16:57:24 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 14:38:35 +00:00
|
|
|
void findProperties();
|
|
|
|
|
|
|
|
void Send();
|
|
|
|
void SendMyPosition(const FGExternalMotionData& motionInfo);
|
2017-02-23 22:33:33 +01:00
|
|
|
short get_scaled_short(double v, double scale);
|
2010-11-13 14:38:35 +00:00
|
|
|
|
2009-02-06 09:50:47 +01:00
|
|
|
union MsgBuf;
|
2006-02-17 09:43:33 +00:00
|
|
|
FGAIMultiplayer* addMultiplayer(const std::string& callsign,
|
|
|
|
const std::string& modelName);
|
|
|
|
FGAIMultiplayer* getMultiplayer(const std::string& callsign);
|
2009-02-06 09:50:47 +01:00
|
|
|
void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
|
2010-10-23 20:37:26 +01:00
|
|
|
void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
|
2009-02-06 09:50:47 +01:00
|
|
|
long stamp);
|
2010-10-23 20:37:26 +01:00
|
|
|
void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
|
2011-01-23 15:07:09 +01:00
|
|
|
bool isSane(const FGExternalMotionData& motionInfo);
|
2006-02-17 09:43:33 +00:00
|
|
|
|
|
|
|
/// maps from the callsign string to the FGAIMultiplayer
|
2010-06-16 06:57:47 +02:00
|
|
|
typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
|
2006-02-17 09:43:33 +00:00
|
|
|
MultiPlayerMap mMultiPlayerMap;
|
|
|
|
|
2016-11-14 22:20:14 +01:00
|
|
|
std::unique_ptr<simgear::Socket> mSocket;
|
2010-10-23 20:37:26 +01:00
|
|
|
simgear::IPAddress mServer;
|
2006-02-17 09:43:33 +00:00
|
|
|
bool mHaveServer;
|
|
|
|
bool mInitialised;
|
2010-10-02 23:40:38 +01:00
|
|
|
std::string mCallsign;
|
2010-11-13 14:38:35 +00:00
|
|
|
|
|
|
|
// Map between the property id's from the multiplayers network packets
|
|
|
|
// and the property nodes
|
|
|
|
typedef std::map<unsigned int, SGSharedPtr<SGPropertyNode> > PropertyMap;
|
|
|
|
PropertyMap mPropertyMap;
|
2017-02-23 00:46:01 +01:00
|
|
|
SGPropertyNode *pProtocolVersion;
|
|
|
|
SGPropertyNode *pXmitLen;
|
|
|
|
SGPropertyNode *pMultiPlayDebugLevel;
|
|
|
|
SGPropertyNode *pMultiPlayRange;
|
2017-07-05 01:23:24 +02:00
|
|
|
SGPropertyNode *pMultiPlayTransmitOnlyGenerics;
|
2017-02-04 23:59:14 +01:00
|
|
|
|
|
|
|
typedef std::map<unsigned int, const struct IdPropertyList*> PropertyDefinitionMap;
|
|
|
|
PropertyDefinitionMap mPropertyDefinition;
|
|
|
|
|
2010-11-13 14:38:35 +00:00
|
|
|
bool mPropertiesChanged;
|
2017-02-12 16:57:24 +01:00
|
|
|
|
2010-11-13 14:38:35 +00:00
|
|
|
MPPropertyListener* mListener;
|
|
|
|
|
|
|
|
double mDt; // reciprocal of /sim/multiplay/tx-rate-hz
|
|
|
|
double mTimeUntilSend;
|
2005-10-30 18:01:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|