当前位置: 首页>>代码示例>>C++>>正文


C++ NetBuffer类代码示例

本文整理汇总了C++中NetBuffer的典型用法代码示例。如果您正苦于以下问题:C++ NetBuffer类的具体用法?C++ NetBuffer怎么用?C++ NetBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NetBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: textMessage

void NetClient::textMessage( const std::string &data )
{
    Packet    packet2;
    NetBuffer netbuf;
    netbuf.addString( data );
    //No data.
    packet2.send( CMD_TXTMESSAGE, 0,
                 netbuf.getData(), netbuf.getDataLength(),
                 SENDRELIABLE, NULL, *this->clt_tcp_sock,
                 __FILE__, PSEUDO__LINE__( 165 ) );
}
开发者ID:vegastrike,项目名称:Vega-Strike-Engine-Source,代码行数:11,代码来源:netclient_login.cpp

示例2: printf

void Server::prespawn(char *cmdline, void *p, ...) {
	Client *client = reinterpret_cast<Client *>(p);
	if (client->m_spawned) {
		printf("prespawn not valid -- allready spawned\n");
		return;
	}
	NetBuffer *msg = &client->m_msg;
	msg->write(m_signon);
	msg->write_byte(svc_signonnum);
	msg->write_byte(2);
	client->m_sendsignon = true;
}
开发者ID:elhobbs,项目名称:spectre3ds,代码行数:12,代码来源:Server.cpp

示例3: god

void Server::god(char *cmdline, void *p, ...) {
	Client *client = reinterpret_cast<Client *>(p);
	edict_t *ent = client->m_edict;
	NetBuffer *msg = &client->m_msg;

	ent->v.flags = (int)ent->v.flags ^ FL_GODMODE;
	msg->write_byte(svc_print);
	if (!((int)ent->v.flags & FL_GODMODE))
		msg->write_string("godmode OFF\n");
	else
		msg->write_string("godmode ON\n");

}
开发者ID:elhobbs,项目名称:spectre3ds,代码行数:13,代码来源:Server.cpp

示例4: read_client_move

void Server::read_client_move(Client *client) {
	NetBuffer *msg = client->m_netconnection->m_receiveMessage;
	usercmd_t *move = &client->m_cmd;

	int		i;
	vec3_t	angle;
	int		bits;

	// read ping time
	client->m_ping_times[client->m_num_pings%NUM_PING_TIMES]
		= m_time - msg->read_float();
	client->m_num_pings++;

	// read current angles	
	for (i = 0; i<3; i++)
		angle[i] = msg->read_angle();

	VectorCopy(angle, client->m_edict->v.v_angle);

	// read movement
	move->forwardmove = msg->read_short();
	move->sidemove = msg->read_short();
	move->upmove = msg->read_short();

	// read buttons
	bits = msg->read_byte();
	client->m_edict->v.button0 = (bits & 1);
	client->m_edict->v.button2 = (bits & 2) >> 1;

	i = msg->read_byte();
	if (i)
		client->m_edict->v.impulse = i;
}
开发者ID:elhobbs,项目名称:spectre3ds,代码行数:33,代码来源:Server.cpp

示例5: Send

void NetChannel::Send(NetBuffer& buffer)
{
	if (buffer.GetCurLength() > FRAGMENT_SIZE)
	{
		return SendFragmented(buffer);
	}

	static char msgBuffer[FRAGMENT_SIZE + 100];
	*(uint32_t*)(msgBuffer) = m_outSequence;
	memcpy(&msgBuffer[4], buffer.GetBuffer(), buffer.GetCurLength());

	m_netLibrary->SendData(m_targetAddress, msgBuffer, buffer.GetCurLength() + 4);

	m_outSequence++;
}
开发者ID:ByModzMaster,项目名称:client,代码行数:15,代码来源:NetChannel.cpp

示例6: fly

void Server::fly(char *cmdline, void *p, ...) {
	Client *client = reinterpret_cast<Client *>(p);
	edict_t *ent = client->m_edict;
	NetBuffer *msg = &client->m_msg;

	msg->write_byte(svc_print);
	if (ent->v.movetype != MOVETYPE_FLY) {
		ent->v.movetype = MOVETYPE_FLY;
		msg->write_string("flymode ON\n");
	}
	else {
		ent->v.movetype = MOVETYPE_WALK;
		msg->write_string("flymode OFF\n");
	}

}
开发者ID:elhobbs,项目名称:spectre3ds,代码行数:16,代码来源:Server.cpp

示例7: sfReqTest

