Exemplo n.º 1
0
void cFireworkItem::FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem)
{
	AStringVector Split = StringSplit(a_String, ";");

	for (size_t itr = 0; itr < Split.size(); ++itr)
	{
		if (Split[itr].empty())
		{
			continue;
		}

		a_FireworkItem.m_FadeColours.push_back(atoi(Split[itr].c_str()));
	}
}
Exemplo n.º 2
0
std::string get_config_path()
{
    //ex: C:\Users\Mark\Documents\Visual Studio
    //2010\Projects\FirstCPPApplication\Debug\BiochRL++.exe
    std::string exepath = get_exe_path();
    std::vector<std::string> exesplit = StringSplit(exepath, kPathSeparator);

    exesplit.pop_back();
    std::string data = "config";
    data+=kPathSeparator;
    exesplit.push_back(data);

    return StringJoin(exesplit, kPathSeparator, false);
};
Exemplo n.º 3
0
void SkinXml::getInstanceNames()
{
	string currentElement = GetFullCurrentElementName();
	string strData = "";
	
	vector<string> Settings;

	StringSplit(currentElement, "--", &Settings);
	unsigned int size = Settings.size()-1;
	if (strcmp(Settings.at(size).c_str(), "Instance")==0)
	{
		Instance = m_Attributes["id"].c_str();
	}
}
Exemplo n.º 4
0
	void AddToMap(const AString & a_Name, const AString & a_Value)
	{
		AStringVector Split = StringSplit(a_Value, ":");
		if (Split.size() == 1)
		{
			Split = StringSplit(a_Value, "^");
		}
		if (Split.empty())
		{
			return;
		}
		short ItemType;
		if (!StringToInteger(Split[0], ItemType))
		{
			ASSERT(!"Invalid item type");
		}
		short ItemDamage = -1;
		if (Split.size() > 1 && !StringToInteger(Split[1], ItemDamage))
		{
			ASSERT(!"Invalid item damage");
		}
		m_Map[a_Name] = std::make_pair(ItemType, ItemDamage);
	}
