Browse Source

Projektdateien hinzufügen.

Kolja Strohm 7 years ago
parent
commit
06de374205

+ 87 - 0
Network Linux.vcxproj

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <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>{6c19e412-b93c-45d5-b95d-feaf978aea55}</ProjectGuid>
+    <Keyword>Linux</Keyword>
+    <RootNamespace>Network_Linux</RootNamespace>
+    <MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
+    <ApplicationType>Linux</ApplicationType>
+    <ApplicationTypeRevision>1.0</ApplicationTypeRevision>
+    <TargetLinuxPlatform>Generic</TargetLinuxPlatform>
+    <LinuxProjectType>{D51BCBC9-82E9-4017-911E-C93873C4EA2B}</LinuxProjectType>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings" />
+  <ImportGroup Label="Shared" />
+  <ImportGroup Label="PropertySheets" />
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <TargetName>libdbgNetwork</TargetName>
+    <TargetExt>.so</TargetExt>
+    <RemoteProjectDir>$(RemoteRootDir)/Network/debug</RemoteProjectDir>
+    <IncludePath>..\Framework;$(IncludePath);$(ISenseIncludePath);../../Framework/release</IncludePath>
+    <OutDir>$(ProjectDir)bin\$(Platform)\debug\</OutDir>
+    <IntDir>$(ProjectDir)obj\$(Platform)\debug\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <RemoteProjectDir>$(RemoteRootDir)/Network/release</RemoteProjectDir>
+    <TargetExt>.so</TargetExt>
+    <IncludePath>..\Framework;$(IncludePath);$(ISenseIncludePath);../../Framework/release</IncludePath>
+    <TargetName>libNetwork</TargetName>
+    <OutDir>$(ProjectDir)bin\$(Platform)\release\</OutDir>
+    <IntDir>$(ProjectDir)obj\$(Platform)\release\</IntDir>
+  </PropertyGroup>
+  <ItemGroup>
+    <ClCompile Include="Network\Klient.cpp" />
+    <ClCompile Include="Network\Network.cpp" />
+    <ClCompile Include="Network\Server.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="Network\Klient.h" />
+    <ClInclude Include="Network\Network.h" />
+    <ClInclude Include="Network\Server.h" />
+  </ItemGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Link />
+    <ClCompile>
+      <AdditionalOptions>-fPIC %(AdditionalOptions)</AdditionalOptions>
+    </ClCompile>
+    <Link>
+      <ForceUndefineSymbolReferences>
+      </ForceUndefineSymbolReferences>
+      <UnresolvedSymbolReferences>false</UnresolvedSymbolReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Link />
+    <ClCompile>
+      <AdditionalOptions>-fPIC %(AdditionalOptions)</AdditionalOptions>
+    </ClCompile>
+    <Link>
+      <ForceUndefineSymbolReferences>
+      </ForceUndefineSymbolReferences>
+      <UnresolvedSymbolReferences>false</UnresolvedSymbolReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets" />
+</Project>

+ 33 - 0
Network Linux.vcxproj.filters

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Headerdateien">
+      <UniqueIdentifier>{03c645d3-e941-4328-9a3b-79b14bd68431}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Quelldateien">
+      <UniqueIdentifier>{2b2ac39d-c387-4807-8616-1b9ec5faf6af}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="Network\Server.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="Network\Network.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="Network\Klient.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="Network\Server.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="Network\Network.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="Network\Klient.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>

+ 42 - 0
Network.sln

