Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit bcc80f8

Browse files
QoL Changes
1 parent db58d90 commit bcc80f8

10 files changed

Lines changed: 71 additions & 21 deletions

File tree

Scenes/Prefabs/LobbyPlayerListing.tscn

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,39 @@ margin_right = 398.0
88
margin_bottom = 19.0
99
theme = ExtResource( 2 )
1010
script = ExtResource( 1 )
11-
__meta__ = {
12-
"_edit_use_anchors_": false
13-
}
1411
NodePathName = NodePath("HBox/Name")
15-
NodePathStatus = NodePath("HBox/Status")
12+
NodePathStatus = NodePath("HBox/HBoxContainer/Status")
13+
NodePathKick = NodePath("HBox/HBoxContainer/Kick")
1614

1715
[node name="HBox" type="HBoxContainer" parent="."]
1816
margin_left = 1.0
1917
margin_top = 1.0
2018
margin_right = 397.0
21-
margin_bottom = 18.0
19+
margin_bottom = 24.0
2220
rect_min_size = Vector2( 200, 0 )
2321

2422
[node name="Name" type="Label" parent="HBox"]
23+
margin_top = 3.0
2524
margin_right = 76.0
26-
margin_bottom = 17.0
25+
margin_bottom = 20.0
2726
text = "PlayerName"
2827

29-
[node name="Status" type="Label" parent="HBox"]
30-
margin_left = 331.0
28+
[node name="HBoxContainer" type="HBoxContainer" parent="HBox"]
29+
margin_left = 295.0
3130
margin_right = 396.0
32-
margin_bottom = 17.0
31+
margin_bottom = 23.0
3332
size_flags_horizontal = 10
33+
34+
[node name="Kick" type="Button" parent="HBox/HBoxContainer"]
35+
margin_right = 32.0
36+
margin_bottom = 23.0
37+
text = "Kick"
38+
39+
[node name="Status" type="Label" parent="HBox/HBoxContainer"]
40+
margin_left = 36.0
41+
margin_top = 3.0
42+
margin_right = 101.0
43+
margin_bottom = 20.0
3444
text = "Not Ready"
45+
46+
[connection signal="pressed" from="HBox/HBoxContainer/Kick" to="." method="_on_Kick_pressed"]

Scenes/Prefabs/PopupDirectConnect.tscn

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[ext_resource path="res://Scripts/Msc/UIPopupDirectConnect.cs" type="Script" id=2]
55

66
[node name="PopupDirectConnect" type="WindowDialog"]
7-
visible = true
87
anchor_left = 0.5
98
anchor_top = 0.5
109
anchor_right = 0.5
@@ -50,7 +49,7 @@ margin_bottom = 41.0
5049
rect_min_size = Vector2( 200, 0 )
5150
size_flags_horizontal = 4
5251
size_flags_vertical = 0
53-
text = "127.0.0.1:7777"
52+
text = "127.0.0.1:25565"
5453
placeholder_text = "Enter IP to connect to"
5554

5655
[node name="MarginContainer2" type="MarginContainer" parent="PanelContainer/VBoxContainer"]

Scenes/Scenes/Lobby.tscn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ anchor_right = 1.0
99
anchor_bottom = 1.0
1010
theme = ExtResource( 1 )
1111
script = ExtResource( 2 )
12-
__meta__ = {
13-
"_edit_use_anchors_": false
14-
}
1512
NodePathPlayers = NodePath("PanelContainer/Players/PanelContainer/ScrollContainer/Players")
1613
NodePathChatText = NodePath("PanelContainer/Chat/PanelContainer/VBoxContainer/MarginContainer/Chat Text")
1714
NodePathChatInput = NodePath("PanelContainer/Chat/PanelContainer/VBoxContainer/Chat Input")

Scripts/Netcode/Client/GameClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ private void HandlePeerLeave(DisconnectOpcode opcode)
3737
Disconnected = true;
3838
Connected = 0;
3939
NetworkManager.GodotCmds.Enqueue(new GodotCmd(GodotOpcode.Disconnect, opcode));
40-
if (CancelTokenSource != null)
41-
CancelTokenSource.Cancel();
4240
}
4341
}
4442
}

Scripts/Netcode/Common/CPacketLobby.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public override void Write(PacketWriter writer)
3232
writer.Write(DirectConnect);
3333
break;
3434

35+
case LobbyOpcode.LobbyKick:
36+
writer.Write(Id);
37+
break;
38+
3539
case LobbyOpcode.LobbyReady:
3640
writer.Write(Ready);
3741
break;
@@ -63,6 +67,10 @@ public override void Read(PacketReader reader)
6367
DirectConnect = reader.ReadBool();
6468
break;
6569

70+
case LobbyOpcode.LobbyKick:
71+
Id = reader.ReadByte();
72+
break;
73+
6674
case LobbyOpcode.LobbyReady:
6775
Ready = reader.ReadBool();
6876
break;
@@ -89,6 +97,10 @@ public override void Handle(Peer peer)
8997
HandleChatMessage(peer);
9098
break;
9199

