def scheduleShutdown(sendRestartTime, restart, message="", delay=20): """ Schedule a server shutdown/restart :param sendRestartTime: time (seconds) to wait before sending server restart packets to every client :param restart: if True, server will restart. if False, server will shudown :param message: if set, send that message to every client to warn about the shutdown/restart :param delay: additional restart delay in seconds. Default: 20 :return: """ # Console output log.info("Pep.py will {} in {} seconds!".format( "restart" if restart else "shutdown", sendRestartTime + delay)) log.info("Sending server restart packets in {} seconds...".format( sendRestartTime)) # Send notification if set if message != "": glob.streams.broadcast("main", serverPackets.notification(message)) # Schedule server restart packet threading.Timer( sendRestartTime, glob.streams.broadcast, ["main", serverPackets.banchoRestart(delay * 2 * 1000)]).start() glob.restarting = True # Restart/shutdown if restart: action = restartServer else: action = shutdownServer # Schedule actual server shutdown/restart some seconds after server restart packet, so everyone gets it threading.Timer(sendRestartTime + delay, action).start()
def spamProtection(self, increaseSpamRate=True): """ Silences the user if is spamming. :param increaseSpamRate: set to True if the user has sent a new message. Default: True :return: """ # Increase the spam rate if needed if increaseSpamRate: self.spamRate += 1 # Silence the user if needed if self.spamRate > 10: self.enqueue(serverPackets.banchoRestart(1))