Exemplo n.º 5
0
bool cPlayer::HasPermission(const AString & a_Permission)
{
	if (a_Permission.empty())
	{
		// Empty permission request is always granted
		return true;
	}
	
	AStringVector Split = StringSplit( a_Permission, "." );
	PermissionMap Possibilities = m_ResolvedPermissions;
	// Now search the namespaces
	while( Possibilities.begin() != Possibilities.end() )
	{
		PermissionMap::iterator itr = Possibilities.begin();
		if( itr->second )
		{
			AStringVector OtherSplit = StringSplit( itr->first, "." );
			if( OtherSplit.size() <= Split.size() )
			{
				unsigned int i;
				for( i = 0; i < OtherSplit.size(); ++i )
				{
					if( OtherSplit[i].compare( Split[i] ) != 0 )
					{
						if( OtherSplit[i].compare("*") == 0 ) return true; // WildCard man!! WildCard!
						break;
					}
				}
				if( i == Split.size() ) return true;
			}
		}
		Possibilities.erase( itr );
	}

	// Nothing that matched :(
	return false;
}
Exemplo n.º 6
0
int CSBFSpot::getSunRiseSunSetMinutes(const bool bGetSunRise)
{
	std::vector<std::string> strarray;
	std::vector<std::string> sunRisearray;
	std::vector<std::string> sunSetarray;

	if (!m_mainworker.m_LastSunriseSet.empty())
	{
		StringSplit(m_mainworker.m_LastSunriseSet, ";", strarray);
		StringSplit(strarray[0], ":", sunRisearray);
		StringSplit(strarray[1], ":", sunSetarray);

		int sunRiseInMinutes = (atoi(sunRisearray[0].c_str()) * 60) + atoi(sunRisearray[1].c_str());
		int sunSetInMinutes = (atoi(sunSetarray[0].c_str()) * 60) + atoi(sunSetarray[1].c_str());

		if (bGetSunRise) {
			return sunRiseInMinutes;
		}
		else {
			return sunSetInMinutes;
		}
	}
	return 0;
}
Exemplo n.º 7
0
bool CNotificationHelper::CheckAndHandleNotification(
	const uint64_t Idx,
	const std::string &devicename,
	const _eNotificationTypes ntype,
	const std::string &message)
{
	std::vector<_tNotification> notifications = GetNotifications(Idx);
	if (notifications.size() == 0)
		return false;

	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT SwitchType, CustomImage FROM DeviceStatus WHERE (ID=%" PRIu64 ")", Idx);
	if (result.size() == 0)
		return false;

	std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|CustomImage=" + result[0][1] + "|";
	std::string notValue;

	time_t atime = mytime(NULL);

	//check if not sent 12 hours ago, and if applicable
	atime -= m_NotificationSensorInterval;

	std::string ltype = Notification_Type_Desc(ntype, 1);
	std::vector<_tNotification>::const_iterator itt;
	for (itt = notifications.begin(); itt != notifications.end(); ++itt)
	{
		if (itt->LastUpdate)
			TouchLastUpdate(itt->ID);
		std::vector<std::string> splitresults;
		StringSplit(itt->Params, ";", splitresults);
		if (splitresults.size() < 1)
			continue; //impossible
		std::string atype = splitresults[0];
		if (atype == ltype)
		{
			if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true
			{
				std::string msg = message;
				if (!itt->CustomMessage.empty())
					msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
				SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
				TouchNotification(itt->ID);
			}
		}
	}
	return true;
}
Exemplo n.º 8
0
int StrSplit(const char *src, const char *delim, __gnu_cxx::StrSplitMap &map, int maxParts)
{

    string  workStr;
    workStr = src;
    return StringSplit(workStr, delim, map, maxParts);
#if 0
    int                 entryCount = 0;

    char                *workStr;
    
    char                *tmpStr;
    char                *part;
    

    if (!strlen(src)) return 0;

    workStr = new char[strlen(src)+1024];
    strcpy(workStr, src);

    part = strsep(&workStr, delim);

    while (part != NULL) {
        if ((maxParts) && (entryCount >= maxParts)) {
            // The user specified a maximum number of parts, append
            // this entry to the previous part, and make sure we
            // put the delimiter back in.
            entryCount--;
            char *tmpStr2 = new char[strlen(part) + strlen(delim) + strlen(map[entryCount].c_str()) + 16];
            strcpy(tmpStr2, map[entryCount].c_str());
            strcat(tmpStr2, delim);
            strcat(tmpStr2, part);
            map[entryCount] = tmpStr2;
            part = strsep(&workStr, delim);
            entryCount++;
        } else {
            tmpStr = new char[strlen(part)+16];
            strcpy(tmpStr, part);
            map[entryCount++] = tmpStr;
            part = strsep(&workStr, delim);
        }
    }

    return entryCount;
#endif
}
Exemplo n.º 9
0
void CTCPClient::handleRead(const boost::system::error_code& e,
	std::size_t bytes_transferred)
{
	if (!e)
	{
		//do something with the data
		//buffer_.data(), buffer_.data() + bytes_transferred
		if (bytes_transferred>7)
		{
			std::string recstr;
			recstr.append(buffer_.data(),bytes_transferred);
			if (recstr.find("AUTH")!=std::string::npos)
			{
				//Authentication
				std::vector<std::string> strarray;
				StringSplit(recstr, ";", strarray);
				if (strarray.size()==3)
				{
					m_bIsLoggedIn=pConnectionManager->HandleAuthentication(shared_from_this(), strarray[1] ,strarray[2]);
					if (!m_bIsLoggedIn)
					{
						//Wrong username/password
						pConnectionManager->stopClient(shared_from_this());
						return;
					}
					m_username=strarray[1];
				}
			}
			else
			{
				pConnectionManager->DoDecodeMessage(this,(const unsigned char *)buffer_.data());
			}
		}

		//ready for next read
		socket_->async_read_some(boost::asio::buffer(buffer_),
			boost::bind(&CTCPClient::handleRead, shared_from_this(),
			boost::asio::placeholders::error,
			boost::asio::placeholders::bytes_transferred));
	}
	else if (e != boost::asio::error::operation_aborted)
	{
		pConnectionManager->stopClient(shared_from_this());
	}
}
Exemplo n.º 10
0
void CYouLess::GetMeterDetails()
{
	std::string sResult;

	char szURL[200];

	if(m_Password.size() == 0)
	{
		sprintf(szURL,"http://%s:%d/a",m_szIPAddress.c_str(), m_usIPPort);
	}
	else
	{
		sprintf(szURL,"http://%s:%d/a&w=%s",m_szIPAddress.c_str(), m_usIPPort, m_Password.c_str());
	}

	if (!HTTPClient::GET(szURL,sResult))
	{
		_log.Log(LOG_ERROR,"YouLess: Error connecting to: %s", m_szIPAddress.c_str());
		return;
	}

	std::vector<std::string> results;
	StringSplit(sResult, "\n", results);
	if (results.size()<2)
	{
		_log.Log(LOG_ERROR,"YouLess: Error connecting to: %s", m_szIPAddress.c_str());
		return;
	}
	int fpos;
	std::string pusage=stdstring_trim(results[0]);
	fpos=pusage.find_first_of(" ");
	if (fpos!=std::string::npos)
		pusage=pusage.substr(0,fpos);
	stdreplace(pusage,",","");

	std::string pcurrent=stdstring_trim(results[1]);
	fpos=pcurrent.find_first_of(" ");
	if (fpos!=std::string::npos)
		pcurrent=pcurrent.substr(0,fpos);
	stdreplace(pcurrent,",","");

	m_meter.powerusage=atol(pusage.c_str());
	m_meter.usagecurrent=atol(pcurrent.c_str());
	sDecodeRXMessage(this, (const unsigned char *)&m_meter);//decode message
}
Exemplo n.º 11
0
static int getErrorPosition(OovStringRef const line, int &charOffset)
    {
    int lineNum = -1;
    OovStringVec tokens = StringSplit(line, ':');
    auto iter = std::find_if(tokens.begin(), tokens.end(),
        [](OovStringRef const tok)
        { return(isdigit(tok[0])); }
        );
    int starti = iter-tokens.begin();
    if(tokens[starti].getInt(0, INT_MAX, lineNum))
        {
        if(static_cast<unsigned int>(starti+1) < tokens.size())
            {
            tokens[starti+1].getInt(0, INT_MAX, charOffset);
            }
        }
    return lineNum;
    }