@@ -0,0 +1,42 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26020.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Network", "Network\Network.vcxproj", "{E52010A0-0060-42AA-9769-AAF6488F8C1C}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Network Linux", "Network Linux.vcxproj", "{6C19E412-B93C-45D5-B95D-FEAF978AEA55}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|ARM = Debug|ARM
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		Release|ARM = Release|ARM
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Debug|ARM.ActiveCfg = Debug|Win32
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Debug|Win32.ActiveCfg = Debug|Win32
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Debug|Win32.Build.0 = Debug|Win32
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Debug|x64.ActiveCfg = Debug|x64
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Debug|x64.Build.0 = Debug|x64
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Release|ARM.ActiveCfg = Release|Win32
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Release|Win32.ActiveCfg = Release|Win32
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Release|Win32.Build.0 = Release|Win32
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Release|x64.ActiveCfg = Release|x64
+		{E52010A0-0060-42AA-9769-AAF6488F8C1C}.Release|x64.Build.0 = Release|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Debug|ARM.ActiveCfg = Debug|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Debug|Win32.ActiveCfg = Debug|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Debug|x64.ActiveCfg = Debug|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Debug|x64.Build.0 = Debug|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Release|ARM.ActiveCfg = Release|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Release|Win32.ActiveCfg = Release|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Release|x64.ActiveCfg = Release|x64
+		{6C19E412-B93C-45D5-B95D-FEAF978AEA55}.Release|x64.Build.0 = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 227 - 0
Network/Klient.cpp

