void StartNetwork (bool autoPort) { u_long trueval = 1; #ifdef __WIN32__ WSADATA wsad; if (WSAStartup (0x0101, &wsad)) { I_FatalError ("Could not initialize Windows Sockets"); } #endif atterm (CloseNetwork); netgame = true; multiplayer = true; // create communication socket mysocket = UDPsocket (); BindToLocalPort (mysocket, autoPort ? 0 : DOOMPORT); #ifndef __sun ioctlsocket (mysocket, FIONBIO, &trueval); #else fcntl(mysocket, F_SETFL, trueval | O_NONBLOCK); #endif }
// // InitNetCommon // void InitNetCommon(void) { unsigned long _true = true; #ifdef _WIN32 WSADATA wsad; WSAStartup(0x0101, &wsad); #endif net_socket = UDPsocket(); BindToLocalPort(net_socket, localport); if (ioctlsocket(net_socket, FIONBIO, &_true) == -1) printf("UDPsocket: ioctl FIONBIO: %s", strerror(errno)); net_message.clear(); }
// // InitNetCommon // void InitNetCommon(void) { unsigned long _true = true; #ifdef _WIN32 WSADATA wsad; WSAStartup( 0x0101, &wsad ); #endif net_socket = UDPsocket (); BindToLocalPort (net_socket, localport); if (ioctlsocket (net_socket, FIONBIO, &_true) == -1) I_FatalError ("UDPsocket: ioctl FIONBIO: %s", strerror(errno)); // enter message information into message info structs InitNetMessageFormats(); SZ_Clear(&net_message); }
// // I_InitNetwork // void I_InitNetwork (void) { boolean trueval = true; int i; int p; struct hostent* hostentry; // host information entry doomcom = malloc (sizeof (*doomcom) ); memset (doomcom, 0, sizeof(*doomcom) ); // set up for network i = M_CheckParm ("-dup"); if (i && i< myargc-1) { doomcom->ticdup = myargv[i+1][0]-'0'; if (doomcom->ticdup < 1) doomcom->ticdup = 1; if (doomcom->ticdup > 9) doomcom->ticdup = 9; } else doomcom-> ticdup = 1; if (M_CheckParm ("-extratic")) doomcom-> extratics = 1; else doomcom-> extratics = 0; p = M_CheckParm ("-port"); if (p && p<myargc-1) { DOOMPORT = atoi (myargv[p+1]); printf ("using alternate port %i\n",DOOMPORT); } // parse network game options, // -net <consoleplayer> <host> <host> ... i = M_CheckParm ("-net"); if (!i) { // single player game netgame = false; doomcom->id = DOOMCOM_ID; doomcom->numplayers = doomcom->numnodes = 1; doomcom->deathmatch = false; doomcom->consoleplayer = 0; return; } netsend = PacketSend; netget = PacketGet; netgame = true; // parse player number and host list doomcom->consoleplayer = myargv[i+1][0]-'1'; doomcom->numnodes = 1; // this node for sure i++; while (++i < myargc && myargv[i][0] != '-') { sendaddress[doomcom->numnodes].sin_family = AF_INET; sendaddress[doomcom->numnodes].sin_port = htons(DOOMPORT); if (myargv[i][0] == '.') { sendaddress[doomcom->numnodes].sin_addr.s_addr = inet_addr (myargv[i]+1); } else { hostentry = gethostbyname (myargv[i]); if (!hostentry) I_Error ("gethostbyname: couldn't find %s", myargv[i]); sendaddress[doomcom->numnodes].sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; } doomcom->numnodes++; } doomcom->id = DOOMCOM_ID; doomcom->numplayers = doomcom->numnodes; // build message to receive insocket = UDPsocket (); BindToLocalPort (insocket,htons(DOOMPORT)); sendsocket = UDPsocket (); }
// // I_InitNetwork // void I_InitNetwork (void) { //qboolean trueval = true; int i; int p; //int a = 0; // struct hostent* hostentry; // host information entry memset (&::g->doomcom, 0, sizeof(::g->doomcom) ); // set up for network i = M_CheckParm ("-dup"); if (i && i< ::g->myargc-1) { ::g->doomcom.ticdup = ::g->myargv[i+1][0]-'0'; if (::g->doomcom.ticdup < 1) ::g->doomcom.ticdup = 1; if (::g->doomcom.ticdup > 9) ::g->doomcom.ticdup = 9; } else ::g->doomcom.ticdup = 1; if (M_CheckParm ("-extratic")) ::g->doomcom.extratics = 1; else ::g->doomcom.extratics = 0; p = M_CheckParm ("-port"); if (p && p < ::g->myargc-1) { DOOMPORT = atoi (::g->myargv[p+1]); I_Printf ("using alternate port %i\n",DOOMPORT); } // parse network game options, // -net <::g->consoleplayer> <host> <host> ... i = M_CheckParm ("-net"); if (!i || !I_TrySetupNetwork()) { // single player game ::g->netgame = false; ::g->doomcom.id = DOOMCOM_ID; ::g->doomcom.numplayers = ::g->doomcom.numnodes = 1; ::g->doomcom.deathmatch = false; ::g->doomcom.consoleplayer = 0; return; } netsend = PacketSend; netget = PacketGet; ::g->netgame = true; { ++i; // skip the '-net' ::g->doomcom.numnodes = 0; ::g->doomcom.consoleplayer = atoi( ::g->myargv[i] ); // skip the console number ++i; ::g->doomcom.numnodes = 0; for (; i < ::g->myargc; ++i) { ::g->sendaddress[::g->doomcom.numnodes].sin_family = AF_INET; ::g->sendaddress[::g->doomcom.numnodes].sin_port = htons(DOOMPORT); // Pull out the port number. const std::string ipAddressWithPort( ::g->myargv[i] ); const std::size_t colonPosition = ipAddressWithPort.find_last_of(':'); std::string ipOnly; if( colonPosition != std::string::npos && colonPosition + 1 < ipAddressWithPort.size() ) { const std::string portOnly( ipAddressWithPort.substr( colonPosition + 1 ) ); ::g->sendaddress[::g->doomcom.numnodes].sin_port = htons( atoi( portOnly.c_str() ) ); ipOnly = ipAddressWithPort.substr( 0, colonPosition ); } else { // Assume the address doesn't include a port. ipOnly = ipAddressWithPort; } in_addr_t ipAddress = inet_addr( ipOnly.c_str() ); if ( ipAddress == INADDR_NONE ) { I_Error( "Invalid IP Address: %s\n", ipOnly.c_str() ); session->QuitMatch(); common->AddDialog( GDM_OPPONENT_CONNECTION_LOST, DIALOG_ACCEPT, NULL, NULL, false ); } ::g->sendaddress[::g->doomcom.numnodes].sin_addr.s_addr = ipAddress; ::g->doomcom.numnodes++; } ::g->doomcom.id = DOOMCOM_ID; ::g->doomcom.numplayers = ::g->doomcom.numnodes; } if ( globalNetworking ) { // Setup sockets ::g->insocket = UDPsocket (); BindToLocalPort (::g->insocket,htons(DOOMPORT)); // PS3 call to enable non-blocking mode int nonblocking = 1; // Non-zero is nonblocking mode. setsockopt( ::g->insocket, SOL_SOCKET, SO_NBIO, &nonblocking, sizeof(nonblocking)); ::g->sendsocket = UDPsocket (); I_Printf( "[+] Setting up sockets for player %d\n", DoomLib::GetPlayer() ); } }