Skip to content

Networking Global

likeich edited this page Feb 15, 2021 · 6 revisions

Description

Methods

Return Type Method Name and Parameters
bool is_server
void register_player_data(data: Dictionary)
String get_local_ip
void start_server(port: int = DEFAULT_PORT, max_players: int = MAX_PLAYERS, net_type: NETWORK_TYPES = NETWORK_TYPES.PEER_TO_PEER)
void start_client(address: String = "127.0.0.1", port: int = DEFAULT_PORT, net_type: NETWORK_TYPES = NETWORK_TYPES.PEER_TO_PEER)
void exit
array create_players(player_object: PackedScene, their_parent: Node)
void show_debug
void start_game(scene_path: String)

Signals

  • player_list_changed(player_list: Array)

Emitted when the player id list changes. It supplies the player id list in the signal.


  • player_data_changed

Emitted when the custom player data dictionary is changed.


  • connection_succeeded

Emitted on a client when it is successfully connected to a server.


  • connection_failed

Emitted when a connection to a server failed.


  • disconnected

Emitted on a client when disconnected from a server.


  • global_ip_found

The Networking global uses an online API to find the global ip address of the player. This signal is emitted when the global ip address has been received.

Method Descriptions

  • bool is_server(data: Dictionary)

Returns true if the caller is the server for the network.


  • void register_player_data(data: Dictionary)

A remotesync function that registers player data on the server and all clients. It also emits the "player_data_changed" signal. An example can be found in the example lobby.


  • String get_local_ip

Returns the ip address of the OS tha starts with 192 or "" if it does not exist. This does not work on all machines.


  • void start_server(port: int = DEFAULT_PORT, max_players: int = MAX_PLAYERS, net_type: NETWORK_TYPES = NETWORK_TYPES.PEER_TO_PEER)

Creates a server using the parameters received or the default values in the global. Adds the server to the player_id list.


  • void start_client(address: String = "127.0.0.1", port: int = DEFAULT_PORT, net_type: NETWORK_TYPES = NETWORK_TYPES.PEER_TO_PEER)

Creates a networking client at the received address and port, or the defaults if not sent. The net_type must be the same as the server you are attempting to join.


  • void exit

Closes any network connections that are open and clears the player_ids and custom_player_data variables.


  • array create_players(player_object: PackedScene, their_parent: Node)

Receives a player PackedScene and creates player objects using all of the active player ids. The network master is set to every player id and the objects are named after the corresponding id. Players are added as a child of the their_parent node. Returns the list of players that were made to allow for custom additions.


  • void show_debug

Shows the networking debug overlay that gives useful information for networking purposes.


  • void start_game(scene_path: String)

A remotesync function that changes the current scene to the String path specified for the server and all clients.

Clone this wiki locally