@@ -0,0 +1,227 @@
+#include "Klient.h"
+#ifndef WIN32
+#include <string.h>
+#endif
+#include <Key.h>
+#include <Datei.h>
+
+using namespace Network;
+
+// inhalt der Klient Klasse aus Klient.h
+// Konstruktor 
+Klient::Klient()
+{
+	memset( &server, 0, sizeof( server ) );
+	server.sin_family = AF_INET;
+	ref = 1;
+	downStreamBytes = 0;
+	upStreamBytes = 0;
+	sock = 0;
+	sendeKey = 0;
+	empfangKey = 0;
+}
+
+// Destruktoe 
+Klient::~Klient()
+{
+	if( sock )
+		trenne();
+	if( sendeKey )
+		sendeKey->release();
+	if( empfangKey )
+		empfangKey->release();
+}
+
+// nicht constant 
+void Klient::setSendeKeyZ( Encryption::Key *key ) // Setzt den Key fürs Senden
+{
+	if( sendeKey )
+		sendeKey->release();
+	sendeKey = key;
+}
+
+void Klient::setEmpfangKeyZ( Encryption::Key *key ) // Setzt den Key fürs Empfangen
+{
+	if( empfangKey )
+		empfangKey->release();
+	empfangKey = key;
+}
+
+void Klient::setSendeKey( char *key, int len ) // Setzt den Key fürs Senden
+{
+	if( !sendeKey )
+		sendeKey = new Encryption::Key();
+	sendeKey->setKey( key, len );
+}
+
+void Klient::setEmpfangKey( char *key, int len ) // Setzt den Key fürs Empfangen
+{
+	if( !empfangKey )
+		empfangKey = new Encryption::Key();
+	empfangKey->setKey( key, len );
+}
+
+bool Klient::verbinde( unsigned short port, const char *ip ) // verbindet mit Server
+{
+	if( sendeKey )
+		sendeKey->setPos( 0 );
+	if( empfangKey )
+		empfangKey->setPos( 0 );
+	if( sock )
+		closesocket( sock );
+	sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
+	long sIp = inet_addr( ip ); // ip addresse
+	memcpy( (char*)&server.sin_addr, &sIp, sizeof( sIp ) );
+	server.sin_port = htons( port ); // port
+	if( connect( sock, ( struct sockaddr* )&server, sizeof( server ) ) < 0 ) // verbinden
+		return 0; // Fehler
+	return 1;
+}
+
+bool Klient::sende( const char *nachricht, int len ) // sendet zum Server
+{
+    int ll = 0;
+    while( len > 0 )
+    {
+#ifdef WIN32
+        int l = send( sock, nachricht + ll, len, 0 );
+#else
+        int l = (int)send( sock, nachricht + ll, len, MSG_NOSIGNAL );
+#endif
+        if( l < 0 )
+            return 0; // Fehler
+        len -= l;
+        ll += l;
+    }
+	upStreamBytes += ll;
+	return 1;
+}
+
+bool Klient::getNachricht( char *nachricht, int len ) // empfängt Nachricht
+{
+    int ll = 0;
+    while( len > 0 )
+    {
+        int l = (int)recv( sock, nachricht + ll, len, MSG_WAITALL );
+        if( l < 0 )
+            return 0; // Fehler
+        len -= l;
+        ll += l;
+    }
+	downStreamBytes += ll;
+	return 1;
+}
+
+bool Klient::sendeEncrypted( const char *nachricht, int len ) // sendet zum Server
+{
+	if( !sendeKey )
+		return sende( nachricht, len );
+	Encryption::Bytes *n = new Encryption::Bytes( nachricht, len );
+	sendeKey->codieren( n->getThis() );
+    int ll = 0;
+    while( len > 0 )
+    {
+#ifdef WIN32
+        int l = send( sock, n->getBytes() + ll, len, 0 );
+#else
+        int l = (int)send( sock, n->getBytes() + ll, len, MSG_NOSIGNAL );
+#endif
+        if( l < 0 )
+        {
+            n->release();
+            return 0; // Fehler
+        }
+        len -= l;
+        ll += l;
+    }
+	upStreamBytes += ll;
+	n->release();
+	return 1;
+}
+
+bool Klient::getNachrichtEncrypted( char *nachricht, int len ) // empfängt Nachricht
+{
+	if( !empfangKey )
+		return getNachricht( nachricht, len );
+    int ll = 0;
+    while( len > 0 )
+    {
+        int l = (int)recv( sock, nachricht + ll, len, MSG_WAITALL );
+        if( l < 0 )
+            return 0; // Fehler
+        len -= l;
+        ll += l;
+    }
+	Encryption::Bytes *n = new Encryption::Bytes();
+	n->setBytesZ( nachricht, ll );
+	empfangKey->decodieren( n );
+	downStreamBytes += ll;
+	return 1;
+}
+
+int Klient::getDownloadBytes( bool reset ) // gibt die anzahl von empfangen bytes zurück
+{
+	int ret = downStreamBytes;
+	if( reset )
+		downStreamBytes = 0;
+	return ret;
+}
+
+int Klient::getUploadBytes( bool reset ) // gibt die anzahl von versendeter bytes zurück
+{
+	int ret = upStreamBytes;
+	if( reset )
+		upStreamBytes = 0;
+	return ret;
+}
+
+bool Klient::trenne() // Trennt die Verbindung zum Server
+{
+	if( !sock )
+		return 1;
+	if( sendeKey )
+		sendeKey->setPos( 0 );
+	if( empfangKey )
+		empfangKey->setPos( 0 );
+	if( closesocket( sock ) < 0 ) // verbindung Trennen
+		return 0; // Fehler
+	sock = 0;
+	return 1;
+}
+
+// constant
+bool Klient::hatNachricht( int zeit ) // Wartet eine Zeit Lang auf eine Nachricht
+{
+#ifdef WIN32
+	fd_set set = { 1, { sock } };
+	timeval time = { zeit / 1000, zeit };
+	return select( 0, &set, 0, 0, &time ) == 1;
+#else
+	return 1;
+#endif
+}
+
+unsigned short Klient::getServerPort() const // gibt den Port zurück
+{
+	return htons( server.sin_port );
+}
+
+const char *Klient::getServerIp() const // gibt die Ip zurück
+{
+	return inet_ntoa( server.sin_addr );
+}
+
+// Reference Counting 
+Klient *Klient::getThis()
+{
+	ref++;
+	return this;
+}
+
+Klient *Klient::release()
+{
+	ref--;
+	if( !ref )
+		delete this;
+	return 0;
+}

+ 59 - 0
Network/Klient.h

