Now removing all known telnet codes from the string received from the client

Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely Polonkai (W00d5t0ck) 2012-03-27 12:38:57 +02:00
parent 419321d9b9
commit 188ce00473
2 changed files with 40 additions and 1 deletions

View File

@ -117,6 +117,9 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient
if (r || n) if (r || n)
{ {
gint i,
sloc = -1;
if ((r < n) && r) if ((r < n) && r)
{ {
if (client->buffer->len > 0) if (client->buffer->len > 0)
@ -134,6 +137,30 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient
buf2 = n; 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) switch (client->state)
{ {
case WMUD_CLIENT_STATE_FRESH: case WMUD_CLIENT_STATE_FRESH:
@ -170,7 +197,7 @@ wmud_client_callback(GSocket *client_socket, GIOCondition condition, wmudClient
{ {
if (wmud_player_auth(client)) 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, " successful.\r\n", TELNET_IAC,
TELNET_WONT, TELNET_ECHO); TELNET_WONT, TELNET_ECHO);
client->authenticated = TRUE; client->authenticated = TRUE;

View File

@ -41,6 +41,18 @@
* Telnet WILL code * Telnet WILL code
*/ */
#define TELNET_WILL '\xfb' #define TELNET_WILL '\xfb'
/**
* TELNET_DO:
*
* Telnet DO code
*/
#define TELNET_DO '\xfd'
/**
* TELNET_DONT:
*
* Telnet DONT code
*/
#define TELNET_DONT '\xfe'
/** /**
* TELNET_ECHO: * TELNET_ECHO:
* *