1 // ServerQueueItem.C -*- C++ -*-
2 // Copyright (c) 1998 Etienne BERNARD
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 #include "StringTokenizer.H"
19 #include "ServerQueue.H"
20 #include "ServerQueueItem.H"
22 ServerQueueItem::ServerQueueItem(int pr, int pen, int t)
23 : priority(pr), penalty(pen), type(t)
28 ServerQueueOtherItem::ServerQueueOtherItem(String l, int pr,
30 : ServerQueueItem(pr, pen, t), line(l)
34 ServerQueueOtherItem::getLine()
41 ServerQueueChannelModeItem::ServerQueueChannelModeItem(String c, String m, String p)
42 : ServerQueueItem(CHANNELMODE_PRIORITY,
45 channel(c), mode(m), parameters(p)
47 StringTokenizer st(p);
48 paramcount = st.countTokens();
52 ServerQueueChannelModeItem::merge(ServerQueueItem *sqi)
54 if (sqi->type != CHANNELMODE)
57 ServerQueueChannelModeItem * sqcmi = (ServerQueueChannelModeItem *)sqi;
59 if (sqcmi->channel != channel || (paramcount + sqcmi->paramcount > 3))
65 for (int i = 0; i < mode.length(); i++) {
76 for (int i = 0; i < sqcmi->mode.length(); i++) {
84 if (othersign == sign)
85 mode = mode + String(c);
87 mode = mode + String(othersign) + String(c);
93 parameters = parameters + " " + sqcmi->parameters;
94 paramcount += sqcmi->paramcount;
95 penalty += sqcmi->penalty;
101 ServerQueueChannelModeItem::getLine()
103 return String("MODE ") + channel + " " + mode + " " + parameters;
108 ServerQueueKickItem::ServerQueueKickItem(String c, String w, String r)
109 : ServerQueueItem(KICK_PRIORITY,
112 channel(c), who(w), reason(r), count(1)
116 ServerQueueKickItem::merge(ServerQueueItem *sqi)
118 if (sqi->type != KICK)
120 ServerQueueKickItem * sqki = (ServerQueueKickItem *)sqi;
121 if (sqki->channel != channel)
123 if (count + sqki->count > 4)
125 who = who + "," + sqki->who;
126 if (reason != sqki->reason)
127 reason = "Mixed kick ! Top efficiency";
128 penalty += sqki->penalty;
129 count += sqki->count;
135 ServerQueueKickItem::getLine()
137 return String("KICK ") + channel + " " + who + " :" + reason;
140 ServerQueueNoticeItem::ServerQueueNoticeItem(String d, String m)
141 : ServerQueueItem(NOTICE_PRIORITY,
144 dest(d), message(m), count(1)
148 ServerQueueNoticeItem::merge(ServerQueueItem *sqi)
150 if (sqi->type != NOTICE)
152 ServerQueueNoticeItem * sqni = (ServerQueueNoticeItem *)sqi;
153 if (sqni->message != message)
155 if (count + sqni->count > 4)
157 dest = dest + "," + sqni->dest;
158 penalty += sqni->penalty;
159 count += sqni->count;
165 ServerQueueNoticeItem::getLine()
167 return String("NOTICE ") + dest + " :" + message;