• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ enet_peer_send函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: enet_packet_create

void Connection::send_packet_reliable(void *data,int ID){
	ENetPacket *packet = enet_packet_create (data, sizeof(data), ENET_PACKET_FLAG_RELIABLE);
	if(!client)
		enet_peer_send (&connS->peers[ID], 0, packet);
	else
		enet_peer_send(peer,0,packet);
}
开发者ID:killertux,项目名称:Troll-Killers,代码行数:7,代码来源:Connection.cpp


示例2: joynet_handle_server_chat_message

void joynet_handle_server_chat_message(JOYNET_SERVER * sp, JOYNET_MESSAGE * mp)
{
	switch(mp->type)
	{
		case JOYNET_CHAT_MESSAGE_SET_NAME:
		{
			int client = joynet_get_client_from_peer(sp, mp->event->peer);
			ENetPacket * packet;
			
			/* send SET_NAME message back to client to finalize the change */
			strcpy(sp->client[client]->screen_name, mp->data);
			packet = joynet_build_packet(JOYNET_CHAT_MESSAGE_SET_NAME, mp->data, strlen(mp->data) + 1);
			enet_peer_send(sp->client[client]->peer, JOYNET_CHANNEL_CHAT, packet);
			break;
		}
		case JOYNET_CHAT_MESSAGE_SET_GROUP:
		{
			int client = joynet_get_client_from_peer(sp, mp->event->peer);
			ENetPacket * packet;
			
			joynet_serialize(sp->serial_data, mp->data);
			joynet_getw(sp->serial_data, &sp->client[client]->group);
			
			/* send SET_GROUP message back to client to finalize the change */
			packet = joynet_build_packet(JOYNET_CHAT_MESSAGE_SET_GROUP, mp->data, sizeof(short));
			enet_peer_send(sp->client[client]->peer, JOYNET_CHANNEL_CHAT, packet);
			break;
		}
		case JOYNET_CHAT_MESSAGE_TALK:
		case JOYNET_CHAT_MESSAGE_GROUP_TALK:
		{
			int client = joynet_get_client_from_peer(sp, mp->event->peer);
			char data[1024] = {0};
			short name_length = strlen(sp->client[client]->screen_name) + 1;
			short message_length = strlen(mp->data) + 1;
			ENetPacket * packet;
			int i;

			/* TALK message is different for client, contains user name and message */
			joynet_serialize(sp->serial_data, data);
			joynet_putw(sp->serial_data, name_length);
			joynet_putw(sp->serial_data, message_length);
			joynet_write(sp->serial_data, sp->client[client]->screen_name, name_length);
			joynet_write(sp->serial_data, mp->data, message_length);
			packet = joynet_create_packet(JOYNET_CHAT_MESSAGE_TALK, sp->serial_data);
			for(i = 0; i < sp->max_clients; i++)
			{
				if((sp->client[i]->peer) && ((mp->type == JOYNET_CHAT_MESSAGE_GROUP_TALK) || (sp->client[i]->group == sp->client[client]->group)))
				{
					enet_peer_send(sp->client[i]->peer, JOYNET_CHANNEL_CHAT, packet);
				}
			}
			break;
		}
	}
}
开发者ID:showkoba,项目名称:JoyNet,代码行数:56,代码来源:chat.c


示例3: connection_send_to

void connection_send_to(uint32_t id, uint8_t channel, const char *data, size_t size, ENetPeer* target) {
    ENetPacket *packet = enet_packet_create(NULL, sizeof(user_id) +sizeof(id) + sizeof(uint32_t) + size, 0);
    pack_format((char *)packet->data, "uua", user_id, id, data, size);

    if (target) {
        enet_peer_send(target, channel, packet);
        return;
    }

    if (connection_is_host()) {
        broadcast_except(NULL, packet, channel);
    } else if (server) {
        enet_peer_send(server, channel, packet);
    }
}
开发者ID:kroltan,项目名称:ifcgame,代码行数:15,代码来源:connection.c


示例4: enet_packet_create

bool Game::send(const Packet & packet, ENetPeer * peer)
{
	ENetPacket * enetPacket = enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
	if (!enetPacket)
		return false;
	return enet_peer_send(peer, 0, enetPacket) == 0;
}
开发者ID:kiwon0905,项目名称:Residents-vs-Aliens,代码行数:7,代码来源:Game.cpp


示例5: handle_input_command

