diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2014-07-18 21:44:54 -0400 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2014-07-18 21:44:54 -0400 |
| commit | 004a0431b5af8b87462d40689c262f912b9d7e4e (patch) | |
| tree | 347afd7d5dd6c47cd6dc6bee4e19fafcc810eef9 | |
| parent | 4233f6c3fa0928b773a1076eda4e82b3e75af97e (diff) | |
| download | wargames-server-004a0431b5af8b87462d40689c262f912b9d7e4e.zip wargames-server-004a0431b5af8b87462d40689c262f912b9d7e4e.tar.gz wargames-server-004a0431b5af8b87462d40689c262f912b9d7e4e.tar.bz2 wargames-server-004a0431b5af8b87462d40689c262f912b9d7e4e.tar.xz | |
Some bugfixes
| -rw-r--r-- | server.c | 27 | ||||
| -rw-r--r-- | telnet.h | 2 | ||||
| -rw-r--r-- | util.c | 11 |
3 files changed, 27 insertions, 13 deletions
@@ -103,6 +103,7 @@ void handle_command(unsigned char* buf, int buflen, int connection) { case NAWS: { + printf("NAWS command recieved.\n"); /* format of NAWS data: IAC SB NAWS W W H H IAC SE */ uint16_t height, width; uint8_t height_hi, height_lo, width_hi, width_lo; @@ -132,8 +133,10 @@ void handle_command(unsigned char* buf, int buflen, int connection) { deny_cmd[1]=WILL; } + /* write(connection, deny_cmd, sizeof(deny_cmd)); fsync(connection); + */ return; } int process_data(int fd) @@ -141,6 +144,7 @@ int process_data(int fd) unsigned char buf[1024]; memset(buf, 0, sizeof(buf)); int ret=read(fd, buf, sizeof(buf)); + debugf("Client %d sends: %s\n", fd, buf); debugf("Byte dump of data: "); for(int i=0;buf[i];++i) { @@ -165,7 +169,6 @@ int process_data(int fd) } else { - debugf("Client %d sends: %s\n", fd, buf); int buflen=strlen(buf); if(buflen>0) /* no need to write nothing to the input stream :D */ { @@ -190,16 +193,22 @@ void serv_cleanup() } void setup_new_connection(int fd) { - unsigned char will_naws[]={IAC, WILL, NAWS}; + unsigned char will_naws[]={IAC, DO, NAWS}; write(fd, will_naws, sizeof(will_naws)); - unsigned char dont_echo[]={IAC, WILL, ECHO}; + will_naws[1]=WILL; + write(fd, will_naws, sizeof(will_naws)); + + unsigned char dont_echo[]={IAC, DONT, ECHO}; write(fd, dont_echo, sizeof(dont_echo)); - dont_echo[1]=DONT; + dont_echo[1]=WONT; write(fd, dont_echo, sizeof(dont_echo)); + unsigned char dont_sga[]={IAC, WONT, SGA}; write(fd, dont_sga, sizeof(dont_sga)); + unsigned char will_linemode[]={IAC, WILL, LINEMODE}; write(fd, will_linemode, sizeof(will_linemode)); + memset(&connection_data[fd], 0, sizeof(struct connection_data_t)); debugf("New connection set up.\n"); } @@ -256,8 +265,8 @@ int main(int argc, char* argv[]) new=accept(sock, (struct sockaddr*) &client, &size); if(new<0) { - debugf("FATAL: Error accepting new connection.\n"); - return 1; + debugf("Error accepting new connection.\n"); + continue; } debugf("New connection, number %d.\n", new); FD_SET(new, &active_fd_set); @@ -265,12 +274,13 @@ int main(int argc, char* argv[]) if(ret<0) { debugf("Pipe error.\n"); + continue; } pid_t pid=fork(); if(pid<0) { - debugf("FATAL: Fork error.\n"); - return 1; + debugf("Fork error.\n"); + continue; } if(pid==0) /* child */ { @@ -290,6 +300,7 @@ int main(int argc, char* argv[]) { shutdown(i, SHUT_RDWR); FD_CLR(i, &active_fd_set); + /* should kill the child associated with this connection, too */ } } } @@ -20,5 +20,5 @@ #define ECHO 1 #define TERMTYPE 24 #define NAWS 31 -#define SURPRESS_LOCAL_ECHO 0x2D +#define SURPRESS_LOCAL_ECHO 45 #define LINEMODE 34 @@ -19,6 +19,7 @@ */ #include "strings.h" +#include "telnet.h" #include "util.h" #include <ctype.h> #include <string.h> @@ -39,9 +40,9 @@ void print_string(const char* str) /* print string, slowly */ while(str[i]) { if(str[i]=='\n') - write(out_fd, "\r\n", 2); + write(out_fd, "\r\n", 2); else - write(out_fd, &str[i], 1); + write(out_fd, &str[i], 1); fsync(out_fd); usleep(SLEEP_TIME); ++i; @@ -89,13 +90,15 @@ int getnstr(char* buf, int max) } void echo_off(void) { - unsigned char echo_off[]={0xff, 254, 1}; + unsigned char echo_off[]={IAC, WILL, ECHO}; + write(out_fd, echo_off, 3); + echo_off[1]=DONT; write(out_fd, echo_off, 3); fsync(out_fd); } void echo_on(void) { - unsigned char echo_on[]={0xff, 253, 1}; + unsigned char echo_on[]={IAC, DO, ECHO}; write(out_fd, echo_on, 3); fsync(out_fd); } |