Skip to content

Commit 18fcf8d

Browse files
committed
Initial commit
0 parents  commit 18fcf8d

17 files changed

Lines changed: 616 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
Client/.godot/
3+
Client/icon.svg.import
4+
5+
Server/.idea

Builds/Client.exe

78.7 MB
Binary file not shown.

Builds/Server.exe

7.54 MB
Binary file not shown.

Client/export_presets.cfg

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[preset.0]
2+
3+
name="Windows Desktop"
4+
platform="Windows Desktop"
5+
runnable=true
6+
advanced_options=true
7+
dedicated_server=false
8+
custom_features=""
9+
export_filter="all_resources"
10+
include_filter=""
11+
exclude_filter=""
12+
export_path="../Builds/Client.exe"
13+
patches=PackedStringArray()
14+
encryption_include_filters=""
15+
encryption_exclude_filters=""
16+
encrypt_pck=false
17+
encrypt_directory=false
18+
script_export_mode=1
19+
20+
[preset.0.options]
21+
22+
custom_template/debug=""
23+
custom_template/release=""
24+
debug/export_console_wrapper=1
25+
binary_format/embed_pck=true
26+
texture_format/s3tc_bptc=true
27+
texture_format/etc2_astc=false
28+
binary_format/architecture="x86_64"
29+
codesign/enable=false
30+
codesign/timestamp=true
31+
codesign/timestamp_server_url=""
32+
codesign/digest_algorithm=1
33+
codesign/description=""
34+
codesign/custom_options=PackedStringArray()
35+
application/modify_resources=false
36+
application/icon=""
37+
application/console_wrapper_icon=""
38+
application/icon_interpolation=4
39+
application/file_version=""
40+
application/product_version=""
41+
application/company_name=""
42+
application/product_name=""
43+
application/file_description=""
44+
application/copyright=""
45+
application/trademarks=""
46+
application/export_angle=0
47+
application/export_d3d12=0
48+
application/d3d12_agility_sdk_multiarch=true
49+
ssh_remote_deploy/enabled=false
50+
ssh_remote_deploy/host="user@host_ip"
51+
ssh_remote_deploy/port="22"
52+
ssh_remote_deploy/extra_args_ssh=""
53+
ssh_remote_deploy/extra_args_scp=""
54+
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
55+
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
56+
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
57+
$settings = New-ScheduledTaskSettingsSet
58+
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
59+
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
60+
Start-ScheduledTask -TaskName godot_remote_debug
61+
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
62+
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
63+
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
64+
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
65+
Remove-Item -Recurse -Force '{temp_dir}'"

Client/icon.svg

Lines changed: 1 addition & 0 deletions
Loading

Client/project.godot

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=5
10+
11+
[application]
12+
13+
config/name="ClientWebSocket"
14+
run/main_scene="res://scene/main.tscn"
15+
config/features=PackedStringArray("4.4", "Forward Plus")
16+
config/icon="res://icon.svg"

Client/scene/login.tscn

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://w6q1covoc7xy"]
2+
3+
[ext_resource type="Script" path="res://script/login.gd" id="1_mc475"]
4+
5+
[node name="Control" type="Control"]
6+
layout_mode = 3
7+
anchor_right = 1.0
8+
anchor_bottom = 1.0
9+
offset_left = 576.0
10+
offset_top = 324.0
11+
offset_right = -576.0
12+
offset_bottom = -324.0
13+
grow_horizontal = 2
14+
grow_vertical = 2
15+
script = ExtResource("1_mc475")
16+
17+
[node name="Connect" type="Button" parent="."]
18+
layout_mode = 0
19+
offset_left = -80.0
20+
offset_top = -44.0
21+
offset_right = 80.0
22+
offset_bottom = -8.0
23+
text = "Connect ..."
24+
25+
[node name="Address" type="LineEdit" parent="."]
26+
layout_mode = 0
27+
offset_left = -160.0
28+
offset_top = -132.0
29+
offset_right = 24.0
30+
offset_bottom = -101.0
31+
placeholder_text = "Enter IP address ..."
32+
33+
[node name="Port" type="LineEdit" parent="."]
34+
layout_mode = 0
35+
offset_left = 40.0
36+
offset_top = -132.0
37+
offset_right = 144.0
38+
offset_bottom = -101.0
39+
placeholder_text = "Enter Port ..."
40+
41+
[connection signal="pressed" from="Connect" to="." method="_on_connect_pressed"]