Exemplo n.º 12
0
float Meteostick::GetRainSensorCounter(const unsigned char Idx)
{
	float counter = 0;

	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT sValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)", m_HwdID, int(Idx), int(pTypeRAIN), int(sTypeRAIN3));
	if (result.size() >0)
	{
		std::vector<std::string> strarray;
		StringSplit(result[0][0], ";", strarray);
		if (strarray.size() == 2)
		{
			counter = static_cast<float>(atof(strarray[1].c_str()));
		}
	}

	return counter;
}
Exemplo n.º 13
0
bool CSBFSpot::GetMeter(const unsigned char ID1,const unsigned char ID2, double &musage, double &mtotal)
{
	int Idx=(ID1 * 256) + ID2;
	std::vector<std::vector<std::string> > result;
	result=m_sql.safe_query("SELECT Name, sValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
		m_HwdID, int(Idx), int(pTypeENERGY), int(sTypeELEC2));
	if (result.size()<1)
	{
		return false;
	}
	std::vector<std::string> splitresult;
	StringSplit(result[0][1],";",splitresult);
	if (splitresult.size()!=2)
		return false;
	musage=atof(splitresult[0].c_str());
	mtotal=atof(splitresult[1].c_str())/1000.0;
	return true;
}
Exemplo n.º 14
0
	static void process_publish(const string &ip, const string &data, string &answer) {
		if(Server::clients.count(ip) > 0) {           
			// "P;piece;status" (status é: FOUND, NOT_FOUND)
			vector<string> cmd_parts;
			StringSplit(data,";", &cmd_parts);
			string piece = cmd_parts[1];	
			if(cmd_parts[2] == "NOT_FOUND") {
				subsets[piece].status = SUBSET_READY;
			} else {
				cout << "FOUND !!!! said client " << ip << endl;
				//stop_clients();
				exit(0);
			}
			answer = "OK";
		} else {
			answer = "You are NOT registered on this server";
		}
	}
