[WIP] NATNEG: Added utils.get_ip_from_str

This commit is contained in:
Sepalani 2016-02-14 16:36:32 +01:00
parent 5ed33d2170
commit 46391303b6
2 changed files with 11 additions and 9 deletions

View File

@ -803,10 +803,7 @@ class GameSpyNatNegServer(object):
for console in [False, True]:
if server is not None:
break
ip = str(utils.get_ip(
bytearray([int(x) for x in ip_str.split('.')]),
0, console
))
ip = str(utils.get_ip_from_str(ip_str, console))
server = next((s for s in servers if s['publicip'] == ip), None)
return server
@ -819,10 +816,7 @@ class GameSpyNatNegServer(object):
for console in [False, True]:
if server is not None:
break
ip = str(utils.get_ip(
bytearray([int(x) for x in ip_str.split('.')]),
0, console
))
ip = str(utils.get_ip_from_str(ip_str, console))
server = self.server_manager.find_server_by_local_address(
ip,
self.session_list[session_id][client_id]['localaddr'],

View File

@ -2,7 +2,7 @@
Copyright (C) 2014 polaris-
Copyright (C) 2014 msoucy
Copyright (C) 2015 Sepalani
Copyright (C) 2016 Sepalani
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@ -165,6 +165,14 @@ def get_ip(data, idx, be=False):
return ctypes.c_int32(get_int(data, idx, be)).value
def get_ip_from_str(ip_str, be=False):
"""Get IP from string.
Endianness by default is little.
"""
return get_ip(bytearray([int(x) for x in ip_str.split('.')]), 0, be)
def get_string(data, idx):
"""Get string from bytes."""
data = data[idx:]