diff options
Diffstat (limited to 'TChannel.cpp.sicher')
-rw-r--r-- | TChannel.cpp.sicher | 258 |
1 files changed, 0 insertions, 258 deletions
diff --git a/TChannel.cpp.sicher b/TChannel.cpp.sicher deleted file mode 100644 index dfd08dd..0000000 --- a/TChannel.cpp.sicher +++ /dev/null @@ -1,258 +0,0 @@ -#include <list> -#include <string> -#include <fstream> -#include <iostream> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <netdb.h> -#include <cstring> -#include <dlfcn.h> -using namespace std; -#include "TChannel.h" - -extern list<TPlugin*> 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<TPlugin*>::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<TPlugin*>::iterator it2=plugins.begin(); - - ircmessage curr_msg=static_cast<TConnection*>(parent)->get_curr_msg(); - - for (list<plugincontext>::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<string>::iterator it; - cout << "---------userlist von "<<name<<" -------" << endl; - users.show_list(); - cout << endl << "---------------------------------------------------" << endl; - -} - -void TChannel::interpret_message (ircmessage msg) -{ -// cout << "chanmodes are " << chanmodes << endl; -// cout << "topic is " << chantopic << endl; -// show_users(); - - string temp; - - if ( ucase(msg.command)=="JOIN" ) - if (ucase(msg.content)==ucase(name)) - { - msg_for_us=true; - users.addtolist(msg.origin); - } - - if (ucase(msg.command)=="PART") - if (ucase(msg.params)==ucase(name)) - { - msg_for_us=true; - users.removefromlist(msg.origin); - } - - if (ucase(msg.command)=="NICK") - if (users.isinlist(msg.origin)) - { - msg_for_us=true; - users.addtolist(msg.content, users.get_info(msg.origin)); //infos übernehmen! - users.removefromlist(msg.origin); - } - - if (ucase(msg.command)=="QUIT") - if (users.isinlist(msg.origin)) - { - msg_for_us=true; - users.removefromlist(msg.origin); - } - - if (ucase(msg.command)=="KICK") //1. param: where?; 2. param: who? - if (ucase(ntharg(msg.params,1))==ucase(name)) - { - msg_for_us=true; - users.removefromlist(ntharg(msg.params,2)); - } - - if (ucase(msg.command)=="PRIVMSG") - if (ucase(msg.params)==ucase(name)) - msg_for_us=true; - - if (ucase(msg.command)=="NOTICE") - if (ucase(msg.params)==ucase(name)) - msg_for_us=true; - - if (ucase(msg.command)=="MODE") - { - if (ucase(ntharg(msg.params,1))==ucase(name)) - { - msg_for_us=true; - parent->send ("mode "+name+NEWLINE); - - list<ircmode_t> l=parsemodes(msg.params); - for (list<ircmode_t>::iterator it=l.begin(); it!=l.end(); it++) //TODO - { - string what=it->mode; - string who=it->param; - cout << "DEBUG: who='"<<who<<"', what='"<<what<<"'"<<endl; - if (who!="") - { - if ((what[1]=='o') || (what[1]=='v')) //voice oder opänderung eines users? - { - string hasmode=users.get_info(who); - if (hasmode=="o") - { - if (what=="-o") //ein op wird deoppt? dann müssen wir schauen, ob er noch voice hat. - parent->send ("names "+name+NEWLINE); - } - else - { - if (what=="+v") hasmode="v"; - if (what=="+o") hasmode="o"; - if (what=="-v") hasmode=""; - } - - users.edit(who,hasmode); - } - } - } - - } - - } - - 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=""; - if (temp[0]=='+') modechar="v"; - if (temp[0]=='@') modechar="o"; - - if ((temp[0]=='+') || (temp[0]=='@')) - 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<TPlugin*> plugins) -{ - ircmessage curr_msg=static_cast<TConnection*>(parent)->get_curr_msg(); - - int reason; - - list<TPlugin*>::iterator it2=plugins.begin(); - for (list<plugincontext>::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<TConnection*>(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 <nick>, 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() -{ -cout << "chanGETNAME" << name << endl; - 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); -} |