|
1 (* |
|
2 * Hedgewars, a worms-like game |
|
3 * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * Distributed under the terms of the BSD-modified licence: |
|
6 * |
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 * of this software and associated documentation files (the "Software"), to deal |
|
9 * with the Software without restriction, including without limitation the |
|
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 * sell copies of the Software, and to permit persons to whom the Software is |
|
12 * furnished to do so, subject to the following conditions: |
|
13 * |
|
14 * 1. Redistributions of source code must retain the above copyright notice, |
|
15 * this list of conditions and the following disclaimer. |
|
16 * 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 * this list of conditions and the following disclaimer in the documentation |
|
18 * and/or other materials provided with the distribution. |
|
19 * 3. The name of the author may not be used to endorse or promote products |
|
20 * derived from this software without specific prior written permission. |
|
21 * |
|
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 *) |
|
33 |
|
34 program hwserv; |
|
35 {$APPTYPE CONSOLE} |
|
36 uses |
|
37 Windows, |
|
38 WinSock, |
|
39 Messages, |
|
40 uServerMisc in 'uServerMisc.pas', |
|
41 uNet, |
|
42 uPlayers in 'uPlayers.pas'; |
|
43 |
|
44 function MainWndProc(hwnd: HWND; Message: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; |
|
45 begin |
|
46 case Message of |
|
47 WM_CLOSE : begin |
|
48 PostQuitMessage(0); |
|
49 end; |
|
50 WM_ASYNC_NETEVENT: NetSockEvent(wParam, lParam); |
|
51 end; |
|
52 Result:= DefWindowProc(hwnd, Message, wParam,lParam) |
|
53 end; |
|
54 |
|
55 procedure DoCreateWindow; |
|
56 var wc: WNDCLASS; |
|
57 begin |
|
58 FillChar(wc, sizeof(wc), 0); |
|
59 wc.style := CS_VREDRAW or CS_HREDRAW; |
|
60 wc.lpfnWndProc := @MainWndProc; |
|
61 wc.hInstance := hInstance; |
|
62 wc.lpszClassName := cAppName; |
|
63 TryDo(RegisterClass(wc) <> 0, 'Cannot register window class'); |
|
64 hwndMain := CreateWindowEx( 0, cAppName, cAppTitle, WS_POPUP, |
|
65 0, 0, |
|
66 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), |
|
67 0, 0, hInstance, nil); |
|
68 TryDo(hwndMain <> 0, 'Cannot create window') |
|
69 end; |
|
70 |
|
71 procedure ProcessMessages; |
|
72 var Message: Windows.MSG; |
|
73 begin |
|
74 if PeekMessage(Message,0,0,0,PM_REMOVE) then |
|
75 if Message.message <> WM_QUIT then |
|
76 begin |
|
77 TranslateMessage(Message); |
|
78 DispatchMessage(Message) |
|
79 end else isTerminated:= true |
|
80 end; |
|
81 |
|
82 begin |
|
83 WriteLn('-= Hedgewars server =-'); |
|
84 WriteLn('protocol version ', cProtVer); |
|
85 DoCreateWindow; |
|
86 InitServer; |
|
87 repeat |
|
88 ProcessMessages; |
|
89 until isTerminated |
|
90 end. |