NMErr NetworkSendAnswer ( char answer /* the answer to send (just a char!) */ ) { AnswerPacket_t answerPacket; NMErr err; /* init the NetSprocket portion of the packet */ NSpClearMessageHeader( &answerPacket.header ); answerPacket.header.what = kMessageType_Answer; answerPacket.header.to = kNSpHostID; /* %% was kNSpHostOnly */ answerPacket.header.messageLen = sizeof(answerPacket); /* fill in the data section */ answerPacket.answer = answer; /* tell NetSprocket to send the message */ err = NSpMessage_Send( _gameReference, &answerPacket.header, kNSpSendFlag_Registered ); if( err ) { printf( "*** ERROR *** Unable to send answer packet, error # %d\n\n", err ); fflush(stdout); } return( err ); }
void ERObject::Clear() { if (mMessage != NULL) NSpClearMessageHeader(mMessage); mEndpoint = NULL; mTimeReceived = 0; }
void sv_Send(char *message, int id_packet, hBool SafeSend) { MessagePacketPtr qpp; unsigned long messageLen, size; NMErr err; NSpFlags Flag; if( !message ) return; //( kNSpInvalidParameterErr ); // get size of message string & total size of network packet messageLen = strlen( message ); size = sizeof(MessagePacket_t) + messageLen + 1; /* header + num_chars + terminator */ // allocate the memory for the packet qpp = (MessagePacketPtr)malloc( size ); if( !qpp ) { m_ConsPrint(" *** ERROR *** Unable to allocate message buffer!\n"); fflush(stdout); return; //( kNSpMemAllocationErr ); } // init the NetSprocket portion of the packet NSpClearMessageHeader( &qpp->header ); qpp->header.what = (NMSInt32)id_packet; qpp->header.to = kNSpAllPlayers; qpp->header.messageLen = size; // fill in the data section strcpy( qpp->str, message ); // tell NetSprocket to send the message if(SafeSend) Flag = kNSpSendFlag_Registered; else Flag = /*kNSpSendFlag_Junk; //*/kNSpSendFlag_Normal; err = NSpMessage_Send( _gameReference, &qpp->header, Flag ); if( !err ) { net_AddUpload(size); // qpp->header.to = kNSpHostOnly; // allow host to play as well! // err = NSpMessage_Send( _gameReference, &qpp->header, kNSpSendFlag_Registered ); } if( err ) { m_ConsPrint("*** ERROR *** Unable to send message packet, error # %d\n", err ); fflush(stdout); } // clean up after ourselves s_free( qpp ); }
void sv_Send2(char *message, int messageLen, int id_packet, hBool SafeSend) { MessagePacketPtr qpp; unsigned long size; NMErr err; NSpFlags Flag; if(!message) return; //( kNSpInvalidParameterErr ); size = sizeof(MessagePacket_t) + messageLen + 1; qpp = (MessagePacketPtr)malloc( size ); if( !qpp ) { m_ConsPrint(" *** ERROR *** Unable to allocate message buffer!\n"); fflush(stdout); return; //( kNSpMemAllocationErr ); } NSpClearMessageHeader( &qpp->header ); qpp->header.what = (NMSInt32)id_packet; qpp->header.to = kNSpAllPlayers; qpp->header.messageLen = size; memcpy( qpp->str, message, messageLen); if(SafeSend) Flag = kNSpSendFlag_Registered; else Flag = /*kNSpSendFlag_Junk; //*/kNSpSendFlag_Normal; err = NSpMessage_Send( _gameReference, &qpp->header, Flag ); if( err ) { m_ConsPrint("*** ERROR *** Unable to send message packet, error # %d\n", err ); fflush(stdout); } else { net_AddUpload(size); } s_free( qpp ); }
NMErr NetworkSendPlayerMessage ( const char *message, /* ptr to message string to send */ NMUInt32 messageType /* type of message (question, info, etc. */ ) { MessagePacketPtr qpp; unsigned long messageLen, size; NMErr err; /* sanity checks */ if( !message ) return( kNSpInvalidParameterErr ); /* get size of message string & total size of network packet */ messageLen = strlen( message ); size = sizeof(MessagePacket_t) + messageLen + 1; /* header + num_chars + terminator */ /* allocate the memory for the packet */ qpp = (MessagePacketPtr)malloc( size ); if( !qpp ) { printf( " *** ERROR *** Unable to allocate message buffer!\n\n" ); fflush(stdout); return( kNSpMemAllocationErr ); } /* init the NetSprocket portion of the packet */ NSpClearMessageHeader( &qpp->header ); qpp->header.what = (NMSInt32)messageType; qpp->header.to = kNSpAllPlayers; qpp->header.messageLen = size; /* fill in the data section */ strcpy( qpp->str, message ); /* tell NetSprocket to send the message */ err = NSpMessage_Send( _gameReference, &qpp->header, kNSpSendFlag_Registered ); if( !err ) { qpp->header.to = kNSpHostID; /* %% was kNSpHostOnly */ /* allow host to play as well! */ err = NSpMessage_Send( _gameReference, &qpp->header, kNSpSendFlag_Registered ); } if( err ) { printf( "*** ERROR *** Unable to send message packet, error # %d\n\n", err ); fflush(stdout); } /* clean up after ourselves! */ free( qpp ); return( err ); }