/**
 * Handle input command.
 *
 * This function should return 0, even if the command failed.
 * Return of != 0 means the event loop will quit.
 */
static int handle_input_command(const dstring* string) {
	dstrlist* list;
	dstring** argv;
	unsigned int argc;
	int error;
	ENetPacket* packet;


	if (string->len == 0) {
		/* empty command */
		return 0;
	} else if (string->data[0] == '/') {
		/* local command */
		/* parse the command */
		list = dstrlex_parse(string, &error);
		if (list == NULL) {
			fprintf(stderr, "Failed to parse command string '%s': %s\n", string->data, dstrlex_errstr(error));
			return 0;
		}

		/* convert list to vector */
		argc = list->size;
		argv = dlist_tovector(list);
		dlist_free(list);

		/* select command to execute */
		if (dcmpcs(argv[0], "/connect") == 0) {
			error = cmd_connect(argc, argv);
		} else if (dcmpcs(argv[0], "/disconnect") == 0) {
			error = cmd_disconnect(argc, argv);
		} else if (dcmpcs(argv[0], "/quit") == 0) {
			error = cmd_quit(argc, argv);
		} else if (dcmpcs(argv[0], "/mute") == 0) {
			error = cmd_mute(argc, argv);
		} else if (dcmpcs(argv[0], "/deafen") == 0) {
			error = cmd_deafen(argc, argv);
		} else {
			fprintf(stderr, "Unknown command '%s'\n", argv[0]->data);
			error = 0;
		}

		dvec_free(argv);
		return error;
	} else if (client.state == SVCECLIENT_STATE_CONNECTED) {
		/* send to server if connected */
		mutex_lock(&client.network_lock);
		packet = enet_packet_create(string->data, string->len, ENET_PACKET_FLAG_RELIABLE);
		enet_peer_send(client.client, 0, packet);
		mutex_unlock(&client.network_lock);
	} else if (client.state == SVCECLIENT_STATE_CONNECTING) {
		/* server command but still connecting */
		fprintf(stderr, "Can't send command to server, still connecting.\n");
	} else {
		/* server command but not connected */
		fprintf(stderr, "Can't send command to server, not connected.\n");
	}


	return 0;
}
开发者ID:atheros,项目名称:svc,代码行数:66,代码来源:main.c


示例6: getClient

void ENetServer::sendMessage(uint32_t id, DeliveryType type, Message::Shared msg) const
{
    auto client = getClient(id);
    if (!client) {
        // no client to send to
        LOG_WARN("No connected client with id: " << id);
        return;
    }
    uint32_t channel = 0;
    uint32_t flags = 0;
    if (type == DeliveryType::RELIABLE) {
        channel = RELIABLE_CHANNEL;
        flags = ENET_PACKET_FLAG_RELIABLE;
    } else {
        channel = UNRELIABLE_CHANNEL;
        flags = ENET_PACKET_FLAG_UNSEQUENCED;
    }

    // get bytes
    auto data = msg->serialize();
    // create the packet
    ENetPacket* p = enet_packet_create(
        &data[0],
        data.size(),
        flags);

    // send the packet to the peer
    enet_peer_send(client, channel, p);
    // flush / send the packet queue
    enet_host_flush(host_);
}
开发者ID:kbirk,项目名称:enet-example,代码行数:31,代码来源:ENetServer.cpp


示例7: while

void GDNetHost::send_messages() {
	while (!_message_queue.is_empty()) {
		GDNetMessage* message = _message_queue.pop();

		int flags = 0;

		switch (message->get_type()) {
			case GDNetMessage::UNSEQUENCED:
				flags |= ENET_PACKET_FLAG_UNSEQUENCED;
				break;

			case GDNetMessage::RELIABLE:
				flags |= ENET_PACKET_FLAG_RELIABLE;
				break;

			default:
				break;
		}

		ByteArray::Read r = message->get_packet().read();
		ENetPacket * enet_packet = enet_packet_create(r.ptr(), message->get_packet().size(), flags);

		if (enet_packet != NULL) {
			if (message->is_broadcast()) {
				enet_host_broadcast(_host, message->get_channel_id(), enet_packet);
			} else {
				enet_peer_send(&_host->peers[message->get_peer_id()], message->get_channel_id(), enet_packet);
			}
		}

		memdelete(message);
	}
}
开发者ID:jrimclean,项目名称:gdnet,代码行数:33,代码来源:gdnet_host.cpp


