summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2003-03-29 06:18:03 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2003-03-29 06:18:03 (GMT)
commit0a748cf59bcda4c8d8cc1bd62067abc7e86ce4a5 (patch)
treed48bc7b41f4b8946df6a9df654dfd1c87c946cad
parent88654d99ac56ecd088ba8abf253144cb3b416238 (diff)
downloadgrv-0a748cf59bcda4c8d8cc1bd62067abc7e86ce4a5.zip
grv-0a748cf59bcda4c8d8cc1bd62067abc7e86ce4a5.tar.gz
grv-0a748cf59bcda4c8d8cc1bd62067abc7e86ce4a5.tar.bz2
grv-0a748cf59bcda4c8d8cc1bd62067abc7e86ce4a5.tar.xz
Cheat codes shouldn't use Alt+Fx; too likely to interfere with window manager
Use winsock2 for networking
-rw-r--r--Makefile.w322
-rw-r--r--netopen.c16
-rw-r--r--play.c25
3 files changed, 24 insertions, 19 deletions
diff --git a/Makefile.w32 b/Makefile.w32
index b3f23de..b843b62 100644
--- a/Makefile.w32
+++ b/Makefile.w32
@@ -22,7 +22,7 @@ CFLAGS = $(OPTFLAGS) $(INCLUDE)
LDFLAGS = -mwindows -L$(SDL)/lib
# We need an extra helping of -lmingw32 before -lSDLmain to make sure
# WinMain is pulled in correctly
-LIBS = -lmingw32 -lSDLmain -lSDL -lwsock32
+LIBS = -lmingw32 -lSDLmain -lSDL -lws2_32
X = .exe
ALL = grv$(X)
diff --git a/netopen.c b/netopen.c
index 94b5bde..9b6a2a4 100644
--- a/netopen.c
+++ b/netopen.c
@@ -13,7 +13,7 @@
#include <string.h>
#include <io.h>
#include <fcntl.h>
-#include <winsock.h>
+#include <winsock2.h>
/* This is basically a lame subset of stdio functionality */
#define NETCON_BUF 32768
@@ -26,6 +26,7 @@ struct netcon {
};
static int winsock_started = 0;
+int socket_errno; /* For debuggability */
static void end_winsock(void)
{
@@ -50,6 +51,9 @@ static int input_get(netcon_t nc)
int rv;
rv = recv(nc->sock, nc->buffer, NETCON_BUF, 0);
+ if ( rv == SOCKET_ERROR )
+ socket_errno = WSAGetLastError();
+
nc->bufdata = nc->buffer;
nc->buffill = (rv == SOCKET_ERROR) ? 0 : rv;
@@ -65,9 +69,11 @@ static int output_send(netcon_t nc)
while ( count ) {
rv = send(nc->sock, p, count, 0);
- if ( rv == 0 || rv == SOCKET_ERROR )
+ if ( rv == 0 || rv == SOCKET_ERROR ) {
+ socket_errno = WSAGetLastError();
return -1;
-
+ }
+
p += rv;
count -= rv;
}
@@ -131,7 +137,7 @@ int fputs_network(const char *s, netcon_t nc)
sl = NETCON_BUF - nc->buffill; /* Space left */
if ( !sl ) {
- if ( output_send(nc) )
+ if ( output_send(nc) <= 0 )
return EOF; /* Error */
else
continue;
@@ -206,7 +212,7 @@ int fclose_network(netcon_t nc)
int rv = 0;
if ( nc->is_output && nc->buffill ) {
- if ( output_send(nc) )
+ if ( output_send(nc) <= 0 )
rv = EOF;
}
diff --git a/play.c b/play.c
index ba843e6..014d08c 100644
--- a/play.c
+++ b/play.c
@@ -103,28 +103,28 @@ static void handle_key(SDL_KeyboardEvent *ke)
if ( mod & (KMOD_RALT|KMOD_LALT) ) {
/* These keystrokes require <Alt> */
switch ( sym ) {
- case SDLK_F5:
+ case SDLK_q: /* Immediate death */
gp.Life = 0;
/* Fall through */
- case SDLK_F4:
+ case SDLK_w: /* Immediate death (one life) */
gp.EOLWait = 0;
/* Fall through */
- case SDLK_d:
+ case SDLK_d: /* Normal death */
gp.Status = Status_Dead;
break;
- case SDLK_l:
+ case SDLK_l: /* Immediate end of level */
gp.EOLWait = 0;
/* Fall through */
- case SDLK_e:
+ case SDLK_e: /* Normal end of level */
gp.Cheat = 1;
- gp.Status = Status_Done; /* End of level */
+ gp.Status = Status_Done;
break;
- case SDLK_p:
+ case SDLK_p: /* +1000 power */
gp.Cheat = 1;
gp.GkCh += 1000;
update_power();
break;
- case SDLK_x:
+ case SDLK_x: /* +1 life */
if ( gp.Life < 6 ) {
gp.Cheat = 1;
gp.Life++;
@@ -132,23 +132,22 @@ static void handle_key(SDL_KeyboardEvent *ke)
lprintf(1,16+2*gp.Life, "\x01");
}
break;
- case SDLK_w:
+ case SDLK_b: /* All white -> black */
gp.Cheat = 1;
while ( gp.nwhite )
white2black();
break;
- case SDLK_s:
+ case SDLK_s: /* +1 shot */
gp.Cheat = 1;
if ( gp.KulSpr < 90 )
gp.KulSpr++;
update_shots();
break;
- case SDLK_t:
+ case SDLK_t: /* Treasure */
gp.Cheat = 1;
mystery();
break;
- case SDLK_END:
- /* Zap game */
+ case SDLK_END: /* Immediate zap game */
exit(1);
default:
break;