void RoomPropertySetter::parseProperty(const QByteArray &command, const Coordinate &roomPos) { QList<QByteArray> words = command.simplified().split(' '); AbstractAction *action = 0; QByteArray property = words[1]; uint pos = propPositions[property]; if (words.size() == 4) { //change exit property ExitDirection dir = Mmapper2Exit::dirForChar(words[2][0]); switch (pos) { case E_FLAGS: case E_DOORFLAGS: action = new ModifyExitFlags(fieldValues[property], dir, pos, FMM_TOGGLE); break; case E_DOORNAME: action = new UpdateExitField(property, dir, pos); break; default: emit sendToUser("unknown property: " + property + "\r\n"); return; } } else if (words.size() == 3) { //change room property switch (pos) { case R_TERRAINTYPE: action = new UpdatePartial(fieldValues[property], pos); break; case R_NAME: case R_DESC: action = new UpdatePartial(property, pos); break; case R_MOBFLAGS: case R_LOADFLAGS: action = new ModifyRoomFlags(fieldValues[property], pos, FMM_TOGGLE); break; case R_DYNAMICDESC: case R_NOTE: action = new UpdateRoomField(property, pos); break; case R_PORTABLETYPE: case R_LIGHTTYPE: case R_ALIGNTYPE: case R_RIDABLETYPE: action = new UpdateRoomField(fieldValues[property], pos); break; default: emit sendToUser("unknown property: " + property + "\r\n"); return; } RoomPropertySetterSlave slave(action); emit lookingForRooms(&slave, roomPos); if (slave.getResult()) { emit sendToUser("OK\r\n"); } else { emit sendToUser("setting " + property + " failed!\r\n"); } } }
void AbstractParser::parseGroupTell(const StringView &view) { if (view.isEmpty()) sendToUser("What do you want to tell the group?\r\n"); else { emit sendGroupTellEvent(view.toQByteArray()); sendToUser("OK.\r\n"); } }
void AbstractParser::parseGroupKick(const StringView &view) { if (view.isEmpty()) sendToUser("Who do you want to kick from the group?\r\n"); else { // REVISIT: We should change GroupManager to be a "FrontEnd" in this // thread and call it directly emit sendGroupKickEvent(view.toQByteArray().simplified()); sendToUser("OK.\r\n"); } }
void MessageServer::sendToAll( string mes ){ map<int, string>::iterator it = users.begin(); while( it != users.end() ){ sendToUser( (*it).first, mes ); ++it; } }
void AbstractParser::parseSpecialCommand(StringView wholeCommand) { if (wholeCommand.isEmpty()) throw std::runtime_error("input is empty"); if (evalSpecialCommandMap(wholeCommand)) return; const auto word = wholeCommand.takeFirstWord(); sendToUser(QString("Unrecognized command: %1\r\n").arg(word.toQString())); }
void Users::send(User *u, const char *fmt, ...){ char buf[MAXLEN]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); sendToUser(u,buf); printf("sent '%s' to user '%s'\n",buf,u->name); }
void Frame::OnUserSelect(wxCommandEvent& event) { if(userListCtrl->GetSelection() == wxNOT_FOUND) return; user_t* usr = getUser(userListCtrl->GetStringSelection().c_str()); if(!usr) return; useKeyCtrl->SetValue(usr->encrypt == '1'); keyCtrl->SetValue(usr->encryptKey); sendToUser(usr->userName); }
void AbstractParser::parseSetCommand(StringView view) { if (view.isEmpty()) { sendToUser(QString("Syntax: %1set prefix [punct-char]\r\n").arg(prefixChar)); return; } auto first = view.takeFirstWord(); if (Abbrev{"prefix", 3}.matches(first)) { if (view.isEmpty()) { showCommandPrefix(); return; } auto next = view.takeFirstWord(); if (next.size() == 3) { auto quote = next.takeFirstLetter(); const bool validQuote = quote == '\'' || quote == '"'; const auto prefix = next.takeFirstLetter().toLatin1(); if (validQuote && isValidPrefix(prefix) && quote == next.takeFirstLetter() && quote != prefix && setCommandPrefix(prefix)) { return; } } else if (next.size() == 1) { const auto prefix = next.takeFirstLetter().toLatin1(); if (setCommandPrefix(prefix)) { return; } } sendToUser("Invalid prefix.\r\n"); return; } sendToUser("That variable is not supported."); }
void Users::send(const char *fmt, ...){ char buf[MAXLEN]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); User *u; for( iterator i = begin(); i != end(); i++ ){ u = *i; if (sendToUser(u,buf) == false){ i = erase(i); } } printf("sent '%s' to all clients\n",buf); }
bool AbstractParser::parseUserCommands(const QString &input) { if (tryParseGenericDoorCommand(input)) return false; if (input.startsWith(prefixChar)) { auto view = StringView{input}.trim(); if (view.isEmpty() || view.takeFirstLetter() != prefixChar) sendToUser("Internal error. Sorry.\r\n"); else parseSpecialCommand(view); sendPromptToUser(); return false; } return parseSimpleCommand(input); }
void Client::slotSendToServer() { bool toUser = false; _gui->isSentToUser(toUser); if (!toUser) { sendToUser(); return; } QByteArray arrBlock; QDataStream out(&arrBlock, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_8); out << quint16(0) << _action_MessageToAll << _gui->getMessage(); out.device()->seek(0); out << quint16(arrBlock.size() - sizeof(quint16)); _socket->write(arrBlock); _gui->cleanInputArea(); }
bool AbstractParser::parsePrint(StringView &input) { const auto syntax = [this]() { sendToUser("Print what? [dynamic | static | note]\r\n"); }; if (input.isEmpty()) { syntax(); return true; } const auto next = input.takeFirstWord(); if (Abbrev{"dynamic", 1}.matches(next)) { printRoomInfo(dynamicRoomFields); return true; } else if (Abbrev{"static", 1}.matches(next)) { printRoomInfo(staticRoomFields); return true; } else if (Abbrev{"note", 1}.matches(next)) { showNote(); return true; } else { syntax(); return true; } }
void AbstractParser::initSpecialCommandMap() { auto &map = m_specialCommandMap; map.clear(); auto add = [this](Abbrev abb, const ParserCallback &callback, const HelpCallback &help) { addSpecialCommand(abb.getCommand(), abb.getMinAbbrev(), callback, help); }; const auto makeSimpleHelp = [this](const std::string &help) { return [this, help](const std::string &name) { sendToUser(QString("Help for %1%2:\r\n %3\r\n\r\n") .arg(prefixChar) .arg(QString::fromStdString(name)) .arg(QString::fromStdString(help))); }; }; qInfo() << "Adding special commands to the map..."; // help is important, so it comes first add(cmdHelp, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseHelp(rest); return true; }, // TODO: create a parse tree, and show all of the help topics. makeSimpleHelp("Provides help.")); add(cmdMapHelp, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->showMapHelp(); return true; }, makeSimpleHelp("Help for mapping console commands.")); add(cmdDoorHelp, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->showDoorCommandHelp(); return true; }, makeSimpleHelp("Help for door console commands.")); add(cmdGroupHelp, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->showGroupHelp(); return true; }, makeSimpleHelp("Help for group manager console commands.")); // door actions for (const DoorActionType x : ALL_DOOR_ACTION_TYPES) { if (auto cmd = getParserCommandName(x)) add(cmd, [this, x](const std::vector<StringView> & /*s*/, StringView rest) { return parseDoorAction(x, rest); }, makeSimpleHelp("Sets door action: " + std::string{cmd.getCommand()})); } for (const DoorFlag x : ALL_DOOR_FLAGS) { if (auto cmd = getParserCommandName(x)) add(getParserCommandName(x), [this, x](const std::vector<StringView> & /*s*/, StringView rest) { return parseDoorFlag(x, rest); }, makeSimpleHelp("Sets door flag: " + std::string{cmd.getCommand()})); } for (const ExitFlag x : ALL_EXIT_FLAGS) { if (auto cmd = getParserCommandName(x)) add(cmd, [this, x](const std::vector<StringView> & /*s*/, StringView rest) { return parseExitFlag(x, rest); }, makeSimpleHelp("Sets exit flag: " + std::string{cmd.getCommand()})); } #define ADD_FIELD_CMDS(X) \ do { \ for (const auto x : DEFINED_ROOM_##X##_TYPES) { \ if (auto cmd = getParserCommandName(x)) { \ auto type = RoomField::X##_TYPE; \ add(cmd, \ [this, x, type](const std::vector<StringView> & /*s*/, StringView rest) { \ if (!rest.isEmpty()) \ return false; \ setRoomFieldCommand(x, type); \ return true; \ }, \ makeSimpleHelp("Sets " #X " flag: " + std::string{cmd.getCommand()})); \ } \ } \ } while (false) ADD_FIELD_CMDS(LIGHT); ADD_FIELD_CMDS(SUNDEATH); ADD_FIELD_CMDS(PORTABLE); ADD_FIELD_CMDS(RIDABLE); ADD_FIELD_CMDS(ALIGN); #undef ADD_FIELD_CMDS for (const RoomMobFlag x : ALL_MOB_FLAGS) { if (auto cmd = getParserCommandName(x)) { add(cmd, [this, x](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; toggleRoomFlagCommand(x, RoomField::MOB_FLAGS); return true; }, makeSimpleHelp("Sets room mob flag: " + std::string{cmd.getCommand()})); } } for (const RoomLoadFlag x : ALL_LOAD_FLAGS) { if (auto cmd = getParserCommandName(x)) add(cmd, [this, x](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; toggleRoomFlagCommand(x, RoomField::LOAD_FLAGS); return true; }, makeSimpleHelp("Sets room load flag: " + std::string{cmd.getCommand()})); } // misc commands add(cmdBack, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->doBackCommand(); return true; }, makeSimpleHelp("Delete prespammed commands from queue.")); add(cmdDirections, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseDirections(rest); return true; }, makeSimpleHelp("Prints directions to matching rooms.")); add(cmdGroupKick, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseGroupKick(rest); return true; }, makeSimpleHelp("Kick [player] from the group.")); add(cmdGroupLock, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->doGroupLockCommand(); return true; }, makeSimpleHelp("Toggle the lock on the group.")); add(cmdGroupTell, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseGroupTell(rest); return true; }, makeSimpleHelp("Send a grouptell with the [message].")); add(cmdMarkCurrent, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->doMarkCurrentCommand(); return true; }, makeSimpleHelp("Highlight the room you are currently in.")); add(cmdName, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseName(rest); return true; }, makeSimpleHelp( "Arguments: <dir> <name>; Sets the name of door in direction <dir> with <name>.")); add(cmdNote, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseNoteCmd(rest); return true; }, makeSimpleHelp("Sets the note for the current room.")); add(cmdRemoveDoorNames, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->doRemoveDoorNamesCommand(); return true; }, makeSimpleHelp( "Removes all secret door names from the current map (WARNING: destructive)!")); add(cmdSearch, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseSearch(rest); return true; }, makeSimpleHelp("Highlight matching rooms on the map.")); add(cmdSet, [this](const std::vector<StringView> & /*s*/, StringView rest) { this->parseSetCommand(rest); return true; }, [this](const std::string &name) { const char help[] = "Subcommands:\r\n" "\tprefix # Displays the current prefix.\r\n" "\tprefix <punct-char> # Changes the current prefix.\r\n" "\r\n" // REVISIT: Does it actually support LATIN-1 punctuation like the degree symbol? "Note: <punct-char> may be any ASCII punctuation character,\r\n" " which can be optionally single- or double-quoted.\r\n" "\r\n" "Examples to set prefix:\r\n" "\tprefix / # slash character\r\n" "\tprefix '/' # single-quoted slash character\r\n" "\tprefix \"/\" # double-quoted slash character\r\n" "\tprefix ' # bare single-quote character\r\n" "\tprefix \"'\" # double-quoted single-quote character\r\n" "\tprefix \" # bare double-quote character\r\n" "\tprefix '\"' # single-quoted double-quote character\r\n" "\r\n" "Note: Quoted versions do not allow escape codes,\r\n" "so you cannot do ''', '\\'', \"\"\", or \"\\\"\"."; sendToUser(QString("Help for %1%2:\r\n%3\r\n\r\n") .arg(prefixChar) .arg(QString::fromStdString(name)) .arg(QString::fromStdString(help))); }); add(cmdTime, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->showMumeTime(); return true; }, makeSimpleHelp("Displays the current MUME time.")); add(cmdTrollExit, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->toggleTrollMapping(); return true; }, makeSimpleHelp("Toggles troll-only exit mapping for direct sunlight.")); add(cmdVote, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; this->openVoteURL(); return true; }, makeSimpleHelp("Launches a web browser so you can vote for MUME on TMC!")); /* print commands */ add(cmdPrint, [this](const std::vector<StringView> & /*s*/, StringView rest) { return parsePrint(rest); }, makeSimpleHelp("There is no help for this command yet.")); add(cmdPDynamic, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; printRoomInfo(dynamicRoomFields); return true; }, makeSimpleHelp("Prints current room description.")); add(cmdPStatic, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; printRoomInfo(staticRoomFields); return true; }, makeSimpleHelp("Prints current room description without movable items.")); add(cmdPNote, [this](const std::vector<StringView> & /*s*/, StringView rest) { if (!rest.isEmpty()) return false; showNote(); return true; }, makeSimpleHelp("Print the note in the current room.")); qInfo() << "Total commands + abbreviations: " << map.size(); }
bool AbstractParser::parseSimpleCommand(const QString &str) { const auto isOnline = ::isOnline(); for (const CommandIdType cmd : ALL_COMMANDS) { if (cmd == CommandIdType::NONE || cmd == CommandIdType::UNKNOWN) continue; if (!isCommand(str, cmd)) continue; switch (cmd) { case CommandIdType::NORTH: case CommandIdType::SOUTH: case CommandIdType::EAST: case CommandIdType::WEST: case CommandIdType::UP: case CommandIdType::DOWN: case CommandIdType::LOOK: doMove(cmd); return isOnline; case CommandIdType::FLEE: if (!isOnline) { offlineCharacterMove(CommandIdType::FLEE); return false; // do not send command to mud server for offline mode } break; case CommandIdType::SCOUT: if (!isOnline) { auto view = StringView{str}.trim(); if (!view.isEmpty() && !view.takeFirstWord().isEmpty()) { const auto dir = static_cast<CommandIdType>(tryGetDir(view)); if (dir >= CommandIdType::UNKNOWN) { sendToUser("In which direction do you want to scout?\r\n"); sendPromptToUser(); } else { queue.enqueue(CommandIdType::SCOUT); queue.enqueue(dir); offlineCharacterMove(); } return false; } } break; case CommandIdType::UNKNOWN: case CommandIdType::NONE: break; } break; /* break the for loop */ } if (!isOnline) { sendToUser("Arglebargle, glop-glyf!?!\r\n"); sendPromptToUser(); } return isOnline; // only forward command to mud server if online }
void MessageServer::processMessage( pair<int, string > mes ){ cout << mes.first << " " << mes.second << endl; string command; string text; Poco::StringTokenizer tokenizer(mes.second, "~"); bool invalid = false; int tokCnt = tokenizer.count(); if( tokCnt < 1 && tokCnt > 2){ invalid = true; } else { command = tokenizer[0]; if(tokCnt > 1 ) text = tokenizer[1]; if( command.length() == 0 ){ invalid = true; } } if( invalid ){ sendToUser( mes.first, "~ERR_INVMSGFRMT"); return; } // VALID format if( command.compare("SETNICK") == 0 ){ if( text.length() == 0 ){ sendToUser( mes.first, "~ERR_EMPTYNICK"); return; } users.insert( pair<int, string>(mes.first, text ) ); sendToUser( mes.first, "~SUCCESS"); } else if( command.compare("MSG") == 0 ){ if( text.length() == 0){ sendToUser( mes.first, "~ERR_EMPTYMSG"); return; } string nick; stringstream allMessage; bool found = false; if( users.find(mes.first) != users.end() ){ nick = users[ mes.first ]; found = true; } if( found ){ string mes(nick); mes += ": "; mes += text; sendToAll( mes ); } else { sendToUser( mes.first, "~ERR_NOTREG"); } } else if( command.compare("QUIT") == 0 ) { map<int, string>::iterator qu = users.find(mes.first); if( qu != users.end() ){ string name = (*qu).second; users.erase( qu ); stringstream allMessage; allMessage << "User " << name << " leaving chat" << endl; sendToAll( allMessage.str() ); } } }
void Parser::parseNewMudInput(IncomingData& data /*TelnetIncomingDataQueue& que*/) { bool staticLine = false; bool dontSendToUser = false; /*IncomingData data; bool staticLine; while ( !que.isEmpty() ) { data = que.dequeue(); */ //dline = (quint8 *)data.line.data(); switch (data.type) { case TDT_DELAY: case TDT_MENU_PROMPT: case TDT_LOGIN: case TDT_LOGIN_PASSWORD: case TDT_TELNET: case TDT_SPLIT: case TDT_UNKNOWN: #ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE (*debugStream) << "***STYPE***"; (*debugStream) << "Other"; (*debugStream) << "***ETYPE***"; #endif emit sendToUser(data.line); break; case TDT_PROMPT: #ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE (*debugStream) << "***STYPE***"; (*debugStream) << "Prompt"; (*debugStream) << "***ETYPE***"; #endif m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size()); m_stringBuffer = m_stringBuffer.simplified(); latinToAscii(m_stringBuffer); if (m_readingRoomDesc) { m_readingRoomDesc = false; // we finished read desc mode m_descriptionReady = true; if (m_examine) m_examine = false; // stop showing bypassing brief-mode } if (m_descriptionReady) { m_descriptionReady = false; parsePrompt(m_stringBuffer); if (!queue.isEmpty()) { CommandIdType c = queue.dequeue(); if ( c != CID_SCOUT ){ //qDebug("%s",m_roomName.toAscii().data()); //qDebug("%s",m_dynamicRoomDesc.toAscii().data()); emit showPath(queue, false); characterMoved(c, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags); } //additional scout move needs to be removed when scout was successful else queue.dequeue(); } else { //qDebug("%s",m_roomName.toAscii().data()); //qDebug("%s",m_dynamicRoomDesc.toAscii().data()); emit showPath(queue, false); characterMoved(CID_NONE, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags); } } emit sendToUser(data.line); break; case TDT_CRLF: #ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE (*debugStream) << "***STYPE***"; (*debugStream) << "CRLF"; (*debugStream) << "***ETYPE***"; #endif if (data.line.contains("null)>")) break; m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size()); m_stringBuffer = m_stringBuffer.simplified(); latinToAscii(m_stringBuffer); if (m_readingRoomDesc) { if (isEndOfRoomDescription(m_stringBuffer)) // standard end of description parsed { m_readingRoomDesc = false; // we finished read desc mode m_descriptionReady = true; dontSendToUser = true; } else if (m_stringBuffer.isEmpty()) // standard end of description parsed { m_readingRoomDesc = false; // we finished read desc mode m_descriptionReady = true; if (Config().m_emulatedExits) emulateExits(); } else // reading room description line { switch(Config().m_roomDescriptionsParserType) { case Configuration::RDPT_COLOR: if ((m_readingStaticDescLines == true) && isStaticRoomDescriptionLine(m_stringBuffer)) { staticLine = true; m_staticRoomDesc += m_stringBuffer+"\n"; } else { m_readingStaticDescLines = false; m_dynamicRoomDesc += m_stringBuffer+"\n"; } m_roomDescLines++; break; case Configuration::RDPT_PARSER: if ((m_roomDescLines >= Config().m_minimumStaticLines) && ((m_readingStaticDescLines == false) || Patterns::matchDynamicDescriptionPatterns(m_stringBuffer))) { m_readingStaticDescLines = false; m_dynamicRoomDesc += m_stringBuffer+"\n"; } else { staticLine = true; m_staticRoomDesc += m_stringBuffer+"\n"; } m_roomDescLines++; break; case Configuration::RDPT_LINEBREAK: m_dynamicRoomDesc += m_stringBuffer+"\n"; m_roomDescLines++; break; } } } else if (!m_readingRoomDesc && m_descriptionReady) //read betwen Exits and Prompt (track for example) { if ( isRoomName(m_stringBuffer) ) //Room name arrived { if (m_descriptionReady) { m_descriptionReady = false; if (!queue.isEmpty()) { CommandIdType c = queue.dequeue(); if ( c != CID_SCOUT ){ emit showPath(queue, false); characterMoved(c, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags); } //additional scout move needs to be removed when scout was successful else queue.dequeue(); } else { emit showPath(queue, false); characterMoved(CID_NONE, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags); } } m_readingRoomDesc = true; //start of read desc mode m_descriptionReady = false; m_roomName=m_stringBuffer; m_dynamicRoomDesc=nullString; m_staticRoomDesc=nullString; m_roomDescLines = 0; m_readingStaticDescLines = true; m_exitsFlags = 0; } else if (!m_stringBuffer.isEmpty()) parseMudCommands(m_stringBuffer); } else if ( isRoomName(m_stringBuffer) ) //Room name arrived { if (m_descriptionReady) { m_descriptionReady = false; if (!queue.isEmpty()) { CommandIdType c = queue.dequeue(); if ( c != CID_SCOUT ){ emit showPath(queue, false); characterMoved(c, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags); } //additional scout move needs to be removed when scout was successful else queue.dequeue(); } else { emit showPath(queue, false); characterMoved(CID_NONE, m_roomName, m_dynamicRoomDesc, m_staticRoomDesc, m_exitsFlags, m_promptFlags); } } m_readingRoomDesc = true; //start of read desc mode m_descriptionReady = false; m_roomName=m_stringBuffer; m_dynamicRoomDesc=nullString; m_staticRoomDesc=nullString; m_roomDescLines = 0; m_readingStaticDescLines = true; m_exitsFlags = 0; } else if (!m_stringBuffer.isEmpty() && Patterns::matchNoDescriptionPatterns(m_stringBuffer)) // non standard end of description parsed (fog, dark or so ...) { m_readingRoomDesc = false; // we finished read desc mode m_descriptionReady = true; m_roomName=nullString; m_dynamicRoomDesc=nullString; m_staticRoomDesc=nullString; m_roomDescLines = 0; m_readingStaticDescLines = false; m_exitsFlags = 0; m_promptFlags = 0; } else // parse standard input (answers) from server { //str=removeAnsiMarks(m_stringBuffer); if (!m_stringBuffer.isEmpty()) parseMudCommands(m_stringBuffer); } if (!dontSendToUser && !(staticLine && (m_examine || Config().m_brief))) emit sendToUser(data.line); break; case TDT_LFCR: #ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE (*debugStream) << "***STYPE***"; (*debugStream) << "LFCR"; (*debugStream) << "***ETYPE***"; #endif m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size()); m_stringBuffer = m_stringBuffer.simplified(); latinToAscii(m_stringBuffer); if (m_readingRoomDesc && (Config().m_roomDescriptionsParserType == Configuration::RDPT_LINEBREAK) ) { staticLine = true; m_staticRoomDesc += m_stringBuffer+"\n"; m_roomDescLines++; } if (!(staticLine && (m_examine || Config().m_brief))) emit sendToUser(data.line); break; case TDT_LF: #ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE (*debugStream) << "***STYPE***"; (*debugStream) << "LF"; (*debugStream) << "***ETYPE***"; #endif m_stringBuffer = QString::fromAscii(data.line.constData(), data.line.size()); emit sendToUser(data.line); break; } #ifdef PARSER_STREAM_DEBUG_INPUT_TO_FILE (*debugStream) << "***S***"; (*debugStream) << data.line; (*debugStream) << "***E***"; #endif //} }
void Parser::parseMudCommands(QString& str) { /*if (str.startsWith('B') && str.startsWith("Brief mode on")){ emit sendToMud((QByteArray)"brief\n"); }*/ if (str.startsWith('<') && str.startsWith("<xml>")) //we are in xml mode { emit setXmlMode(); emit sendToUser((QByteArray)"[MMapper] Mode ---> XML\n"); emptyQueue(); } if (str.startsWith('Y')) { if (str.startsWith("You are dead!")) { queue.clear(); emit showPath(queue, true); emit releaseAllPaths(); return; } if (str.startsWith("You flee")) { if (str.contains("north")) queue.enqueue(CID_NORTH); else if (str.contains("south")) queue.enqueue(CID_SOUTH); else if (str.contains("east")) queue.enqueue(CID_EAST); else if (str.contains("west")) queue.enqueue(CID_WEST); else if (str.contains("up")) queue.enqueue(CID_UP); else if (str.contains("down")) queue.enqueue(CID_DOWN); return; } if (str.startsWith("You now follow")){ m_following = true; emit sendToUser((QByteArray)"----> follow mode on.\n"); return; } else if (str.startsWith("You quietly scout")) { queue.prepend(CID_SCOUT); return; } if (m_following) { if (str=="You will not follow anyone else now.") { m_following = false; emit sendToUser((QByteArray)"----> follow mode off.\n"); return; } if (str.startsWith("You follow")) { switch (m_followDir) { case NORTH: queue.enqueue(CID_NORTH);break; case SOUTH: queue.enqueue(CID_SOUTH);break; case EAST: queue.enqueue(CID_EAST);break; case WEST: queue.enqueue(CID_WEST);break; case UP: queue.enqueue(CID_UP);break; case DOWN: queue.enqueue(CID_DOWN);break; case UNKNOWN: queue.enqueue(CID_NONE);break; } return; } } } if (m_following) { if(str.contains("leave")) { if ((str.contains("leaves north")) || (str.contains("leave north"))) m_followDir = NORTH; else if ((str.contains("leaves south")) || (str.contains("leave south"))) m_followDir = SOUTH; else if ((str.contains("leaves east")) || (str.contains("leave east"))) m_followDir = EAST; else if ((str.contains("leaves west")) || (str.contains("leave west"))) m_followDir = WEST; else if ((str.contains("leaves up")) || (str.contains("leave up"))) m_followDir = UP; else if ((str.contains("leaves down")) || (str.contains("leave down"))) m_followDir = DOWN; } } // parse regexps which cancel last char move if (Patterns::matchMoveCancelPatterns(str)) { if(!queue.isEmpty()) queue.dequeue(); emit showPath(queue, true); return; } // parse regexps which force new char move if (Patterns::matchMoveForcePatterns(str)) { queue.enqueue(CID_NONE); emit showPath(queue, true); return; } }
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; }
void MumeXmlParser::parse(const IncomingData &data) { const QByteArray &line = data.line; m_lineToUser.clear(); int index; for (index = 0; index < line.size(); index++) { if (m_readingTag) { if (line.at(index) == '>') { // send tag if (!m_tempTag.isEmpty()) { element(m_tempTag); } m_tempTag.clear(); m_readingTag = false; continue; } m_tempTag.append(line.at(index)); } else { if (line.at(index) == '<') { m_lineToUser.append(characters(m_tempCharacters)); m_tempCharacters.clear(); m_readingTag = true; continue; } m_tempCharacters.append(line.at(index)); } } if (!m_readingTag) { m_lineToUser.append(characters(m_tempCharacters)); m_tempCharacters.clear(); } if (!m_lineToUser.isEmpty()) { const auto isGoAhead = [](TelnetDataType type) -> bool { switch (type) { case TelnetDataType::DELAY: case TelnetDataType::LOGIN: case TelnetDataType::LOGIN_PASSWORD: case TelnetDataType::MENU_PROMPT: case TelnetDataType::PROMPT: return true; case TelnetDataType::CRLF: case TelnetDataType::LFCR: case TelnetDataType::LF: case TelnetDataType::SPLIT: case TelnetDataType::UNKNOWN: return false; } return false; }; sendToUser(m_lineToUser, isGoAhead(data.type)); if (m_readStatusTag) { m_readStatusTag = false; if (getConfig().groupManager.state != GroupManagerState::Off) { QByteArray temp = m_lineToUser; if (!getConfig().parser.removeXmlTags) { stripXmlEntities(temp); } QString tempStr = temp; tempStr = normalizeStringCopy(tempStr.trimmed()); if (Patterns::matchScore(tempStr)) { // inform groupManager temp = tempStr.toLocal8Bit(); emit sendScoreLineEvent(temp); } } } } }