[project @ 2002-08-06 20:48:44 by unknown_lamer]
[clinton/bobotpp.git] / source / ServerQueueItem.C
CommitLineData
cb21075d 1// ServerQueueItem.C -*- C++ -*-
2// Copyright (c) 1998 Etienne BERNARD
3
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
7// any later version.
8
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.
13
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.
17
18#include "StringTokenizer.H"
19#include "ServerQueue.H"
20#include "ServerQueueItem.H"
21
22ServerQueueItem::ServerQueueItem(int pr, int pen, int t)
23 : priority(pr), penalty(pen), type(t)
24{ }
25
26
27
28ServerQueueOtherItem::ServerQueueOtherItem(String l, int pr,
29 int pen, int t)
30 : ServerQueueItem(pr, pen, t), line(l)
31{ }
32
33String
34ServerQueueOtherItem::getLine()
35{
36 return line;
37}
38
39
40
41ServerQueueChannelModeItem::ServerQueueChannelModeItem(String c, String m, String p)
42 : ServerQueueItem(CHANNELMODE_PRIORITY,
43 CHANNELMODE_PENALTY,
44 CHANNELMODE),
45 channel(c), mode(m), parameters(p)
46{
47 StringTokenizer st(p);
48 paramcount = st.countTokens();
49}
50
51bool
52ServerQueueChannelModeItem::merge(ServerQueueItem *sqi)
53{
54 if (sqi->type != CHANNELMODE)
55 return false;
56
57 ServerQueueChannelModeItem * sqcmi = (ServerQueueChannelModeItem *)sqi;
58
59 if (sqcmi->channel != channel || (paramcount + sqcmi->paramcount > 3))
60 return false;
61
62 char sign = '+';
63 char c;
64
65 for (int i = 0; i < mode.length(); i++) {
66 c = mode[i];
67 switch (c) {
68 case '+':
69 case '-':
70 sign = c;
71 }
72 }
73
74 char othersign = '+';
75
76 for (int i = 0; i < sqcmi->mode.length(); i++) {
77 c = sqcmi->mode[i];
78 switch (c) {
79 case '+':
80 case '-':
81 othersign = c;
82 break;
83 default:
84 if (othersign == sign)
85 mode = mode + String(c);
86 else {
87 mode = mode + String(othersign) + String(c);
88 sign = othersign;
89 }
90 }
91 }
92
93 parameters = parameters + " " + sqcmi->parameters;
94 paramcount += sqcmi->paramcount;
95 penalty += sqcmi->penalty;
96
97 return true;
98}
99
100String
101ServerQueueChannelModeItem::getLine()
102{
103 return String("MODE ") + channel + " " + mode + " " + parameters;
104}
105
106
107
108ServerQueueKickItem::ServerQueueKickItem(String c, String w, String r)
109 : ServerQueueItem(KICK_PRIORITY,
110 KICK_PENALTY,
111 KICK),
112 channel(c), who(w), reason(r), count(1)
113{ }
114
115bool
116ServerQueueKickItem::merge(ServerQueueItem *sqi)
117{
118 if (sqi->type != KICK)
119 return false;
120 ServerQueueKickItem * sqki = (ServerQueueKickItem *)sqi;
121 if (sqki->channel != channel)
122 return false;
123 if (count + sqki->count > 4)
124 return false;
125 who = who + "," + sqki->who;
126 if (reason != sqki->reason)
127 reason = "Mixed kick ! Top efficiency";
128 penalty += sqki->penalty;
129 count += sqki->count;
130
131 return true;
132}
133
134String
135ServerQueueKickItem::getLine()
136{
137 return String("KICK ") + channel + " " + who + " :" + reason;
138}
139
140ServerQueueNoticeItem::ServerQueueNoticeItem(String d, String m)
141 : ServerQueueItem(NOTICE_PRIORITY,
142 NOTICE_PENALTY,
143 NOTICE),
144 dest(d), message(m), count(1)
145{ }
146
147bool
148ServerQueueNoticeItem::merge(ServerQueueItem *sqi)
149{
150 if (sqi->type != NOTICE)
151 return false;
152 ServerQueueNoticeItem * sqni = (ServerQueueNoticeItem *)sqi;
153 if (sqni->message != message)
154 return false;
155 if (count + sqni->count > 4)
156 return false;
157 dest = dest + "," + sqni->dest;
158 penalty += sqni->penalty;
159 count += sqni->count;
160
161 return true;
162}
163
164String
165ServerQueueNoticeItem::getLine()
166{
167 return String("NOTICE ") + dest + " :" + message;
168}