Example #1
0
	std::string JoinTokenizer(Poco::StringTokenizer& tokenizer, const char *sep, int begin)
	{
		std::string joined = "";
		joined += sep;
		for (size_t i = begin; i < tokenizer.count(); i++) {
			joined += tokenizer[i];
			if (i < tokenizer.count() - 1) {
				joined += sep;
			}
		}
		return joined;
	}
Example #2
0
  virtual std::string Process(Poco::StringTokenizer& token, std::pair<int, int>& cursorPos)
  {
    Message("     SetProcessor::Process called.");
 
    std::string rtn;
 
    if(3 != token.count())
      {
	rtn = "ERROR: set command requires two arguments.\n";
      }
    else
      {
	int x, y;
	if(Poco::NumberParser::tryParse(token[1], x) && Poco::NumberParser::tryParse(token[2], y))
	  {
	    cursorPos.first  = x;
	    cursorPos.second = y;
	    rtn = CommandProcessor::Process(token, cursorPos);
	  }
	else
	  {
	    rtn = "ERROR: set command requires two integer arguments.\n";
	  }
      }
    return rtn;
  }
Example #3
0
    /// Deserialize a TileDesc from a tokenized string.
    static
    TileDesc parse(const Poco::StringTokenizer& tokens)
    {
        // We don't expect undocumented fields and
        // assume all values to be int.
        std::map<std::string, int> pairs;

        // Optional.
        pairs["ver"] = -1;
        pairs["imgsize"] = 0;
        pairs["id"] = -1;

        for (size_t i = 0; i < tokens.count(); ++i)
        {
            std::string name;
            int value = -1;
            if (LOOLProtocol::parseNameIntegerPair(tokens[i], name, value))
            {
                pairs[name] = value;
            }
        }

        return TileDesc(pairs["part"], pairs["width"], pairs["height"],
                        pairs["tileposx"], pairs["tileposy"],
                        pairs["tilewidth"], pairs["tileheight"],
                        pairs["ver"],
                        pairs["imgsize"], pairs["id"]);
    }
bool MasterProcessSession::handleDisconnect(Poco::StringTokenizer& tokens)
{
    Log::info("Graceful disconnect on " + getName() + " [" +
              (tokens.count() > 1 ? tokens[1] : std::string("no reason")) +
              "].");

    LOOLSession::handleDisconnect(tokens);

    auto peer = _peer.lock();
    if (peer)
    {
        const auto reason = (tokens.count() > 1 ? tokens[1] : std::string());
        peer->disconnect(reason);
    }

    return false;
}
Example #5
0
/** Convert the units specification line from the RKH file into a
*  Mantid unit name
*  @param line :: units specification line
*  @return Mantid unit name
*/
const std::string LoadRKH::readUnit(const std::string & line)
{
    // split the line into words
    const Poco::StringTokenizer codes(line, " ", Poco::StringTokenizer::TOK_TRIM);
    if ( codes.count() < 1 )
    {
        return "C++ no unit found";
    }

    // the symbol for the quantity q = MomentumTransfer, etc.
    const std::string symbol(codes[0]);
    // this is units used to measure the quantity e.g. angstroms, counts, ...
    const std::string unit( *(codes.end()-1) );

    // theQuantity will contain the name of the unit, which can be many words long
    std::string theQuantity;
    Poco::StringTokenizer::Iterator current = codes.begin()+1, end = codes.end();
    for ( ; current != end; ++current)
    {
        if ( current != end - 1 )
        {
            theQuantity += *current;
        }
    }

    //this is a syntax check the line before returning its data
    if ( codes.count() >= 3 )
    {
        if ( unit.find('(') != 0 || unit.find(')') != unit.size() )
        {
            std::string qCode = boost::lexical_cast<std::string>(SaveRKH::Q_CODE);
            if ( symbol == qCode && theQuantity == "q" && unit == "(1/Angstrom)" )
            {   // 6 q (1/Angstrom) is the synatx for MomentumTransfer
                return "MomentumTransfer";
            }

            if ( symbol == "0" && theQuantity != "q" )
            {   // zero means the unit is not q but something else, which I'm assuming is legal
                return theQuantity + " " + unit;
            }
        }
    }
    // the line doesn't contain a valid 2D data file unit line
    return "C++ no unit found";
}
Example #6
0
 bool getTokenKeyword(const Poco::StringTokenizer& tokens, const std::string& name, const std::map<std::string, int>& map, int& value)
 {
     for (size_t i = 0; i < tokens.count(); i++)
     {
         if (getTokenKeyword(tokens[i], name, map, value))
             return true;
     }
     return false;
 }
