Пример #1
0
    def login(self, username, password, serverNumber=0):
        """
        Perform a KoL login given a username and password. A server number may also be specified
        to ensure that the user logs in using that particular server. This can be helpful
        if the user continues to be redirected to a server that is down.
        """

        self.userName = username
        self.userPasswordHash = hashlib.md5(password).hexdigest()

        # Grab the KoL homepage.
        homepageRequest = HomepageRequest(self, serverNumber=serverNumber)
        homepageResponse = homepageRequest.doRequest()
        self.serverURL = homepageResponse["serverURL"]

        # Perform the login.
        loginRequest = LoginRequest(self, homepageResponse["loginChallenge"])
        loginRequest.doRequest()

        # Load the charpane once to make StatusRequest report the rollover time
        charpaneRequest = CharpaneRequest(self)
        charpaneRequest.doRequest()

        # Get pwd, user ID, and the user's name.
        request = StatusRequest(self)
        response = request.doRequest()
        self.pwd = response["pwd"]
        self.userName = response["name"]
        self.userId = int(response["playerid"])
        self.rollover = int(response["rollover"])
Пример #2
0
    def _heartbeat(self):
        # actual breakfast is done inside the heartbeat thread to make it
        # asynchronous.
        if self._breakfasted or not self._initialized:
            return
        self._breakfasted = True
        r = RumpusRoomRequest(self.session)
        d1 = self.tryRequest(r)
        d = d1.get('furniture', [])
        sourceList = []

        self.log("Performing breakfast...")
        if 'A Mr. Klaw "Skill" Crane Game' in d:
            success = self._doRequest(MrKlawRequest)
            success |= self._doRequest(MrKlawRequest)
            success |= self._doRequest(MrKlawRequest)
            if success:
                sourceList.append("Mr. Klaw")
        if "An Exotic Hanging Meat Orchid" in d:
            success = self._doRequest(MeatOrchidRequest)
            if success:
                sourceList.append("Meat Orchid")
        if "A Potted Meat Bush" in d:
            success = self._doRequest(MeatBushRequest)
            if success:
                sourceList.append("Meat Bush")
        if "A Potted Meat Tree" in d:
            success = self._doRequest(MeatTreeRequest)
            if success:
                sourceList.append("Meat Tree")
        if self._vip:
            success = self._doRequest(CrimboTreeRequest)
            if success:
                sourceList.append("Crimbo Tree")
            success = self._doRequest(LookingGlassRequest)
            if success:
                sourceList.append("Looking Glass")
            success = self._doRequest(DeluxeMrKlawRequest)
            success |= self._doRequest(DeluxeMrKlawRequest)
            success |= self._doRequest(DeluxeMrKlawRequest)
            if success:
                sourceList.append("Deluxe Mr. Klaw")

        r = CharpaneRequest(self.session)
        d = self.tryRequest(r, nothrow=True)
        if d is not None and d['meat'] > 2000:
            success = self._getClover()
            while success:
                success = self._getClover()

        if self._meat > 0 or len(self._items) > 0:
            itemTxt = '\n'.join("{}x {}".format(qty, name)
                                for name, qty in self._items.items()
                                if qty != 0)
            self.log("Breakfast results:\nGot {} meat and the following "
                     "items:\n{}".format(self._meat, itemTxt))
        else:
            self.log("Got nothing.")
