Rev 140 | Rev 171 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 140 | Rev 153 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | 2 | ||
| 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 StartThread_ListenToServer (void *thread_parms); |
- | |
| 8 | 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 | } |
|
| 9 | 26 | ||
| 10 | 27 | ||
| 11 | bool PlayerNetwork_Init (player_t *player) |
28 | bool PlayerNetwork_Init (player_t *player) |
| 12 | { |
29 | { |
| 13 | // this function initializes the network layer and connects to the chess server |
30 | // this function initializes the network layer and connects to the chess server |
| 14 | 31 | ||
| 15 | WSADATA wsaData; |
- | |
| 16 | struct hostent *hostinfo; |
32 | struct hostent *hostinfo; |
| 17 | struct sockaddr_in service; |
33 | struct sockaddr_in service; |
| 18 | unsigned long nonblocking_mode; |
34 | unsigned long nonblocking_mode; |
| 19 | char ascii_hostname[256]; |
35 | char ascii_hostname[256]; |
| 20 | 36 | ||
| Line 44... | Line 60... | ||
| 44 | player->game_number = 0; |
60 | player->game_number = 0; |
| 45 | player->remaining_seconds = 0; |
61 | player->remaining_seconds = 0; |
| 46 | player->our_socket = INVALID_SOCKET; // and that we have no socket yet |
62 | player->our_socket = INVALID_SOCKET; // and that we have no socket yet |
| 47 | player->name[0] = 0; // player name undefined |
63 | player->name[0] = 0; // player name undefined |
| 48 | 64 | ||
| 49 | // initialize |
65 | // initialize the network subsystem if required |
| 50 | if ( |
66 | if (!Network_Init ()) |
| 51 | { |
67 | { |
| 52 | messagebox.hWndParent = hMainWnd; |
68 | messagebox.hWndParent = hMainWnd; |
| 53 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
69 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
| 54 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_NetworkInitializationFailed")); |
70 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_NetworkInitializationFailed")); |
| 55 | messagebox.flags = MB_ICONWARNING | MB_OK; |
71 | messagebox.flags = MB_ICONWARNING | MB_OK; |