mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-20 13:48:22 +00:00
Comms stuff
This commit is contained in:
@@ -26,6 +26,8 @@ namespace EQ
|
||||
bool Connected() const { return m_connecting != true; }
|
||||
|
||||
std::shared_ptr<EQ::Net::TCPConnection> Handle() { return m_connection; }
|
||||
|
||||
std::string GetIdentifier() const { return m_identifier; }
|
||||
private:
|
||||
void Connect();
|
||||
void ProcessData(EQ::Net::TCPConnection *c, const unsigned char *data, size_t length);
|
||||
|
||||
@@ -19,16 +19,26 @@ void EQ::Net::ServertalkServer::Listen(const ServertalkServerOptions& opts)
|
||||
});
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionIdentified(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb)
|
||||
void EQ::Net::ServertalkServer::OnConnectionIdentified(const std::string &type, IdentityCallback cb)
|
||||
{
|
||||
m_on_ident.insert(std::make_pair(type, cb));
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionRemoved(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb)
|
||||
void EQ::Net::ServertalkServer::OnConnectionRemoved(const std::string &type, IdentityCallback cb)
|
||||
{
|
||||
m_on_disc.insert(std::make_pair(type, cb));
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionIdentified(IdentityCallback cb)
|
||||
{
|
||||
m_on_any_ident = cb;
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionRemoved(IdentityCallback cb)
|
||||
{
|
||||
m_on_any_disc = cb;
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::ConnectionDisconnected(ServertalkServerConnection *conn)
|
||||
{
|
||||
if (conn->GetIdentifier().empty()) {
|
||||
@@ -51,6 +61,11 @@ void EQ::Net::ServertalkServer::ConnectionDisconnected(ServertalkServerConnectio
|
||||
if (on_disc != m_on_disc.end()) {
|
||||
on_disc->second(*iter);
|
||||
}
|
||||
|
||||
if (m_on_any_disc) {
|
||||
m_on_any_disc(*iter);
|
||||
}
|
||||
|
||||
type->second.erase(iter);
|
||||
return;
|
||||
}
|
||||
@@ -70,6 +85,10 @@ void EQ::Net::ServertalkServer::ConnectionIdentified(ServertalkServerConnection
|
||||
on_ident->second(*iter);
|
||||
}
|
||||
|
||||
if (m_on_any_ident) {
|
||||
m_on_any_ident(*iter);
|
||||
}
|
||||
|
||||
if (m_ident_connections.count(conn->GetIdentifier()) > 0) {
|
||||
auto &vec = m_ident_connections[conn->GetIdentifier()];
|
||||
vec.push_back(*iter);
|
||||
|
||||
@@ -36,12 +36,16 @@ namespace EQ
|
||||
class ServertalkServer
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(std::shared_ptr<ServertalkServerConnection>)> IdentityCallback;
|
||||
|
||||
ServertalkServer();
|
||||
~ServertalkServer();
|
||||
|
||||
void Listen(const ServertalkServerOptions& opts);
|
||||
void OnConnectionIdentified(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb);
|
||||
void OnConnectionRemoved(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb);
|
||||
void OnConnectionIdentified(const std::string &type, IdentityCallback cb);
|
||||
void OnConnectionRemoved(const std::string &type, IdentityCallback cb);
|
||||
void OnConnectionIdentified(IdentityCallback cb);
|
||||
void OnConnectionRemoved(IdentityCallback cb);
|
||||
|
||||
private:
|
||||
void ConnectionDisconnected(ServertalkServerConnection *conn);
|
||||
@@ -52,8 +56,10 @@ namespace EQ
|
||||
std::vector<std::shared_ptr<ServertalkServerConnection>> m_unident_connections;
|
||||
std::map<std::string, std::vector<std::shared_ptr<ServertalkServerConnection>>> m_ident_connections;
|
||||
|
||||
std::map<std::string, std::function<void(std::shared_ptr<ServertalkServerConnection>)>> m_on_ident;
|
||||
std::map<std::string, std::function<void(std::shared_ptr<ServertalkServerConnection>)>> m_on_disc;
|
||||
std::map<std::string, IdentityCallback> m_on_ident;
|
||||
std::map<std::string, IdentityCallback> m_on_disc;
|
||||
IdentityCallback m_on_any_ident;
|
||||
IdentityCallback m_on_any_disc;
|
||||
bool m_encrypted;
|
||||
bool m_allow_downgrade;
|
||||
std::string m_credentials;
|
||||
|
||||
Reference in New Issue
Block a user