示例8: udpr_send_char

/**
        udpr_send_char : peer -> data:int -> chan:int -> reliable:bool -> void
        Send a character [ over a connected socket. Must be in the range 0..255</doc>
**/
static value udpr_send_char( value p, value data, value chan, value reliable ) {
	ENetPeer *peer;
	ENetPacket *packet;
	int c,d;
	char buf[2];
	val_check_kind(p,k_udprpeer);
	val_check(data,int);
	val_check(chan,int);
	val_check(reliable,bool);

	peer = (ENetPeer *)val_data(p);
	c = val_int(chan);
    d = val_int(data);

    if( peer == NULL || c < 0 || c > 255 || d < 0 || d > 255 )
        neko_error();
   	buf[0] = (unsigned char)d;
   	buf[1] = '\0';
	packet = enet_packet_create(
		buf,
		1,
		val_bool(reliable) ? ENET_PACKET_FLAG_RELIABLE : 0);
    if(enet_peer_send(peer, c, packet))
		neko_error();
    return val_true;
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:30,代码来源:udprsocket.c


示例9: joynet_select_player

void joynet_select_player(JOYNET_GAME * gp, int player)
{
	char data[2];
	ENetPacket * pp;
	if(gp->client)
	{
		if(gp->client->master && gp->state == JOYNET_GAME_STATE_PLAYING)
		{
			joynet_serialize(gp->client->serial_data, data);
			joynet_putw(gp->client->serial_data, player);
			pp = joynet_create_packet(JOYNET_GAME_MESSAGE_SELECT_PLAYER, gp->client->serial_data);
			enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
		}
	}
	else
	{
		JOYNET_MESSAGE message;
		
		if(gp->callback)
		{
			message.type = JOYNET_GAME_MESSAGE_SELECT_PLAYER;
			message.data = NULL;
			message.data_size = 0;
			message.event = NULL;
			gp->callback(&message);
			gp->current_player = player;
		}
	}
}
开发者ID:showkoba,项目名称:JoyNet,代码行数:29,代码来源:game.c


示例10: joynet_end_game

void joynet_end_game(JOYNET_GAME * gp)
{
	ENetPacket * pp;
	if(gp->client)
	{
		if(gp->client->master && (gp->state == JOYNET_GAME_STATE_PAUSED || gp->state == JOYNET_GAME_STATE_PLAYING))
		{
			pp = joynet_create_packet(JOYNET_GAME_MESSAGE_END, NULL);
			enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
		}
	}
	else
	{
		JOYNET_MESSAGE message;
		
		if(gp->state == JOYNET_GAME_STATE_PLAYING || gp->state == JOYNET_GAME_STATE_PAUSED)
		{
			gp->state = JOYNET_GAME_STATE_OFF;
			if(gp->callback)
			{
				message.type = JOYNET_GAME_MESSAGE_END;
				message.data = NULL;
				message.data_size = 0;
				message.event = NULL;
				gp->callback(&message);
			}
		}
	}
}
开发者ID:showkoba,项目名称:JoyNet,代码行数:29,代码来源:game.c


示例11: joynet_update_game_option

/* high level functions */
void joynet_update_game_option(JOYNET_GAME * gp, int * option)
{
	char data[1024] = {0};
	ENetPacket * pp;
	int i, c = 0;
	
	if(gp->client && gp->client->master)
	{
		for(i = 0; i < gp->options; i++)
		{
			if(gp->option[i] == option)
			{
				c = i;
				break;
			}
		}
		if(i < gp->options)
		{
			joynet_serialize(gp->client->serial_data, data);
			joynet_putw(gp->client->serial_data, c);
			joynet_putl(gp->client->serial_data, *gp->option[c]);
			pp = joynet_create_packet(JOYNET_GAME_MESSAGE_UPDATE_OPTION, gp->client->serial_data);
			enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
		}
	}
	else
	{
	}
}
开发者ID:showkoba,项目名称:JoyNet,代码行数:30,代码来源:game.c


示例12: joynet_update_game

/* if process is true, input will be sent (online play) */
void joynet_update_game(JOYNET_GAME * gp, int process)
{
	ENetPacket * pp;
	char data[1024];
	if(gp->client)
	{
		if(gp->player[gp->current_player]->local && process)
		{
			if(joynet_encode_game_input(gp, data))
			{
				pp = joynet_create_packet(JOYNET_GAME_MESSAGE_INPUT, gp->serial_data);
				enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
			}
		}
	}
	else
	{
		if(joynet_encode_game_input(gp, data))
		{
            joynet_write_input_buffer_frame(gp->input_buffer, data);
		}
		else
		{
			printf("failed to encode\n");
		}
	}
}
开发者ID:NewCreature,项目名称:JoyNet,代码行数:28,代码来源:game.c


示例13: while

void networkEngine::sendPacket(std::string packetData)
{
    //conversion *convert = conversion::Instance();
    boost::shared_ptr<conversion> convert = conversion::Instance();
    //gameEngine *gameE = gameEngine::Instance();
    boost::shared_ptr<gameEngine> gameE = gameEngine::Instance();

    if (gameE->getServerRunning())
    {
        while (enet_host_service (server, &event, 0) > 0)
        {
        }
    }
    else if (gameE->getClientRunning())
    {
        while (enet_host_service (client, &event, 0) > 0)
        {
        }
    }
    std::string host = convert->toString(peer->address.host);
    logMsg("packetData == " + packetData);
    logMsg("Peer host == " +host);
    exit(0);
    packet = enet_packet_create(packetData.c_str(),strlen(packetData.c_str())+1,ENET_PACKET_FLAG_RELIABLE);
    enet_peer_send (peer, 0, packet);

}
开发者ID:libolt,项目名称:ubc-merge,代码行数:27,代码来源:networkengine.cpp


示例14: udpr_send

/**
        udpr_send : peer -> data:string -> pos:int -> len:int -> chan:int -> reliable:bool -> int
        Send up to [len] bytes from [buf] starting at [pos] over a connected socket on channel [chan]
        using reliable setting [reliable]
        Return the number of bytes sent.
**/
static value udpr_send( value p, value data, value pos, value len, value chan, value reliable ) {
	ENetPeer *peer;
	ENetPacket *packet;
	int pp,l,sLen,c;
	val_check_kind(p,k_udprpeer);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	val_check(chan,int);
	val_check(reliable,bool);

	peer = (ENetPeer *)val_data(p);
	pp = val_int(pos);
	l = val_int(len);
	sLen = val_strlen(data);
	c = val_int(chan);
	if( peer == NULL || c < 0 || c > 255 || pp < 0 || l < 0 || pp > sLen || pp + l > sLen )
			neko_error();
	packet = enet_packet_create(
		val_string(data) + pp,
		l,
		val_bool(reliable) ? ENET_PACKET_FLAG_RELIABLE : 0);
	if(enet_peer_send(peer, c, packet))
		neko_error();
	return alloc_int(l);
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:32,代码来源:udprsocket.c


示例15: joynet_update_game

/* if process is true, input will be sent (online play) */
void joynet_update_game(JOYNET_GAME * gp, int process)
{
	ENetPacket * pp;
	char data[1024];
	if(gp->client)
	{
		if(process)
		{
			if(joynet_encode_game_input(gp, data))
			{
				pp = joynet_create_packet(JOYNET_GAME_MESSAGE_INPUT, gp->serial_data);
				enet_peer_send(gp->client->peer, JOYNET_CHANNEL_GAME, pp);
			}
		}
	}
	else
	{
		if(joynet_encode_game_input(gp, data))
		{
			memcpy(&(gp->input_buffer->data[gp->input_buffer->write_pos]), data, gp->input_buffer->frame_size);
//			printf("data - %d - %d\n", data[0], data[1]);
			gp->input_buffer->write_pos += gp->input_buffer->frame_size;
			if(gp->input_buffer->write_pos >= gp->input_buffer->frame_size * gp->max_buffer_frames)
			{
				gp->input_buffer->write_pos = 0;
			}
			gp->input_buffer->frames++;
		}
	}
}
开发者ID:showkoba,项目名称:JoyNet,代码行数:31,代码来源:game.c


示例16: assert

void Connection::send(u16 peer_id, u8 channelnum,
		SharedBuffer<u8> data, bool reliable)
{
	{
		//MutexAutoLock peerlock(m_peers_mutex);
		if (m_peers.find(peer_id) == m_peers.end())
			return;
	}
	//dout_con<<getDesc()<<" sending to peer_id="<<peer_id<<std::endl;

	assert(channelnum < CHANNEL_COUNT);

	ENetPacket *packet = enet_packet_create(*data, data.getSize(), reliable ? ENET_PACKET_FLAG_RELIABLE : 0);

	ENetPeer *peer = getPeer(peer_id);
	if(!peer) {
		deletePeer(peer_id, false);
		return;
	}
	if (enet_peer_send(peer, channelnum, packet) < 0) {
		infostream<<"enet_peer_send failed peer="<<peer_id<<" reliable="<<reliable<< " size="<<data.getSize()<<std::endl;
		if (reliable)
			deletePeer(peer_id, false);
		return;
	}
}
开发者ID:Wayward1,项目名称:freeminer,代码行数:26,代码来源:fm_connection.cpp


示例17: net_controller_har_hook

void net_controller_har_hook(int action, void *cb_data) {
    controller *ctrl = cb_data;
    wtf *data = ctrl->data;
    serial ser;
    ENetPeer *peer = data->peer;
    ENetHost *host = data->host;
    ENetPacket *packet;
    if (action == ACT_STOP && data->last_action == ACT_STOP) {
        data->last_action = -1;
        return;
    }
    if (action == ACT_FLUSH) {
        enet_host_flush(host);
        return;
    }
    data->last_action = action;
    serial_create(&ser);
    serial_write_int8(&ser, EVENT_TYPE_ACTION);
    serial_write_int16(&ser, action);
    /*DEBUG("controller hook fired with %d", action);*/
    /*sprintf(buf, "k%d", action);*/
    packet = enet_packet_create(ser.data, ser.len, ENET_PACKET_FLAG_RELIABLE);
    if (peer) {
        enet_peer_send(peer, 1, packet);
        /*enet_host_flush (host);*/
    } else {
        DEBUG("peer is null~");
    }
}
开发者ID:gdeda,项目名称:openomf,代码行数:29,代码来源:net_controller.c


示例18: pstrlen

pbool PNetworkServer::send(PNetworkPeer *peer, const puint8 *message, pint32 length)
{
    if (m_state == NETWORK_CONNECTED)
    {
        PMap<puint32, PNetworkPeer*>::iterator it = m_peers.find(peer->id());
        if (it != m_peers.end())
        {
            if (length == -1)
            {
                m_data->packet->dataLength = pstrlen((const pchar *)message) + 1;
            }
            else
            {
                m_data->packet->dataLength = length;
            }
            
            pmemcpy(m_data->packet->data, message, m_data->packet->dataLength);
            if (enet_peer_send(peer->data()->peer, 0, m_data->packet) < 0)
            {
                PLOG_ERROR("Failed to send message to peer (%d).", peer->id());
                return false;
            }

            return true;
        }
    }

    return false;
}
开发者ID:Freedom000,项目名称:FutureInterface,代码行数:29,代码来源:pnetworkserver.cpp


示例19: renet_connection_send_packet

VALUE renet_connection_send_packet(VALUE self, VALUE data, VALUE flag, VALUE channel)
{
  Connection* connection;
  Data_Get_Struct(self, Connection, connection);
  VALUE lock = rb_iv_get(self, "@lock");
  rb_mutex_lock(lock);

  Check_Type(data, T_STRING);
  char* cdata = StringValuePtr(data);
  ENetPacket* packet;
  if (connection->online != 0)
  {
    if (flag == Qtrue)
    {
      packet = enet_packet_create(cdata, RSTRING_LEN(data) + 1, ENET_PACKET_FLAG_RELIABLE);
    }
    else
    {
      packet = enet_packet_create(cdata, RSTRING_LEN(data) + 1, 0);
    }
    enet_peer_send(connection->peer, NUM2UINT(channel), packet);
  }

  rb_mutex_unlock(lock);
  return Qnil;
}
开发者ID:jvranish,项目名称:rENet,代码行数:26,代码来源:renet_connection.c


示例20: sendclientpacket

void sendclientpacket(ENetPacket *packet, int chan, int cn) // INTENSITY: added cn
{
    if(curpeer) enet_peer_send(curpeer, chan, packet);
    else localclienttoserver(chan, packet, cn); // INTENSITY: added cn

    NetworkSystem::Cataloger::packetSent(chan, packet->dataLength); // INTENSITY
}
开发者ID:bartbes,项目名称:CubeCreate,代码行数:7,代码来源:client.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ engEvalString函数代码示例发布时间:2022-05-30
下一篇:
C++ enet_peer_reset函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap