diff --git a/fish.h b/fish.h index 39d0fdf..1a6feb4 100755 --- a/fish.h +++ b/fish.h @@ -3,6 +3,7 @@ #include #include +using namespace std; namespace fish { void init(); diff --git a/key.cpp b/key.cpp index eeb11e9..5d98d82 100755 --- a/key.cpp +++ b/key.cpp @@ -1,13 +1,14 @@ -#include "key.h" -#include "misc.h" -#include "fish.h" -#include "define.h" #include #include #include #include #include +#include "key.h" +#include "misc.h" +#include "fish.h" +#include "define.h" + using namespace std; algomap_t algomap; @@ -193,13 +194,81 @@ int key::encode(const string &search, const string &in, string &out) return kiter->encode(in, out); } +string get_nick_from_privlog_line(const string& in) { + string::size_type start, stop; + + start = in.find("("); + stop = in.find("!"); + + if(start == string::npos || stop == string::npos) + return ""; + + string newnick = in.substr(start + 1, stop - start - 1); + return newnick; +} + +string get_prefix_from_privlog_line(const string& in) { + string::size_type start; + + start = in.find(")"); + + if(start == string::npos) + return ""; + + return in.substr(0, start + 2); +} + +string get_msg_from_privlog_line(const string& in) { + string::size_type start; + + start = in.find(")"); + + if(start == string::npos) + return ""; + + return in.substr(start + 2); +} + int key::decode(const string &search, const string &in, string &out) { - if (!find(search)) { + bool psybnc_hack = false; + + string to_search = search; + string to_in = in; + string to_out = out; + string to_prefix; + + if(search == "-psyBNC") + psybnc_hack = true; + + if(psybnc_hack) { + string nick = get_nick_from_privlog_line(in); + + if(nick.size() == 0) + psybnc_hack = false; + else { + to_search = nick; + } + } + + if (!find(to_search)) { out = in; + return bad_target; } - return kiter->decode(in, out); + + if(psybnc_hack) { + to_prefix = get_prefix_from_privlog_line(in); + to_in = get_msg_from_privlog_line(in); + } + + int ret = kiter->decode(to_in, to_out); + out = to_out; + + if(psybnc_hack) + out = to_prefix + out; + + return ret; } bool key::addalias(const string &search, const string &alias) diff --git a/key.h b/key.h index 75a1d16..6436b8d 100755 --- a/key.h +++ b/key.h @@ -5,6 +5,7 @@ #include #include #include +using namespace std; typedef std::map algomap_t; typedef std::list keylist_t; diff --git a/misc.cpp b/misc.cpp index a954c58..d702b7f 100755 --- a/misc.cpp +++ b/misc.cpp @@ -84,7 +84,7 @@ string gettok(const string &s, const string delim, const int index) return empty; } -string lowercase(string s) +string lowercase(std::string s) { string::size_type i; for (i = 0; i < s.size(); i++) s[i] = (char)tolower(s[i]); diff --git a/misc.h b/misc.h index 21b712e..a679ce1 100755 --- a/misc.h +++ b/misc.h @@ -4,6 +4,8 @@ #include #include +using namespace std; + extern std::string base64; std::string itos(int i, const int base = 10); diff --git a/unix.mak b/unix.mak index 726e608..270a188 100755 --- a/unix.mak +++ b/unix.mak @@ -4,11 +4,19 @@ CC = gcc CXX = g++ +CPPFLAGS = -D DIRT_UNIX + +# release CFLAGS = -pipe -O3 -Wall -pedantic -Wno-long-long -std=c99 CXXFLAGS = -pipe -O3 -Wall -pedantic -Wno-long-long -CPPFLAGS = -D DIRT_UNIX LDFLAGS = -s +# debug +#CFLAGS = -pipe -g3 -O0 -Wall -pedantic -Wno-long-long -std=c99 +#CXXFLAGS = -pipe -g3 -O0 -Wall -pedantic -Wno-long-long +#LDFLAGS = + + MAKEDEPEND = $(CXX) -MM $(CPPFLAGS) -o $*.d $< DIRT = dirt