dedicated.c
changeset 736 75bcef85daeb
parent 721 617a397f8b4b
child 770 c2eacca29601
equal deleted inserted replaced
735:995f97df3bd7 736:75bcef85daeb
    63 }
    63 }
    64 
    64 
    65 /* Signal handlers */
    65 /* Signal handlers */
    66 static void DedicatedSignalHandler(int sig)
    66 static void DedicatedSignalHandler(int sig)
    67 {
    67 {
    68 		_exit_game = true;
    68 	_exit_game = true;
    69 		signal(sig, DedicatedSignalHandler);
    69 	signal(sig, DedicatedSignalHandler);
    70 }
    70 }
    71 #endif
    71 #endif
    72 
    72 
    73 static const char *DedicatedVideoStart(char **parm) {
    73 static const char *DedicatedVideoStart(char **parm) {
    74 	_screen.width = _screen.pitch = _cur_resolution[0];
    74 	_screen.width = _screen.pitch = _cur_resolution[0];
    95 
    95 
    96 static bool InputWaiting()
    96 static bool InputWaiting()
    97 {
    97 {
    98 	struct timeval tv;
    98 	struct timeval tv;
    99 	fd_set readfds;
    99 	fd_set readfds;
       
   100 	byte ret;
   100 
   101 
   101 	tv.tv_sec = 0;
   102 	tv.tv_sec = 0;
   102 	tv.tv_usec = 1;
   103 	tv.tv_usec = 1;
   103 
   104 
   104 	FD_ZERO(&readfds);
   105 	FD_ZERO(&readfds);
   105 	FD_SET(STDIN, &readfds);
   106 	FD_SET(STDIN, &readfds);
   106 
   107 
   107 	/* don't care about writefds and exceptfds: */
   108 	/* don't care about writefds and exceptfds: */
   108 	select(STDIN+1, &readfds, NULL, NULL, &tv);
   109 	ret = select(STDIN + 1, &readfds, NULL, NULL, &tv);
   109 
   110 
   110 	if (FD_ISSET(STDIN, &readfds))
   111 	if (ret > 0)
   111 		return true;
   112 		return true;
   112 	else
   113 	else
   113 		return false;
   114 		return false;
   114 }
   115 }
   115 #else
   116 #else
   126 #endif
   127 #endif
   127 	static char input_line[200] = "";
   128 	static char input_line[200] = "";
   128 
   129 
   129 #ifdef UNIX
   130 #ifdef UNIX
   130 	if (InputWaiting()) {
   131 	if (InputWaiting()) {
       
   132 		if (_exit_game)
       
   133 			return;
       
   134 
   131 		fgets(input_line, 200, stdin);
   135 		fgets(input_line, 200, stdin);
   132 		// Forget about the final \n (or \r)
   136 		// Forget about the final \n (or \r)
   133 		strtok(input_line, "\r\n");
   137 		strtok(input_line, "\r\n");
   134 		IConsoleCmdExec(input_line);
   138 		IConsoleCmdExec(input_line);
   135 	}
   139 	}
   165 
   169 
   166 	/* Siganl handlers */
   170 	/* Siganl handlers */
   167 #ifdef UNIX
   171 #ifdef UNIX
   168 	signal(SIGTERM, DedicatedSignalHandler);
   172 	signal(SIGTERM, DedicatedSignalHandler);
   169 	signal(SIGINT, DedicatedSignalHandler);
   173 	signal(SIGINT, DedicatedSignalHandler);
   170 	signal(SIGABRT, DedicatedSignalHandler);
   174 	signal(SIGQUIT, DedicatedSignalHandler);
   171 #endif
   175 #endif
   172 
   176 
   173 	// Load the dedicated server stuff
   177 	// Load the dedicated server stuff
   174 	_is_network_server = true;
   178 	_is_network_server = true;
   175 	_network_dedicated = true;
   179 	_network_dedicated = true;