]> granicus.if.org Git - nethack/commitdiff
SAFERHANGUP support for win32tty
authornethack.allison <nethack.allison>
Fri, 19 Sep 2003 11:22:00 +0000 (11:22 +0000)
committernethack.allison <nethack.allison>
Fri, 19 Sep 2003 11:22:00 +0000 (11:22 +0000)
win32gui support still needs to be developed.

include/ntconf.h
sys/winnt/nh340key.c
sys/winnt/nhdefkey.c
sys/winnt/nhraykey.c
sys/winnt/nttty.c

index 2761128017a530b961e254aebcfe17cb3ac528d0..ca111963c21f9b434147508defb6299282f8b85e 100644 (file)
 
 #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 */
index be3f870bf97b75aa2498886ef1df8642f3321777..fd078269d7ce7ec612caaaf17d7cabed32b7f5d3 100644 (file)
@@ -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) {
index 1b809b704dbcf9f8b35adefb4326a36e5ee52d79..ec2e3905b5d4adf8e30944feeb824407c575ce19 100644 (file)
@@ -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) {
index e1f4c8d88aea59cb95b5b784d996f84142380f9c..e057d8d856d83c76d32f1905820d4a031773ab2c 100644 (file)
@@ -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) {
index 88e20826bfb0f11df9ef83c10943efd310a51bb7..3615275f8c27fa7906cceca14f7c59d7792aa70b 100644 (file)
@@ -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;