Skip to main content

Joining and Leaving a Server

Currently, the game can only be joined on a dedicated server. This server needs to be built with a separate build template, which currently only runs on linux. A dedicated server uses the "dedicated_server" feature, which allows for queries to determine whether a function or section of a function should be run.

Spawning and Despawning Players

When the server is started, the presence of the dedicated_server feature is queried to connect the spawn_player and remove_player functions, such that only the server can spawn and despawn players.

The spawn_player function instatiates a new player scene, calls the pre_ready function, adds the node to the scene tree, and finally calls the post_ready function on the new player.

The pre_ready function sets the name of the node to the peer_id of the joined player, and calls the initialization of the BaseUnit class, from which player scenes inherit. This initialization initializes stats and the available spells in the spell container.

When the scene is added to the scene tree, _enter_tree is called. This function sets the multiplayer authority of the player_input node within the player scene. This has to be done at this stage, as otherwise the game crashes, or the authority is not properly set.

After the scene is fully loaded into the scene tree, the post_ready function is called. This function adds a camera for the player scene via rpc from the server to the peer controlling this player scene. The camera orientation is used in the player_input script to generate the direction vector that is then synced to the server and to peers. As the resulting direction is synced, the camera orientation does not have to be synced, and therefore the camera scene only has to exist locally. Finally, the processing of the player_input node is enabled by an rpc from the server to the controlling peer.

Note: Movement is processed by the server and all peers to reduce lag. However, the position and orientation of all players is synced from the server to enforce consistency, and any checks that involve position and orientation are done by the server.

When a player disconnects, the corresponding player scene in the scene tree is freed.

 

Combat

 

Interactbales