View Single Post
  #4  
Old 02-01-2002, 06:11 AM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

net.cpp

Comment out the 'server listening' message, is sent in InitTCP now'
Code:
//	cout << "World server listening on port:" << PORT << endl;

Change the UDP port
Code:
bool NetConnection::Init()
{
	struct sockaddr_in address;
	int reuse_addr = 1;
	
	// Disgrace: for windows compile
#ifdef WIN32
	unsigned long nonblocking = 1;
	WORD version = MAKEWORD (1,1);
	WSADATA wsadata;
	WSAStartup (version, &wsadata);
#endif
	struct hostent *phostent = NULL;


  /* Setup internet address information.  
     This is used with the bind() call */
	memset((char *) &address, 0, sizeof(address));
	address.sin_family = AF_INET;
	address.sin_port = htons(PORT);
	address.sin_addr.s_addr = htonl(INADDR_ANY);
	unsigned long lAddr = INADDR_NONE;

	//GET WORLD SERVER ADDRESS
	if((lAddr = inet_addr(net.GetWorldAddress())) != INADDR_NONE){
		if((phostent = gethostbyaddr((char*)&lAddr, sizeof(unsigned long), AF_INET)) != NULL){
			memcpy ((char*)&(address.sin_addr), phostent->h_addr, phostent->h_length);
		}
	}else if((phostent = gethostbyname(net.GetWorldAddress())) != NULL){
		memcpy ((char*)&(address.sin_addr), phostent->h_addr, phostent->h_length);
	}

	/* Setting up UDP port for new clients */
	listening_socket = socket(AF_INET, SOCK_DGRAM, 0);
	if (listening_socket < 0) 
 	{
	
		return false;
	}

	// Disgrace: for windows compile
#ifndef WIN32
	setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr));
#else
	setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &reuse_addr, sizeof(reuse_addr));
#endif

	if (bind(listening_socket, (struct sockaddr *) &address, sizeof(address)) < 0) 
	{
		// Disgrace: for windows compile
		#ifdef WIN32
			closesocket(listening_socket);
		#else
			close(listening_socket);
		#endif
		
		return false;
	}

	// Disgrace: for windows compile
#ifndef WIN32
	fcntl(listening_socket, F_SETFL, O_NONBLOCK);
#else
	ioctlsocket (listening_socket, FIONBIO, &nonblocking);
#endif


	return true;
}
Reply With Quote