summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2019-01-10 18:25:20 -0500
committergumi <git@gumi.ca>2019-01-10 19:43:09 -0500
commitd8145c4f940a664eb403f7acca10f2caf86e5330 (patch)
tree8744da55214c50e6d0c742b6f89445e86b2733da
parent6b70eb63ffcd46859cfce8ec7d063c3f3b1421f5 (diff)
downloadtmwa-d8145c4f940a664eb403f7acca10f2caf86e5330.tar.gz
tmwa-d8145c4f940a664eb403f7acca10f2caf86e5330.tar.bz2
tmwa-d8145c4f940a664eb403f7acca10f2caf86e5330.tar.xz
tmwa-d8145c4f940a664eb403f7acca10f2caf86e5330.zip
kill idle connections to login-server after a while
-rw-r--r--src/login/login.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/login/login.cpp b/src/login/login.cpp
index c8a44c2..68898ca 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -164,7 +164,7 @@ void delete_login(Session *sess)
(void)sess;
}
-std::vector<IP4Address> recent_ips;
+static std::vector<IP4Address> recent_ips;
static
void conn_limit_empty(TimerData *, tick_t)
@@ -2355,6 +2355,16 @@ bool lan_ip_check(IP4Address p)
return lancheck;
}
+static
+void login_waitclose(TimerData *, tick_t, Session *s)
+{
+ if (s)
+ {
+ LOGIN_LOG_AND_ECHO("Idle session: disconnecting IP %s.\n"_fmt, s->client_ip);
+ s->set_eof();
+ }
+}
+
//----------------------------------------------------------------------------------------
// Default packet parsing (normal players or administration/char-server connection requests)
//----------------------------------------------------------------------------------------
@@ -2367,6 +2377,15 @@ void parse_login(Session *s)
IP4Address ip = s->client_ip;
RecvResult rv = RecvResult::Complete;
uint16_t packet_id;
+
+ if (!login_lan_conf.lan_subnet.covers(ip) && !s->timed_close)
+ {
+ // there is no valid reason to stay connected to login-server longer
+ // than a few seconds, even with huge network lag
+ s->timed_close = Timer(gettick() + 90_s, std::bind(login_waitclose,
+ std::placeholders::_1, std::placeholders::_2, s));
+ }
+
while (rv == RecvResult::Complete && packet_peek_id(s, &packet_id))
{
if (login_conf.display_parse_login)