]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - sys_wind.c
apply the 0 byte udp packet DoS fix from nuq.
[xonotic/darkplaces.git] / sys_wind.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // sys_null.h -- null system driver to aid porting efforts
21
22 #include "quakedef.h"
23 #include "winquake.h"
24 #include "errno.h"
25 #include <sys\types.h>
26 #include <sys\timeb.h>
27
28
29 /*
30 ===============================================================================
31
32 FILE IO
33
34 ===============================================================================
35 */
36
37 // LordHavoc: 256 pak files (was 10)
38 #define MAX_HANDLES             256
39 FILE    *sys_handles[MAX_HANDLES];
40
41 int             findhandle (void)
42 {
43         int             i;
44         
45         for (i=1 ; i<MAX_HANDLES ; i++)
46                 if (!sys_handles[i])
47                         return i;
48         Sys_Error ("out of handles");
49         return -1;
50 }
51
52 /*
53 ================
54 filelength
55 ================
56 */
57 int filelength (FILE *f)
58 {
59         int             pos;
60         int             end;
61
62         pos = ftell (f);
63         fseek (f, 0, SEEK_END);
64         end = ftell (f);
65         fseek (f, pos, SEEK_SET);
66
67         return end;
68 }
69
70 int Sys_FileOpenRead (char *path, int *hndl)
71 {
72         FILE    *f;
73         int             i;
74         
75         i = findhandle ();
76
77         f = fopen(path, "rb");
78         if (!f)
79         {
80                 *hndl = -1;
81                 return -1;
82         }
83         sys_handles[i] = f;
84         *hndl = i;
85         
86         return filelength(f);
87 }
88
89 int Sys_FileOpenWrite (char *path)
90 {
91         FILE    *f;
92         int             i;
93         
94         i = findhandle ();
95
96         f = fopen(path, "wb");
97         if (!f)
98                 Sys_Error ("Error opening %s: %s", path,strerror(errno));
99         sys_handles[i] = f;
100         
101         return i;
102 }
103
104 void Sys_FileClose (int handle)
105 {
106         fclose (sys_handles[handle]);
107         sys_handles[handle] = NULL;
108 }
109
110 void Sys_FileSeek (int handle, int position)
111 {
112         fseek (sys_handles[handle], position, SEEK_SET);
113 }
114
115 int Sys_FileRead (int handle, void *dest, int count)
116 {
117         return fread (dest, 1, count, sys_handles[handle]);
118 }
119
120 int Sys_FileWrite (int handle, void *data, int count)
121 {
122         return fwrite (data, 1, count, sys_handles[handle]);
123 }
124
125 int     Sys_FileTime (char *path)
126 {
127         FILE    *f;
128         
129         f = fopen(path, "rb");
130         if (f)
131         {
132                 fclose(f);
133                 return 1;
134         }
135         
136         return -1;
137 }
138
139 void Sys_mkdir (char *path)
140 {
141 }
142
143
144 /*
145 ===============================================================================
146
147 SYSTEM IO
148
149 ===============================================================================
150 */
151
152 void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
153 {
154 }
155
156
157 void Sys_DebugLog(char *file, char *fmt, ...)
158 {
159 }
160
161 void Sys_Error (char *error, ...)
162 {
163         va_list         argptr;
164         char            text[1024];
165
166         va_start (argptr,error);
167         vsprintf (text, error,argptr);
168         va_end (argptr);
169
170 //    MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
171         printf ("ERROR: %s\n", text);
172
173         exit (1);
174 }
175
176 void Sys_Printf (char *fmt, ...)
177 {
178         va_list         argptr;
179         
180         va_start (argptr,fmt);
181         vprintf (fmt,argptr);
182         va_end (argptr);
183 }
184
185 void Sys_Quit (void)
186 {
187         exit (0);
188 }
189
190 double Sys_FloatTime (void)
191 {
192         double t;
193     struct _timeb tstruct;
194         static int      starttime;
195
196         _ftime( &tstruct );
197  
198         if (!starttime)
199                 starttime = tstruct.time;
200         t = (tstruct.time-starttime) + tstruct.millitm*0.001;
201         
202         return t;
203 }
204
205 void Sys_Sleep (void)
206 {
207 }
208
209
210 void Sys_SendKeyEvents (void)
211 {
212 }
213
214 char *Sys_ConsoleInput (void)
215 {
216         static char     text[256];
217         static int              len;
218         INPUT_RECORD    recs[1024];
219         int             count;
220         int             i;
221         int             c;
222
223         // read a line out
224         while (_kbhit())
225         {
226                 c = _getch();
227                 putch (c);
228                 if (c == '\r')
229                 {
230                         text[len] = 0;
231                         putch ('\n');
232                         len = 0;
233                         return text;
234                 }
235                 if (c == 8)
236                 {
237                         putch (' ');
238                         putch (c);
239                         len--;
240                         text[len] = 0;
241                         continue;
242                 }
243                 text[len] = c;
244                 len++;
245                 text[len] = 0;
246                 if (len == sizeof(text))
247                         len = 0;
248         }
249
250         return NULL;
251 }
252
253
254
255 /*
256 ==================
257 main
258
259 ==================
260 */
261 char    *newargv[256];
262
263 int main (int argc, char **argv)
264 {
265     MSG        msg;
266         quakeparms_t    parms;
267         double                  time, oldtime;
268         static  char    cwd[1024];
269
270         memset (&parms, 0, sizeof(parms));
271
272         parms.memsize = 16384*1024;
273         parms.membase = malloc (parms.memsize);
274
275         _getcwd (cwd, sizeof(cwd));
276         if (cwd[strlen(cwd)-1] == '\\')
277                 cwd[strlen(cwd)-1] = 0;
278         parms.basedir = cwd; //"f:/quake";
279 //      parms.basedir = "f:\\quake";
280
281         COM_InitArgv (argc, argv);
282
283         // dedicated server ONLY!
284         if (!COM_CheckParm ("-dedicated"))
285         {
286                 memcpy (newargv, argv, argc*4);
287                 newargv[argc] = "-dedicated";
288                 argc++;
289                 argv = newargv;
290                 COM_InitArgv (argc, argv);
291         }
292
293         parms.argc = argc;
294         parms.argv = argv;
295
296         printf ("Host_Init\n");
297         Host_Init (&parms);
298
299         oldtime = Sys_FloatTime ();
300
301     /* main window message loop */
302         while (1)
303         {
304                 time = Sys_FloatTime();
305                 if (time - oldtime < sys_ticrate.value )
306                 {
307                         Sleep(1);
308                         continue;
309                 }
310
311                 Host_Frame ( time - oldtime );
312                 oldtime = time;
313         }
314
315     /* return success of application */
316     return TRUE;
317 }
318