Open Shadowblitz16 opened 3 years ago
This should be doable in GDScript.
Add this script as an Autoload.
# autoload.gd
signal network_self_connected()
func create_server():
# initialize server
emit_signal("network_self_connected")
In the function where you would setup the server call:
Autoload.create_server()
where you initialize your game use:
func _read():
Autoload.connect("network_self_connected", self, "self_connected")
Does this solution fits your needs?
@Faless how would disconnection be handled?
@Shadowblitz16 pretty much the same way:
# autoload.gd
signal network_self_disconnected()
func stop_server():
# stop server
multiplayer.network_peer = null
emit_signal("network_self_disconnected")
@Faless the issue is I have to rely on calling these functions. if the server or client fails or doesn't connect it needs to be taken in account.
@Shadowblitz16 if the client connection fails (or disconnect), either connection_failed
or network_peer_disconnected
are emitted. https://docs.godotengine.org/en/stable/classes/class_scenetree.html#signals
I don't see how the server can fail after being started (it can fail if the port is busy during start, but you will get an Error so you can easily manage that)
Describe the project you are working on: NetworkingTest
Describe the problem or limitation you are having in your project: I find it difficult to initialize the server due to the fact that I have to put my server initialization code right after i create the server.
I actually have multiple places I need to initialize the server and.
Describe the feature / enhancement and how it helps to overcome the problem or limitation: Add a NetworkSelfConnected and NetworkSelfDisconnected signal to tree.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: Basically it would trigger on the server when the server is created or closed or on a client when the client is connected to the server or disconnected from the server.
If this enhancement will not be used often, can it be worked around with a few lines of script?: It would be used to setup things in other nodes that don't have networking code and while it can be by creating your own signals it may not be very clear on where to do so.
Is there a reason why this should be core and not an add-on in the asset library?: It compliments the peer functions and makes it easy to initialize things when on the server or client when connected or disconnected.
Note I know the server doesn't connect to itself or disconnect from itself but the idea and code that would be used in these signals would be the same.