genesis 1 import socket
genesis 2 import time
genesis 3 import re
genesis 4 import os
genesis 5 import base64
9990-keep-ephemer... 6 import traceback
9987-embargoing 7 import logging
9982-getdata 8 import datetime
9982-getdata 9 from message import Message, PEST_VERSION
9982-getdata 10 from broadcast import Broadcast
9982-getdata 11 from direct import Direct
9982-getdata 12 from station import VERSION
genesis 13 from funcs import *
9982-getdata 14 from commands import BROADCAST, DIRECT
genesis 15
genesis 16 class Client(object):
genesis 17 __linesep_regexp = re.compile(r"\r?\n")
genesis 18
genesis 19 __valid_nickname_regexp = re.compile(
genesis 20 r"^[][\`_^{|}A-Za-z][][\`_^{|}A-Za-z0-9-]{0,50}$")
genesis 21 __valid_channelname_regexp = re.compile(
genesis 22 r"^[&#+!][^\x00\x07\x0a\x0d ,:]{0,50}$")
genesis 23
genesis 24 def __init__(self, server, socket):
genesis 25 self.server = server
9982-getdata 26 self.state = None
genesis 27 self.socket = socket
genesis 28 self.channels = {}
genesis 29 self.nickname = None
genesis 30 self.user = None
genesis 31 self.realname = None
genesis 32 (self.host, self.port) = socket.getpeername()
genesis 33 self.__timestamp = time.time()
genesis 34 self.__readbuffer = ""
genesis 35 self.__writebuffer = ""
genesis 36 self.__sent_ping = False
genesis 37 if self.server.password:
genesis 38 self.__handle_command = self.__pass_handler
genesis 39 else:
genesis 40 self.__handle_command = self.__registration_handler
genesis 41
9987-embargoing 42 def message_from_station(self, msg):
9987-embargoing 43 targetname = self.server.channel_name if msg.command == BROADCAST else self.nickname
9987-embargoing 44 pest_prefix = msg.prefix if msg.prefix else msg.speaker
9981-replay-notice 45 formatted_message = ":%s PRIVMSG %s :%s" % (
9982-getdata 46 pest_prefix,
9982-getdata 47 targetname,
9982-getdata 48 msg.body
9982-getdata 49 )
9987-embargoing 50 self.__writebuffer += formatted_message + "\r\n"
genesis 51
genesis 52 def get_prefix(self):
9989-show-wot-nicks 53 return "%s" % (self.nickname)
genesis 54 prefix = property(get_prefix)
genesis 55
genesis 56 def check_aliveness(self):
genesis 57 now = time.time()
genesis 58 if self.__timestamp + 180 < now:
genesis 59 self.disconnect("ping timeout")
genesis 60 return
genesis 61 if not self.__sent_ping and self.__timestamp + 90 < now:
genesis 62 if self.__handle_command == self.__command_handler:
genesis 63
genesis 64 self.message("PING :%s" % self.server.name)
genesis 65 self.__sent_ping = True
genesis 66 else:
genesis 67
genesis 68 self.disconnect("ping timeout")
genesis 69
genesis 70 def write_queue_size(self):
genesis 71 return len(self.__writebuffer)
genesis 72
genesis 73 def __parse_read_buffer(self):
genesis 74 lines = self.__linesep_regexp.split(self.__readbuffer)
genesis 75 self.__readbuffer = lines[-1]
genesis 76 lines = lines[:-1]
genesis 77 for line in lines:
genesis 78 if not line:
genesis 79
genesis 80 continue
9982-getdata 81 command, arguments = self.__parse_command_arguments(line)
genesis 82 self.__handle_command(command, arguments)
genesis 83
9982-getdata 84 def __parse_command_arguments(self, line):
9982-getdata 85 x = line.split(" ", 1)
9982-getdata 86 command = x[0].upper()
9982-getdata 87 if len(x) == 1:
9982-getdata 88 arguments = []
9982-getdata 89 else:
9982-getdata 90 if len(x[1]) > 0 and x[1][0] == ":":
9982-getdata 91 arguments = [x[1][1:]]
9982-getdata 92 else:
9982-getdata 93 y = string.split(x[1], " :", 1)
9982-getdata 94 arguments = string.split(y[0])
9982-getdata 95 if len(y) == 2:
9982-getdata 96 arguments.append(y[1])
9982-getdata 97 return command, arguments
9982-getdata 98
genesis 99 def __pass_handler(self, command, arguments):
genesis 100 server = self.server
genesis 101 if command == "PASS":
genesis 102 if len(arguments) == 0:
genesis 103 self.reply_461("PASS")
genesis 104 else:
genesis 105 if arguments[0].lower() == server.password:
genesis 106 self.__handle_command = self.__registration_handler
genesis 107 else:
genesis 108 self.reply("464 :Password incorrect")
genesis 109 elif command == "QUIT":
genesis 110 self.disconnect("Client quit")
genesis 111 return
genesis 112
genesis 113 def __registration_handler(self, command, arguments):
genesis 114 server = self.server
genesis 115 if command == "NICK":
genesis 116 if len(arguments) < 1:
genesis 117 self.reply("431 :No nickname given")
genesis 118 return
genesis 119 nick = arguments[0]
genesis 120 if server.get_client(nick):
genesis 121 self.reply("433 * %s :Nickname is already in use" % nick)
genesis 122 elif not self.__valid_nickname_regexp.match(nick):
genesis 123 self.reply("432 * %s :Erroneous nickname" % nick)
genesis 124 else:
genesis 125 self.nickname = nick
9982-getdata 126 self.state.set_knob("nick", nick)
genesis 127 server.client_changed_nickname(self, None)
genesis 128 elif command == "USER":
genesis 129 if len(arguments) < 4:
genesis 130 self.reply_461("USER")
genesis 131 return
genesis 132 self.user = arguments[0]
genesis 133 self.realname = arguments[3]
genesis 134 elif command == "QUIT":
genesis 135 self.disconnect("Client quit")
genesis 136 return
genesis 137 if self.nickname and self.user:
9982-getdata 138 self.reply("001 %s :Hi, welcome to PestNet" % self.nickname)
9982-getdata 139 self.reply("002 %s :Your host is %s, running Blatta %d and Pest 0x%X"
9982-getdata 140 % (self.nickname, server.name, VERSION, PEST_VERSION))
9982-getdata 141 self.reply("003 %s :This server was created %s"
9982-getdata 142 % (self.nickname, datetime.datetime.now()))
genesis 143 self.reply("004 %s :%s blatta-%s o o"
genesis 144 % (self.nickname, server.name, VERSION))
genesis 145 self.send_motd()
genesis 146 self.__handle_command = self.__command_handler
genesis 147
genesis 148 def __command_handler(self, command, arguments):
genesis 149 def away_handler():
genesis 150 pass
genesis 151
genesis 152 def ison_handler():
genesis 153 if len(arguments) < 1:
genesis 154 self.reply_461("ISON")
genesis 155 return
genesis 156 nicks = arguments
genesis 157 online = [n for n in nicks if server.get_client(n)]
genesis 158 self.reply("303 %s :%s" % (self.nickname, " ".join(online)))
genesis 159
genesis 160 def join_handler():
genesis 161 if len(arguments) < 1:
genesis 162 self.reply_461("JOIN")
genesis 163 return
genesis 164 if arguments[0] == "0":
genesis 165 for (channelname, channel) in self.channels.items():
genesis 166 self.message_channel(channel, "PART", channelname, True)
genesis 167 server.remove_member_from_channel(self, channelname)
genesis 168 self.channels = {}
genesis 169 return
genesis 170 channelnames = arguments[0].split(",")
9987-embargoing 171 for channelname in channelnames:
genesis 172 if irc_lower(channelname) in self.channels:
genesis 173 continue
genesis 174 if not valid_channel_re.match(channelname):
genesis 175 self.reply_403(channelname)
genesis 176 continue
genesis 177 channel = server.get_channel(channelname)
genesis 178 channel.add_member(self)
genesis 179 self.channels[irc_lower(channelname)] = channel
genesis 180 self.message_channel(channel, "JOIN", channelname, True)
genesis 181 self.reply("353 %s = %s :%s"
genesis 182 % (self.nickname,
genesis 183 channelname,
9989-show-wot-nicks 184 " ".join(sorted(x
9987-embargoing 185 for x in self.state.get_peer_handles()))))
9985-single-thread 186 self.reply("366 %s %s :End of NAMES list" % (self.nickname, channelname))
genesis 187
genesis 188 def list_handler():
9982-getdata 189 pass
genesis 190
genesis 191 def lusers_handler():
9982-getdata 192 pass
genesis 193
genesis 194 def mode_handler():
9982-getdata 195 pass
genesis 196
genesis 197 def motd_handler():
genesis 198 self.send_motd()
genesis 199
genesis 200 def nick_handler():
genesis 201 if len(arguments) < 1:
genesis 202 self.reply("431 :No nickname given")
genesis 203 return
genesis 204 newnick = arguments[0]
genesis 205 client = server.get_client(newnick)
genesis 206 if newnick == self.nickname:
genesis 207 pass
genesis 208 elif client and client is not self:
genesis 209 self.reply("433 %s %s :Nickname is already in use"
genesis 210 % (self.nickname, newnick))
genesis 211 elif not self.__valid_nickname_regexp.match(newnick):
genesis 212 self.reply("432 %s %s :Erroneous Nickname"
genesis 213 % (self.nickname, newnick))
genesis 214 else:
genesis 215 oldnickname = self.nickname
genesis 216 self.nickname = newnick
genesis 217 server.client_changed_nickname(self, oldnickname)
genesis 218 self.message_related(
genesis 219 ":%s!%s@%s NICK %s"
genesis 220 % (oldnickname, self.user, self.host, self.nickname),
genesis 221 True)
9982-getdata 222 self.state.set_knob('nick', self.nickname)
genesis 223
genesis 224 def notice_and_privmsg_handler():
genesis 225 if len(arguments) == 0:
genesis 226 self.reply("411 %s :No recipient given (%s)"
genesis 227 % (self.nickname, command))
genesis 228 return
genesis 229 if len(arguments) == 1:
genesis 230 self.reply("412 %s :No text to send" % self.nickname)
genesis 231 return
genesis 232 targetname = arguments[0]
genesis 233 message = arguments[1]
genesis 234
9982-getdata 235
9982-getdata 236 if message[0] is "%":
9982-getdata 237 pest_command, pest_arguments = self.__parse_command_arguments(message[1:])
9982-getdata 238 self.__handle_command(pest_command, pest_arguments)
9982-getdata 239 return
9982-getdata 240
genesis 241 if server.has_channel(targetname):
genesis 242 channel = server.get_channel(targetname)
genesis 243 self.message_channel(
genesis 244 channel, command, "%s :%s" % (channel.name, message))
9987-embargoing 245
9982-getdata 246 Broadcast(
9982-getdata 247 {
9982-getdata 248 "speaker": self.nickname,
9982-getdata 249 "body": message,
9982-getdata 250 "long_buffer": self.server.station.long_buffer
9982-getdata 251 },
9982-getdata 252 self.state).send()
genesis 253 else:
9982-getdata 254 Direct({
genesis 255 "speaker": self.nickname,
genesis 256 "handle": targetname,
9987-embargoing 257 "body": message,
9982-getdata 258 "long_buffer": self.server.station.long_buffer
9982-getdata 259 }, self.state).send()
genesis 260
genesis 261 def part_handler():
genesis 262 if len(arguments) < 1:
genesis 263 self.reply_461("PART")
genesis 264 return
genesis 265 if len(arguments) > 1:
genesis 266 partmsg = arguments[1]
genesis 267 else:
genesis 268 partmsg = self.nickname
genesis 269 for channelname in arguments[0].split(","):
genesis 270 if not valid_channel_re.match(channelname):
genesis 271 self.reply_403(channelname)
genesis 272 elif not irc_lower(channelname) in self.channels:
genesis 273 self.reply("442 %s %s :You're not on that channel"
genesis 274 % (self.nickname, channelname))
genesis 275 else:
genesis 276 channel = self.channels[irc_lower(channelname)]
genesis 277 self.message_channel(
genesis 278 channel, "PART", "%s :%s" % (channelname, partmsg),
genesis 279 True)
genesis 280 del self.channels[irc_lower(channelname)]
genesis 281 server.remove_member_from_channel(self, channelname)
genesis 282
genesis 283 def ping_handler():
genesis 284 if len(arguments) < 1:
genesis 285 self.reply("409 %s :No origin specified" % self.nickname)
genesis 286 return
genesis 287 self.reply("PONG %s :%s" % (server.name, arguments[0]))
genesis 288
genesis 289 def pong_handler():
genesis 290 pass
genesis 291
genesis 292 def quit_handler():
genesis 293 if len(arguments) < 1:
genesis 294 quitmsg = self.nickname
genesis 295 else:
genesis 296 quitmsg = arguments[0]
genesis 297 self.disconnect(quitmsg)
genesis 298
genesis 299 def topic_handler():
9982-getdata 300 pass
genesis 301
genesis 302 def wallops_handler():
9982-getdata 303 pass
genesis 304
genesis 305 def who_handler():
9982-getdata 306 pass
genesis 307
genesis 308 def whois_handler():
9982-getdata 309 pass
genesis 310
genesis 311 def wot_handler():
genesis 312 if len(arguments) < 1:
genesis 313
9987-embargoing 314 peers = self.state.get_peers()
9992-handle-edge-... 315 if len(peers) > 0:
9992-handle-edge-... 316 for peer in peers:
9987-embargoing 317 if peer.address and peer.port:
9987-embargoing 318 address = "%s:%s" % (peer.address, peer.port)
9987-embargoing 319 else:
9987-embargoing 320 address = "<address not configured>"
9982-getdata 321 self.pest_reply("%s %s" % (string.join(peer.handles, ","),
9982-getdata 322 address))
9992-handle-edge-... 323 else:
9992-handle-edge-... 324 self.pest_reply("WOT is empty")
genesis 325 elif len(arguments) == 1:
genesis 326
genesis 327
genesis 328 handle = arguments[0]
9987-embargoing 329 peer = self.state.get_peer_by_handle(handle)
9992-handle-edge-... 330 if peer:
9992-handle-edge-... 331 self.pest_reply("keys:")
9992-handle-edge-... 332 for key in peer.keys:
9984-unbork-at-co... 333 self.pest_reply("'%s'" % key)
9992-handle-edge-... 334 else:
9992-handle-edge-... 335 self.pest_reply("unknown peer: %s" % handle)
genesis 336
genesis 337 else:
genesis 338 pass
genesis 339
genesis 340 def peer_handler():
genesis 341 if len(arguments) == 1:
9991-improved-log... 342 try:
9987-embargoing 343 self.state.add_peer(arguments[0])
9991-improved-log... 344 self.pest_reply("added new peer %s" % arguments[0])
9989-show-wot-nicks 345 self.message(":%s JOIN %s" % (arguments[0], self.server.channel_name))
9984-unbork-at-co... 346 except Exception, ex:
9991-improved-log... 347 self.pest_reply("error attempting to add peer %s" % arguments[0])
9984-unbork-at-co... 348 stack = traceback.format_exc()
9984-unbork-at-co... 349 logging.debug(ex)
9984-unbork-at-co... 350 logging.debug(stack)
genesis 351 else:
genesis 352 self.pest_reply("Usage: PEER <HANDLE>")
genesis 353
genesis 354 def unpeer_handler():
genesis 355 if len(arguments) == 1:
genesis 356 try:
9987-embargoing 357 self.state.remove_peer(arguments[0])
genesis 358 self.pest_reply("removed peer %s" % arguments[0])
9989-show-wot-nicks 359 self.message(":%s PART %s" % (arguments[0], self.server.channel_name))
9984-unbork-at-co... 360 except Exception, ex:
9984-unbork-at-co... 361 self.pest_reply("Error attempting to remove peer: %s" % ex)
9984-unbork-at-co... 362 stack = traceback.format_exc()
9984-unbork-at-co... 363 logging.debug(stack)
genesis 364 else:
genesis 365 self.pest_reply("Usage: UNPEER <HANDLE>")
genesis 366
genesis 367 def genkey_handler():
genesis 368 self.pest_reply(base64.b64encode(os.urandom(64)))
genesis 369
genesis 370 def key_handler():
genesis 371 if len(arguments) != 2:
genesis 372 self.pest_reply("Usage: KEY <HANDLE> <KEY>")
genesis 373 else:
genesis 374 handle = arguments[0]
genesis 375 key = arguments[1]
genesis 376 try:
9987-embargoing 377 self.state.add_key(handle, key)
9992-handle-edge-... 378 self.pest_reply("added key: %s" % key)
genesis 379 except:
genesis 380 self.pest_reply("Error attempting to add key")
genesis 381
genesis 382 def unkey_handler():
genesis 383 if len(arguments) != 1:
genesis 384 self.pest_reply("Usage: UNKEY <KEY>")
genesis 385 else:
genesis 386 try:
9987-embargoing 387 self.state.remove_key(arguments[0])
9992-handle-edge-... 388 self.pest_reply("removed key: %s" % arguments[0])
9992-handle-edge-... 389 except Exception, e:
genesis 390 self.pest_reply("Error attempting to remove key")
9987-embargoing 391 logging.debug(e)
genesis 392
genesis 393 def at_handler():
genesis 394 if len(arguments) == 0:
9987-embargoing 395 at = self.state.get_at()
genesis 396 elif len(arguments) == 1:
genesis 397 handle = arguments[0]
9987-embargoing 398 at = self.state.get_at(handle)
genesis 399 elif len(arguments) == 2:
9990-keep-ephemer... 400 try:
9990-keep-ephemer... 401 handle, address = arguments
9990-keep-ephemer... 402 address_ip, port = string.split(address, ":")
9984-unbork-at-co... 403 self.state.update_at(
9984-unbork-at-co... 404 {"handle": handle,
9984-unbork-at-co... 405 "address": address_ip,
9984-unbork-at-co... 406 "port": int(port)},
9984-unbork-at-co... 407 False)
9990-keep-ephemer... 408 self.pest_reply("updated address table: %s %s" % (handle, address))
9990-keep-ephemer... 409 except Exception as ex:
9984-unbork-at-co... 410 self.pest_reply("Error attempting to update address table: %s" % ex)
9990-keep-ephemer... 411 stack = traceback.format_exc()
9986-rebroadcast-... 412 logging.debug(stack)
genesis 413 return
genesis 414 elif len(arguments) > 2:
genesis 415 self.pest_reply("Usage: AT [<HANDLE>] [<ADDRESS>]")
genesis 416 return
9992-handle-edge-... 417 if len(at) > 0:
9992-handle-edge-... 418 for address in at:
9992-handle-edge-... 419 self.pest_reply("%s %s %s" % (address["handle"],
9992-handle-edge-... 420 address["address"],
9991-improved-log... 421 address["active_at"]))
9992-handle-edge-... 422 else:
9992-handle-edge-... 423 self.pest_reply("no results")
genesis 424
9983-knobs 425 def knob_handler():
9983-knobs 426 if len(arguments) == 0:
9983-knobs 427 knobs = self.state.get_knobs()
9983-knobs 428 if len(knobs) > 0:
9983-knobs 429 for key in knobs.keys():
9983-knobs 430 self.pest_reply("%s %s" % (key, knobs[key]))
9983-knobs 431 else:
9983-knobs 432 self.pest_reply("no knobs configured")
9983-knobs 433 elif len(arguments) == 1:
9983-knobs 434 knob_value = self.state.get_knob(arguments[0])
9982-getdata 435 if knob_value:
9983-knobs 436 self.pest_reply("%s %s" % (arguments[0], knob_value))
9983-knobs 437 else:
9983-knobs 438 self.pest_reply("no such knob")
9983-knobs 439 elif len(arguments) == 2:
9983-knobs 440 self.state.set_knob(arguments[0], arguments[1])
9983-knobs 441 self.pest_reply("set %s to %s" % (arguments[0], arguments[1]))
9983-knobs 442 else:
9983-knobs 443 self.pest_reply("Usage: KNOB [<NAME>] [<VALUE>]")
9982-getdata 444
9982-getdata 445 def resolve_handler():
9982-getdata 446 if len(arguments) == 1:
9982-getdata 447 handle = arguments[0]
9982-getdata 448 peer = self.state.get_peer_by_handle(handle)
9982-getdata 449 if peer:
9982-getdata 450 self.state.resolve(handle)
9982-getdata 451 self.pest_reply("resolved %s" % handle)
9982-getdata 452 else:
9982-getdata 453 self.pest_reply("peer with handle %s not found" % handle)
9982-getdata 454 else:
9982-getdata 455 self.pest_reply("Usage: RESOLVE <HANDLE>")
9983-knobs 456
genesis 457 handler_table = {
genesis 458 "AWAY": away_handler,
genesis 459 "AT": at_handler,
genesis 460 "GENKEY": genkey_handler,
genesis 461 "ISON": ison_handler,
genesis 462 "JOIN": join_handler,
genesis 463 "KEY": key_handler,
9982-getdata 464 "KNOB": knob_handler,
genesis 465 "LIST": list_handler,
genesis 466 "LUSERS": lusers_handler,
genesis 467 "MODE": mode_handler,
genesis 468 "MOTD": motd_handler,
genesis 469 "NICK": nick_handler,
genesis 470 "NOTICE": notice_and_privmsg_handler,
genesis 471 "PART": part_handler,
genesis 472 "PEER": peer_handler,
genesis 473 "PING": ping_handler,
genesis 474 "PONG": pong_handler,
genesis 475 "PRIVMSG": notice_and_privmsg_handler,
genesis 476 "QUIT": quit_handler,
9982-getdata 477 "RESOLVE": resolve_handler,
genesis 478 "TOPIC": topic_handler,
genesis 479 "UNKEY": unkey_handler,
genesis 480 "UNPEER": unpeer_handler,
genesis 481 "WALLOPS": wallops_handler,
genesis 482 "WHO": who_handler,
genesis 483 "WHOIS": whois_handler,
9983-knobs 484 "WOT": wot_handler,
genesis 485 }
genesis 486 server = self.server
genesis 487 valid_channel_re = self.__valid_channelname_regexp
genesis 488 try:
genesis 489 handler_table[command]()
genesis 490 except KeyError:
9985-single-thread 491 self.reply("421 %s %s :Unknown command" % (self.nickname, command))
9985-single-thread 492 stack = traceback.format_exc()
9985-single-thread 493 logging.debug(stack)
genesis 494
genesis 495 def socket_readable_notification(self):
genesis 496 try:
genesis 497 data = self.socket.recv(2 ** 10)
9982-getdata 498 if os.environ.get("LOG_CLIENT_MESSAGES"):
9982-getdata 499 logging.debug(
9982-getdata 500 "[%s:%d] -> %r" % (self.host, self.port, data))
genesis 501 quitmsg = "EOT"
genesis 502 except socket.error as x:
genesis 503 data = ""
genesis 504 quitmsg = x
genesis 505 if data:
genesis 506 self.__readbuffer += data
genesis 507 self.__parse_read_buffer()
genesis 508 self.__timestamp = time.time()
genesis 509 self.__sent_ping = False
genesis 510 else:
genesis 511 self.disconnect(quitmsg)
genesis 512
genesis 513 def socket_writable_notification(self):
genesis 514 try:
genesis 515 sent = self.socket.send(self.__writebuffer)
9982-getdata 516 if os.environ.get("LOG_CLIENT_MESSAGES"):
9982-getdata 517 logging.debug(
9982-getdata 518 "[%s:%d] <- %r" % (
9982-getdata 519 self.host, self.port, self.__writebuffer[:sent]))
genesis 520 self.__writebuffer = self.__writebuffer[sent:]
genesis 521 except socket.error as x:
genesis 522 self.disconnect(x)
genesis 523
genesis 524 def disconnect(self, quitmsg):
genesis 525 self.message("ERROR :%s" % quitmsg)
9987-embargoing 526 logging.info(
genesis 527 "Disconnected connection from %s:%s (%s)." % (
genesis 528 self.host, self.port, quitmsg))
genesis 529 self.socket.close()
genesis 530 self.server.remove_client(self, quitmsg)
genesis 531
genesis 532 def message(self, msg):
genesis 533 self.__writebuffer += msg + "\r\n"
genesis 534
genesis 535 def reply(self, msg):
genesis 536 self.message(":%s %s" % (self.server.name, msg))
genesis 537
genesis 538 def pest_reply(self, msg):
9981-replay-notice 539 self.message(":Pest NOTICE %s :%s" % (self.server.channel_name, msg))
genesis 540
genesis 541 def reply_403(self, channel):
genesis 542 self.reply("403 %s %s :No such channel" % (self.nickname, channel))
genesis 543
genesis 544 def reply_461(self, command):
genesis 545 nickname = self.nickname or "*"
genesis 546 self.reply("461 %s %s :Not enough parameters" % (nickname, command))
genesis 547
genesis 548 def message_channel(self, channel, command, message, include_self=False):
genesis 549 line = ":%s %s %s" % (self.prefix, command, message)
9987-embargoing 550 if include_self:
9987-embargoing 551 self.message(line)
genesis 552
genesis 553 def message_related(self, msg, include_self=False):
genesis 554 clients = set()
genesis 555 if include_self:
genesis 556 clients.add(self)
genesis 557 for channel in self.channels.values():
genesis 558 clients |= channel.members
genesis 559 if not include_self:
genesis 560 clients.discard(self)
genesis 561 for client in clients:
genesis 562 client.message(msg)
genesis 563
genesis 564 def send_motd(self):
genesis 565 server = self.server
genesis 566 motdlines = server.get_motd_lines()
genesis 567 if motdlines:
genesis 568 self.reply("375 %s :- %s Message of the day -"
genesis 569 % (self.nickname, server.name))
genesis 570 for line in motdlines:
genesis 571 self.reply("372 %s :- %s" % (self.nickname, line.rstrip()))
genesis 572 self.reply("376 %s :End of /MOTD command" % self.nickname)
genesis 573 else:
genesis 574 self.reply("422 %s :MOTD File is missing" % self.nickname)