Changeset - r5524:2b4f5c3335dd
[Not reviewed]
master
0 3 0
rubidium - 17 years ago 2007-01-04 19:12:45
rubidium@openttd.org
(svn r7830) -Codechange: let NetworkCoreInitialize return a bool, so we have to set _network_available only once.
3 files changed with 12 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/network/core/core.c
Show inline comments
 
@@ -10,40 +10,38 @@
 
struct Library *SocketBase = NULL;
 
#endif
 

	
 
/**
 
 * Initializes the network core (as that is needed for some platforms
 
 */
 
void NetworkCoreInitialize(void)
 
bool NetworkCoreInitialize(void)
 
{
 
#if defined(__MORPHOS__) || defined(__AMIGA__)
 
	/*
 
	 *  IMPORTANT NOTE: SocketBase needs to be initialized before we use _any_
 
	 *  network related function, else: crash.
 
	 */
 
	DEBUG(net, 3, "[core] loading bsd socket library");
 
	SocketBase = OpenLibrary("bsdsocket.library", 4);
 
	if (SocketBase == NULL) {
 
		DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable");
 
		_network_available = false;
 
		return;
 
		return false;
 
	}
 

	
 
#if defined(__AMIGA__)
 
	/* for usleep() implementation (only required for legacy AmigaOS builds) */
 
	TimerPort = CreateMsgPort();
 
	if (TimerPort != NULL) {
 
		TimerRequest = (struct timerequest*)CreateIORequest(TimerPort, sizeof(struct timerequest);
 
		if (TimerRequest != NULL) {
 
			if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) {
 
				TimerBase = TimerRequest->tr_node.io_Device;
 
				if (TimerBase == NULL) {
 
					// free ressources...
 
					/* free ressources... */
 
					DEBUG(net, 0, "[core] can't initialize timer, network unavailable");
 
					_network_available = false;
 
					return;
 
					return false;
 
				}
 
			}
 
		}
 
	}
 
#endif // __AMIGA__
 
#endif // __MORPHOS__ / __AMIGA__
 
@@ -52,17 +50,18 @@ void NetworkCoreInitialize(void)
 
#ifdef WIN32
 
	{
 
		WSADATA wsa;
 
		DEBUG(net, 3, "[core] loading windows socket library");
 
		if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
 
			DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
 
			_network_available = false;
 
			return;
 
			return false;
 
		}
 
	}
 
#endif /* WIN32 */
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Shuts down the network core (as that is needed for some platforms
 
 */
 
void NetworkCoreShutdown(void)
src/network/core/core.h
Show inline comments
 
@@ -2,12 +2,12 @@
 

	
 
#ifndef NETWORK_CORE_H
 
#define NETWORK_CORE_H
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
void NetworkCoreInitialize(void);
 
bool NetworkCoreInitialize(void);
 
void NetworkCoreShutdown(void);
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif /* NETWORK_CORE_H */
src/network/network.c
Show inline comments
 
@@ -1333,26 +1333,24 @@ static void NetworkGenerateUniqueId(void
 
		sprintf(hex_output + di * 2, "%02x", digest[di]);
 

	
 
	/* _network_unique_id is our id */
 
	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)
 
{
 
	DEBUG(net, 3, "[core] starting network...");
 

	
 
	// Network is available
 
	_network_available = true;
 
	/* Network is available */
 
	_network_available = NetworkCoreInitialize();;
 
	_network_dedicated = false;
 
	_network_last_advertise_frame = 0;
 
	_network_need_advertise = true;
 
	_network_advertise_retries = 0;
 

	
 
	NetworkCoreInitialize();
 

	
 
	/* Load the ip from the openttd.cfg */
 
	_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 */
 
	snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
 

	
 
	/* Generate an unique id when there is none yet */
 
@@ -1372,13 +1370,13 @@ void NetworkStartUp(void)
 

	
 
	NetworkInitialize();
 
	DEBUG(net, 3, "[core] network online, multiplayer available");
 
	NetworkFindIPs();
 
}
 

	
 
// This shuts the network down
 
/** This shuts the network down */
 
void NetworkShutDown(void)
 
{
 
	NetworkDisconnect();
 
	NetworkUDPStop();
 

	
 
	DEBUG(net, 3, "[core] shutting down network");
0 comments (0 inline, 0 general)