00001
00002
00003
00004
00005
00006
00007
00008 #include "NativeFeatureIncludes.h"
00009 #if _RAKNET_SUPPORT_ConnectionGraph==1
00010
00011 #ifndef __CONNECTION_GRAPH_H
00012 #define __CONNECTION_GRAPH_H
00013
00014 class RakPeerInterface;
00015 #include "RakMemoryOverride.h"
00016 #include "RakNetTypes.h"
00017 #include "PluginInterface2.h"
00018 #include "DS_List.h"
00019 #include "DS_WeightedGraph.h"
00020 #include "GetTime.h"
00021 #include "Export.h"
00022
00029
00030
00031 typedef unsigned char ConnectionGraphGroupID;
00032
00036 class RAK_DLL_EXPORT ConnectionGraph : public PluginInterface2
00037 {
00038 public:
00039 ConnectionGraph();
00040 virtual ~ConnectionGraph();
00041
00043 struct RAK_DLL_EXPORT SystemAddressAndGroupId
00044 {
00045 SystemAddressAndGroupId();
00046 ~SystemAddressAndGroupId();
00047 SystemAddressAndGroupId(SystemAddress _systemAddress, ConnectionGraphGroupID _groupID, RakNetGUID _guid);
00048
00049 SystemAddress systemAddress;
00050 ConnectionGraphGroupID groupId;
00051 RakNetGUID guid;
00052
00053 bool operator==( const SystemAddressAndGroupId& right ) const;
00054 bool operator!=( const SystemAddressAndGroupId& right ) const;
00055 bool operator > ( const SystemAddressAndGroupId& right ) const;
00056 bool operator < ( const SystemAddressAndGroupId& right ) const;
00057 };
00058
00059
00060
00061
00063 void SetPassword(const char *password);
00064
00067 DataStructures::WeightedGraph<ConnectionGraph::SystemAddressAndGroupId, unsigned short, false> *GetGraph(void);
00068
00076 void SetAutoAddNewConnections(bool autoAdd);
00077
00082 void RequestConnectionGraph(SystemAddress systemAddress);
00083
00093 void AddNewConnection(RakPeerInterface *peer, SystemAddress systemAddress, RakNetGUID guid, ConnectionGraphGroupID groupId);
00094
00099 void SetGroupId(ConnectionGraphGroupID groupId);
00100
00105 void SubscribeToGroup(ConnectionGraphGroupID groupId);
00106
00110 void UnsubscribeFromGroup(ConnectionGraphGroupID groupId);
00111
00112
00113
00114
00116 virtual void OnRakPeerShutdown(void);
00118 virtual void Update(void);
00120 virtual PluginReceiveResult OnReceive(Packet *packet);
00122 virtual void OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
00124 virtual void OnNewConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, bool isIncoming);
00125
00126 protected:
00127 void HandleDroppedConnection(RakPeerInterface *peer, SystemAddress systemAddress, unsigned char packetId);
00128 void DeleteFromPeerList(SystemAddress systemAddress);
00129
00130 void OnNewIncomingConnection(Packet *packet);
00131 void OnConnectionGraphRequest(Packet *packet);
00132 void OnConnectionGraphReply(Packet *packet);
00133 void OnConnectionGraphUpdate(Packet *packet);
00134 void OnNewConnectionInternal(Packet *packet);
00135 bool OnConnectionLostInternal(Packet *packet, unsigned char packetId);
00136 void OnConnectionAddition(Packet *packet);
00137 void OnConnectionRemoval(Packet *packet);
00138 void SendConnectionGraph(SystemAddress target, unsigned char packetId, RakPeerInterface *peer);
00139 void SerializeWeightedGraph(RakNet::BitStream *out, const DataStructures::WeightedGraph<ConnectionGraph::SystemAddressAndGroupId, unsigned short, false> &g) const;
00140 bool DeserializeWeightedGraph(RakNet::BitStream *inBitstream, RakPeerInterface *peer);
00141 void AddAndRelayConnection(DataStructures::OrderedList<SystemAddress,SystemAddress> &ignoreList, const SystemAddressAndGroupId &conn1, const SystemAddressAndGroupId &conn2, unsigned short ping, RakPeerInterface *peer);
00142 bool RemoveAndRelayConnection(DataStructures::OrderedList<SystemAddress,SystemAddress> &ignoreList, unsigned char packetId, const SystemAddress node1, const SystemAddress node2, RakPeerInterface *peer);
00143 void RemoveParticipant(SystemAddress systemAddress);
00144 void AddParticipant(SystemAddress systemAddress);
00145 void BroadcastGraphUpdate(DataStructures::OrderedList<SystemAddress,SystemAddress> &ignoreList, RakPeerInterface *peer);
00146 void NotifyUserOfRemoteConnection(const SystemAddressAndGroupId &conn1, const SystemAddressAndGroupId &conn2,unsigned short ping, RakPeerInterface *peer);
00147 bool IsNewRemoteConnection(const SystemAddressAndGroupId &conn1, const SystemAddressAndGroupId &conn2,RakPeerInterface *peer);
00148 bool DeserializeIgnoreList(DataStructures::OrderedList<SystemAddress,SystemAddress> &ignoreList, RakNet::BitStream *inBitstream );
00149 void SerializeIgnoreListAndBroadcast(RakNet::BitStream *outBitstream, DataStructures::OrderedList<SystemAddress,SystemAddress> &ignoreList, RakPeerInterface *peer);
00150
00151 RakNetTime nextWeightUpdate;
00152 char *pw;
00153 DataStructures::OrderedList<SystemAddress, SystemAddress> participantList;
00154
00155 DataStructures::WeightedGraph<ConnectionGraph::SystemAddressAndGroupId, unsigned short, false> graph;
00156 bool autoAddNewConnections;
00157 ConnectionGraphGroupID myGroupId;
00158
00159 DataStructures::OrderedList<ConnectionGraphGroupID, ConnectionGraphGroupID> subscribedGroups;
00160
00161
00162
00163 };
00164
00165 #endif
00166
00167 #endif // _RAKNET_SUPPORT_*