void sv_Create() { NMErr err; unsigned char gameNameStr[32], playerNameStr[32]; char gameName[32], playerName[32]; NMUInt32 port; int players; NSpProtocolReference protocolRef; unsigned char Pass[32]; err = NSpInitialize( 0, 0, 0, 'NSe1', 0 ); if( err ) { m_ConsPrint("Network Initialization failed\n"); return; } port = (NMUInt32)(int)net_port.value; // 1000->32767 players = (NMUInt32)NET_MAXPLAYER; // 1->32 sprintf(gameName,"%s",net_svname.string); sprintf(playerName,"%s",net_clname.string); GameC2PStr( gameName, gameNameStr ); GameC2PStr( playerName, playerNameStr ); GameC2PStr( net_password.string, Pass ); err = NSpProtocolList_New( NULL, &_protocolListRef ); if( err ) { m_ConsPrint("Network Protocol Initialization failed\n"); return; } protocolRef = NSpProtocol_CreateIP( (NMUInt16)port, 0, 0 ); if(!protocolRef) { m_ConsPrint("Network kNSpInvalidProtocolRefErr error\n"); return; } err = NSpProtocolList_Append( _protocolListRef, protocolRef ); if(err) { m_ConsPrint("Network NSpProtocolList_Append error\n"); return; } err = NSpGame_Host( &_gameReference, _protocolListRef, players, gameNameStr, Pass, playerNameStr, kPlayerType, kNSpClientServer, 0 ); if(err) { m_ConsPrint("Network NSpGame_Host error\n"); return; } gNetworkInitialised = true; m_ConsPrint("Network Initialization ok\n"); }
NMErr NetworkStartServer ( NMUInt16 port, /* port clients will connect on */ NMUInt32 maxPlayers, /* max # of players to allow into game */ const unsigned char *gameName, /* name of game (displayed to clients on connect) */ const unsigned char *playerName /* name of player on server computer */ ) { NSpProtocolReference protocolRef; NMErr err; /* Create a new protocol list to store our IP protocol reference in */ err = NSpProtocolList_New( NULL, &_protocolListRef ); if( !err ) { /* Create a protocol reference for our IP connection, on our specified port w/default maxRTT and throughput */ protocolRef = NSpProtocol_CreateIP( port, 0, 0 ); if( protocolRef ) { unsigned char passwordPStr[32]; doCopyC2PStr("Password",passwordPStr); /* We got a good reference, append it to the list we created earlier */ err = NSpProtocolList_Append( _protocolListRef, protocolRef ); if( !err ) { /* We got a protocol and it's in our reference list, now we can create the game to host, using the parms sent in and defaulting rest of the "unused" hosting parms */ err = NSpGame_Host( &_gameReference, _protocolListRef, maxPlayers, gameName, passwordPStr, playerName, kPlayerType, kNSpClientServer, 0 ); } } else err = kNSpInvalidProtocolRefErr; /* assign somewhat meaningful error on failure to create protocol reference */ } return( err ); }