/*	send func
	테스트 프로토콜 타입 
	test0: 문자열
	test1: 소수점 4바이트
	test2: 소수점 8바이트
	test3: 정수 1바이트
	test4: 정수 2바이트
	test5: 정수 4바이트
	test6: 정수 8바이트
*/
bool ProtocolHandler::sfReqTest(string test0, float test1, double test2, uint8_t test3, uint16_t test4, uint32_t test5, uint64_t test6)
{
	NetBuffer buffer;
	buffer.AddUInt32(PROTOCOLS::PPREQTEST);
	buffer.AddString(test0);
	buffer.AddFloat(test1);
	buffer.AddDouble(test2);
	buffer.AddUInt8(test3);
	buffer.AddUInt16(test4);
	buffer.AddUInt32(test5);
	buffer.AddUInt64(test6);

	return mpPeer->SendData(&buffer);
}
开发者ID:kimsy0727,项目名称:ProtocolGenerator,代码行数:24,代码来源:ProtocolHandler.cpp

示例8: noclip

void Server::noclip(char *cmdline, void *p, ...) {
	Client *client = reinterpret_cast<Client *>(p);
	edict_t *ent = client->m_edict;
	NetBuffer *msg = &client->m_msg;

	if (m_progs->m_global_struct->deathmatch)
		return;

	msg->write_byte(svc_print);
	if (ent->v.movetype != MOVETYPE_NOCLIP)
	{
		//noclip_anglehack = true;
		ent->v.movetype = MOVETYPE_NOCLIP;
		msg->write_string("noclip ON\n");
	}
	else
	{
		ent->v.movetype = MOVETYPE_WALK;
		msg->write_string("noclip OFF\n");
	}
}
开发者ID:elhobbs,项目名称:spectre3ds,代码行数:21,代码来源:Server.cpp

示例9: selectShip

/*
 ************************************************************
 **** Create a new character                              ***
 ************************************************************
 */
bool NetClient::selectShip( unsigned int ship )
{
    if (lastsave.empty() || lastsave[0] == "") {
        NetBuffer netbuf;
        string    shipname;
        netbuf.addShort( (unsigned short) ship );
        if ( ship < ship_select_list.size() )
            shipname = ship_select_list[ship];
        netbuf.addString( shipname );
        Packet p;
        p.send( CMD_CHOOSESHIP, 0, netbuf.getData(), netbuf.getDataLength(), SENDRELIABLE,
               NULL, *clt_tcp_sock, __FILE__, PSEUDO__LINE__( 628 ) );
        string err;
        int    ret = loginLoop( err );
        if (ret != 1 || lastsave.size() < 2 || lastsave[0] == "") {
            cout<<"Error in CHOOSEHIP: "<<err
                <<"choice="<<ship<<"("<<shipname<<"), max="<<ret<<endl;
            return false;
        }
    }
    return true;
}
开发者ID:vegastrike,项目名称:Vega-Strike-Engine-Source,代码行数:27,代码来源:netclient_login.cpp

示例10: handleTransmitInterrupt

    void MacBase::handleTransmitInterrupt() {

      uint16_t i;
      ETH_DMADESCTypeDef *txbuf;
      NetBuffer *nb;

      // loop over the small number of tx buffers

      txbuf=_transmitDmaDescriptors.get();
      for(i=0;i<_params.mac_transmitBufferCount;i++) {

        // if the CPU owns the descriptor and a buffer is present then it's finished
        // free the buffer and clear it out

        if((txbuf->Status & ETH_DMATxDesc_OWN)==0 && _transmitNetBuffers[i]!=nullptr) {

          // send a notification that a NetBuffer is being cleaned up. This can be used by
          // the receiver to synchronise frame send requests with the frame actually being
          // transmitted

          nb=_transmitNetBuffers[i];
          this->NetworkNotificationEventSender.raiseEvent(DatalinkFrameSentEvent(*nb));

          // if this is the last in a sequence of fragmented packets then there will be a referenced
          // netbuffer that is serving to hold the jumbo packet's memory in scope while the fragments
          // got tx'd. now that's done we're safe to delete it and we must also notify it upwards
          // because that's the buffer that anything waiting on will recognise.

          if(nb->getReference())
            this->NetworkNotificationEventSender.raiseEvent(DatalinkFrameSentEvent(*(nb->getReference())));

          // clean up the buffer

          delete _transmitNetBuffers[i];
          _transmitNetBuffers[i]=nullptr;
        }
      }
    }
开发者ID:ADTL,项目名称:stm32plus,代码行数:38,代码来源:MacBase.cpp

示例11: addAsteroidBuffer

