1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
extends Node2D
var client : NetworkedMultiplayerENet
var server
var world
var local_server_tree = null
var start_server = false
func _ready():
#PROCESS ARGS
var arguments = {}
for argument in OS.get_cmdline_args():
if argument.find("=") > -1:
var key_value = argument.split("=")
arguments[key_value[0].lstrip("--")] = key_value[1]
else:
# Options without an argument will be present in the dictionary,
# with the value set to an empty string.
arguments[argument.lstrip("--")] = ""
set_process(false)
set_physics_process(false)
if "server" in arguments:
start_server = true
print("Server starting in 0.5 seconds.")
yield(get_tree().create_timer(0.5), "timeout")
print("Server starting...")
server = preload("res://scenes/Server.tscn").instance()
#server.start_server($ServerName.text, $MOTD.text, $PlayerCount.value, $MapPath.text, $IP.text, $Port.value, get_tree(), console, "add_line")
server.start_server("Dedicated Server", "Dedicated Multiplayer Server", 3, "res://maps/Main.tscn", false, 25565, get_tree(), null, "print")
server.world.visible= false
get_tree().get_root().set_update_mode(Viewport.UPDATE_DISABLED)
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
call_deferred("queue_free")
return
#if regular game instance:
world = preload("res://scenes/GameBase.tscn").instance()
#get_tree().connect("network_peer_connected", self, "_player_connected")
#get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
var _discard = [get_tree().connect("connected_to_server", self, "_local_connection_successful"),
get_tree().connect("connection_failed", self, "_connected_fail"),
get_tree().connect("server_disconnected", world, "_connection_lost")]
func to_host_menu():
var host_menu = preload("res://ui/servermenu/ServerUI.tscn").instance()
get_tree().get_root().add_child(host_menu)
queue_free()
func to_join_menu():
var client_menu = preload("res://ui/clientmenu/ClientUI.tscn").instance()
get_tree().get_root().add_child(client_menu)
queue_free()
func run_local_server():
var server_script = preload("res://scenes/Server.tscn").instance()
#CHANGE LEVEL HERE
server_script.start_server("Local Server", "Local Singleplayer Server", 3, "res://maps/Main.tscn", true, 25565, get_tree(), null, "print")
queue_free()
func _local_connection_failed():
pass
func _local_connection_successful():
get_tree().get_root().add_child(world)
world.client = client
world.client_id = get_tree().get_network_unique_id()
world.player_name = "Player"
world.is_local = true
world.local_server_tree = local_server_tree
print("Connected to local server.")
queue_free()
func _process(delta):
local_server_tree.idle(delta)
func _physics_process(delta):
local_server_tree.iteration(delta)
func quit_game():
get_tree().quit()
|