Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
png85 committed Sep 19, 2015
2 parents 1a16989 + 41ba40c commit add146f
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 105 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ add_subdirectory(Lib)

set(RAKNET_COMMON_LIBS RakNetLibStatic)

if( RAKNET_GENERATE_SAMPLES )
if( RAKNET_ENABLE_SAMPLES )
add_subdirectory(Samples)
endif()
4 changes: 4 additions & 0 deletions DependentExtensions/Autopatcher/ApplyPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ int TestPatchInMemory(int argc,char *argv[])
fclose(newFile);
fclose(oldFile);

delete[] patch;
delete[] old;
delete[] _new;

return res;
}

Expand Down
12 changes: 6 additions & 6 deletions Lib/DLL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ IF(WIN32 AND NOT UNIX)
SET( CMAKE_CXX_FLAGS "/D WIN32 /D _RAKNET_DLL /D _CRT_NONSTDC_NO_DEPRECATE /D _CRT_SECURE_NO_DEPRECATE /GS- /GR- ")
ENDIF(WIN32 AND NOT UNIX)

IF(WIN32 AND NOT UNIX)
target_link_libraries (RakNetDLL ${RAKNET_LIBRARY_LIBS})
ELSE(WIN32 AND NOT UNIX)
target_link_libraries (RakNetDLL ${RAKNET_LIBRARY_LIBS})
INSTALL(TARGETS RakNetDLL DESTINATION ${RakNet_SOURCE_DIR}/Lib/DLL)
ENDIF(WIN32 AND NOT UNIX)
target_link_libraries (RakNetDLL ${RAKNET_LIBRARY_LIBS})

# install lib and header files to CMAKE_INSTALL_PREFIX
install(TARGETS RakNetDLL DESTINATION "lib")
install(FILES ${ALL_HEADER_SRCS} DESTINATION "include/RakNet")

6 changes: 4 additions & 2 deletions Lib/LibStatic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ IF(WIN32 AND NOT UNIX)

ELSE(WIN32 AND NOT UNIX)
target_link_libraries (RakNetLibStatic ${RAKNET_LIBRARY_LIBS})
INSTALL(TARGETS RakNetLibStatic DESTINATION ${RakNet_SOURCE_DIR}/Lib/RakNetLibStatic)
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION ${RakNet_SOURCE_DIR}/include/raknet)
ENDIF(WIN32 AND NOT UNIX)

INSTALL(TARGETS RakNetLibStatic DESTINATION "lib")
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION "include/RakNet")



2 changes: 1 addition & 1 deletion Samples/CrossConnectionTest/CrossConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main()
{
printf("Test failed, ID_NEW_INCOMING_CONNECTION is true for both instances\n");
}
else if (gotConnectionRequestAccepted[0]==0 && gotConnectionRequestAccepted[1]==0)
else if (gotNewIncomingConnection[0]==0 && gotNewIncomingConnection[1]==0)
{
printf("Test failed, ID_NEW_INCOMING_CONNECTION is false for both instances\n");
}
Expand Down
2 changes: 1 addition & 1 deletion Source/BitStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ namespace RakNet
}

template <class templateType>
BitStream& operator<<(BitStream& out, templateType& c)
BitStream& operator<<(BitStream& out, const templateType& c)
{
out.Write(c);
return out;
Expand Down
4 changes: 2 additions & 2 deletions Source/DS_WeightedGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ namespace DataStructures
if (row==0)
{
path.Insert(startNode, _FILE_AND_LINE_);
for (col=0; outputQueue.Size(); col++)
while (!outputQueue.Empty())
path.Insert(outputQueue.Pop(), _FILE_AND_LINE_);
return true;
}
Expand All @@ -296,7 +296,7 @@ namespace DataStructures
}

path.Insert(startNode, _FILE_AND_LINE_);
for (col=0; outputQueue.Size(); col++)
while (!outputQueue.Empty())
path.Insert(outputQueue.Pop(), _FILE_AND_LINE_);
return true;
}
Expand Down
10 changes: 9 additions & 1 deletion Source/NatPunchthroughClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ void NatPunchthroughClient::SendTTL(const SystemAddress &sa)
rakPeerInterface->SendTTL(ipAddressString,sa.GetPort(), 2);
}

