From c1743c954c52776f60140789d4dcd3a5f1041e18 Mon Sep 17 00:00:00 2001 From: Anakin5 Date: Tue, 16 Aug 2016 11:02:14 +0800 Subject: [PATCH 1/5] Do not spin fort on timeout when restarting the bot (#3931) Fix bot stuck between forts when inventory is full --- pokemongo_bot/__init__.py | 9 +++++++++ pokemongo_bot/cell_workers/spin_fort.py | 20 +++----------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index bfe2c25cf3..3f5c0ebad4 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -474,6 +474,15 @@ def _register_events(self): def tick(self): self.health_record.heartbeat() self.cell = self.get_meta_cell() + + now = time.time() * 1000 + + for fort in self.cell["forts"]: + timeout = fort.get("cooldown_complete_timestamp_ms", 0) + + if timeout >= now: + self.fort_timeouts[fort["id"]] = timeout + self.tick_count += 1 # Check if session token has expired diff --git a/pokemongo_bot/cell_workers/spin_fort.py b/pokemongo_bot/cell_workers/spin_fort.py index cc25936350..4d4b8b001f 100644 --- a/pokemongo_bot/cell_workers/spin_fort.py +++ b/pokemongo_bot/cell_workers/spin_fort.py @@ -57,15 +57,14 @@ def work(self): player_latitude=f2i(self.bot.position[0]), player_longitude=f2i(self.bot.position[1]) ) - if 'responses' in response_dict and 'FORT_SEARCH' in response_dict['responses']: + if ('responses' in response_dict) and ('FORT_SEARCH' in response_dict['responses']): spin_details = response_dict['responses']['FORT_SEARCH'] spin_result = spin_details.get('result', -1) - if spin_result == SPIN_REQUEST_RESULT_SUCCESS: + + if (spin_result == SPIN_REQUEST_RESULT_SUCCESS) or (spin_result == SPIN_REQUEST_RESULT_INVENTORY_FULL): self.bot.softban = False experience_awarded = spin_details.get('experience_awarded', 0) - - items_awarded = self.get_items_awarded_from_fort_spinned(response_dict) if experience_awarded or items_awarded: @@ -108,12 +107,6 @@ def work(self): formatted="Pokestop {pokestop} on cooldown. Time left: {minutes_left}.", data={'pokestop': fort_name, 'minutes_left': minutes_left} ) - elif spin_result == SPIN_REQUEST_RESULT_INVENTORY_FULL: - if not self.ignore_item_count: - self.emit_event( - 'inventory_full', - formatted="Inventory is full!" - ) else: self.emit_event( 'unknown_spin_result', @@ -148,12 +141,6 @@ def work(self): def get_forts_in_range(self): forts = self.bot.get_forts(order_by_distance=True) - - for fort in reversed(forts): - if 'cooldown_complete_timestamp_ms' in fort: - self.bot.fort_timeouts[fort["id"]] = fort['cooldown_complete_timestamp_ms'] - forts.remove(fort) - forts = filter(lambda fort: fort["id"] not in self.bot.fort_timeouts, forts) forts = filter(lambda fort: distance( self.bot.position[0], @@ -186,4 +173,3 @@ def get_items_awarded_from_fort_spinned(self, response_dict): # TODO : Refactor this class, hide the inventory update right after the api call def _update_inventory(self, item_awarded): inventory.items().get(item_awarded['item_id']).add(item_awarded['item_count']) - From ad32f1d279bfb02e769af7e9f3fc4c439794207a Mon Sep 17 00:00:00 2001 From: mjmadsen Date: Mon, 15 Aug 2016 22:45:43 -0500 Subject: [PATCH 2/5] Fixed references to self.bot.config.walk (#4046) * Fixed error * Fixed error --- pokemongo_bot/cell_workers/follow_path.py | 2 +- pokemongo_bot/cell_workers/follow_spiral.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index bf05d14984..055150070a 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -126,7 +126,7 @@ def work(self): lng ) - if dist <= 1 or (self.bot.config.walk > 0 and is_at_destination): + if dist <= 1 or (self.bot.config.walk_min > 0 and is_at_destination): if (self.ptr + 1) == len(self.points): self.ptr = 0 if self.path_mode == 'linear': diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index 8dbab17546..f956f352eb 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -114,7 +114,7 @@ def work(self): } ) - if dist <= 1 or (self.bot.config.walk > 0 and step_walker == None): + if dist <= 1 or (self.bot.config.walk_min > 0 and step_walker == None): if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1: self.direction *= -1 if len(self.points) != 1: From 6fa57fe9b1d9af1d8cb74d19b0dbdb6f31d3c91c Mon Sep 17 00:00:00 2001 From: Simon Shi Date: Tue, 16 Aug 2016 13:13:33 +0800 Subject: [PATCH 3/5] Updating run.sh and install.sh (#4033) * Update run.sh * Update setup.sh * Update setup.sh * Update setup.sh --- run.sh | 9 +++++++++ setup.sh | 25 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index fa6d8ffab1..31743bb1bf 100755 --- a/run.sh +++ b/run.sh @@ -8,6 +8,15 @@ filename="./configs/config.json" fi cd $pokebotpath source bin/activate +git fetch -a +if [ "1" == $(git branch -vv |grep -c "* dev") ] && [ $(git log --pretty=format:"%h" -1) != $(git log --pretty=format:"%h" -1 origin/dev) ] +then +echo "Branch dev hav an update. Run ./setup.sh -u to update." +elif [ "1" == $(git branch -vv |grep -c "* master") ] && [ $(git log --pretty=format:"%h" -1) != $(git log --pretty=format:"%h" -1 origin/master) ] +then +echo "Branch master hav an update. Run ./setup.sh -u to update." +fi +sleep 2 if [ ! -f "$filename" ]; then echo "There's no "$filename" file. Please use ./setup.sh -c to creat one." fi diff --git a/setup.sh b/setup.sh index 26c0eb4745..a013407f74 100755 --- a/setup.sh +++ b/setup.sh @@ -62,6 +62,17 @@ then echo "You are on Mac os" sudo brew update sudo brew install --devel protobuf +elif [ $(uname -s) == CYGWIN* ] +then +echo "You are on Cygwin" +if [ !-x "$(command -v apt-cyg)" ] +then +wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg +chmod +x apt-cyg +mv apt-cyg /usr/local/bin/ +fi +apt-cyg install gcc-core make +easy_install pip elif [ -x "$(command -v apt-get)" ] then echo "You are on Debian/Ubuntu" @@ -91,7 +102,7 @@ echo "Please check if you have python pip gcc make installed on your device." echo "Wait 5 seconds to continue or Use ctrl+c to interrupt this shell." sleep 5 fi -sudo pip install virtualenv +easy_install virtualenv Pokebotreset Pokebotupdate Pokebotencrypt @@ -101,8 +112,16 @@ Pokebotconfig function Pokebotreset () { cd $pokebotpath -git fetch --all +git fetch -a +if [ "1" == $(git branch -vv |grep -c "* dev") ] +then +echo "Branch dev resetting." git reset --hard origin/dev +elif [ "1" == $(git branch -vv |grep -c "* master") ] +then +echo "Branch master resetting." +git reset --hard origin/master +fi if [ -x "$(command -v python2)" ] then virtualenv -p python2 . @@ -118,7 +137,7 @@ echo " -i,--install. Install PokemonGo-Bot." echo " -b,--backup. Backup config files." echo " -c,--config. Easy config generator." echo " -e,--encrypt. Make encrypt.so." -echo " -r,--reset. Force sync dev branch." +echo " -r,--reset. Force sync source branch." echo " -u,--update. Command git pull to update." } From 7d0da5a2a400e3dc9f7696d9886de039d7b890ab Mon Sep 17 00:00:00 2001 From: Eli White Date: Mon, 15 Aug 2016 23:56:48 -0700 Subject: [PATCH 4/5] Fixing typo --- pokemongo_bot/inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/inventory.py b/pokemongo_bot/inventory.py index c59ba4b046..62a595b07d 100644 --- a/pokemongo_bot/inventory.py +++ b/pokemongo_bot/inventory.py @@ -304,7 +304,7 @@ def all(self): def add(self, pokemon): if pokemon.id <= 0: - raise ValueError("Can't add a pokemin whitout id") + raise ValueError("Can't add a pokemon without id") if pokemon.id in self._data: raise ValueError("Pokemon already present in the inventory") self._data[pokemon.id] = pokemon From 91aea57335c6fa78eb6e6f1e68fedc7d1c3647d8 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Tue, 16 Aug 2016 07:16:15 -0700 Subject: [PATCH 5/5] Added heartbeat threshold, it's not reasonable to send heartbeat to server every second. (#4058) * Added heartbeat threshold, it's not reasonable to send heartbeat to server every second. * Added example in config. --- configs/config.json.example | 1 + configs/config.json.map.example | 1 + configs/config.json.pokemon.example | 1 + pokecli.py | 9 ++++++++- pokemongo_bot/__init__.py | 14 +++++++++----- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 41b3bd0535..d5dfebf0c5 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -6,6 +6,7 @@ "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", "websocket_server": false, + "heartbeat_threshold": 10, "tasks": [ { "type": "HandleSoftBan" diff --git a/configs/config.json.map.example b/configs/config.json.map.example index ffe7b58335..d691011e0f 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -5,6 +5,7 @@ "location": "SOME_LOCATION", "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", + "heartbeat_threshold": 10, "tasks": [ { "type": "HandleSoftBan" diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 33736ab883..1876ba82b2 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -5,6 +5,7 @@ "location": "SOME_LOCATION", "gmapkey": "GOOGLE_MAPS_API_KEY", "encrypt_location": "", + "heartbeat_threshold": 10, "tasks": [ { "type": "HandleSoftBan" diff --git a/pokecli.py b/pokecli.py index 4fbe9db748..2f99d17cbe 100644 --- a/pokecli.py +++ b/pokecli.py @@ -492,7 +492,14 @@ def _json_loader(filename): type=float, default=1 ) - + add_config( + parser, + load, + long_flag="--heartbeat_threshold", + help="A threshold between each heartbeat sending to server", + type=int, + default=10 + ) # Start to parse other attrs config = parser.parse_args() if not config.username and 'username' not in load: diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 3f5c0ebad4..9efea4071d 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -79,7 +79,8 @@ def __init__(self, config): self.web_update_queue = Queue.Queue(maxsize=1) self.web_update_thread = threading.Thread(target=self.update_web_location_worker) self.web_update_thread.start() - + self.heartbeat_threshold = self.config.heartbeat_threshold + self.heartbeat_counter = 0 def start(self): self._setup_event_system() self._setup_logging() @@ -1017,10 +1018,13 @@ def heartbeat(self): self.fort_timeouts = {id: timeout for id, timeout in self.fort_timeouts.iteritems() if timeout >= time.time() * 1000} - request = self.api.create_request() - request.get_player() - request.check_awarded_badges() - request.call() + self.heartbeat_counter = self.heartbeat_counter + 1 + if self.heartbeat_counter >= self.heartbeat_threshold: + self.heartbeat_counter = 0 + request = self.api.create_request() + request.get_player() + request.check_awarded_badges() + request.call() try: self.web_update_queue.put_nowait(True) # do this outside of thread every tick except Queue.Full: