1
0
Fork 0

(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.

release/0.6
rubidium 2007-01-04 19:12:45 +00:00
parent 627ebe8430
commit 85d1768b34
3 changed files with 12 additions and 15 deletions

View File

@ -13,7 +13,7 @@ struct Library *SocketBase = NULL;
/** /**
* Initializes the network core (as that is needed for some platforms * Initializes the network core (as that is needed for some platforms
*/ */
void NetworkCoreInitialize(void) bool NetworkCoreInitialize(void)
{ {
#if defined(__MORPHOS__) || defined(__AMIGA__) #if defined(__MORPHOS__) || defined(__AMIGA__)
/* /*
@ -24,8 +24,7 @@ void NetworkCoreInitialize(void)
SocketBase = OpenLibrary("bsdsocket.library", 4); SocketBase = OpenLibrary("bsdsocket.library", 4);
if (SocketBase == NULL) { if (SocketBase == NULL) {
DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable"); DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable");
_network_available = false; return false;
return;
} }
#if defined(__AMIGA__) #if defined(__AMIGA__)
@ -37,10 +36,9 @@ void NetworkCoreInitialize(void)
if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) { if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) {
TimerBase = TimerRequest->tr_node.io_Device; TimerBase = TimerRequest->tr_node.io_Device;
if (TimerBase == NULL) { if (TimerBase == NULL) {
// free ressources... /* free ressources... */
DEBUG(net, 0, "[core] can't initialize timer, network unavailable"); DEBUG(net, 0, "[core] can't initialize timer, network unavailable");
_network_available = false; return false;
return;
} }
} }
} }
@ -55,11 +53,12 @@ void NetworkCoreInitialize(void)
DEBUG(net, 3, "[core] loading windows socket library"); DEBUG(net, 3, "[core] loading windows socket library");
if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) { if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
DEBUG(net, 0, "[core] WSAStartup failed, network unavailable"); DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
_network_available = false; return false;
return;
} }
} }
#endif /* WIN32 */ #endif /* WIN32 */
return true;
} }
/** /**

View File

@ -5,7 +5,7 @@
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
void NetworkCoreInitialize(void); bool NetworkCoreInitialize(void);
void NetworkCoreShutdown(void); void NetworkCoreShutdown(void);
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -1336,20 +1336,18 @@ static void NetworkGenerateUniqueId(void)
snprintf(_network_unique_id, sizeof(_network_unique_id), "%s", hex_output); snprintf(_network_unique_id, sizeof(_network_unique_id), "%s", hex_output);
} }
// This tries to launch the network for a given OS /** This tries to launch the network for a given OS */
void NetworkStartUp(void) void NetworkStartUp(void)
{ {
DEBUG(net, 3, "[core] starting network..."); DEBUG(net, 3, "[core] starting network...");
// Network is available /* Network is available */
_network_available = true; _network_available = NetworkCoreInitialize();;
_network_dedicated = false; _network_dedicated = false;
_network_last_advertise_frame = 0; _network_last_advertise_frame = 0;
_network_need_advertise = true; _network_need_advertise = true;
_network_advertise_retries = 0; _network_advertise_retries = 0;
NetworkCoreInitialize();
/* Load the ip from the openttd.cfg */ /* Load the ip from the openttd.cfg */
_network_server_bind_ip = inet_addr(_network_server_bind_ip_host); _network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
/* And put the data back in it in case it was an invalid ip */ /* And put the data back in it in case it was an invalid ip */
@ -1375,7 +1373,7 @@ void NetworkStartUp(void)
NetworkFindIPs(); NetworkFindIPs();
} }
// This shuts the network down /** This shuts the network down */
void NetworkShutDown(void) void NetworkShutDown(void)
{ {
NetworkDisconnect(); NetworkDisconnect();