Handle IAC (well ignore it)

This commit is contained in:
Andrew Pamment 2020-10-12 17:10:28 +10:00
parent 318b385ce4
commit 29a19692fe

View File

@ -10,12 +10,17 @@
#include <string.h>
#include "MagiDoor.h"
#define IAC 255
extern time_t mdtimeout;
extern time_t mdtimeremaining;
char md_getc() {
char c;
ssize_t ret;
int stage = 0;
while (1) {
if (mdcontrol.socket == -1) {
ret = read(STDIN_FILENO, &c, 1);
@ -41,6 +46,35 @@ char md_getc() {
usleep(100);
continue;
}
if (mdcontrol.socket != -1) {
if ((unsigned char)c == IAC && stage == 0) {
stage = 1;
continue;
}
if (stage == 1) {
if ((unsigned char)c == IAC) {
stage = 0;
} else if ((unsigned char)c == 250) {
stage = 3;
continue;
} else {
stage = 2;
continue;
}
}
if (stage == 2) {
stage = 0;
continue;
}
if (stage == 3) {
if ((unsigned char)c == 240) {
stage = 0;
}
continue;
}
}
mdtimeout = time(NULL) + 900;
return c;
}