This commit is contained in:
2025-11-24 14:19:51 +05:30
commit f5c1412b28
6734 changed files with 1527575 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#
# This file was taken from RakNet 4.082.
# Please see licenses/RakNet license.txt for the underlying license and related copyright.
#
#
# Modified work: Copyright (c) 2017-2019, SLikeSoft UG (haftungsbeschränkt)
#
# This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
# license found in the license.txt file in the root directory of this source tree.
#
cmake_minimum_required(VERSION 2.6)
GETCURRENTFOLDER()
project(${current_folder})
include_directories(${SLIKENET_HEADER_FILES} ./)
add_executable(${current_folder} DirectoryDeltaTransferTest.cpp)
target_link_libraries(${current_folder} ${SLIKENET_COMMON_LIBS})
set_target_properties(${current_folder} PROPERTIES PROJECT_GROUP Samples)

View File

@ -0,0 +1,181 @@
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*/
#include "RakNetworkFactory.h"
#include "GetTime.h"
#include "RakPeerInterface.h"
#include "PacketEnumerations.h"
#include "RakNetStatistics.h"
#include "DirectoryDeltaTransfer.h"
#include "FileListTransfer.h"
#include <cstdio>
#include <stdlib.h>
#include <conio.h>
#include "FileList.h"
#include "DataCompressor.h"
#include "FileListTransferCBInterface.h"
#ifdef _WIN32
#include <windows.h> // Sleep
#else
#include <unistd.h> // usleep
#endif
class TestCB : public FileListTransferCBInterface
{
public:
void OnFile(
unsigned fileIndex,
char *filename,
unsigned char *fileData,
unsigned compressedTransmissionLength,
unsigned finalDataLength,
unsigned short setID,
unsigned setCount,
unsigned setTotalCompressedTransmissionLength,
unsigned setTotalFinalLength)
{
printf("%i. %i/%i %s %ib->%ib / %ib->%ib\n", setID, fileIndex, setCount, filename, compressedTransmissionLength, finalDataLength, setTotalCompressedTransmissionLength, setTotalFinalLength);
}
} transferCallback;
int main(void)
{
char ch;
RakPeerInterface *rakPeer;
// directoryDeltaTransfer is the main plugin that does the work for this sample.
DirectoryDeltaTransfer directoryDeltaTransfer;
// The fileListTransfer plugin is used by the DirectoryDeltaTransfer plugin and must also be registered (you could use this yourself too if you wanted, of course).
FileListTransfer fileListTransfer;
rakPeer = RakNetworkFactory::GetRakPeerInterface();
rakPeer->AttachPlugin(&directoryDeltaTransfer);
rakPeer->AttachPlugin(&fileListTransfer);
directoryDeltaTransfer.SetFileListTransferPlugin(&fileListTransfer);
printf("This sample demonstrates the plugin to incrementally transfer compressed\n");
printf("deltas of directories. In essence, it's a simple autopatcher.\n");
printf("Unlike the full autopatcher, it has no dependencies. It is suitable for\n");
printf("patching from non-dedicated servers at runtime.\n");
printf("Difficulty: Intermediate\n\n");
printf("Enter listen port, or hit enter to choose automatically\n");
unsigned short localPort;
char str[256];
gets(str);
if (str[0]==0)
localPort=60000;
else
localPort=atoi(str);
if (rakPeer->Initialize(8,localPort,30,0)==false)
{
RakNetworkFactory::DestroyRakPeerInterface(rakPeer);
printf("RakNet initialize failed. Possibly duplicate port.\n");
return 1;
}
rakPeer->SetMaximumIncomingConnections(8);
printf("Commands:\n");
printf("(S)et application directory.\n");
printf("(A)dd allowed uploads from subdirectory.\n");
printf("(D)ownload from subdirectory.\n");
printf("(C)lear allowed uploads.\n");
printf("C(o)nnect to another system.\n");
printf("(Q)uit.\n");
Packet *p;
while (1)
{
// Process packets
p=rakPeer->Receive();
while (p)
{
if (p->data[0]==ID_NEW_INCOMING_CONNECTION)
printf("ID_NEW_INCOMING_CONNECTION\n");
else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
rakPeer->DeallocatePacket(p);
p=rakPeer->Receive();
}
if (kbhit())
{
ch=getch();
if (ch=='s')
{
printf("Enter application directory\n");
gets(str);
if (str[0]==0)
strcpy(str, "C:/RakNet");
directoryDeltaTransfer.SetApplicationDirectory(str);
printf("This directory will be prefixed to upload and download subdirectories.\n");
}
else if (ch=='a')
{
printf("Enter uploads subdirectory\n");
gets(str);
directoryDeltaTransfer.AddUploadsFromSubdirectory(str);
printf("%i files for upload.\n", directoryDeltaTransfer.GetNumberOfFilesForUpload());
}
else if (ch=='d')
{
char subdir[256];
char outputSubdir[256];
printf("Enter remote subdirectory to download from.\n");
printf("This directory may be any uploaded directory, or a subdir therein.\n");
gets(subdir);
printf("Enter subdirectory to output to.\n");
gets(outputSubdir);
unsigned short setId;
setId=directoryDeltaTransfer.DownloadFromSubdirectory(subdir, outputSubdir, true, rakPeer->GetPlayerIDFromIndex(0), &transferCallback, HIGH_PRIORITY, 0);
if (setId==(unsigned short)-1)
printf("Download failed. Host unreachable.\n");
else
printf("Downloading set %i\n", setId);
}
else if (ch=='c')
{
directoryDeltaTransfer.ClearUploads();
printf("Uploads cleared.\n");
}
else if (ch=='o')
{
char host[256];
printf("Enter host IP: ");
gets(host);
if (host[0]==0)
strcpy(host, "127.0.0.1");
unsigned short remotePort;
printf("Enter host port: ");
gets(str);
if (str[0]==0)
remotePort=60000;
else
remotePort=atoi(str);
rakPeer->Connect(host, remotePort, 0, 0);
printf("Connecting.\n");
}
else if (ch=='q')
{
printf("Bye!\n");
break;
}
}
}
RakNetworkFactory::DestroyRakPeerInterface(rakPeer);
return 0;
}

