Added Tests project, Callback functions are in progress, NetworkBuffer is done, Network Message is WIP but already has a lot of code, Serializer is done (subject to change), Utility classes are being made, and TcpClientWindows is WIP.
Every single piece of code wrote today may or not change, but it will probably change because ill find a better way to do it xD
This commit is contained in:
1
TestsVS/Tests/Release/Tests.tlog/CL.command.1.tlog
Normal file
1
TestsVS/Tests/Release/Tests.tlog/CL.command.1.tlog
Normal file
@ -0,0 +1 @@
|
||||
<EFBFBD><EFBFBD>
|
||||
2
TestsVS/Tests/Release/Tests.tlog/Tests.lastbuildstate
Normal file
2
TestsVS/Tests/Release/Tests.tlog/Tests.lastbuildstate
Normal file
@ -0,0 +1,2 @@
|
||||
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
|
||||
Release|Win32|F:\VoidNet\VoidNetVS\|
|
||||
BIN
TestsVS/Tests/Release/Tests.tlog/link.command.1.tlog
Normal file
BIN
TestsVS/Tests/Release/Tests.tlog/link.command.1.tlog
Normal file
Binary file not shown.
BIN
TestsVS/Tests/Release/Tests.tlog/link.read.1.tlog
Normal file
BIN
TestsVS/Tests/Release/Tests.tlog/link.read.1.tlog
Normal file
Binary file not shown.
BIN
TestsVS/Tests/Release/Tests.tlog/link.write.1.tlog
Normal file
BIN
TestsVS/Tests/Release/Tests.tlog/link.write.1.tlog
Normal file
Binary file not shown.
0
TestsVS/Tests/Release/Tests.tlog/unsuccessfulbuild
Normal file
0
TestsVS/Tests/Release/Tests.tlog/unsuccessfulbuild
Normal file
12
TestsVS/Tests/Tests.cpp
Normal file
12
TestsVS/Tests/Tests.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "Utility.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
byte *bytes = Utility::BitConverter::FromUint8(20);
|
||||
std::cout << Utility::BitConverter::ToUint8(bytes, 0) << std::endl;
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
156
TestsVS/Tests/Tests.vcxproj
Normal file
156
TestsVS/Tests/Tests.vcxproj
Normal file
@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{41663B22-3949-4570-9AB5-309363EAD56F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Tests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>F:\VoidNet\include;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Tests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\VoidNetVS\VoidNetVS\VoidNetVS.vcxproj">
|
||||
<Project>{5172321e-ccb0-4a77-9f3d-faaf0084f434}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
6
TestsVS/Tests/Tests.vcxproj.filters
Normal file
6
TestsVS/Tests/Tests.vcxproj.filters
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Tests.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
BIN
VoidNetVS/Release/Tests.iobj
Normal file
BIN
VoidNetVS/Release/Tests.iobj
Normal file
Binary file not shown.
BIN
VoidNetVS/Release/Tests.ipdb
Normal file
BIN
VoidNetVS/Release/Tests.ipdb
Normal file
Binary file not shown.
@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25123.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VoidNetVS", "VoidNetVS\VoidNetVS.vcxproj", "{5172321E-CCB0-4A77-9F3D-FAAF0084F434}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tests", "..\TestsVS\Tests\Tests.vcxproj", "{41663B22-3949-4570-9AB5-309363EAD56F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -21,6 +23,14 @@ Global
|
||||
{5172321E-CCB0-4A77-9F3D-FAAF0084F434}.Release|x64.Build.0 = Release|x64
|
||||
{5172321E-CCB0-4A77-9F3D-FAAF0084F434}.Release|x86.ActiveCfg = Release|Win32
|
||||
{5172321E-CCB0-4A77-9F3D-FAAF0084F434}.Release|x86.Build.0 = Release|Win32
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Debug|x64.Build.0 = Debug|x64
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Release|x64.ActiveCfg = Release|x64
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Release|x64.Build.0 = Release|x64
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{41663B22-3949-4570-9AB5-309363EAD56F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog
Normal file
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog
Normal file
Binary file not shown.
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog
Normal file
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog
Normal file
Binary file not shown.
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog
Normal file
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog
Normal file
Binary file not shown.
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib-link.write.1.tlog
Normal file
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib-link.write.1.tlog
Normal file
Binary file not shown.
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog
Normal file
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog
Normal file
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
|
||||
Release|Win32|F:\VoidNet\VoidNetVS\|
|
||||
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog
Normal file
BIN
VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog
Normal file
Binary file not shown.
@ -19,18 +19,25 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\Callbacks.hpp" />
|
||||
<ClInclude Include="..\..\include\Config.hpp" />
|
||||
<ClInclude Include="..\..\include\Defs.hpp" />
|
||||
<ClInclude Include="..\..\include\Init.hpp" />
|
||||
<ClInclude Include="..\..\include\NetworkBuffer.hpp" />
|
||||
<ClInclude Include="..\..\include\NetworkMessage.hpp" />
|
||||
<ClInclude Include="..\..\include\Serializer.hpp" />
|
||||
<ClInclude Include="..\..\include\TcpClient.hpp" />
|
||||
<ClInclude Include="..\..\include\Utility.hpp" />
|
||||
<ClInclude Include="..\..\include\VoidNet.hpp" />
|
||||
<ClInclude Include="..\..\include\VoidNetClient.hpp" />
|
||||
<ClInclude Include="..\..\include\VoidNetServer.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Config.cpp" />
|
||||
<ClCompile Include="..\..\src\Init.cpp" />
|
||||
<ClCompile Include="..\..\src\InitWindows.cpp" />
|
||||
<ClCompile Include="..\..\src\NetworkBuffer.cpp" />
|
||||
<ClCompile Include="..\..\src\NetworkMessage.cpp" />
|
||||
<ClCompile Include="..\..\src\Serializer.cpp" />
|
||||
<ClCompile Include="..\..\src\TcpClient.cpp" />
|
||||
<ClCompile Include="..\..\src\TcpClientWindows.cpp" />
|
||||
<ClCompile Include="..\..\src\Utility.cpp" />
|
||||
|
||||
@ -15,9 +15,6 @@
|
||||
<ClInclude Include="..\..\include\Defs.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\VoidNet.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\TcpClient.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
@ -30,6 +27,21 @@
|
||||
<ClInclude Include="..\..\include\NetworkMessage.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\VoidNetClient.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\VoidNetServer.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\NetworkBuffer.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Serializer.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Callbacks.hpp">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Init.cpp">
|
||||
@ -50,6 +62,15 @@
|
||||
<ClCompile Include="..\..\src\Config.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\NetworkBuffer.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Serializer.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\NetworkMessage.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\TODO" />
|
||||
|
||||
17
include/Callbacks.hpp
Normal file
17
include/Callbacks.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef CALLBACKS_HPP
|
||||
#define CALLBACKS_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
#include "Serializer.hpp"
|
||||
|
||||
void OnMessage(byte sender, byte tag, uint16 subject, byte *data);
|
||||
|
||||
void OnDisconnect(byte id);
|
||||
|
||||
void OnConnect(byte id);
|
||||
|
||||
#endif
|
||||
@ -2,10 +2,7 @@
|
||||
#define DEFS_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WINSOCKAPI_
|
||||
#include <windows.h>
|
||||
@ -185,4 +182,14 @@ enum VoidCode
|
||||
VOID_COULDNT_CONNECT,
|
||||
};
|
||||
|
||||
enum DistributionType
|
||||
{
|
||||
All,
|
||||
Server,
|
||||
Others,
|
||||
ID,
|
||||
Reply,
|
||||
Custom,
|
||||
}
|
||||
|
||||
#endif // DEFS_HPP
|
||||
19
include/NetworkBuffer.hpp
Normal file
19
include/NetworkBuffer.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef NETWORK_BUFFER_HPP
|
||||
#define NETWORK_BUFFER_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
struct NetworkBuffer
|
||||
{
|
||||
NetworkBuffer();
|
||||
~NetworkBuffer();
|
||||
|
||||
int body_size;
|
||||
byte *body = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -5,12 +5,30 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class NetworkMessage
|
||||
{
|
||||
public:
|
||||
NetworkMessage();
|
||||
#include "Defs.hpp"
|
||||
#include "NetworkBuffer.hpp"
|
||||
|
||||
private:
|
||||
struct NetworkMessage
|
||||
{
|
||||
NetworkMessage();
|
||||
NetworkMessage(uint16 sender, byte distribution_mode, uint16 destination_id, byte tag, uint16 subject, NetworkBuffer buffer);
|
||||
~NetworkMessage();
|
||||
|
||||
const NetworkMessage &EncodeMessage();
|
||||
|
||||
const NetworkMessage &NetworkMessage::DecodeMessage(const NetworkBuffer &buffer);
|
||||
const NetworkMessage &NetworkMessage::DecodeMessageHeader(const NetworkBuffer &buffer);
|
||||
void *DecodeMessageData(const NetworkBuffer &buffer);
|
||||
|
||||
uint16 sender;
|
||||
uint16 destination_id;
|
||||
byte distribution_mode;
|
||||
uint16 tag;
|
||||
uint16 subject;
|
||||
|
||||
void *data;
|
||||
|
||||
NetworkBuffer buffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
18
include/Serializer.hpp
Normal file
18
include/Serializer.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef SERIALIZER_HPP
|
||||
#define SERIALIZER_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
class Serializer
|
||||
{
|
||||
template<typename T> std::array<byte, sizeof(T)> to_bytes(const T& object);
|
||||
template<typename T> T& from_bytes(const std::array<byte, sizeof(T)> &bytes, T& object);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -23,7 +23,7 @@ public:
|
||||
uint16 GetPort();
|
||||
void SetPort(uint16 port);
|
||||
|
||||
VoidCode Connect(); // this function is used if Initialize was not called
|
||||
VoidCode Connect();
|
||||
|
||||
char *ReceiveDataArray();
|
||||
const NetworkMessage &ReceiveData();
|
||||
|
||||
@ -5,10 +5,24 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include <streambuf>
|
||||
#include <istream>
|
||||
|
||||
struct Utility
|
||||
{
|
||||
static void Delete(void *pointer);
|
||||
static void DeleteArray(void *pointer);
|
||||
|
||||
struct BitConverter
|
||||
{
|
||||
static byte *FromUint8(uint8 number);
|
||||
static uint8 ToUint8(byte *bytes, uint16 start_index);
|
||||
|
||||
static byte *FromUint16(uint16 number);
|
||||
static uint16 ToUint16(byte *bytes, uint16 start_index);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
#ifndef VOID_NET_HPP
|
||||
#define VOID_NET_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <Defs.hpp>
|
||||
#include <Init.hpp>
|
||||
|
||||
#endif
|
||||
15
include/VoidNetClient.hpp
Normal file
15
include/VoidNetClient.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef VOID_NET_HPP
|
||||
#define VOID_NET_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "Defs.hpp"
|
||||
#include "Init.hpp"
|
||||
#include "TcpClient.hpp"
|
||||
#include "Callbacks.hpp"
|
||||
#include "NetworkBuffer.hpp"
|
||||
#include "NetworkMessage.hpp"
|
||||
|
||||
#endif
|
||||
8
include/VoidNetServer.hpp
Normal file
8
include/VoidNetServer.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef VOID_NET_SERVER_HPP
|
||||
#define VOID_NET_SERVER_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#endif
|
||||
11
src/NetworkBuffer.cpp
Normal file
11
src/NetworkBuffer.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "NetworkBuffer.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
NetworkBuffer::NetworkBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
NetworkBuffer::~NetworkBuffer()
|
||||
{
|
||||
Utility::DeleteArray(body);
|
||||
}
|
||||
53
src/NetworkMessage.cpp
Normal file
53
src/NetworkMessage.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "NetworkMessage.hpp"
|
||||
#include "Utility.hpp"
|
||||
#include "Serializer.hpp"
|
||||
|
||||
NetworkMessage::NetworkMessage()
|
||||
{
|
||||
}
|
||||
|
||||
NetworkMessage::NetworkMessage(uint16 sender, byte distribution_mode, uint16 destination_id, byte tag, uint16 subject, NetworkBuffer buffer) :
|
||||
sender(sender), distribution_mode(distribution_mode), destination_id(destination_id), tag(tag), subject(subject), buffer(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
NetworkMessage::~NetworkMessage()
|
||||
{
|
||||
}
|
||||
|
||||
const NetworkMessage &NetworkMessage::EncodeMessage()
|
||||
{
|
||||
return NetworkMessage();
|
||||
}
|
||||
|
||||
const NetworkMessage & NetworkMessage::DecodeMessage(const NetworkBuffer &buffer)
|
||||
{
|
||||
NetworkMessage message = DecodeMessageHeader(buffer);
|
||||
message.data = DecodeMessageData(buffer);
|
||||
return message;
|
||||
}
|
||||
|
||||
void *NetworkMessage::DecodeMessageData(const NetworkBuffer &buffer)
|
||||
{
|
||||
if (buffer.body_size < 9)
|
||||
return nullptr;
|
||||
byte version = buffer.body[0];
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
//version nor supported
|
||||
return nullptr;// WORKING HERE!!!!!!!!!!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const NetworkMessage &NetworkMessage::DecodeMessageHeader(const NetworkBuffer &buffer)
|
||||
{
|
||||
return NetworkMessage(Utility::BitConverter::ToUint16(buffer.body, 1), buffer.body[3], Utility::BitConverter::ToUint16(buffer.body, 4),
|
||||
buffer.body[6], Utility::BitConverter::ToUint16(buffer.body, 7), buffer);
|
||||
}
|
||||
22
src/Serializer.cpp
Normal file
22
src/Serializer.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "Serializer.hpp"
|
||||
|
||||
template<typename T> std::array<byte, sizeof(T)> Serializer::to_bytes(const T& object)
|
||||
{
|
||||
std::array<byte, sizeof(T)> bytes;
|
||||
|
||||
const byte *begin = reinterpret_cast<const byte*>(std::addressof(object));
|
||||
const byte *end = begin + sizeof(T);
|
||||
std::copy(begin, end, std::begin(bytes));
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
template<typename T> T& Serializer::from_bytes(const std::array<byte, sizeof(T)> &bytes, T& object)
|
||||
{
|
||||
static_assert(std::is_trivially_copyable<T>::value, "not a TriviallyCopyable type");
|
||||
|
||||
byte *begin_object = reinterpret_cast<byte*>(std::addressof(object));
|
||||
std::copy(std::begin(bytes), std::end(bytes), begin_object);
|
||||
|
||||
return object;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
#include "TcpClient.hpp"
|
||||
#include "Utility.hpp"
|
||||
#include "Config.hpp"
|
||||
#include "NetworkBuffer.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -57,21 +58,21 @@ TcpClient::~TcpClient()
|
||||
Utility::Delete(ptr);
|
||||
}
|
||||
|
||||
const std::string & TcpClient::GetIP()
|
||||
const std::string &TcpClient::GetIP()
|
||||
{
|
||||
return ip;
|
||||
}
|
||||
|
||||
void TcpClient::SetIP(const std::string & ip)
|
||||
{
|
||||
this->ip = ip;
|
||||
}
|
||||
|
||||
uint16 TcpClient::GetPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
void TcpClient::SetIP(const std::string & ip)
|
||||
{
|
||||
this->ip = ip;
|
||||
}
|
||||
|
||||
void TcpClient::SetPort(uint16 port)
|
||||
{
|
||||
this->port = port;
|
||||
@ -96,19 +97,20 @@ VoidCode TcpClient::Connect()
|
||||
|
||||
char *TcpClient::ReceiveDataArray()
|
||||
{
|
||||
char *header = new char[4]();
|
||||
|
||||
int remote_buffer_size;
|
||||
do
|
||||
{
|
||||
remote_buffer_size = recv(socket, header, 4, 0);
|
||||
NetworkBuffer buffer;
|
||||
|
||||
if (WSAGetLastError() != 0)
|
||||
{
|
||||
// there was a problem receiving
|
||||
}
|
||||
}
|
||||
while (remote_buffer_size > 0);
|
||||
if (recv(socket, reinterpret_cast<char*>(buffer.body_size), 4, 0) != 4 || WSAGetLastError() != 0)
|
||||
{
|
||||
// there was a problem receiving the body size of the message
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
buffer.body = new byte[buffer.body_size]();
|
||||
if (recv(socket, reinterpret_cast<char*>(buffer.body), buffer.body_size, 0) != buffer.body_size || WSAGetLastError() != 0)
|
||||
{
|
||||
//there was a problem receiving the body of the message
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const NetworkMessage &TcpClient::ReceiveData()
|
||||
|
||||
@ -14,4 +14,32 @@ void Utility::DeleteArray(void *pointer)
|
||||
return;
|
||||
delete[] pointer;
|
||||
pointer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
byte *Utility::BitConverter::FromUint8(uint8 number)
|
||||
{
|
||||
if (number == 0)
|
||||
return nullptr;
|
||||
return reinterpret_cast<byte*>(number);
|
||||
}
|
||||
|
||||
uint8 Utility::BitConverter::ToUint8(byte *bytes, uint16 start_index)
|
||||
{
|
||||
if (bytes == nullptr)
|
||||
return 0;
|
||||
return reinterpret_cast<uint8>(&bytes[start_index]);
|
||||
}
|
||||
|
||||
byte *Utility::BitConverter::FromUint16(uint16 number)
|
||||
{
|
||||
if (number == 0)
|
||||
return nullptr;
|
||||
return reinterpret_cast<byte*>(number);
|
||||
}
|
||||
|
||||
uint16 Utility::BitConverter::ToUint16(byte *bytes, uint16 start_index)
|
||||
{
|
||||
if (bytes == nullptr)
|
||||
return 0;
|
||||
return reinterpret_cast<uint16>(&bytes[start_index]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user