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