Example #7
0
 bool getTokenString(const Poco::StringTokenizer& tokens, const std::string& name, std::string& value)
 {
     for (size_t i = 0; i < tokens.count(); i++)
     {
         if (getTokenString(tokens[i], name, value))
             return true;
     }
     return false;
 }
Example #8
0
  virtual std::string Process(Poco::StringTokenizer& token, std::pair<int, int>& cursorPos)
  {
    Message("     GetProcessor::Process called.");
 
    std::string rtn;
 
    if(1 != token.count())
      {
	rtn = "WARNING: get command does not need argument(s).\n";
      }
    rtn += CommandProcessor::Process(token, cursorPos);
    return rtn;
  }
Example #9
0
    /// Deserialize a TileDesc from a tokenized string.
    static
    TileCombined parse(const Poco::StringTokenizer& tokens)
    {
        // We don't expect undocumented fields and
        // assume all values to be int.
        std::map<std::string, int> pairs;

        // Optional.
        pairs["ver"] = -1;
        pairs["id"] = -1;

        std::string tilePositionsX;
        std::string tilePositionsY;
        std::string imgSizes;
        for (size_t i = 0; i < tokens.count(); ++i)
        {
            std::string name;
            std::string value;
            if (LOOLProtocol::parseNameValuePair(tokens[i], name, value))
            {
                if (name == "tileposx")
                {
                    tilePositionsX = value;
                }
                else if (name == "tileposy")
                {
                    tilePositionsY = value;
                }
                else if (name == "imgsize")
                {
                    imgSizes = value;
                }
                else
                {
                    int v = 0;
                    if (LOOLProtocol::stringToInteger(value, v))
                    {
                        pairs[name] = v;
                    }
                }
            }
        }

        return TileCombined(pairs["part"], pairs["width"], pairs["height"],
                            tilePositionsX, tilePositionsY,
                            pairs["tilewidth"], pairs["tileheight"],
                            pairs["ver"],
                            imgSizes, pairs["id"]);
    }
