Added missing global TcpClient.cpp file
Fixed Serializer from_bytes parentisis missing Fixed client shutdown, now it sends a message saying its disconnected in TcpServerWindows
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										3
									
								
								VoidNetVS/VoidNetVS/TcpClient.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								VoidNetVS/VoidNetVS/TcpClient.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | #ifdef _MSC_VER | ||||||
|  | #include "TcpClientWindows.cpp" | ||||||
|  | #endif | ||||||
| @ -51,6 +51,7 @@ | |||||||
|     </ClCompile> |     </ClCompile> | ||||||
|     <ClCompile Include="..\..\src\Utility.cpp" /> |     <ClCompile Include="..\..\src\Utility.cpp" /> | ||||||
|     <ClCompile Include="..\..\src\VoidNetClient.cpp" /> |     <ClCompile Include="..\..\src\VoidNetClient.cpp" /> | ||||||
|  |     <ClCompile Include="TcpClient.cpp" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Text Include="..\..\DEV_INFO" /> |     <Text Include="..\..\DEV_INFO" /> | ||||||
|  | |||||||
| @ -83,6 +83,9 @@ | |||||||
|     <ClCompile Include="..\..\src\Handshake.cpp"> |     <ClCompile Include="..\..\src\Handshake.cpp"> | ||||||
|       <Filter>src</Filter> |       <Filter>src</Filter> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|  |     <ClCompile Include="TcpClient.cpp"> | ||||||
|  |       <Filter>src</Filter> | ||||||
|  |     </ClCompile> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Text Include="..\..\TODO" /> |     <Text Include="..\..\TODO" /> | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| #include "NetworkMessage.hpp" | #include "NetworkMessage.hpp" | ||||||
| #include "Utility.hpp" | #include "Utility.hpp" | ||||||
| #include "Serializer.hpp" | #include "Serializer.hpp" | ||||||
| #include "Tags.hpp" |  | ||||||
|  |  | ||||||
| #include <vector> | #include <vector> | ||||||
|  |  | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ template<typename T> const std::vector<byte> &Serializer::to_bytes(const T& obje | |||||||
| template<typename T> const T& Serializer::from_bytes(const std::vector<byte> &bytes, T& object) | template<typename T> const T& Serializer::from_bytes(const std::vector<byte> &bytes, T& object) | ||||||
| { | { | ||||||
| 	static_assert(std::is_trivially_copyable<T>::value, "not a TriviallyCopyable type"); | 	static_assert(std::is_trivially_copyable<T>::value, "not a TriviallyCopyable type"); | ||||||
| 	std::copy(bytes.begin(), bytes.end(), reinterpret_cast<const byte*>(std::addressof(object)); | 	std::copy(bytes.begin(), bytes.end(), reinterpret_cast<const byte*>(std::addressof(object))); | ||||||
|  |  | ||||||
| 	return object; | 	return object; | ||||||
| } | } | ||||||
| @ -2,7 +2,6 @@ | |||||||
| #include "Utility.hpp" | #include "Utility.hpp" | ||||||
| #include "Config.hpp" | #include "Config.hpp" | ||||||
| #include "NetworkBuffer.hpp" | #include "NetworkBuffer.hpp" | ||||||
| #include "Tags.hpp" |  | ||||||
| #include "Handshake.hpp" | #include "Handshake.hpp" | ||||||
|  |  | ||||||
| #include <iostream> | #include <iostream> | ||||||
|  | |||||||
| @ -72,7 +72,10 @@ TcpServer::~TcpServer() | |||||||
| void TcpServer::Shutdown() | void TcpServer::Shutdown() | ||||||
| { | { | ||||||
| 	for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | 	for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | ||||||
| 		(*it).Shutdown(); | 	{ | ||||||
|  | 		TcpClient client = *it; | ||||||
|  | 		client.Shutdown(); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| bool TcpServer::StartServer(bool accept_connections) | bool TcpServer::StartServer(bool accept_connections) | ||||||
| @ -201,7 +204,8 @@ uint16 TcpServer::AllocateID() // this function is only used in the AddToClients | |||||||
| 		bool flag = true; | 		bool flag = true; | ||||||
| 		for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | 		for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | ||||||
| 		{ | 		{ | ||||||
| 			if ((*it).GetID() == i) | 			TcpClient client = *it; | ||||||
|  | 			if (client.GetID() == i) | ||||||
| 			{ | 			{ | ||||||
| 				flag = false; | 				flag = false; | ||||||
| 				break; | 				break; | ||||||
| @ -235,7 +239,7 @@ void TcpServer::RejectConnection(TcpClient &client) | |||||||
| { | { | ||||||
| 	Handshake handshake(client.GetID(), ConnectionCode::Reject); | 	Handshake handshake(client.GetID(), ConnectionCode::Reject); | ||||||
| 	client.SendBytes(Handshake::EncodeHandshake(handshake)); | 	client.SendBytes(Handshake::EncodeHandshake(handshake)); | ||||||
| 	client.Shutdown(); | 	CloseSocket(client); | ||||||
| } | } | ||||||
|  |  | ||||||
| void TcpServer::AcceptConnection(TcpClient & client) | void TcpServer::AcceptConnection(TcpClient & client) | ||||||
| @ -245,6 +249,19 @@ void TcpServer::AcceptConnection(TcpClient & client) | |||||||
| } | } | ||||||
|  |  | ||||||
| void TcpServer::CloseSocket(TcpClient & client) | void TcpServer::CloseSocket(TcpClient & client) | ||||||
|  | { | ||||||
|  | 	bool removed; | ||||||
|  | 	for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | ||||||
|  | 	{ | ||||||
|  | 		TcpClient it_client = *it; | ||||||
|  | 		if (client.GetID() == it_client.GetID()) | ||||||
|  | 		{ | ||||||
|  | 			clients.erase(it); | ||||||
|  | 			removed = true; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (removed) | ||||||
| 	{ | 	{ | ||||||
| 		NetworkMessage message; | 		NetworkMessage message; | ||||||
| 		message.sender = -1; | 		message.sender = -1; | ||||||
| @ -252,7 +269,7 @@ void TcpServer::CloseSocket(TcpClient & client) | |||||||
| 		message.destination_id = client.GetID(); | 		message.destination_id = client.GetID(); | ||||||
| 		message.tag = DISCONNECT; | 		message.tag = DISCONNECT; | ||||||
| 		SendMessage(message); | 		SendMessage(message); | ||||||
| 	clients.erase(std::remove(clients.begin(), clients.end(), client), clients.end()); | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| void TcpServer::CloseSocket(uint16 id) | void TcpServer::CloseSocket(uint16 id) | ||||||
| @ -266,8 +283,9 @@ const TcpClient & TcpServer::GetClientByID(uint16 id) | |||||||
| { | { | ||||||
| 	for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | 	for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it) | ||||||
| 	{ | 	{ | ||||||
| 		if ((*it).GetID() == id) | 		TcpClient client = *it; | ||||||
| 			return *it; | 		if (client.GetID() == id) | ||||||
|  | 			return client; | ||||||
| 	} | 	} | ||||||
| 	return TcpClient(); | 	return TcpClient(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,5 @@ | |||||||
| #include "VoidNetClient.hpp" | #include "VoidNetClient.hpp" | ||||||
| #include "Utility.hpp" | #include "Utility.hpp" | ||||||
| #include "Tags.hpp" |  | ||||||
|  |  | ||||||
| #include <future> | #include <future> | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 xX-TheDoctor-Xx
					xX-TheDoctor-Xx