aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2014-07-16 20:33:51 -0400
committerFranklin Wei <frankhwei536@gmail.com>2014-07-16 20:34:56 -0400
commitd3d405d257a328e8454b851846703bb708e0a975 (patch)
tree3d88cb2976d0949e9dfe0de765b5018d7778fdd3
parente3f71f0b75062a755fe32082803c6c4175049834 (diff)
downloadwargames-server-d3d405d257a328e8454b851846703bb708e0a975.zip
wargames-server-d3d405d257a328e8454b851846703bb708e0a975.tar.gz
wargames-server-d3d405d257a328e8454b851846703bb708e0a975.tar.bz2
wargames-server-d3d405d257a328e8454b851846703bb708e0a975.tar.xz
Some more minor bugfixes
-rw-r--r--TRANSCRIPT4
-rw-r--r--server.c25
2 files changed, 18 insertions, 11 deletions
diff --git a/TRANSCRIPT b/TRANSCRIPT
index 9a6d843..23133de 100644
--- a/TRANSCRIPT
+++ b/TRANSCRIPT
@@ -39,7 +39,7 @@ WHICH SIDE DO YOU WANT?
1. UNITED STATES
2. SOVIET UNION
-PLEASE CHOOSE ONE: 2
+PLEASE CHOOSE ONE: 2
<CLEAR>
AWAITING FIRST STRIKE COMMAND (UNDERLINED)
@@ -54,4 +54,4 @@ Seattle
<ASCII ART OF US + USSR>
<US HAS TRAJECTORY HEADINGS OF ICBMS BOUND FOR LAS VEGAS AND SEATTLE>
-<SUBS REPRESENTED BY BLINKING DOTS ARE OFF US SHORELINES> \ No newline at end of file
+<SUBS REPRESENTED BY BLINKING DOTS ARE OFF US SHORELINES>
diff --git a/server.c b/server.c
index 2efa121..610796f 100644
--- a/server.c
+++ b/server.c
@@ -55,7 +55,7 @@ int make_server_socket(uint16_t port)
sock=socket(AF_INET, SOCK_STREAM, 0);
if(sock<0)
{
- debugf("error opening socket.\n");
+ debugf("FATAL: Error opening socket.\n");
return -1;
}
name.sin_family=AF_INET;
@@ -64,7 +64,7 @@ int make_server_socket(uint16_t port)
int ret=bind(sock, (struct sockaddr*) &name, sizeof(name));
if(ret<0)
{
- debugf("error binding to port %d\n", port);
+ debugf("FATAL: Error binding to port %d\n", port);
return -1;
}
return sock;
@@ -150,7 +150,7 @@ int process_data(int fd)
char ctrl_c[]={0xff, 0xf4, 0xff, 0xfd, 0x06, 0x00};
if(strcmp(ctrl_c, buf)==0)
{
- debugf("Got CTRL-C from client.\n");
+ debugf("Got CTRL-C from client %d.\n", fd);
return -1;
}
if(ret<0) /* error */
@@ -160,12 +160,12 @@ int process_data(int fd)
}
if(ret==0)
{
- debugf("EOF from client\n");
+ debugf("EOF from client %d.\n", fd);
return -1;
}
else
{
- debugf("Client sends: %s\n", buf);
+ 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 */
{
@@ -192,7 +192,9 @@ void setup_new_connection(int fd)
{
unsigned char will_naws[]={IAC, WILL, NAWS};
write(fd, will_naws, sizeof(will_naws));
- unsigned char dont_echo[]={IAC, WONT, ECHO};
+ unsigned char dont_echo[]={IAC, WILL, ECHO};
+ write(fd, dont_echo, sizeof(dont_echo));
+ dont_echo[1]=DONT;
write(fd, dont_echo, sizeof(dont_echo));
unsigned char dont_sga[]={IAC, WONT, SGA};
write(fd, dont_sga, sizeof(dont_sga));
@@ -213,7 +215,7 @@ int main(int argc, char* argv[])
int port2=atoi(argv[1]);
if(port2<0 || port2>65535)
{
- debugf("Port out of range.\n");
+ debugf("FATAL: Port out of range.\n");
return 2;
}
port=atoi(argv[1]);
@@ -226,7 +228,7 @@ int main(int argc, char* argv[])
struct sockaddr_in client;
if(listen(sock, 1)<0)
{
- debugf("Error opening socket.\n");
+ debugf("FATAL: Error opening socket.\n");
return 1;
}
FD_ZERO(&active_fd_set);
@@ -254,7 +256,7 @@ int main(int argc, char* argv[])
new=accept(sock, (struct sockaddr*) &client, &size);
if(new<0)
{
- debugf("Error accepting new connection.\n");
+ debugf("FATAL: Error accepting new connection.\n");
return 1;
}
debugf("New connection, number %d.\n", new);
@@ -265,6 +267,11 @@ int main(int argc, char* argv[])
debugf("Pipe error.\n");
}
pid_t pid=fork();
+ if(pid<0)
+ {
+ debugf("FATAL: Fork error.\n");
+ return 1;
+ }
if(pid==0) /* child */
{
/* set up the connection */