示例#1
0
 def onMessage(self, conn, msg):
     person = self.registry[msg.getFrom().getResource()]
     if not self.findPerson(person):
         return
     print u"message from %s: %s" % (person, msg.getBody())
     if not self.defeated_commands and self.question and utils.sEq(msg.getBody(), self.question.answer):            
         if person in self.offenders:
             damage = logic.getDamage(person, self.target)
             self.health -= damage
             if not self.defeated():
                 utils.answerConf(conn, msg, u"System damaged: %d, left: %d" % (damage, self.health))
         else:
             return
         self.question = None
         self.next_question = time.time() + random.randint(1, config.nextQuestionMaxTimeout)
     else:
         if not msg.getBody(): return
         parts = [utils.normalize(x) for x in msg.getBody().strip().split(" ")]
         if parts:
             if self.defeated_commands and parts[0] in logic.availableRewards():
                 if parts[0] in self.defeated_commands:
                     print u"reward command: %s" % (parts[0])
                     if not self.reward_person:
                         self.rewardCommand(conn, person, parts[0], parts[1:])
                 else:
                     utils.answerConf(conn, msg, u"Command %s is unsupported by target. Time left: %d" % (parts[0], int(self.defeated_timeout - time.time())))
             else:
                 {"stat": self.printStats, "attack": self.scheduleAttack, "defend": self.doDefend}.get(parts[0], lambda x, y, z: None)(conn, person, parts[1:])
示例#2
0
def processCommand(conn, msg, msgText):
    parts = [normalize(x) for x in msgText.strip().split(" ")]
    if len(parts) != 3:
        return
    cmd, target, action = parts
    is_defend = sEq(action, u"защита")
    is_offend = sEq(action, u"атака")
    if sEq(cmd, "connect") and (is_offend or is_defend):
        person = registry[msg.getFrom().getResource()]
        if isValidTarget(person, target) and cooldown.canEnter(person):
            if is_offend and not cooldown.canAttack(person):
                answerPrivate(conn, msg, u"Передохни, выпей пивка")
                return
            conf = getConfByTarget(target)
            joinConference(conn, config.conference, conf.name, config.nickname)
            sendInvite(conn, person, conf.name)
            if is_offend:
                conf.newOffender(person)
                cooldown.startedAttack(person)
            else:
                conf.newDefender(person)
        else:
            answerPrivate(conn, msg, u"Тебе туда нельзя")
示例#3
0
    def onMessage(self, conn, msg):
        person = self.registry[msg.getFrom().getResource()]
        if not self.findPerson(person):
            return
        if self.question and utils.sEq(msg.getBody(), self.question.answer):            
            if person in self.offenders:
                damage = logic.getDamage(person, self.target)
                self.health -= damage
                if not self.defeated():
                    utils.answerConf(conn, msg, u"Нанесено урона: %d, осталось: %d" % (damage, self.health))
            elif person in self.defenders:
                for p in self.offenders.itervalues():
                    p.damage(conn, self.findPerson(person), logic.getDefenderDamage(person, self.target), self.name)
            else:
                return
            
            self.kickDeads(conn)

            self.question = None
            self.next_question = time.time() + 1
        else:
            parts = [utils.normalize(x) for x in msg.getBody().strip().split(" ")]
            if parts:
                {"stat": self.printStats, "attack": self.scheduleAttack, "defend": self.doDefend}.get(parts[0], lambda x, y, z: None)(conn, person, parts[1:])
示例#4
0
def getConfByName(name):
    ret = [c for (t, c) in getConfs().iteritems() if utils.sEq(c.name, name)]
    if ret:
        return ret[0]
    return None
示例#5
0
def getConfByName(name):
    ret = [c for (t, c) in getConfs().iteritems() if utils.sEq(c.name, name)]
    if ret:
        return ret[0]
    return None
示例#6
0
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)
示例#7
0
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)