ModResult DoMsg(User *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list, bool privmsg) { if (!IS_LOCAL(user) || target_type != TYPE_CHANNEL || status) return MOD_RES_PASSTHRU; Channel* chan = static_cast<Channel*>(dest); ModResult res = ServerInstance->OnCheckExemption(user,chan,"opmoderated"); if (res == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; if (!chan->GetExtBanStatus(user, 'u').check(!chan->IsModeSet(&mh)) && chan->GetPrefixValue(user) < VOICE_VALUE) { FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list)); chan->WriteAllExcept(user, false, '@', exempt_list, "%s @%s :%s", privmsg ? "PRIVMSG" : "NOTICE", chan->name.c_str(), text.c_str()); if (privmsg) { FOREACH_MOD(I_OnUserMessage,OnUserMessage(user,chan,TYPE_CHANNEL,text,'@',exempt_list)); } else FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,'@',exempt_list)); return MOD_RES_DENY; } return MOD_RES_PASSTHRU; }
// // 新しい文字列を追加して、パーサを回す。 // void XmlParser::Parse(const std::string &toAppend) { for(std::string::size_type i = 0; i < toAppend.length(); ++i) { switch(ParserState) { case ST_TEXT: // ST_TEXTの間は、要素の先頭を探す。見つからない間はテキストを解析しているとして扱う。 if(toAppend[i] == '<') { if(buffer.length() > 0) { OnText(buffer); buffer.clear(); } ParserState = ST_ELEMENT; } else { buffer += toAppend[i]; } break; case ST_ELEMENT: // ST_ELEMENTの間は、要素の終了('>')を探す。 if(toAppend[i] == '>') { ParseElement(buffer); buffer.clear(); ParserState = ST_TEXT; } else { buffer += toAppend[i]; } break; } } return; }
void CModelReaderNode::parseContent(_In_ CXmlReader * pXMLReader) { __NMRASSERT(pXMLReader); if (m_sName == L"") throw CNMRException(NMR_ERROR_NODENAMEISEMPTY); if (m_bParsedContent) throw CNMRException(NMR_ERROR_ALREADYPARSEDXMLNODE); m_bParsedContent = true; if (m_bIsEmptyElement) return; while (!pXMLReader->IsEOF()) { LPCWSTR pwszQualifiedName = nullptr; LPCWSTR pwszText = nullptr; UINT nCount = 0; eXmlReaderNodeType NodeType; pXMLReader->Read(NodeType); switch (NodeType) { case XMLREADERNODETYPE_STARTELEMENT: pXMLReader->GetQualifiedName(&pwszQualifiedName, &nCount); if (!pwszQualifiedName) throw CNMRException(NMR_ERROR_COULDNOTGETQUALIFIEDXMLNAME); if (nCount > 0) OnChildElement(pwszQualifiedName, pXMLReader); break; case XMLREADERNODETYPE_TEXT: pXMLReader->GetValue(&pwszText, &nCount); if (!pwszText) throw CNMRException(NMR_ERROR_COULDNOTGETXMLTEXT); if (nCount > 0) OnText(pwszText, pXMLReader); break; case XMLREADERNODETYPE_ENDELEMENT: pXMLReader->GetQualifiedName(&pwszQualifiedName, &nCount); if (!pwszQualifiedName) throw CNMRException(NMR_ERROR_COULDNOTGETQUALIFIEDXMLNAME); if (wcscmp(pwszQualifiedName, m_sName.c_str()) == 0) { OnEndElement (pXMLReader); return; } break; case XMLREADERNODETYPE_UNKNOWN: break; } } }
TEST_F(LocalConnectionTest, recv_text) { const Text kExpected(text_); Connection::Ptr conn(LocalConnection::New()); Connection::Ptr other(((LocalConnection*) conn.get())->other()); ConnectionDelegateMock mock; EXPECT_CALL(mock, OnText(conn.get(), kExpected)); conn->BindDelegate(&mock); other->SendText(text_); }
void OnCommand( HWND hWnd, WPARAM wParam ) { switch( LOWORD(wParam) ) { case 1001: if( HIWORD(wParam)==CBN_SELCHANGE ) { HWND hSimple = GetDlgItem( hWnd, 1001 ); HWND hDropDown = GetDlgItem( hWnd, 1002 ); HWND hDropList = GetDlgItem( hWnd, 1003 ); LRESULT nSel = SendMessage( hSimple, CB_GETCURSEL, 0, 0 ); SendMessage(hDropDown,CB_SETCURSEL,nSel,0); SendMessage(hDropList,CB_SETCURSEL,nSel,0); }else if( HIWORD(wParam)==CBN_EDITCHANGE ) { MessageBox(hWnd,"键盘输入内容有变化","Infor", MB_OK ); } break; case ID_DATA: OnData( hWnd );//获取选择项的附加数据 break; case ID_TEXT: OnText( hWnd );//获取选择项文本内容 break; case ID_FIND: OnFind( hWnd );//匹配选项 break; case ID_DELETE: OnDelete( hWnd );//删除选择项 break; case ID_CLEAR: OnClear( hWnd );//清空选项 break; case ID_ADD: OnAdd( hWnd );//添加选项 break; } }
void OnCommand(HWND hWnd,WPARAM wParam){ switch(LOWORD(wParam)){ case 1001: if(HIWORD(wParam) == CBN_SELCHANGE){ HWND hSimple = GetDlgItem(hWnd,1001); HWND hDropDown = GetDlgItem(hWnd,1002); HWND hDropList = GetDlgItem(hWnd,1003); LRESULT nRet = SendMessage(hSimple,CB_GETCURSEL,0,0); SendMessage(hDropDown,CB_SETCURSEL,nRet,0); SendMessage(hDropList,CB_SETCURSEL,nRet,0); } else if(HIWORD(wParam) == CBN_EDITCHANGE ){ MessageBox(hWnd,"Keyboard Input changes","Info",MB_OK); } break; case ID_DATA: OnData(hWnd); break; case ID_DIR: OnDir(hWnd); break; case ID_TEXT: OnText(hWnd); break; case ID_FIND: OnFind(hWnd); break; case ID_ADD: OnAdd(hWnd); break; case ID_CLEAN: OnClean(hWnd); break; case ID_DELETE: OnDelete(hWnd); break; } }
CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, User *user) { User *dest; Channel *chan; CUList except_list; LocalUser* localuser = IS_LOCAL(user); if (localuser) localuser->idle_lastmsg = ServerInstance->Time(); if (ServerInstance->Parser->LoopCall(user, this, parameters, 0)) return CMD_SUCCESS; if (parameters[0][0] == '$') { if (!user->HasPrivPermission("users/mass-message")) return CMD_SUCCESS; ModResult MOD_RESULT; std::string temp = parameters[1]; FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list, MSG_PRIVMSG)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; const char* text = temp.c_str(); const char* servermask = (parameters[0].c_str()) + 1; FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list)); if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL)) { user->SendAll("PRIVMSG", "%s", text); } FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, MSG_PRIVMSG)); return CMD_SUCCESS; } char status = 0; const char* target = parameters[0].c_str(); if (ServerInstance->Modes->FindPrefix(*target)) { status = *target; target++; } if (*target == '#') { chan = ServerInstance->FindChan(target); except_list.insert(user); if (chan) { if (localuser && chan->GetPrefixValue(user) < VOICE_VALUE) { if (chan->IsModeSet('n') && !chan->HasUser(user)) { user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str()); return CMD_FAILURE; } if (chan->IsModeSet('m')) { user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str()); return CMD_FAILURE; } if (ServerInstance->Config->RestrictBannedUsers) { if (chan->IsBanned(user)) { user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str()); return CMD_FAILURE; } } } ModResult MOD_RESULT; std::string temp = parameters[1]; FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, chan, TYPE_CHANNEL, temp, status, except_list, MSG_PRIVMSG)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; const char* text = temp.c_str(); /* Check again, a module may have zapped the input string */ if (temp.empty()) { user->WriteNumeric(412, "%s :No text to send", user->nick.c_str()); return CMD_FAILURE; } FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,except_list)); if (status) { if (ServerInstance->Config->UndernetMsgPrefix) { chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%c %s", status, chan->name.c_str(), status, text); } else { chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %c%s :%s", status, chan->name.c_str(), text); } } else { chan->WriteAllExcept(user, false, status, except_list, "PRIVMSG %s :%s", chan->name.c_str(), text); } FOREACH_MOD(I_OnUserMessage, OnUserMessage(user,chan, TYPE_CHANNEL, text, status, except_list, MSG_PRIVMSG)); } else { /* no such nick/channel */ user->WriteNumeric(401, "%s %s :No such nick/channel", user->nick.c_str(), target); return CMD_FAILURE; } return CMD_SUCCESS; } const char* destnick = parameters[0].c_str(); if (localuser) { const char* targetserver = strchr(destnick, '@'); if (targetserver) { std::string nickonly; nickonly.assign(destnick, 0, targetserver - destnick); dest = ServerInstance->FindNickOnly(nickonly); if (dest && strcasecmp(dest->server.c_str(), targetserver + 1)) { /* Incorrect server for user */ user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str()); return CMD_FAILURE; } } else dest = ServerInstance->FindNickOnly(destnick); } else dest = ServerInstance->FindNick(destnick); if ((dest) && (dest->registered == REG_ALL)) { if (parameters[1].empty()) { user->WriteNumeric(412, "%s :No text to send", user->nick.c_str()); return CMD_FAILURE; } if (dest->IsAway()) { /* auto respond with aweh msg */ user->WriteNumeric(301, "%s %s :%s", user->nick.c_str(), dest->nick.c_str(), dest->awaymsg.c_str()); } ModResult MOD_RESULT; std::string temp = parameters[1]; FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, except_list, MSG_PRIVMSG)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; const char* text = temp.c_str(); FOREACH_MOD(I_OnText,OnText(user, dest, TYPE_USER, text, 0, except_list)); if (IS_LOCAL(dest)) { // direct write, same server user->WriteTo(dest, "PRIVMSG %s :%s", dest->nick.c_str(), text); } FOREACH_MOD(I_OnUserMessage,OnUserMessage(user, dest, TYPE_USER, text, 0, except_list, MSG_PRIVMSG)); } else { /* no such nick/channel */ user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str()); return CMD_FAILURE; } return CMD_SUCCESS; }
void Widget::HandleEvent( const sf::Event& event ) { if( !IsVisible() ) { return; } // Set widget active in context. Context::Get().SetActiveWidget( shared_from_this() ); Container::Ptr parent( m_parent.lock() ); switch( event.Type ) { case sf::Event::MouseMoved: // Check if pointer inside of widget's allocation. if( GetAllocation().Contains( static_cast<float>( event.MouseMove.X ), static_cast<float>( event.MouseMove.Y ) ) ) { // Check for enter event. if( m_mouse_in == false ) { m_mouse_in = true; OnMouseEnter(); HandleMouseEnter( event.MouseMove.X, event.MouseMove.Y ); } OnMouseMove(); } else if( m_mouse_in == true ) { // Check for leave event. m_mouse_in = false; OnMouseLeave(); HandleMouseLeave( event.MouseMove.X, event.MouseMove.Y ); } HandleMouseMoveEvent( event.MouseMove.X, event.MouseMove.Y ); break; case sf::Event::MouseButtonPressed: // If a mouse button has already been pressed for this widget, drop further // presses. This maybe needs changing, but up to now, I can't think of any // cases where it would be useful to have such a functionality. if( m_mouse_button_down == -1 ) { if( m_mouse_in ) { m_mouse_button_down = event.MouseButton.Button; HandleMouseButtonEvent( event.MouseButton.Button, true, event.MouseButton.X, event.MouseButton.Y ); OnMouseButtonPress(); } } break; case sf::Event::MouseButtonReleased: // Only process when mouse button has been clicked inside the widget before. if( m_mouse_button_down == event.MouseButton.Button ) { m_mouse_button_down = -1; // When released inside the widget, the event can be considered a click. if( m_mouse_in ) { HandleMouseClick( event.MouseButton.Button, event.MouseButton.X, event.MouseButton.Y ); } OnMouseButtonRelease(); } HandleMouseButtonEvent( event.MouseButton.Button, false, event.MouseButton.X, event.MouseButton.Y ); break; case sf::Event::KeyPressed: if( GetState() == Active ) { // TODO: Delegate event too when widget's not active? HandleKeyEvent( event.Key.Code, true ); OnKeyPress(); } break; case sf::Event::KeyReleased: if( GetState() == Active ) { // TODO: Delegate event too when widget's not active? HandleKeyEvent( event.Key.Code, false ); OnKeyRelease(); } break; case sf::Event::TextEntered: if( GetState() == Active ) { // TODO: Delegate event too when widget's not active? HandleTextEvent( event.Text.Unicode ); OnText(); } break; default: break; } }
CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, User *user) { User *dest; Channel *chan; CUList exempt_list; user->idle_lastmsg = ServerInstance->Time(); if (ServerInstance->Parser->LoopCall(user, this, parameters, 0)) return CMD_SUCCESS; if (parameters[0][0] == '$') { if (!user->HasPrivPermission("users/mass-message")) return CMD_SUCCESS; int MOD_RESULT = 0; std::string temp = parameters[1]; FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, exempt_list)); if (MOD_RESULT) return CMD_FAILURE; const char* text = temp.c_str(); const char* servermask = (parameters[0].c_str()) + 1; FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list)); if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL)) { user->SendAll("NOTICE", "%s", text); } FOREACH_MOD(I_OnUserNotice,OnUserNotice(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list)); return CMD_SUCCESS; } char status = 0; const char* target = parameters[0].c_str(); if (ServerInstance->Modes->FindPrefix(*target)) { status = *target; target++; } if (*target == '#') { chan = ServerInstance->FindChan(target); exempt_list[user] = user->nick; if (chan) { if (IS_LOCAL(user)) { if ((chan->IsModeSet('n')) && (!chan->HasUser(user))) { user->WriteNumeric(404, "%s %s :Cannot send to channel (no external messages)", user->nick.c_str(), chan->name.c_str()); return CMD_FAILURE; } if ((chan->IsModeSet('m')) && (chan->GetStatus(user) < STATUS_VOICE)) { user->WriteNumeric(404, "%s %s :Cannot send to channel (+m)", user->nick.c_str(), chan->name.c_str()); return CMD_FAILURE; } } int MOD_RESULT = 0; std::string temp = parameters[1]; FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,chan,TYPE_CHANNEL,temp,status, exempt_list)); if (MOD_RESULT) { return CMD_FAILURE; } const char* text = temp.c_str(); if (temp.empty()) { user->WriteNumeric(412, "%s :No text to send", user->nick.c_str()); return CMD_FAILURE; } FOREACH_MOD(I_OnText,OnText(user,chan,TYPE_CHANNEL,text,status,exempt_list)); if (status) { if (ServerInstance->Config->UndernetMsgPrefix) { chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%c %s", status, chan->name.c_str(), status, text); } else { chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %c%s :%s", status, chan->name.c_str(), text); } } else { chan->WriteAllExcept(user, false, status, exempt_list, "NOTICE %s :%s", chan->name.c_str(), text); } FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,chan,TYPE_CHANNEL,text,status,exempt_list)); } else { /* no such nick/channel */ user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target); return CMD_FAILURE; } return CMD_SUCCESS; } const char* destnick = parameters[0].c_str(); if (IS_LOCAL(user)) { const char* targetserver = strchr(destnick, '@'); if (targetserver) { std::string nickonly; nickonly.assign(destnick, 0, targetserver - destnick); dest = ServerInstance->FindNickOnly(nickonly); if (dest && strcasecmp(dest->server, targetserver + 1)) { /* Incorrect server for user */ user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str()); return CMD_FAILURE; } } else dest = ServerInstance->FindNickOnly(destnick); } else dest = ServerInstance->FindNick(destnick); if (dest) { if (parameters[1].empty()) { user->WriteNumeric(412, "%s :No text to send", user->nick.c_str()); return CMD_FAILURE; } int MOD_RESULT = 0; std::string temp = parameters[1]; FOREACH_RESULT(I_OnUserPreNotice,OnUserPreNotice(user,dest,TYPE_USER,temp,0,exempt_list)); if (MOD_RESULT) { return CMD_FAILURE; } const char* text = temp.c_str(); FOREACH_MOD(I_OnText,OnText(user,dest,TYPE_USER,text,0,exempt_list)); if (IS_LOCAL(dest)) { // direct write, same server user->WriteTo(dest, "NOTICE %s :%s", dest->nick.c_str(), text); } FOREACH_MOD(I_OnUserNotice,OnUserNotice(user,dest,TYPE_USER,text,0,exempt_list)); } else { /* no such nick/channel */ user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str()); return CMD_FAILURE; } return CMD_SUCCESS; }