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

Commit e51fa1f

Browse files
Kick logic
1 parent e24e0da commit e51fa1f

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

Scripts/Scenes/Lobby/SceneLobby.cs

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

128128
player.SetUsername($"{name} (Id: {id})");
129129
player.SetReady(false);
130-
player.Id = id;
130+
player.SetId(id);
131131
}
132132

133133
public void RemovePlayer(uint id)

Scripts/Scenes/Lobby/UILobbyPlayerListing.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public class UILobbyPlayerListing : Control
1515
public string Username { get; private set; }
1616
public bool Ready { get; private set; }
1717
public bool Host { get; private set; }
18-
public uint Id { get; set; }
18+
public uint Id { get; private set; }
1919

2020
public override void _Ready()
2121
{
2222
PlayerName = GetNode<Label>(NodePathName);
2323
Status = GetNode<Label>(NodePathStatus);
2424
Kick = GetNode<Button>(NodePathKick);
2525

26-
// Only host may kick others and host cannot kick self
27-
if (!NetworkManager.IsHost || NetworkManager.PeerId == Id)
26+
// Only host may kick others
27+
if (!NetworkManager.IsHost)
2828
Kick.Visible = false;
2929
}
3030

@@ -45,10 +45,24 @@ public void SetHost(bool value)
4545
Host = value;
4646
}
4747

48-
private void _on_Kick_pressed()
48+
public void SetId(uint value)
4949
{
50-
// TODO: Kick Id
51-
Logger.LogTODO("Kick ID: " + Id);
50+
Id = value;
51+
52+
// host cannot kick self
53+
if (NetworkManager.PeerId == Id)
54+
Kick.Visible = false;
55+
}
56+
57+
private async void _on_Kick_pressed()
58+
{
59+
SceneManager.GetActiveSceneScript<SceneLobby>().RemovePlayer(Id);
60+
NetworkManager.GameServer.Players.Remove((byte)Id);
61+
62+
await NetworkManager.GameClient.Send(ClientPacketOpcode.Lobby, new CPacketLobby {
63+
LobbyOpcode = LobbyOpcode.LobbyKick,
64+
Id = (byte)Id
65+
});
5266
}
5367
}
5468
}

0 commit comments

Comments
 (0)