// // I_InitNetwork // Only required for DOS, so this is more a dummy // boolean I_InitNetwork(void) { #ifdef HAVE_SDLNET char serverhostname[255]; boolean ret = false; SDL_version SDLcompiled; const SDL_version *SDLlinked = SDLNet_Linked_Version(); SDL_NET_VERSION(&SDLcompiled) CONS_Printf("Compiled for SDL_Net version: %d.%d.%d\n", SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); CONS_Printf("Linked with SDL_Net version: %d.%d.%d\n", SDLlinked->major, SDLlinked->minor, SDLlinked->patch); //if (!M_CheckParm ("-sdlnet")) // return false; // initilize the driver I_InitSDLNetDriver(); I_AddExitFunc(I_ShutdownSDLNetDriver); if (!init_SDLNet_driver) return false; if (M_CheckParm("-udpport")) { if (M_IsNextParm()) sock_port = (UINT16)atoi(M_GetNextParm()); else sock_port = 0; } // parse network game options, if (M_CheckParm("-server") || dedicated) { server = true; // If a number of clients (i.e. nodes) is specified, the server will wait for the clients // to connect before starting. // If no number is specified here, the server starts with 1 client, and others can join // in-game. // Since Boris has implemented join in-game, there is no actual need for specifying a // particular number here. // FIXME: for dedicated server, numnodes needs to be set to 0 upon start /* if (M_IsNextParm()) doomcom->numnodes = (INT16)atoi(M_GetNextParm()); else */if (dedicated) doomcom->numnodes = 0; else doomcom->numnodes = 1; if (doomcom->numnodes < 0) doomcom->numnodes = 0; if (doomcom->numnodes > MAXNETNODES) doomcom->numnodes = MAXNETNODES; // server servernode = 0; // FIXME: // ??? and now ? // server on a big modem ??? 4*isdn net_bandwidth = 16000; hardware_MAXPACKETLENGTH = INETPACKETLENGTH; ret = true; } else if (M_CheckParm("-connect")) { if (M_IsNextParm()) strcpy(serverhostname, M_GetNextParm()); else serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it // server address only in ip if (serverhostname[0]) { COM_BufAddText("connect \""); COM_BufAddText(serverhostname); COM_BufAddText("\"\n"); // probably modem hardware_MAXPACKETLENGTH = INETPACKETLENGTH; } else { // so we're on a LAN COM_BufAddText("connect any\n"); net_bandwidth = 800000; hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; } } mypacket.maxlen = hardware_MAXPACKETLENGTH; I_NetOpenSocket = NET_OpenSocket; I_Ban = NET_Ban; I_ClearBans = NET_ClearBans; I_GetNodeAddress = NET_GetNodeAddress; I_GetBenAddress = NET_GetBenAddress; I_SetBanAddress = NET_SetBanAddress; bannednode = NET_bannednode; return ret; #else if ( M_CheckParm ("-net") ) { I_Error("-net not supported, use -server and -connect\n" "see docs for more\n"); } return false; #endif }
const SDL_version *SDLNet_Linked_Version(void) { static SDL_version linked_version; SDL_NET_VERSION(&linked_version); return(&linked_version); }
int main(int argc, char **argv) { IPaddress ip; const char *host; Uint8 *ipaddr; /* check our commandline */ if(argc>1 && !strncmp("-h",argv[1],2)) { printf("%s host|ip\n",argv[0]); exit(0); } /* do a little version check for information */ { SDL_version compile_version; const SDL_version *link_version=SDLNet_Linked_Version(); SDL_NET_VERSION(&compile_version); printf("compiled with SDL_net version: %d.%d.%d\n", compile_version.major, compile_version.minor, compile_version.patch); printf("running with SDL_net version: %d.%d.%d\n", link_version->major, link_version->minor, link_version->patch); } /* initialize SDL */ if(SDL_Init(0)==-1) { printf("SDL_Init: %s\n",SDL_GetError()); exit(1); } /* initialize SDL_net */ if(SDLNet_Init()==-1) { printf("SDLNet_Init: %s\n",SDLNet_GetError()); exit(2); } #ifndef WIN32 /* has no gethostname that we can use here... */ { char localhostname[256]; if((gethostname(localhostname, 256)>=0)) { printf("Local Host: %s\n",localhostname); printf("Resolving %s\n",localhostname); if(SDLNet_ResolveHost(&ip,localhostname,0)==-1) { printf("Could not resolve host \"%s\"\n%s\n", localhostname,SDLNet_GetError()); } else { /* use the IP as a Uint8[4] */ ipaddr=(Uint8*)&ip.host; /* output the IP address nicely */ printf("Local IP Address : %d.%d.%d.%d\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); } } } #endif if(argc<2) exit(0); /* Resolve the argument into an IPaddress type */ printf("Resolving %s\n",argv[1]); if(SDLNet_ResolveHost(&ip,argv[1],0)==-1) { printf("Could not resolve host \"%s\"\n%s\n",argv[1],SDLNet_GetError()); exit(3); } /* use the IP as a Uint8[4] */ ipaddr=(Uint8*)&ip.host; /* output the IP address nicely */ printf("IP Address : %d.%d.%d.%d\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); /* resolve the hostname for the IPaddress */ host=SDLNet_ResolveIP(&ip); /* print out the hostname we got */ if(host) printf("Hostname : %s\n",host); else printf("No Hostname found\n"); /* shutdown SDL_net */ SDLNet_Quit(); /* shutdown SDL */ SDL_Quit(); return(0); }