@@ -0,0 +1,59 @@
+#ifndef Klient_H
+#define Klient_H
+
+#include "Network.h"
+
+namespace Framework
+{
+	namespace Encryption
+	{
+		class Key;
+	}
+}
+
+using namespace Framework;
+
+namespace Network
+{
+	class Klient; // aus dieser Datei
+
+	class Klient
+	{
+	private:
+		SOCKET sock;
+		sockaddr_in server;
+		Encryption::Key *sendeKey;
+		Encryption::Key *empfangKey;
+		int downStreamBytes;
+		int upStreamBytes;
+		int ref;
+
+	public:
+		// Konstruktor 
+		__declspec( dllexport ) Klient();
+		// Destruktor 
+		__declspec( dllexport ) ~Klient();
+		// nicht constant 
+		__declspec( dllexport ) void setSendeKeyZ( Encryption::Key *key ); // Setzt den Schlüssel fürs Senden
+		__declspec( dllexport ) void setEmpfangKeyZ( Encryption::Key *key ); // Setzt den Schlüssel fürs Empfangen
+		__declspec( dllexport ) void setSendeKey( char *key, int len ); // Setzt den Schlüssel fürs Senden
+		__declspec( dllexport ) void setEmpfangKey( char *key, int len ); // Setzt den Schlüssel fürs Empfangen
+		__declspec( dllexport ) bool verbinde( unsigned short port, const char *ip ); // verbindet mit Server
+		__declspec( dllexport ) bool sende( const char *nachricht, int len ); // sendet zum Server
+		__declspec( dllexport ) bool getNachricht( char *nachricht, int len ); // empfängt Nachricht
+		__declspec( dllexport ) bool sendeEncrypted( const char *nachricht, int len ); // sendet zum Server
+		__declspec( dllexport ) bool getNachrichtEncrypted( char *nachricht, int len ); // empfängt Nachricht
+		__declspec( dllexport ) int getDownloadBytes( bool reset ); // gibt die anzahl von empfangen bytes zurück
+		__declspec( dllexport ) int getUploadBytes( bool reset ); // gibt die anzahl von versendeter bytes zurück
+		__declspec( dllexport ) bool trenne(); // Trennt die Verbindung zum Server
+		// constant 
+		__declspec( dllexport ) bool hatNachricht( int zeit ); // Wartet eine Zeit Lang auf eine Nachricht
+		__declspec( dllexport ) unsigned short getServerPort() const; // gibt den Port des Servers zurück
+		__declspec( dllexport ) const char *getServerIp() const; // gibt die Ip des Servers zurück
+		// Reference Counting 
+		__declspec( dllexport ) Klient *getThis();
+		__declspec( dllexport ) Klient *release();
+	};
+}
+
+#endif

+ 50 - 0
Network/Network.cpp

@@ -0,0 +1,50 @@
+#include "Network.h"
+#ifndef WIN32
+#include <iostream>
+#include <netdb.h>
+#endif
+
+// Starte Netzwerk
+void Network::Start( int maxClients )
+{
+#ifdef WIN32
+	WSADATA lpwd;
+	lpwd.iMaxSockets = maxClients;
+	int fehler = WSAStartup( MAKEWORD( 2, 0 ), &lpwd );
+	if( fehler != 0 )
+		MessageBox( 0, "Win Sock 2.0 konnte nocht gestartet werden.", "Fehler", MB_ICONERROR );
+#endif
+}
+
+void Network::getHostName( char *name, int bufferLen )
+{
+	gethostname( name, bufferLen );
+}
+
+char *Network::getHostAddresse()
+{
+	char *addresse;
+	char name[ 255 ] = "";
+	getHostName( name, 255 );
+	PHOSTENT hostinfo;
+	hostinfo = gethostbyname( name );
+	if( !hostinfo )
+	{
+#ifdef WIN32
+		MessageBox( 0, "Die Ip Addresse konnte nicht ermittelt werden.", "Fehler", MB_ICONERROR );
+#else
+		std::cout << "Fehler: Die Ip Addresse konnte nicht ermittelt werden.";
+#endif
+	}
+	addresse = inet_ntoa( *( struct in_addr* )*hostinfo->h_addr_list );
+	return addresse;
+}
+
+
+// Beende Netzwerk
+void Network::Exit()
+{
+#ifdef WIN32
+	WSACleanup();
+#endif
+}

+ 44 - 0
Network/Network.h

