Beispiel #1
0
/**
	Destroy an ENetPeer structure.
**/
static void destroy_enetpeer( value p ) {
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enetpeer\n");
	exit(0);
#endif
return;
	ENetPeer *peer;
	if(!val_is_abstract(p) || !val_is_kind(p, k_udprpeer))
		return;
	peer = (ENetPeer *)val_data(p);
	if(peer == NULL)
		return;

	// force immediate disconnect, if still connected.
	enet_peer_disconnect_now(peer, 0);

	// if the peer has an event still, destroy it
	//free_peer_event(peer);

	// clear the peer structure
	enet_peer_reset(peer);

	// peers never need be deallocated, they are part of an ENetHost
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enetpeer done.\n");
#endif
	return;
}
void NetworkedMultiplayerENet::close_connection() {

	if (!active)
		return;

	_pop_current_packet();

	bool peers_disconnected=false;
	for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
		if (E->get()) {
			enet_peer_disconnect_now(E->get(),unique_id);
			peers_disconnected=true;
		}
	}

	if (peers_disconnected) {
		enet_host_flush(host);
		OS::get_singleton()->delay_usec(100); //wait 100ms for disconnection packets to send

	}

	enet_host_destroy(host);
	active=false;
	incoming_packets.clear();
	unique_id=1; //server is 1
	connection_status=CONNECTION_DISCONNECTED;
}
Beispiel #3
0
/**
	Destroy an allocated ENetHost pointer. Must be used with val_gc() for every ENetHost created.
*/
static void destroy_enethost( value h ) {
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enethost\n");
	//exit(0);
#endif
//return;
	if(!val_is_kind(h, k_udprhost))
		return;
	ENetHost *host = (ENetHost *)val_data(h);
	ENetPeer *peer;
	//int x, count;
	if(host == NULL)
		return;
	enet_host_flush( host );
	for (peer = host->peers;
         peer < &host->peers[host->peerCount];
         ++peer)
    {
    	if (peer->state == ENET_PEER_STATE_CONNECTED) {
    		enet_peer_disconnect_now(peer, 0);
    	}
    }

#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enethost\n");
#endif
	enet_host_destroy( host );
	//val_kind(v) = NULL;
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enethost done.\n");
#endif
	return;
}
Beispiel #4
0
static value udpr_close_now(value p)
{
	// in order to avoid this, the library would have to queue events
	// and handle them in select() and add to them in udpr_close()
	val_check_kind(p,k_udprpeer);
    enet_peer_disconnect_now((ENetPeer *)val_data(p), 0);
    return val_true;
}
Beispiel #5
0
		void CNetManager::kickClient(const u16 playerId, bool hardKick = false)
		{
			ENetPeer* currentPeer = getPlayerById(playerId);

			if(currentPeer)
				hardKick ?	enet_peer_disconnect_now(currentPeer,0) :
							enet_peer_disconnect(currentPeer,0);
		}
Beispiel #6
0
void Network::finalize(Client & client)
{
	if(m_server)
		enet_peer_disconnect_now(m_server, 0);
	if(m_client)
		enet_host_destroy(m_client);
	enet_socket_destroy(m_socket);
	enet_deinitialize();
}
Beispiel #7
0
void GameLabyrinth::Client::disconenct()
{
    if (peer != NULL)
    {
        log_msg("net", "Disconnecting client " + getNetworkName());
        enet_peer_disconnect_now(peer, 0);
        state = DISCONNECTED;
        peer->data = NULL;
        peer = NULL;
    }
}
Beispiel #8
0
VALUE renet_server_disconnect_client(VALUE self, VALUE peer_id)
{
    Server* server;
    Data_Get_Struct(self, Server, server);
    VALUE lock = rb_iv_get(self, "@lock");
    rb_mutex_lock(lock);
    enet_peer_disconnect_now(&(server->host->peers[NUM2UINT(peer_id)]), 0);
    renet_server_execute_on_disconnection(self, peer_id);
    rb_mutex_unlock(lock);
    return Qtrue;
}
Beispiel #9
0
void CNetClientSession::Disconnect(u32 reason)
{
	ENSURE(m_Host && m_Server);

	// TODO: ought to do reliable async disconnects, probably
	enet_peer_disconnect_now(m_Server, reason);
	enet_host_destroy(m_Host);

	m_Host = NULL;
	m_Server = NULL;

	SAFE_DELETE(m_Stats);
}
Beispiel #10
0
CNetClientSession::~CNetClientSession()
{
	delete m_Stats;

	if (m_Host && m_Server)
	{
		// Disconnect immediately (we can't wait for acks)
		enet_peer_disconnect_now(m_Server, NDR_SERVER_SHUTDOWN);
		enet_host_destroy(m_Host);

		m_Host = NULL;
		m_Server = NULL;
	}
}
Beispiel #11
0
Host::~Host()
{
  for (auto& p : m_peers)
    enet_peer_disconnect_now((ENetPeer*) p.m_peer, 0);

  m_peers.clear();

  if (m_object)
  {
    enet_host_flush((ENetHost*) m_object);
    enet_host_destroy((ENetHost*) m_object);
    m_object = nullptr;
  }
}
Beispiel #12
0
/**
 *  Destroy the host and all connected peers.
 */