100+
case LobbyOpcode.LobbyKick:
101+
HandleKick(peer);
102+
break;
103+
92104
case LobbyOpcode.LobbyReady:
93105
HandleReady(peer);
94106
break;
@@ -103,6 +115,16 @@ public override void Handle(Peer peer)
103115
}
104116
}
105117

118+
// LobbyKick
119+
public byte Id { get; set; }
120+
private void HandleKick(Peer peer)
121+
{
122+
if (!Server.Players[(byte)peer.ID].Host)
123+
return;
124+
125+
Server.Kick(Id, DisconnectOpcode.Kicked);
126+
}
127+
106128
// LobbyCreate
107129
public string LobbyName { get; set; }
108130
public string LobbyDescription { get; set; }
@@ -144,6 +166,9 @@ private void HandleChatMessage(Peer peer)
144166

145167
private void HandleCountdownChange(Peer peer)
146168
{
169+
if (!Server.Players[(byte)peer.ID].Host)
170+
return;
171+
147172
Server.SendToOtherPlayers(peer.ID, ServerPacketOpcode.Lobby, new SPacketLobby
148173
{
149174
LobbyOpcode = LobbyOpcode.LobbyCountdownChange,
@@ -154,6 +179,9 @@ private void HandleCountdownChange(Peer peer)
154179
// LobbyGameStart
155180
private void HandleGameStart(Peer peer)
156181
{
182+
if (!Server.Players[(byte)peer.ID].Host)
183+
return;
184+
157185
Server.DisallowJoiningLobby = true;
158186
Server.SendToAllPlayers(ServerPacketOpcode.Lobby, new SPacketLobby { LobbyOpcode = LobbyOpcode.LobbyGameStart });
159187
}

Scripts/Netcode/Common/_Opcodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum LobbyOpcode
3737
LobbyCreate,
3838
LobbyJoin,
3939
LobbyLeave,
40+
LobbyKick,
4041
LobbyInfo,
4142
LobbyChatMessage,
4243
LobbyReady,

Scripts/Netcode/Web/WebClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class WebClient : IDisposable
1818
private static int FailedPingAttempts { get; set; }
1919
public static string WEB_SERVER_IP = "localhost:4000";
2020
private const int WEB_PING_INTERVAL = 10000;
21-
private static bool LogExceptions = true;
21+
private static bool LogExceptions = false;
2222
public static Timer TimerPingMasterServer { get; set; }
2323

2424
public WebClient()

Scripts/Scenes/Lobby/SceneLobby.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public void AddPlayer(uint id, string name)
127127

128128
player.SetUsername(name);
129129
player.SetReady(false);
130+
player.Id = id;
130131
}
131132

132133
public void RemovePlayer(uint id)

Scripts/Scenes/Lobby/UILobbyPlayerListing.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,26 @@ public class UILobbyPlayerListing : Control
66
{
77
[Export] public readonly NodePath NodePathName;
88
[Export] public readonly NodePath NodePathStatus;
9+
[Export] public readonly NodePath NodePathKick;
910

1011
private Label PlayerName { get; set; }
1112
private Label Status { get; set; }
13+
private Button Kick { get; set; }
1214

1315
public string Username { get; private set; }
1416
public bool Ready { get; private set; }
1517
public bool Host { get; private set; }
18+
public uint Id { get; set; }
1619

1720
public override void _Ready()
1821
{
1922
PlayerName = GetNode<Label>(NodePathName);
2023
Status = GetNode<Label>(NodePathStatus);
24+
Kick = GetNode<Button>(NodePathKick);
25+
26+
// Only host may kick others and host cannot kick self
27+
if (!NetworkManager.IsHost || NetworkManager.PeerId == Id)
28+
Kick.Visible = false;
2129
}
2230

2331
public void SetUsername(string value)
@@ -36,5 +44,11 @@ public void SetHost(bool value)
3644
{
3745
Host = value;
3846
}
47+
48+
private void _on_Kick_pressed()
49+
{
50+
// TODO: Kick Id
51+
Logger.LogDebug(Id);
52+
}
3953
}
4054
}

Scripts/Utils/Logger.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public static void LogErr(Exception ex, string hint = "")
1313
Hint = hint
1414
}));
1515
}
16-
public static void LogWarning(string text, ConsoleColor color = ConsoleColor.Yellow) => Log($"[Warning]: {text}", color);
17-
public static void LogDebug(string text, ConsoleColor color = ConsoleColor.Magenta) => Log($"[Debug]: {text}", color);
18-
public static void Log(string text, ConsoleColor color = ConsoleColor.Gray)
16+
public static void LogWarning(object v, ConsoleColor color = ConsoleColor.Yellow) => Log($"[Warning]: {v}", color);
17+
public static void LogDebug(object v, ConsoleColor color = ConsoleColor.Magenta) => Log($"[Debug]: {v}", color);
18+
public static void Log(object v, ConsoleColor color = ConsoleColor.Gray)
1919
{
2020
NetworkManager.GodotCmds.Enqueue(new GodotCmd(GodotOpcode.LogMessage, new GodotMessage
2121
{
22-
Text = text,
22+
Text = $"{v}",
2323
Color = color
2424
}));
2525
}

0 commit comments

Comments
 (0)