diff options
author | Pixel <Pixel> | 2001-09-23 22:10:43 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-09-23 22:10:43 +0000 |
commit | ec2ecbd35bea64c88ab783b06100edc65c418048 (patch) | |
tree | f270dc1a013c3fe26170e63bc2be8d8a3ca936d0 /lib/IRC.cc | |
parent | 76fde1f5b754845bd9b40cf9b2f15734686f6d09 (diff) |
Some IRC features...
Diffstat (limited to 'lib/IRC.cc')
-rw-r--r-- | lib/IRC.cc | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/lib/IRC.cc b/lib/IRC.cc new file mode 100644 index 0000000..8ba15cc --- /dev/null +++ b/lib/IRC.cc @@ -0,0 +1,233 @@ +#include "String.h" +#include "IRC.h" +#include "HttpServ.h" + +ircmsg_t ircmsgs[MSG_COUNT] = + +{ + { "RPL_WELCOME", RPL_WELCOME }, + { "RPL_YOURHOST", RPL_YOURHOST }, + { "RPL_CREATED", RPL_CREATED }, + { "RPL_MYINFO", RPL_MYINFO }, + { "RPL_BOUNCE", RPL_BOUNCE }, + { "RPL_TRACELINK", RPL_TRACELINK }, + { "RPL_TRACECONNECTING", RPL_TRACECONNECTING }, + { "RPL_TRACEHANDSHAKE", RPL_TRACEHANDSHAKE }, + { "RPL_TRACEUNKNOWN", RPL_TRACEUNKNOWN }, + { "RPL_TRACEOPERATOR", RPL_TRACEOPERATOR }, + { "RPL_TRACEUSER", RPL_TRACEUSER }, + { "RPL_TRACESERVER", RPL_TRACESERVER }, + { "RPL_TRACESERVICE", RPL_TRACESERVICE }, + { "RPL_TRACENEWTYPE", RPL_TRACENEWTYPE }, + { "RPL_TRACECLASS", RPL_TRACECLASS }, + { "RPL_TRACERECONNECT", RPL_TRACERECONNECT }, + { "RPL_STATSLINKINFO", RPL_STATSLINKINFO }, + { "RPL_STATSCOMMANDS", RPL_STATSCOMMANDS }, + { "RPL_STATSCLINE", RPL_STATSCLINE }, + { "RPL_STATSILINE", RPL_STATSILINE }, + { "RPL_STATSQLINE", RPL_STATSQLINE }, + { "RPL_ENDOFSTATS", RPL_ENDOFSTATS }, + { "RPL_UMODEIS", RPL_UMODEIS }, + { "RPL_SERVICEINFO", RPL_SERVICEINFO }, + { "RPL_SERVICE", RPL_SERVICE }, + { "RPL_SERVLIST", RPL_SERVLIST }, + { "RPL_SERVLISTEND", RPL_SERVLISTEND }, + { "RPL_STATSVLINE", RPL_STATSVLINE }, + { "RPL_STATSUPTIME", RPL_STATSUPTIME }, + { "RPL_STATSOLINE", RPL_STATSOLINE }, + { "RPL_STATSHLINE", RPL_STATSHLINE }, + { "RPL_STATSPING", RPL_STATSPING }, + { "RPL_STATSDLINE", RPL_STATSDLINE }, + { "RPL_LUSERCLIENT", RPL_LUSERCLIENT }, + { "RPL_LUSEROP", RPL_LUSEROP }, + { "RPL_LUSERUNKNOWN", RPL_LUSERUNKNOWN }, + { "RPL_LUSERCHANNELS", RPL_LUSERCHANNELS }, + { "RPL_LUSERME", RPL_LUSERME }, + { "RPL_ADMINME", RPL_ADMINME }, + { "RPL_ADMINLOC1", RPL_ADMINLOC1 }, + { "RPL_ADMINLOC2", RPL_ADMINLOC2 }, + { "RPL_ADMINEMAIL", RPL_ADMINEMAIL }, + { "RPL_TRACELOG", RPL_TRACELOG }, + { "RPL_TRACEEND", RPL_TRACEEND }, + { "RPL_TRYAGAIN", RPL_TRYAGAIN }, + { "RPL_NONE", RPL_NONE }, + { "RPL_AWAY", RPL_AWAY }, + { "RPL_USERHOST", RPL_USERHOST }, + { "RPL_ISON", RPL_ISON }, + { "RPL_UNAWAY", RPL_UNAWAY }, + { "RPL_NOWAWAY", RPL_NOWAWAY }, + { "RPL_WHOISUSER", RPL_WHOISUSER }, + { "RPL_WHOISSERVER", RPL_WHOISSERVER }, + { "RPL_WHOISOPERATOR", RPL_WHOISOPERATOR }, + { "RPL_WHOWASUSER", RPL_WHOWASUSER }, + { "RPL_ENDOFWHO", RPL_ENDOFWHO }, + { "RPL_WHOISIDLE", RPL_WHOISIDLE }, + { "RPL_ENDOFWHOIS", RPL_ENDOFWHOIS }, + { "RPL_WHOISCHANNELS", RPL_WHOISCHANNELS }, + { "RPL_LISTSTART", RPL_LISTSTART }, + { "RPL_LIST", RPL_LIST }, + { "RPL_LISTEND", RPL_LISTEND }, + { "RPL_CHANNELMODEIS", RPL_CHANNELMODEIS }, + { "RPL_UNIQOPIS", RPL_UNIQOPIS }, + { "RPL_NOTOPIC", RPL_NOTOPIC }, + { "RPL_TOPIC", RPL_TOPIC }, + { "RPL_INVITING", RPL_INVITING }, + { "RPL_SUMMONING", RPL_SUMMONING }, + { "RPL_INVITELIST", RPL_INVITELIST }, + { "RPL_ENDOFINVITELIST", RPL_ENDOFINVITELIST }, + { "RPL_EXCEPTLIST", RPL_EXCEPTLIST }, + { "RPL_ENDOFEXCEPTLIST", RPL_ENDOFEXCEPTLIST }, + { "RPL_VERSION", RPL_VERSION }, + { "RPL_WHOREPLY", RPL_WHOREPLY }, + { "RPL_NAMREPLY", RPL_NAMREPLY }, + { "RPL_KILLDONE", RPL_KILLDONE }, + { "RPL_CLOSEEND", RPL_CLOSEEND }, + { "RPL_LINKS", RPL_LINKS }, + { "RPL_ENDOFLINKS", RPL_ENDOFLINKS }, + { "RPL_ENDOFNAMES", RPL_ENDOFNAMES }, + { "RPL_BANLIST", RPL_BANLIST }, + { "RPL_ENDOFBANLIST", RPL_ENDOFBANLIST }, + { "RPL_ENDOFWHOWAS", RPL_ENDOFWHOWAS }, + { "RPL_INFO", RPL_INFO }, + { "RPL_MOTD", RPL_MOTD }, + { "RPL_ENDOFINFO", RPL_ENDOFINFO }, + { "RPL_MOTDSTART", RPL_MOTDSTART }, + { "RPL_ENDOFMOTD", RPL_ENDOFMOTD }, + { "RPL_YOUREOPER", RPL_YOUREOPER }, + { "RPL_REHASHING", RPL_REHASHING }, + { "RPL_YOURESERVICE", RPL_YOURESERVICE }, + { "RPL_MYPORTIS", RPL_MYPORTIS }, + { "RPL_TIME", RPL_TIME }, + { "RPL_USERSSTART", RPL_USERSSTART }, + { "RPL_USERS", RPL_USERS }, + { "RPL_ENDOFUSERS", RPL_ENDOFUSERS }, + { "RPL_NOUSERS", RPL_NOUSERS }, + { "ERR_NOSUCHNICK", ERR_NOSUCHNICK }, + { "ERR_NOSUCHSERVER", ERR_NOSUCHSERVER }, + { "ERR_NOSUCHCHANNEL", ERR_NOSUCHCHANNEL }, + { "ERR_CANNOTSENDTOCHAN", ERR_CANNOTSENDTOCHAN }, + { "ERR_TOOMANYCHANNELS", ERR_TOOMANYCHANNELS }, + { "ERR_WASNOSUCHNICK", ERR_WASNOSUCHNICK }, + { "ERR_TOOMANYTARGETS", ERR_TOOMANYTARGETS }, + { "ERR_NOSUCHSERVICE", ERR_NOSUCHSERVICE }, + { "ERR_NOORIGIN", ERR_NOORIGIN }, + { "ERR_NORECIPIENT", ERR_NORECIPIENT }, + { "ERR_NOTEXTTOSEND", ERR_NOTEXTTOSEND }, + { "ERR_NOTOPLEVEL", ERR_NOTOPLEVEL }, + { "ERR_WILDTOPLEVEL", ERR_WILDTOPLEVEL }, + { "ERR_BADMASK", ERR_BADMASK }, + { "ERR_UNKNOWNCOMMAND", ERR_UNKNOWNCOMMAND }, + { "ERR_NOMOTD", ERR_NOMOTD }, + { "ERR_NOADMININFO", ERR_NOADMININFO }, + { "ERR_FILEERROR", ERR_FILEERROR }, + { "ERR_NONICKNAMEGIVEN", ERR_NONICKNAMEGIVEN }, + { "ERR_ERRONEUSNICKNAME", ERR_ERRONEUSNICKNAME }, + { "ERR_NICKNAMEINUSE", ERR_NICKNAMEINUSE }, + { "ERR_NICKCOLLISION", ERR_NICKCOLLISION }, + { "ERR_UNAVAILRESOURCE", ERR_UNAVAILRESOURCE }, + { "ERR_USERNOTINCHANNEL", ERR_USERNOTINCHANNEL }, + { "ERR_NOTONCHANNEL", ERR_NOTONCHANNEL }, + { "ERR_USERONCHANNEL", ERR_USERONCHANNEL }, + { "ERR_NOLOGIN", ERR_NOLOGIN }, + { "ERR_SUMMONDISABLED", ERR_SUMMONDISABLED }, + { "ERR_USERSDISABLED", ERR_USERSDISABLED }, + { "ERR_NOTREGISTERED", ERR_NOTREGISTERED }, + { "ERR_NEEDMOREPARAMS", ERR_NEEDMOREPARAMS }, + { "ERR_ALREADYREGISTRED", ERR_ALREADYREGISTRED }, + { "ERR_NOPERMFORHOST", ERR_NOPERMFORHOST }, + { "ERR_PASSWDMISMATCH", ERR_PASSWDMISMATCH }, + { "ERR_YOUREBANNEDCREEP", ERR_YOUREBANNEDCREEP }, + { "ERR_YOUWILLBEBANNED", ERR_YOUWILLBEBANNED }, + { "ERR_KEYSET", ERR_KEYSET }, + { "ERR_CHANNELISFULL", ERR_CHANNELISFULL }, + { "ERR_UNKNOWNMODE", ERR_UNKNOWNMODE }, + { "ERR_INVITEONLYCHAN", ERR_INVITEONLYCHAN }, + { "ERR_BANNEDFROMCHAN", ERR_BANNEDFROMCHAN }, + { "ERR_BADCHANNELKEY", ERR_BADCHANNELKEY }, + { "ERR_BADCHANMASK", ERR_BADCHANMASK }, + { "ERR_NOCHANMODES", ERR_NOCHANMODES }, + { "ERR_BANLISTFULL", ERR_BANLISTFULL }, + { "ERR_NOPRIVILEGES", ERR_NOPRIVILEGES }, + { "ERR_CHANOPRIVSNEEDED", ERR_CHANOPRIVSNEEDED }, + { "ERR_CANTKILLSERVER", ERR_CANTKILLSERVER }, + { "ERR_RESTRICTED", ERR_RESTRICTED }, + { "ERR_UNIQOPPRIVSNEEDED", ERR_UNIQOPPRIVSNEEDED }, + { "ERR_NOOPERHOST", ERR_NOOPERHOST }, + { "ERR_NOSERVICEHOST", ERR_NOSERVICEHOST }, + { "ERR_UMODEUNKNOWNFLAG", ERR_UMODEUNKNOWNFLAG }, + { "ERR_USERSDONTMATCH", ERR_USERSDONTMATCH }, +}; + +Channel * Channel::start = NULL; + +Channel::Channel(const String & Name, const String & Key) : next(NULL), prev(NULL) { + next = start->next; + prev = start; + start = this; + if (next) next->prev = this; +} + +Channel::~Channel() { + if (next) next->prev = prev; + if (prev) prev->next = next; else start = next; +} + +ircmsg_t find_msg(int code) { + int i; + + ircmsg_t ret = {"", code}; + + for (i = 0; i < MSG_COUNT; i++) { + if (code == ircmsgs[i].code) return ircmsgs[i]; + } + + return ret; +} + +IRC::IRC(const String & nick_n, const String & server_n, const String & user_n, const String & name_n, int port_n) : + nick(nick_n), server(server_n), user(user_n), name(name_n), port(port_n), loginsequence(1) { +} + +IRC::~IRC() { +} + +bool IRC::Connect() { + return sock.Connect(server, port); +} + +int IRC::Parse(const String & line) { + if (!strcmp(line.to_charp(0, 3), "PING")) { + sock << "PONG" << line.to_charp(4) << endhl; + cerr << "PING/PONG" << line.to_charp(4) << endhl; + return 0; + } + + return 1; +} + +void IRC::MainLoop() { + String line; + int code, count = 0; + + while (true) { + switch (loginsequence) { + case 1: + cerr << "Trying the login sequence..." << endl; + sock << "NICK " << nick << endhl; + sock << "USER " << user << " 8 * :" << name << endhl; + sock << "JOIN #phear.org dede" << endhl; + loginsequence = 0; + } + sock >> line; + if ((code = Parse(line))) { +// sock << "PRIVMSG #phear.org : Unparsable: " << line << endhl; + cerr << "Unparsable: " << line << endl; + } + + if (count == 20) { + sock << "JOIN #phear.org dede" << endhl; + } + + count++; + } +} |