• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

FullyConnectedMesh.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 #include "NativeFeatureIncludes.h"
00008 #if _RAKNET_SUPPORT_FullyConnectedMesh==1
00009 
00010 #include "FullyConnectedMesh.h"
00011 #include "RakPeerInterface.h"
00012 #include "MessageIdentifiers.h"
00013 #include "BitStream.h"
00014 #include "ConnectionGraph.h"
00015 #include <string.h>
00016 #include "RakAssert.h"
00017 
00018 #ifdef _MSC_VER
00019 #pragma warning( push )
00020 #endif
00021 
00022 FullyConnectedMesh::FullyConnectedMesh()
00023 {
00024         pw=0;
00025 }
00026 
00027 FullyConnectedMesh::~FullyConnectedMesh()
00028 {
00029         if (pw)
00030                 rakFree_Ex(pw, __FILE__, __LINE__ );
00031 }
00032 
00033 void FullyConnectedMesh::Startup(const char *password, int _passwordLength)
00034 {
00035         if (pw)
00036                 rakFree_Ex(pw, __FILE__, __LINE__ );
00037         if (password)
00038         {
00039                 pw = (char*) rakMalloc_Ex( _passwordLength, __FILE__, __LINE__ );
00040                 memcpy(pw, password, _passwordLength);
00041                 passwordLength=_passwordLength;
00042         }
00043         else
00044                 pw=0;
00045         
00046 }
00047 
00048 PluginReceiveResult FullyConnectedMesh::OnReceive(Packet *packet)
00049 {
00050         RakAssert(packet);
00051 
00052         switch (packet->data[0])
00053         {
00054         case ID_REMOTE_NEW_INCOMING_CONNECTION: // This comes from the connection graph plugin
00055                 {
00056                         RakNet::BitStream b(packet->data, packet->length, false);
00057                         b.IgnoreBits(8);
00058                         ConnectionGraphGroupID group1, group2;
00059                         SystemAddress node1, node2;
00060                         RakNetGUID guid1, guid2;
00061                         b.Read(node1);
00062                         b.Read(group1);
00063                         b.Read(guid1);
00064                         if (rakPeerInterface->IsConnected(node1,true)==false)
00065                         {
00066                                 char str1[64];
00067                                 node1.ToString(false, str1);
00068                                 rakPeerInterface->Connect(str1, node1.port, pw, pw ? passwordLength : 0);
00069                         }                               
00070                         b.Read(node2);
00071                         b.Read(group2);
00072                         b.Read(guid2);
00073                         if (rakPeerInterface->IsConnected(node2,true)==false)
00074                         {
00075                                 char str1[64];
00076                                 node2.ToString(false, str1);
00077                                 rakPeerInterface->Connect(str1, node2.port, pw, pw ? passwordLength : 0);
00078                         }
00079                                 
00080                         break;
00081                 }
00082         }
00083 
00084         return RR_CONTINUE_PROCESSING;
00085 }
00086 
00087 #ifdef _MSC_VER
00088 #pragma warning( pop )
00089 #endif
00090 
00091 #endif // _RAKNET_SUPPORT_*

Generated on Thu Sep 30 2010 01:27:24 for RakNet by  doxygen 1.7.1