From dacd393fefeabafd1306533dd6c5a56e0ab347cc Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 27 Feb 2011 18:48:35 +0100 Subject: Initial commit --- TChannel.cpp | 278 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 TChannel.cpp (limited to 'TChannel.cpp') diff --git a/TChannel.cpp b/TChannel.cpp new file mode 100644 index 0000000..a242605 --- /dev/null +++ b/TChannel.cpp @@ -0,0 +1,278 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#include "TChannel.h" + +extern list plugins; + +TChannel::TChannel (string channame,TConnection* parent_) +{ + name=channame; + cout << "new TChannel ("<< channame << "," << parent_ << ")" << endl; + + parent=parent_; + + receiving_names_list=false; + + ircmessage curr_msg; + curr_msg.origin=""; curr_msg.content=""; curr_msg.command=""; curr_msg.params=""; + + for (list::iterator it=plugins.begin(); it!=plugins.end(); it++) + { + TPluginParent::hiddenaddplugincontext((*it)->get_default_flags_for_channels(), (*it)->get_context_size()); + if (contexts.rbegin()->flags & PFLAGS_EXEC_ONCREATE) + (*it)->execute( &(*(contexts.rbegin())) , curr_msg, this, PFLAGS_EXEC_ONCREATE); + } + + parent->send("mode "+name+NEWLINE); +} +TChannel::~TChannel () +{ + cout << "~TChannel (" << name << ")" << endl; + + cout << "executing all plugins with the ONDESTROY flag set..." << endl; + list::iterator it2=plugins.begin(); + + ircmessage curr_msg=static_cast(parent)->get_curr_msg(); + + for (list::iterator it=contexts.begin(); it!=contexts.end(); it++) + { + if (it->flags & PFLAGS_EXEC_ONDESTROY) + (*it2)->execute( &(*it) , curr_msg, this, PFLAGS_EXEC_ONDESTROY); + + it2++; + } +} + +void TChannel::show_users() +{ + list::iterator it; + cout << "---------userlist von "< l=parsemodes(msg.params); + for (list::iterator it=l.begin(); it!=l.end(); it++) //TODO + { + string what=it->mode; + string who=it->param; + + string hasmode; + switch (it->mode[1]) + { + case 'q': + case 'a': + case 'o': + case 'h': + case 'v': + hasmode=users.get_info(it->param); + if (it->mode[0]=='+') //added a mode? + { + if (numchanperm(it->mode.substr(1)) > numchanperm(hasmode)) //added a better mode than the user previously had? if not, ignore. + hasmode=it->mode[1]; + } + else // removed a mode? + { + if (it->mode.substr(1)==hasmode) //removed the mode a user has? better and "worse" modes can be ignored. + { + if (it->mode[1]=='v') //removed voice? then the result is "nothing" + { + hasmode=""; + } + else //removed something different than voice? + { + parent->send ("names "+name+NEWLINE); + } + } + } + users.edit(it->param,hasmode); + break; + case 'b': //ignore; do not send a /mode message + break; + default: + parent->send ("mode "+name+NEWLINE); + break; + } + } + + } + + } + + if (ucase(msg.command)=="TOPIC") + if (ucase(msg.params)==ucase(name)) + chantopic=msg.content; + + int pos,pos2; + string where; + switch (atoi(msg.command.c_str())) + { + case 353: if (lcase(msg.params.substr(msg.params.rfind(' ')+1))==lcase(name)) + { + if (!receiving_names_list) + { + users.clear(); + receiving_names_list=true; + } + string temp; + string temp2=msg.content; + while ((temp=split(temp2))!="") + { + string modechar=""; + + switch(temp[0]) + { + case '*': modechar="q"; break; + case '!': modechar="a"; break; + case '@': modechar="o"; break; + case '%': modechar="h"; break; + case '+': modechar="v"; break; + } + if (modechar!="") //i.e., if there was a *!@%+ + temp=temp.substr(1); + + users.addtolist(temp, modechar); + } + } + break; + case 366: if (lcase(msg.params.substr(msg.params.rfind(' ')+1))==lcase(name)) + receiving_names_list=false; + break; + case 324: if (lcase(ntharg(msg.params,2))==lcase(name)) //antwort auf /mode? + chanmodes=ntharg(msg.params,3); + break; + case 332: if (lcase(ntharg(temp,2))==lcase(name)) //topic-antwort für uns? + chantopic=msg.content; + break; + case 331: if (lcase(ntharg(temp,2))==lcase(name)) //notopic-antwort für uns? + chantopic=""; + break; + } + + if (msg_for_us) + cout << "in " << name << ": " << msg.origin << " " << msg.command << " " << msg.params << " :" << msg.content << endl; +} + + +void TChannel::exec_plugins(list plugins) +{ + ircmessage curr_msg=static_cast(parent)->get_curr_msg(); + + int reason; + + list::iterator it2=plugins.begin(); + for (list::iterator it=contexts.begin(); it!=contexts.end(); it++) + { + reason=0; + + if (((it->flags) & PFLAGS_EXEC_ONDEMAND) && (curr_msg) && (msg_for_us) )//ist ondemand an und ham wir ne nachricht bekommen? + if (ucase(curr_msg.command)=="PRIVMSG") //wars eine privmsg? + if (curr_msg.content[0]==static_cast(parent)->comchar) //ist sie ein aufruf? + if (match(curr_msg.content.substr(1),(*it2)->get_name())) //ist sie an uns gerichtet? //TODO: wenn cmd geändert wird, z.B. dass , foo statt !foo auch geht, ändern!!! + reason|=PFLAGS_EXEC_ONDEMAND; + + if (((it->flags) & PFLAGS_EXEC_ONEVENT) && (curr_msg) && (msg_for_us) ) + reason|=PFLAGS_EXEC_ONEVENT; + + if (((it->flags) & PFLAGS_EXEC_ONANYEVENT) && (curr_msg) ) + reason|=PFLAGS_EXEC_ONANYEVENT; + + if ((it->flags) & PFLAGS_EXEC_ALWAYS) + reason|=PFLAGS_EXEC_ALWAYS; + + if (reason) + (*it2)->execute( &(*it) , curr_msg, this, reason); + + it2++; + } +} + + +TUserList TChannel::get_users(){return users;} + +string TChannel::get_name() +{ + return name; +} + +void TChannel::addplugincontext(TPlugin* plugin){TPluginParent::hiddenaddplugincontext(plugin->get_default_flags_for_channels(), plugin->get_context_size());} + +string TChannel::get_modes() { return chanmodes; } +string TChannel::get_topic() { return chantopic; } + +int TChannel::get_type() {return TYPE_CHAN;} + +void TChannel::say (string what) +{ + parent->send("PRIVMSG "+get_name()+" :"+what); +} -- cgit v1.2.1