@@ -0,0 +1,44 @@
+#ifndef Network_H
+#define Network_H
+
+#ifdef WIN32
+#ifdef _DEBUG
+#ifndef _LTMDB
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+#define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
+#define new DEBUG_CLIENTBLOCK
+#define _LTMDB
+#endif
+#endif
+#define _WINSOCK_DEPRECATED_NO_WARNINGS
+#include <WinSock2.h>
+#else
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <iostream>
+#define __declspec( x )
+#define __int64           long long
+#ifndef SOCKET
+#define SOCKET            int
+#define SOCKADDR_IN       sockaddr_in
+#define ADDR_ANY          INADDR_ANY
+#define closesocket       close
+#define PHOSTENT          hostent*
+#endif
+#endif
+
+namespace Network
+{
+	__declspec( dllexport ) void Start( int maxClients );
+	__declspec( dllexport ) void getHostName( char *name, int bufferLen );
+	__declspec( dllexport ) char *getHostAddresse();
+	__declspec( dllexport ) void Exit();
+}
+
+#endif

+ 190 - 0
Network/Network.vcxproj

@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.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="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{E52010A0-0060-42AA-9769-AAF6488F8C1C}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>Network</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <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 Condition="'$(Configuration)|$(Platform)'=='Release|x64'" 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 Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <IncludePath>$(IncludePath)</IncludePath>
+    <SourcePath>$(SourcePath)</SourcePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <IncludePath>..\..\Framework;$(IncludePath)</IncludePath>
+    <SourcePath>$(SourcePath)</SourcePath>
+    <CustomBuildBeforeTargets>Build</CustomBuildBeforeTargets>
+    <LibraryPath>..\..\Framework\x64\Debug;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <CustomBuildBeforeTargets>Build</CustomBuildBeforeTargets>
+    <IncludePath>..\..\Framework;$(IncludePath)</IncludePath>
+    <LibraryPath>..\..\Framework\Release;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <CustomBuildBeforeTargets>Build</CustomBuildBeforeTargets>
+    <IncludePath>..\..\Framework;$(IncludePath)</IncludePath>
+    <LibraryPath>..\..\Framework\x64\Release;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NETWORK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NETWORK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>Ws2_32.lib;Framework.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+    <CustomBuildStep>
+      <Command>copy "..\x64\Debug\Network.dll" "..\..\..\Spiele Platform\Klient\Start\Start\network.dll"
+copy "..\x64\Debug\Network.dll" "..\..\..\Spiele Platform\Klient\patcher\patcher\network.dll"
+copy "..\x64\Debug\Network.dll" "..\..\..\Spiele Platform\SMP\SMP\network.dll"</Command>
+      <Outputs>kopiere...;%(Outputs)</Outputs>
+    </CustomBuildStep>
+  </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;_WINDOWS;_USRDLL;NETWORK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>Ws2_32.lib;Framework.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+    <CustomBuildStep>
+      <Command>copy "..\Release\Network.dll" "..\..\..\Spiele Platform\Klient\Fertig\x32\network.dll"
+copy "..\Release\Network.dll" "..\..\..\Spiele Platform\SMP\Fertig\x32\network.dll"</Command>
+      <Outputs>kopieren...;%(Outputs)</Outputs>
+    </CustomBuildStep>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;NETWORK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>Ws2_32.lib;Framework.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+    <CustomBuildStep>
+      <Command>copy "..\x64\Release\Network.dll" "..\..\..\Spiele Platform\Klient\Fertig\x64\network.dll"
+copy "..\x64\Release\Network.dll" "..\..\..\Spiele Platform\SMP\Fertig\x64\network.dll"</Command>
+    </CustomBuildStep>
+    <CustomBuildStep>
+      <Outputs>kopieren...;%(Outputs)</Outputs>
+    </CustomBuildStep>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClInclude Include="Klient.h" />
+    <ClInclude Include="Network.h" />
+    <ClInclude Include="Server.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="Klient.cpp" />
+    <ClCompile Include="Network.cpp" />
+    <ClCompile Include="Server.cpp" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 39 - 0
Network/Network.vcxproj.filters

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Quelldateien">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Headerdateien">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Ressourcendateien">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="Network.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="Server.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+    <ClInclude Include="Klient.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="Server.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="Klient.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+    <ClCompile Include="Network.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>

+ 284 - 0
Network/Server.cpp

