irc.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           irc.h  -  description
00003                              -------------------
00004     begin                : Thu Dec 9 2004
00005     copyright            : (C) 2004 by VooDooMan
00006     email                : vdmfun@hotmail.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010 
00011 VooDoo cIRCle - an IRC (ro)bot
00012 Copyright (C) 2004 by Marian VooDooMan Meravy (vdmfun@hotmail.com)
00013 
00014 This program is free software; you can redistribute it and/or
00015 modify it under the terms of the GNU General Public License
00016 as published by the Free Software Foundation; either version 2
00017 of the License, or (at your option) any later version.
00018 
00019 This program is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License
00025 along with this program; if not, write to the Free Software
00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ****************************************************************************/
00029 
00030 /*!
00031     \file
00032     \brief Handles core communication with IRC server
00033 */
00034 
00035 //---------------------------------------------------------------------------
00036 
00037 #ifndef ircH
00038 #define ircH
00039 //---------------------------------------------------------------------------
00040 
00041 #include <time.h>
00042 #include <string>
00043 #include <map>
00044 
00045 using namespace std;
00046 
00047 /*!
00048     \def CRITICAL_PRIORITY
00049     \brief Command is sent immediatelly
00050 */
00051 #define CRITICAL_PRIORITY   1
00052 /*!
00053     \def HIGH_PRIORITY
00054     \brief Command is put to high-priority queue
00055 */
00056 #define HIGH_PRIORITY       2
00057 /*!
00058     \def LOW_PRIORITY
00059     \brief Command is put to low-priority queue
00060 */
00061 #define LOW_PRIORITY        3
00062 
00063 /*!
00064     \brief Stores messages for server (for bot's flood protection mechanism)
00065     \author VooDooMan
00066     \version 1
00067     \date 2004
00068 */
00069 struct s_msg_to_server {
00070     char* msg;                              //!< Raw message
00071     bool wait_for_response;                 //!< Should we wait for server's response?
00072 
00073     bool flood_protection;                  //!< Should be aplied flood protecion methods? (set to true for PRIVMSG && NOTICE)
00074 
00075     char response[1024];                    //!< Response of server (if response[0]==0: response wasn't received yet)
00076 
00077     time_t timestamp;                       //!< Timestamp of message
00078 
00079     s_msg_to_server()
00080     {
00081         msg=NULL;
00082         wait_for_response=false;
00083         memset(response,0,sizeof(response));
00084         flood_protection=true;
00085         timestamp=time(NULL);
00086     }
00087 };
00088 
00089 /*!
00090     \brief Stores parsed data of ISUPPORT 005 numeric reply
00091     \author VooDooMan
00092     \version 1
00093     \date 2004
00094 */
00095 struct s_005 {
00096     map<string,string> raw;                     //!< Raw associative array of features
00097     string chanmodes_a;                         //!< chanmodes A - has a parameter as mask of user
00098     string chanmodes_b;                         //!< chanmodes B - always have a parameter
00099     string chanmodes_c;                         //!< chanmodes C - only has parameter when set (+)
00100     string chanmodes_d;                         //!< chanmodes D - never has a parameter
00101     map<char,char> prefix;                      //!< Prefixes ('o'=='@', 'v'=='+', etc.)
00102 
00103     int max_modes;                              //!< Maximum modes with parameter in one single MODE command
00104 
00105     void clear() {
00106         raw.clear();
00107         chanmodes_a="";
00108         chanmodes_b="";
00109         chanmodes_c="";
00110         chanmodes_d="";
00111         prefix.clear();
00112         max_modes=3;
00113     }
00114 
00115     /*!
00116         \brief Translates mode
00117         \param x Mode (e.g. 'o', 'v')
00118         \return Returns translated mode (e.g. '@' for x=='o', '+' for x=='v')
00119     */
00120     char get_prefix1(char x) {
00121         map<char,char>::iterator i1;
00122         for(i1=prefix.begin(); i1!=prefix.end(); i1++)
00123             if((*i1).first==x)
00124                 return (*i1).second;
00125         return '0';
00126     }
00127 
00128     /*!
00129         \brief Translates mode
00130         \param x Mode (e.g. '@', '+')
00131         \return Returns translated mode (e.g. 'o' for x=='@', 'v' for x=='+')
00132     */
00133     char get_prefix2(char x) {
00134         map<char,char>::iterator i1;
00135         for(i1=prefix.begin(); i1!=prefix.end(); i1++)
00136             if((*i1).second==x)
00137                 return (*i1).first;
00138         return '0';
00139     }
00140 };
00141 
00142 int irc_disconnect();
00143 int irc_connect(const char* bind_ip, const char* host_, unsigned short port);
00144 bool irc_loop_putserv();
00145 int irc_loop_process_input();
00146 bool irc_op(const char* channel, const char* nick, int priority); // false==error
00147 bool irc_deop(const char* channel, const char* nick, int priority); // false==error
00148 bool irc_voice(const char* channel, const char* nick, int priority); // false==error
00149 bool irc_devoice(const char* channel, const char* nick, int priority); // false==error
00150 bool irc_kick(const char* channel, const char* nick, const char* reason); // false==error
00151 bool irc_join(const char* channel, const char* key);
00152 bool irc_part(const char* channel, const char* reason);
00153 bool irc_privmsg(const char* target, const char* msg, int priority);
00154 bool irc_notice(const char* target, const char* msg, int priority);
00155 bool irc_unban(const char* channel, const char* mask);
00156 bool irc_ban(const char* channel, const char* mask);
00157 bool irc_chan_mode(const char* channel, const char* mode,int priority);
00158 
00159 void irc_set_redir(bool follow_redirs);
00160 
00161 // returns nick of known user; if user is unknown, returns user
00162 string irc_get_nick(string user);
00163 // returns nick of known user; if user is not online, returns an empty string
00164 string irc_is_online(string user);
00165 
00166 string irc_get_ident(string nick);
00167 string irc_get_host(string nick);
00168 bool irc_is_ircop(string nick);
00169 string irc_get_mode(string channel, string nick);
00170 string irc_get_fullname(string nick);
00171 bool irc_got_op(string channel);
00172 
00173 void irc_put(string data, int priority);
00174 
00175 int cmp_strings_case_insensitive(string s1, string s2);
00176 
00177 void irc_quit(const char* reason);
00178 
00179 void irc_await_dcc_chat(string nick, string user_name_as_in_logic, int dcc_group);
00180 
00181 bool irc_putserv(const char* msg, bool wait_for_response, int priority);
00182 
00183 void irc_rehashed();
00184 
00185 string irc_get_chan_mode(string channel, string& topic);
00186 
00187 void irc_get_005(map<string,string>& raw, map<char,char>& prefix, string& chm_a, string& chm_b, string& chm_c, string& chm_d);
00188 void irc_parse_modes(string modes, map<char,string>& with_param, string& plain);
00189 
00190 string irc_get_modes_for_log(string channel, string nick);
00191 
00192 #endif
00193 
00194 

Generated on Sun Jul 10 03:22:55 2005 for VooDoo cIRCle by doxygen 1.4.3

Hosted by SourceForge.net Logo