Rev 177 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 177 | Rev 179 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | #include "common.h" |
3 | #include "common.h" |
4 | 4 | ||
5 | 5 | ||
6 | // prototypes of local functions |
6 | // prototypes of local functions |
7 | static void EvaluateServerReply (player_t *player); |
7 | static void EvaluateServerReply (player_t *player); |
8 | - | ||
9 | - | ||
10 | bool Network_Init (void) |
- | |
11 | { |
- | |
12 | // this function initializes the network subsystem on operating systems that require it |
- | |
13 | - | ||
14 | #ifdef _WIN32 |
- | |
15 | static bool is_winsock_initialized = false; |
- | |
16 | WSADATA wsa_data; |
- | |
17 | - | ||
18 | if (!is_winsock_initialized) |
- | |
19 | is_winsock_initialized = (WSAStartup (MAKEWORD (2, 2), &wsa_data) == 0); |
- | |
20 | - | ||
21 | return (is_winsock_initialized); // return whether the network subsystem was successfully initialized |
- | |
22 | #else // !_WIN32 |
- | |
23 | return (true); // all other systems than Win32 don't need to initialize the network |
- | |
24 | #endif // _WIN32 |
- | |
25 | } |
- | |
26 | 8 | ||
27 | 9 | ||
28 | bool PlayerNetwork_Init (player_t *player) |
10 | bool PlayerNetwork_Init (player_t *player) |
29 | { |
11 | { |
30 | // this function initializes the network layer and connects to the chess server |
12 | // this function initializes the network layer and connects to the chess server |
Line 59... | Line 41... | ||
59 | player->is_in_game = false; // we aren't in game either |
41 | player->is_in_game = false; // we aren't in game either |
60 | player->game_number = 0; |
42 | player->game_number = 0; |
61 | player->remaining_seconds = 0; |
43 | player->remaining_seconds = 0; |
62 | player->our_socket = INVALID_SOCKET; // and that we have no socket yet |
44 | player->our_socket = INVALID_SOCKET; // and that we have no socket yet |
63 | player->name[0] = 0; // player name undefined |
45 | player->name[0] = 0; // player name undefined |
64 | - | ||
65 | // initialize the network subsystem if required |
- | |
66 | if (!Network_Init ()) |
- | |
67 | { |
- | |
68 | messagebox.hWndParent = hMainWnd; |
- | |
69 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
- | |
70 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_NetworkInitializationFailed")); |
- | |
71 | messagebox.flags = MB_ICONWARNING | MB_OK; |
- | |
72 | DialogBox_Message (&messagebox); // display a modeless error message box |
- | |
73 | - | ||
74 | PlayerNetwork_Shutdown (player); // on error, shutdown the network and display an error message |
- | |
75 | return (false); |
- | |
76 | } |
- | |
77 | 46 | ||
78 | // get the chess server's IP address from the host name |
47 | // get the chess server's IP address from the host name |
79 | ConvertTo7BitASCII (ascii_hostname, sizeof (ascii_hostname), options.network.server_address); |
48 | ConvertTo7BitASCII (ascii_hostname, sizeof (ascii_hostname), options.network.server_address); |
80 | hostinfo = gethostbyname (ascii_hostname); |
49 | hostinfo = gethostbyname (ascii_hostname); |
81 | if (hostinfo == NULL) |
50 | if (hostinfo == NULL) |
Line 200... | Line 169... | ||
200 | DestroyWindow (hOpponentsWnd); |
169 | DestroyWindow (hOpponentsWnd); |
201 | hOpponentsWnd = NULL; |
170 | hOpponentsWnd = NULL; |
202 | if (IsWindow (hSoughtWnd)) |
171 | if (IsWindow (hSoughtWnd)) |
203 | DestroyWindow (hSoughtWnd); |
172 | DestroyWindow (hSoughtWnd); |
204 | hSoughtWnd = NULL; |
173 | hSoughtWnd = NULL; |
205 | - | ||
206 | // shutdown WinSock |
- | |
207 | WSACleanup (); |
- | |
208 | 174 | ||
209 | return; // finished |
175 | return; // finished |
210 | } |
176 | } |
211 | 177 | ||
212 | 178 |