예제 #1
0
static HWND FindWindowHandle(const char *windowTitle)
{
	char buf[CHAR_BUFFER_SIZE];
	std::string searchTitle(windowTitle);
	ToLowerString(searchTitle);
	for (HandleList::iterator it = s_windows->begin(); it != s_windows->end(); ++it)
	{
		GetWindowText(*it, buf, sizeof(buf));
		std::string s(buf);
		ToLowerString(s);
		if (s.find(searchTitle) != -1)
		{
			return *it;
		}
	}
	return 0;
}
예제 #2
0
void IRCMsgThread::onChatMsg(std::wstring channel, std::wstring nickname, bool isOp, std::wstring message){
    //onSysMsg(L"[CHAT] %ls: %ls\n", nickname.c_str(), message.c_str());
	std::wstring lower_name=nickname;
	ToLowerString(lower_name);
	if(lower_name.compare(L"nightbot")!=0&&lower_name.compare(L"moobot")!=0&&lower_name.compare(L"jtv")!=0) {
		TircMsg ircMsg;
		ircMsg.user=nickname;
		ircMsg.msg=message;
		ircMsg.usercolor=GetUserColor(lower_name);
		IRCMsgQueue.push(ircMsg);
	}
}
예제 #3
0
void IRCMsgThread::parseMessage(std::wstring message){
	//Old Style
	//:[email protected] PRIVMSG #ptken :what song is this ?
	//
	//New Style
	//@color=#FF4500;display-name=Gm470520;emotes=;mod=0;room-id=47281189;subscriber=1;turbo=0;user-id=24255667;user-type= :[email protected] PRIVMSG #tetristhegrandmaster3 :這片到底在沖三小w
	//@color=#1E90FF;display-name=pikads;emotes=;mod=1;room-id=24805060;subscriber=0;turbo=0;user-id=25141849;user-type=mod :[email protected] PRIVMSG #ptken :诶
	std::vector<std::wstring> firstParse = split(message,L' ',4);
    if(firstParse.size()<3) return; //Do Nothing
	//parse[0]=@color=#1E90FF;display-name=pikads;emotes=;mod=1;room-id=24805060;subscriber=0;turbo=0;user-id=25141849;user-type=mod
	//parse[1]=:[email protected]
	//parse[2]=PRIVMSG
	//parse[3]=#ptken
	//parse[4]=:诶
    if(!firstParse[2].compare(L"PRIVMSG")){
        std::vector<std::wstring> parse = split(message,L' ',5);
		if(parse.size() < 5) return; //discard this incomplete message
        /*
         * parse[1].substr(1): sender
         * parse[3]: target channel/user
         * parse[4].subString(1): message
         */
		//std::wstring sender = getUsername(parse[1].substr(1)); Old Style
		std::wstring sender = getUsername(parse[0].substr(1),parse[1].substr(1));
		std::wstring target = parse[3]; //maybe need .c_str(), but never used in the plugin
		std::wstring content = parse[4].substr(1);
        if(parse[3][0]==L'#'){
            if(!content.substr(0,8).compare(L"ACTION ")){
                //onChatAction(target, sender, replaceFirst(content.substr(8),L"", L"").c_str());
				onChatAction(target, sender, content);
            }else{
                onChatMsg(target, sender, false, content);
            }
        }else{
            onPrivateMsg(sender, content); //not sure about the number of tokens, but for a plugin, never mind.
        }
        
    }else if(!firstParse[1].compare(L"JOIN")){ //JOIN: LOG to [SYS]
        std::vector<std::wstring> parse = split(message,L' ',3);
		if(parse.size() < 3) return; //discard this incomplete message
        if(!(parse[2].compare(ToLowerString(ircbotPtr->lastIRCChannel)))){ //user succesffully joins a channel
//            onSysMsg(L"Joined %ls",parse[2]);
        }
	/*	else { //other users join the channel
			onIRCMsg(L"%ls Joined %ls\n",getUsername(parse[0].substr(1)).c_str(),parse[2].c_str());
		}*/
		
    }else if(!firstParse[1].compare(L"001")){ //login successful        
        ircbotPtr->loginSuccessful = true;
        ircbotPtr->onLoginSuccess();
    }
}
예제 #4
0
std::wstring IRCMsgThread::getUsername(std::wstring sender,std::wstring backup){
    //parse twitch username from twitch chats
    //Old Style: ex: [email protected] -> user	
    /*if(sender.find(L"!")!=std::wstring::npos){
        return sender.substr(0,sender.find(L"!"));
    } else return sender;*/
	//New Style: ex: color=#1E90FF;display-name=pikads;emotes=;mod=1;room-id=24805060;subscriber=0;turbo=0;user-id=25141849;user-type=mod
	//@badges=;color=#F6BFB5;display-name=F6BFB5;emotes=;mod=0;room-id=47281189;subscriber=1;turbo=0;user-id=23745737;user-type= :[email protected] PRIVMSG #tetristhegrandmaster3 :我以榮耀作戰

	//if the number of tokens is wrong, return Old Style username
	std::vector<std::wstring> tag_parse = split(sender,L';',9);
	if(tag_parse.size()<9) return getBackupUsername(backup);
	
	std::wstring name;
	for(int i=0;i<tag_parse.size();i++) {
		//std::vector<std::wstring> name_parse = split(tag_parse[1],L'=',2);	
		//if(name_parse.size()<2) name = getBackupUsername(backup);	

		std::vector<std::wstring> name_parse = split(tag_parse[i],L'=',2);	
		if(name_parse[0].compare(L"display-name")==0) {
			if(name_parse.size()<2) name = getBackupUsername(backup); //old-style	
			else {	//New style username	
				name=name_parse[1]; //return name when displayname has something
			}
		}
		if(name_parse[0].compare(L"color")==0) {
			//set color when color has something
			//color: SetUserColor(std::wstring User,std::wstring Color), need lowercase
			//std::vector<std::wstring> color_parse = split(tag_parse[0],L'=',2);		
			//if(color_parse.size()==2) SetUserColor(ToLowerString(lower_name),ToLowerString(color_parse[1])); 
			if(name_parse.size()==2) {
				std::wstring lower_name=getBackupUsername(backup);
				SetUserColor(ToLowerString(lower_name),ToLowerString(name_parse[1]));
			}; 
		}
	}
	
	return name;
}
예제 #5
0
파일: Process.c 프로젝트: k2b3d/authsrc
void BatchProcess(char *UserID, char *DeviceType)
{
    int	i;
    int	RealCount = 0;
    UUID_T	*UUIDList;

    int	Count, ErrorCode = NO_ERROR;

    Count = 0;
    UUIDList = DB_UUIDSelectByUserNDeviceType(UserID, DeviceType, &Count, &ErrorCode);
    if(ErrorCode == MYSQL_EXCEPTION) {
        printLog(HEAD, "<<<MyDBC Exception Error program exits now...>>>\n");
        exit(-1);
    }
    printLog(HEAD, "++++++++++++++++++UUID Product Records++++++++++++++++++(%d)\n", Count);
    for(i = 0; i < Count; i++)	{
//		printLog(HEAD, "(%04d/%04d) UUID(%s)ProductID(%s)\n", i, Count, UUIDList[i].UUID, UUIDList[i].ProductID);
    }
    printLog(HEAD, "++++++++++++++++++UUID Product Records++++++++++++++++++(%d)\n", Count);
    for(i = 0; i < Count; i++)	{
        if(IsUpperString(UUIDList[i].UUID) > 1)	{
            ToLowerString(UUIDList[i].UUID);
            if((ErrorCode = DB_UpdateUUID(UUIDList[i], UserID, DeviceType)) == NO_ERROR)	{
                printLog(HEAD, "RealCount(%d) UUID(%s)ProductID(%s) really updated\n", ++RealCount, UUIDList[i].UUID, UUIDList[i].ProductID);
            }
            else	{
                //	(ErrorCode == MYSQL_EXCEPTION) {
                printLog(HEAD, "<<<MyDBC Exception Error program exits now...>>>\n");
                exit(-1);
            }
        }
    }
    printLog(HEAD, "Update UUID Count(%d) Processing Finished\n", Count);
    if(Count > 0)
        free(UUIDList);
}
예제 #6
0
CFilterElementHide::CFilterElementHide(const std::wstring& filterText)
  : m_filterText(filterText), m_type(ETraverserComplexType::TRAVERSER_TYPE_ERROR)
{
  std::wstring filterSuffix(filterText); // The unparsed remainder of the input filter text

  // Find tag name, class or any (*)
  wchar_t firstTag = filterText[0];
  if (firstTag == '*')
  {
    // Any tag
    filterSuffix = filterSuffix.substr(1);
  }
  else if (firstTag == '[' || firstTag == '.' || firstTag == '#')
  {
    // Any tag (implicitly)
  }
  else if (isalnum(firstTag))
  {
    // Real tag
    // TODO: Add support for descendant selectors
    auto pos = filterSuffix.find_first_of(L".#[(");
    if (pos == std::wstring::npos)
    {
      pos = filterSuffix.length();
    }
    m_tag = ToLowerString(filterSuffix.substr(0, pos));
    filterSuffix = filterSuffix.substr(pos);
  }
  else
  {
    // Error
    throw ElementHideParseException(filterText, "invalid tag");
  }

  // Find Id and class name
  if (!filterSuffix.empty())
  {
    wchar_t firstId = filterSuffix[0];

    // Id
    if (firstId == '#')
    {
      auto pos = filterSuffix.find('[');
      if (pos == std::wstring::npos)
      {
        pos = filterSuffix.length();
      }
      m_tagId = filterSuffix.substr(1, pos - 1);
      filterSuffix = filterSuffix.substr(pos);
      pos = m_tagId.find(L".");
      if (pos != std::wstring::npos)
      {
        if (pos == 0)
        {
          throw ElementHideParseException(filterText, "empty tag id");
        }
        m_tagClassName = m_tagId.substr(pos + 1);
        m_tagId = m_tagId.substr(0, pos);
      }
    }
    // Class name
    else if (firstId == '.')
    {
      auto pos = filterSuffix.find('[');
      if (pos == std::wstring::npos)
      {
        pos = filterSuffix.length();
      }
      m_tagClassName = filterSuffix.substr(1, pos - 1);
      filterSuffix = filterSuffix.substr(pos);
    }
  }

  while (!filterSuffix.empty())
  {
    if (filterSuffix[0] != '[')
    {
      throw ElementHideParseException(filterText, "expected '['");
    }
    auto endPos = filterSuffix.find(']') ;
    if (endPos == std::wstring::npos)
    {
      throw ElementHideParseException(filterText, "expected ']'");
    }
    std::wstring arg = filterSuffix.substr(1, endPos - 1);
    filterSuffix = filterSuffix.substr(endPos + 1);

    CFilterElementHideAttrSelector attrSelector;
    auto posEquals = arg.find('=');
    if (posEquals != std::wstring::npos)
    {
      if (posEquals == 0)
      {
        throw ElementHideParseException(filterText, "empty attribute name before '='");
      }
      attrSelector.m_value = arg.substr(posEquals + 1);
      if (attrSelector.m_value.length() >= 2 && attrSelector.m_value[0] == '\"' && attrSelector.m_value[attrSelector.m_value.length() - 1] == '\"')
      {
        attrSelector.m_value = attrSelector.m_value.substr(1, attrSelector.m_value.length() - 2);
      }

      if (arg[posEquals - 1] == '^')
      {
        attrSelector.m_pos = CFilterElementHideAttrPos::STARTING;
      }
      else if (arg[posEquals - 1] == '*')
      {
        attrSelector.m_pos = CFilterElementHideAttrPos::ANYWHERE;
      }
      else if (arg[posEquals - 1] == '$')
      {
        attrSelector.m_pos = CFilterElementHideAttrPos::ENDING;
      }
      if (attrSelector.m_pos != CFilterElementHideAttrPos::POS_NONE)
      {
        if (posEquals == 1)
        {
          throw ElementHideParseException(filterText, "empty attribute name before " + std::string(1, static_cast<char>(arg[0])) + "'='");
        }
        attrSelector.m_attr = arg.substr(0, posEquals - 1);
      }
      else
      {
        attrSelector.m_pos = CFilterElementHideAttrPos::EXACT;
        attrSelector.m_attr = arg.substr(0, posEquals);
      }
    }

    if (attrSelector.m_attr == L"style")
    {
      attrSelector.m_type = CFilterElementHideAttrType::STYLE;
      attrSelector.m_value = ToLowerString(attrSelector.m_value);
    }
    else if (attrSelector.m_attr == L"id")
    {
      attrSelector.m_type = CFilterElementHideAttrType::ID;
    }
    else if (attrSelector.m_attr == L"class")
    {
      attrSelector.m_type = CFilterElementHideAttrType::CLASS;
    }
    m_attributeSelectors.push_back(attrSelector);
  }

  // End check
  if (!filterSuffix.empty())
  {
    throw ElementHideParseException(filterText, "extra characters at end");
  }
}
예제 #7
0
bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const
{
  HRESULT hr;
  /*
   * If a tag id is specified, it must match
   */
  if (!m_tagId.empty())
  {
    CComBSTR idBstr;
    if (FAILED(pEl->get_id(&idBstr)) || !idBstr || m_tagId != ToWstring(idBstr))
    {
      return false;
    }
  }
  /*
   * If a class name is specified, it must match
   */
  if (!m_tagClassName.empty())
  {
    CComBSTR classNameListBstr;
    hr = pEl->get_className(&classNameListBstr);
    if (FAILED(hr) || !classNameListBstr)
    {
      return false; // We can't match a class name if there's no class name
    }
    std::wstring classNameList(ToWstring(classNameListBstr));
    if (classNameList.empty())
    {
      return false;
    }
    // TODO: Consider case of multiple classes. (m_tagClassName can be something like "foo.bar")
    /*
     * Match when 'm_tagClassName' appears as a token within classNameList
     */
    bool foundMatch = false;
    wchar_t* nextToken = nullptr;
    const wchar_t* token = wcstok_s(&classNameList[0], L" ", &nextToken);
    while (token != nullptr)
    {
      if (std::wstring(token) == m_tagClassName)
      {
        foundMatch = true;
        break;
      }
      token = wcstok_s(nullptr, L" ", &nextToken);
    }
    if (!foundMatch)
    {
      return false;
    }
  }
  /*
   * If a tag name is specified, it must match
   */
  if (!m_tag.empty())
  {
    CComBSTR tagNameBstr;
    if (FAILED(pEl->get_tagName(&tagNameBstr)) || !tagNameBstr)
    {
      return false;
    }
    if (m_tag != ToLowerString(ToWstring(tagNameBstr)))
    {
      return false;
    }
  }
  /*
   * Match each attribute
   */
  for (auto attrIt = m_attributeSelectors.begin(); attrIt != m_attributeSelectors.end(); ++attrIt)
  {
    std::wstring value;
    bool attrFound = false;
    if (attrIt->m_type == CFilterElementHideAttrType::STYLE)
    {
      CComPtr<IHTMLStyle> pStyle;
      if (SUCCEEDED(pEl->get_style(&pStyle)) && pStyle)
      {
        CComBSTR styleBstr;
        if (SUCCEEDED(pStyle->get_cssText(&styleBstr)) && styleBstr)
        {
          value = ToLowerString(ToWstring(styleBstr));
          attrFound = true;
        }
      }
    }
    else if (attrIt->m_type == CFilterElementHideAttrType::CLASS)
    {
      CComBSTR classNamesBstr;
      if (SUCCEEDED(pEl->get_className(&classNamesBstr)) && classNamesBstr)
      {
        value = ToWstring(classNamesBstr);
        attrFound = true;
      }
    }
    else if (attrIt->m_type == CFilterElementHideAttrType::ID)
    {
      CComBSTR idBstr;
      if (SUCCEEDED(pEl->get_id(&idBstr)) && idBstr)
      {
        value = ToWstring(idBstr);
        attrFound = true;
      }
    }
    else
    {
      CComBSTR attrArgument(attrIt->m_attr.length(), attrIt->m_attr.c_str());
      auto x = GetHtmlElementAttribute(*pEl, attrArgument);
      attrFound = x.isAttributeFound;
      if (attrFound)
      {
        value = x.attributeValue;
      }
    }

    if (attrFound)
    {
      if (attrIt->m_pos == CFilterElementHideAttrPos::EXACT)
      {
        // TODO: IE rearranges the style attribute completely. Figure out if anything can be done about it.
        if (value != attrIt->m_value)
          return false;
      }
      else if (attrIt->m_pos == CFilterElementHideAttrPos::STARTING)
      {
        if (value.compare(0, attrIt->m_value.length(), attrIt->m_value) != 0)
          return false;
      }
      else if (attrIt->m_pos == CFilterElementHideAttrPos::ENDING)
      {
        size_t valueLength = value.length();
        size_t attrLength = attrIt->m_value.length();
        if (valueLength < attrLength)
          return false;
        if (value.compare(valueLength - attrLength, attrLength, attrIt->m_value) != 0)
          return false;
      }
      else if (attrIt->m_pos == CFilterElementHideAttrPos::ANYWHERE)
      {
        if (value.find(attrIt->m_value) == std::wstring::npos)
          return false;
      }
      else if (attrIt->m_value.empty())
      {
        return true;
      }
    }
    else
    {
      return false;
    }
  }

  if (m_predecessor)
  {
    CComPtr<IHTMLElement> pDomPredecessor;
    HRESULT hr = S_FALSE;
    switch (m_predecessor->m_type)
    {
    case ETraverserComplexType::TRAVERSER_TYPE_PARENT:
      hr = pEl->get_parentElement(&pDomPredecessor);
      break;
    case ETraverserComplexType::TRAVERSER_TYPE_IMMEDIATE:
      hr = S_FALSE;
      CComQIPtr<IHTMLDOMNode> pPrevSiblingNode = pEl;
      long type = 0;
      while (pPrevSiblingNode && type != 1)
      {
        IHTMLDOMNode* tmpNode;
        pPrevSiblingNode->get_previousSibling(&tmpNode);
        pPrevSiblingNode.Attach(tmpNode);
        if (pPrevSiblingNode)
        {
          hr = pPrevSiblingNode->get_nodeType(&type);
          if (hr != S_OK)
            pPrevSiblingNode.Release();
        }
      }

      if (pPrevSiblingNode)
        hr = pPrevSiblingNode.QueryInterface(&pDomPredecessor);
      else
        return false;
      break;
    }
    if (hr != S_OK)
      return false;
    return m_predecessor->IsMatchFilterElementHide(pDomPredecessor);
  }

  return true;
}
예제 #8
0
void NameProcess(std::string &c) {
	Trim(c);
	ToLowerString(c);
	UpcaseFirstSpace(c);
}