Example #1
0
void Server::run()
{
	sf::Clock stepClock, syncClock;
	sf::Time elapsedStep = sf::Time::Zero, elapsedSync = sf::Time::Zero;
	
	while (true)
	{
		handleNewConnection();
		handleDisconnection();
		handlePackets();


		elapsedStep += stepClock.restart();
		elapsedSync += syncClock.restart();


		while (elapsedStep >= TimeStep)
		{
			elapsedStep -= TimeStep;
			mGame.step(*this);
		}
		while (elapsedSync >= TimeSync)
		{
			elapsedSync -= TimeSync;
			mGame.sync(*this);
		}

	}
}
Example #2
0
void NetworkManager::update(float dt)
{
    ENetEvent event;
    int result = enet_host_service (m_host, &event, 0);

    if(result==0)	//No hay evento
		return;

    if(result<0)	//Error en el Mensaje
    {
        fprintf(stderr, "Error while receiving messages -> ignored.\n");
        return;
    }

	fprintf(stderr, "Event : %d\n", event.type);

    switch (event.type)
    {
		case ENET_EVENT_TYPE_CONNECT:
			//handleNewConnection(&event);
			break;
		case ENET_EVENT_TYPE_RECEIVE:
			handleMessagefromServer(&event);
			break;
		case ENET_EVENT_TYPE_DISCONNECT:
			handleDisconnection(&event);
			break;
		case ENET_EVENT_TYPE_NONE:
			break;
    }
}   // update
void
DBusInputContextConnection::onDisconnection()
{
    const QString &name = connection().name();
    unsigned int connectionNumber = mConnectionNumbers.take(name);
    ComMeegoInputmethodInputcontext1Interface *proxy = mProxys.take(connectionNumber);
    mConnections.remove(connectionNumber);
    delete proxy;
    handleDisconnection(connectionNumber);
}
Example #4
0
void NetMaster::handleConnection()
{
    QTcpSocket * socket = m_server->nextPendingConnection();
    connect(socket, SIGNAL(disconnected()), this, SLOT(handleDisconnection()));
    connect(socket, SIGNAL(readyRead()), this, SLOT(dataReady()));
    m_sockets.append(socket);
    m_connectedClients.appendRow(new QStandardItem(socket->peerAddress().toString()));

    qDebug() << "New connection from" << socket->peerAddress().toString();

    // Send initial packets:
    
    NetPacket("INIT_DONE").writeOut(socket);
}
QT_BEGIN_NAMESPACE

/*!
	Construct the transport object and wrap the given socket.

	The socket is also set as the parent of the transport object.
*/
WebSocketTransport::WebSocketTransport(QWebSocket *socket)
: QWebChannelAbstractTransport(socket)
, m_socket(socket)
{
	connect(socket, &QWebSocket::textMessageReceived,
			this, &WebSocketTransport::textMessageReceived);
	connect(socket, SIGNAL(disconnected()), this, SLOT(handleDisconnection()));
}
Example #6
0
    /**
      * Appelé quand un client se connecte au serveur.
      * Envoie la connexion au serveur si celle-ci
      * n'est pas filtrée
      */
    void ClientHandler::handleIncomming()
    {
        //On recupère le socket server
        QTcpServer *server = qobject_cast<QTcpServer*>(sender());
        //Si ce n'est pas un socket qui a envoyé
        if (server == NULL)
        {
            qDebug() << "ClientHandler::handleIncomming: Erreur, socket serveur incorrect";
            return;
        }
        //On recupère la socket
        QTcpSocket *socket = server->nextPendingConnection();
        //Si la socket n'existe pas, on retourne
        if (socket == NULL)
        {
            return;
        }
        //On indique qu'un client s'est connecté.
        qDebug() << "Nouvelle connexion en provenance de " << socket->peerAddress().toString();
        //Sinon, on procède à des vérifications

        //On vérifie que le nombre maximal de joueurs n'est pas atteint
        if (getClientsOnline() >= _maxPlayers)
        {
            //On affiche un message dans la console
            qDebug() << "Trop de joueurs dans le serveur.";
            //On deconnecte le client
            socket->close();

            return;
        }
        //TODO: Programmer la véfification du client.

        //On connecte le signal pour la deconnexion
        connect(socket,SIGNAL(disconnected()),this,SLOT(handleDisconnection()));
        //On envoie le signal pour dire qu'il y'a un nouveau client
        emit newClient(socket);
    }
Example #7
0
void MainWindow::onConnectTimeout()
{
    handleDisconnection("Connection timed out. Disconnected.");
}
Example #8
0
void MainWindow::onSocketError(QAbstractSocket::SocketError socketError)
{
    handleDisconnection("Socket error! Disconnected.");
    qDebug() << "Socket error:" << socketError;
}
Example #9
0
void MainWindow::onDisconnected(QString jsonMessage)
{
    QString disconnectMessage = ChatHtmlFormatter::formatChatMessageToHtml(jsonMessage);

    handleDisconnection("Disconnected with reason: " + disconnectMessage);
}
Example #10
0
void MainWindow::onDisconnected()
{
    handleDisconnection("Disconnected.");
}