View File

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug - Unicode|Win32">
<Configuration>Debug - Unicode</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release - Unicode|Win32">
<Configuration>Release - Unicode</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Retail - Unicode|Win32">
<Configuration>Retail - Unicode</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Retail|Win32">
<Configuration>Retail</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>DirectoryDeltaTransfer</ProjectName>
<ProjectGuid>{BC349AD2-94A3-4D99-BFD1-02ED5D3F103E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">$(Configuration)\</OutDir>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">*.obj%3b*.ilk%3b*.pdb%3b*.tlb%3b*.tli%3b*.tlh%3b*.tmp%3b*.rsp%3b*.bat%3b$(TargetPath)</ExtensionsToDeleteOnClean>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">*.obj%3b*.ilk%3b*.pdb%3b*.tlb%3b*.tli%3b*.tlh%3b*.tmp%3b*.rsp%3b*.bat%3b$(TargetPath)</ExtensionsToDeleteOnClean>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">$(Configuration)\</OutDir>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">*.obj%3b*.ilk%3b*.pdb%3b*.tlb%3b*.tli%3b*.tlh%3b*.tmp%3b*.rsp%3b*.bat%3b$(TargetPath)</ExtensionsToDeleteOnClean>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">*.obj%3b*.ilk%3b*.pdb%3b*.tlb%3b*.tli%3b*.tlh%3b*.tmp%3b*.rsp%3b*.bat%3b$(TargetPath)</ExtensionsToDeleteOnClean>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">*.obj%3b*.ilk%3b*.pdb%3b*.tlb%3b*.tli%3b*.tlh%3b*.tmp%3b*.rsp%3b*.bat%3b$(TargetPath)</ExtensionsToDeleteOnClean>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">*.obj%3b*.ilk%3b*.pdb%3b*.tlb%3b*.tli%3b*.tlh%3b*.tmp%3b*.rsp%3b*.bat%3b$(TargetPath)</ExtensionsToDeleteOnClean>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Debug_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)DirectoryDeltaTransfer.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug - Unicode|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Debug - Unicode_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)DirectoryDeltaTransfer.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<MinimalRebuild>true</MinimalRebuild>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Release_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMTD.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Retail|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;WIN32;_RETAIL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<MinimalRebuild>true</MinimalRebuild>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Retail_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMTD.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release - Unicode|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<MinimalRebuild>true</MinimalRebuild>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Release - Unicode_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMTD.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Retail - Unicode|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>./../../Source/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;WIN32;_RETAIL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<MinimalRebuild>true</MinimalRebuild>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>./../../Lib/SLikeNet_LibStatic_Retail - Unicode_Win32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMTD.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DirectoryDeltaTransferTest.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Lib\LibStatic\LibStatic.vcxproj">
<Project>{6533bdae-0f0c-45e4-8fe7-add0f37fe063}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DirectoryDeltaTransferTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,325 @@
/*
* Original work: Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* RakNet License.txt file in the licenses directory of this source tree. An additional grant
* of patent rights can be found in the RakNet Patents.txt file in the same directory.
*
*
* Modified work: Copyright (c) 2016-2017, SLikeSoft UG (haftungsbeschränkt)
*
* This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
* license found in the license.txt file in the root directory of this source tree.
*/
#include "slikenet/GetTime.h"
#include "slikenet/peerinterface.h"
#include "slikenet/MessageIdentifiers.h"
#include "slikenet/statistics.h"
#include "slikenet/DirectoryDeltaTransfer.h"
#include "slikenet/FileListTransfer.h"
#include <cstdio>
#include <stdlib.h>
#include <limits> // used for std::numeric_limits
#include "slikenet/Kbhit.h"
#include "slikenet/FileList.h"
#include "slikenet/DataCompressor.h"
#include "slikenet/FileListTransferCBInterface.h"
#include "slikenet/sleep.h"
#include "slikenet/IncrementalReadInterface.h"
#include "slikenet/PacketizedTCP.h"
#include "slikenet/Gets.h"
#include "slikenet/linux_adapter.h"
#include "slikenet/osx_adapter.h"
#ifdef _WIN32
#include "slikenet/WindowsIncludes.h" // Sleep
#else
#include <unistd.h> // usleep
#endif
#define USE_TCP
class TestCB : public SLNet::FileListTransferCBInterface
{
public:
bool OnFile(
OnFileStruct *onFileStruct)
{
assert(onFileStruct->byteLengthOfThisFile >= onFileStruct->bytesDownloadedForThisFile);
printf("%i. (100%%) %i/%i %s %ib / %ib\n", onFileStruct->setID, onFileStruct->fileIndex+1, onFileStruct->numberOfFilesInThisSet, onFileStruct->fileName, onFileStruct->byteLengthOfThisFile, onFileStruct->byteLengthOfThisSet);
// Return true to have RakNet delete the memory allocated to hold this file.
// False if you hold onto the memory, and plan to delete it yourself later
return true;
}
virtual void OnFileProgress(FileProgressStruct *fps)
{
assert(fps->onFileStruct->byteLengthOfThisFile >= fps->onFileStruct->bytesDownloadedForThisFile);
printf("%i (%i%%) %i/%i %s %ib / %ib\n", fps->onFileStruct->setID, (int) (100.0*(double)fps->partCount/(double)fps->partTotal),
fps->onFileStruct->fileIndex+1,
fps->onFileStruct->numberOfFilesInThisSet,
fps->onFileStruct->fileName,
fps->onFileStruct->byteLengthOfThisFile,
fps->onFileStruct->byteLengthOfThisSet);
}
virtual bool OnDownloadComplete(DownloadCompleteStruct *dcs)
{
// unused parameters
(void)dcs;
printf("Download complete.\n");
// Returning false automatically deallocates the automatically allocated handler that was created by DirectoryDeltaTransfer
return false;
}
} transferCallback;
int main(void)
{
int ch;
#ifdef USE_TCP
SLNet::PacketizedTCP tcp1;
#else
SLNet::RakPeerInterface *rakPeer;
#endif
// directoryDeltaTransfer is the main plugin that does the work for this sample.
SLNet::DirectoryDeltaTransfer directoryDeltaTransfer;
// The fileListTransfer plugin is used by the DirectoryDeltaTransfer plugin and must also be registered (you could use this yourself too if you wanted, of course).
SLNet::FileListTransfer fileListTransfer;
// Read files in parts, rather than the whole file from disk at once
SLNet::IncrementalReadInterface iri;
directoryDeltaTransfer.SetDownloadRequestIncrementalReadInterface(&iri, 1000000);
#ifdef USE_TCP
tcp1.AttachPlugin(&directoryDeltaTransfer);
tcp1.AttachPlugin(&fileListTransfer);
#else
rakPeer = SLNet::RakPeerInterface::GetInstance();
rakPeer->AttachPlugin(&directoryDeltaTransfer);
rakPeer->AttachPlugin(&fileListTransfer);
// Get download progress notifications. Handled by the plugin.
rakPeer->SetSplitMessageProgressInterval(100);
#endif
directoryDeltaTransfer.SetFileListTransferPlugin(&fileListTransfer);
printf("This sample demonstrates the plugin to incrementally transfer compressed\n");
printf("deltas of directories. In essence, it's a simple autopatcher.\n");
printf("Unlike the full autopatcher, it has no dependencies. It is suitable for\n");
printf("patching from non-dedicated servers at runtime.\n");
printf("Difficulty: Intermediate\n\n");
printf("Enter listen port. Enter for default. If running two instances on the\nsame computer, use 0 for the client.\n");
unsigned short localPort;
char str[256];
Gets(str, sizeof(str));
if (str[0]==0)
localPort=60000;
else {
const int intLocalPort = atoi(str);
if ((intLocalPort < 0) || (intLocalPort > std::numeric_limits<unsigned short>::max())) {
printf("Specified local port %d is outside valid bounds [0, %u]", intLocalPort, std::numeric_limits<unsigned short>::max());
return 2;
}
localPort = static_cast<unsigned short>(intLocalPort);
}
SLNet::SocketDescriptor socketDescriptor(localPort,0);
#ifdef USE_TCP
SLNET_VERIFY(tcp1.Start(localPort, 8));
#else
if (rakPeer->Startup(8,&socketDescriptor, 1)!= SLNet::RAKNET_STARTED)
{
SLNet::RakPeerInterface::DestroyInstance(rakPeer);
printf("RakNet initialize failed. Possibly duplicate port.\n");
return 1;
}
rakPeer->SetMaximumIncomingConnections(8);
#endif
printf("Commands:\n");
printf("(S)et application directory.\n");
printf("(A)dd allowed uploads from subdirectory.\n");
printf("(D)ownload from subdirectory.\n");
printf("(C)lear allowed uploads.\n");
printf("C(o)nnect to another system.\n");
printf("(Q)uit.\n");
SLNet::SystemAddress sysAddrZero= SLNet::UNASSIGNED_SYSTEM_ADDRESS;
// SLNet::TimeMS nextStatTime = SLNet::GetTimeMS() + 1000;
SLNet::Packet *p;
for(;;)
{
/*
if (//directoryDeltaTransfer.GetNumberOfFilesForUpload()>0 &&
SLNet::GetTimeMS() > nextStatTime)
{
// If sending, periodically show connection stats
char statData[2048];
RakNetStatistics *statistics = rakPeer->GetStatistics(rakPeer->GetSystemAddressFromIndex(0));
// if (statistics->messagesOnResendQueue>0 || statistics->internalOutputQueueSize>0)
if (rakPeer->GetSystemAddressFromIndex(0)!=SLNet::UNASSIGNED_SYSTEM_ADDRESS)
{
StatisticsToString(statistics, statData, 2048, 2);
printf("%s\n", statData);
}
nextStatTime=SLNet::GetTimeMS()+5000;
}
*/
// Process packets
#ifdef USE_TCP
p=tcp1.Receive();
#else
p=rakPeer->Receive();
#endif
#ifdef USE_TCP
SLNet::SystemAddress sa;
sa=tcp1.HasNewIncomingConnection();
if (sa!= SLNet::UNASSIGNED_SYSTEM_ADDRESS)
{
printf("ID_NEW_INCOMING_CONNECTION\n");
sysAddrZero=sa;
}
if (tcp1.HasLostConnection()!= SLNet::UNASSIGNED_SYSTEM_ADDRESS)
printf("ID_DISCONNECTION_NOTIFICATION\n");
if (tcp1.HasFailedConnectionAttempt()!= SLNet::UNASSIGNED_SYSTEM_ADDRESS)
printf("ID_CONNECTION_ATTEMPT_FAILED\n");
sa=tcp1.HasCompletedConnectionAttempt();
if (sa!= SLNet::UNASSIGNED_SYSTEM_ADDRESS)
{
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
sysAddrZero=sa;
}
#endif
while (p)
{
#ifdef USE_TCP
tcp1.DeallocatePacket(p);
tcp1.Receive();
#else
if (p->data[0]==ID_NEW_INCOMING_CONNECTION)
{
printf("ID_NEW_INCOMING_CONNECTION\n");
sysAddrZero=p->systemAddress;
}
else if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
{
printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
sysAddrZero=p->systemAddress;
}
else if (p->data[0]==ID_DISCONNECTION_NOTIFICATION)
printf("ID_DISCONNECTION_NOTIFICATION\n");
else if (p->data[0]==ID_CONNECTION_LOST)
printf("ID_CONNECTION_LOST\n");
else if (p->data[0]==ID_CONNECTION_ATTEMPT_FAILED)
printf("ID_CONNECTION_ATTEMPT_FAILED\n");
rakPeer->DeallocatePacket(p);
p=rakPeer->Receive();
#endif
}
if (_kbhit())
{
ch=_getch();
if (ch=='s')
{
printf("Enter application directory\n");
Gets(str, sizeof(str));
if (str[0]==0)
strcpy_s(str, "C:/Temp");
directoryDeltaTransfer.SetApplicationDirectory(str);
printf("This directory will be prefixed to upload and download subdirectories.\n");
}
else if (ch=='a')
{
printf("Enter uploads subdirectory\n");
Gets(str, sizeof(str));
directoryDeltaTransfer.AddUploadsFromSubdirectory(str);
printf("%i files for upload.\n", directoryDeltaTransfer.GetNumberOfFilesForUpload());
}
else if (ch=='d')
{
char subdir[256];
char outputSubdir[256];
printf("Enter remote subdirectory to download from.\n");
printf("This directory may be any uploaded directory, or a subdir therein.\n");
Gets(subdir,sizeof(subdir));
printf("Enter subdirectory to output to.\n");
Gets(outputSubdir,sizeof(outputSubdir));
unsigned short setId;
setId=directoryDeltaTransfer.DownloadFromSubdirectory(subdir, outputSubdir, true, sysAddrZero, &transferCallback, HIGH_PRIORITY, 0, 0);
if (setId==(unsigned short)-1)
printf("Download failed. Host unreachable.\n");
else
printf("Downloading set %i\n", setId);
}
else if (ch=='c')
{
directoryDeltaTransfer.ClearUploads();
printf("Uploads cleared.\n");
}
else if (ch=='o')
{
char host[256];
printf("Enter host IP: ");
Gets(host,sizeof(host));
if (host[0]==0)
strcpy_s(host, "127.0.0.1");
unsigned short remotePort;
printf("Enter host port: ");
Gets(str, sizeof(str));
if (str[0]==0)
remotePort=60000;
else {
const int intRemotePort = atoi(str);
if ((intRemotePort < 0) || (intRemotePort > std::numeric_limits<unsigned short>::max())) {
printf("Specified remote port %d is outside valid bounds [0, %u]", intRemotePort, std::numeric_limits<unsigned short>::max());
return 3;
}
remotePort = static_cast<unsigned short>(intRemotePort);
}
#ifdef USE_TCP
tcp1.Connect(host,remotePort,false);
#else
rakPeer->Connect(host, remotePort, 0, 0);
#endif
printf("Connecting.\n");
}
else if (ch=='q')
{
printf("Bye!\n");
#ifdef USE_TCP
tcp1.Stop();
#else
rakPeer->Shutdown(1000,0);
#endif
break;
}
}
// Keeps the threads responsive
RakSleep(0);
}
#ifdef USE_TCP
#else
SLNet::RakPeerInterface::DestroyInstance(rakPeer);
#endif
return 0;
}