Exemplo n.º 15
0
std::string CNotificationKodi::GetCustomIcon(std::string &szCustom)
{
	int	iIconLine = atoi(szCustom.c_str());
	std::string szRetVal = "Light48";
	if (iIconLine < 100)  // default set of custom icons
	{
		std::string sLine = "";
		std::ifstream infile;
		std::string switchlightsfile = szWWWFolder + "/switch_icons.txt";
		infile.open(switchlightsfile.c_str());
		if (infile.is_open())
		{
			int index = 0;
			while (!infile.eof())
			{
				getline(infile, sLine);
				if ((sLine.size() != 0) && (index++ == iIconLine))
				{
					std::vector<std::string> results;
					StringSplit(sLine, ";", results);
					if (results.size() == 3)
					{
						szRetVal = results[0] + "48";
						break;
					}
				}
			}
			infile.close();
		}
	}
	else  // Uploaded icons
	{
		std::vector<std::vector<std::string> > result;
		result = m_sql.safe_query("SELECT Base FROM CustomImages WHERE ID = %d", iIconLine-100);
		if (result.size() == 1)
		{
			std::string sBase = result[0][0];
			return sBase;
		}
	}
	
//	_log.Log(LOG_NORM, "Custom Icon look up for %s returned: '%s'", szCustom.c_str(), szRetVal.c_str());
	return szRetVal;
}
Exemplo n.º 16
0
std::string BleBox::IPToHex(const std::string &IPAddress, const int type)
{
	std::vector<std::string> strarray;
	StringSplit(IPAddress, ".", strarray);
	if (strarray.size() != 4)
		return "";

	char szIdx[10];
	// because exists inconsistency when comparing deviceID in method decode_xxx in mainworker(Limitless uses small letter, lighting2 etc uses capital letter)
	if (type != pTypeLimitlessLights)
	{ 
		sprintf(szIdx, "%02X%02X%02X%02X", atoi(strarray[0].data()), atoi(strarray[1].data()), atoi(strarray[2].data()), atoi(strarray[3].data()));
	}
	else
	{
		sprintf(szIdx, "%02x%02x%02x%02x", atoi(strarray[0].data()), atoi(strarray[1].data()), atoi(strarray[2].data()), atoi(strarray[3].data()));
	}
	return szIdx;
}
Exemplo n.º 17
0
cPluginManager::CommandResult cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions)
{
	ASSERT(a_Player != NULL);

	AStringVector Split(StringSplit(a_Command, " "));
	if (Split.empty())
	{
		return crUnknownCommand;
	}

	CommandMap::iterator cmd = m_Commands.find(Split[0]);
	if (cmd == m_Commands.end())
	{
		// Command not found
		return crUnknownCommand;
	}

	// Ask plugins first if a command is okay to execute the command:
	if (CallHookExecuteCommand(a_Player, Split))
	{
		LOGINFO("Player %s tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player->GetName().c_str(), Split[0].c_str());
		return crBlocked;
	}

	if (
		a_ShouldCheckPermissions &&
		!cmd->second.m_Permission.empty() &&
		!a_Player->HasPermission(cmd->second.m_Permission)
	)
	{
		LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player->GetName().c_str(), Split[0].c_str());
		return crNoPermission;
	}

	ASSERT(cmd->second.m_Plugin != NULL);

	if (!cmd->second.m_Plugin->HandleCommand(Split, a_Player))
	{
		return crError;
	}

	return crExecuted;
}
Exemplo n.º 18
0
void cPlayer::LoadRank(void)
{
	// Load the values from cRankManager:
	cRankManager & RankMgr = cRoot::Get()->GetRankManager();
	m_Rank = RankMgr.GetPlayerRankName(m_UUID);
	if (m_Rank.empty())
	{
		m_Rank = RankMgr.GetDefaultRank();
	}
	m_Permissions = RankMgr.GetPlayerPermissions(m_UUID);
	RankMgr.GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);

	// Break up the individual permissions on each dot, into m_SplitPermissions:
	m_SplitPermissions.clear();
	m_SplitPermissions.reserve(m_Permissions.size());
	for (AStringVector::const_iterator itr = m_Permissions.begin(), end = m_Permissions.end(); itr != end; ++itr)
	{
		m_SplitPermissions.push_back(StringSplit(*itr, "."));
	}  // for itr - m_Permissions[]
}
Exemplo n.º 19
0
float Meteostick::GetRainSensorCounter(const unsigned char Idx)
{
	float counter = 0;

	std::stringstream szQuery;
	std::vector<std::vector<std::string> > result;
	szQuery << "SELECT sValue FROM DeviceStatus WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID==" << int(Idx) << ") AND (Type==" << int(pTypeRAIN) << ") AND (Subtype==" << int(sTypeRAIN3) << ")";
	result = m_sql.query(szQuery.str());
	if (result.size() >0)
	{
		std::vector<std::string> strarray;
		StringSplit(result[0][0], ";", strarray);
		if (strarray.size() == 2)
		{
			counter = (float)atof(strarray[1].c_str());
		}
	}

	return counter;
}
bool CPVOutputInput::GetMeter(const unsigned char ID1,const unsigned char ID2, double &musage, double &mtotal)
{
	int Idx=(ID1 * 256) + ID2;
	bool bDeviceExits=true;
	std::stringstream szQuery;
	std::vector<std::vector<std::string> > result;
	szQuery << "SELECT Name, sValue FROM DeviceStatus WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID==" << int(Idx) << ") AND (Type==" << int(pTypeENERGY) << ") AND (Subtype==" << int(sTypeELEC2) << ")";
	result=m_sql.query(szQuery.str());
	if (result.size()<1)
	{
		return false;
	}
	std::vector<std::string> splitresult;
	StringSplit(result[0][1],";",splitresult);
	if (splitresult.size()!=2)
		return false;
	musage=atof(splitresult[0].c_str());
	mtotal=atof(splitresult[1].c_str())/1000.0;
	return true;
}
Exemplo n.º 21
0
void cEnchantments::AddFromString(const AString & a_StringSpec)
{
	// Add enchantments in the stringspec; if a specified enchantment already exists, overwrites it
	
	// Split the StringSpec into separate declarations, each in the form "id=lvl":
	AStringVector Decls = StringSplit(a_StringSpec, ";");
	for (AStringVector::const_iterator itr = Decls.begin(), end = Decls.end(); itr != end; ++itr)
	{
		// Split each declaration into the id and lvl part:
		if (itr->empty())
		{
			// The decl is empty (may happen if there's an extra semicolon at the end), ignore silently
			continue;
		}
		AStringVector Split = StringSplitAndTrim(*itr, "=");
		if (Split.size() != 2)
		{
			// Malformed decl
			LOG("%s: Malformed enchantment decl: \"%s\", skipping.", __FUNCTION__, itr->c_str());
			continue;
		}
		int id = atoi(Split[0].c_str());
		if ((id == 0) && (Split[0] != "0"))
		{
			id = StringToEnchantmentID(Split[0]);
		}
		int lvl = atoi(Split[1].c_str());
		if (
			((id  <= 0) && (Split[0] != "0")) ||
			((lvl == 0) && (Split[1] != "0"))
		)
		{
			// Numbers failed to parse
			LOG("%s: Failed to parse enchantment declaration for numbers: \"%s\" and \"%s\", skipping.",
				__FUNCTION__, Split[0].c_str(), Split[1].c_str()
			);
			continue;
		}
		SetLevel(id, lvl);
	}  // for itr - Decls[]
}
Exemplo n.º 22
0
Element& Document::GetElementByPath(const std::string& path, bool_t* exists)
{
    std::vector<std::string> pathParts;
        
    if (exists != nullptr)
    {
        *exists = false;
    }
    
    StringSplit(pathParts, path, '/');
    
    if (pathParts.size() >= 1)
    {
        Element* currentElement = &this->GetRootElement();
        pathParts.erase(pathParts.begin());
        
        while (pathParts.size())
        {
            bool_t nextElementExists;
            Element& nextElement = currentElement->GetElement(pathParts[0], &nextElementExists);
            
            if (!nextElementExists)
            {
                return this->GetUndefinedElement();    
            }
            
            pathParts.erase(pathParts.begin());
            currentElement = &nextElement;
        }
        
        if (exists != nullptr)
        {
            *exists = true;
        }
        
        return *currentElement;
    }

    return this->GetUndefinedElement();    
}
Exemplo n.º 23
0
bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden)
{
	ASSERT(a_Player != NULL);

	AStringVector Split(StringSplit(a_Command, " "));
	if (Split.empty())
	{
		return false;
	}

	CommandMap::iterator cmd = m_Commands.find(Split[0]);
	if (cmd == m_Commands.end())
	{
		// Command not found
		return false;
	}

	// Ask plugins first if a command is okay to execute the command:
	if (CallHookExecuteCommand(a_Player, Split))
	{
		LOGINFO("Player %s tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player->GetName().c_str(), Split[0].c_str());
		return false;
	}

	if (
		a_ShouldCheckPermissions &&
		!cmd->second.m_Permission.empty() &&
		!a_Player->HasPermission(cmd->second.m_Permission)
	)
	{
		a_Player->SendMessage(Printf("%s[INFO] %sForbidden command; insufficient privileges: \"%s\"", cChatColor::Rose.c_str(), cChatColor::White.c_str(), Split[0].c_str()));
		LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player->GetName().c_str(), Split[0].c_str());
		a_WasCommandForbidden = true;
		return false;
	}

	ASSERT(cmd->second.m_Plugin != NULL);

	return cmd->second.m_Plugin->HandleCommand(Split, a_Player);
}
Exemplo n.º 24
0
//解析 CVS 文件  
bool CCSVParse::openFile(const char* fileName)
{
	string pathKey = CCFileUtils::fullPathFromRelativePath(fileName);
	unsigned char* pBuffer = NULL;
	unsigned long bufferSize = 0;
	pBuffer = CCFileUtils::getFileData(pathKey.c_str(), "r", &bufferSize);

	string s = (char*)pBuffer;
	string str = s.substr(0, bufferSize);

	vector<string> line;
	StringSplit(str, line, '\n');
	for (unsigned int i = 0; i < line.size(); ++i)
	{
		vector<string> field;
		split(field, line[i]);
		data.push_back(field);
		cols = max(cols, (int)field.size());
	}

	return true;
}
Exemplo n.º 25
0
bool cPlayer::HasPermission(const AString & a_Permission)
{
	if (a_Permission.empty())
	{
		// Empty permission request is always granted
		return true;
	}
	
	AStringVector Split = StringSplit(a_Permission, ".");

	// Iterate over all granted permissions; if any matches, then return success:
	for (AStringVectorVector::const_iterator itr = m_SplitPermissions.begin(), end = m_SplitPermissions.end(); itr != end; ++itr)
	{
		if (PermissionMatches(Split, *itr))
		{
			return true;
		}
	}  // for itr - m_SplitPermissions[]

	// No granted permission matches
	return false;
}
Exemplo n.º 26
0
bool CNotificationHelper::SendMessageEx(
	const uint64_t Idx,
	const std::string &Name,
	const std::string &Subsystems,
	const std::string &Subject,
	const std::string &Text,
	const std::string &ExtraData,
	const int Priority,
	const std::string &Sound,
	const bool bFromNotification)
{
	bool bRet = false;
#if defined WIN32
	//Make a system tray message
	ShowSystemTrayNotification(Subject.c_str());
#endif
	std::vector<std::string> sResult;
	StringSplit(Subsystems, ";", sResult);

	std::map<std::string, int> ActiveSystems;

	std::vector<std::string>::const_iterator itt;
	for (itt = sResult.begin(); itt != sResult.end(); ++itt)
	{
		ActiveSystems[*itt] = 1;
	}

	for (it_noti_type iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) {
		std::map<std::string, int>::const_iterator ittSystem = ActiveSystems.find(iter->first);
		if (ActiveSystems.empty() || (ittSystem!=ActiveSystems.end() && iter->second->IsConfigured())) 
		{
			bRet |= iter->second->SendMessageEx(Idx, Name, Subject, Text, ExtraData, Priority, Sound, bFromNotification);
		}
	}
#ifdef USE_PYTHON_PLUGINS
	Plugins::CPluginSystem::SendNotification(Subject, Text, ExtraData, Priority, Sound);
#endif
	return bRet;
}
Exemplo n.º 27
0
bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message)
{
	bool WasCommandForbidden = false;
	if (HandleCommand(a_Player, a_Message, true, WasCommandForbidden))  // We use HandleCommand as opposed to ExecuteCommand to accomodate the need to the WasCommandForbidden bool
	{
		return true;  // Chat message was handled as command
	}
	else if (WasCommandForbidden) // Couldn't be handled as command, was it because of insufficient permissions?
	{
		return true;  // Yes - message was sent in HandleCommand, abort
	}

	// Check if it was a standard command (starts with a slash)
	// If it was, we know that it was completely unrecognised (WasCommandForbidden == false)
	if (!a_Message.empty() && (a_Message[0] == '/'))
	{
		AStringVector Split(StringSplit(a_Message, " "));
		ASSERT(!Split.empty());  // This should not happen - we know there's at least one char in the message so the split needs to be at least one item long
		a_Player->SendMessage(Printf("%s[INFO] %sUnknown command: \"%s\"", cChatColor::Yellow.c_str(), cChatColor::White.c_str(), Split[0].c_str()));
		LOGINFO("Player %s issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str());
		return true;  // Cancel sending
	}

	HookMap::iterator Plugins = m_Hooks.find(HOOK_CHAT);
	if (Plugins == m_Hooks.end())
	{
		return false;
	}

	for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
	{
		if ((*itr)->OnChat(a_Player, a_Message))
		{
			return true;
		}
	}

	return false;
}
Exemplo n.º 28
0
float CDomoticzHardwareBase::GetRainSensorValue(const int NodeID, bool &bExists)
{
	char szIdx[10];
	sprintf(szIdx, "%d", NodeID & 0xFFFF);
	int Unit = 0;

	std::vector<std::vector<std::string> > results;
	results = m_sql.safe_query("SELECT ID,sValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit == %d) AND (Type==%d) AND (Subtype==%d)", m_HwdID, szIdx, Unit, int(pTypeRAIN), int(sTypeRAIN3));
	if (results.size() < 1)
	{
		bExists = false;
		return 0.0f;
	}
	std::vector<std::string> splitresults;
	StringSplit(results[0][1], ";", splitresults);
	if (splitresults.size() != 2)
	{
		bExists = false;
		return 0.0f;
	}
	bExists = true;
	return (float)atof(splitresults[1].c_str());
}
Exemplo n.º 29
0
std::string CDataPush::DropdownOptionsValue(const unsigned long long DeviceRowIdxIn,int pos)
{	
	std::string wording = "???";
	int getpos = pos-1; // 0 pos is always nvalue/status, 1 and higher goes to svalues
	std::vector<std::vector<std::string> > result;
	char szTmp[300];
	
	sprintf(szTmp, "SELECT Type, SubType FROM DeviceStatus WHERE (ID== %llu)", DeviceRowIdxIn);
	result=m_sql.query(szTmp);
	if (result.size()>0)
	{
		int dType=atoi(result[0][0].c_str());
		int dSubType=atoi(result[0][1].c_str());

		std::string sOptions = RFX_Type_SubType_Values(dType,dSubType);
		std::vector<std::string> tmpV; 
		StringSplit(sOptions, ",", tmpV); 
		if ( (int) tmpV.size() >= pos) {
			wording = tmpV[getpos];
		}
	}
	return wording;
}
Exemplo n.º 30
0
void cFurnaceRecipe::AddFuelFromLine(const AString & a_Line, unsigned int a_LineNum)
{
	AString Line(a_Line);
	Line.erase(Line.begin());  // Remove the beginning "!"
	Line.erase(std::remove_if(Line.begin(), Line.end(), isspace), Line.end());

	std::unique_ptr<cItem> Item = cpp14::make_unique<cItem>();
	int BurnTime;

	const AStringVector & Sides = StringSplit(Line, "=");
	if (Sides.size() != 2)
	{
		LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!ParseItem(Sides[0], *Item))
	{
		LOGWARNING("furnace.txt: line %d: Cannot parse item \"%s\".", a_LineNum, Sides[0].c_str());
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	if (!StringToInteger<int>(Sides[1], BurnTime))
	{
		LOGWARNING("furnace.txt: line %d: Cannot parse burn time.", a_LineNum);
		LOGINFO("Offending line: \"%s\"", a_Line.c_str());
		return;
	}

	// Add to fuel list:
	cFuel Fuel;
	Fuel.In = Item.release();
	Fuel.BurnTime = BurnTime;
	m_pState->Fuel.push_back(Fuel);
}