Exemple #1
0
def loadMods():
    global BOT, A
    for i in config_plugins:
        log.info("Loading plugin %s..." % i)
        __import__("mods." + i)
        i = sys.modules["mods." + i]
        try:
            fire("module_init", i.init, ())
            log.info("Loaded mod %s" % i)
        except Exception, e:
            A.warning("Error loading mod %s [%s]" % (i, e))
Exemple #2
0
def parse(inp):
    global BOT
    if inp.startswith("say:"):
        # say: 0 [WoC]*B1naryth1ef: blah blah
        inp = inp.split(" ", 3)
        inp.pop(0)
        inp[1] = inp[1].strip(":")
        if inp[2].startswith("!"):
            inp[2] = inp[2].lower()
            BOT.eventFire(
                "CLIENT_COMMAND", {"event": "CHAT_MESSAGE", "name": inp[1].lower(), "sender": inp[0], "msg": inp[2]}
            )  # @FIX ffs dont fire chat_message fire command!
            cmd = inp[2].rstrip().split(" ")[0]
            if cmd in BOT.Commands.keys():
                parseCommand(inp, cmd)
            if cmd in BOT.Aliases.keys():
                parseCommand(BOT.Aliases[inp][3])
        BOT.eventFire("CHAT_MESSAGE", {"event": "CHAT_MESSAGE", "sender": inp[1], "gid": inp[0], "msg": inp[2]})

    elif inp.startswith("ClientConnect:"):
        # ClientConnect: 0
        inp = int(inp.split(" ")[1])
        if inp in BOT.Clients.keys():
            #'til we find ways to work around the missing ClientDisconnect messages... this won't be fatal.
            # raise const.UrTBotError('Client #%s is already connected... Something is wrong.' % (inp))
            if BOT.loadingMap is False and BOT.justChangedMap is False:
                print const.UrTBotError(
                    "Client #%s is already connected... Something is wrong. Flush 'em, danno!" % (inp)
                )
                del BOT.Clients[inp]
            else:
                BOT.justChangedMap = False
        if inp >= 0:
            BOT.eventFire("CLIENT_CONNECT", {"client": inp})

    elif inp.startswith("ClientUserinfo:"):
        uid, varz = parseUserInfo(inp)
        if uid in BOT.Clients.keys():
            fire("update_clientinfo", BOT.Clients[uid].updateData, (varz,))
        else:
            BOT.Clients[uid] = player.Player(uid, varz, A)
            if BOT.Clients[uid].cl_guid != None:
                # BOT.pdb.playerUpdate(BOT.Clients[uid], True) WTF DOES THIS DO?
                # db.tableSelect('penalties', 'userid')
                log.info(
                    "User %s connected with Game ID %s and Database ID %s"
                    % (BOT.Clients[uid].name, BOT.Clients[uid].uid, BOT.Clients[uid].cid)
                )
                # en2 = db.rowFindAll(BOT.Clients[uid].cid)
                # if en2 != None:
                #     for en in en2:
                #         if en != None:
                #             if en['type'] == 'ban' and en['status'] == 1:
                #                 print 'Disconnecting user because he/she has been banned'
                #                 return BOT.Q.rcon('kick %s' % uid)
                #             elif en['type'] == 'tempban' and en['status'] == 1:
                #                 #print float(time.time())-float(en['expiration'])
                #                 if float(time.time())-float(en['expiration']) < 0:
                #                     print 'Disconnecting user because he/she has been tempbanned'
                #                     return BOT.Q.rcon('kick %s' % uid)
                #                 else:
                #                     print 'Setting tempban unactive'
                #                     db2 = database.DB()
                #                     db2.tableSelect('penalties')
                #                     enx = db2.rowFind(en['id'])
                #                     enx['status'] = 0
                #                     db2.rowUpdate(enx)
                #                     db2.commit()
            BOT.eventFire("CLIENT_CONNECTED", {"client": uid})

    elif inp.startswith("ClientUserinfoChanged:"):
        # Different than ClientUserinfo because we don't add clients to the list or DB, just update
        uid, varz = parseUserInfoChange(inp, {}, {})
        if uid in BOT.Clients.keys():
            fire("update_clientinfo", BOT.Clients[uid].updateData, (varz,))
    elif inp.startswith("ClientDisconnect:"):
        inp = int(inp.split(" ")[1])
        BOT.eventFire("CLIENT_DISCONNECT", {"client": inp})
        if inp in BOT.Clients.keys():
            del BOT.Clients[inp]
    elif inp.startswith("Kill:"):
        parseKill(inp)
    elif inp.startswith("Hit:"):
        parseHit(inp)
    elif inp.startswith("Item"):
        parseItem(inp)
    elif inp.startswith("Flag:"):
        parseFlag(inp)
    elif inp.startswith("Flag Return:"):
        parseFlagReturn(inp)
    elif inp.startswith("ClientBegin:"):
        parsePlayerBegin(inp)
    elif inp.startswith("ShutdownGame:"):
        BOT.eventFire("GAME_SHUTDOWN", {})
        BOT.matchEnd()
        # We clear out our client list on shutdown. Doesn't happen with 'rcon map ..' but does
        # when the mapcycle changes maps? hrmph. investigate.
        # In fact I'm not sure how to detect an 'rcon map' yet! Geeeeeez.
        # rcon from 127.0.0.1:
        # map
        # That should work ye?
        # for key in BOT.Clients.keys():
        #     BOT.eventFire('CLIENT_DISCONNECT', {'client':key})
        #     del BOT.Clients[key]
        # ^^^ Dont run that because then a map change is treated as new clients connecting. Not sure how to fix that stuffz
    elif inp.startswith("InitGame:"):
        fire("parse_initgame", BOT.gameData.update, (parseInitGame(inp),))
        BOT.matchNew()
    elif inp.startswith("InitRound:"):
        BOT.roundNew()
    elif inp.startswith("SurvivorWinner:"):
        BOT.roundEnd()
        if int(BOT.gameData["g_gametype"]) in [4, 8]:
            BOT.eventFire("GAME_ROUND_END", {})  # <<< Will this work?
        else:
            log.warning("Wait... Got SurvivorWinner but we're not playing Team Surivivor or bomb?")
    elif inp.startswith("InitRound:"):
        pass
    elif inp.startswith("clientkick") or inp.startswith("kick"):  # @DEV This needs to be fixed in beta
        log.debug("Seems like a user was kicked... Threading out parseUserKicked()")
        fire(
            "parse_userkicked", parseUserKicked, (inp,)
        )  # Threaded because we have to delay sending out CLIENT_KICKED events slightly
    elif inp.startswith("Exit: Timelimit hit."):
        parseTimeLimitHit(inp)