void UnitFactory::addAsteroidBuffer( NetBuffer &netbuf,
                                     const char *filename,
                                     int faction,
                                     Flightgroup *fg,
                                     int fg_snumber,
                                     float difficulty,
                                     ObjSerial netcreate )
{
    netbuf.addChar( ZoneMgr::AddAsteroid );
    netbuf.addSerial( netcreate );
    netbuf.addString( string( filename ) );
    netbuf.addInt32( faction );
    netbuf.addString( fg->name );
    netbuf.addInt32( fg_snumber );
    netbuf.addFloat( difficulty );
}
开发者ID:vegastrike,项目名称:Vega-Strike-Engine-Source,代码行数:16,代码来源:unit_factory_generic.cpp

示例12: addNebulaBuffer

void UnitFactory::addNebulaBuffer( NetBuffer &netbuf,
                                   const char *unitfile,
                                   bool SubU,
                                   int faction,
                                   Flightgroup *fg,
                                   int fg_snumber,
                                   ObjSerial netcreate )
{
    netbuf.addChar( ZoneMgr::AddNebula );
    netbuf.addSerial( netcreate );
    netbuf.addString( string( unitfile ) );
    netbuf.addChar( SubU );
    netbuf.addInt32( faction );
    netbuf.addString( fg->name );
    netbuf.addInt32( fg_snumber );
}
开发者ID:vegastrike,项目名称:Vega-Strike-Engine-Source,代码行数:16,代码来源:unit_factory_generic.cpp

示例13: sendLoginAccept

void NetServer::sendLoginAccept( ClientPtr clt, Cockpit *cp )
{
    COUT<<"enter "<<__PRETTY_FUNCTION__<<endl;
    //Verify that client already has a character
    NetBuffer netbuf;
    Unit     *un = cp->GetParent();
    if (!un) {
        sendLoginError( clt );
        return;
    }
    //Put the save parts in buffers in order to load them properly
    netbuf.Reset();

    string datestr = _Universe->current_stardate.GetFullTrekDate();
    netbuf.addString( datestr );
    netbuf.addString( clt->savegame[0] );
    netbuf.addString( clt->savegame[1] );

    Packet    packet2;

    //Create a cockpit for the player and parse its savegame
    ObjSerial cltserial = un->GetSerial();

    COUT<<">>> SEND LOGIN ACCEPT =( serial #"<<cltserial<<" )= --------------------------------------"<<endl;
    COUT<<"SAVE="<<clt->savegame[0].length()<<" bytes - XML="<<clt->savegame[1].length()<<" bytes"<<endl;
    cerr<<"SENDING STARDATE : "<<datestr<<endl;
    //Add the initial star system filename + hash if crypto++ support too
    string sysname = cp->savegame->GetStarSystem();
    string relsys  = sysname+".system";
    netbuf.addString( relsys );

    //Generate the starsystem before addclient so that it already contains serials
    StarSystem    *sts    = zonemgr->addZone( sysname );

#ifdef CRYPTO
    unsigned char *digest = new unsigned char[FileUtil::Hash.DigestSize()];
    string sysxml;
    if ( !( sysxml = zonemgr->getSystem( relsys ) ).empty() )
        FileUtil::HashStringCompute( sysxml, digest );
    else if ( !sysname.empty() )
        FileUtil::HashFileCompute( relsys, digest, SystemFile );
    netbuf.addShort( FileUtil::Hash.DigestSize() );
    netbuf.addBuffer( digest, FileUtil::Hash.DigestSize() );
    delete[] digest;
#else
    netbuf.addShort( 0 );
#endif

    int zoneid = _Universe->StarSystemIndex( sts );
    netbuf.addShort( zoneid );

    //Add system string to packet...
    //Long, I know, but is there any other way to keep all the proper graphics-related data that the server discards?
    //netbuf.addString( zonemgr->getSystem(sysname) );

    packet2.send( LOGIN_ACCEPT, cltserial, netbuf.getData(),
                 netbuf.getDataLength(), SENDRELIABLE, &clt->cltadr, clt->tcp_sock, __FILE__, PSEUDO__LINE__( 241 ) );
    //Now that we have a starsystem, we will want to make a mission.
    if (Mission::getNthPlayerMission( _Universe->whichPlayerStarship( un ), 0 ) == NULL) {
        if (active_missions.size() == 1)
            active_missions[0]->DirectorInitgame();
        //Make a mission specially for this cockpit.
        unsigned int oldcp = _Universe->CurrentCockpit();
        _Universe->SetActiveCockpit( cp );
        _Universe->pushActiveStarSystem( _Universe->AccessCockpit()->activeStarSystem );
        LoadMission( "", vs_config->getVariable( "server", "serverscript", "import server;my_obj=server.player()" ), false );
        _Universe->popActiveStarSystem();
        _Universe->SetActiveCockpit( oldcp );
    }
}
开发者ID:Ezeer,项目名称:VegaStrike_win32FR,代码行数:70,代码来源:netserver_login.cpp

