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)
30 ServerQueueOtherItem::ServerQueueOtherItem(String l, int pr,
32 : ServerQueueItem(pr, pen, t), line(l)
36 ServerQueueOtherItem::getLine()
43 ServerQueueChannelModeItem::ServerQueueChannelModeItem(String c, String m, String p)
44 : ServerQueueItem(CHANNELMODE_PRIORITY,
47 channel(c), mode(m), parameters(p)
49 StringTokenizer st(p);
50 paramcount = st.count_tokens();
54 ServerQueueChannelModeItem::merge(ServerQueueItem *sqi)
56 if (sqi->type != CHANNELMODE)
59 ServerQueueChannelModeItem * sqcmi = (ServerQueueChannelModeItem *)sqi;
61 if (sqcmi->channel != channel || (paramcount + sqcmi->paramcount > 3))
67 for (int i = 0; i < mode.length(); i++) {
78 for (int i = 0; i < sqcmi->mode.length(); i++) {
86 if (othersign == sign)
87 mode = mode + String(c);
89 mode = mode + String(othersign) + String(c);
95 parameters = parameters + " " + sqcmi->parameters;
96 paramcount += sqcmi->paramcount;
97 penalty += sqcmi->penalty;
103 ServerQueueChannelModeItem::getLine()
105 return String("MODE ") + channel + " " + mode + " " + parameters;
110 ServerQueueKickItem::ServerQueueKickItem(String c, String w, String r)
111 : ServerQueueItem(KICK_PRIORITY,
114 channel(c), who(w), reason(r), count(1)
118 ServerQueueKickItem::merge(ServerQueueItem *sqi)
120 if (sqi->type != KICK)
122 ServerQueueKickItem * sqki = (ServerQueueKickItem *)sqi;
123 if (sqki->channel != channel)
125 if (count + sqki->count > 4)
127 who = who + "," + sqki->who;
128 if (reason != sqki->reason)
129 reason = "Mixed kick ! Top efficiency";
130 penalty += sqki->penalty;
131 count += sqki->count;
137 ServerQueueKickItem::getLine()
139 return String("KICK ") + channel + " " + who + " :" + reason;
142 ServerQueueNoticeItem::ServerQueueNoticeItem(String d, String m)
143 : ServerQueueItem(NOTICE_PRIORITY,
146 dest(d), message(m), count(1)
150 ServerQueueNoticeItem::merge(ServerQueueItem *sqi)
152 if (sqi->type != NOTICE)
154 ServerQueueNoticeItem * sqni = (ServerQueueNoticeItem *)sqi;
155 if (sqni->message != message)
157 if (count + sqni->count > 4)
159 dest = dest + "," + sqni->dest;
160 penalty += sqni->penalty;
161 count += sqni->count;
167 ServerQueueNoticeItem::getLine()
169 return String("NOTICE ") + dest + " :" + message;