Update
NetworkMessage->GetData fixed Plugin -> Splitted message types PluginManager is now thread safe TcpConnection added list of events Properly handling disconnection now Fixed bug in Socket with error translation It crashes when it exits, i think it has something to do with shared ptrs or something
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <VoidNet_HL/NetworkMessage.hpp>
|
||||
#include <VoidNet_HL/InternalTags.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace std::net
|
||||
{
|
||||
@ -11,6 +13,29 @@ namespace std::net
|
||||
{
|
||||
}
|
||||
|
||||
virtual void HandleMessage(const NetworkMessage& msg) = 0;
|
||||
void HandleMessage(const NetworkMessage& msg)
|
||||
{
|
||||
if (msg.GetTag() == (uint32_t)InternalTags::Disconnect)
|
||||
{
|
||||
OnDisconnect(*(msg.GetData<string>()));
|
||||
}
|
||||
else if (msg.GetTag() == (uint32_t)InternalTags::Connect)
|
||||
{
|
||||
OnNewConnection(msg.GetSenderID(), msg.GetData<void>());
|
||||
}
|
||||
else if (msg.GetTag() == (uint32_t)InternalTags::AssignID)
|
||||
{
|
||||
OnConnection();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDataReceived(msg.GetSenderID(), msg.GetDistributionMode(), msg.GetDestinationID(), msg.GetTag(), msg.GetData<void>());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnDisconnect(string) abstract;
|
||||
virtual void OnNewConnection(uint32_t, void*) abstract;
|
||||
virtual void OnConnection() abstract;
|
||||
virtual void OnDataReceived(uint32_t, DistributionMode, uint32_t, uint32_t, void*) abstract;
|
||||
};
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include "VoidNet_HL/Plugin/Plugin.hpp"
|
||||
|
||||
@ -14,16 +15,24 @@ namespace std::net
|
||||
|
||||
void HandleMessage(const NetworkMessage& msg)
|
||||
{
|
||||
m_pluginsMutex.lock();
|
||||
|
||||
for (size_t i = 0; i < m_plugins.size(); i++)
|
||||
m_plugins.at(i)->HandleMessage(msg);
|
||||
|
||||
m_pluginsMutex.unlock();
|
||||
}
|
||||
|
||||
void AddPlugin(Plugin* p)
|
||||
{
|
||||
m_pluginsMutex.lock();
|
||||
m_plugins.emplace_back(p);
|
||||
m_pluginsMutex.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
vector<Plugin*> m_plugins;
|
||||
|
||||
mutex m_pluginsMutex;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user