2024-12-03 21:44:07 +01:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
func test() -> void:
|
|
|
|
start_server()
|
|
|
|
join_server()
|
|
|
|
close_network()
|
|
|
|
|
|
|
|
# Start the network listener.
|
|
|
|
func start_server() -> void:
|
|
|
|
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
2024-12-04 09:42:04 +01:00
|
|
|
if peer.create_server(Game.PORT, Game.MAX_CLIENTS) != OK:
|
|
|
|
Log.warning("Couldn't create the server at port %d!" % Game.PORT)
|
2024-12-03 21:44:07 +01:00
|
|
|
return
|
|
|
|
multiplayer.multiplayer_peer = peer
|
2024-12-04 09:42:04 +01:00
|
|
|
Log.info("Created the server at port %d." % Game.PORT)
|
2024-12-03 21:44:07 +01:00
|
|
|
|
|
|
|
# Connect to a server.
|
|
|
|
func join_server() -> void:
|
|
|
|
var peer: ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
2024-12-04 09:42:04 +01:00
|
|
|
if peer.create_client(Game.IP_ADDRESS, Game.PORT) != OK:
|
|
|
|
Log.warning("Couldn't connect to the server at %s:%d!" % [Game.IP_ADDRESS, Game.PORT])
|
2024-12-03 21:44:07 +01:00
|
|
|
return
|
|
|
|
multiplayer.multiplayer_peer = peer
|
2024-12-04 09:42:04 +01:00
|
|
|
Log.info("Connected to the server at %s:%d." % [Game.IP_ADDRESS, Game.PORT])
|
2024-12-03 21:44:07 +01:00
|
|
|
|
|
|
|
# Close all network connections.
|
|
|
|
func close_network() -> void:
|
|
|
|
multiplayer.multiplayer_peer = null
|
|
|
|
Log.info("Closed all network connections.")
|