[Source] Autoresolve DNS

Results 1 to 1 of 1
  1. #1
    Member darren0020 is offline
    MemberRank
    Apr 2009 Join Date
    IrelandLocation
    94Posts

    [Source] Autoresolve DNS

    I've noticed that in the flyff .ini files, the servers and client don't really like it when you specify domain names in place of IP addresses, so I have decided to release a little source snippet that allows the server's owner to use their domain name in place of their IP, however, I'm only going to explain how to set it for the account server, it should be easy enough to find how to do this for the other files.

    AccountServer.cpp:
    First, add this to the very top of the document (yes yes, I know, pragma is bad but I don't care.)
    Code:
    #pragma comment(lib, "ws2_32.lib")
    #include <winsock2.h>
    #include <ws2tcpip.h>
    Add this method above the BOOL Script(LPCTSTR lpszFileName) method.

    Code:
    const char* resolve()
    {
    	WSADATA wsaData;
    	int result;
    
    	DWORD dwError;
    
    	struct hostent *remoteHost;
    	char *host_name;
    	struct in_addr addr;
    
    	// Initialize Winsock
    	result = WSAStartup(MAKEWORD(2, 2), &wsaData);
    	if (result != 0){return "Error";}
    
    	host_name = "DNS here"; 
    	remoteHost = gethostbyname(host_name);
    
    	if (remoteHost == NULL) 
    	{
    		dwError = WSAGetLastError();
    		if (dwError != 0)
    		{
    			if (dwError == WSAHOST_NOT_FOUND){return "Errhnf";}
    			else if (dwError == WSANO_DATA){return "Errndrf";}
    			else{return "Errff";}
    		}
    	}
    	else 
    	{
    		addr.s_addr = *(u_long *) remoteHost->h_addr_list[0];
    		return inet_ntoa(addr);
    	}
    	return "False";
    }
    In the same file, search for strcpy( pServer->lpAddr, s.Token ); and change it to:
    Code:
    				strcpy(pServer->lpAddr, ::resolve());
    Has Fun.
    Last edited by darren0020; 23-02-13 at 04:53 AM.




Advertisement