Init
This commit is contained in:
14
Samples/TwoWayAuthentication/CMakeLists.txt
Normal file
14
Samples/TwoWayAuthentication/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
#
|
||||
# This file was taken from RakNet 4.082 without any modifications.
|
||||
# Please see licenses/RakNet license.txt for the underlying license and related copyright.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
GETCURRENTFOLDER()
|
||||
STANDARDSUBPROJECT(${current_folder})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
251
Samples/TwoWayAuthentication/TwoWayAuthentication.vcxproj
Normal file
251
Samples/TwoWayAuthentication/TwoWayAuthentication.vcxproj
Normal file
@ -0,0 +1,251 @@
|
||||
<?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">
|
||||
<ProjectGuid>{F860F6E8-5B0F-4892-99B3-69E5CDA1102A}</ProjectGuid>
|
||||
<RootNamespace>TwoWayAuthentication</RootNamespace>
|
||||
<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" />
|
||||
</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" />
|
||||
</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" />
|
||||
</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" />
|
||||
</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" />
|
||||
</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" />
|
||||
</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>
|
||||
<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>
|
||||
<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>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>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<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>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>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<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>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>
|
||||
<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>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>
|
||||
<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>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>
|
||||
<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>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>
|
||||
<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="TwoWayAuthenticationTest.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>
|
||||
@ -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;cc;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="TwoWayAuthenticationTest.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
191
Samples/TwoWayAuthentication/TwoWayAuthenticationTest.cpp
Normal file
191
Samples/TwoWayAuthentication/TwoWayAuthenticationTest.cpp
Normal file
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* 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) 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 <cstdio>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
#include "slikenet/GetTime.h"
|
||||
#include "slikenet/Rand.h"
|
||||
#include "slikenet/peerinterface.h"
|
||||
#include "slikenet/MessageIdentifiers.h"
|
||||
#include "slikenet/BitStream.h"
|
||||
#include "slikenet/TwoWayAuthentication.h"
|
||||
#include "slikenet/sleep.h"
|
||||
|
||||
static const int NUM_PEERS=2;
|
||||
SLNet::RakPeerInterface *rakPeer[NUM_PEERS];
|
||||
SLNet::TwoWayAuthentication *twoWayAuthenticationPlugin[NUM_PEERS];
|
||||
int main(void)
|
||||
{
|
||||
for (int i=0; i < NUM_PEERS; i++)
|
||||
rakPeer[i]= SLNet::RakPeerInterface::GetInstance();
|
||||
|
||||
printf("This project tests and demonstrates the two way authentication plugin.\n");
|
||||
printf("Difficulty: Beginner\n\n");
|
||||
|
||||
// Initialize the message handlers
|
||||
for (unsigned short peerIndex=0; peerIndex < NUM_PEERS; peerIndex++)
|
||||
{
|
||||
twoWayAuthenticationPlugin[peerIndex]= SLNet::OP_NEW<SLNet::TwoWayAuthentication>(_FILE_AND_LINE_);
|
||||
rakPeer[peerIndex]->AttachPlugin(twoWayAuthenticationPlugin[peerIndex]);
|
||||
rakPeer[peerIndex]->SetMaximumIncomingConnections(NUM_PEERS);
|
||||
}
|
||||
|
||||
// Initialize the peers
|
||||
for (unsigned short peerIndex=0; peerIndex < NUM_PEERS; peerIndex++)
|
||||
{
|
||||
SLNet::SocketDescriptor socketDescriptor(60000+peerIndex,0);
|
||||
rakPeer[peerIndex]->Startup(NUM_PEERS, &socketDescriptor, 1);
|
||||
}
|
||||
|
||||
// Connect each peer to the prior peer
|
||||
for (unsigned short peerIndex=1; peerIndex < NUM_PEERS; peerIndex++)
|
||||
{
|
||||
rakPeer[peerIndex]->Connect("127.0.0.1", 60000+peerIndex-1, 0, 0);
|
||||
}
|
||||
|
||||
RakSleep(100);
|
||||
|
||||
|
||||
printf("Peers initialized and connected.\n");
|
||||
twoWayAuthenticationPlugin[0]->AddPassword("PWD0", "Password0");
|
||||
twoWayAuthenticationPlugin[0]->AddPassword("PWD1", "Password1");
|
||||
twoWayAuthenticationPlugin[1]->AddPassword("PWD0", "Password0");
|
||||
SLNET_VERIFY(twoWayAuthenticationPlugin[0]->Challenge("PWD0", rakPeer[0]->GetGUIDFromIndex(0)));
|
||||
printf("Stage 0, instance 0 challenges instance 1 (should pass)\n");
|
||||
int stage=0;
|
||||
int stage4FailureCount=0;
|
||||
int passCount=0;
|
||||
bool quit=false;
|
||||
|
||||
while (!quit)
|
||||
{
|
||||
SLNet::Packet *packet;
|
||||
for (unsigned short peerIndex=0; peerIndex < NUM_PEERS; peerIndex++)
|
||||
{
|
||||
packet=rakPeer[peerIndex]->Receive();
|
||||
if (packet)
|
||||
{
|
||||
switch (packet->data[0])
|
||||
{
|
||||
case ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_SUCCESS:
|
||||
case ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_SUCCESS:
|
||||
{
|
||||
SLNet::BitStream bs(packet->data, packet->length, false);
|
||||
bs.IgnoreBytes(sizeof(SLNet::MessageID));
|
||||
SLNet::RakString password;
|
||||
bs.Read(password);
|
||||
if (packet->data[0]==ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_SUCCESS)
|
||||
printf("ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_SUCCESS with %s from %s\n", password.C_String(), packet->systemAddress.ToString(true));
|
||||
else
|
||||
printf("ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_SUCCESS with %s from %s\n", password.C_String(), packet->systemAddress.ToString(true));
|
||||
if (++passCount==2)
|
||||
{
|
||||
if (stage<=2)
|
||||
{
|
||||
if (stage==0)
|
||||
{
|
||||
printf("Stage 1, instance 1 challenges instance 0 (should pass)\n");
|
||||
twoWayAuthenticationPlugin[1]->Challenge("PWD0", rakPeer[1]->GetGUIDFromIndex(0));
|
||||
passCount=0;
|
||||
// stage==1
|
||||
}
|
||||
else if (stage==1)
|
||||
{
|
||||
printf("Stage 2, instance 1 re-challenges instance 0 (should pass)\n");
|
||||
twoWayAuthenticationPlugin[1]->Challenge("PWD0", rakPeer[1]->GetGUIDFromIndex(0));
|
||||
passCount=0;
|
||||
// stage==2
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Stage 3, instance 0 challenges with bad password (call should fail)\n");
|
||||
if (twoWayAuthenticationPlugin[0]->Challenge("PWD3", rakPeer[0]->GetGUIDFromIndex(0))==false)
|
||||
{
|
||||
printf("Passed stage 3\n");
|
||||
stage++;
|
||||
printf("Stage 4, instance 0 challenges with unknown password (should fail twice)\n");
|
||||
twoWayAuthenticationPlugin[0]->Challenge("PWD1", rakPeer[0]->GetGUIDFromIndex(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed stage 3, Challenge() did not return false\n");
|
||||
}
|
||||
}
|
||||
stage++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_FAILURE:
|
||||
{
|
||||
printf("ID_TWO_WAY_AUTHENTICATION_INCOMING_CHALLENGE_FAILED from %s\n", packet->systemAddress.ToString(true));
|
||||
if (stage!=4)
|
||||
{
|
||||
printf("Failed stage %i\n", stage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (++stage4FailureCount==2)
|
||||
quit=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_TIMEOUT:
|
||||
{
|
||||
SLNet::BitStream bs(packet->data, packet->length, false);
|
||||
bs.IgnoreBytes(sizeof(SLNet::MessageID));
|
||||
SLNet::RakString password;
|
||||
bs.Read(password);
|
||||
printf("ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_TIMEOUT with %s from %s\n", password.C_String(), packet->systemAddress.ToString(true));
|
||||
printf("Failed stage %i\n", stage);
|
||||
}
|
||||
break;
|
||||
case ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_FAILURE:
|
||||
{
|
||||
SLNet::BitStream bs(packet->data, packet->length, false);
|
||||
bs.IgnoreBytes(sizeof(SLNet::MessageID));
|
||||
SLNet::RakString password;
|
||||
bs.Read(password);
|
||||
printf("ID_TWO_WAY_AUTHENTICATION_OUTGOING_CHALLENGE_FAILED with %s from %s\n", password.C_String(), packet->systemAddress.ToString(true));
|
||||
if (stage!=4)
|
||||
{
|
||||
printf("Failed stage %i\n", stage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (++stage4FailureCount==2)
|
||||
quit=true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
rakPeer[peerIndex]->DeallocatePacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
RakSleep(30);
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i < NUM_PEERS; i++)
|
||||
SLNet::RakPeerInterface::DestroyInstance(rakPeer[i]);
|
||||
|
||||
for (unsigned short peerIndex=0; peerIndex < NUM_PEERS; peerIndex++)
|
||||
SLNet::OP_DELETE(twoWayAuthenticationPlugin[peerIndex], _FILE_AND_LINE_);
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user