Пример #3
0
def mainloop():
    global s
    global chatMgr
    while True:
        event = droid.eventWait().result
        if event["name"] == "key" and event["data"]["key"] == "4":
            return

        id = event["name"]
        if id == "makeToast":
            droid.makeToast(event["data"])
        elif id == "charData":
            droid.dialogCreateSpinnerProgress("Loading", "Loading...")
            droid.dialogShow()
            c = CharpaneRequest(s)
            response = None
            try:
                response = c.doRequest()
            except Error as e:
                alertNotLoggedIn(True)
            message = ""
            title = "Character Data"
            for key in response.keys():
                if key != "effects":
                    message += "%s: %s\n" % (key, response[key])
                else:
                    message += "-------\nEFFECTS:\n"
                    for effect in response["effects"]:
                        message += " - " + effect["name"] + ": " + str(
                            effect["turns"]) + "\n"
            droid.dialogDismiss()
            droid.dialogCreateAlert(title, message)
            droid.dialogSetPositiveButtonText("OK")
            droid.dialogShow()
            # objectPost("charDataInfo", response)
        elif id == "inventory":
            droid.dialogCreateSpinnerProgress("Loading", "Loading...")
            droid.dialogShow()
            i = InventoryRequest(s)
            response = None
            try:
                response = i.doRequest()
            except Error as e:
                alertNotLoggedIn(True)
            title = "Inventory"
            message = ""
            for key in response["items"]:
                message += "%s: %s\n" % (key["name"], key["quantity"])
            droid.dialogDismiss()
            droid.dialogCreateAlert(title, message)
            droid.dialogSetPositiveButtonText("OK")
            droid.dialogShow()
            # objectPost("inventoryInfo", response)
        elif id == "findInventory":
            droid.dialogCreateInput(
                "Item to find:",
                "Enter the name (or partial name) of the item to find")
            droid.dialogSetPositiveButtonText("OK")
            droid.dialogSetNegativeButtonText("Cancel")
            droid.dialogShow()
            response = droid.dialogGetResponse().result
            if response.has_key("which") and response[
                    "which"] == "positive" and response.has_key(
                        "value") and response["value"] != "":
                droid.dialogCreateSpinnerProgress("Searching...",
                                                  "Finding items...")
                droid.dialogShow()
                i = InventoryRequest(s)
                inventory = None
                try:
                    inventory = i.doRequest()
                except Error as e:
                    alertNotLoggedIn(True)
                title = "Search results"
                message = ""
                for item in inventory["items"]:
                    if item.has_key("name") and response["value"].lower(
                    ) in item["name"].lower():
                        message += "%s: %s\n" % (item["name"],
                                                 item["quantity"])
                if message == "":
                    message = "No item matching %s was found" % response[
                        "value"]
                droid.dialogDismiss()
                droid.dialogCreateAlert(title, message)
                droid.dialogSetPositiveButtonText("OK")
                droid.dialogShow()
        elif id == "getNewChat":
            try:
                objectPost("getNewChatResult", chatMgr.getNewChatMessages())
            except Error as e:
                alertNotLoggedIn(True)
        elif id == "sendChat":
            try:
                data = json.loads(event["data"])
                chatMgr.sendChatMessage("/" + data["channel"] + " " +
                                        data["message"])
                droid.eventPost("sendChatResult", "success")
            except Error as e:
                droid.eventPost("sendChatResult", "fail")
        elif id == "getChannels":
            try:
                pass
            except Error as e:
                alertNotLoggedIn(True)
        elif id == "searchMall":
            try:
                m = MallItemSearchRequest(s, event["data"], numResults=10)
                droid.dialogCreateSpinnerProgress(
                    "Searching...", "Searching for \"%s\"" % event["data"])
                droid.dialogShow()
                objectPost("searchMallResult", m.doRequest())
                droid.dialogDismiss()
            except Error as e:
                alertNotLoggedIn(True)
        elif id == "buyMall":
            droid.dialogCreateInput("Purchase mall item",
                                    "Enter quantity to purchase", "0",
                                    "number")
            droid.dialogSetPositiveButtonText("OK")
            droid.dialogSetNegativeButtonText("Cancel")
            droid.dialogShow()
            resp = droid.dialogGetResponse().result
            evtdata = None
            try:
                evtdata = json.loads(event["data"])
                droid.log("evtdata loaded from string")
                droid.log("evtdata = %s" % event["data"])
                buy = MallItemPurchaseRequest(s, evtdata["storeId"],
                                              evtdata["id"], evtdata["price"],
                                              resp["value"])
                droid.log("MIPR created")
                droid.dialogCreateSpinnerProgress("Buying...",
                                                  "Buying item(s)...")
                droid.dialogShow()
                buyResponse = buy.doRequest()
                droid.dialogDismiss()
                droid.dialogCreateAlert(
                    "Results", "Brought %s for %d" %
                    (resp["value"], buyResponse["meatSpent"]))
                droid.dialogSetPositiveButtonText("OK")
                droid.dialogShow()
            except Error as e:
                droid.dialogCreateAlert("Results", e.msg)
                droid.dialogSetPositiveButtonText("OK")
                droid.dialogShow()
            except:
                droid.dialogCreateAlert("WTF", "WTF?")
                droid.dialogSetPositiveButtonText("OK")
                droid.dialogShow()
        elif id == "exit":
            s.logout()
            sys.exit()
            return