def __init__(self, gen_dict, headers_info, request): self.logger = Logger("Data") self.data = { "player": {}, "alliance": {}, "habitat": {}, "habitat_unit": [], "report": {}, "transit": [], "diplomacy": { "red": [], "green": [], "blue": [], "orange": [] } } self.own_ids = {'player': headers_info["playerID"], 'alliance': None} self._calc_server_id(gen_dict) self.parse_dict(gen_dict) self._find_own() self.request = request
from Request import Request from Module.Logger import Logger logger = Logger("-") request = Request("*****@*****.**", "1") data = request.enter()[1] print("im in") res = request.load_worlds()[1]["allAvailableWorlds"] for server in res: if server["language"] in ["de"]: logger.log(server["url"]) exit() alliancesFromRating = request.load_alliance_rating()[1]["allianceRanks"] ids = [allianceFromRating["id"] for allianceFromRating in alliancesFromRating] alliances = data.get_instances_by_ids("alliance", ids) logger.log(alliances) players = data.get_players_by_alliances(alliances) subject = "!!!" content = """Ihr Russen spielt euch immer auf und denkt ihr hättet einen Wert in Lords and Knights und in der echten Welt Kommt auf G4 und holt euch die Niederlage ab die ihr auch im Weltkrieg kassiert hättet wenn eure großen Brüder USA Großbritannien und Frankreich euch nicht gerettet hätten. Alleine seid ihr Russen nichts, Insekten unter meinen deutschen Füßen.""" counter = 0 for player in players: counter += 1 response = request.create_message(subject, player.id, content) if response[0]: logger.log("{}/{} - Sent to {}".format(counter, len(players), player)) else: logger.log("{}/{} - Didnt succeed sending message to {}".format(counter, len(players), player))
from Request import Request from Module.Logger import Logger import gspread import time from oauth2client.service_account import ServiceAccountCredentials logger = Logger("-") request = Request("*****@*****.**", "*****@*****.**") data = request.enter()[1] logger.log("logged in") def work_on_account(link): player = data.get_instance_by_link(link) habitats = [ habitat for habitat in data.data["habitat"].values() if habitat.player_id == player.id ] castles, fortresses, cities = (len([ habitat for habitat in habitats if habitat.type == "CAST" ]), len([ habitat for habitat in habitats if habitat.type == "FORT" ]), len([habitat for habitat in habitats if habitat.type == "CITY"])) if player.alliance_id is None: alliance = "-" else: alliance = [ alliance for alliance in data.data["alliance"].values() if alliance.id == player.alliance_id ][0].name
from Request import Request from Module.Logger import Logger from Module import Telegram import time EMAIL = "*****@*****.**" PASSWORD = "******" COUNTER_HOURS = 6 MINUTES_BETWEEN_CHECK = 3 REPORTS_IN_MESSAGE = 5 DISCUSSSION_ID = "11453" SOURCE_HABITAT_LINK = "l+k://coordinates?16546,16440&230" TRIPWIRE_SIZE = 5 logger = Logger("TripwireNew") request = Request(EMAIL, PASSWORD) data = request.enter()[1] telegram = Telegram.Telegram() ALLIANCES_LINKS = ["l+k://alliance?408&230"] ADDITIONAL_PLAYER_LINKS = [] # Inactive EXCLUDED_PLAYERS_LINKS = [] # Inactive def clean_changes_dict(changes_dict): temp_dict = {} for hab_id in changes_dict: amount = changes_dict[hab_id] if amount == 0: continue temp_dict[hab_id] = amount return temp_dict
class Data: world_id = None def __init__(self, gen_dict, headers_info, request): self.logger = Logger("Data") self.data = { "player": {}, "alliance": {}, "habitat": {}, "habitat_unit": [], "report": {}, "transit": [], "diplomacy": { "red": [], "green": [], "blue": [], "orange": [] } } self.own_ids = {'player': headers_info["playerID"], 'alliance': None} self._calc_server_id(gen_dict) self.parse_dict(gen_dict) self._find_own() self.request = request def parse_dict(self, dict_to_parse): # Player from Rating try: for item in dict_to_parse["playerRanks"]: new_object = Player(item, world_id=self.world_id) self.data["player"][new_object.id] = new_object except KeyError: pass # Player try: for item in dict_to_parse["Data"]["Player"]: new_object = Player(item, world_id=self.world_id) self.data["player"][new_object.id] = new_object except KeyError: pass # Alliance try: for item in dict_to_parse["Data"]["Alliance"]: new_object = Alliance(item, world_id=self.world_id) self.data["alliance"][new_object.id] = new_object except KeyError: pass # Habitat try: for item in dict_to_parse["Data"]["Habitat"]: new_object = Habitat(item, world_id=self.world_id) self.data["habitat"][new_object.id] = new_object except KeyError: pass # Diplomacy try: for diplomacy_item in dict_to_parse["Data"]["Diplomacy"]: _, target_alliance_id = diplomacy_item['id'].split('-') relationship_kind = RELATIONSHIP_NUM_TO_WORD[ diplomacy_item["relationship"]] self.data["diplomacy"][relationship_kind].append( target_alliance_id) except KeyError: pass # HabitatUnit try: if "HabitatUnit" in dict_to_parse["Data"]: self.data["habitat_unit"] = [] for item in dict_to_parse["Data"]["HabitatUnit"]: new_object = HabitatUnit(item) self.data["habitat_unit"].append(new_object) except KeyError: pass # Transit try: if "Transit" in dict_to_parse["Data"]: self.data["transit"] = [] for item in dict_to_parse["Data"]["Transit"]: new_object = Transit(item) self.data["transit"].append(new_object) except KeyError: pass def load_and_parse_reports(self): request_result = self.request.fetch_reports() try: for item in request_result[1]["Data"]["Report"]: new_object = Report(item, world_id=self.world_id) self.data["report"][new_object.id] = new_object except KeyError: return True, [] def _find_own(self): own_player_instance = self.get_instances_by_ids( "player", [self.own_ids["player"]])[0] own_alliance_id = own_player_instance.alliance_id if own_alliance_id: self.own_ids['alliance'] = self.get_instances_by_ids( "alliance", [own_alliance_id])[0] def _calc_server_id(self, gen_dict): string = gen_dict["serverVersion"] _, _, server_ids = string.split("_") world_id, _, _ = server_ids.split("-") self.world_id = world_id def get_instances_by_ids(self, instance_type, ids, force_request=False): def get_instance_by_id(): if not force_request: try: return self.data[instance_type][item_id] except ValueError: pass except KeyError: pass type_to_request = { "alliance": self.request.alliance_info, "player": self.request.player_info, "habitat": self.request.habitat_info, } type_to_request[instance_type](item_id) return self.data[instance_type][item_id] items = [] index = 0 for item_id in ids: index += 1 self.logger.log("Getting instance {} out of {}".format( index, len(ids))) items.append(get_instance_by_id()) return items def get_players_by_alliances(self, alliances, force_request=True): alliance_ids = [alliance.id for alliance in alliances] # only to make sure all players of these alliances are in data self.get_instances_by_ids("alliance", alliance_ids, force_request=force_request) players_list = [] for player_id in self.data["player"]: player = self.data["player"][player_id] if player.alliance_id in alliance_ids: players_list.append(player) return players_list def get_habitats_by_players(self, players, force_request=True): # only to make sure all habitats of these players are in data player_ids = [player.id for player in players] if force_request: self.get_instances_by_ids("player", player_ids, force_request=force_request) habitats_list = [] for habitat_id in self.data["habitat"]: habitat = self.data["habitat"][habitat_id] try: if habitat.player_id in player_ids: habitats_list.append(habitat) except AttributeError: pass return habitats_list def get_habitat_by_coordinates(self, x, y): for habitat_id in self.data["habitat"]: habitat = self.data["habitat"][habitat_id] if habitat.compare_coordinates((x, y)): return habitat self.request.map(x, y, width="15", height="15") return self.get_habitat_by_coordinates(x, y) def get_instance_by_link(self, link): if 'alliance' in link: item_id = link.split("l+k://alliance?")[1].split("&")[0] return self.get_instances_by_ids("alliance", [item_id])[0] if 'player' in link: item_id = link.split("l+k://player?")[1].split("&")[0] return self.get_instances_by_ids("player", [item_id])[0] if 'coordinates' in link: x, y = link.split("l+k://coordinates?")[1].split("&")[0].split(",") return self.get_habitat_by_coordinates(x, y) def get_instances_by_links(self, links): instances = [] for link in links: instances.append(self.get_instance_by_link(link)) return instances
from Request import Request from Module.Logger import Logger import time mails = [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", ] names = ["Nichobow", "Nichoth", "Antinicholas", "Lobstroscholas", "Scolka"] for number in range(len(mails)): logger = Logger("mail placeholder") request = Request(mails[number], "3259") data = request.enter()[1] # alliance = data.get_instance_by_link("l+k://alliance?408&230") # res1 = request.apply_to_alliance(alliance.id) res2 = request.change_nickname(names[number]) # print("{} - apply:{} change:{}".format(number, res1[0], res2[0])) print("{} - rename:{}".format(number, res2[0])) time.sleep(11)
def __init__(self, email, password): self.requester = Requester(email, password) self.data = None self.logger = Logger(email)
class Request: def __init__(self, email, password): self.requester = Requester(email, password) self.data = None self.logger = Logger(email) def request(self, url, params, short_url=True, times=REATTEMPTS_COUNT, sleeping_time=3): success = False data = "No error info" while not success and times > 0: times -= 1 success, data = self.requester.make(url, params, short_url) if not success and times > 0: if "No session" in str(data): self.logger.warning("re-loginning") self.enter() elif "Please try again in a minute" in str(data): self.logger.warning("{} secs waiting".format(sleeping_time)) time.sleep(sleeping_time) else: self.logger.warning(data) if success: self.data.parse_dict(data) return [success, data] def enter(self, times=REATTEMPTS_COUNT): success = False data = "No error info" while not success and times > 0: times -= 1 success, data = self.requester.enter() if not success and times > 0: self.logger.warning("Cant log in {}".format(data)) time.sleep(RELOGIN_TIMEOUT) if success: self.logged_in = True if self.data is None: self.data = Data(data, self.requester.player_info, self) else: self.data.parse_dict(data) return [success, self.data] def request_help(self): url = "AllianceAction/helpAllMembersForFree" params = {} return self.request(url, params) def habitat_info(self, habitat_id): url = "HabitatAction/habitatInformation" params = { "id": habitat_id } return self.request(url, params) def alliance_info(self, alliance_id): url = "AllianceAction/allianceInformation" params = { "id": alliance_id } return self.request(url, params) def player_info(self, player_id): url = "ProfileAction/playerInformation" params = { "id": player_id } return self.request(url, params) def send_message(self, content, discussion_id): url = "DiscussionAction/addDiscussionEntry" params = { "discussionId": str(discussion_id), "content": urllib.parse.quote_plus(str(content)) } return self.request(url, params) def public_report(self, report): url = "ReportAction/setReportPublished" params = { "id": str(report.id), "published": "true" } return self.request(url, params) def fetch_reports(self): url = "ReportAction/habitatReportArray" params = {} return self.request(url, params) def send_support(self, destination_id, unit_dictionary, source_id): url = "TransitAction/startTransit" params = { "transitType": str(0), "unitDictionary": str(unit_dictionary), "sourceHabitatID": str(source_id), "resourceDictionary": "{}", "destinationHabitatID": str(destination_id) } return self.request(url, params) def send_resources(self, destination_id, unit_dictionary, resource_dictionary, source_id): url = "TransitAction/startTransit" params = { "transitType": str(4), "resourceDictionary": str(resource_dictionary), "unitDictionary": str(unit_dictionary), "sourceHabitatID": str(source_id), "destinationHabitatID": str(destination_id) } return self.request(url, params) def delete_report(self, report): url = "ReportAction/deleteHabitatReport" params = { "id": str(report.id) } return self.request(url, params) def recall_support(self, source_id, unit_dictionary, destination_id): url = "TransitAction/startTransit" params = { "destinationHabitatID": str(destination_id), "sourceHabitatID": str(source_id), "unitDictionary": str(unit_dictionary), "transitType": str(1) } return self.request(url, params) def load_alliance_rating(self): url = "QueryAction/allianceRanks" params = { "offset": str(0), "limit": str(50) } return self.request(url, params) def load_player_rating(self, offset): url = "QueryAction/playerRanks" params = { "offset": str(offset), "limit": str(50) } return self.request(url, params) def create_message(self, subject, player_id, content): url = "DiscussionAction/createDiscussion" params = { "content": str(content), "subject": str(subject), "receivingPlayerArray": str(player_id) } return self.request(url, params) def check_valid_login_browser(self): url = "" params = { "login": self.requester.email, "password": self.requester.password_hashed, "deviceType": "Email", } return self.request(url, params, short_url=False, times=1) def load_worlds(self): url = WORLDS_URL params = { "login": self.requester.email, "deviceId": self.requester.email, "password": self.requester.password_hashed, "deviceType": "Email", } return self.request(url, params, short_url=False) def send_attack(self, destination_id, unit_dictionary, source_id): url = "TransitAction/startTransit" params = { "unitDictionary": str(unit_dictionary), "sourceHabitatID": str(source_id), "destinationHabitatID": str(destination_id) } return self.request(url, params) def set_diplo(self, alliance_id, alliance_rel): url = "AllianceAction/setDiplomaticRelation" params = { "id": str(alliance_id), "diplomaticValue": str(alliance_rel) } return self.request(url, params) def send_spy(self, destination_id, source_id, amount=1): url = "SpyAction/startSpyingTransit" params = { "copperAmount": str(amount), "sourceHabitatID": str(source_id), "destinationHabitatID": str(destination_id) } return self.request(url, params) def map(self, x, y, width, height): url = "MapAction/map" params = { "mapX": x, "mapY": y, "mapWidth": width, "mapHeight": height } return self.request(url, params) def change_password(self, new): url = "" params = { "password": self.requester.password_hashed, "newPassword": hashlib.sha256(new.encode("utf-8")).hexdigest(), "deviceId": self.requester.email, "login": self.requester.email, "deviceType": "Email" } return self.request(url, params, short_url=False) def create_account(self, nick, world_id): url = "LoginAction/create" params = { "worldId": str(world_id), "nick": nick, "deviceId": self.requester.email, "deviceType": "Email", "login": self.requester.email, "password": self.requester.password_hashed, } print(params) return self.request(url, params) def apply_to_alliance(self, alliance_id): url = "AllianceAction/apply" params = { "id": alliance_id } return self.request(url, params) def change_nickname(self, name): url = "ProfileAction/changeNickname" params = { "nick": name } return self.request(url, params) def get_messages_titles(self): url = "MessageAction/messageTitleArray" params = {} return self.request(url, params)
from Request import Request from Module.Logger import Logger from Operator.LinkSearch import search_text_for_links email = "*****@*****.**" password = "******" logger = Logger(email) request = Request(email, password) data = request.enter()[1] hunter = data.get_instance_by_link("l+k://player?377&230") has = data.get_habitats_by_players([hunter]) for h in has: logger.log(h) exit() # load spies with open("ourSpiesText", "r") as targetPlayersFile: spiesText = targetPlayersFile.read() spiesPlayersLinks = search_text_for_links(spiesText)["player"] spiesPlayers = data.get_instances_by_links(spiesPlayersLinks) # center centerHab = data.get_instance_by_link("l+k://coordinates?16473,16384&230") # Get targets targetAlliances = data.get_instances_by_links(["l+k://alliance?71&230"]) targetPlayers = data.get_players_by_alliances(targetAlliances) targetPlayers = [ player for player in targetPlayers if player not in spiesPlayers ] targetPlayers = [player for player in targetPlayers if not player.vacation]
from Request import Request from Module.Logger import Logger import time import random from Operator.LinkSearch import search_text_for_links logger = Logger("-") request = Request("*****@*****.**", "123") data = request.enter()[1] logger.log("logged in") own_castle = data.get_instance_by_link("l+k://coordinates?16546,16440&230") logger.log(own_castle) with open("realattackcastles ", "r") as realsFile: realsText = realsFile.read() realLinks = search_text_for_links(realsText)["habitat"] realHabs = data.get_instances_by_links(realLinks) habitats = realHabs # habitat instances for habitat in habitats: # time.sleep(random.randint(4, 8)) logger.log("Spy to ") logger.log(habitat) success, info = request.send_spy(habitat.id, own_castle.id, "1") if success: logger.log("successfully") else: logger.log("unsuccessfully. Error: {}".format(info)) logger.log("-")