def updateCooldowns(): now = time.time() remove = [] for who in gCooldowns: if confs.getConfsCount(who) > 0: continue delta = int(now - gCooldowns[who][1]) if delta > config.cooldownRestore: newhits = gCooldowns[who][0] + 1 if newhits > logic.getVitality(who): logging.info("cooldown: user %s restored" , who) remove.append(who) else: #print "cooldown: user %s incremented (%d)" % (who, newhits) gCooldowns[who] = (newhits, now) for r in remove: del gCooldowns[r] remove = [] for t in gTargets: if time.time() > gTargets[t]: remove.append(t) for r in remove: del gTargets[r]
def processCommand(conn, msg, msgText): if not msgText: return parts = [normalize(x) for x in msgText.strip().split(" ")] name = msg.getFrom().getResource() if not name: return if name not in registry: return logging.info("Command from %s: %s",name,msgText) person = registry[name] jid = person.getStripped() hackername = utils.jidStrip(jid) if len(parts) == 3: cmd, target, action = parts is_defend = sEq(action, u"defend") is_offend = sEq(action, u"attack") if sEq(cmd, "connect") and (is_offend or is_defend): hour = time.localtime().tm_hour if hour >= config.nightSleepHour and hour < config.morningStartHour: answerPrivate(conn, msg, u"Cool down, guy! Time to sleep for a while... Back to work at 9 a.m.") return if isValidTarget(name, target) and getConfsCount(person) < allowedChannelsCount(jid): if not cooldown.canEnter(person): answerPrivate(conn, msg, u"Cool down, guy! Take a beer...") logging.info( u"Cool down, guy! Take a beer... %s", hackername) return if is_offend and (not cooldown.canAttack(target)): answerPrivate(conn, msg, u"Target was broken recently. It's impossible to hack it for now.") logging.info(u"Target was broken recently. It's impossible to hack it for now. %s", hackername) return conf = getConfByTarget(target) if not conf.defeated(): joinConference(conn, config.conference, conf.name, config.nickname) sendInvite(conn, person, conf.name) if is_offend: conf.newOffender(person) # cooldown.startedAttack(person) subs = subscribe.subscribersFor(target) for p in subs: if registry.containsHacker(p) and p != hackername: # print "SUBS %s"%p sendSubscription(conn, registry.getHacker(p), target) else: conf.newDefender(person) logging.info(u"CONF STARTED: %s" ,conf) else: answerPrivate(conn, msg, u"Access denied.") elif len(parts) == 2: cmd, target = parts if sEq(cmd, "subscribe"): if subscribe.canSubscribe(hackername, target): subscribe.add(hackername, target) answerPrivate(conn, msg, u"Target %s subscribed." % (target)) else: answerPrivate(conn, msg, u"Too many subscriptions.") elif sEq(cmd, "unsubscribe"): if subscribe.remove(hackername, target): answerPrivate(conn, msg, u"Target %s unsubscribed." % (target)) else: answerPrivate(conn, msg, u"Target %s isn't subscribed." % (target)) elif len(parts) == 1: cmd = parts[0] if sEq(cmd, "subscriptions"): txt = u"List of subscriptions:\n" for s in subscribe.subscriptionsOf(hackername): txt += u"%s\n" % (s) answerPrivate(conn, msg, txt) elif sEq(cmd, "status"): txt = u"Current personal status: %d" % cooldown.getVitality(hackername) answerPrivate(conn, msg, txt)
def processCommand(conn, msg, msgText): if not msgText: return parts = [normalize(x) for x in msgText.strip().split(" ")] name = msg.getFrom().getResource() if not name: return if name not in registry: return logging.info("Command from %s: %s", name, msgText) person = registry[name] jid = person.getStripped() hackername = utils.jidStrip(jid) if len(parts) == 3: cmd, target, action = parts is_defend = sEq(action, u"defend") is_offend = sEq(action, u"attack") if sEq(cmd, "connect") and (is_offend or is_defend): hour = time.localtime().tm_hour if hour >= config.nightSleepHour and hour < config.morningStartHour: answerPrivate( conn, msg, u"Cool down, guy! Time to sleep for a while... Back to work at 9 a.m." ) return if isValidTarget(name, target) and getConfsCount( person) < allowedChannelsCount(jid): if not cooldown.canEnter(person): answerPrivate(conn, msg, u"Cool down, guy! Take a beer...") logging.info(u"Cool down, guy! Take a beer... %s", hackername) return if is_offend and (not cooldown.canAttack(target)): answerPrivate( conn, msg, u"Target was broken recently. It's impossible to hack it for now." ) logging.info( u"Target was broken recently. It's impossible to hack it for now. %s", hackername) return conf = getConfByTarget(target) if not conf.defeated(): joinConference(conn, config.conference, conf.name, config.nickname) sendInvite(conn, person, conf.name) if is_offend: conf.newOffender(person) # cooldown.startedAttack(person) subs = subscribe.subscribersFor(target) for p in subs: if registry.containsHacker(p) and p != hackername: # print "SUBS %s"%p sendSubscription(conn, registry.getHacker(p), target) else: conf.newDefender(person) logging.info(u"CONF STARTED: %s", conf) else: answerPrivate(conn, msg, u"Access denied.") elif len(parts) == 2: cmd, target = parts if sEq(cmd, "subscribe"): if subscribe.canSubscribe(hackername, target): subscribe.add(hackername, target) answerPrivate(conn, msg, u"Target %s subscribed." % (target)) else: answerPrivate(conn, msg, u"Too many subscriptions.") elif sEq(cmd, "unsubscribe"): if subscribe.remove(hackername, target): answerPrivate(conn, msg, u"Target %s unsubscribed." % (target)) else: answerPrivate(conn, msg, u"Target %s isn't subscribed." % (target)) elif len(parts) == 1: cmd = parts[0] if sEq(cmd, "subscriptions"): txt = u"List of subscriptions:\n" for s in subscribe.subscriptionsOf(hackername): txt += u"%s\n" % (s) answerPrivate(conn, msg, txt) elif sEq(cmd, "status"): txt = u"Current personal status: %d" % cooldown.getVitality( hackername) answerPrivate(conn, msg, txt)