ircproxy  The Ultimate Cyborg

QuestionTarget Class Reference

#include <QuestionTarget.h>

Inheritance diagram for QuestionTarget:

PrivateTarget Target

List of all members.


Detailed Description

A fake channel that is used for communication between user and ircproxy.

The application can ask questions to the user. Doing so will cause the user to join a new channel where the question will be displayed. Answering the question has to be done on this channel as a public message.

Those public messages will end up being sent to this QuestionTarget object. Also any queries about the channel by the client will end up being sent to this target.

Definition at line 38 of file QuestionTarget.h.


Public Member Functions

 QuestionTarget (ClientSession &client_session, std::string const &target_name, Network &network)
 Construct a QuestionTarget with name target_name, defined uniquely for.
 ~QuestionTarget ()
 Destructor.
 QuestionTarget (QuestionTarget const &question_target)
 Copy-constructor.
void set_user_question (boost::shared_ptr< UserQuestion > const &user_question)
void reset_user_question (void)
void create_channel_and_ask_question (void)
 Ask a question.
virtual void new_client_message_received (ClientMessageIn const &msg)
 Called when a new (client) message is received for this target.

Private Attributes

boost::shared_ptr< UserQuestionM_user_question
 Shared pointer to the associated UserQuestion.

Constructor & Destructor Documentation

QuestionTarget::QuestionTarget ( ClientSession client_session,
std::string const &  target_name,
Network network 
) [inline]

Construct a QuestionTarget with name target_name, defined uniquely for.

Definition at line 45 of file QuestionTarget.h.

References debug::channels::dc::objects.

00045                                                                                                   :
00046         PrivateTarget(client_session, target_name, network)
00047         { Dout(dc::objects, "Constructing QuestionTarget(" <<
00048             client_session << ", \"" << target_name << "\", " << network << ")"); }
#ifdef CWDEBUG

QuestionTarget::~QuestionTarget (  )  [inline]

Destructor.

Definition at line 51 of file QuestionTarget.h.

00051 { Dout(dc::objects, "Destructing QuestionTarget " << *this); }

QuestionTarget::QuestionTarget ( QuestionTarget const &  question_target  )  [inline]

Copy-constructor.

Definition at line 53 of file QuestionTarget.h.

References debug::channels::dc::objects.

00053                                                           : PrivateTarget(question_target)
00054         { Dout(dc::objects, "Copy-constructing QuestionTarget from " << question_target); }


Member Function Documentation

void QuestionTarget::set_user_question ( boost::shared_ptr< UserQuestion > const &  user_question  )  [inline]

Assign the corresponding UserQuestion to this object. Called by UserAnswerEventRequestBase::UserAnswerEventRequestBase.

Definition at line 59 of file QuestionTarget.h.

References M_user_question.

00059 { M_user_question = user_question; }

void QuestionTarget::reset_user_question ( void   )  [inline]

Disconnect UserQuestion from this object again. Called by UserAnswerEventRequestBase::~UserAnswerEventRequestBase.

Definition at line 62 of file QuestionTarget.h.

References M_user_question.

00062 { M_user_question.reset(); }

void QuestionTarget::create_channel_and_ask_question ( void   ) 

Ask a question.

Make the user join the associated channel and ask the question.

Definition at line 82 of file QuestionTarget.cc.

References ClientSession::client_out_nick(), ClientSession::create_private_target(), PrivateTarget::do_names_output(), and M_user_question.

Referenced by new_client_message_received().

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 }

void QuestionTarget::new_client_message_received ( ClientMessageIn const &  msg  )  [virtual]

Called when a new (client) message is received for this target.

This function handles incoming messages for this target.

Reimplemented from PrivateTarget.

Definition at line 33 of file QuestionTarget.cc.

References ClientSession::client_in_nick(), ClientMessageIn::client_session(), create_channel_and_ask_question(), DoutEntering, Identity::hostname(), Identity::ident(), IdentityReference::identity(), is_channel(), MessageIn::key(), M_user_question, PrivateTarget::new_client_message_received(), MessageIn::param(), and ClientSession::user_answer_event_server.

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 }


Member Data Documentation

boost::shared_ptr<UserQuestion> QuestionTarget::M_user_question [private]

Shared pointer to the associated UserQuestion.

Definition at line 40 of file QuestionTarget.h.

Referenced by create_channel_and_ask_question(), new_client_message_received(), reset_user_question(), and set_user_question().


The documentation for this class was generated from the following files:

Copyright © 2005-2007 Carlo Wood.  All rights reserved.