ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An IRC bouncer. 00002 // 00003 //! @file Flags.cc 00004 //! @brief This file contains the implementation of class Flags. 00005 // 00006 // Copyright (C) 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef USE_PCH 00017 #include "sys.h" 00018 #endif 00019 00020 #include "Flags.h" 00021 00022 typedef Network::who_flags_type flags_type; 00023 00024 void Network::init_who_flag_table(std::string const& umodes, std::string LIBCW_UNUSED(prefix)) 00025 { 00026 // Only initialize the table once. 00027 if (!M_who_flag_vector.empty()) 00028 return; 00029 // FIXME: use prefix to map special characters to channel modes. 00030 int n = 1; // The AWAY flag (H/G). 00031 n += umodes.size(); 00032 M_who_flag_vector.resize(n); 00033 while(--n) 00034 { 00035 ASSERT(umodes[n] != '*'); // '*' has the special meaning of umode 'o', see Network::char_to_flag. 00036 M_who_flag_vector[n].who_flag = umodes[n]; 00037 M_who_flag_vector[n].mask = (1 << n); 00038 } 00039 // By ignoring the 'H' flag, we get the same effect for 'G' as for any other flag. 00040 M_who_flag_vector[n].who_flag = 'G'; 00041 M_who_flag_vector[n].mask = 1; 00042 } 00043 00044 char Network::flag_to_char(who_flags_type maskbit) const 00045 { 00046 // Make sure that Network::init_who_flag_table was already called. 00047 ASSERT(!M_who_flag_vector.empty()); 00048 // Find the corresponding flag. 00049 int index = 0; 00050 #ifdef CWDEBUG 00051 who_flags_type orig_maskbit; 00052 #endif 00053 while ((maskbit >>= 1)) 00054 ++index; 00055 #ifdef CWDEBUG 00056 if (M_who_flag_vector[index].mask != orig_maskbit) 00057 DoutFatal(dc::core, "Network::flag_to_char: Unknown maskbit " << std::hex << "0x" << orig_maskbit); 00058 #endif 00059 return M_who_flag_vector[index].who_flag; 00060 } 00061 00062 flags_type Network::char_to_flag(char who_flag) const 00063 { 00064 // Make sure that Network::init_who_flag_table was already called. 00065 ASSERT(!M_who_flag_vector.empty()); 00066 // Find the corresponding mask. 00067 if (who_flag == '*') 00068 who_flag = 'o'; 00069 for (who_flag_vector_type::const_iterator iter = M_who_flag_vector.begin(); iter != M_who_flag_vector.end(); ++iter) 00070 if (iter->who_flag == who_flag) 00071 return iter->mask; 00072 // We deliberately do not process 'H' because it just means that flag 'G' is off. 00073 // We also don't handle '@' because we never use WHO to determine who is op and who isn't. 00074 if (who_flag != 'H' && who_flag != '@') 00075 Dout(dc::warning, "Network::char_to_flag: Unknown who_flag '" << who_flag << "'."); 00076 return 0; 00077 } 00078 00079 void Flags::assign(Network const& network, std::string const& who_flags) 00080 { 00081 M_flags = 0; 00082 M_network = &network; 00083 for (std::string::const_iterator iter = who_flags.begin(); iter != who_flags.end(); ++iter) 00084 M_flags |= network.char_to_flag(*iter); 00085 }
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|