def show_error(self, key): errors = { 'count_limit': "You cannot build more buildings of that type.", 'outside_sector': "You cannot build that far from your headquarters.", 'outside_border': "You must build within your borders.", 'insufficient_resources': "Insufficient resources.", 'adjacency_error': "You cannot build a building next to another building" } error = errors[key] util.verboseprint(error)
def send_request(self, attempts=10): is_error = False data = None try: url = _server_address + '/server.py?' + urlencode(self.args) util.verboseprint("Sending: " + url) c = urlopen(url) raw_bytes = c.read() if 'bytes' in str(type(raw_bytes)): # Ugh, new Python 3 annoyance I learned just now raw_bytes = raw_bytes.decode('utf-8') data = deserialize_thing(raw_bytes) util.verboseprint("RECEIVED: " + str(data)) if data == None: util.verboseprint("RAW DATA: " + raw_bytes.replace('<br />', "\n")) c.close() if data != None and data.get('redirect') != None: self.update_address(str(data['redirect'])) self.send_request() return except: if attempts < 1: data = { 'success': False, 'message': "Server did not respond" } is_error = True else: time.sleep((11 - attempts) * 3.0) self.send_request(attempts - 1) return self.lock.acquire(True) self.error = is_error self.response = data self.hasresponse = True self.lock.release()
def send_request(self, attempts=10): is_error = False data = None try: url = _server_address + '/server.py?' + urlencode(self.args) util.verboseprint("Sending: " + url) c = urlopen(url) raw_bytes = c.read() if 'bytes' in str( type(raw_bytes )): # Ugh, new Python 3 annoyance I learned just now raw_bytes = raw_bytes.decode('utf-8') data = deserialize_thing(raw_bytes) util.verboseprint("RECEIVED: " + str(data)) if data == None: util.verboseprint("RAW DATA: " + raw_bytes.replace('<br />', "\n")) c.close() if data != None and data.get('redirect') != None: self.update_address(str(data['redirect'])) self.send_request() return except: if attempts < 1: data = {'success': False, 'message': "Server did not respond"} is_error = True else: time.sleep((11 - attempts) * 3.0) self.send_request(attempts - 1) return self.lock.acquire(True) self.error = is_error self.response = data self.hasresponse = True self.lock.release()
def update_address(self, new_address): global _server_address _server_address = new_address util.verboseprint("SERVER HAS MOVED TO:", new_address) util.write_file('server.txt', new_address)