bcirpggithubmirror/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd

36 lines
936 B
GDScript3
Raw Normal View History

Squashed commit of the following: commit db69386b6d2f12adf284b45a3f84111bbfeb2b0b Author: Andrew Tang <tandrew@gmail.com> Date: Mon Aug 1 02:48:32 2022 +0800 Test Lobby Working Server creation works and others are able to join by entering the creator's IP. Shows a list of player names (currently only shows player #) commit 3fbf2640da1a59e6bc5727b4b2748b72df59fefa Author: Andrew Tang <tandrew@gmail.com> Date: Mon Jul 25 02:29:27 2022 +0800 Test Multiplayer commit 59b74b946a090dd0b95e21814fe2ed7751b6e09b Author: Andrew Tang <tandrew@gmail.com> Date: Mon Jul 11 01:16:34 2022 +0800 Complete DiceRoller Singleton Version Created script: "DiceRoller.gd" to be the only dice script attached to a node and will act as a singleton. A single DieManager object is created in this script. The DieManager's values can be changed and methods can be called through the DiceRoller Script commit 3a402d43316599c1a883ab583583942dd7723d7b Author: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun Jul 3 13:05:28 2022 -0400 Delete .DS_Store commit c00b24c60ac3cc9a39a93b79cf3352241b1c9186 Author: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun Jul 3 13:05:16 2022 -0400 Delete .DS_Store commit 4f788de0c7676fec60624f50be6284b4f2e419ac Author: Andrew Tang <90939405+TangoDevelopments@users.noreply.github.com> Date: Sun Jul 3 13:05:05 2022 -0400 Delete .DS_Store commit c20fd855676052b135e7c99af9800af86ad81060 Author: Andrew Tang <tandrew@gmail.com> Date: Mon Jul 4 00:13:15 2022 +0800 Added D10 and easier die selection
2022-08-07 18:00:04 +00:00
extends Node
const DEFAULT_PORT = 28960
const MAX_CLIENTS = 6
var server = null
var client = null
var ip_address = ""
func _ready() -> void:
ip_address = IP.get_local_addresses()[3]
for ip in IP.get_local_addresses():
if ip.begins_with("192.168.") and not ip.ends_with(".1"):
ip_address = ip
get_tree().connect("connected_to_server", self, "_connected_to_server")
get_tree().connect("server_disconnected", self, "_server_disconnected")
func _create_server() -> void:
server = NetworkedMultiplayerENet.new()
server.create_server(DEFAULT_PORT, MAX_CLIENTS)
get_tree().set_network_peer(server)
func _join_server() -> void:
client = NetworkedMultiplayerENet.new()
client.create_client(ip_address, DEFAULT_PORT)
get_tree().set_network_peer(client)
func _connected_to_server() -> void:
print("Successfully connected to the server")
func _server_disconnected() -> void:
print("Disconnected from the server")