Example #1
0
void GroupClient::stop()
{
    clientConnected = false;
    socket.disconnectFromHost();
    emit scheduleAction(new ResetCharacters());
    deleteLater();
}
Example #2
0
void GroupClient::tryReconnecting()
{
    clientConnected = false;

    if (reconnectAttempts <= 0) {
        emit sendLog("Exhausted reconnect attempts.");
        stop();
        return;
    }
    emit sendLog(QString("Attempting to reconnect... (%1 left)").arg(reconnectAttempts));

    // Retry
    reconnectAttempts--;
    emit scheduleAction(new ResetCharacters());
    socket.connectToHost();
}
Example #3
0
void FrameActionScheduler::scheduleEvent(PassRefPtr<Event> event, PassRefPtr<Node> eventTarget)
{
    scheduleAction(adoptPtr(new EventFrameAction(event, eventTarget)));
}
Example #4
0
void GroupClient::retrieveData(GroupSocket *const /* socket */,
                               const Messages message,
                               const QVariantMap &data)
{
    if (message == Messages::STATE_KICKED) {
        emit messageBox(QString("You got kicked! Reason: %1").arg(data["text"].toString()));
        stop();
        return;
    }
    if (socket.getProtocolState() == ProtocolState::AwaitingLogin) {
        // Login state. either REQ_HANDSHAKE, REQ_LOGIN, or ACK should come
        if (message == Messages::REQ_HANDSHAKE) {
            sendHandshake(data);
        } else if (message == Messages::REQ_LOGIN) {
            assert(!NO_OPEN_SSL);
            socket.setProtocolVersion(proposedProtocolVersion);
            socket.startClientEncrypted();
        } else if (message == Messages::ACK) {
            // aha! logged on!
            sendMessage(&socket, Messages::REQ_INFO);
            socket.setProtocolState(ProtocolState::AwaitingInfo);
        } else {
            // ERROR: unexpected message marker!
            // try to ignore?
            qWarning("(AwaitingLogin) Unexpected message marker. Trying to ignore.");
        }

    } else if (socket.getProtocolState() == ProtocolState::AwaitingInfo) {
        // almost connected. awaiting full information about the connection
        if (message == Messages::UPDATE_CHAR) {
            emit scheduleAction(new AddCharacter(data));
        } else if (message == Messages::STATE_LOGGED) {
            socket.setProtocolState(ProtocolState::Logged);
        } else if (message == Messages::REQ_ACK) {
            sendMessage(&socket, Messages::ACK);
        } else {
            // ERROR: unexpected message marker!
            // try to ignore?
            qWarning("(AwaitingInfo) Unexpected message marker. Trying to ignore.");
        }

    } else if (socket.getProtocolState() == ProtocolState::Logged) {
        if (message == Messages::ADD_CHAR) {
            emit scheduleAction(new AddCharacter(data));
        } else if (message == Messages::REMOVE_CHAR) {
            emit scheduleAction(new RemoveCharacter(data));
        } else if (message == Messages::UPDATE_CHAR) {
            emit scheduleAction(new UpdateCharacter(data));
        } else if (message == Messages::RENAME_CHAR) {
            emit scheduleAction(new RenameCharacter(data));
        } else if (message == Messages::GTELL) {
            emit gTellArrived(data);
        } else if (message == Messages::REQ_ACK) {
            sendMessage(&socket, Messages::ACK);
        } else {
            // ERROR: unexpected message marker!
            // try to ignore?
            qWarning("(Logged) Unexpected message marker. Trying to ignore.");
        }
    }
}
Example #5
0
void PathMachine::approved(const SigParseEvent &sigParseEvent)
{
    ParseEvent &event = sigParseEvent.deref();

    Approved appr(factory, sigParseEvent, params.matchingTolerance);
    const Room *perhaps = nullptr;

    if (event.getMoveType() == CommandIdType::LOOK) {
        emit lookingForRooms(appr, mostLikelyRoom.getId());

    } else {
        tryExits(&mostLikelyRoom, appr, event, true);
    }

    perhaps = appr.oneMatch();

    if (perhaps == nullptr) {
        // try to match by reverse exit
        appr.reset();
        tryExits(&mostLikelyRoom, appr, event, false);
        perhaps = appr.oneMatch();
        if (perhaps == nullptr) {
            // try to match by coordinate
            appr.reset();
            tryCoordinate(&mostLikelyRoom, appr, event);
            perhaps = appr.oneMatch();
            if (perhaps == nullptr) {
                // try to match by coordinate one step below expected
                // FIXME: need stronger type checking here.

                const auto cmd = event.getMoveType();
                // NOTE: This allows ExitDirection::UNKNOWN,
                // which means the coordinate can be Coordinate(0,0,0).
                const Coordinate &eDir = RoomFactory::exitDir(getDirection(cmd));

                // CAUTION: This test seems to mean it wants only NESW,
                // but it would also accept ExitDirection::UNKNOWN,
                // which in the context of this function would mean "no move."
                if (eDir.z == 0) {
                    appr.reset();
                    Coordinate c = mostLikelyRoom.getPosition() + eDir;
                    c.z--;
                    emit lookingForRooms(appr, c);
                    perhaps = appr.oneMatch();

                    if (perhaps == nullptr) {
                        // try to match by coordinate one step above expected
                        appr.reset();
                        c.z += 2;
                        emit lookingForRooms(appr, c);
                        perhaps = appr.oneMatch();
                    }
                }
            }
        }
    }
    if (perhaps != nullptr) {
        // Update the exit from the previous room to the current room
        const CommandIdType move = event.getMoveType();
        if (static_cast<uint32_t>(move) < NUM_EXITS) {
            emit scheduleAction(new AddExit(mostLikelyRoom.getId(),
                                            perhaps->getId(),
                                            static_cast<ExitDirection>(move)));
        }

        // Update most likely room with player's current location
        mostLikelyRoom = *perhaps;

        // Update rooms behind exits now that we are certain about our current location
        const ConnectedRoomFlagsType bFlags = event.getConnectedRoomFlags();
        if (bFlags.isValid()) {
            for (const auto dir : ALL_DIRECTIONS6) {
                const Exit &e = mostLikelyRoom.exit(dir);
                if (!e.outIsUnique()) {
                    continue;
                }
                RoomId connectedRoomId = e.outFirst();
                auto bThisRoom = bFlags.getDirectionalLight(dir);
                if (IS_SET(bThisRoom, DirectionalLightType::DIRECT_SUN_ROOM)) {
                    emit scheduleAction(
                        new SingleRoomAction(new UpdateRoomField(RoomSundeathType::SUNDEATH),
                                             connectedRoomId));
                } else if (IS_SET(bThisRoom, DirectionalLightType::INDIRECT_SUN_ROOM)) {
                    emit scheduleAction(
                        new SingleRoomAction(new UpdateRoomField(RoomSundeathType::NO_SUNDEATH),
                                             connectedRoomId));
                }
            }
        }

        // Update the room if we had a tolerant match rather than an exact match
        if (appr.needsUpdate()) {
            emit scheduleAction(
                new SingleRoomAction(new Update(sigParseEvent), mostLikelyRoom.getId()));
        }

        // Send updates
        emit playerMoved(mostLikelyRoom.getPosition());
        // GroupManager
        emit setCharPosition(mostLikelyRoom.getId());
    } else {
        // couldn't match, give up
        state = PathState::EXPERIMENTING;
        pathRoot = mostLikelyRoom;
        auto *const root = new Path(&pathRoot, nullptr, nullptr, &signaler);
        paths->push_front(root);
        experimenting(sigParseEvent);
    }
}