@@ -0,0 +1,284 @@
+#include "Server.h"
+#ifndef WIN32
+#include <string.h>
+#endif
+#include <Key.h>
+
+using namespace Network;
+
+// Inhalt der Server Klasse aus Server.h
+// Konstruktor 
+Server::Server()
+{
+	sock = 0;
+	memset( &addresse, 0, sizeof( addresse ) ); // Adresse setzen
+	addresse.sin_family = AF_INET;
+	addresse.sin_addr.s_addr = ADDR_ANY;
+	ref = 1;
+	klients = 0;
+}
+
+// Destruktor 
+Server::~Server()
+{
+
+}
+
+// nicht constant 
+bool Server::verbinde( unsigned short port, int warteschlangenLen ) // Öffnet das Socket
+{
+	sock = socket( AF_INET, SOCK_STREAM, 0 ); // Socket erstellen
+	addresse.sin_port = htons( port ); // port setzen
+	if( bind( sock, ( struct sockaddr* )&addresse, sizeof( addresse ) ) == -1 ) // socket öffnen
+		return 0; // Fehler
+	if( listen( sock, warteschlangenLen ) == -1 ) // Klients annehmen
+		return 0; // Fehler
+	return 1;
+}
+
+SKlient *Server::getKlient() // nimmt Klient an
+{
+	if( !sock )
+		return 0;
+	sockaddr_in client;
+	int len = sizeof( addresse );
+#ifdef WIN32
+	SOCKET cls = accept( sock, (sockaddr*)&client, &len ); // Klient empfangen
+	if( cls == INVALID_SOCKET )
+		return 0;
+#else
+	SOCKET cls = accept( sock, (sockaddr*)&client, (socklen_t*)&len ); // Klient empfangen
+	if( !cls )
+		return 0;
+#endif
+	client.sin_port = addresse.sin_port;
+	klients++;
+	return new SKlient( client, cls ); // Klient Handle Klasse zurückgeben
+}
+
+int Server::getKlients( bool reset ) // gibt die Anzahl der Klients zurück
+{
+	int ret = klients;
+	if( reset )
+		klients = 0;
+	return ret;
+}
+
+bool Server::trenne() // beendet den Server
+{
+	if( !sock )
+		return 1;
+	if( closesocket( sock ) < 0 ) // socket schließen
+		return 0;
+	sock = 0;
+	return 1;
+}
+
+// constant
+unsigned short Server::getPort() const // gibt den Port zurück
+{
+	return htons( addresse.sin_port );
+}
+
+// Reference Counting 
+Server *Server::getThis()
+{
+	ref++;
+	return this;
+}
+
+Server *Server::release()
+{
+	ref--;
+	if( !ref )
+		delete this;
+	return 0;
+}
+
+// Inhalt der SKlient Klasse aus Server.h
+// Konstruktor 
+SKlient::SKlient( sockaddr_in addresse, SOCKET sock )
+{
+	clientAddr = addresse;
+	this->sock = sock;
+	ref = 1;
+	downStreamBytes = 0;
+	upStreamBytes = 0;
+	sendeKey = 0;
+	empfangKey = 0;
+}
+
+// Destruktor 
+SKlient::~SKlient()
+{
+    trenne();
+	if( sendeKey )
+		sendeKey->release();
+	if( empfangKey )
+		empfangKey->release();
+}
+
+// nicht constant 
+void SKlient::setSendeKeyZ( Encryption::Key *key ) // Setzt den Key fürs Senden
+{
+	if( sendeKey )
+		sendeKey->release();
+	sendeKey = key;
+}
+
+void SKlient::setEmpfangKeyZ( Encryption::Key *key ) // Setzt den Key fürs Empfangen
+{
+	if( empfangKey )
+		empfangKey->release();
+	empfangKey = key;
+}
+
+void SKlient::setSendeKey( char *key, int len ) // Setzt den Key fürs Senden
+{
+	if( !sendeKey )
+		sendeKey = new Encryption::Key();
+	sendeKey->setKey( key, len );
+}
+
+void SKlient::setEmpfangKey( char *key, int len ) // Setzt den Key fürs Empfangen
+{
+	if( !empfangKey )
+		empfangKey = new Encryption::Key();
+	empfangKey->setKey( key, len );
+}
+
+bool SKlient::sende( const char *nachricht, int len ) // sendet zum Klient
+{
+	if( !sock )
+		return 0;
+    int ll = 0;
+    while( len > 0 )
+    {
+#ifdef WIN32
+        int l = send( sock, nachricht + ll, len, 0 );
+#else
+        int l = (int)send( sock, nachricht + ll, len, MSG_NOSIGNAL );
+#endif
+        if( l < 0 )
+            return 0; // Fehler
+        len -= l;
+        ll += l;
+    }
+	upStreamBytes += ll;
+	return 1;
+}
+
+bool SKlient::getNachricht( char *nachricht, int len ) // empfängt Nachricht von Klient
+{
+	if( !sock )
+		return 0;
+    int ll = 0;
+    while( len > 0 )
+    {
+        int l = (int)recv( sock, nachricht + ll, len, MSG_WAITALL );
+        if( l < 0 )
+            return 0; // Fehler
+        len -= l;
+        ll += l;
+    }
+	downStreamBytes += ll;
+	return 1;
+}
+
+bool SKlient::sendeEncrypted( const char *nachricht, int len ) // sendet zum Server
+{
+	if( !sendeKey )
+		return sende( nachricht, len );
+	Encryption::Bytes *n = new Encryption::Bytes( nachricht, len );
+	sendeKey->codieren( n->getThis() ); int ll = 0;
+    while( len > 0 )
+    {
+#ifdef WIN32
+        int l = send( sock, n->getBytes() + ll, len, 0 );
+#else
+        int l = (int)send( sock, n->getBytes() + ll, len, MSG_NOSIGNAL );
+#endif
+        if( l < 0 )
+        {
+            n->release();
+            return 0; // Fehler
+        }
+        len -= l;
+        ll += l;
+    }
+    upStreamBytes += ll;
+	n->release();
+	return 1;
+}
+
+bool SKlient::getNachrichtEncrypted( char *nachricht, int len ) // empfängt Nachricht
+{
+	if( !empfangKey )
+		return getNachricht( nachricht, len );
+    int ll = 0;
+    while( len > 0 )
+    {
+        int l = (int)recv( sock, nachricht + ll, len, MSG_WAITALL );
+        if( l < 0 )
+            return 0; // Fehler
+        len -= l;
+        ll += l;
+    }
+	Encryption::Bytes *n = new Encryption::Bytes();
+	n->setBytesZ( nachricht, ll );
+	empfangKey->decodieren( n );
+	downStreamBytes += ll;
+	return 1;
+}
+
+int SKlient::getDownloadBytes( bool reset ) // gibt die anzahl von empfangen bytes zurück
+{
+	int ret = downStreamBytes;
+	if( reset )
+		downStreamBytes = 0;
+	return ret;
+}
+
+int SKlient::getUploadBytes( bool reset ) // gibt die anzahl von versendeter bytes zurück
+{
+	int ret = upStreamBytes;
+	if( reset )
+		upStreamBytes = 0;
+	return ret;
+}
+
+bool SKlient::trenne() // trennt die Verbindung zum Klient
+{
+	if( !sock )
+		return 0;
+	if( closesocket( sock ) < 0 ) // trennen
+		return 0;
+	sock = 0;
+	return 1;
+}
+
+// constant 
+unsigned short SKlient::getPort() const // gibt den Port zurück
+{
+	return htons( clientAddr.sin_port );
+}
+
+const char *SKlient::getIp() const // gibt die Ip des Klients zurück
+{
+	return inet_ntoa( clientAddr.sin_addr );
+}
+
+// Reference Counting 
+SKlient *SKlient::getThis()
+{
+	ref++;
+	return this;
+}
+
+SKlient *SKlient::release()
+{
+	ref--;
+	if( !ref )
+		delete this;
+	return 0;
+}

