diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog index 7f91709..937ff5b 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 57bc734..fef2bcc 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 e4491a3..48ac30b 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 new file mode 100644 index 0000000..e69de29 diff --git a/include/TcpServer.hpp b/include/TcpServer.hpp index 22e6b47..bea2620 100644 --- a/include/TcpServer.hpp +++ b/include/TcpServer.hpp @@ -7,6 +7,7 @@ #include "Defs.hpp" #include "TcpClient.hpp" +#include "Handshake.hpp" #include @@ -38,7 +39,7 @@ public: const TcpClient &GetClientByID(uint16 id); - std::function OnMessage; // this is going to be used for plugins + std::vector> OnMessageFunctions; // this is going to be used for plugins private: static void process_client_messages(TcpServer *server, TcpClient &client); diff --git a/include/VoidNetClient.hpp b/include/VoidNetClient.hpp index 9a564d8..5bf0c51 100644 --- a/include/VoidNetClient.hpp +++ b/include/VoidNetClient.hpp @@ -30,9 +30,10 @@ struct VoidNetClientAPI static void Receive(); private: + static void receive_data(); + static TcpClient client; static uint16 id; - static bool receive; }; #endif diff --git a/src/TcpClientWindows.cpp b/src/TcpClientWindows.cpp index 3b6a49d..2e2c4d9 100644 --- a/src/TcpClientWindows.cpp +++ b/src/TcpClientWindows.cpp @@ -55,8 +55,8 @@ void TcpClient::Shutdown() { NetworkMessage message; message.sender = id; - message.distribution_mode = static_cast(Server); - message.tag = static_cast(DISCONNECT); + message.distribution_mode = Server; + message.tag = DISCONNECT; SendMessage(message); uint16 code = closesocket(tcp_socket); if (code == SOCKET_ERROR) diff --git a/src/TcpServer.cpp b/src/TcpServer.cpp index 471b445..d153329 100644 --- a/src/TcpServer.cpp +++ b/src/TcpServer.cpp @@ -60,7 +60,8 @@ void TcpServer::SendMessage(const NetworkMessage & message) if (message.sender != client.GetID()) client.SendMessage(message); } - OnMessage(message); + for (uint16 i = 0; i < OnMessageFunctions.size(); i++) + OnMessageFunctions[i](message); break; } case AllAndMe: // this will send the message to EVERYONE including the user that sent it @@ -70,14 +71,16 @@ void TcpServer::SendMessage(const NetworkMessage & message) TcpClient client = *it; client.SendMessage(message); } - OnMessage(message); + for (uint16 i = 0; i < OnMessageFunctions.size(); i++) + OnMessageFunctions[i](message); break; } case Server: // this will only send the message to the server { if (message.tag == DISCONNECT) CloseSocket(message.sender); - OnMessage(message); + for (uint16 i = 0; i < OnMessageFunctions.size(); i++) + OnMessageFunctions[i](message); break; } case Others: // this will send the message to others, excluding server and the user that sent it @@ -106,7 +109,7 @@ void TcpServer::SendMessage(const NetworkMessage & message) } } -void TcpServer::SendHandshake(const Handshake &handshake) +void TcpServer::SendHandshake(const Handshake & handshake) { switch (handshake.distribution_mode) { diff --git a/src/VoidNetClient.cpp b/src/VoidNetClient.cpp index 408df29..776074c 100644 --- a/src/VoidNetClient.cpp +++ b/src/VoidNetClient.cpp @@ -52,11 +52,15 @@ void VoidNetClientAPI::SendMessage(byte distribution_mode, uint16 destination_id void VoidNetClientAPI::Receive() { - std::async(std::launch::async, &client.ReceiveMessages); + std::async(std::launch::async, &receive_data); +} + +void VoidNetClientAPI::receive_data() +{ + client.ReceiveMessages(); } void VoidNetClientAPI::Disconnect() { - receive = false; - SendMessageToServer + client.Shutdown(); }