ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An IRC bouncer. 00002 // 00003 //! @file QuestionTarget.cc 00004 //! @brief This file contains the implementation of class QuestionTarget. 00005 // 00006 // Copyright (C) 2006, 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef USE_PCH 00017 #include "sys.h" 00018 #include "debug.h" 00019 #endif 00020 00021 #include "QuestionTarget.h" 00022 #include "Application.h" 00023 #include "MessageIn.h" 00024 #include "keys.h" 00025 #include "ClientSession.h" 00026 #include "Identity.h" 00027 #include "is_channel.h" 00028 00029 /*! @brief Called when a new (client) message is received for this target. 00030 * 00031 * This function handles incoming messages for this target. 00032 */ 00033 void QuestionTarget::new_client_message_received(ClientMessageIn const& msg) 00034 { 00035 DoutEntering(dc::debug, "QuestionTarget::new_client_message_received(" << msg << ") for target \"" << in_name(msg.client_session()) << "\"."); 00036 00037 int param = 1; 00038 switch(msg.key()) 00039 { 00040 case keys::MODE: 00041 case keys::NAMES: 00042 case keys::WHO: 00043 PrivateTarget::new_client_message_received(msg); 00044 return; 00045 case keys::PART: 00046 // Only ask the question when the request for the question still exists. 00047 // M_user_question is reset by a call to reset_user_question() from the destructor of the request object. 00048 if (M_user_question.get()) 00049 create_channel_and_ask_question(); // Make clear we need an answer. 00050 else 00051 PrivateTarget::new_client_message_received(msg); 00052 break; 00053 case keys::JOIN: 00054 // We should already BE on the channel. However, bounce the join back to give a broken client the chance to synchronize. 00055 client_session() << ':' << client_session().client_in_nick() << 00056 '!' << client_session().identity().ident() << '@' << client_session().identity().hostname() << " JOIN " << out_name(client_session()) << "\r\n"; 00057 break; 00058 case keys::CPRIVMSG: 00059 case keys::CNOTICE: 00060 if (!is_channel(in_name(msg.client_session()))) 00061 param = -1; 00062 param = 2; 00063 /* FALL-THROUGH */ 00064 case keys::PRIVMSG: 00065 case keys::NOTICE: 00066 if (param == 1 || param == 2) 00067 { 00068 client_session().user_answer_event_server.trigger(UserAnswerEventType(msg.param(param), client_session(), out_name(client_session()))); 00069 break; 00070 } 00071 /* FALL-THROUGH */ 00072 default: 00073 client_session() << ":Leandro PRIVMSG " << out_name(client_session()) << " :Please type the answer in the channel.\r\n"; 00074 break; 00075 } 00076 } 00077 00078 /*! @brief Ask a question. 00079 * 00080 * Make the user join the associated channel and ask the question. 00081 */ 00082 void QuestionTarget::create_channel_and_ask_question(void) 00083 { 00084 client_session() << ":" << client_session().client_out_nick() << " JOIN " << out_name(client_session()) << "\r\n"; 00085 client_session().create_private_target(out_name(client_session()), client_session().identity().private_network()); 00086 do_names_output(); 00087 client_session() << ":Leandro PRIVMSG " << out_name(client_session()) << " :" << M_user_question->question() << "\r\n"; 00088 }
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|