+ 83 - 0
Network/Server.h

@@ -0,0 +1,83 @@
+#ifndef Server_H
+#define Server_H
+
+#include "Network.h"
+
+namespace Framework
+{
+	namespace Encryption
+	{
+		class Key;
+	}
+}
+
+using namespace Framework;
+
+namespace Network
+{
+	class Server; // aus dieser Datei
+	class SKlient; // aus dieser Datei
+
+	class Server
+	{
+	private:
+		SOCKET sock;
+		SOCKADDR_IN addresse;
+		int klients;
+		int ref;
+
+	public:
+		// Konstruktor 
+		__declspec( dllexport ) Server();
+		// Destruktor 
+		__declspec( dllexport ) ~Server();
+		// nicht constant 
+		__declspec( dllexport ) bool verbinde( unsigned short port, int warteschlangenLen ); // Öffnet das Socket
+		__declspec( dllexport ) SKlient *getKlient(); // nimmt Klient an
+		__declspec( dllexport ) int getKlients( bool reset ); // gibt die Anzahl der Klients zurück
+		__declspec( dllexport ) bool trenne(); // beendet den Server
+		// constant
+		__declspec( dllexport ) unsigned short getPort() const; // gibt den Port zurück
+		// Reference Counting 
+		__declspec( dllexport ) Server *getThis();
+		__declspec( dllexport ) Server *release();
+	};
+
+	class SKlient
+	{
+	private:
+		SOCKET sock;
+		sockaddr_in clientAddr;
+		Encryption::Key *sendeKey;
+		Encryption::Key *empfangKey;
+		int downStreamBytes;
+		int upStreamBytes;
+		int ref;
+
+	public:
+		// Konstruktor 
+		__declspec( dllexport ) SKlient( sockaddr_in client, SOCKET sock );
+		// Destruktor 
+		__declspec( dllexport ) ~SKlient();
+		// nicht constant 
+		__declspec( dllexport ) void setSendeKeyZ( Encryption::Key *key ); // Setzt den Schlüssel fürs Senden
+		__declspec( dllexport ) void setEmpfangKeyZ( Encryption::Key *key ); // Setzt den Schlüssel fürs Empfangen
+		__declspec( dllexport ) void setSendeKey( char *key, int len ); // Setzt den Schlüssel fürs Senden
+		__declspec( dllexport ) void setEmpfangKey( char *key, int len ); // Setzt den Schlüssel fürs Empfangen
+		__declspec( dllexport ) bool sende( const char *nachricht, int len ); // sendet zum Klient
+		__declspec( dllexport ) bool getNachricht( char *nachricht, int len ); // empfängt Nachricht von Klient
+		__declspec( dllexport ) bool sendeEncrypted( const char *nachricht, int len ); // sendet zum Server
+		__declspec( dllexport ) bool getNachrichtEncrypted( char *nachricht, int len ); // empfängt Nachricht
+		__declspec( dllexport ) int getDownloadBytes( bool reset ); // gibt die anzahl von empfangen bytes zurück
+		__declspec( dllexport ) int getUploadBytes( bool reset ); // gibt die anzahl von versendeter bytes zurück
+		__declspec( dllexport ) bool trenne(); // trennt die Verbindung zum Klient
+		// constant 
+		__declspec( dllexport ) unsigned short getPort() const; // gibt den Port zurück
+		__declspec( dllexport ) const char *getIp() const; // gibt die Ip des Klients zurück
+		// Reference Counting 
+		__declspec( dllexport ) SKlient *getThis();
+		__declspec( dllexport ) SKlient *release();
+	};
+}
+
+#endif

+ 6 - 0
build.bat

@@ -0,0 +1,6 @@
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" Network.sln /t:Network:rebuild /p:configuration=debug /p:platform=x64
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" Network.sln /t:Network:rebuild /p:configuration=release /p:platform=x64
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" Network.sln /t:Network:rebuild /p:configuration=release /p:platform=win32
+
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "Network Linux.vcxproj" /t:rebuild /p:configuration=debug /p:platform=x64
+"D:\Visual Studio 2017\MSBuild\15.0\Bin\MSBuild.exe" "Network Linux.vcxproj" /t:rebuild /p:configuration=release /p:platform=x64