示例14: while

bool IpPacketFragmentFeature::createFragmentsFrom(NetBuffer *inputBuffer,
        const void *sourceData,
        uint16_t sourceDataSize,
        NetBuffer **outputBuffers,
        uint16_t firstOutputBuffer,
        bool lastFragmentIsHere,
        uint16_t& offset) {

    NetBuffer *nb;
    uint16_t fragmentSize,flags;
    const uint8_t *ptr;

    ptr=reinterpret_cast<const uint8_t *>(sourceData);

    while(sourceDataSize) {

        // calculate sizes

        fragmentSize=sourceDataSize<_mtu-IpPacketHeader::getNoOptionsHeaderSize() ?
                     sourceDataSize :
                     _mtu-IpPacketHeader::getNoOptionsHeaderSize();

        // create a new netbuffer for the fragment

        nb=new NetBuffer(_linkHeaderSize+IpPacketHeader::getNoOptionsHeaderSize(),  // needs IP and link layer headers
                         0,
                         ptr,                                 // fragment data starts here
                         fragmentSize);                       // size of this fragment

        // more fragments flag if this is not the last in the run

        if(lastFragmentIsHere && fragmentSize==sourceDataSize) {

            // this is the last

            flags=0;
            nb->setReference(inputBuffer);
        }
        else
            flags=MORE_FRAGMENTS;

        // insert the IP fragment header

        IpPacketHeader *header=reinterpret_cast<IpPacketHeader *>(nb->moveWritePointerBack(IpPacketHeader::getNoOptionsHeaderSize()));

        // set up only the parts that are unique to the fragmenter

        header->ip_hdr_length=NetUtil::htons(IpPacketHeader::getNoOptionsHeaderSize()+fragmentSize);
        header->ip_hdr_identification=_identification;
        header->ip_hdr_flagsAndOffset=NetUtil::htons((offset/8) | flags);

        // store the netbuffer in the array

        outputBuffers[firstOutputBuffer++]=nb;

        // update pointers

        ptr+=fragmentSize;
        sourceDataSize-=fragmentSize;
        offset+=fragmentSize;
    }

    return true;
}
开发者ID:purinda,项目名称:stm32plus,代码行数:64,代码来源:IpPacketFragmentFeature.cpp

示例15: addPlanetBuffer

void UnitFactory::addPlanetBuffer( NetBuffer &netbuf,
                                   QVector x,
                                   QVector y,
                                   float vely,
                                   const Vector &rotvel,
                                   float pos,
                                   float gravity,
                                   float radius,
                                   const char *filename,
                                   BLENDFUNC sr,
                                   BLENDFUNC ds,
                                   const vector< string > &dest,
                                   const QVector &orbitcent,
                                   Unit *parent,
                                   const GFXMaterial &ourmat,
                                   const std::vector< GFXLightLocal > &ligh,
                                   int faction,
                                   string fullname,
                                   bool inside_out,
                                   ObjSerial netcreate )
{
    netbuf.addChar( ZoneMgr::AddPlanet );
    netbuf.addSerial( netcreate );
    netbuf.addQVector( x );
    netbuf.addQVector( y );
    netbuf.addFloat( vely );
    netbuf.addVector( Vector( rotvel ) );
    netbuf.addFloat( pos );
    netbuf.addFloat( gravity );
    netbuf.addFloat( radius );

    netbuf.addString( string( filename ) );
    netbuf.addChar( sr );
    netbuf.addChar( ds );

    netbuf.addShort( dest.size() );
    for (unsigned int i = 0; i < dest.size(); i++)
        netbuf.addString( dest[i] );
    netbuf.addQVector( QVector( orbitcent ) );
    netbuf.addSerial( parent->GetSerial() );
    netbuf.addGFXMaterial( ourmat );
    netbuf.addShort( ligh.size() );
    for (unsigned int j = 0; j < ligh.size(); j++)
        netbuf.addGFXLightLocal( ligh[j] );
    netbuf.addInt32( faction );
    netbuf.addString( fullname );
    netbuf.addChar( inside_out );
}
开发者ID:vegastrike,项目名称:Vega-Strike-Engine-Source,代码行数:48,代码来源:unit_factory_generic.cpp


注:本文中的NetBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。