From: nethack.allison Date: Fri, 19 Sep 2003 11:22:00 +0000 (+0000) Subject: SAFERHANGUP support for win32tty X-Git-Tag: MOVE2GIT~1770 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=018123c00761aaf864e0803e423194e251da2167;p=nethack SAFERHANGUP support for win32tty win32gui support still needs to be developed. --- diff --git a/include/ntconf.h b/include/ntconf.h index 276112801..ca111963c 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -57,6 +57,11 @@ #ifdef WIN32CON #define PORT_DEBUG /* include ability to debug international keyboard issues */ +#define SAFERHANGUP /* Define SAFERHANGUP to delay hangup processing + * until the main command loop. 'safer' because it + * avoids certain cheats and also avoids losing + * objects being thrown when the hangup occurs. + */ #endif /* The following is needed for prototypes of certain functions */ diff --git a/sys/winnt/nh340key.c b/sys/winnt/nh340key.c index be3f870bf..fd078269d 100644 --- a/sys/winnt/nh340key.c +++ b/sys/winnt/nh340key.c @@ -224,9 +224,19 @@ int mode; int *mod; coord *cc; { +#if defined(SAFERHANGUP) + DWORD dwWait; +#endif int ch; boolean valid = 0, done = 0; while (!done) { +#if defined(SAFERHANGUP) + dwWait = WaitForSingleObjectEx( + hConIn, // event object to wait for + INFINITE, // waits indefinitely + TRUE); // alertable wait enabled + if (dwWait == WAIT_FAILED) return '\033'; +#endif ReadConsoleInput(hConIn,ir,1,count); if (mode == 0) { if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { diff --git a/sys/winnt/nhdefkey.c b/sys/winnt/nhdefkey.c index 1b809b704..ec2e3905b 100644 --- a/sys/winnt/nhdefkey.c +++ b/sys/winnt/nhdefkey.c @@ -25,6 +25,8 @@ static char author[] = "The NetHack Development Team"; extern HANDLE hConIn; extern INPUT_RECORD ir; +extern struct sinfo program_state; + char dllname[512]; char *shortdllname; @@ -256,9 +258,20 @@ int mode; int *mod; coord *cc; { +#if defined(SAFERHANGUP) + DWORD dwWait; +#endif int ch; boolean valid = 0, done = 0; while (!done) { + +#if defined(SAFERHANGUP) + dwWait = WaitForSingleObjectEx( + hConIn, // event object to wait for + INFINITE, // waits indefinitely + TRUE); // alertable wait enabled + if (dwWait == WAIT_FAILED) return '\033'; +#endif ReadConsoleInput(hConIn,ir,1,count); if (mode == 0) { if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { diff --git a/sys/winnt/nhraykey.c b/sys/winnt/nhraykey.c index e1f4c8d88..e057d8d85 100644 --- a/sys/winnt/nhraykey.c +++ b/sys/winnt/nhraykey.c @@ -455,11 +455,17 @@ int *mod; boolean numpad; coord *cc; { +#if defined(SAFERHANGUP) + DWORD dwWait; +#endif int ch; boolean valid = 0, done = 0; while (!done) { *count = 0; - WaitForSingleObject(hConIn, INFINITE); + dwWait = WaitForSingleObject(hConIn, INFINITE); +#if defined(SAFERHANGUP) + if (dwWait == WAIT_FAILED) return '\033'; +#endif PeekConsoleInput(hConIn,ir,1,count); if (mode == 0) { if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) { diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 88e20826b..3615275f8 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -258,9 +258,9 @@ DWORD ctrltype; #ifndef NOSAVEONHANGUP hangup(0); #endif -#if 0 - clearlocks(); - terminate(EXIT_FAILURE); +#if defined(SAFERHANGUP) + CloseHandle(hConIn); /* trigger WAIT_FAILED */ + return TRUE; #endif default: return FALSE; @@ -376,7 +376,9 @@ tgetch() int mod; coord cc; DWORD count; - return pCheckInput(hConIn, &ir, &count, iflags.num_pad, 0, &mod, &cc); + return (program_state.done_hup) ? + '\033' : + pCheckInput(hConIn, &ir, &count, iflags.num_pad, 0, &mod, &cc); } int @@ -386,7 +388,9 @@ int *x, *y, *mod; int ch; coord cc; DWORD count; - ch = pCheckInput(hConIn, &ir, &count, iflags.num_pad, 1, mod, &cc); + ch = (program_state.done_hup) ? + '\033' : + pCheckInput(hConIn, &ir, &count, iflags.num_pad, 1, mod, &cc); if (!ch) { *x = cc.x; *y = cc.y;