void TabDeckStorage::actDownload()
{
    QString filePath;
    QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
    if (!curLeft.isValid())
        filePath = localDirModel->rootPath();
    else {
        while (!localDirModel->isDir(curLeft))
            curLeft = curLeft.parent();
        filePath = localDirModel->filePath(curLeft);
    }

    RemoteDeckList_TreeModel::FileNode *curRight = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
    if (!curRight)
        return;
    filePath += QString("/deck_%1.cod").arg(curRight->getId());
    
    Command_DeckDownload cmd;
    cmd.set_deck_id(curRight->getId());
    
    PendingCommand *pend = client->prepareSessionCommand(cmd);
    pend->setExtraData(filePath);
    connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(downloadFinished(Response, CommandContainer, QVariant)));
    client->sendCommand(pend);
}
Esempio n. 2
0
void TabReplays::actDownload()
{
    QString filePath;
    QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
    if (!curLeft.isValid())
        filePath = localDirModel->rootPath();
    else {
        while (!localDirModel->isDir(curLeft))
            curLeft = curLeft.parent();
        filePath = localDirModel->filePath(curLeft);
    }

    ServerInfo_Replay const *curRight = serverDirView->getCurrentReplay();
    if (!curRight)
        return;
    filePath += QString("/replay_%1.cor").arg(curRight->replay_id());
    
    Command_ReplayDownload cmd;
    cmd.set_replay_id(curRight->replay_id());
    
    PendingCommand *pend = client->prepareSessionCommand(cmd);
    pend->setExtraData(filePath);
    connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(downloadFinished(Response, CommandContainer, QVariant)));
    client->sendCommand(pend);
}
Esempio n. 3
0
void RoomSelector::joinRoom(int id, bool setCurrent)
{
    Command_JoinRoom cmd;
    cmd.set_room_id(id);

    PendingCommand *pend = client->prepareSessionCommand(cmd);
    pend->setExtraData(setCurrent);
    connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(joinFinished(Response, CommandContainer, QVariant)));

    client->sendCommand(pend);
}
Esempio n. 4
0
void AbstractClient::processProtocolItem(const ServerMessage &item)
{
    switch (item.message_type()) {
        case ServerMessage::RESPONSE: {
            const Response &response = item.response();
            const int cmdId = response.cmd_id();
            
            PendingCommand *pend = pendingCommands.value(cmdId, 0);
            if (!pend)
                return;
            pendingCommands.remove(cmdId);
            
            pend->processResponse(response);
            pend->deleteLater();
            break;
        }
        case ServerMessage::SESSION_EVENT: {
            const SessionEvent &event = item.session_event();
            switch ((SessionEvent::SessionEventType) getPbExtension(event)) {
                case SessionEvent::SERVER_IDENTIFICATION: emit serverIdentificationEventReceived(event.GetExtension(Event_ServerIdentification::ext)); break;
                case SessionEvent::SERVER_MESSAGE: emit serverMessageEventReceived(event.GetExtension(Event_ServerMessage::ext)); break;
                case SessionEvent::SERVER_SHUTDOWN: emit serverShutdownEventReceived(event.GetExtension(Event_ServerShutdown::ext)); break;
                case SessionEvent::CONNECTION_CLOSED: emit connectionClosedEventReceived(event.GetExtension(Event_ConnectionClosed::ext)); break;
                case SessionEvent::USER_MESSAGE: emit userMessageEventReceived(event.GetExtension(Event_UserMessage::ext)); break;
                case SessionEvent::NOTIFY_USER: emit notifyUserEventReceived(event.GetExtension(Event_NotifyUser::ext)); break;
                case SessionEvent::LIST_ROOMS: emit listRoomsEventReceived(event.GetExtension(Event_ListRooms::ext)); break;
                case SessionEvent::ADD_TO_LIST: emit addToListEventReceived(event.GetExtension(Event_AddToList::ext)); break;
                case SessionEvent::REMOVE_FROM_LIST: emit removeFromListEventReceived(event.GetExtension(Event_RemoveFromList::ext)); break;
                case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break;
                case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break;
                case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break;
                case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break;
                default: break;
            }
            break;
        }
        case ServerMessage::GAME_EVENT_CONTAINER: {
            emit gameEventContainerReceived(item.game_event_container());
            break;
        }
        case ServerMessage::ROOM_EVENT: {
            emit roomEventReceived(item.room_event());
            break;
        }
    }
}
Esempio n. 5
0
void TabServer::joinRoom(int id, bool setCurrent)
{
    TabRoom *room = tabSupervisor->getRoomTabs().value(id);
    if(!room)
    {
        Command_JoinRoom cmd;
        cmd.set_room_id(id);
        
        PendingCommand *pend = client->prepareSessionCommand(cmd);
        pend->setExtraData(setCurrent);
        connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(joinRoomFinished(Response, CommandContainer, QVariant)));
        
        client->sendCommand(pend);

        return;   
    }

    if(setCurrent)
        tabSupervisor->setCurrentWidget((QWidget*)room);
}
Esempio n. 6
0
void RemoteClient::ping()
{
    QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
    while (i.hasNext()) {
        PendingCommand *pend = i.next().value();
        if (pend->tick() > maxTimeout) {
            i.remove();
            pend->deleteLater();
        }
    }

    int maxTime = timeRunning - lastDataReceived;
    emit maxPingTime(maxTime, maxTimeout);
    if (maxTime >= maxTimeout) {
        disconnectFromServer();
        emit serverTimeout();
    } else {
        sendCommand(prepareSessionCommand(Command_Ping()));
        ++timeRunning;
    }
}