From 188ce00473cdf0c90b9cb77fb14dfc7b8b66ac36 Mon Sep 17 00:00:00 2001 From: "Gergely Polonkai (W00d5t0ck)" Date: Tue, 27 Mar 2012 12:38:57 +0200 Subject: [PATCH] Now removing all known telnet codes from the string received from the client Signed-off-by: Gergely Polonkai (W00d5t0ck) --- src/game-networking.c | 29 ++++++++++++++++++++++++++++- src/game-networking.h | 12 ++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/game-networking.c b/src/game-networking.c index 51544a7..1f546fa 100644 --- a/src/game-networking.c +++ b/src/game-networking.c @@ -117,6 +117,9 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient if (r || n) { + gint i, + sloc = -1; + if ((r < n) && r) { if (client->buffer->len > 0) @@ -134,6 +137,30 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient buf2 = n; } + /* Remove telnet codes from the string */ + for (i = 0; i < client->buffer->len; i++) + { + guchar c = (client->buffer->str)[i]; + + if ((c >= 240) || (c == 1)) + { + if (sloc == -1) + sloc = i; + } + else + { + if (sloc != -1) + { + g_string_erase(client->buffer, sloc, i - sloc); + sloc = -1; + } + } + } + if (sloc != -1) + { + g_string_erase(client->buffer, sloc, -1); + } + switch (client->state) { case WMUD_CLIENT_STATE_FRESH: @@ -170,7 +197,7 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient { if (wmud_player_auth(client)) { - wmud_client_send(client, "%c%c%cLogin" + wmud_client_send(client, "%c%c%c\r\nLogin" " successful.\r\n", TELNET_IAC, TELNET_WONT, TELNET_ECHO); client->authenticated = TRUE; diff --git a/src/game-networking.h b/src/game-networking.h index 4a63bd3..a44b902 100644 --- a/src/game-networking.h +++ b/src/game-networking.h @@ -41,6 +41,18 @@ * Telnet WILL code */ #define TELNET_WILL '\xfb' +/** + * TELNET_DO: + * + * Telnet DO code + */ +#define TELNET_DO '\xfd' +/** + * TELNET_DONT: + * + * Telnet DONT code + */ +#define TELNET_DONT '\xfe' /** * TELNET_ECHO: *