Base multiplayer
This commit is contained in:
parent
4716048186
commit
b81f4cedff
|
@ -0,0 +1,59 @@
|
|||
[preset.0]
|
||||
|
||||
name="Linux"
|
||||
platform="Linux/X11"
|
||||
runnable=true
|
||||
dedicated_server=true
|
||||
custom_features=""
|
||||
export_filter="customized"
|
||||
customized_files={
|
||||
"res://": "strip",
|
||||
"res://icon.svg": "strip",
|
||||
"res://models/": "strip",
|
||||
"res://models/player.tscn": "strip",
|
||||
"res://models/puppet.gd": "strip",
|
||||
"res://models/puppet.tscn": "strip",
|
||||
"res://scenes/": "strip",
|
||||
"res://scenes/menu.tscn": "strip",
|
||||
"res://scenes/test_map.tscn": "strip",
|
||||
"res://scripts/": "strip",
|
||||
"res://scripts/ConnectButton.gd": "strip",
|
||||
"res://scripts/GameData.gd": "strip",
|
||||
"res://scripts/Networking.gd": "strip",
|
||||
"res://scripts/Player.gd": "strip",
|
||||
"res://scripts/PlayerClass.gd": "strip",
|
||||
"res://settings/": "strip",
|
||||
"res://textures/": "strip",
|
||||
"res://textures/texture_04_2.png": "strip"
|
||||
}
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="./Cs-os.x86_64"
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
encrypt_pck=false
|
||||
encrypt_directory=false
|
||||
|
||||
[preset.0.options]
|
||||
|
||||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
debug/export_console_wrapper=1
|
||||
binary_format/embed_pck=true
|
||||
texture_format/bptc=true
|
||||
texture_format/s3tc=true
|
||||
texture_format/etc=false
|
||||
texture_format/etc2=false
|
||||
binary_format/architecture="x86_64"
|
||||
ssh_remote_deploy/enabled=false
|
||||
ssh_remote_deploy/host="user@host_ip"
|
||||
ssh_remote_deploy/port="22"
|
||||
ssh_remote_deploy/extra_args_ssh=""
|
||||
ssh_remote_deploy/extra_args_scp=""
|
||||
ssh_remote_deploy/run_script="#!/usr/bin/env bash
|
||||
export DISPLAY=:0
|
||||
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
|
||||
\"{temp_dir}/{exe_name}\" {cmd_args}"
|
||||
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
|
||||
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
|
||||
rm -rf \"{temp_dir}\""
|
|
@ -0,0 +1 @@
|
|||
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>
|
After Width: | Height: | Size: 950 B |
|
@ -0,0 +1,37 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bxmfgknljdw65"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
|
@ -0,0 +1,24 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://b2jhgtduapovl"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Player.gd" id="1_o6o4b"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_yyp7b"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_jqfxo"]
|
||||
|
||||
[node name="player" type="Node3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.10113, 0)
|
||||
|
||||
[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
|
||||
script = ExtResource("1_o6o4b")
|
||||
|
||||
[node name="Head" type="Node3D" parent="CharacterBody3D"]
|
||||
|
||||
[node name="Camera" type="Camera3D" parent="CharacterBody3D/Head"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.675496, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
|
||||
shape = SubResource("CapsuleShape3D_yyp7b")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="CharacterBody3D"]
|
||||
mesh = SubResource("CapsuleMesh_jqfxo")
|
|
@ -0,0 +1,6 @@
|
|||
extends CharacterBody3D
|
||||
#
|
||||
#@rpc ("authority", "call_remote")
|
||||
#func move_puppet(v: Vector3):
|
||||
#var velocity = v
|
||||
#move_and_slide()
|
|
@ -0,0 +1,21 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://vj3v8qlchp0r"]
|
||||
|
||||
[ext_resource type="Script" path="res://models/puppet.gd" id="1_5nucb"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_yyp7b"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_jqfxo"]
|
||||
|
||||
[node name="puppet" type="Node3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.10113, 0)
|
||||
|
||||
[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
|
||||
script = ExtResource("1_5nucb")
|
||||
|
||||
[node name="Head" type="Node3D" parent="CharacterBody3D"]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
|
||||
shape = SubResource("CapsuleShape3D_yyp7b")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="CharacterBody3D"]
|
||||
mesh = SubResource("CapsuleMesh_jqfxo")
|
|
@ -0,0 +1,54 @@
|
|||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Cs-os"
|
||||
run/main_scene="res://scenes/menu.tscn"
|
||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
Networking="*res://scripts/Networking.gd"
|
||||
GameData="*res://scripts/GameData.gd"
|
||||
|
||||
[input]
|
||||
|
||||
forward={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
backward={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
left={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
right={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
jump={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
run={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cjlgs86ey1u1o"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ConnectButton.gd" id="1_oqnod"]
|
||||
|
||||
[node name="Menu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Connect" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 24.0
|
||||
offset_top = 584.0
|
||||
offset_right = 196.0
|
||||
offset_bottom = 634.0
|
||||
pivot_offset = Vector2(88, 24)
|
||||
text = "Connect"
|
||||
script = ExtResource("1_oqnod")
|
||||
|
||||
[node name="IP" type="TextEdit" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 25.0
|
||||
offset_top = 496.0
|
||||
offset_right = 194.0
|
||||
offset_bottom = 535.0
|
||||
text = "127.0.0.1"
|
||||
placeholder_text = "IP Address"
|
||||
|
||||
[node name="Port" type="TextEdit" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 24.0
|
||||
offset_top = 539.0
|
||||
offset_right = 195.0
|
||||
offset_bottom = 576.0
|
||||
text = "2390"
|
||||
placeholder_text = "Port"
|
|
@ -0,0 +1,90 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://d0tdlmmo1texv"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cs0ysba50acxp" path="res://textures/texture_04_2.png" id="1_rei8g"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_68arr"]
|
||||
albedo_texture = ExtResource("1_rei8g")
|
||||
|
||||
[node name="test_map" type="Node3D"]
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.83748, 0.546467, 0, -0.546467, 0.83748, 0, 94.6015, 141.501)
|
||||
|
||||
[node name="terrain" type="Node3D" parent="."]
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="terrain"]
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D2" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D3" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D4" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 0)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D5" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, -10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D6" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D7" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10, 0, -10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D8" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10, 0, 0)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D9" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10, 0, 10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D10" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 15, 5, -10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D11" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 15, 5, 0)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D12" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(8.9407e-08, 1, 0, -1, 8.9407e-08, 0, 0, 0, 1, 15, 5, 10)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.1, 10)
|
||||
|
||||
[node name="CSGBox3D13" type="CSGBox3D" parent="terrain"]
|
||||
transform = Transform3D(-1, 1.78814e-07, 0, -1.26441e-07, -0.707107, -0.707107, -1.26441e-07, -0.707107, 0.707107, 10, 14.3726, -29.4839)
|
||||
material_override = SubResource("StandardMaterial3D_68arr")
|
||||
use_collision = true
|
||||
size = Vector3(10, 0.09425, 57.5945)
|
|
@ -0,0 +1,16 @@
|
|||
extends Button
|
||||
|
||||
@onready var button = $"."
|
||||
@onready var ip_input: TextEdit = $"../IP"
|
||||
@onready var port_input: TextEdit = $"../Port"
|
||||
|
||||
func _ready():
|
||||
button.text = "Click me"
|
||||
button.pressed.connect(self._button_pressed)
|
||||
|
||||
func _button_pressed():
|
||||
var ip = ip_input.text
|
||||
var port = port_input.text
|
||||
print("Trying to connect to " + ip + ":" + port)
|
||||
Networking.ConnectToServer(str(ip), int(port))
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
var client_settings
|
||||
var server_settings
|
||||
|
||||
func _ready():
|
||||
var client_settings_file = FileAccess.open("res://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)
|
||||
server_settings = JSON.parse_string(server_settings_file.get_as_text())
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
extends Node
|
||||
|
||||
enum Class_type {
|
||||
Spectator = 0,
|
||||
Astra = 1,
|
||||
BlackArch = 2,
|
||||
Kali = 3,
|
||||
Debian = 4,
|
||||
Arch = 5,
|
||||
Windows11 = -1,
|
||||
WindowsServer = -2,
|
||||
MacOS = -3,
|
||||
WindowsXP = -4,
|
||||
Windows10 = -5
|
||||
}
|
||||
|
||||
var Distro = {
|
||||
HP = 100,
|
||||
AP = 100,
|
||||
HACK = 1.0,
|
||||
class_type = 0,
|
||||
}
|
||||
var Player = {
|
||||
distro = Distro.duplicate(),
|
||||
speed = 1.0,
|
||||
position = Vector3(0, 10, 0),
|
||||
velocity = Vector3.ZERO,
|
||||
internal_id = 0,
|
||||
}
|
||||
|
||||
const player_class := preload("res://scripts/PlayerClass.gd")
|
||||
|
||||
var player_model = preload("res://models/player.tscn")
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
var settings
|
||||
var clients = {}
|
||||
|
||||
func _ready():
|
||||
if "--server" in OS.get_cmdline_args():
|
||||
await get_tree().create_timer(0.01).timeout #костыль пиздец но мне похую как-то
|
||||
get_tree().change_scene_to_file("res://scenes/test_map.tscn")
|
||||
StartServer()
|
||||
|
||||
#######################################SERVER####################################
|
||||
func StartServer():
|
||||
settings = GameData.server_settings
|
||||
var port = int(settings["port"])
|
||||
var maxclients = int(settings["maxclients"])
|
||||
if (peer.create_server(port, maxclients) != OK):
|
||||
print("Couldn't create server. Check if another proccess binds port " + str(port))
|
||||
return
|
||||
|
||||
multiplayer.multiplayer_peer = peer
|
||||
print("Server started")
|
||||
|
||||
peer.connect("peer_connected", _Peer_Connected)
|
||||
peer.connect("peer_disconnected", _Peer_Disconnected)
|
||||
|
||||
func send_everyone_except(client_id, args):
|
||||
for current_client_id in clients.keys():
|
||||
if (str(current_client_id) == str(client_id)): continue
|
||||
if (args[1] == null): args[0].rpc_id(int(current_client_id))
|
||||
elif (args[2] == null): args[0].rpc_id(int(current_client_id), args[1])
|
||||
else: args[0].rpc_id(int(current_client_id), args[1], args[2])
|
||||
|
||||
func _Peer_Connected(client_id):
|
||||
var puppet = player_model.instantiate()
|
||||
var internal_id = clients.size() + 2
|
||||
puppet.find_child("CharacterBody3D").set_is_playable(false)
|
||||
puppet.find_child("CharacterBody3D").set_internal_id(internal_id)
|
||||
puppet.name = "player" + str(internal_id)
|
||||
|
||||
clients[str(client_id)] = Player.duplicate()
|
||||
clients[str(client_id)]["internal_id"] = internal_id
|
||||
|
||||
add_child(puppet)
|
||||
|
||||
for current_client_id in clients.keys():
|
||||
if (int(current_client_id) == int(client_id)): continue
|
||||
rpc_id(int(current_client_id), "spawn_puppet", internal_id)
|
||||
|
||||
func _Peer_Disconnected(client_id):
|
||||
clients.erase(str(client_id))
|
||||
|
||||
@rpc ("any_peer", "reliable", "call_remote")
|
||||
func get_character_properties(client_id):
|
||||
if !clients.has(str(client_id)):
|
||||
return
|
||||
var to_send = clients[str(client_id)]
|
||||
rpc_id(client_id, "set_character_properties", to_send)
|
||||
|
||||
@rpc("any_peer", "call_remote")
|
||||
func move_client(client_id, position):
|
||||
#if(settings["enableAntiCheat"]): if(position > 10): return # нормально допилить надо
|
||||
clients[str(client_id)]["position"] = position
|
||||
var client = clients[str(client_id)]
|
||||
send_everyone_except(client_id, [get_node("player" + str(client["internal_id"])).find_child("CharacterBody3D").move_puppet, position, client["internal_id"]])
|
||||
|
||||
@rpc ("any_peer", "call_remote", "reliable")
|
||||
func get_client_list(client_id):
|
||||
for current_client_id in clients.keys():
|
||||
if (current_client_id == str(client_id)): continue
|
||||
rpc_id(client_id, "spawn_puppet", clients[str(current_client_id)]["internal_id"])
|
||||
|
||||
##########################################CLIENT#######################
|
||||
|
||||
var player
|
||||
|
||||
@rpc ("reliable", "call_remote")
|
||||
func set_character_properties(p):
|
||||
player = p
|
||||
|
||||
@rpc("authority", "reliable", "call_remote")
|
||||
func spawn_puppet(internal_id):
|
||||
var puppet = player_model.instantiate()
|
||||
puppet.find_child("CharacterBody3D").set_is_playable(false)
|
||||
puppet.find_child("CharacterBody3D").set_internal_id(internal_id)
|
||||
puppet.name = "player" + str(internal_id)
|
||||
|
||||
add_child(puppet)
|
||||
|
||||
func ConnectToServer(ip, port):
|
||||
peer.create_client(ip, port)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
if not multiplayer.connected_to_server.is_connected(_Connection_Succseeded):
|
||||
multiplayer.connected_to_server.connect(_Connection_Succseeded)
|
||||
if not multiplayer.connection_failed.is_connected(_Connection_Failed):
|
||||
multiplayer.connection_failed.connect(_Connection_Failed)
|
||||
if not multiplayer.server_disconnected.is_connected(_Server_Disconnected):
|
||||
multiplayer.server_disconnected.connect(_Server_Disconnected)
|
||||
|
||||
func _Connection_Failed():
|
||||
print("Failed to connect to server")
|
||||
peer = ENetMultiplayerPeer.new()
|
||||
multiplayer.multiplayer_peer = null
|
||||
|
||||
func _Connection_Succseeded():
|
||||
print("Succsessfully connected to the server")
|
||||
|
||||
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")
|
||||
|
||||
var player_node = player_model.instantiate()
|
||||
player_node.find_child("CharacterBody3D").set_is_playable(true)
|
||||
player_node.find_child("CharacterBody3D").set_internal_id(player["internal_id"])
|
||||
add_child(player_node)
|
||||
|
||||
func _Server_Disconnected():
|
||||
print("Server has disconnected")
|
|
@ -0,0 +1,71 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
const WALK_VELOCITY = 12.0
|
||||
const RUN_VELOCITY = 24.0
|
||||
const JUMP_VELOCITY = 12.0
|
||||
const SENSETIVITY = 0.009;
|
||||
|
||||
var gravity = 9.8
|
||||
var speed = WALK_VELOCITY
|
||||
@onready var head = $Head
|
||||
@onready var camera = $Head/Camera
|
||||
@onready var playerCharacterBody = $"."
|
||||
var is_playable = false
|
||||
var internal_id
|
||||
|
||||
func set_internal_id(id):
|
||||
internal_id = id
|
||||
|
||||
func set_is_playable(value):
|
||||
is_playable = value
|
||||
|
||||
func test(text):
|
||||
print(text)
|
||||
|
||||
func _ready():
|
||||
if (!is_playable): return
|
||||
camera.make_current()
|
||||
playerCharacterBody.up_direction = Vector3.UP;
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _unhandled_input(event):
|
||||
if (!is_playable): return
|
||||
if event is InputEventMouseMotion:
|
||||
head.rotate_y(-event.relative.x * SENSETIVITY)
|
||||
camera.rotate_x(-event.relative.y * SENSETIVITY)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60))
|
||||
|
||||
func _physics_process(delta):
|
||||
if (!is_playable): return
|
||||
if not is_on_floor():
|
||||
velocity.y -= 4 * gravity * delta
|
||||
|
||||
var input_dir = Input.get_vector("left", "right", "forward", "backward")
|
||||
var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
if is_on_floor():
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
velocity.y = JUMP_VELOCITY
|
||||
if Input.is_action_pressed("run"):
|
||||
speed = RUN_VELOCITY
|
||||
else:
|
||||
speed = WALK_VELOCITY
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 8)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 8)
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta)
|
||||
move_and_slide()
|
||||
if (!multiplayer.is_server()):
|
||||
Networking.move_client.rpc_id(1, multiplayer.get_unique_id(), $".".position)
|
||||
print("I am " + $"..".name +", belonging of " + str(multiplayer.get_unique_id()) + ", with internal ID: " + str(internal_id))
|
||||
|
||||
@rpc ("authority", "call_remote")
|
||||
func move_puppet(p: Vector3, i_id):
|
||||
if (i_id == internal_id):
|
||||
playerCharacterBody.position = p
|
|
@ -0,0 +1,25 @@
|
|||
enum Class_type {
|
||||
Spectator = 0,
|
||||
Astra = 1,
|
||||
BlackArch = 2,
|
||||
Kali = 3,
|
||||
Debian = 4,
|
||||
Arch = 5,
|
||||
Windows11 = -1,
|
||||
WindowsServer = -2,
|
||||
MacOS = -3,
|
||||
WindowsXP = -4,
|
||||
Windows10 = -5
|
||||
}
|
||||
|
||||
var Distro = {
|
||||
HP = 100,
|
||||
AP = 100,
|
||||
HACK = 1.0,
|
||||
class_type = 0,
|
||||
}
|
||||
var Player = {
|
||||
distro = Distro,
|
||||
speed = 1.0,
|
||||
position = Vector3(0, 10, 0)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"port": 2390,
|
||||
"maxclients": 10,
|
||||
"enableAntiCheat": false,
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
|
@ -0,0 +1,35 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cs0ysba50acxp"
|
||||
path.s3tc="res://.godot/imported/texture_04_2.png-b107066fb6487ebd3c651f32c491c785.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://textures/texture_04_2.png"
|
||||
dest_files=["res://.godot/imported/texture_04_2.png-b107066fb6487ebd3c651f32c491c785.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
Loading…
Reference in New Issue