diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog
index 937ff5b..8b65bd7 100644
Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog differ
diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog
index fef2bcc..56ae1e2 100644
Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog differ
diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog
index 48ac30b..813be0b 100644
Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog differ
diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/unsuccessfulbuild b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/unsuccessfulbuild
deleted file mode 100644
index e69de29..0000000
diff --git a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj
index 1eef0c8..a7e809d 100644
--- a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj
+++ b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj
@@ -28,6 +28,7 @@
+
diff --git a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters
index c6ec425..527b7fc 100644
--- a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters
+++ b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters
@@ -45,6 +45,9 @@
include
+
+ include
+
diff --git a/include/Config.hpp b/include/Config.hpp
index 5a6516d..2dcb94a 100644
--- a/include/Config.hpp
+++ b/include/Config.hpp
@@ -13,8 +13,6 @@ struct Config
static void SetLogToFile(bool value);
static bool GetLogToFile();
-
-
private:
static bool using_console;
static bool log_to_file;
diff --git a/include/Defs.hpp b/include/Defs.hpp
index 8028c2a..75d8065 100644
--- a/include/Defs.hpp
+++ b/include/Defs.hpp
@@ -216,6 +216,8 @@ typedef unsigned long long uint64;
#endif // compiler data type defenitions
+typedef long long longlong;
+
const uint16 default_client_port = 60250;
const uint16 default_server_port = 61250;
diff --git a/include/TcpClient.hpp b/include/TcpClient.hpp
index ad3af38..382dcff 100644
--- a/include/TcpClient.hpp
+++ b/include/TcpClient.hpp
@@ -12,9 +12,8 @@
#pragma once
#endif
-class TcpClient
+struct TcpClient
{
-public:
TcpClient();
TcpClient(const SOCKET &socket);
TcpClient(const std::string &ip);
diff --git a/include/TcpServer.hpp b/include/TcpServer.hpp
index bea2620..4ac6ddf 100644
--- a/include/TcpServer.hpp
+++ b/include/TcpServer.hpp
@@ -11,9 +11,8 @@
#include
-class TcpServer
+struct TcpServer
{
-public:
TcpServer();
TcpServer(uint16 port = default_server_port);
~TcpServer();
diff --git a/include/UdpClient.hpp b/include/UdpClient.hpp
new file mode 100644
index 0000000..e95709b
--- /dev/null
+++ b/include/UdpClient.hpp
@@ -0,0 +1,13 @@
+#ifndef UDP_CLIENT_HPP
+#define UDP_CLIENT_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+struct UdpClient
+{
+
+};
+
+#endif
diff --git a/include/Utility.hpp b/include/Utility.hpp
index 2d56b4a..a257d00 100644
--- a/include/Utility.hpp
+++ b/include/Utility.hpp
@@ -57,14 +57,17 @@ struct Utility
static const std::string &ToString(const std::vector &bytes);
static const std::string &ToString(const std::vector &bytes, uint16 start_index = 0, uint16 lenght = 0);
+
+ static const std::string &Trim(std::string &str, char ch);
+ static std::vector Split(const std::string &str, const std::string &delimiter);
};
struct ConfigReader
{
void ReadConfig(const std::string &file_name);
- const std::map &ReadNodes();
+ void ReadNodes();
- const std::string &operator[](uint16 index);
+ const std::string &operator[](const std::string &key);
private:
std::map nodes;
diff --git a/include/VoidNetClient.hpp b/include/VoidNetClient.hpp
index 5bf0c51..712fd8b 100644
--- a/include/VoidNetClient.hpp
+++ b/include/VoidNetClient.hpp
@@ -32,7 +32,7 @@ struct VoidNetClientAPI
private:
static void receive_data();
- static TcpClient client;
+ static TcpClient tcp_client;
static uint16 id;
};
diff --git a/include/VoidNetServer.hpp b/include/VoidNetServer.hpp
index 870304b..a2dff8f 100644
--- a/include/VoidNetServer.hpp
+++ b/include/VoidNetServer.hpp
@@ -5,4 +5,12 @@
#pragma once
#endif
+#include "TcpServer.hpp"
+
+struct VoidNetServer
+{
+private:
+ TcpServer server;
+};
+
#endif
\ No newline at end of file
diff --git a/src/Utility.cpp b/src/Utility.cpp
index 3f3b7cb..7285157 100644
--- a/src/Utility.cpp
+++ b/src/Utility.cpp
@@ -1,5 +1,9 @@
#include "Utility.hpp"
+#include
+#include
+#include
+
void Utility::Delete(void *pointer)
{
if (pointer == nullptr)
@@ -16,6 +20,18 @@ void Utility::DeleteArray(void *pointer)
pointer = nullptr;
}
+std::vector Utility::StringConverter::Split(const std::string & str, const std::string & delimiter)
+{
+ std::vector splited;
+ if (str.empty() && delimiter.empty())
+ return std::vector();
+ std::stringstream ss(str);
+ std::string token;
+ while (std::getline(ss, token, delimiter[0]))
+ splited.push_back(token);
+ return splited;
+}
+
const std::vector &Utility::BitConverter::FromUint8(uint8 number)
{
return std::vector();
@@ -151,17 +167,55 @@ const std::string & Utility::StringConverter::ToString(const std::vector &
return std::string();
}
+const std::string & Utility::StringConverter::Trim(std::string & str, char ch)
+{
+ if (str.empty() && ch == 0)
+ return std::string();
+ for (std::string::iterator it = str.begin(); it != str.end(); ++it)
+ {
+ if (*it == ch)
+ str.erase(it);
+ }
+ return str;
+}
+
void Utility::ConfigReader::ReadConfig(const std::string & file_name)
{
-
+ if (file_name.empty())
+ return;
+ std::fstream file;
+ file.open(file_name);
+ if (file.is_open)
+ {
+ longlong file_lenght = file.gcount();
+ char *content = new char[file_lenght]();
+ file.read(content, file_lenght);
+ file_content = std::string(content);
+ }
}
-const std::map& Utility::ConfigReader::ReadNodes()
+void Utility::ConfigReader::ReadNodes()
{
- return std::map();
+ if (file_content.empty())
+ return;
+ std::stringstream ss(file_content);
+ std::string temp;
+ std::vector nodes_lines;
+ while (std::getline(ss, temp, '\n'))
+ {
+ if (temp.substr(0, 2) != "//")
+ nodes_lines.emplace_back(temp);
+ }
+
+ for (std::vector::iterator it = nodes_lines.begin(); it != nodes_lines.end(); ++it)
+ {
+ std::string node_str = Utility::StringConverter::Trim(*it, ' ');
+ std::vector node = Utility::StringConverter::Split(node_str, "=");
+ nodes.insert(std::pair(node.at(0), node.at(1)));
+ }
}
-const std::string & Utility::ConfigReader::operator[](uint16 index)
+const std::string & Utility::ConfigReader::operator[](const std::string &key)
{
- return std::string();
+ return nodes.at(key);
}
diff --git a/src/VoidNetClient.cpp b/src/VoidNetClient.cpp
index 776074c..dde69e3 100644
--- a/src/VoidNetClient.cpp
+++ b/src/VoidNetClient.cpp
@@ -5,9 +5,9 @@
bool VoidNetClientAPI::Connect(const std::string &ip, uint16 port)
{
- client.SetIP(ip);
- client.SetPort(port);
- return client.Connect();
+ tcp_client.SetIP(ip);
+ tcp_client.SetPort(port);
+ return tcp_client.Connect();
}
void VoidNetClientAPI::SendMessageToServer(byte tag, byte subject, void *data)
@@ -46,7 +46,7 @@ void VoidNetClientAPI::SendMessage(byte distribution_mode, uint16 destination_id
message.distribution_mode = distribution_mode;
message.sender = id;
message.destination_id = destination_id;
- client.SendMessage(message);
+ tcp_client.SendMessage(message);
}
}
@@ -57,10 +57,10 @@ void VoidNetClientAPI::Receive()
void VoidNetClientAPI::receive_data()
{
- client.ReceiveMessages();
+ tcp_client.ReceiveMessages();
}
void VoidNetClientAPI::Disconnect()
{
- client.Shutdown();
+ tcp_client.Shutdown();
}