1 // ServerQueue.C -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (C) 2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24 #include "ServerQueue.H"
26 ServerQueue::ServerQueue(Socket * s, bool d)
27 : Queue(s,d), penalty(0)
34 ServerQueue::~ServerQueue()
41 ServerQueue::addItem(ServerQueueItem *sqi)
43 std::list<ServerQueueItem *>::iterator it, it2;
45 for (it = serverQueue.begin(); it != serverQueue.end(); ++it) {
46 if ((*it)->priority > sqi->priority)
50 if (it2 != serverQueue.end() && *it2) {
51 // All right, we try to merge this item to the previous
52 if ((*it2)->merge(sqi)) {
57 serverQueue.insert(it, sqi);
61 ServerQueue::addLine(String l, int pr, int pen, int t)
63 ServerQueueOtherItem * sqoi =
64 new ServerQueueOtherItem(l, pr, pen, t);
71 // Called every second, we decrement the penalty
75 while (!serverQueue.empty() && (penalty < 5)) {
76 ServerQueueItem * sqi = (*serverQueue.begin());
77 penalty += sqi->penalty + sqi->getLine().length()/100 + 1;
78 bool res = sendLine(sqi->getLine());
79 serverQueue.erase(serverQueue.begin());
88 ServerQueue::sendCTCP(String to, String command,
91 sendPrivmsg(to, String("\001") + command + " " + message + "\001");
95 ServerQueue::sendCTCPReply(String to, String command,
98 sendNotice(to, String("\001") + command + " " +
103 ServerQueue::sendChannelMode(String mode)
105 addLine(mode, CHANNELMODE_PRIORITY, CHANNELMODE_PENALTY,
106 ServerQueueItem::CHANNELMODE);
110 ServerQueue::sendChannelMode(String channel, String mode, String parameters)
112 ServerQueueChannelModeItem * sqcmi =
113 new ServerQueueChannelModeItem(channel, mode, parameters);
118 ServerQueue::sendInvite(String channel, String nick)
120 addLine(String("INVITE ") + nick + " " + channel,
121 INVITE_PRIORITY, INVITE_PENALTY, ServerQueueItem::INVITE);
125 ServerQueue::sendJoin(String channel, String key)
127 addLine(String("JOIN ") + channel + " " + key,
128 JOIN_PRIORITY, JOIN_PENALTY, ServerQueueItem::JOIN);
132 ServerQueue::sendKick(String channel, String nick, String reason)
134 ServerQueueKickItem * sqki =
135 new ServerQueueKickItem(channel, nick, reason);
140 ServerQueue::sendNick(String nick)
142 addLine(String("NICK ") + nick,
143 NICK_PRIORITY, NICK_PENALTY, ServerQueueItem::NICK);
147 ServerQueue::sendNotice(String to, String message)
149 ServerQueueNoticeItem *sqni =
150 new ServerQueueNoticeItem(to, message);
155 ServerQueue::sendPart(String channel)
157 addLine(String("PART ") + channel,
158 PART_PRIORITY, PART_PENALTY, ServerQueueItem::PART);
162 ServerQueue::sendPass(String pass)
164 addLine(String("PASS ") + pass,
165 NICK_PRIORITY, NICK_PENALTY, ServerQueueItem::PASS);
169 ServerQueue::sendPing(String server)
171 addLine(String("PING :") + server,
172 PING_PRIORITY, PING_PENALTY, ServerQueueItem::PING);
176 ServerQueue::sendPong(String crap)
178 addLine(String("PONG ") + crap,
179 PONG_PRIORITY, PONG_PENALTY, ServerQueueItem::PONG);
183 ServerQueue::sendPrivmsg(String dest, String message)
185 addLine(String("PRIVMSG ") + dest + " :" + message,
186 PRIVMSG_PRIORITY, PRIVMSG_PENALTY, ServerQueueItem::PRIVMSG);
190 ServerQueue::sendQuit(String reason)
192 addLine(String("QUIT :") + reason,
193 QUIT_PRIORITY, QUIT_PENALTY, ServerQueueItem::QUIT);
197 ServerQueue::sendTopic(String channel, String topic)
199 addLine(String("TOPIC ") + channel + " :" + topic,
200 TOPIC_PRIORITY, TOPIC_PENALTY, ServerQueueItem::TOPIC);
204 ServerQueue::sendUser(String username, String ircname)
206 addLine(String("USER ") + username + " . . :" + ircname,
207 NICK_PRIORITY, NICK_PENALTY, ServerQueueItem::USER);
211 ServerQueue::sendUserMode(String nick, String mode)
213 addLine(String("MODE ") + nick + " " + mode,
214 USERMODE_PRIORITY, USERMODE_PENALTY,
215 ServerQueueItem::USERMODE);
219 ServerQueue::sendUserhost(String nick)
221 addLine(String("USERHOST ") + nick,
222 USERHOST_PRIORITY, USERHOST_PENALTY, ServerQueueItem::USERHOST);
226 ServerQueue::sendWho(String who)
228 addLine(String("WHO ") + who,
229 WHO_PRIORITY, WHO_PENALTY, ServerQueueItem::WHO);
233 ServerQueue::sendWhois(String nick)
235 addLine(String("WHOIS ") + nick,
236 NICK_PRIORITY, WHOIS_PENALTY, ServerQueueItem::WHOIS);