From d34c96aa69d2aee1aaa3bb12366b36ff22d674c0 Mon Sep 17 00:00:00 2001 From: Anson Bridges Date: Thu, 20 Oct 2022 13:54:06 -0400 Subject: network work work work --- godot/scripts/Server.gd | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'godot/scripts/Server.gd') diff --git a/godot/scripts/Server.gd b/godot/scripts/Server.gd index b4ab995..498c5d8 100644 --- a/godot/scripts/Server.gd +++ b/godot/scripts/Server.gd @@ -25,7 +25,7 @@ func _ready(): if sig != OK: print("SERVER: Error connecting one or more signals. Error code: " + str(sig)) -func start_server(_server_name: String, _motd: String, max_players: int, map_path: String, _ip: String, port: int, tree, output_obj, output_f): +func start_server(_server_name: String, _motd: String, max_players: int, map_path: String, is_local: bool, port: int, tree, output_obj, output_f): output = output_obj output_func = output_f server_name = _server_name @@ -48,6 +48,11 @@ func start_server(_server_name: String, _motd: String, max_players: int, map_pat return world.add_child(self) + world.client_id = 1 + world.is_host = true + world.is_local = is_local + if is_local: + connected_players[1] = ["Player", -1] tree.get_root().add_child(world) world.client_id = 1 @@ -73,9 +78,9 @@ func _client_disconnect(id): func _client_connect(id): print_line("Client (ID: "+str(id)+") connecting...") connected_player_count += 1 - connected_players[id] = ["", "SPEC"] #Placeholder for name + connected_players[id] = ["", -1] #Placeholder for name - var server_info = {"player_count" : connected_player_count, "server_name" : server_name, "MOTD" : motd, "cam_pos" : world.get_node("DEFAULTCAM").transform} + var server_info = {"player_count" : connected_player_count, "server_name" : server_name, "MOTD" : motd, "cam_pos" : world.get_node("DEFAULTCAM").transform, "teams" : {0 : "RED", 1 : "BLUE"}} world.rpc_id(id, "set_up_server_info", server_info) var geo_info = [] @@ -91,11 +96,11 @@ func _client_connect(id): func _client_connection_confirmed(arguments): print_line("Client (ID: "+str(arguments["id"])+") connected as " +arguments["username"] +".") - connected_players[arguments["id"]] = [arguments["username"], "SPEC"] + connected_players[arguments["id"]] = [arguments["username"], -1] world.rpc("update_players_info", connected_players) func _client_change_teams(arguments): - print_line(connected_players[arguments["id"]][PLAYER_NAME] + " ("+ str(arguments["id"]) +") changed to team " + arguments["team"]) + print_line(connected_players[arguments["id"]][PLAYER_NAME] + " ("+ str(arguments["id"]) +") changed to team " + str(arguments["team"])) connected_players[arguments["id"]][PLAYER_TEAM] = arguments["team"] world.rpc("update_players_info", connected_players) @@ -106,7 +111,7 @@ func _client_request_change_character(arguments): dest.rpc("set_net_owner", arguments["id"]) if arguments["current_char_name"] != "NULL": var old = world.get_node("PLAYERS/"+arguments["current_char_name"]) - old.rpc("set_net_owner", int(1)) + old.rpc("set_net_owner", int(1), true) func _client_request_control_vehicle(arguments): var dest_machine = world.get_node(arguments["machine_path"]) -- cgit v1.2.3