Embeeded configs of the game to server, made client ask it
This commit is contained in:
parent
c47d3da2cf
commit
46353fc8f6
|
@ -13,12 +13,14 @@ config_version=5
|
|||
config/name="Cs-os"
|
||||
run/main_scene="res://scenes/menu.tscn"
|
||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||
boot_splash/bg_color=Color(0.282353, 0.00784314, 0.0745098, 1)
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
Networking="*res://scripts/Networking.gd"
|
||||
GameData="*res://scripts/GameData.gd"
|
||||
Anticheat="*res://scripts/Anticheat.gd"
|
||||
|
||||
[input]
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
extends Node
|
|
@ -5,7 +5,7 @@ extends Button
|
|||
@onready var port_input: TextEdit = $"../Port"
|
||||
|
||||
func _ready():
|
||||
button.text = "Click me"
|
||||
button.text = "Connect"
|
||||
button.pressed.connect(self._button_pressed)
|
||||
|
||||
func _button_pressed():
|
||||
|
|
|
@ -4,8 +4,28 @@ var client_settings
|
|||
var server_settings
|
||||
|
||||
func _ready():
|
||||
var client_settings_file = FileAccess.open("res://settings/client-settings.json", FileAccess.READ)
|
||||
var user_dir = DirAccess.open(".")
|
||||
if(!user_dir.dir_exists("./settings")):
|
||||
user_dir.make_dir("settings")
|
||||
var client_settings_file
|
||||
|
||||
if(!FileAccess.file_exists("./settings/client-settings.json")):
|
||||
print("Client-settings doesn't exist, creating one")
|
||||
var example = FileAccess.open("res://settings/client-settings.json", FileAccess.READ)
|
||||
client_settings_file = FileAccess.open("./settings/client-settings.json", FileAccess.WRITE_READ)
|
||||
client_settings_file.store_buffer(example.get_as_text())
|
||||
else:
|
||||
client_settings_file = FileAccess.open("./settings/client-settings.json", FileAccess.READ)
|
||||
client_settings = JSON.parse_string(client_settings_file.get_as_text())
|
||||
var server_settings_file = FileAccess.open("res://settings/server-settings.json", FileAccess.READ)
|
||||
|
||||
|
||||
var server_settings_file
|
||||
if(!FileAccess.file_exists("./settings/server-settings.json")):
|
||||
print("Server-settings doesn't exist, creating one")
|
||||
var example = FileAccess.open("res://settings/server-settings.json", FileAccess.READ)
|
||||
server_settings_file = FileAccess.open("./settings/server-settings.json", FileAccess.WRITE_READ)
|
||||
server_settings_file.store_string(example.get_as_text())
|
||||
else:
|
||||
server_settings_file = FileAccess.open("./settings/server-settings.json", FileAccess.READ)
|
||||
server_settings = JSON.parse_string(server_settings_file.get_as_text())
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extends Node
|
||||
|
||||
const player_script := preload("res://scripts/Player.gd")
|
||||
#var player_script := load("res://scripts/Player.gd")
|
||||
var player_script := preload("res://scripts/Player.gd")
|
||||
|
||||
var player_model = preload("res://models/player.tscn")
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
|
@ -76,6 +77,9 @@ func move_client(client_id, position):
|
|||
var internal_id = client["internal_id"]
|
||||
client["position"] = position
|
||||
send_everyone_except(client_id, [get_node("player" + str(internal_id)).find_child("CharacterBody3D").move_puppet, position, internal_id])
|
||||
#send_everyone_except(client_id, [get_node("player" + str(internal_id)).find_child("CharacterBody3D").move_puppet, position, internal_id])
|
||||
#send_everyone_except(client_id, ["move_puppet", position, internal_id])
|
||||
#send_everyone_except(client_id, [player_script.move_puppet, position, internal_id])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
func get_client_list(client_id):
|
||||
|
@ -83,6 +87,11 @@ func get_client_list(client_id):
|
|||
if (current_client_id == str(client_id)): continue
|
||||
rpc_id(client_id, "spawn_puppet", clients[str(current_client_id)]["internal_id"])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
func get_server_settings(client_id):
|
||||
var client = clients[str(client_id)]
|
||||
var internal_id = client["internal_id"]
|
||||
get_node("player" + str(internal_id)).find_child("CharacterBody3D").set_game_settings.rpc_id(int(client_id), settings["game"])
|
||||
##########################################CLIENT#######################
|
||||
|
||||
var player
|
||||
|
@ -124,9 +133,11 @@ func _Connection_Succseeded():
|
|||
|
||||
rpc_id(1, "get_character_properties", multiplayer.get_unique_id())
|
||||
rpc_id(1, "get_client_list", multiplayer.get_unique_id())
|
||||
await get_tree().create_timer(0.2).timeout # костыль
|
||||
|
||||
get_tree().change_scene_to_file("res://scenes/test_map.tscn")
|
||||
await get_tree().create_timer(0.2).timeout # костыль
|
||||
|
||||
rpc_id(1, "get_server_settings", multiplayer.get_unique_id())
|
||||
|
||||
var player_node = player_model.instantiate()
|
||||
player_node.find_child("CharacterBody3D").set_is_playable(true)
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
const WALK_VELOCITY = 12.0
|
||||
const RUN_VELOCITY = 24.0
|
||||
const JUMP_VELOCITY = 12.0
|
||||
const SENSETIVITY = 0.009;
|
||||
|
||||
enum Class_type {
|
||||
|
@ -28,8 +25,14 @@ var properties = {
|
|||
internal_id = 0
|
||||
}
|
||||
|
||||
var speed = WALK_VELOCITY
|
||||
var gravity = 9.8
|
||||
var speed = 0
|
||||
var walk = 0
|
||||
var run = 0
|
||||
var jump = 0
|
||||
var gravity = 0
|
||||
var game_settings
|
||||
var client_settings
|
||||
|
||||
@onready var head = $Head
|
||||
@onready var camera = $Head/Camera
|
||||
@onready var playerCharacterBody = $"."
|
||||
|
@ -59,7 +62,8 @@ func _unhandled_input(event):
|
|||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60))
|
||||
|
||||
func _physics_process(delta):
|
||||
if (!properties["is_playable"]): return
|
||||
if (!properties["is_playable"]): return
|
||||
if (game_settings == null): return
|
||||
if not is_on_floor():
|
||||
velocity.y -= 4 * gravity * delta
|
||||
|
||||
|
@ -68,11 +72,11 @@ func _physics_process(delta):
|
|||
|
||||
if is_on_floor():
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
velocity.y = JUMP_VELOCITY
|
||||
velocity.y = jump
|
||||
if Input.is_action_pressed("run"):
|
||||
speed = RUN_VELOCITY
|
||||
speed = run
|
||||
else:
|
||||
speed = WALK_VELOCITY
|
||||
speed = walk
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
|
@ -91,3 +95,13 @@ func _physics_process(delta):
|
|||
func move_puppet(p: Vector3, i_id):
|
||||
if (i_id == properties["internal_id"]):
|
||||
playerCharacterBody.position = p
|
||||
|
||||
@rpc ("authority", "call_remote", "reliable")
|
||||
func set_game_settings(s):
|
||||
if(!properties["is_playable"]): return
|
||||
print("Got settings from server: " + str(s))
|
||||
game_settings = s
|
||||
gravity = game_settings["moving"]["gravity"]
|
||||
walk = game_settings["moving"]["walk"]
|
||||
run = game_settings["moving"]["run"]
|
||||
jump = game_settings["moving"]["jump"]
|
||||
|
|
|
@ -2,4 +2,12 @@
|
|||
"port": 2390,
|
||||
"maxclients": 10,
|
||||
"enableAntiCheat": false,
|
||||
"game": {
|
||||
"moving": {
|
||||
"walk": 12,
|
||||
"run": 24,
|
||||
"gravity": 2,
|
||||
"jump": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue