mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-04-24 23:37:09 -05:00
[WIP] NATNEG: Added utils.get_ip_from_str
This commit is contained in:
parent
5ed33d2170
commit
46391303b6
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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:]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user