void host_destroy (void)
{
        int i = 0;

        /* deallocate all peers */
        for (i = 0; i < host->peerCount; i++) {
                if (host->peers[i].state == ENET_PEER_STATE_CONNECTED) {
                        if (host->peerCount > 1)
                                free(host->peers[i].data);
                        enet_peer_disconnect_now(&host->peers[i], 0);
                }
        }

        /* deallocate the host */
        enet_host_destroy(host);
}
void PNetworkServer::shutdown()
{
    if (m_state == NETWORK_CONNECTED ||
        m_state == NETWORK_ERROR)
    {
        PMap<puint32, PNetworkPeer*>::iterator it = m_peers.begin();
        PMap<puint32, PNetworkPeer*>::iterator ie = m_peers.end();
        while (it != ie)
        {
            enet_peer_disconnect_now(it.value()->data()->peer, it.key());
            PDELETE(it.value());
            ++it;
        }

        enet_host_destroy(m_data->server);

        m_state = NETWORK_DISCONNECTED;
    }
}
Beispiel #14
0
VALUE renet_connection_disconnect(VALUE self, VALUE timeout)
{
  Connection* connection;
  Data_Get_Struct(self, Connection, connection);
  VALUE lock = rb_iv_get(self, "@lock");
  rb_mutex_lock(lock);

  VALUE rv = Qfalse;

  if (connection->online == 0)
  {
    rv = Qtrue;
  }
  else
  {      
    connection->online = 0;
    enet_peer_disconnect(connection->peer, 0);

    while (service(self, connection, NUM2UINT(timeout)) > 0)
    {
      switch (connection->event->type)
      {
      case ENET_EVENT_TYPE_NONE:
        break;
      case ENET_EVENT_TYPE_CONNECT:
        break;
      case ENET_EVENT_TYPE_RECEIVE:
        enet_packet_destroy (connection->event->packet);
        break;
      case ENET_EVENT_TYPE_DISCONNECT:
        rv = Qtrue;
        break;
      }
      if (rv == Qtrue)
      {
        break;
      }
    }
    if (rv != Qtrue) { enet_peer_disconnect_now(connection->peer, 0); }
  }
  rb_mutex_unlock(lock);
  return rv;
}
Beispiel #15
0
int enet_lua_api enet_lua_peer_disconnect_now(lua_State* L) {
    ENetPeer** udata = luaL_checkudata(L, 1, "_enet.peer");
    enet_peer_disconnect_now(*udata, 0);
    return 0;
}
Beispiel #16
0
 void IncomingClientBase::disconnect(void)
 {
     enet_peer_disconnect_now(mInternalClient, 0);
 }
Beispiel #17
0
	void ServerClient::disconnect()
	{
		enet_peer_disconnect_now (m_peer, 0);
	}
Beispiel #18
0
void CNetServerSession::DisconnectNow(u32 reason)
{
	enet_peer_disconnect_now(m_Peer, reason);
}