equal
deleted
inserted
replaced
15 #endif |
15 #endif |
16 #ifdef UNIX |
16 #ifdef UNIX |
17 # include <sys/time.h> /* gettimeofday */ |
17 # include <sys/time.h> /* gettimeofday */ |
18 # include <sys/types.h> |
18 # include <sys/types.h> |
19 # include <unistd.h> |
19 # include <unistd.h> |
|
20 # include <signal.h> |
20 # define STDIN 0 /* file descriptor for standard input */ |
21 # define STDIN 0 /* file descriptor for standard input */ |
21 #endif |
22 #endif |
22 |
23 |
23 // This file handles all dedicated-server in- and outputs |
24 // This file handles all dedicated-server in- and outputs |
24 |
25 |
25 static void *_dedicated_video_mem; |
26 static void *_dedicated_video_mem; |
|
27 |
|
28 #ifdef UNIX |
|
29 /* Signal handlers */ |
|
30 void DedicatedSignalHandler(int sig) |
|
31 { |
|
32 _exit_game = true; |
|
33 signal(sig, DedicatedSignalHandler); |
|
34 } |
|
35 #endif |
26 |
36 |
27 static const char *DedicatedVideoStart(char **parm) { |
37 static const char *DedicatedVideoStart(char **parm) { |
28 _screen.width = _screen.pitch = _cur_resolution[0]; |
38 _screen.width = _screen.pitch = _cur_resolution[0]; |
29 _screen.height = _cur_resolution[1]; |
39 _screen.height = _cur_resolution[1]; |
30 _dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]); |
40 _dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]); |
86 #ifdef WIN32 |
96 #ifdef WIN32 |
87 next_tick = GetTickCount() + 30; |
97 next_tick = GetTickCount() + 30; |
88 #else |
98 #else |
89 gettimeofday(&tim, NULL); |
99 gettimeofday(&tim, NULL); |
90 next_tick = (tim.tv_usec / 1000) + 30 + (tim.tv_sec * 1000); |
100 next_tick = (tim.tv_usec / 1000) + 30 + (tim.tv_sec * 1000); |
|
101 #endif |
|
102 |
|
103 /* Siganl handlers */ |
|
104 #ifdef UNIX |
|
105 signal(SIGTERM, DedicatedSignalHandler); |
|
106 signal(SIGINT, DedicatedSignalHandler); |
91 #endif |
107 #endif |
92 |
108 |
93 // Load the dedicated server stuff |
109 // Load the dedicated server stuff |
94 _is_network_server = true; |
110 _is_network_server = true; |
95 _network_dedicated = true; |
111 _network_dedicated = true; |
104 return ML_QUIT; |
120 return ML_QUIT; |
105 } |
121 } |
106 |
122 |
107 while (true) { |
123 while (true) { |
108 InteractiveRandom(); // randomness |
124 InteractiveRandom(); // randomness |
|
125 |
|
126 if (_exit_game) return ML_QUIT; |
109 |
127 |
110 #ifdef UNIX |
128 #ifdef UNIX |
111 if (InputWaiting()) { |
129 if (InputWaiting()) { |
112 fgets(input_line, 200, stdin); |
130 fgets(input_line, 200, stdin); |
113 // Forget about the final \n (or \r) |
131 // Forget about the final \n (or \r) |
126 sprintf(input_line, ""); |
144 sprintf(input_line, ""); |
127 } |
145 } |
128 } |
146 } |
129 #endif |
147 #endif |
130 |
148 |
131 if (_exit_game) return ML_QUIT; |
|
132 |
|
133 #ifdef WIN32 |
149 #ifdef WIN32 |
134 cur_ticks = GetTickCount(); |
150 cur_ticks = GetTickCount(); |
135 #else |
151 #else |
136 gettimeofday(&tim, NULL); |
152 gettimeofday(&tim, NULL); |
137 cur_ticks = (tim.tv_usec / 1000) + (tim.tv_sec * 1000); |
153 cur_ticks = (tim.tv_usec / 1000) + (tim.tv_sec * 1000); |