Tried to implement some Utility::Bitconverter methods but it didnt worked
InternalTags cant be higher than 255 because they will be converted to byte added new ToString method in Utility::StringConverter Server now closes the connection better
This commit is contained in:
2
TODO
2
TODO
@ -6,6 +6,4 @@ handle ReceiveDataArray errors for windows
|
||||
revamped BitConverter class
|
||||
new StringConverter class
|
||||
|
||||
implement close() in TcpClientWindows
|
||||
|
||||
implement ConfigReader methods
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
||||
<EFBFBD><EFBFBD>
|
||||
Binary file not shown.
@ -4,9 +4,10 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
byte *bytes = Utility::BitConverter::FromUint8(20);
|
||||
std::cout << Utility::BitConverter::ToUint8(bytes, 0) << std::endl;
|
||||
getchar();
|
||||
std::vector<byte> bytes = Utility::BitConverter::FromInt32(50000);
|
||||
int32 integer = Utility::BitConverter::ToInt32(bytes);
|
||||
std::cout << integer << std::endl;
|
||||
std::cin.get();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -42,6 +42,7 @@
|
||||
<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">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
@ -51,7 +52,6 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Utility.cpp" />
|
||||
<ClCompile Include="..\..\src\VoidNetClient.cpp" />
|
||||
<ClCompile Include="TcpClient.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\DEV_INFO" />
|
||||
|
||||
@ -83,7 +83,7 @@
|
||||
<ClCompile Include="..\..\src\Handshake.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TcpClient.cpp">
|
||||
<ClCompile Include="..\..\src\TcpClient.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
||||
@ -187,8 +187,8 @@ enum ConnectionCode
|
||||
|
||||
enum InternalTags
|
||||
{
|
||||
CONNECT = 65534,
|
||||
DISCONNECT = 65535,
|
||||
CONNECT = 254,
|
||||
DISCONNECT = 255,
|
||||
};
|
||||
|
||||
#endif // DEFS_HPP
|
||||
@ -15,7 +15,7 @@ struct NetworkBuffer
|
||||
NetworkBuffer();
|
||||
~NetworkBuffer();
|
||||
|
||||
std::vector<byte> header = Utility::BitConverter::FromUint32(8); // contains the size of the body
|
||||
std::vector<byte> header; // size must always be 8
|
||||
std::vector<byte> body;
|
||||
};
|
||||
|
||||
|
||||
@ -54,13 +54,14 @@ struct Utility
|
||||
static const std::string &ToString(int16 value);
|
||||
static const std::string &ToString(int32 value);
|
||||
static const std::string &ToString(int64 value);
|
||||
static const std::string &ToString(const std::vector<byte> &bytes);
|
||||
|
||||
static const std::string &ToString(const std::vector<byte> &bytes, uint16 start_index = 0, uint16 lenght = 0);
|
||||
};
|
||||
|
||||
struct ConfigReader
|
||||
{
|
||||
const void ReadConfig(const std::string &file_name);
|
||||
void ReadConfig(const std::string &file_name);
|
||||
const std::map<std::string, std::string> &ReadNodes();
|
||||
|
||||
const std::string &operator[](uint16 index);
|
||||
|
||||
@ -75,8 +75,8 @@ void TcpClient::Shutdown()
|
||||
{
|
||||
NetworkMessage message;
|
||||
message.sender = id;
|
||||
message.distribution_mode = Server;
|
||||
message.tag = DISCONNECT;
|
||||
message.distribution_mode = static_cast<byte>(Server);
|
||||
message.tag = static_cast<byte>(DISCONNECT);
|
||||
SendMessage(message);
|
||||
uint16 code = closesocket(tcp_socket);
|
||||
if (code == SOCKET_ERROR)
|
||||
|
||||
@ -73,9 +73,8 @@ void TcpServer::Shutdown()
|
||||
{
|
||||
for (std::vector<TcpClient>::iterator it = clients.begin(); it != clients.end(); ++it)
|
||||
{
|
||||
TcpClient client = *it;
|
||||
client.Shutdown();
|
||||
clients.erase(std::find(clients.begin(), clients.end(), client));
|
||||
(*it).Shutdown();
|
||||
clients.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +112,7 @@ void TcpServer::accept_connections(TcpServer *server)
|
||||
std::cerr << WSAGetLastError() << std::endl;
|
||||
closesocket(server->server_tcp_socket);
|
||||
WSACleanup();
|
||||
server->running = false;
|
||||
server->running = false; // if we cant accept a connection idk if we should stop the server or not mh
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -98,65 +98,70 @@ int64 Utility::BitConverter::ToInt64(const std::vector<byte> & bytes, uint16 sta
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(bool value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(uint8 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(uint16 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(uint32 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(uint64 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(int8 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(int16 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(int32 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(int64 value)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(const std::vector<byte>& bytes)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const std::string & Utility::StringConverter::ToString(const std::vector<byte> & bytes, uint16 start_index, uint16 lenght)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
const void Utility::ConfigReader::ReadConfig(const std::string & file_name)
|
||||
void Utility::ConfigReader::ReadConfig(const std::string & file_name)
|
||||
{
|
||||
return void();
|
||||
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string>& Utility::ConfigReader::ReadNodes()
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
const std::string & Utility::ConfigReader::operator[](uint16 index)
|
||||
{
|
||||
// TODO: insert return statement here
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user