1 #include "xrisk.h"
2 #include "xriskex.h"
3 #include "risklibex.h"
4 #include "xrisklibex.h"
5 
6 /* We lost connection to a player */
xrisk_errorhandler(display)7 int xrisk_errorhandler(display)
8      Display *display;
9 {
10   int t;
11   static int errnum = 0;
12   playerp player=NULL;
13 
14   if (++errnum > 100) risk_exit("To many errors occured (%d)",errnum,LAST_ARG);
15   Do_each_player(t) if (players[t]->xcon->disp == display) player=players[t];
16   if (!player) risk_exit("Mistake in xrisk_errorhandler",LAST_ARG);
17 
18   if ( player->state->state <= INIT_PL_STAT ) risk_exit
19     ("Player(%s) killed a window. Exiting to avoid trouble.\n",player->client);
20   fprintf(stderr,"Probably broken pipe server %s, forgets it and continues\n",
21 	  DisplayString(display));
22 
23   if (player->state->state < END_GAME)
24     {
25       player->xcon = NULL;
26       num_players--;
27       new_state(player,END_GAME);
28     }
29   players[player->indexs] = NULL;
30   (who_where[player->state->state]) ^= (1<<player->indexs);
31   write_msg_all_arg
32     ("#077_%s probably destroy a window in anger, but we fooled him"
33      ,player->name,LAST_ARG);
34   check_mission((playerp)NULL);
35   xrisk_mainloop();
36   return(0);
37 }
38 
init_errorhandlers()39 void init_errorhandlers()
40 {
41   /* Notice than xrisk_mainloop never returns */
42   /* Errors almost allways occures as a result of someone killing his window */
43   XSetIOErrorHandler(xrisk_errorhandler);
44 }
45