[Telnet] Automatically prune connections

This commit is contained in:
Akkadius 2024-12-14 21:16:14 -06:00
parent 4493ebebab
commit aa8b0570d6
2 changed files with 14 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include "../eqemu_logsys.h"
#include "../servertalk.h"
#include "../rulesys.h"
#include "../event/timer.h"
#include <fmt/format.h>
EQ::Net::ConsoleServerConnection::ConsoleServerConnection(ConsoleServer *parent, std::shared_ptr<TCPConnection> connection)
@ -21,7 +22,13 @@ EQ::Net::ConsoleServerConnection::ConsoleServerConnection(ConsoleServer *parent,
m_connection->OnDisconnect(std::bind(&ConsoleServerConnection::OnDisconnect, this, std::placeholders::_1));
m_connection->Start();
ClearBuffer();
m_keepalive = std::make_unique<EQ::Timer>(1000, true, [this](EQ::Timer *t) {
EQ::Net::DynamicPacket clear;
clear.PutUInt8(0, 0);
m_connection->Write((const char*)clear.Data(), clear.Length());
});
auto addr = m_connection->RemoteIP();
SendLine(fmt::format("Establishing connection from: {0}:{1}", addr, m_connection->RemotePort()));
@ -85,12 +92,12 @@ void EQ::Net::ConsoleServerConnection::QueueMessage(const std::string &msg)
}
else {
std::string cmd(m_line, m_line + m_cursor);
size_t len = m_user.length() + 2 + cmd.length();
for (size_t i = 0; i < len; ++i) {
Send("\x08");
}
if (msg.length() < cmd.length()) {
Send(msg);
size_t blank_spaces = 2 + cmd.length() - msg.length();
@ -227,6 +234,8 @@ void EQ::Net::ConsoleServerConnection::OnRead(TCPConnection *c, const unsigned c
void EQ::Net::ConsoleServerConnection::OnDisconnect(TCPConnection *c)
{
LogInfo("Console connection disconnected");
m_parent->ConnectionDisconnected(this);
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "tcp_server.h"
#include "../event/timer.h"
#include <memory>
#include <map>
@ -58,6 +59,7 @@ namespace EQ
int m_user_id;
int m_admin;
bool m_accept_messages;
std::unique_ptr<EQ::Timer> m_keepalive;
size_t m_cursor;
char m_line[MaxConsoleLineLength];