00001 00010 /* 00011 * Copyright (c) 2002 James Hess 00012 * All rights reserved. 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions 00016 * are met: 00017 * 1. Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * 2. Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in the 00021 * documentation and/or other materials provided with the distribution. 00022 * 3. Neither the name of the authors nor the names of its contributors 00023 * may be used to endorse or promote products derived from this software 00024 * without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 00027 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 00030 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00031 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00032 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00033 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00034 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00035 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00036 * SUCH DAMAGE. 00037 */ 00038 00039 #include "services.h" 00040 #include "chanserv.h" 00041 #include "nickserv.h" 00042 #include "macro.h" 00043 #include "queue.h" 00044 #include "hash.h" 00045 #include "db.h" 00046 #include "chantrig.h" 00047 00053 ChanTrigger* FindChannelTrigger(const char* name) 00054 { 00055 ChanTrigger* s; 00056 long hashEnt = getHashKey(name)%CHANTRIGHASHSIZE; 00057 00058 if (!LIST_FIRST(&ChanTrigHash[hashEnt])) 00059 return 0; 00060 00061 for(s = LIST_FIRST(&ChanTrigHash[hashEnt]); s != 0; 00062 s = LIST_NEXT(s, cn_lst)) 00063 if (!strcasecmp(name, s->chan_name)) 00064 return s; 00065 return 0; 00066 } 00067 00073 void DelChannelTrigger(ChanTrigger* ct) 00074 { 00075 if (ct) { 00076 LIST_REMOVE(ct, cn_lst); 00077 } 00078 } 00079 00083 void AddChannelTrigger(ChanTrigger* ct) 00084 { 00085 long hashEnt = getHashKey(ct->chan_name)%CHANTRIGHASHSIZE; 00086 00087 if (ct) { 00088 LIST_INSERT_HEAD(&ChanTrigHash[hashEnt], ct, cn_lst); 00089 } 00090 } 00091 00095 void FreeChannelTrigger(ChanTrigger* ct) 00096 { 00097 if (ct) { 00098 if (ct->chan_name) 00099 FREE(ct->chan_name); 00100 FREE(ct); 00101 } 00102 } 00103 00107 ChanTrigger* MakeChannelTrigger(const char* cn) 00108 { 00109 ChanTrigger* t_new = (ChanTrigger *) oalloc(sizeof(ChanTrigger)); 00110 00111 t_new->chan_name = str_dup(cn); 00112 t_new->op_trigger = t_new->ak_trigger = 0; 00113 t_new->impose_modes = 0; 00114 t_new->flags = 0; 00115 00116 return t_new; 00117 } 00118 00122 unsigned int ChanMaxAkicks(RegChanList* cn) 00123 { 00124 ChanTrigger* trig; 00125 int lim = AkickLimit; 00126 00127 trig = FindChannelTrigger(cn->name); 00128 00129 if (trig && trig->ak_trigger != 0) 00130 lim = trig->ak_trigger; 00131 return lim; 00132 } 00133 00137 unsigned int ChanMaxOps(RegChanList* cn) 00138 { 00139 ChanTrigger* trig; 00140 int lim = OpLimit; 00141 00142 trig = FindChannelTrigger(cn->name); 00143 00144 if (trig && trig->op_trigger != 0) 00145 lim = trig->op_trigger; 00146 return lim; 00147 } 00148