mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix unhandled exception with port check function
This commit is contained in:
parent
3e84df601f
commit
d93038a70d
@ -82,18 +82,21 @@ class Helpers:
|
|||||||
try:
|
try:
|
||||||
requests.get('https://google.com', timeout=1)
|
requests.get('https://google.com', timeout=1)
|
||||||
return True
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_port(server_port):
|
def check_port(server_port):
|
||||||
host_public = get('https://api.ipify.org').text
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
host_public = get('https://api.ipify.org').text
|
||||||
result = sock.connect_ex((host_public ,server_port))
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.close()
|
result = sock.connect_ex((host_public ,server_port))
|
||||||
if result == 0:
|
sock.close()
|
||||||
return True
|
if result == 0:
|
||||||
else:
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except Exception as err:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -451,7 +454,7 @@ class Helpers:
|
|||||||
sizes = []
|
sizes = []
|
||||||
for p in paths:
|
for p in paths:
|
||||||
sizes.append({
|
sizes.append({
|
||||||
"path": p,
|
"path": p,
|
||||||
"size": self.human_readable_file_size(os.stat(p).st_size)
|
"size": self.human_readable_file_size(os.stat(p).st_size)
|
||||||
})
|
})
|
||||||
return sizes
|
return sizes
|
||||||
@ -610,7 +613,7 @@ class Helpers:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def in_path_old(x, y):
|
def in_path_old(x, y):
|
||||||
return os.path.abspath(y).__contains__(os.path.abspath(x))
|
return os.path.abspath(y).__contains__(os.path.abspath(x))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_banned_players(server_id, db_helper):
|
def get_banned_players(server_id, db_helper):
|
||||||
stats = db_helper.get_server_stats_by_id(server_id)
|
stats = db_helper.get_server_stats_by_id(server_id)
|
||||||
@ -624,7 +627,7 @@ class Helpers:
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print (ex)
|
print (ex)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return json.loads(content)
|
return json.loads(content)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user