char *TestModeToString(NatPunchthroughClient::SendPing::TestMode tm)
const char *TestModeToString(NatPunchthroughClient::SendPing::TestMode tm)
{
switch (tm)
{
Expand Down Expand Up @@ -855,9 +855,17 @@ void NatPunchthroughClient::SendOutOfBand(SystemAddress sa, MessageID oobId)
RakNet::Time serverTime = RakNet::GetTime() + clockDifferential;

if (oobId==ID_NAT_ESTABLISH_UNIDIRECTIONAL)
#if defined(_WIN32)
natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("%I64d: %s: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid %s, system address %s.\n", serverTime, TestModeToString(sp.testMode), guidString, ipAddressString));
#else
natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("%lld: %s: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid %s, system address %s.\n", serverTime, TestModeToString(sp.testMode), guidString, ipAddressString));
#endif
else
#if defined(_WIN32)
natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("%I64d: %s: OOB ID_NAT_ESTABLISH_BIDIRECTIONAL to guid %s, system address %s.\n", serverTime, TestModeToString(sp.testMode), guidString, ipAddressString));
#else
natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("%lld: %s: OOB ID_NAT_ESTABLISH_BIDIRECTIONAL to guid %s, system address %s.\n", serverTime, TestModeToString(sp.testMode), guidString, ipAddressString));
#endif
}
}
void NatPunchthroughClient::OnNewConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
Expand Down
4 changes: 2 additions & 2 deletions Source/PacketizedTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ bool PacketizedTCP::SendList( const char **data, const unsigned int *lengths, co
#endif


unsigned int lengthsArray[512];
const char *dataArray[512];
unsigned int lengthsArray[513];
const char *dataArray[513];
dataArray[0]=(char*) &dataLength;
lengthsArray[0]=sizeof(dataLength);
for (int i=0; i < 512 && i < numParameters; i++)
Expand Down
2 changes: 1 addition & 1 deletion Source/RakNetSocket2_Berkley_NativeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void DomainNameToIP_Berkley_IPV4And6( const char *domainName, char ip[65] )
hints.ai_socktype = SOCK_DGRAM;

if ((status = getaddrinfo(domainName, NULL, &hints, &res)) != 0) {
memset(ip, 0, sizeof(ip));
memset(ip, 0, 65); // sizeof(ip) returns pointer size, not array size
return;
}

Expand Down
102 changes: 59 additions & 43 deletions Source/RakPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ static const int mtuSizes[NUM_MTU_SIZES]={MAXIMUM_MTU_SIZE, 1200, 576};

using namespace RakNet;

static RakNetRandom rnr;

/*
struct RakPeerAndIndex
{
Expand Down Expand Up @@ -400,11 +398,6 @@ StartupResult RakPeer::Startup( unsigned int maxConnections, SocketDescriptor *s

FillIPList();

if (myGuid==UNASSIGNED_RAKNET_GUID)
{
rnr.SeedMT( GenerateSeedFromGuid() );
}

//RakPeerAndIndex rpai[32];
//RakAssert(socketDescriptorCount<32);

Expand Down Expand Up @@ -1685,28 +1678,41 @@ void RakPeer::CloseConnection( const AddressOrGUID target, bool sendDisconnectio
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void RakPeer::CancelConnectionAttempt( const SystemAddress target )
{
unsigned int i;
requestedConnectionCancelQueueMutex.Lock();
requestedConnectionCancelQueue.Push(target, _FILE_AND_LINE_ );
requestedConnectionCancelQueueMutex.Unlock();
}

// Cancel pending connection attempt, if there is one
i=0;
requestedConnectionQueueMutex.Lock();
while (i < requestedConnectionQueue.Size())
void RakPeer::HandleConnectionCancelQueue( )
{
requestedConnectionCancelQueueMutex.Lock();
while (requestedConnectionCancelQueue.Size() > 0)
{
if (requestedConnectionQueue[i]->systemAddress==target)
unsigned int i;

// Cancel pending connection attempt, if there is one
i=0;
requestedConnectionQueueMutex.Lock();
while (i < requestedConnectionQueue.Size())
{
if (requestedConnectionQueue[i]->systemAddress==requestedConnectionCancelQueue[0])
{
#if LIBCAT_SECURITY==1
CAT_AUDIT_PRINTF("AUDIT: Deleting requestedConnectionQueue %i client_handshake %x\n", i, requestedConnectionQueue[ i ]->client_handshake);
RakNet::OP_DELETE(requestedConnectionQueue[i]->client_handshake, _FILE_AND_LINE_ );
CAT_AUDIT_PRINTF("AUDIT: Deleting requestedConnectionQueue %i client_handshake %x\n", i, requestedConnectionQueue[ i ]->client_handshake);
RakNet::OP_DELETE(requestedConnectionQueue[i]->client_handshake, _FILE_AND_LINE_ );
#endif
RakNet::OP_DELETE(requestedConnectionQueue[i], _FILE_AND_LINE_ );
requestedConnectionQueue.RemoveAtIndex(i);
break;
RakNet::OP_DELETE(requestedConnectionQueue[i], _FILE_AND_LINE_ );
requestedConnectionQueue.RemoveAtIndex(i);
break;
}
else
i++;
}
else
i++;
}
requestedConnectionQueueMutex.Unlock();
requestedConnectionQueueMutex.Unlock();

requestedConnectionCancelQueue.RemoveAtIndex(0);
}
requestedConnectionCancelQueueMutex.Unlock();
}

// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -2559,7 +2565,7 @@ RakNet::TimeMS RakPeer::GetTimeoutTime( const SystemAddress target )
RemoteSystemStruct * remoteSystem = GetRemoteSystemFromSystemAddress( target, false, true );

if ( remoteSystem != 0 )
remoteSystem->reliabilityLayer.GetTimeoutTime();
return remoteSystem->reliabilityLayer.GetTimeoutTime();
}
return defaultTimeoutTime;
}
Expand Down Expand Up @@ -3778,6 +3784,7 @@ void RakPeer::ShiftIncomingTimestamp( unsigned char *data, const SystemAddress &
#endif

RakNet::BitStream timeBS( data, sizeof(RakNet::Time), false);
timeBS.EndianSwapBytes(0,sizeof(RakNet::Time));
RakNet::Time encodedTimestamp;
timeBS.Read(encodedTimestamp);

Expand Down Expand Up @@ -4495,31 +4502,38 @@ uint64_t RakPeerInterface::Get64BitUniqueRandomNumber(void)



uint64_t g;
#if defined(_WIN32)
uint64_t g=RakNet::GetTimeUS();
g = RakNet::GetTimeUS();
#else
struct timeval tv;
gettimeofday(&tv, NULL);
g = tv.tv_usec + tv.tv_sec * 1000000;
#endif

RakNet::TimeUS lastTime, thisTime;
int j;
// Sleep a small random time, then use the last 4 bits as a source of randomness
for (j=0; j < 8; j++)
for (j=0; j < 4; j++)
{
lastTime = RakNet::GetTimeUS();
RakSleep(1);
RakSleep(0);
thisTime = RakNet::GetTimeUS();
RakNet::TimeUS diff = thisTime-lastTime;
unsigned int diff4Bits = (unsigned int) (diff & 15);
diff4Bits <<= 32-4;
diff4Bits >>= j*4;
((char*)&g)[j] ^= diff4Bits;
unsigned char diffByte = 0;
for (int i=0; i < 4; i++)
{
lastTime = RakNet::GetTimeUS();
RakSleep(1);
RakSleep(0);
thisTime = RakNet::GetTimeUS();
RakNet::TimeUS diff = thisTime-lastTime;
diffByte ^= (unsigned char) ((diff & 15) << (i * 2));
if (i == 3)
{
diffByte ^= (unsigned char) ((diff & 15) >> 2);
}
}

((char*)&g)[4 + j] ^= diffByte;
}
return g;

#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_usec + tv.tv_sec * 1000000;
#endif
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void RakPeer::GenerateGUID(void)
Expand Down Expand Up @@ -5459,7 +5473,7 @@ void ProcessNetworkPacket( SystemAddress systemAddress, const char *data, const
{
remoteSystem->reliabilityLayer.HandleSocketReceiveFromConnectedPlayer(
data, length, systemAddress, rakPeer->pluginListNTS, remoteSystem->MTUSize,
rakNetSocket, &rnr, timeRead, updateBitStream);
rakNetSocket, timeRead, updateBitStream);
}
}
else
Expand Down Expand Up @@ -5497,7 +5511,7 @@ void RakPeer::DerefAllSockets(void)
unsigned int i;
for (i=0; i < socketList.Size(); i++)
{
delete socketList[i];
RakNet::OP_DELETE(socketList[i], _FILE_AND_LINE_);
}
socketList.Clear(false, _FILE_AND_LINE_);
}
Expand Down Expand Up @@ -5688,6 +5702,8 @@ bool RakPeer::RunUpdateCycle(BitStream &updateBitStream )
bufferedCommands.Deallocate(bcs, _FILE_AND_LINE_);
}

HandleConnectionCancelQueue();

if (requestedConnectionQueue.IsEmpty()==false)
{
if (timeNS==0)
Expand Down Expand Up @@ -5868,7 +5884,7 @@ bool RakPeer::RunUpdateCycle(BitStream &updateBitStream )
}
}

remoteSystem->reliabilityLayer.Update( remoteSystem->rakNetSocket, systemAddress, remoteSystem->MTUSize, timeNS, maxOutgoingBPS, pluginListNTS, &rnr, updateBitStream ); // systemAddress only used for the internet simulator test
remoteSystem->reliabilityLayer.Update( remoteSystem->rakNetSocket, systemAddress, remoteSystem->MTUSize, timeNS, maxOutgoingBPS, pluginListNTS, updateBitStream ); // systemAddress only used for the internet simulator test

// Check for failure conditions
if ( remoteSystem->reliabilityLayer.IsDeadConnection() ||
Expand Down
3 changes: 3 additions & 0 deletions Source/RakPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ class RAK_DLL_EXPORT RakPeer : public RakPeerInterface, public RNS2EventHandler
// Two versions needed because some buggy compilers strip the last parameter if unused, and crashes
ConnectionAttemptResult SendConnectionRequest( const char* host, unsigned short remotePort, const char *passwordData, int passwordDataLength, PublicKey *publicKey, unsigned connectionSocketIndex, unsigned int extraData, unsigned sendConnectionAttemptCount, unsigned timeBetweenSendConnectionAttemptsMS, RakNet::TimeMS timeoutTime, RakNetSocket2* socket );
ConnectionAttemptResult SendConnectionRequest( const char* host, unsigned short remotePort, const char *passwordData, int passwordDataLength, PublicKey *publicKey, unsigned connectionSocketIndex, unsigned int extraData, unsigned sendConnectionAttemptCount, unsigned timeBetweenSendConnectionAttemptsMS, RakNet::TimeMS timeoutTime );
void HandleConnectionCancelQueue( );
///Get the reliability layer associated with a systemAddress.
/// \param[in] systemAddress The player identifier
/// \return 0 if none
Expand Down Expand Up @@ -864,7 +865,9 @@ class RAK_DLL_EXPORT RakPeer : public RakPeerInterface, public RNS2EventHandler
DataStructures::List<PluginInterface2*> pluginListTS, pluginListNTS;

DataStructures::Queue<RequestedConnectionStruct*> requestedConnectionQueue;
DataStructures::Queue<SystemAddress> requestedConnectionCancelQueue;
SimpleMutex requestedConnectionQueueMutex;
SimpleMutex requestedConnectionCancelQueueMutex;

// void RunMutexedUpdateCycle(void);

Expand Down
2 changes: 1 addition & 1 deletion Source/RakString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ void RakString::Assign(const char *str, va_list ap)
if (_vsnprintf(stackBuff, 512, str, ap)!=-1
#ifndef _WIN32
// Here Windows will return -1 if the string is too long; Linux just truncates the string.
&& strlen(str) <511
&& strlen(stackBuff) <511
#endif
)
{
Expand Down
Loading

0 comments on commit add146f

Please sign in to comment.