Skip to content

Commit

Permalink
Merge pull request #132 from Jibbajabbafic/Jibbajabbafic/issue123
Browse files Browse the repository at this point in the history
Add more controls for hosts
  • Loading branch information
Jibbajabbafic authored Sep 26, 2023
2 parents a18f333 + 4368f6d commit 61f5f5e
Show file tree
Hide file tree
Showing 25 changed files with 277 additions and 77 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@ Types of changes:
- New item:
- Flomb - A flying bomb which targets the player in first place!
- Show when players join or leave the game
- Add buttons to allow the host to kick players and change hosts

### Changed
- Coins can now spawn item boxes instead so players can get more items!
- Tweak laser item chance
- Tweaked all item chances
- Turn on bots by default
- Made item debug server side only to stop clients using it outside the editor

### Fixed
- Stopped the same coin/item being taken multiple times
- Made IP finder update periodically
- Made boost work for remote clients
- Stop leaderboard being cut off by buttons
- Enter key now works when joining by IP
- Various connection bugs

## [0.10.1] - 2023-08-01

Expand Down
39 changes: 30 additions & 9 deletions client/client_network.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var setup_scene := "res://client/menu/setup/setup.tscn"
var world_scene := "res://client/world/world.tscn"

# Clock sync and latency vars
var is_connected := false
var client_clock: int = 0
var latency = 0
var delta_latency = 0
Expand All @@ -38,6 +39,7 @@ func _ready() -> void:
assert(result == OK)
result = multiplayer.connect("connected_to_server", self, "_on_connected_to_server")
assert(result == OK)
# This signal doesn't seem to work for WebSocket Clients in Godot 3.5.2
result = multiplayer.connect("server_disconnected", self, "_on_server_disconnected")
assert(result == OK)

Expand Down Expand Up @@ -99,6 +101,7 @@ func start_client(host: String, port: int, singleplayer: bool = false) -> void:
func stop_client() -> void:
$LatencyUpdater.stop()
$ClockSyncTimer.stop()
is_connected = false
if multiplayer.network_peer:
multiplayer.network_peer.disconnect_from_host()
multiplayer.call_deferred("set_network_peer", null)
Expand All @@ -109,15 +112,12 @@ func stop_client() -> void:


func _on_connection_failed() -> void:
Logger.print(self, "Failed to connect to server!")
stop_client()
if is_singleplayer:
change_scene_to_title_screen()
Globals.show_message("Failed to connect to the server!", "Server Connection Failed")
lost_connection("Connection to the server failed!")


func _on_connected_to_server() -> void:
Logger.print(self, "Successfully connected to server!")
is_connected = true
send_clock_sync_request()
# Start calculating latency regularly
$LatencyUpdater.start()
Expand All @@ -127,10 +127,7 @@ func _on_connected_to_server() -> void:


func _on_server_disconnected() -> void:
Logger.print(self, "Disconnected from server!")
stop_client()
change_scene_to_title_screen()
Globals.show_message("Lost connection to the server.", "Server Disconnect")
lost_connection("Lost connection to the server.")


func is_server_connected() -> bool:
Expand All @@ -143,6 +140,16 @@ func is_server_connected() -> bool:
)


func lost_connection(reason: String) -> void:
# Only lose connection once
if not is_connected:
return
Logger.print(self, "Lost connection to server, reason: %s" % reason)
Network.stop_networking()
change_scene_to_title_screen()
Globals.show_message(reason, "Server Disconnect")


func is_rpc_from_server() -> bool:
var sender: int = multiplayer.get_rpc_sender_id()
if sender != SERVER_ID:
Expand Down Expand Up @@ -231,6 +238,20 @@ remote func receive_game_options(new_game_options: Dictionary) -> void:
emit_signal("game_options_changed", new_game_options)


func send_host_change_request(player_id: int) -> void:
rpc_id(SERVER_ID, "receive_host_change_request", player_id)


func send_kick_request(player_id: int) -> void:
rpc_id(SERVER_ID, "receive_kick_request", player_id)


remote func receive_player_kicked() -> void:
if is_rpc_from_server() == false:
return
lost_connection("You have been kicked from the server")