Client/scene/main.tscn

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://bhwe2xl6qgluv"]
2+
3+
[ext_resource type="Script" path="res://script/main.gd" id="1_itxqv"]
4+
5+
[sub_resource type="SystemFont" id="SystemFont_itxqv"]
6+
font_names = PackedStringArray("Comic Sans MS")
7+
8+
[sub_resource type="Theme" id="Theme_v0l8b"]
9+
default_font = SubResource("SystemFont_itxqv")
10+
11+
[node name="Control" type="Control"]
12+
layout_mode = 3
13+
anchors_preset = 15
14+
anchor_right = 1.0
15+
anchor_bottom = 1.0
16+
grow_horizontal = 2
17+
grow_vertical = 2
18+
script = ExtResource("1_itxqv")
19+
20+
[node name="Username" type="LineEdit" parent="."]
21+
layout_mode = 0
22+
offset_left = 24.0
23+
offset_top = 576.0
24+
offset_right = 192.0
25+
offset_bottom = 607.0
26+
placeholder_text = "Username"
27+
max_length = 20
28+
caret_blink = true
29+
30+
[node name="Message" type="LineEdit" parent="."]
31+
layout_mode = 0
32+
offset_left = 240.0
33+
offset_top = 576.0
34+
offset_right = 1056.0
35+
offset_bottom = 607.0
36+
placeholder_text = "Write a message..."
37+
editable = false
38+
clear_button_enabled = true
39+
caret_blink = true
40+
41+
[node name="Quit" type="Button" parent="."]
42+
layout_mode = 0
43+
offset_left = 1088.0
44+
offset_top = 24.0
45+
offset_right = 1136.0
46+
offset_bottom = 56.0
47+
text = "Quit"
48+
49+
[node name="BG" type="ItemList" parent="."]
50+
clip_contents = false
51+
layout_mode = 0
52+
offset_left = 240.0
53+
offset_top = 24.0
54+
offset_right = 1056.0
55+
offset_bottom = 552.0
56+
allow_search = false
57+
same_column_width = true
58+
59+
[node name="Chat" type="RichTextLabel" parent="BG"]
60+
layout_mode = 0
61+
offset_left = 8.0
62+
offset_top = 8.0
63+
offset_right = 808.0
64+
offset_bottom = 528.0
65+
focus_mode = 2
66+
theme = SubResource("Theme_v0l8b")
67+
bbcode_enabled = true
68+
scroll_following = true
69+
context_menu_enabled = true
70+
threaded = true
71+
selection_enabled = true
72+
73+
[connection signal="text_submitted" from="Username" to="." method="_on_username_text_submitted"]
74+
[connection signal="text_submitted" from="Message" to="." method="_on_message_text_submitted"]
75+
[connection signal="pressed" from="Quit" to="." method="_on_button_pressed"]

Client/script/login.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extends Control
2+
3+
4+
func _on_connect_pressed() -> void:
5+
var address = $Address.text
6+
var port = $Port.text
7+
8+
if address and port:
9+
var chat = preload("res://scene/main.tscn").instantiate()
10+
chat.address = "ws://%s:%s/ws"% [address, port]
11+
get_tree().get_root().add_child(chat)
12+
hide()
13+
queue_free()

Client/script/main.gd

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
extends Control
2+
3+
var address:String
4+
var ws:WebSocketPeer
5+
var username_set = false
6+
7+
8+
func _ready() -> void:
9+
$Username.cancel_ime()
10+
$Message.cancel_ime()
11+
12+
ws = WebSocketPeer.new()
13+
var err = FAILED
14+
while err != OK:
15+
err = ws.connect_to_url(address)
16+
17+
18+
func _process(_delta: float) -> void:
19+
if ws == null:
20+
return
21+
22+
ws.poll()
23+
24+
match ws.get_ready_state():
25+
ws.STATE_OPEN:
26+
processMessages()
27+
ws.STATE_CLOSED:
28+
print("Connexion lost, trying reconnexion...")
29+
reconnexion()
30+
31+
32+
func processMessages():
33+
while ws.get_available_packet_count() > 0:
34+
var raw_message = ws.get_packet().get_string_from_utf8()
35+
var parsed_message = parseReceivedMessage(raw_message)
36+
addMessage(parsed_message.keys()[0], parsed_message.values()[0])
37+
38+
39+
func reconnexion():
40+
await get_tree().create_timer(2.0).timeout
41+
ws.connect_to_url(address)
42+
43+
44+
func randomName() -> String:
45+
return "User" + str(randi() % 10000)
46+
47+
48+
func parseReceivedMessage(received_message:String)-> Dictionary[String, String]:
49+
var parts = received_message.split(": ", true, 1)
50+
var message:Dictionary[String, String]
51+
message[parts[0]] = parts[1]
52+
return message
53+
54+
55+
func addMessage(sender:String, body:String):
56+
var final_message
57+
if sender == $Username.text:
58+
final_message = (
59+
"[right]" +
60+
"[color=GREEN_YELLOW]" +
61+
sender.capitalize() + " : " +
62+
"[/color]\n" +
63+
"[color=POWDER_BLUE]" +
64+
"\t" + body +
65+
"[/color]" +
66+
"[/right]\n")
67+
else:
68+
final_message = (
69+
"[left]" +
70+
"[color=TOMATO]" +
71+
sender.capitalize() + " : " +
72+
"[/color] \n" +
73+
"[color=WHITE_SMOKE]" +
74+
"\t" + body +
75+
"[/color]" +
76+
"[/left]\n")
77+
78+
$BG/Chat.append_text(final_message)
79+
80+
81+
func _on_username_text_submitted(new_text: String) -> void:
82+
while ws.get_ready_state() != ws.STATE_OPEN:
83+
await get_tree().create_timer(0.1).timeout
84+
85+
if new_text == "":
86+
new_text = randomName()
87+
$Username.text = new_text
88+
var err = ws.send_text(new_text)
89+
username_set = true
90+
if err == OK:
91+
$Username.release_focus()
92+
$Message.editable = true
93+
$Username.editable = false
94+
95+
96+
func _on_message_text_submitted(new_text: String) -> void:
97+
if new_text != "":
98+
var err = ws.send_text(new_text)
99+
if err == OK:
100+
$Message.clear()
101+
$Message.release_focus()
102+
$Message.grab_focus.call_deferred()
103+
104+
105+
106+
func _on_button_pressed() -> void:
107+
if ws and ws.get_ready_state() == ws.STATE_OPEN:
108+
if username_set == false:
109+
ws.send_text("")
110+
ws.close(1000, "Client quitting")
111+
while ws.get_ready_state() != ws.STATE_CLOSED:
112+
ws.poll()
113+
get_tree().quit()

0 commit comments

Comments
 (0)