author | rubidium |
Thu, 04 Jan 2007 21:21:14 +0000 | |
changeset 5527 | 7a624281971a |
parent 5526 | befe0373e6ae |
child 5528 | 45a70016d39a |
permissions | -rw-r--r-- |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
2 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
3 |
#ifdef ENABLE_NETWORK |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
4 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
5 |
#include "../../stdafx.h" |
5526
befe0373e6ae
(svn r7833) -Fix (r7829): forgot to add debug.h to the includes.
rubidium
parents:
5524
diff
changeset
|
6 |
#include "../../debug.h" |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
7 |
#include "os_abstraction.h" |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
8 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
9 |
#ifdef __MORPHOS__ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
10 |
/* the library base is required here */ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
11 |
struct Library *SocketBase = NULL; |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
12 |
#endif |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
13 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
14 |
/** |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
15 |
* Initializes the network core (as that is needed for some platforms |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
16 |
*/ |
5524
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
17 |
bool NetworkCoreInitialize(void) |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
18 |
{ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
19 |
#if defined(__MORPHOS__) || defined(__AMIGA__) |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
20 |
/* |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
21 |
* IMPORTANT NOTE: SocketBase needs to be initialized before we use _any_ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
22 |
* network related function, else: crash. |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
23 |
*/ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
24 |
DEBUG(net, 3, "[core] loading bsd socket library"); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
25 |
SocketBase = OpenLibrary("bsdsocket.library", 4); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
26 |
if (SocketBase == NULL) { |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
27 |
DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable"); |
5524
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
28 |
return false; |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
29 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
30 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
31 |
#if defined(__AMIGA__) |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
32 |
/* for usleep() implementation (only required for legacy AmigaOS builds) */ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
33 |
TimerPort = CreateMsgPort(); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
34 |
if (TimerPort != NULL) { |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
35 |
TimerRequest = (struct timerequest*)CreateIORequest(TimerPort, sizeof(struct timerequest); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
36 |
if (TimerRequest != NULL) { |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
37 |
if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) { |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
38 |
TimerBase = TimerRequest->tr_node.io_Device; |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
39 |
if (TimerBase == NULL) { |
5524
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
40 |
/* free ressources... */ |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
41 |
DEBUG(net, 0, "[core] can't initialize timer, network unavailable"); |
5524
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
42 |
return false; |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
43 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
44 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
45 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
46 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
47 |
#endif // __AMIGA__ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
48 |
#endif // __MORPHOS__ / __AMIGA__ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
49 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
50 |
/* Let's load the network in windows */ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
51 |
#ifdef WIN32 |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
52 |
{ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
53 |
WSADATA wsa; |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
54 |
DEBUG(net, 3, "[core] loading windows socket library"); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
55 |
if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) { |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
56 |
DEBUG(net, 0, "[core] WSAStartup failed, network unavailable"); |
5524
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
57 |
return false; |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
58 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
59 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
60 |
#endif /* WIN32 */ |
5524
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
61 |
|
93460e0fed07
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
rubidium
parents:
5523
diff
changeset
|
62 |
return true; |
5523
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
63 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
64 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
65 |
/** |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
66 |
* Shuts down the network core (as that is needed for some platforms |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
67 |
*/ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
68 |
void NetworkCoreShutdown(void) |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
69 |
{ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
70 |
#if defined(__MORPHOS__) || defined(__AMIGA__) |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
71 |
/* free allocated ressources */ |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
72 |
#if defined(__AMIGA__) |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
73 |
if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest); // XXX This smells wrong |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
74 |
if (TimerRequest != NULL) DeleteIORequest(TimerRequest); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
75 |
if (TimerPort != NULL) DeleteMsgPort(TimerPort); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
76 |
#endif |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
77 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
78 |
if (SocketBase != NULL) CloseLibrary(SocketBase); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
79 |
#endif |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
80 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
81 |
#if defined(WIN32) |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
82 |
WSACleanup(); |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
83 |
#endif |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
84 |
} |
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
85 |
|
623a8856e35b
(svn r7829) -Codechange: move the network (core) initialization/shutdown functions into network/core, so the can be reused in the masterserver_updater.
rubidium
parents:
diff
changeset
|
86 |
#endif /* ENABLE_NETWORK */ |