remote func receive_host_change(new_host_id: int) -> void:
if is_rpc_from_server() == false:
return
Expand Down
10 changes: 9 additions & 1 deletion client/menu/lobby/join_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ onready var info_message = $MarginContainer/VBoxContainer/InfoMessage
onready var ip_input = $MarginContainer/VBoxContainer/IpContainer/IpInput


func _on_JoinButton_pressed() -> void:
func try_join() -> void:
if ip_input.text.empty():
show_error("Please enter an IP")
return
Expand Down Expand Up @@ -43,3 +43,11 @@ func show_error(message: String) -> void:
func _on_ConnectionTimer_timeout() -> void:
show_error("Connection failed!")
Network.Client.stop_client()


func _on_JoinButton_pressed() -> void:
try_join()


func _on_IpInput_text_entered(_new_text: String) -> void:
try_join()
1 change: 1 addition & 0 deletions client/menu/lobby/join_panel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ align = 1
valign = 1

[connection signal="timeout" from="ConnectionTimer" to="." method="_on_ConnectionTimer_timeout"]
[connection signal="text_entered" from="MarginContainer/VBoxContainer/IpContainer/IpInput" to="." method="_on_IpInput_text_entered"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/IpContainer/JoinButton" to="." method="_on_JoinButton_pressed"]
Binary file added client/menu/setup/multiplayer/boot-kick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions client/menu/setup/multiplayer/boot-kick.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/boot-kick.png-7bb6a9ee6c76656a060779cdec756ef3.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://client/menu/setup/multiplayer/boot-kick.png"
dest_files=[ "res://.import/boot-kick.png-7bb6a9ee6c76656a060779cdec756ef3.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
15 changes: 9 additions & 6 deletions client/menu/setup/multiplayer/ip_finder.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ var public_ip: String = ""

onready var ip_label = $IP


func _ready() -> void:
update_public_ip()
$RefreshTimer.start(IP_REFRESH_TIME)


func update_public_ip() -> void:
var result: int = $HTTPRequest.request("https://api.ipify.org")
if result != OK:
Expand Down Expand Up @@ -58,3 +52,12 @@ func _on_MessageTimer_timeout() -> void:

func _on_RefreshTimer_timeout() -> void:
update_public_ip()


func _on_IpFinder_visibility_changed() -> void:
# Assume the IP isn't needed when hidden
if is_visible_in_tree():
update_public_ip()
$RefreshTimer.start(IP_REFRESH_TIME)
else:
$RefreshTimer.stop()
1 change: 1 addition & 0 deletions client/menu/setup/multiplayer/ip_finder.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ one_shot = true

[node name="RefreshTimer" type="Timer" parent="."]

[connection signal="visibility_changed" from="." to="." method="_on_IpFinder_visibility_changed"]
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]
[connection signal="toggled" from="ButtonContainer/ShowButton" to="." method="_on_ShowButton_toggled"]
[connection signal="pressed" from="ButtonContainer/CopyButton" to="." method="_on_CopyButton_pressed"]
Expand Down
Binary file added client/menu/setup/multiplayer/laurel-crown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions client/menu/setup/multiplayer/laurel-crown.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/laurel-crown.png-c930b589408395ceb2e7e1ac4cde7029.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://client/menu/setup/multiplayer/laurel-crown.png"
dest_files=[ "res://.import/laurel-crown.png-c930b589408395ceb2e7e1ac4cde7029.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
29 changes: 26 additions & 3 deletions client/menu/setup/multiplayer/player_entry.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
extends HBoxContainer

var player_id: int
var is_bot := false
var is_host := false


func _ready() -> void:
$PlayerIcon/Player.set_physics_process(false)


func setup(player_id: int, player_name: String, colour_choice: int) -> void:
func setup(_player_id: int, player_name: String, colour_choice: int, _is_bot: bool) -> void:
player_id = _player_id
is_bot = _is_bot
set_name(str(player_id))
$Name.text = player_name
set_colour(colour_choice)
Expand All @@ -20,5 +26,22 @@ func set_spectating(is_spectating: bool) -> void:
$SpectateIcon.visible = is_spectating


func set_host(is_host: bool) -> void:
$HostPlaceholder/HostIcon.visible = is_host
func set_host(value: bool) -> void:
is_host = value
$HostIcon.visible = is_host
var show_host_buttons := not is_host and Network.Client.is_host() and not is_bot
show_host_buttons(show_host_buttons)


func show_host_buttons(value: bool) -> void:
$HostPlaceholder.visible = value
$HostPlaceholder/Promote.visible = value
$HostPlaceholder/Kick.visible = value


func _on_Promote_pressed() -> void:
Network.Client.send_host_change_request(player_id)


func _on_Kick_button_down() -> void:
Network.Client.send_kick_request(player_id)
56 changes: 35 additions & 21 deletions client/menu/setup/multiplayer/player_entry.tscn
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=9 format=2]

[ext_resource path="res://client/fonts/DelaGothicOne-24.tres" type="DynamicFont" id=1]
[ext_resource path="res://client/world/player/player.tscn" type="PackedScene" id=2]
[ext_resource path="res://client/menu/setup/multiplayer/player_entry.gd" type="Script" id=3]
[ext_resource path="res://client/ui/custom_label.tscn" type="PackedScene" id=4]
[ext_resource path="res://client/menu/setup/multiplayer/semi-closed-eye.png" type="Texture" id=5]
[ext_resource path="res://client/menu/setup/multiplayer/crown.png" type="Texture" id=6]
[ext_resource path="res://client/menu/setup/multiplayer/laurel-crown.png" type="Texture" id=6]
[ext_resource path="res://client/menu/setup/multiplayer/boot-kick.png" type="Texture" id=7]
[ext_resource path="res://client/menu/setup/multiplayer/crown.png" type="Texture" id=8]

[node name="PlayerEntry" type="HBoxContainer"]
margin_right = 374.0
margin_bottom = 64.0
grow_horizontal = 0
rect_min_size = Vector2( 0, 67 )
custom_constants/separation = 10
alignment = 2
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Name" parent="." instance=ExtResource( 4 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 300.0
margin_bottom = 64.0
margin_bottom = 67.0
grow_horizontal = 0
rect_min_size = Vector2( 300, 64 )
custom_fonts/font = ExtResource( 1 )
Expand All @@ -32,10 +32,17 @@ valign = 1
autowrap = true
clip_text = true

[node name="PlayerIcon" type="Control" parent="."]
[node name="HostIcon" type="TextureRect" parent="."]
margin_left = 310.0
margin_right = 374.0
margin_bottom = 64.0
margin_bottom = 67.0
rect_min_size = Vector2( 64, 64 )
texture = ExtResource( 8 )

[node name="PlayerIcon" type="Control" parent="."]
margin_left = 384.0
margin_right = 448.0
margin_bottom = 67.0
rect_min_size = Vector2( 64, 64 )
size_flags_horizontal = 5
size_flags_vertical = 5
Expand All @@ -56,17 +63,24 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="HostPlaceholder" type="Control" parent="."]
margin_left = 384.0
margin_right = 448.0
margin_bottom = 64.0
rect_min_size = Vector2( 64, 64 )
[node name="HostPlaceholder" type="HBoxContainer" parent="."]
margin_left = 458.0
margin_right = 610.0
margin_bottom = 67.0
rect_min_size = Vector2( 148, 64 )

[node name="HostIcon" type="TextureRect" parent="HostPlaceholder"]
visible = false
margin_right = 64.0
margin_bottom = 64.0
texture = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Promote" type="Button" parent="HostPlaceholder"]
margin_right = 74.0
margin_bottom = 67.0
icon = ExtResource( 6 )
icon_align = 1

[node name="Kick" type="Button" parent="HostPlaceholder"]
margin_left = 78.0
margin_right = 152.0
margin_bottom = 67.0
icon = ExtResource( 7 )
icon_align = 1

[connection signal="pressed" from="HostPlaceholder/Promote" to="." method="_on_Promote_pressed"]
[connection signal="button_down" from="HostPlaceholder/Kick" to="." method="_on_Kick_button_down"]
Loading

0 comments on commit 61f5f5e

Please sign in to comment.