def add_search(): print("Adding a new search entry") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") connector = init_mysql("db_map") cursor = connector.cursor() # Adding a new sig ADD_NEW_SEARCH = "INSERT INTO tb_search (search_name, search_character) VALUES (%s, %s)" cursor.execute(ADD_NEW_SEARCH, (json_data['search_name'], json_data['character_id'])) connector.commit() throw_json_success("Success", {})
def get_settings(): print("Getting character settings") ### Authenticating user json_input = request.data json_data = json.loads(json_input.decode('utf-8')) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") mydb = init_mysql("db_character") select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor = mydb.cursor() cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() if len(result_raw) <= 0: init_setting_file(json_data['character_id'], cursor, mydb) cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result) else: result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result)
def get_search(): print("Getting all of the search data") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") connector = init_mysql("db_map") cursor = connector.cursor() SELECT_ALL_SEARCH = "SELECT * FROM tb_search" cursor.execute(SELECT_ALL_SEARCH) result = cursor.fetchall() result_encoded = get_format_from_raw_full(result) throw_json_success("Success", result_encoded)
def get_character(): json_input = request.data.decode('utf-8') json_data = json.loads(json_input) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") ### Okay if we have authenticated, lets get all of the relevant information get_character_query = "SELECT tb_character_type.*, tb_character.character_id, tb_character.character_type FROM tb_character INNER JOIN tb_character_type WHERE tb_character.character_id = %s AND character_type_id = character_type" ### Connecting mydb = init_mysql("db_character") cursor = mydb.cursor() cursor.execute(get_character_query, (json_data['character_id'], )) result_raw = cursor.fetchall() print(result_raw) result_full = get_format_from_raw(result_raw, cursor) return throw_json_success("Success", result_full)
def get_new_auth(): print("Getting a new auth code for the stream data") # Getting the characters location # Checking how hardcore we are on updating json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") ### Okay, we will now proceed to generate a new authentication token.... new_token = gen_random_string(8) ### Inserting into our database connector = init_mysql("db_cctv") cursor = connector.cursor() INSERT_CCTV_TOKEN = "INSERT INTO tb_cctv_token (cctv_token_code, cctv_init_character) VALUES (%s, %s)" cursor.execute(INSERT_CCTV_TOKEN, (new_token, json_data['character_id'])) connector.commit() return throw_json_success("Success", new_token)
def get_current_tokens(): print("Getting all available tokens") json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") ### Connecting with our database connector = init_mysql("db_cctv") cursor = connector.cursor() SELECT_TOKEN = "SELECT * FROM tb_cctv_token" cursor.execute(SELECT_TOKEN, ) result = list(cursor.fetchall()) new_result = [] for element in result: new_element = [] for value in element: if isinstance(value, datetime.datetime): value = date_to_string(value) new_element.append(value) new_element = tuple(new_element) new_result.append(new_element) print(new_result) return throw_json_success("Success", new_result)
def get_sigs(): ##print("Getting all sigs :O") # Getting the sig info json_input = request.data json_data = json.loads(json_input.decode('utf-8')) ### Authenticating the player # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Building data from the given info mydb = init_mysql("db_map") cursor = mydb.cursor() select = "SELECT * FROM tb_sig WHERE sig_status = 0" cursor.execute(select) result_raw = cursor.fetchall() result = get_format_from_raw_full(result_raw, cursor) result = encode_datetime(result) return throw_json_success("success", result)
def add_eft_fit(): json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") character_id, character_auth_code = json_data['character_id'], json_data[ 'character_auth_code'] # Converting from EFT to ESI eft_fit = json_data['eft_fit'] esi_fit = convert_eft_to_esi(eft_fit) esi_fit_str = json.dumps(esi_fit) fit_attributes = json.dumps(json_data['fit_attributes']) fit_title = json_data['fit_title'] # Saving it into our database mydb = init_mysql("db_fitting") cursor = mydb.cursor() skill_type_id, skill_type_name = (calculate_fit_skill_reqs(esi_fit, mydb)) fitting_add = "INSERT INTO tb_fitting (fit_attributes, fit_esi, fit_eft, character_id, fit_title, fit_skillreqs_typeid, fit_skillreqs_typename) VALUES (%s, %s, %s, %s, %s, %s, %s)" cursor.execute( fitting_add, (fit_attributes, esi_fit_str, eft_fit, json_data['character_id'], fit_title, json.dumps(skill_type_id), json.dumps(skill_type_name))) mydb.commit() return throw_json_success("success", "Fit inserted")
def add_wormhole_mask(): print("Getting character settings") ### Authenticating user json_input = request.data json_data = json.loads(json_input.decode('utf-8')) print(json_data) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") mydb = init_mysql("db_character") select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor = mydb.cursor() cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) print(result) wormhole_mask = json.loads(result['wormhole_mask']) ### Appending the system by system name system_name = json_data['system_name'] system_nickname = json_data['system_nickname'] system_id = get_solar_system_id_from_name(system_name) ### Using this, we are rebuilding it new_tag = { "systemName": system_name, "systemID": system_id, "systemNickname": system_nickname } wormhole_mask.append(new_tag) wormhole_mask = json.dumps(wormhole_mask) print(wormhole_mask) update = "UPDATE tb_character_setting SET wormhole_mask = %s WHERE character_id = %s" cursor.execute(update, (wormhole_mask, json_data['character_id'])) mydb.commit() select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result)
def get_new_token(): print("Getting a new token for accessing the stream") # Getting the characters location # Checking how hardcore we are on updating json_input = request.data.decode('utf-8') json_data = json.loads(json_input) ### Authenticating the token... connector = init_mysql("db_cctv") cursor = connector.cursor() print("Loading from ") print(json_data) ### AND cctv_init < (NOW() - INTERVAL 5 MINUTE GET_TOKEN = "SELECT * FROM db_cctv.tb_cctv_token WHERE cctv_use_status = 0 AND cctv_token_code = %s AND cctv_init_character = %s" cursor.execute(GET_TOKEN, (json_data['stream_access_code'], json_data['character_id'])) result = cursor.fetchall() ### Checking for sizes if (len(result) <= 0): return throw_json_error(500, "Invalid token or character ID") result_full = get_format_from_raw_full(result, cursor)[0] ### Checking for sizes if (len(result_full) <= 0): ### Invalid token return throw_json_error(500, "Invalid token or character ID") ### Okay, if we made it this far we are good ### Lets first set this token to used UPDATE_TOKEN_USE_STATUS = "UPDATE db_cctv.tb_cctv_token SET cctv_use_status = 1 WHERE cctv_token_code = %s" cursor.execute(UPDATE_TOKEN_USE_STATUS, (json_data['stream_access_code'],)) ### Okay, now we are going to insert this new stream into our system ### Once we have done that, we are going to go ahead and generate the authentication token ### Then we are going to insert this stream into our system access_token = gen_random_string(256) INSERT_NEW_STREAM = "INSERT INTO db_cctv.tb_cctv (cctv_auth, cctv_name, cctv_character_id) VALUES (%s, %s, %s)" cursor.execute(INSERT_NEW_STREAM, (access_token, json_data['stream_title'], json_data['character_id'])) connector.commit() return throw_json_success("Success", access_token)
def get_all_systems(): ### Getting all of the possible wormhole types and all of their associative datapoints #print("Getting all static wormhole data values") ### Getting data connector = init_mysql("db_static") cursor = connector.cursor() select = "SELECT solarSystemName, security FROM mapSolarSystems" cursor.execute(select) result_raw = cursor.fetchall() result = get_format_from_raw_full(result_raw, cursor) return throw_json_success("Success", result)
def delete_wormhole_mask(): print("Getting character settings") ### Authenticating user json_input = request.data json_data = json.loads(json_input.decode('utf-8')) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") mydb = init_mysql("db_character") select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor = mydb.cursor() cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) print(result) wormhole_mask = json.loads(result['wormhole_mask']) ### Getting the index we need to delete index_track = 0 for entry in wormhole_mask: system_name = entry['systemName'] if system_name == json_data['system_name']: break index_track = index_track + 1 wormhole_mask.pop(0) wormhole_mask = json.dumps(wormhole_mask) update = "UPDATE tb_character_setting SET wormhole_mask = %s WHERE character_id = %s" cursor.execute(update, (wormhole_mask, json_data['character_id'])) mydb.commit() select = "SELECT * FROM tb_character_setting WHERE character_id = %s" cursor.execute(select, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw(result_raw, cursor) result['wormhole_mask'] = json.loads(result['wormhole_mask']) return throw_json_success(200, result)
def delete_tokens(): print("Deleting given token") json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") token_ids = json_data['token_delete_array'] ### Converting for token_id in token_ids: print(token_id) ### Connecting with our database connector = init_mysql("db_cctv") cursor = connector.cursor() DELETE_CCTV_TOKEN = "DELETE FROM tb_cctv_token WHERE cctv_token_id = %s" cursor.execute(DELETE_CCTV_TOKEN, (token_id,)) connector.commit() SELECT_TOKEN = "SELECT * FROM tb_cctv_token" cursor.execute(SELECT_TOKEN, ) result = list(cursor.fetchall()) new_result = [] for element in result: new_element = [] for value in element: if isinstance(value, datetime.datetime): value = date_to_string(value) new_element.append(value) new_element = tuple(new_element) new_result.append(new_element) print(new_result) return throw_json_success("Success", new_result)
def get_eve_all(): json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") character_id, character_auth_code = json_data['character_id'], json_data[ 'character_auth_code'] # Attempting to load all of the eve fits associated with this account # Given the character ID and character auth code, lets get (or generate) and access token sso_id = auth_character(character_id, character_auth_code) # Checking for error if sso_id == -1: return throw_json_error(500, "Invalid character authentication code") # Otherwise, lets get that token access_token = get_access_token(character_id, sso_id) # Now that we have an access token, lets begin working with it # First we will get the players exact location result_fit = api_call_get("characters/" + str(character_id) + "/fittings/", { "character_id": character_id, "token": access_token }) # Getting the solar system ID and the structure ID result_fit_content = json.loads(result_fit.content.decode('utf-8')) # Converting each fit over to EFT style fitting output_eft = [] for fit in result_fit_content: output_eft.append(convert_esi_to_eft(fit)) return throw_json_success("success", output_eft)
def get_location(): # Getting the characters location # Checking how hardcore we are on updating json_input = request.data.decode('utf-8') json_data = json.loads(json_input) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") # Lets get the options... refresh_type = "Normal" try: refresh_type = json_data['refresh_type'] except: print("Not given a refresh type, using the normal default type") # Lets check how old the datapoint is. Older than the normal value will result in a refresh refresh_time = default_refresh_time if refresh_type == "Normal": refresh_time = default_refresh_time elif refresh_type == "Force": refresh_time = 0 elif refresh_type == "Cache": refresh_time = 99999 # We have our refresh time, lets get the location and its update time... mydb = init_mysql("db_character") cursor = mydb.cursor() location_get = "SELECT * FROM tb_character_location WHERE character_id = %s" cursor.execute(location_get, (json_data['character_id'], )) result_raw = cursor.fetchall() ### Wait a second... ### Did this character ever get generated their location? ### If not, we need to generate it first... if len(result_raw) <= 0: print("Missing data for this character, generating the information...") result_raw = update_character_location( json_data['character_id'], json_data['character_auth_code']) result = get_format_from_raw_full(result_raw, cursor)[0] # Removing update time result['update_time'] = "" if len(result['wormhole_data']) > 0: result['wormhole_data'] = json.loads(result['wormhole_data']) else: result['wormhole_data'] = "{}" print(result) ### Getting the actual information we need data system_info = get_system_info(result['character_system_id']) result['data'] = system_info return throw_json_success("success", result) else: result = get_format_from_raw(result_raw, cursor) update_time = result['update_time'] time_between = datetime.now() - update_time minutes = time_between.seconds / 60 / 60 if (minutes < refresh_time): print("Refreshing our location information...") update_character_location(json_data['character_id'], json_data['character_auth_code']) location_get = "SELECT * FROM tb_character_location WHERE character_id = %s" cursor.execute(location_get, (json_data['character_id'], )) result_raw = cursor.fetchall() result = get_format_from_raw_full(result_raw, cursor)[0] print(result) # Removing update time result['update_time'] = "" if len(result['wormhole_data']) > 0: result['wormhole_data'] = json.loads(result['wormhole_data']) else: result['wormhole_data'] = "{}" # Giving the result the location-based data that we are SUPPOSED to have... ### Getting the actual information we need data system_info = get_system_info(result['character_system_id']) result['data'] = system_info return throw_json_success("success", result)
def get_chain(): #print("Getting the users full chain") json_input = request.data json_data = json.loads(json_input.decode('utf-8')) # Authenticating our user auth = auth_character(json_data['character_id'], json_data['character_auth_code']) if auth == -1: return throw_json_error(400, "Invalid authentication code") system_name = json_data['system_name'] system_id = get_solar_system_id_from_name(system_name)['solarSystemID'] ### Getting sig data sig_data = get_sigs_internal() ### Loading the first to-visit visit_list = [] visit_list.append(system_id) parent_data = {} visisted_list = [] ### Loading from system name output = {} ### Iterate on all connections, deep search while len(visit_list) > 0: system_to_visit = visit_list.pop(0) if system_to_visit in visisted_list: continue #print("Iterating on " + str(system_to_visit)) child_data = [] ### Appending the data from the solar system id location_data = get_system_info(system_to_visit) location_name = location_data['solarSystemName'] if location_name in sig_data['sig_output_system']: ### Okay this system has sigs... ### Lets work on those real quick sig_system_data = sig_data['sig_output_system'][location_name] for sig in sig_system_data: sig_data_iterate = sig_system_data[sig] if "sig_wormhole_data" in sig_data_iterate: sig_wormhole_data = json.loads( sig_data_iterate['sig_wormhole_data']) if "wormhole_destination" not in sig_wormhole_data: continue sig_wormhole_destination = sig_wormhole_data[ 'wormhole_destination'] ### If this is a real thing, lets continue if len(sig_wormhole_destination) <= 0: continue ### Okay, we have a valid destination... ### Lets add this ID to our system solar_system_id = get_solar_system_id_from_name( sig_wormhole_destination) ### Checking for invalid systems if len(solar_system_id) <= 0: continue ### Getting the final system ID solar_system_id = solar_system_id['solarSystemID'] visit_list.append(solar_system_id) child_data.append(sig_wormhole_destination) location_data['children_by_system'] = child_data output[location_data['solarSystemName']] = location_data visisted_list.append(system_to_visit) return throw_json_success(200, output)