Example #10
0
void Rcon::processMessageMission(Poco::StringTokenizer &tokens)
{
	std::vector<std::string> info_vector;
	for (int i = 1; i < (tokens.count()); ++i)
	{
		if (boost::algorithm::ends_with(tokens[i], ".pbo"))
		{
			info_vector.push_back(tokens[i].substr(0, tokens[i].size() - 4));
		}
		else
		{
			info_vector.push_back(tokens[i]);
		}
	}

	AbstractExt::resultData result_data;
	if (info_vector.empty())
	{
		result_data.message  = "[1,[]]";
	}
	else
	{
		result_data.message = "[1,[";
		for(auto &info : info_vector)
		{
			result_data.message += info;
			result_data.message += ",";
			logger->info("Server Mission: {0}", info);
		}
		result_data.message.pop_back();
		result_data.message += "]]";
	}

	#ifdef RCON_APP
		logger->info("RCON: Mission: {0}", result_data.message);
	#else
		std::vector<unsigned int> unique_id_saves;
		{
			std::lock_guard<std::mutex> lock(rcon_socket.mutex_mission_requests);
			for (unsigned int unique_id : rcon_socket.mission_requests)
			{
				unique_id_saves.push_back(unique_id);
			}
			rcon_socket.mission_requests.clear();
		}
		extension_ptr->saveResult_mutexlock(unique_id_saves, result_data);
	#endif
}
Example #11
0
void Rcon::processMessagePlayers(Poco::StringTokenizer &tokens)
{
	std::string player_str;
	std::vector<RconPlayerInfo> info_vector;

	for (int i = 3; i < (tokens.count() - 1); ++i)
	{
		player_str = tokens[i];
		player_str.erase(std::unique(player_str.begin(), player_str.end(), [](char a, char b) { return a == ' ' && b == ' '; } ), player_str.end() );

		Poco::StringTokenizer player_tokens(player_str, " ");
		if (player_tokens.count() >= 5)
		{
			RconPlayerInfo player_data;

			player_data.number = player_tokens[0];
			auto found = player_tokens[1].find(":");
			player_data.ip = player_tokens[1].substr(0, found - 1);
			player_data.port = player_tokens[1].substr(found + 1);
			player_data.ping = player_tokens[2];

			if (boost::algorithm::iends_with(player_tokens[3], "(OK)"))
			{
				player_data.verified = "true";
				player_data.guid = player_tokens[3].substr(0, (player_tokens[3].size() - 4));
				found = tokens[i].find(")");
				player_data.player_name = tokens[i].substr(found + 2);
				boost::replace_all(player_data.player_name, "\"", "\"\"");
				boost::replace_all(player_data.player_name, "'", "''");
			}
			else if (boost::algorithm::iends_with(player_tokens[3], "(unverified)"))
			{
				player_data.verified = "false";
				player_data.guid = player_tokens[3].substr(0, (player_tokens[3].size() - 12));
				found = tokens[i].find("- ");
				player_data.player_name = tokens[i].substr(found + 2);
				boost::replace_all(player_data.player_name, "\"", "\"\"");
				boost::replace_all(player_data.player_name, "'", "''");
			}
			else
			{
				player_data.verified = "false";
			}

			if (boost::algorithm::iends_with(player_data.player_name, " (Lobby)"))
			{
				player_data.player_name = player_data.player_name.substr(0, player_data.player_name.size() - 8);
				player_data.lobby = "true";
			}
			else
			{
				player_data.lobby = "false";
			}

			logger->info("DEBUG players Player Number: {0}.", player_data.number);
			logger->info("DEBUG players Player Name: {0}.", player_data.player_name);
			logger->info("DEBUG players Player GUID: {0}.", player_data.guid);

			bool kicked = false;
			if (player_data.verified == "true")
			{
				players_name_beguid[player_data.player_name] = player_data.guid;
				if (bad_playername_settings.enable)
				{
					checkBadPlayerString(player_data.number, player_data.player_name, kicked);
				}
				if (!kicked)
				{
					if (whitelist_settings.enable && (whitelist_settings.open_slots == 0))
					{
						checkWhitelistedPlayer(player_data.number, player_data.player_name, player_data.guid, kicked);
					}
				}

				#ifndef RCON_APP
					if ((!kicked) && rcon_settings.generate_unique_id)
					{
						// We only bother to generate a key if player has not been kicked
						extension_ptr->createPlayerKey_mutexlock(player_data.guid, 10);
					}
				#endif
				info_vector.push_back(std::move(player_data));
			}
			else
			{
				if (bad_playername_settings.enable)
				{
					checkBadPlayerString(player_data.number, player_data.player_name, kicked);
				}
			}
		}
		else
		{
			logger->info("Rcon: Error: Wrong RconPlayerInfo count: {0}.", player_tokens.count());
		}
	}


	AbstractExt::resultData result_data;
	if (info_vector.empty())
	{
		result_data.message  = "[1,[]]";
	}
	else
	{
		result_data.message = "[1,[";
		if (rcon_settings.return_full_player_info)
		{
			for(auto &info : info_vector)
			{
				result_data.message += "[\"" + info.number + "\",";
				result_data.message += "\"" + info.ip + "\",";
				result_data.message += info.port + ",";
				result_data.message += info.ping + ",";
				result_data.message += "\"" + info.guid + "\",";
				result_data.message += info.verified + ",";
				result_data.message += "\"" + info.player_name + "\",";
				result_data.message += info.lobby + "],";
			}
		}
		else
		{
			for(auto &info : info_vector)
			{
				result_data.message += "[\"" + info.number + "\",";
				result_data.message += "\"" + info.guid + "\",";
				result_data.message += info.verified + ",";
				result_data.message += "\"" + info.player_name + "\",";
				result_data.message += info.lobby + "],";
			}
		}

		result_data.message.pop_back();
		result_data.message += "]]";
	}

	#ifndef RCON_APP
		std::vector<unsigned int> unique_id_saves;
	#endif
	{
		std::lock_guard<std::mutex> lock(rcon_socket.mutex_players_requests);
		#ifdef RCON_APP
			logger->info("RCON: Player: {0}", result_data.message);
		#else
			for (unsigned int unique_id : rcon_socket.player_requests)
			{
				unique_id_saves.push_back(unique_id);
			}
			rcon_socket.player_requests.clear();
		#endif
	}
	#ifndef RCON_APP
		extension_ptr->saveResult_mutexlock(unique_id_saves, result_data);
	#endif
}