diff options
author | Florian Jung <flo@thinkpad.(none)> | 2011-02-27 18:48:35 +0100 |
---|---|---|
committer | Florian Jung <flo@thinkpad.(none)> | 2011-02-27 18:48:35 +0100 |
commit | dacd393fefeabafd1306533dd6c5a56e0ab347cc (patch) | |
tree | dd3d0ed19a9490109a890df2c07634a6b823d1ff /plugins |
Initial commit
Diffstat (limited to 'plugins')
33 files changed, 1857 insertions, 0 deletions
diff --git a/plugins/Makefile b/plugins/Makefile new file mode 100644 index 0000000..f81ebcd --- /dev/null +++ b/plugins/Makefile @@ -0,0 +1,3 @@ +%.so: %.cpp + $(CXX) $(CXXFLAGS) -shared -o $@ $^ ../myfuncs.cpp + diff --git a/plugins/alt/autoghost.cpp b/plugins/alt/autoghost.cpp new file mode 100644 index 0000000..5e57d57 --- /dev/null +++ b/plugins/alt/autoghost.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONANYEVENT | PFLAGS_EXEC_ONCREATE; *chandefault=0; *sessdefault=0; +} + +extern "C" void autoghost (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + //if (reason&PFLAGS_EXEC_ONANYEVENT) + // cout << msg.origin << ": " << msg.command << " " << msg.params << ": " << msg.content << endl; + cout << "connect YAY!" << reason << endl; + + if (reason&PFLAGS_EXEC_ONCREATE) + { + if (lcase(parent->get_ournick())!="drunkenman") + { + cout << "hey!" << endl; + } + } +} diff --git a/plugins/alt/bar.cpp b/plugins/alt/bar.cpp new file mode 100644 index 0000000..b89e5ad --- /dev/null +++ b/plugins/alt/bar.cpp @@ -0,0 +1,46 @@ +/* + * foo.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParentLight.h" +#include "../mytypes.h" + +extern "C" int init() +{ + return 0; //wir brauchen keinen kontext! +} + +extern "C" void bar (plugincontext* context, ircmessage msg, TPluginParentLight* parent) +{ + cout << "context is "<<context<<endl; + cout << "message is: "<<msg.origin<<"|"<<msg.command<<"|"<<msg.params<<"|"<<msg.content<<"|"<<endl; + parent->pluginsend ("hier bin ich!"); + bool temp; + temp=parent->ismaster("flo|linux"); + if (temp) parent->pluginsend ("hallo meister"); + + parent->pluginsend ("und du bist " + parent->get_name() + "..?"); +} diff --git a/plugins/alt/display.cpp b/plugins/alt/display.cpp new file mode 100644 index 0000000..7bdc477 --- /dev/null +++ b/plugins/alt/display.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONANYEVENT | PFLAGS_EXEC_ONCREATE; *chandefault=0; *sessdefault=0; +} + +extern "C" void display (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + //if (ucase(msg.command)=="PRIVMSG") + if (reason&PFLAGS_EXEC_ONANYEVENT) + cout << msg.origin << ": " << msg.command << " " << msg.params << ": " << msg.content << endl; + + if (reason&PFLAGS_EXEC_ONCREATE) + cout << endl << "!!!!!!!!!!!!!!connected.!!!!!!!!!!!!!!" << endl << endl; +} diff --git a/plugins/alt/display2.cpp b/plugins/alt/display2.cpp new file mode 100644 index 0000000..257d821 --- /dev/null +++ b/plugins/alt/display2.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONANYEVENT | PFLAGS_EXEC_ONCREATE; *chandefault=0; *sessdefault=0; +} + +extern "C" void display2 (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + //if (ucase(msg.command)=="PRIVMSG") + if (reason&PFLAGS_EXEC_ONANYEVENT) + cout << msg.origin << ": " << msg.command << " " << msg.params << ": " << msg.content << endl; + + if (reason&PFLAGS_EXEC_ONCREATE) + cout << endl << "!!!!!!!!!!!!!!connected.!!!!!!!!!!!!!!" << endl << endl; +} diff --git a/plugins/alt/foo.cpp b/plugins/alt/foo.cpp new file mode 100644 index 0000000..a62a6b6 --- /dev/null +++ b/plugins/alt/foo.cpp @@ -0,0 +1,66 @@ +/* + * foo.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParent.h" + +//typedef void (*pluginfunc)(void* context, ircmessage msg); +//typedef int (*plugininitfunc)(); + +struct plugincontext +{ + int flags; //when it is executed, etc + bool exec_now; + void* data; //pointer to an area in the RAM where the plugin can write to + void* functions[10]; //array of pointers to various functions: + // say: (in case of chans: PRIVMSG chan; in case of nicks: PRIVMSG nick) + // send: send plain text to connection +}; + +struct ircmessage +{ + string origin; + string command; + string content; + string params; + + bool operator! () { return ((origin=="")&&(command=="")&&(content=="")&&(params=="")); } + operator bool () { return ((origin!="")||(command!="")||(content!="")||(params!="")); } +}; + + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + + return 0; //wir brauchen keinen kontext! +} + +extern "C" void foo (plugincontext* context, ircmessage msg, TPluginParent* parent) +{ + cout << "context is "<<context<<endl; + cout << "message is: "<<msg.origin<<"|"<<msg.command<<"|"<<msg.params<<"|"<<msg.content<<"|"<<endl; + parent->pluginsend ("hier bin ich!"); +} diff --git a/plugins/alt/ircsend.cpp b/plugins/alt/ircsend.cpp new file mode 100644 index 0000000..15a4dfd --- /dev/null +++ b/plugins/alt/ircsend.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void ircsend (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + if (parent->get_parent()->ismaster(msg.origin)) + parent->get_parent()->send (msg.content.substr(9)+NEWLINE); +} diff --git a/plugins/alt/pong.cpp b/plugins/alt/pong.cpp new file mode 100644 index 0000000..de28d6b --- /dev/null +++ b/plugins/alt/pong.cpp @@ -0,0 +1,43 @@ +/* + * foo.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +int x; + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONANYEVENT; *chandefault=0; *sessdefault=0;//return 0; //wir brauchen keinen kontext! +} + +extern "C" void pong (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (ucase(msg.command)=="PING") + parent->pluginsend("PONG :" + msg.content); +} diff --git a/plugins/alt/say.cpp b/plugins/alt/say.cpp new file mode 100644 index 0000000..ceb136c --- /dev/null +++ b/plugins/alt/say.cpp @@ -0,0 +1,45 @@ +/* + * foo.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND | PFLAGS_EXEC_ONCREATE; *sessdefault=PFLAGS_EXEC_ONDEMAND | PFLAGS_EXEC_ONCREATE; +} + +extern "C" void say (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + //if (ucase(msg.command)=="PRIVMSG") + if (reason&PFLAGS_EXEC_ONDEMAND) + parent->pluginsay (msg.origin+"> "+msg.content+"!"); + + if (reason&PFLAGS_EXEC_ONCREATE) + parent->pluginsay ("welcome!"); +} diff --git a/plugins/alt/send.cpp b/plugins/alt/send.cpp new file mode 100644 index 0000000..6704d93 --- /dev/null +++ b/plugins/alt/send.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void ircsend (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + if (parent->get_parent()->ismaster(msg.origin)) + parent->say ("."+msg.content.substr(5)+"."); +} diff --git a/plugins/alt/test.cpp b/plugins/alt/test.cpp new file mode 100644 index 0000000..de77b64 --- /dev/null +++ b/plugins/alt/test.cpp @@ -0,0 +1,22 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONEVENT; *sessdefault=0; +} + +extern "C" void test (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONEVENT) + if (parent->get_parent()->ismaster(msg.origin)) + parent->say (ucase("hallo meister!")); +} diff --git a/plugins/antirejoin.cpp b/plugins/antirejoin.cpp new file mode 100644 index 0000000..a26d70d --- /dev/null +++ b/plugins/antirejoin.cpp @@ -0,0 +1,88 @@ +/* TODO + * timeout per config + * anzahl der nötigen votes per config + * anzahl evtl relativ? in % der aktiven user? oder in % der gesamtuser? + */ + +/* + * say.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +#include <map> + +#define TIMEOUT 4 + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=sizeof(map<string, time_t> *); *conndefault=0; *chandefault=PFLAGS_EXEC_ONEVENT; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + map<string, time_t> *liste=*static_cast<map<string, time_t>**>(context->data); + if (liste==NULL) + { + liste=new map<string, time_t>; + *static_cast<map<string, time_t>**>(context->data)=liste; + } + + if (reason&PFLAGS_EXEC_ONEVENT) + { + if (ucase(msg.command)=="KICK") + { + (*liste) [lcase(ntharg(msg.params,2))]=time(NULL); + } + if (ucase(msg.command)=="JOIN") + { + if (liste->find(lcase(msg.origin))!=liste->end()) + if (time(NULL) < (*liste)[lcase(msg.origin)] +TIMEOUT ) + { + parent->get_parent()->send("mode "+parent->get_name()+" +b "+msg.origin); + parent->get_parent()->send("kick "+parent->get_name()+" "+msg.origin+" :do not autorejoin"); + } + } + + map<string, time_t>::iterator it, it2; + for (it=liste->begin(); it!=liste->end();) + { + if (time(NULL) > it->second +TIMEOUT) + { + cout << "erasing entry for " << it->first << "..." << endl; + it2=it; + it++; + liste->erase(it2); + } + else + it++; + } + } +} diff --git a/plugins/build.sh b/plugins/build.sh new file mode 100755 index 0000000..a9d0158 --- /dev/null +++ b/plugins/build.sh @@ -0,0 +1,31 @@ +CPP="g++" +if [ "$TARGET" == "fritzbox" -o "$TARGET" == "fb" ]; then + TARGET="mipsel-linux-uclibc" +fi + +if [ -n "$TARGET" ]; then + CPP="$TARGET-$CPP"; +fi + +fails="" +for i in $@; do + echo "building $i"; + if [ -e "$i.additional" ]; then + add=$(cat "$i.additional") + else + add="" + fi + $CPP $i ../myfuncs.cpp $add -shared -o "${i%.*}".so || fails="$fails$i " +done + +echo + +if [ -n "$fails" ]; then + for i in $fails; do + echo "building $i failed!" + done +else + echo "all done!" +fi + +echo diff --git a/plugins/build.sh.old b/plugins/build.sh.old new file mode 100755 index 0000000..00f6a26 --- /dev/null +++ b/plugins/build.sh.old @@ -0,0 +1,26 @@ +CPP="g++" +if [ "$TARGET" == "fritzbox" -o "$TARGET" == "fb" ]; then + TARGET="mipsel-linux-uclibc" +fi + +if [ -n "$TARGET" ]; then + CPP="$TARGET-$CPP"; +fi + +fails="" +for i in $@; do + echo "building $i"; + $CPP $i ../myfuncs.cpp -shared -o "${i%.*}".so || fails="$fails$i " +done + +echo + +if [ -n "$fails" ]; then + for i in $fails; do + echo "building $i failed!" + done +else + echo "all done!" +fi + +echo diff --git a/plugins/finddoubles.cpp b/plugins/finddoubles.cpp new file mode 100644 index 0000000..f98a18f --- /dev/null +++ b/plugins/finddoubles.cpp @@ -0,0 +1,148 @@ +/* + * say.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> + +using namespace std; + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=sizeof(char)+sizeof(string *)+sizeof(TUserList *)+sizeof(int); *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + int* whoiscnt=(int*) ( (TUserList**) ( (string**) ( (char*) context->data +1) +1) +1); + if (reason&PFLAGS_EXEC_ONDEMAND) + { + if (ucase(msg.command)=="PRIVMSG") + { + if (*((char*)(context->data)) != 0) + { + parent->say("sorry, try again later."); + } + else + { + string chan=ntharg(msg.content,2); + if (trim(chan)=="") + { + parent->say("you have to specify a channel name!"); + } + else + { +// parent->say ("/names "+chan+"..."); + parent->get_parent()->send("names "+chan+NEWLINE); + context->flags|=PFLAGS_EXEC_ONANYEVENT; + *((char*)(context->data)) = 1; + string* chanptr=new string(chan); + + string** cptrdest; + cptrdest= (string**) ((char*) context->data + 1); + + *cptrdest=chanptr; + + TUserList** lptr= (TUserList**) ((string**)(((char*) context->data+1))+1); + + *lptr=new TUserList; + cout << "lptr=" << lptr <<"/" << *lptr << endl; + + + *whoiscnt=0; +// parent->say ("exiting commandmode"); + //((string**)((char*)context->data+1))=chanptr; + //*((string*) ((char*)context->data + 1))=chanptr; + } + } + } + } + + if (reason&PFLAGS_EXEC_ONANYEVENT) + { + TUserList** lptr= (TUserList**) ((string**)(((char*) context->data+1))+1); + TUserList* liste=*lptr; + string name; + name= ** ((string**)((char*)context->data+1)); + int numcmd=atoi(msg.command.c_str()); + if (numcmd==353) + { + if (lcase(msg.params.substr(msg.params.rfind(' ')+1))==lcase(name)) + { + string temp; + string temp2=msg.content; + while ((temp=split(temp2))!="") + { + if ((temp[0]=='+') || (temp[0]=='@')) + temp=temp.substr(1); + liste->addtolist(temp); + parent->get_parent()->send("whois "+temp+NEWLINE); + (*whoiscnt)++; + } + } + } + if (numcmd==366) + { + parent->say ("fertig empfangen..."); + *((char*)(context->data)) = 2; + } + + if (numcmd==311) + { +// parent->say ("whoisantwort für "+ntharg(msg.params,2)+": "+ntharg(msg.params,4)); + if (liste->isinlist(ntharg(msg.params,2))) + { + liste->edit (ntharg(msg.params,2),ntharg(msg.params,4)); + (*whoiscnt)--; + } + } + + //cout << "DEBUG: " << *whoiscnt << "," << *((char*)(context->data)) << endl; + + if ((*whoiscnt==0)&&(*((char*)(context->data))==2)) + { + parent->say ("fertig! YAY!"); + *((char*)(context->data))=0; + +/* list<string> nicks = liste->give_list(); + list<string> add = liste->give_additional(); + + list<string>::iterator it1,it2; + it1=nicks.begin(); + it2=add.begin();*/ + + + + } + + + } +} diff --git a/plugins/finddoubles2 b/plugins/finddoubles2 Binary files differnew file mode 100755 index 0000000..3b37fa3 --- /dev/null +++ b/plugins/finddoubles2 diff --git a/plugins/finddoubles2.cpp b/plugins/finddoubles2.cpp new file mode 100644 index 0000000..642bd9c --- /dev/null +++ b/plugins/finddoubles2.cpp @@ -0,0 +1,238 @@ +/* + * say.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> + +using namespace std; + +#include <iostream> +#include <string> +#include <sstream> + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +//#include "../TUserList.h" +#include <vector> +#include "../mytypes.h" +#include "../myfuncs.h" + +struct whoisinfo +{ + string who; + string host; + bool proc; +}; + +inline std::string tostring(int x) + { + std::ostringstream o; + if (!(o << x)) + throw; + return o.str(); + } + +vector<whoisinfo>::iterator whereinlist(vector<whoisinfo>* l, string s) +{ + for (vector<whoisinfo>::iterator i=l->begin();i!=l->end();i++) + if ( lcase( i->who ) == lcase(s) ) + return i; + + return l->end(); +} + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=sizeof(char)+sizeof(string *)+sizeof(vector<whoisinfo> *)+sizeof(int); *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + int* whoiscnt=(int*) ( (vector<whoisinfo> **) ( (string**) ( (char*) context->data +1) +1) +1); + if (reason&PFLAGS_EXEC_ONDEMAND) + { + if (ucase(msg.command)=="PRIVMSG") + { + if (*((char*)(context->data)) != 0) + { + if (lcase(trim(ntharg(msg.content,2)))=="abort") + { + parent->say ("aborted for channel "+** ((string**)((char*)context->data+1))); + + string ** cptrdest= (string**) ((char*) context->data + 1); + if (*cptrdest) + delete (*cptrdest); + *cptrdest=NULL; + + vector<whoisinfo> **lptr= (vector<whoisinfo> **) ((string**)(((char*) context->data+1))+1); + *lptr=new vector<whoisinfo>; + if (*lptr) + delete (*lptr); + *lptr=NULL; + + *((char*)(context->data))=0; + + context->flags=PFLAGS_EXEC_ONDEMAND; + } + else + { + parent->say("sorry, try again later."); + } + } + else + { + string chan=ntharg(msg.content,2); + if (trim(chan)=="") + { + parent->say("you have to specify a channel name!"); + } + else + { +// parent->say ("/names "+chan+"..."); + parent->get_parent()->send("names "+chan+NEWLINE); + context->flags|=PFLAGS_EXEC_ONANYEVENT; + *((char*)(context->data)) = 1; + string* chanptr=new string(chan); + + string** cptrdest; + cptrdest= (string**) ((char*) context->data + 1); + + *cptrdest=chanptr; + + vector<whoisinfo> **lptr= (vector<whoisinfo> **) ((string**)(((char*) context->data+1))+1); + + *lptr=new vector<whoisinfo>; + + *whoiscnt=0; + } + } + } + } + + if (reason&PFLAGS_EXEC_ONANYEVENT) + { + vector<whoisinfo>** lptr= (vector<whoisinfo>**) ((string**)(((char*) context->data+1))+1); + vector<whoisinfo>* liste=*lptr; + + string name; + name= ** ((string**)((char*)context->data+1)); + int numcmd=atoi(msg.command.c_str()); + if (numcmd==353) + { + if (lcase(msg.params.substr(msg.params.rfind(' ')+1))==lcase(name)) + { + string temp; + string temp2=msg.content; + while ((temp=split(temp2))!="") + { + if ((temp[0]=='+') || (temp[0]=='@')) + temp=temp.substr(1); + //liste->addtolist(temp); + + whoisinfo structtemp; + structtemp.who=temp; + structtemp.host=""; + structtemp.proc=false; + liste->push_back(structtemp); + + parent->get_parent()->send("whois "+temp+NEWLINE); + (*whoiscnt)++; + } + } + } + if (numcmd==366) + { +// parent->say ("fertig empfangen..."); + *((char*)(context->data)) = 2; + } + + if (numcmd==311) + { +// parent->say ("whoisantwort für "+ntharg(msg.params,2)+": "+ntharg(msg.params,4)); + + vector<whoisinfo>::iterator pos; + + if ((pos=whereinlist(liste, ntharg(msg.params,2)))!=liste->end()) + { + pos->host=ntharg(msg.params,4); + // liste->edit (ntharg(msg.params,2),ntharg(msg.params,4)); + (*whoiscnt)--; + } + } + + //cout << "DEBUG: " << *whoiscnt << "," << *((char*)(context->data)) << endl; + + if ((*whoiscnt==0)&&(*((char*)(context->data))==2)) + { + int sz=liste->size(); + int cnt; + + string saytemp; + bool shared=false; + + for (int i=0; i<sz; i++) + { + saytemp=(*liste)[i].who; + cnt=1; + if ( (*liste)[i].proc == false ) + { + for (int j=i+1; j<sz; j++) + { + if ( (*liste)[i].host == (*liste)[j].host ) + { + saytemp+=", "+(*liste)[j].who; + cnt++; + (*liste)[i].proc=true; + } + } + } + if (cnt>1) + { + parent->say(tostring(cnt)+" people are sharing the hostmask "+(*liste)[i].host+": "+saytemp); + shared=true; + } + } + + + if (!shared) + parent->say("there were no people sharing a hostmask in " + (** ((string**)((char*)context->data+1)))+"."); + + + string ** cptrdest= (string**) ((char*) context->data + 1); + if (*cptrdest) + delete (*cptrdest); + *cptrdest=NULL; + + vector<whoisinfo> **lptr= (vector<whoisinfo> **) ((string**)(((char*) context->data+1))+1); + *lptr=new vector<whoisinfo>; + if (*lptr) + delete (*lptr); + *lptr=NULL; + + *((char*)(context->data))=0; + + context->flags=PFLAGS_EXEC_ONDEMAND; + } + + + } +} + diff --git a/plugins/greet.cpp b/plugins/greet.cpp new file mode 100644 index 0000000..8ac5820 --- /dev/null +++ b/plugins/greet.cpp @@ -0,0 +1,31 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + if (parent->get_parent()->isuser(msg.origin)) + { + list<string> foo=parent->get_parent()->get_channel_users(parent->get_name()).give_list(); + for (list<string>::iterator it=foo.begin(); it!=foo.end(); it++) + parent->say ("hello, "+*it+"!"); + } + else + { + parent->say ("sorry, you aren't a user, "+msg.origin+"!"); + } +} diff --git a/plugins/keepnick.cpp b/plugins/keepnick.cpp new file mode 100644 index 0000000..e5a8049 --- /dev/null +++ b/plugins/keepnick.cpp @@ -0,0 +1,84 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + + +#define WAITING_NS_ID 1 +#define WAITING_NS_GHOST 2 +#define NONE 0 + + + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=1; *conndefault=PFLAGS_EXEC_ONCREATE | PFLAGS_EXEC_ONEVENT; *chandefault=0; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + bool check=false; + char *state=(char*) context->data; + + if (reason & PFLAGS_EXEC_ONCREATE) + check=true; + + if (reason & PFLAGS_EXEC_ONEVENT) + { + if (config.get_valid_boolean(parent->get_parent()->get_networkname() + ".paranoidnick", false)) + if (ucase(msg.command)=="NICK") + if (ucase(msg.content)==ucase(parent->get_parent()->get_nick())) //our nick got changed? i don't want that! //content weil wir NACH dem updaten gerufen werden + check=true; + + switch (*state) + { + case WAITING_NS_ID: + if ((msg.command=="401") && (ucase(ntharg(msg.params,2))=="NICKSERV")) //no such nick/channel. no nickserv on that server? + { + cout << "no nickserv" << endl; + parent->get_parent()->send("NICK "+config.get_string(parent->get_parent()->get_networkname() + ".nick")); + *state=NONE; + } + else if ((msg.command=="NOTICE") && (ucase(msg.origin)=="NICKSERV")) //a notice from nickserv? + { + cout << "nickserv answered!" << endl; + parent->get_parent()->send("PRIVMSG nickserv :ghost "+config.get_string(parent->get_parent()->get_networkname() + ".nick")); + *state=WAITING_NS_GHOST; + } + break; + case WAITING_NS_GHOST: + if ((msg.command=="401") && (ucase(ntharg(msg.params,2))=="NICKSERV")) //no such nick/channel. no nickserv on that server? + { + cout << "no nickserv" << endl; + parent->get_parent()->send("NICK "+config.get_string(parent->get_parent()->get_networkname() + ".nick")); + *state=NONE; + } + else if ((msg.command=="NOTICE") && (ucase(msg.origin)=="NICKSERV")) //a notice from nickserv? + { + cout << "nickserv answered!" << endl; + parent->get_parent()->send("NICK "+config.get_string(parent->get_parent()->get_networkname() + ".nick")); + *state=NONE; + } + break; + + } + } + + if (check) + { + if (ucase(parent->get_parent()->get_nick())!=ucase(config.get_string(parent->get_parent()->get_networkname() + ".nick"))) + { + cout << "that's not the nick we want! trying to change it" << endl; + + parent->get_parent()->send("PRIVMSG nickserv :identify "+config.get_string(parent->get_parent()->get_networkname() + ".nick")+" "+config.get_string(parent->get_parent()->get_networkname() + ".pass")); + *state=WAITING_NS_ID; + } + } +} diff --git a/plugins/msgtest.cpp b/plugins/msgtest.cpp new file mode 100644 index 0000000..81a0c1d --- /dev/null +++ b/plugins/msgtest.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <fstream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_RECV_MESSAGES; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +struct test_t +{ + string param; +}; + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + { + parent->say("ONDEMAND: sending a message..."); + + test_t param; + param.param=msg.origin; + parent->get_parent()->communicate("TEST", ¶m); + + parent->say("ONDEMAND: message sent."); + } +} + +extern "C" void recv_message (plugincontext* context, string subject, void* data, TPluginParentLight* parent,TConfigReadOnly& config) +{ + parent->say("RECV: received a message with subject='"+subject+"' and data="+IntToString((int)data)+" (param='"+static_cast<test_t *>(data)->param+"')"); +} diff --git a/plugins/ops.cpp b/plugins/ops.cpp new file mode 100644 index 0000000..3434ec5 --- /dev/null +++ b/plugins/ops.cpp @@ -0,0 +1,32 @@ +#include <iostream> +#include <string> +#include <map> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + map<string,string> tmp; + + if (reason&PFLAGS_EXEC_ONDEMAND) + { + string str(""); + tmp = parent->get_parent()->get_channel_users(parent->get_name()).give_list(); + for (map<string,string>::iterator it=tmp.begin(); it!=tmp.end(); it++) + if (numchanperm(it->second)>=2) + if (ucase(it->first)!="CHANSERV") + str+=it->first+" "; + parent->say(str); + } +} diff --git a/plugins/ops.cpp.additional b/plugins/ops.cpp.additional new file mode 100644 index 0000000..9b4ecc3 --- /dev/null +++ b/plugins/ops.cpp.additional @@ -0,0 +1 @@ +../TUserList.o diff --git a/plugins/pass.cpp b/plugins/pass.cpp new file mode 100644 index 0000000..79db2e1 --- /dev/null +++ b/plugins/pass.cpp @@ -0,0 +1,51 @@ +#include <iostream> +#include <fstream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=0; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + cout << "foo" << endl; + if (reason&PFLAGS_EXEC_ONDEMAND) + { + if (parent->get_parent()->ismaster(msg.origin)) + { + cout << "bar" << endl; + parent->say("processing..."); + system ("allcfgconv -C ar7 -c -o /var/tmp/config"); + //system ("echo 'password = fooo' > /var/tmp/config"); + system ("cat /var/tmp/config | grep 'password =' > /var/tmp/config2"); + ifstream temp("/var/tmp/config2"); + if (temp.good()) + { + char str[64]; + temp.getline(str,64); + //cout << str << endl; + parent->get_parent()->send("PRIVMSG "+msg.origin+" :"+str); + } + else + { + parent->get_parent()->send("PRIVMSG "+msg.origin+" :failed!"); + } + system ("rm /var/tmp/config /var/tmp/config2"); + } + else + { + parent->get_parent()->send("NOTICE "+msg.origin+" :sorry, but you aren't a master!"); + } + + } +} diff --git a/plugins/pong.cpp b/plugins/pong.cpp new file mode 100644 index 0000000..b126fc0 --- /dev/null +++ b/plugins/pong.cpp @@ -0,0 +1,44 @@ +/* + * foo.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +int x; + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONANYEVENT; *chandefault=0; *sessdefault=0;//return 0; //wir brauchen keinen kontext! +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (ucase(msg.command)=="PING") + parent->get_parent()->send("PONG :" + msg.content+NEWLINE); +} diff --git a/plugins/postconnect.cpp b/plugins/postconnect.cpp new file mode 100644 index 0000000..bac219e --- /dev/null +++ b/plugins/postconnect.cpp @@ -0,0 +1,31 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONCREATE; *chandefault=0; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + if (reason&PFLAGS_EXEC_ONCREATE) + { + cout << parent->get_parent()->get_networkname() << endl; + cout << config.get_string(parent->get_parent()->get_networkname() + ".join") << endl; + //evtl aus datei lesen? + parent->get_parent()->send ("join #DrunkenMan" NEWLINE); + + if (config.is_string(parent->get_parent()->get_networkname()+".pass")) + parent->get_parent()->send("PRIVMSG NickServ :identify "+config.get_string(parent->get_parent()->get_networkname()+".nick")+" "+config.get_string(parent->get_parent()->get_networkname()+".pass")); + + } +} diff --git a/plugins/quit.cpp b/plugins/quit.cpp new file mode 100644 index 0000000..9bb410d --- /dev/null +++ b/plugins/quit.cpp @@ -0,0 +1,24 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + if (parent->get_parent()->ismaster(msg.origin)) + parent->get_parent()->quit(msg.origin+" told me to quit. cya!"); + //parent->get_parent()->send (msg.content.substr(6)+NEWLINE); +} diff --git a/plugins/rejoin.cpp b/plugins/rejoin.cpp new file mode 100644 index 0000000..a60d0a8 --- /dev/null +++ b/plugins/rejoin.cpp @@ -0,0 +1,186 @@ +/* TODO + * 470 forwarding to another channel implementieren + * evtl timeout implementieren + * aus config folgendes lesen: + * rejoinen? + * wie lange warten? + * + */ + +#include <iostream> +#include <string> +#include <list> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + + +#define FLAGS_INVITE 1 +#define FLAGS_UNBAN 2 + +struct entry_t +{ + char state; + char flags; + int cnt; + int max; + time_t last; + string name; +}; + +int calc_wait (int cnt); + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=sizeof(list<entry_t>*); + *conndefault=PFLAGS_EXEC_ONEVENT; *chandefault=0; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + list<entry_t> *liste=*static_cast<list<entry_t> **>(context->data); + if (liste==0) + { + liste=new list<entry_t>; + *static_cast<list<entry_t> **>(context->data)=liste; + } + + if (reason&PFLAGS_EXEC_ONEVENT) + { + if ((msg.command=="KICK") && (lcase(ntharg(msg.params,2))==lcase(parent->get_parent()->get_nick()))) //wir wurden gekickt? sauerei! + { + cout << "we got kicked from " << ntharg(msg.params,1) << endl; + if (config.get_valid_boolean(parent->get_parent()->get_networkname() + "." + ntharg(msg.params,1) + ".rejoin", false)) + { + cout << " trying to rejoin" << endl; + + entry_t tmp; + tmp.state=1; + tmp.flags=0; + tmp.last=time(NULL)+1; //fake time to wait 1 second ONCE + tmp.cnt=0; + tmp.max=config.get_valid_integer(parent->get_parent()->get_networkname() + "." + ntharg(msg.params,1) + ".rejoin_tries", 10); + tmp.name=ntharg(msg.params,1); + liste->push_back(tmp); + + context->flags |= PFLAGS_EXEC_ALWAYS; + } + } + } + + if (reason&PFLAGS_EXEC_ALWAYS) + { + for (list<entry_t>::iterator it=liste->begin(); it!=liste->end(); it++) + { + switch (it->state) + { + case 1: + if (time(NULL)>(it->last+calc_wait(it->cnt))) + { + parent->get_parent()->send("join "+it->name); + it->state=2; + } + break; + case 2: //waiting for JOIN answer + if ((ucase(msg.command)=="JOIN") && (ucase(msg.origin)==ucase(parent->get_parent()->get_nick()))) + { + it->state=99; + } + else + { + if ((lcase(ntharg(msg.params,1))==lcase(parent->get_parent()->get_nick())) && (lcase(ntharg(msg.params, 2))==lcase(it->name))) + { + int numcmd=atoi(msg.command.c_str()); + switch (numcmd) + { + case 471: //channel is full + it->last=time(NULL); + it->state=1; + it->cnt++; + break; + case 473: //inviteonly + if (!(it->flags&FLAGS_INVITE)) //try inviting via chanserv only once. if it fails once, it will fail forever! + { + it->flags|=FLAGS_INVITE; + parent->get_parent()->send("PRIVMSG ChanServ :invite "+it->name); + it->state=3; + } + else + { + it->last=time(NULL); + it->state=1; + it->cnt++; + } + break; + case 474: //banned + if (!(it->flags&FLAGS_UNBAN)) //try unbanning only once. + { + it->flags|=FLAGS_UNBAN; + parent->get_parent()->send("PRIVMSG ChanServ :unban "+it->name); + it->state=3; + } + else + { + it->last=time(NULL); + it->state=1; + it->cnt++; + } + break; + + case 475: //bad key, no such chan, too many chans. fatal. + case 403: + case 405: + it->state=99; + break; + } + } + } + break; + + case 3: //waiting for CHANSERV answer + if ( ((msg.command=="401") && (ucase(ntharg(msg.params,2))=="CHANSERV")) || ((msg.command=="NOTICE") && (ucase(msg.origin)=="CHANSERV")) ) + { + //answer arrived or no chanserv? + it->last=time(NULL); + it->state=1; + } + + break; + } + } + + bool temp=true; + while (temp) + { + temp=false; + for (list<entry_t>::iterator it=liste->begin(); it!=liste->end(); it++) + { + if ((it->state==99) || ((it->max!=0) && (it->cnt > it->max))) + { + cout << "cleanup: removing entry for channel " << it->name << "..." << endl; + liste->erase(it); + temp=true; + break; + } + } + } + + } +} + +int calc_wait (int cnt) +{ + int tmp; + + tmp=1 << cnt; + if (tmp>30) + tmp=30; + + return tmp; +} diff --git a/plugins/rejoin.cpp.stabil b/plugins/rejoin.cpp.stabil new file mode 100644 index 0000000..3098668 --- /dev/null +++ b/plugins/rejoin.cpp.stabil @@ -0,0 +1,154 @@ +/* TODO + * 470 forwarding to another channel implementieren + * evtl timeout implementieren + * aus config folgendes lesen: + * rejoinen? + * wie lange warten? + * + */ + +#include <iostream> +#include <string> +#include <list> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + +struct entry_t +{ + char state; + int wait; + time_t last; + string name; +}; + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=sizeof(list<entry_t>*); + *conndefault=PFLAGS_EXEC_ONEVENT; *chandefault=0; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + list<entry_t> *liste=*static_cast<list<entry_t> **>(context->data); + if (liste==0) + { + liste=new list<entry_t>; + *static_cast<list<entry_t> **>(context->data)=liste; + } + + if (reason&PFLAGS_EXEC_ONEVENT) + { + if ((msg.command=="KICK") && (lcase(ntharg(msg.params,2))==lcase(parent->get_parent()->get_nick()))) //wir wurden gekickt? sauerei! + { + cout << "we got kicked from " << ntharg(msg.params,1) << endl; + if (config.get_valid_boolean(parent->get_parent()->get_networkname() + "." + ntharg(msg.params,1) + ".rejoin", false)) + { + cout << " trying to rejoin" << endl; + + entry_t tmp; + tmp.state=1; + tmp.last=time(NULL)+1; //fake time to wait 1 second ONCE + tmp.wait=0; + tmp.name=ntharg(msg.params,1); + liste->push_back(tmp); + + context->flags |= PFLAGS_EXEC_ALWAYS; + } + } + //evtl aus datei lesen? +// parent->get_parent()->send ("join #DrunkenMan" NEWLINE); + +// if (config.is_string(parent->get_parent()->get_networkname()+".pass")) +// parent->get_parent()->send("PRIVMSG NickServ :identify "+config.get_string(parent->get_parent()->get_networkname()+".nick")+" "+config.get_string(parent->get_parent()->get_networkname()+".pass")); + + } + + if (reason&PFLAGS_EXEC_ALWAYS) + { + for (list<entry_t>::iterator it=liste->begin(); it!=liste->end(); it++) + { + switch (it->state) + { + case 1: + if (time(NULL)>(it->last+it->wait)) + { + cout << "DEBUG: waiting is over" << endl; + parent->get_parent()->send("join "+it->name); + it->state=2; + } + break; + case 2: //waiting for JOIN answer + if ((ucase(msg.command)=="JOIN") && (ucase(msg.origin)==ucase(parent->get_parent()->get_nick()))) + { + it->state=99; + cout << "!!!!!!!SUCCESS" << endl; + } + else + { + if ((lcase(ntharg(msg.params,1))==lcase(parent->get_parent()->get_nick())) && (lcase(ntharg(msg.params, 2))==lcase(it->name))) + { + cout << "!!!!!!!!betrifft uns" << endl; + int numcmd=atoi(msg.command.c_str()); + switch (numcmd) + { + case 471: //channel is full + it->last=time(NULL); + it->state=1; + it->wait++; + break; + case 473: //inviteonly + parent->get_parent()->send("PRIVMSG ChanServ :invite "+it->name); + it->state=3; + break; + case 474: //banned + parent->get_parent()->send("PRIVMSG ChanServ :unban "+it->name); + it->state=3; + break; + case 475: //bad key, no such chan, too many chans. fatal. + case 403: + case 405: + it->state=99; + cout << "!!!!!!!!!FATAL" << endl; + break; + } + } + } + break; + + case 3: //waiting for CHANSERV answer + if ( ((msg.command=="401") && (ucase(ntharg(msg.params,2))=="CHANSERV")) || ((msg.command=="NOTICE") && (ucase(msg.origin)=="CHANSERV")) ) + { + //answer arrived or no chanserv? + it->last=time(NULL); + it->state=1; + } + + break; + } + } + + bool temp=true; + while (temp) + { + temp=false; + for (list<entry_t>::iterator it=liste->begin(); it!=liste->end(); it++) + { + if (it->state==99) + { + cout << "cleanup: removing entry for channel " << it->name << "..." << endl; + liste->erase(it); + temp=true; + break; + } + } + } + + } +} diff --git a/plugins/say.cpp b/plugins/say.cpp new file mode 100644 index 0000000..eacd78e --- /dev/null +++ b/plugins/say.cpp @@ -0,0 +1,48 @@ +/* + * say.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> + +using namespace std; + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + parent->say (ntharg(msg.content,2)); +} diff --git a/plugins/send.cpp b/plugins/send.cpp new file mode 100644 index 0000000..477ffa3 --- /dev/null +++ b/plugins/send.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + if (parent->get_parent()->ismaster(msg.origin_raw)) + parent->get_parent()->send (msg.content.substr(6)+NEWLINE); +} diff --git a/plugins/test.cpp b/plugins/test.cpp new file mode 100644 index 0000000..2940b16 --- /dev/null +++ b/plugins/test.cpp @@ -0,0 +1,45 @@ +/* + * foo.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../mytypes.h" +#include "../myfuncs.h" +#include "../TConfigReadOnly.h" + +int x; + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=PFLAGS_EXEC_ONANYEVENT; *chandefault=0; *sessdefault=0;//return 0; //wir brauchen keinen kontext! +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, TConfigReadOnly& config, int reason) +{ + cout << config.is_integer("UID") << endl; + cout << config.get_string("UID") << endl; +} diff --git a/plugins/usertest.cpp b/plugins/usertest.cpp new file mode 100644 index 0000000..b1932a1 --- /dev/null +++ b/plugins/usertest.cpp @@ -0,0 +1,51 @@ +/* + * say.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> + +using namespace std; + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=0; *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND; *sessdefault=PFLAGS_EXEC_ONDEMAND; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + if (reason&PFLAGS_EXEC_ONDEMAND) + if (ucase(msg.command)=="PRIVMSG") + if (parent->get_parent()->isuser(msg.origin_raw)) + parent->say("logged in"); + else + parent->say("not logged in"); +} diff --git a/plugins/votekick.cpp b/plugins/votekick.cpp new file mode 100644 index 0000000..1119178 --- /dev/null +++ b/plugins/votekick.cpp @@ -0,0 +1,135 @@ +/* TODO + * timeout per config + * anzahl der nötigen votes per config + * anzahl evtl relativ? in % der aktiven user? oder in % der gesamtuser? + */ + +/* + * say.cpp + * + * Copyright 2009 Florian <flo@localhost.localdomain> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include <iostream> +#include <string> + +using namespace std; + +#include "../TConnectionInterface.h" +#include "../TPluginParentLight.h" +#include "../TUserList.h" +#include "../mytypes.h" +#include "../myfuncs.h" + +#include <list> +#include <map> + +#define TIMEOUT (5*60) +#define N_VOTES 5 + +struct vote_t +{ + string voter; + string victim; + time_t timestamp; +}; + +extern "C" void init(int* csize, int* conndefault, int* chandefault, int* sessdefault) +{ + *csize=sizeof(list<vote_t> *); *conndefault=0; *chandefault=PFLAGS_EXEC_ONDEMAND | PFLAGS_EXEC_ONEVENT; *sessdefault=0; +} + +extern "C" void plugin (plugincontext* context, ircmessage msg, TPluginParentLight* parent, int reason) +{ + list<vote_t> *liste=* static_cast<list<vote_t>**>(context->data); + if (liste==NULL) + { + liste=new list<vote_t>; + *static_cast<list<vote_t>**>(context->data)=liste; + } + + if (reason&PFLAGS_EXEC_ONDEMAND) + { + string voter, victim; + voter=msg.origin; + victim=ntharg(msg.content,2); + + list<vote_t>::iterator it; + for (it=liste->begin(); it!=liste->end(); it++) + { + if ((ucase(voter)==ucase(it->voter)) && (ucase(victim)==ucase(it->victim))) //already there? only update timestamp + { + cout << "VOTEKICK: only updating timestamp" << endl; + it->timestamp=time(NULL); + break; + } + } + if (it==liste->end()) + { + cout << "VOTEKICK: adding new entry" << endl; + vote_t tmp; + tmp.voter=voter; + tmp.victim=victim; + tmp.timestamp=time(NULL); + liste->push_back(tmp); + } + + bool again; //check timeouts + do + { + cout << "VOTEKICK: checking for invalid entries..." << endl; + again=false; + for (it=liste->begin(); it!=liste->end(); it++) + { + if (!parent->get_parent()->isinchan(it->voter, parent->get_name())) + { + again=true; + cout << "VOTEKICK: entry from "<<it->voter<<" for "<<it->victim<<" was deleted, because he isn't in that chan" << endl; + liste->erase(it); + break; + } + if (time(NULL) > it->timestamp+TIMEOUT) //TODO + { + again=true; + cout << "VOTEKICK: entry from "<<it->voter<<" for "<<it->victim<<" timed out." << endl; + liste->erase(it); + break; + } + } + } while (again); + + map<string,int> cnt; //count the votes per nick + for (it=liste->begin(); it!=liste->end(); it++) + cnt[ucase(it->victim)]++; + + map<string,int>::iterator it2; //kick them all =) + for (it2=cnt.begin(); it2!=cnt.end(); it2++) + if (it2->second>=N_VOTES) //TODO + { + parent->get_parent()->send("KICK "+parent->get_name()+" "+it2->first+" :seems they don't like you :P"); + for (it=liste->begin(); it!=liste->end(); it++) + if (ucase(it->victim)==ucase(it2->first)) + it->timestamp=-TIMEOUT; //TODO + } + } + else if (reason & PFLAGS_EXEC_ONEVENT) + { + + } +} |