Exemple #1
0
bool Parser::isEndOfRoomDescription(QString& str) {

	if (Patterns::matchExitsPatterns(str)) {
		parseExits(str);
		return true;
	}
	return false;
}
void MMapperPluginParser::exits(QString text) {
  m_descriptionReady = true;

  if (text.isEmpty()) {
    if (!queue.isEmpty())
      if (queue.head() == CID_SCOUT)
	return ;
    emulateExits();
  }
  else {
    parseExits(text);
  }
}
Exemple #3
0
bool MumeXmlParser::element(const QByteArray &line)
{
    const int length = line.length();
    const XmlMode lastMode = m_xmlMode;

    switch (m_xmlMode) {
    case XmlMode::NONE:
        if (length > 0) {
            switch (line.at(0)) {
            case '/':
                if (line.startsWith("/xml")) {
                    sendToUser("[MMapper] Mapper cannot function without XML mode\n");
                    queue.clear();
                }
                break;
            case 'p':
                if (line.startsWith("prompt")) {
                    m_xmlMode = XmlMode::PROMPT;
                }
                break;
            case 'e':
                if (line.startsWith("exits")) {
                    m_exits = nullString; // Reset string since payload can be from the 'exit' command
                    m_xmlMode = XmlMode::EXITS;
                }
                break;
            case 'r':
                if (line.startsWith("room")) {
                    m_xmlMode = XmlMode::ROOM;
                    m_roomName = emptyString; // 'name' tag will not show up when blinded
                    m_descriptionReady = false;
                    m_dynamicRoomDesc = nullString;
                    m_staticRoomDesc = nullString;
                    m_exits = nullString;
                    m_exitsFlags.reset();
                    m_connectedRoomFlags.reset();
                }
                break;
            case 'm':
                if (length > 8) {
                    switch (line.at(8)) {
                    case ' ':
                        if (length > 13) {
                            switch (line.at(13)) {
                            case 'n':
                                m_move = CommandIdType::NORTH;
                                break;
                            case 's':
                                m_move = CommandIdType::SOUTH;
                                break;
                            case 'e':
                                m_move = CommandIdType::EAST;
                                break;
                            case 'w':
                                m_move = CommandIdType::WEST;
                                break;
                            case 'u':
                                m_move = CommandIdType::UP;
                                break;
                            case 'd':
                                m_move = CommandIdType::DOWN;
                                break;
                            };
                        }
                        break;
                    case '/':
                        m_move = CommandIdType::NONE;
                        break;
                    }
                };
                break;
            case 'w':
                if (line.startsWith("weather")) {
                    m_readWeatherTag = true;
                }
                break;
            case 's':
                if (line.startsWith("status")) {
                    m_readStatusTag = true;
                    m_xmlMode = XmlMode::NONE;
                } else if (line.startsWith("snoop")) {
                    m_readSnoopTag = true;
                }
                break;
            }
        };
        break;

    case XmlMode::ROOM:
        if (length > 0) {
            switch (line.at(0)) {
            case 'g':
                if (line.startsWith("gratuitous") && getConfig().parser.removeXmlTags) {
                    m_gratuitous = true;
                }
                break;
            case 'n':
                if (line.startsWith("name")) {
                    m_xmlMode = XmlMode::NAME;
                }
                break;
            case 'd':
                if (line.startsWith("description")) {
                    m_xmlMode = XmlMode::DESCRIPTION;
                    m_staticRoomDesc = emptyString; // might be empty but valid description
                }
                break;
            case 't': // terrain tag only comes up in blindness or fog
                if (line.startsWith("terrain")) {
                    m_xmlMode = XmlMode::TERRAIN;
                }
                break;

            case '/':
                if (line.startsWith("/room")) {
                    m_xmlMode = XmlMode::NONE;
                } else if (line.startsWith("/gratuitous")) {
                    m_gratuitous = false;
                }
                break;
            }
        }
        break;
    case XmlMode::NAME:
        if (line.startsWith("/name")) {
            m_xmlMode = XmlMode::ROOM;
        }
        break;
    case XmlMode::DESCRIPTION:
        if (length > 0) {
            switch (line.at(0)) {
            case '/':
                if (line.startsWith("/description")) {
                    m_xmlMode = XmlMode::ROOM;
                }
                break;
            }
        }
        break;
    case XmlMode::EXITS:
        if (length > 0) {
            switch (line.at(0)) {
            case '/':
                if (line.startsWith("/exits")) {
                    parseExits();
                    m_xmlMode = XmlMode::NONE;
                }
                break;
            }
        }
        break;
    case XmlMode::PROMPT:
        if (length > 0) {
            switch (line.at(0)) {
            case '/':
                if (line.startsWith("/prompt")) {
                    m_xmlMode = XmlMode::NONE;
                    m_overrideSendPrompt = false;
                }
                break;
            }
        }
        break;
    case XmlMode::TERRAIN:
        if (length > 0) {
            switch (line.at(0)) {
            case '/':
                if (line.startsWith("/terrain")) {
                    m_xmlMode = XmlMode::ROOM;
                    m_readingRoomDesc = true;
                }
                break;
            }
        }
        break;
    }

    if (!getConfig().parser.removeXmlTags) {
        m_lineToUser.append(lessThanChar).append(line).append(greaterThanChar);
    }

    if (lastMode == XmlMode::PROMPT) {
        // Store prompts in case an internal command is executed
        m_lastPrompt = m_lineToUser;
    }

    return true;
}