Work on exports and some fixes to sound and multiplayer functions
This commit is contained in:
@@ -25,11 +25,12 @@ func become_host() -> void:
|
||||
multiplayer.peer_disconnected.connect(_remove_player_from_game)
|
||||
|
||||
|
||||
func join_game(new_handle : String) -> Error:
|
||||
func join_game(new_handle : String, ip : String = "") -> Error:
|
||||
print("Player 2 joining.")
|
||||
|
||||
if ip == "":
|
||||
ip = SERVER_IP
|
||||
var client_peer = ENetMultiplayerPeer.new()
|
||||
var error = client_peer.create_client(SERVER_IP, SERVER_PORT)
|
||||
var error = client_peer.create_client(ip, SERVER_PORT)
|
||||
multiplayer.multiplayer_peer = client_peer
|
||||
handle = new_handle
|
||||
id = multiplayer.get_unique_id()
|
||||
@@ -85,3 +86,18 @@ func receive_peer_handle(peer_id, peer_handle) -> void:
|
||||
@rpc("any_peer", "call_remote")
|
||||
func report_handle_to_peer(peer_id : int) -> void:
|
||||
rpc_id(peer_id, "receive_peer_handle", multiplayer.get_unique_id(), handle)
|
||||
|
||||
func get_local_ip() -> String:
|
||||
var ip_address = ""
|
||||
# Get all local addresses as an Array
|
||||
var addresses: PackedStringArray = IP.get_local_addresses()
|
||||
|
||||
for address in addresses:
|
||||
# Check if it is an IPv4 address and not a loopback or link-local address
|
||||
if "." in address and not address.begins_with("127.") and not address.begins_with("169.254."):
|
||||
# Filter for common private IP ranges (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
|
||||
if address.begins_with("192.168.") or address.begins_with("10.") or (address.begins_with("172.") and int(address.split(".")[1]) >= 16 and int(address.split(".")[1]) <= 31):
|
||||
ip_address = address
|
||||
break # Exit the loop once a valid local IP is found
|
||||
|
||||
return ip_address
|
||||
|
||||
Reference in New Issue
Block a user