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 NetworkStartup( void ) { NMErr err; /* First, make sure that NetSprockets is available (we weak linked to OpenPlayStubLib) */ if( NULL == NSpInitialize ) /*|| NULL == ProtocolAcceptConnection )*/ return( kNMModuleNotFoundErr ); /* Initialize NetSprockets, 0 == use defaults & NSe1 stands for "NetSprocket Example 1" It is an identifier for games of our type on the network */ err = NSpInitialize( 0, 0, 0, 'NSe1', 0 ); return( err ); }