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