コード例 #1
0
ファイル: server.cpp プロジェクト: GuillaumeSeren/Cockatrice
void Server::removeClient(Server_ProtocolHandler *client)
{
    QWriteLocker locker(&clientsLock);
    clients.removeAt(clients.indexOf(client));
    ServerInfo_User *data = client->getUserInfo();
    if (data) {
        Event_UserLeft event;
        event.set_name(data->name());
        SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
        for (int i = 0; i < clients.size(); ++i)
            if (clients[i]->getAcceptsUserListChanges())
                clients[i]->sendProtocolItem(*se);
        sendIsl_SessionEvent(*se);
        delete se;

        users.remove(QString::fromStdString(data->name()));
        qDebug() << "Server::removeClient: name=" << QString::fromStdString(data->name());

        if (data->has_session_id()) {
            const qint64 sessionId = data->session_id();
            usersBySessionId.remove(sessionId);
            emit endSession(sessionId);
            qDebug() << "closed session id:" << sessionId;
        }
    }
    qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left";
}
コード例 #2
0
ファイル: server.cpp プロジェクト: GuillaumeSeren/Cockatrice
void Server::externalUserLeft(const QString &userName)
{
    // This function is always called from the main thread via signal/slot.

    clientsLock.lockForWrite();
    Server_AbstractUserInterface *user = externalUsers.take(userName);
    externalUsersBySessionId.remove(user->getUserInfo()->session_id());
    clientsLock.unlock();

    QMap<int, QPair<int, int> > userGames(user->getGames());
    QMapIterator<int, QPair<int, int> > userGamesIterator(userGames);
    roomsLock.lockForRead();
    while (userGamesIterator.hasNext()) {
        userGamesIterator.next();
        Server_Room *room = rooms.value(userGamesIterator.value().first);
        if (!room)
            continue;

        QReadLocker roomGamesLocker(&room->gamesLock);
        Server_Game *game = room->getGames().value(userGamesIterator.key());
        if (!game)
            continue;

        QMutexLocker gameLocker(&game->gameMutex);
        Server_Player *player = game->getPlayers().value(userGamesIterator.value().second);
        if (!player)
            continue;

        player->disconnectClient();
    }
    roomsLock.unlock();

    delete user;

    Event_UserLeft event;
    event.set_name(userName.toStdString());

    SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
    clientsLock.lockForRead();
    for (int i = 0; i < clients.size(); ++i)
        if (clients[i]->getAcceptsUserListChanges())
            clients[i]->sendProtocolItem(*se);
    clientsLock.unlock();
    delete se;
}
コード例 #3
0
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
{
    QString userName = QString::fromStdString(event.name());

    if (buddyList->getUsers().keys().contains(userName))
        soundEngine->playSound("buddy_leave");

    if (allUsersList->deleteUser(userName)) {
        ignoreList->setUserOnline(userName, false);
        buddyList->setUserOnline(userName, false);
        ignoreList->sortItems();
        buddyList->sortItems();

        emit userLeft(userName);
    }
}
コード例 #4
0
void IslInterface::sessionEvent_UserLeft(const Event_UserLeft &event)
{
	emit externalUserLeft(QString::fromStdString(event.name()));
}