本文整理汇总了C++中enet_packet_create函数的典型用法代码示例。如果您正苦于以下问题:C++ enet_packet_create函数的具体用法?C++ enet_packet_create怎么用?C++ enet_packet_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enet_packet_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: sendmap
void sendmap(char *mapname)
{
if(*mapname) save_world(mapname);
changemap(mapname);
mapname = getclientmap();
int mapsize;
uchar *mapdata = readmap(mapname, &mapsize);
if(!mapdata) return;
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data;
uchar *p = start+2;
putint(p, SV_SENDMAP);
sendstring(mapname, p);
putint(p, mapsize);
if(65535 - (p - start) < mapsize)
{
conoutf("map %s is too large to send", mapname);
free(mapdata);
enet_packet_destroy(packet);
return;
};
memcpy(p, mapdata, mapsize);
p += mapsize;
free(mapdata);
*(ushort *)start = ENET_HOST_TO_NET_16(p-start);
enet_packet_resize(packet, p-start);
sendpackettoserv(packet);
conoutf("sending map %s to server...", mapname);
sprintf_sd(msg)("[map %s uploaded to server, \"getmap\" to receive it]", mapname);
toserver(msg);
}
示例3: GetDriverName
void NetClient::SendReadyToStartPacket()
{
std::string strDName = GetDriverName();
GfLogTrace("Sending ready to start packet\n");
PackedBuffer msg;
try
{
msg.pack_ubyte(CLIENTREADYTOSTART_PACKET);
msg.pack_stdstring(strDName);
}
// catch (PackedBufferException &e)
catch (PackedBufferException)
{
GfLogFatal("SendReadyToStartPacket: packed buffer error\n");
}
GfLogTrace("SendReadyToStartPacket: packed data length=%d\n",
msg.length());
ENetPacket *pPacket = enet_packet_create (msg.buffer(),
msg.length(),
ENET_PACKET_FLAG_RELIABLE);
if (enet_peer_send (m_pServer, RELIABLECHANNEL, pPacket))
GfLogError("SendReadyToStartPacket : enet_peer_send failed\n");
}
示例4: 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;
}
示例5: enet_packet_create
void Connection::send_packet_unreliable(void *data,int ID){
ENetPacket *packet = enet_packet_create (data, sizeof(data), ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
if(!client)
enet_peer_send (&connS->peers[ID], 0, packet);
else
enet_peer_send(peer,0,packet);
}
示例6: 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);
}
}
示例7: enet_packet_create
void ENetServer::broadcastMessage(DeliveryType type, Message::Shared msg) const
{
if (numClients() == 0) {
// no clients to broadcast to
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_host_broadcast(host_, channel, p);
// flush / send the packet queue
enet_host_flush(host_);
}
示例8: qDebug
void Tunnelc::onENetPeerConnected(ENetHost *enhost, ENetPeer *enpeer, quint32 data)
{
qDebug()<<enhost<<enpeer<<data;
// ToxTunChannel *chan = this->m_enpeer_chans[enpeer];
// ToxTunChannel *chan = (ToxTunChannel*)enpeer->toxchan;
ToxTunChannel *chan = peerLastChan(enpeer);
// enet_peer_ping_interval()
// enet_peer_ping(
enet_peer_timeout(enpeer, UINT32_MAX/*ENET_PEER_TIMEOUT_LIMIT * 0xfffff*/,
UINT32_MAX/*ENET_PEER_TIMEOUT_MINIMUM * 0xffff*/,
UINT32_MAX/*ENET_PEER_TIMEOUT_MAXIMUM * 0xffff*/);
enet_peer_ping_interval(enpeer, UINT32_MAX/*ENET_PEER_PING_INTERVAL * 0xfffff*/);
emit chan->m_sock->readyRead();
if (false) {
ENetPacket *packet = enet_packet_create("hehehe123", 10, ENET_PACKET_FLAG_RELIABLE);
enet_packet_resize(packet, 13);
strcpy((char*)&packet->data[9], "foo");
uint8_t chanid = 0;
// enet_peer_send(enpeer, chanid, packet);
m_enpoll->sendPacket(enpeer, chanid, packet);
}
}
示例9: main
int main (int argc, char * const argv[]) {
if(enet_initialize() != 0)
{
printf("An error occurred while initializing ENet.\n");
}
ENetAddress address;
ENetHost* server;
address.host = ENET_HOST_ANY;
address.port = 9050;
// up to 32 clients with unlimited bandwidth
server = enet_host_create(&address, 32, 0, 0);
if(server == NULL)
{
printf("An error occurred while trying to create an ENet server host.\n");
}
int clients = 0;
// server main loop
while(true)
{
ENetEvent event;
while(enet_host_service(server, &event, 1000) > 0)
{
switch(event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf ("A new client connected from %x:%u.\n",
event.peer -> address.host,
event.peer -> address.port);
clients++;
break;
case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s was received.\n",
event.packet->dataLength,
event.packet->data);
ENetPacket* packet = enet_packet_create(event.packet->data, event.packet->dataLength, ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(server, 0, packet);
enet_host_flush(server);
enet_packet_destroy(event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf("Client disconnected.\n");
event.peer->data = NULL;
}
}
}
return 0;
}
示例10: sizeof
void NetManager::sendServerPacket()
{
FAWorld::World& world = *FAWorld::World::get();
size_t bytesPerClient = world.getCurrentPlayer()->getSize() + sizeof(uint32_t); // the uint is for player id
size_t packetSize = sizeof(ServerPacketHeader) + bytesPerClient*(mClients.size() +1); // +1 for the local player
ENetPacket* packet = enet_packet_create(NULL, packetSize, 0);
size_t position = 0;
// write header
ServerPacketHeader header;
header.numPlayers = mClients.size() + 1;
header.tick = mTick;
writeToPacket(packet, position, header);
// write server player
writeToPacket<uint32_t>(packet, position, SERVER_PLAYER_ID);
position = world.getCurrentPlayer()->writeTo(packet, position);
// write all clients
for(size_t i = 0; i < mClients.size(); i++)
{
writeToPacket<uint32_t>(packet, position, mClients[i]->connectID);
position = world.getPlayer(mClients[i]->connectID)->writeTo(packet, position);
}
enet_host_broadcast(mHost, 0, packet);
}
示例11: enet_packet_create
void CNetManager::sendOutPacket(SOutPacket& outpacket)
{
ENetPacket* packet = enet_packet_create((char*)outpacket.getData(), outpacket.getSize(),
ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(host, 0, packet);
}
示例12: send_welcome
void send_welcome(int n) {
ENetPacket * packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data;
uchar *p = start + 2;
putint(p, SV_INITS2C);
putint(p, n);
putint(p, PROTOCOL_VERSION);
putint(p, smapname[0]);
sendIString(serverpassword, p);
putint(p, clients.size() > maxclients);
if (smapname[0]) {
putint(p, SV_MAPCHANGE);
sendIString(smapname, p);
putint(p, mode);
putint(p, SV_ITEMLIST);
for (int i = 0; i < sents.size(); i++) {
if (sents[i].spawned)
putint(p, i);
}
putint(p, -1);
};
*(ushort *) start = ENET_HOST_TO_NET_16(p - start);
enet_packet_resize(packet, p - start);
send(n, packet);
}
示例13: 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;
}
示例14: ThreadSend
void* ThreadSend() {
while(1) {
CCLOG("wait mutex to send");
mutexMapPlay.lock();
// pthread_mutex_lock(&mutexMapPlay);
mapLayerToString(playLayer, packetBuffer);
// strcpy(packetBuffer, "0000000030000003000000000000000000000010000000000\1");
ENetPacket * packet = enet_packet_create (packetBuffer,
150,
ENET_PACKET_FLAG_RELIABLE);
CCLOG(packet->data);
/* Send the packet to the peer over channel id 0. */
/* One could also broadcast the packet by */
/* enet_host_broadcast (host, 0, packet); */
enet_peer_send (peer, 0, packet);
/* One could just use enet_host_service() instead. */
enet_host_flush (server);
CCLOG("finish send packet");
}
enet_peer_disconnect (peer, 0);
enet_peer_reset (peer);
CCLOG("exit thread send");
return NULL;
}
示例15: qDebug
void Tunneld::onTcpDisconnected()
{
qDebug()<<""<<enet_host_used_peer_size(m_ensrv)<<m_sock_chans.count()<<m_conid_chans.count();
QTcpSocket *sock = (QTcpSocket*)(sender());
ToxTunChannel *chan = this->m_sock_chans[sock];
// qDebug()<<chan<<chan->m_enpeer->state;
chan->sock_closed = true;
chan->sock_close_time = QDateTime::currentDateTime();
// 防止对方没有收完,暂时还不能关闭连接。
// enet_peer_disconnect_later(chan->m_enpeer, qrand());
if (true) {
QByteArray ba = "SRVFIN";
ENetPacket *packet = enet_packet_create(ba.data(), ba.length(), ENET_PACKET_FLAG_RELIABLE);
// enet_packet_resize(packet, 13);
// strcpy((char*)&packet->data[9], "foo");
uint8_t chanid = 1;
ENetPeer *enpeer = chan->m_enpeer;
// enet_peer_send(enpeer, chanid, packet);
m_enpoll->sendPacket(enpeer, chanid, packet);
}
this->promiseChannelCleanup(chan);
}