1 // ServerQueueItem.C -*- C++ -*-
2 // Copyright (c) 1998 Etienne BERNARD
3 // Copyright (c) 2005 Clinton Ebadi
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include "StringTokenizer.H"
21 #include "ServerQueue.H"
22 #include "ServerQueueItem.H"
24 ServerQueueItem::ServerQueueItem(int pr, int pen, int t)
25 : priority(pr), penalty(pen), type(t)
28 ServerQueueOtherItem::ServerQueueOtherItem(String l, int pr,
30 : ServerQueueItem(pr, pen, t), line(l)
33 bool ServerQueueItem::operator< (const ServerQueueItem & item)
35 // lower numeric priority is higher priority
36 return item.priority < priority;
40 ServerQueueOtherItem::getLine()
45 ServerQueueChannelModeItem::ServerQueueChannelModeItem(String c, String m, String p)
46 : ServerQueueItem(CHANNELMODE_PRIORITY,
49 channel(c), mode(m), parameters(p)
51 StringTokenizer st(p);
52 paramcount = st.count_tokens();
56 ServerQueueChannelModeItem::merge(ServerQueueItem *sqi)
58 if (sqi->type != CHANNELMODE)
61 ServerQueueChannelModeItem * sqcmi = (ServerQueueChannelModeItem *)sqi;
63 if (sqcmi->channel != channel || (paramcount + sqcmi->paramcount > 3))
69 for (int i = 0; i < mode.length(); i++) {
80 for (int i = 0; i < sqcmi->mode.length(); i++) {
88 if (othersign == sign)
89 mode = mode + String(c);
91 mode = mode + String(othersign) + String(c);
97 parameters = parameters + " " + sqcmi->parameters;
98 paramcount += sqcmi->paramcount;
99 penalty += sqcmi->penalty;
105 ServerQueueChannelModeItem::getLine()
107 return String("MODE ") + channel + " " + mode + " " + parameters;
112 ServerQueueKickItem::ServerQueueKickItem(String c, String w, String r)
113 : ServerQueueItem(KICK_PRIORITY,
116 channel(c), who(w), reason(r), count(1)
120 ServerQueueKickItem::merge(ServerQueueItem *sqi)
122 if (sqi->type != KICK)
124 ServerQueueKickItem * sqki = (ServerQueueKickItem *)sqi;
125 if (sqki->channel != channel)
127 if (count + sqki->count > 4)
129 who = who + "," + sqki->who;
130 if (reason != sqki->reason)
131 reason = "Mixed kick ! Top efficiency";
132 penalty += sqki->penalty;
133 count += sqki->count;
139 ServerQueueKickItem::getLine()
141 return String("KICK ") + channel + " " + who + " :" + reason;
144 ServerQueueNoticeItem::ServerQueueNoticeItem(String d, String m)
145 : ServerQueueItem(NOTICE_PRIORITY,
148 dest(d), message(m), count(1)
152 ServerQueueNoticeItem::merge(ServerQueueItem *sqi)
154 if (sqi->type != NOTICE)
156 ServerQueueNoticeItem * sqni = (ServerQueueNoticeItem *)sqi;
157 if (sqni->message != message)
159 if (count + sqni->count > 4)
161 dest = dest + "," + sqni->dest;
162 penalty += sqni->penalty;
163 count += sqni->count;
169 ServerQueueNoticeItem::getLine()
171 return String("NOTICE ") + dest + " :" + message;