-
-
Notifications
You must be signed in to change notification settings - Fork 218
use kick inside manage player window #2798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+126
−83
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
00c02e2
use kick inside manage player
Wunka 6c1e0ab
make playerIndex optinal and rename manage_players
Wunka a8e19d8
do what was asked
Wunka 742d450
Merge branch 'master' into switch-manage
Wunka e7743e5
wierd merge
Wunka f5c3ca0
Update src/gui/windows/players.zig
Wunka 4a47048
even with no name you get kicked
Wunka c1c80cf
bring back client-server side implementation
Wunka 781ebd0
skip self when using server-client implementation and display 0 lengt…
Wunka 99b97a1
applied suggestions and use handshake state to know if player has alr…
Wunka 52ffd89
only on complete
Wunka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const ConnectionManager = main.network.ConnectionManager; | ||
| const settings = main.settings; | ||
| const Vec2f = main.vec.Vec2f; | ||
|
|
||
| const gui = @import("../gui.zig"); | ||
| const GuiComponent = gui.GuiComponent; | ||
| const GuiWindow = gui.GuiWindow; | ||
| const Button = @import("../components/Button.zig"); | ||
| const Label = @import("../components/Label.zig"); | ||
| const TextInput = @import("../components/TextInput.zig"); | ||
| const VerticalList = @import("../components/VerticalList.zig"); | ||
| const HorizontalList = @import("../components/HorizontalList.zig"); | ||
|
|
||
| pub var window = GuiWindow{ | ||
| .contentSize = Vec2f{128, 256}, | ||
| .closeIfMouseIsGrabbed = true, | ||
| }; | ||
|
|
||
| const padding: f32 = 8; | ||
| var userList: []*main.server.User = &.{}; | ||
| var entityCount: u32 = 0; | ||
|
|
||
| fn kickbyConnection(conn: *main.network.Connection) void { | ||
| conn.disconnect(); | ||
| } | ||
|
|
||
| fn kickByPlayerIndex(playerIndex: usize) void { | ||
| const command = std.fmt.allocPrint(main.globalAllocator.allocator, "kick @{d}", .{playerIndex}) catch unreachable; | ||
| main.sync.ClientSide.executeCommand(.{.chatCommand = .{.message = command}}); | ||
| } | ||
|
|
||
| pub fn onOpen() void { | ||
| const list = VerticalList.init(.{padding, 16 + padding}, 300, 16); | ||
| if (main.server.world == null) blk: { | ||
| entityCount = main.client.entity_manager.entities.len; | ||
| if (entityCount == 0) { | ||
| list.add(Label.init(.{0, 0}, 200, "No other players", .left)); | ||
| break :blk; | ||
| } | ||
|
|
||
| for (main.client.entity_manager.entities.items()) |ent| { | ||
| if (ent.playerIndex == null) continue; | ||
| const row = HorizontalList.init(); | ||
|
|
||
| const string = std.fmt.allocPrint(main.stackAllocator.allocator, "{f}", .{std.fmt.alt(ent, .formatWithPlayerIndex)}) catch unreachable; | ||
| defer main.stackAllocator.free(string); | ||
| row.add(Label.init(.{0, 0}, 200, string, .left)); | ||
| row.add(Button.initText(.{0, 0}, 100, "Kick", .initWithInt(kickByPlayerIndex, ent.playerIndex.?))); | ||
| list.add(row); | ||
| } | ||
| } else { | ||
| main.server.connectionManager.mutex.lock(); | ||
| defer main.server.connectionManager.mutex.unlock(); | ||
| std.debug.assert(userList.len == 0); | ||
| userList = main.globalAllocator.alloc(*main.server.User, main.server.connectionManager.connections.items.len); | ||
| for (main.server.connectionManager.connections.items, 0..) |connection, i| { | ||
| userList[i] = connection.user.?; | ||
| userList[i].increaseRefCount(); | ||
| if (userList[i].id == main.game.Player.id and connection.isConnected()) continue; | ||
| const row = HorizontalList.init(); | ||
| if (connection.handShakeState.load(.monotonic) == .complete) { | ||
| const string = std.fmt.allocPrint(main.stackAllocator.allocator, "{f}", .{connection.user.?}) catch unreachable; | ||
| defer main.stackAllocator.free(string); | ||
| row.add(Label.init(.{0, 0}, 200, string, .left)); | ||
| row.add(Button.initText(.{0, 0}, 100, "Kick", .initWithPtr(kickbyConnection, connection))); | ||
| } else { | ||
| const ip = std.fmt.allocPrint(main.stackAllocator.allocator, "{f}", .{connection.remoteAddress}) catch unreachable; | ||
| defer main.stackAllocator.free(ip); | ||
| row.add(Label.init(.{0, 0}, 200, ip, .left)); | ||
| row.add(Button.initText(.{0, 0}, 100, "Cancel", .initWithPtr(kickbyConnection, connection))); | ||
| } | ||
| list.add(row); | ||
| } | ||
| if (userList.len == 1) { | ||
| list.add(Label.init(.{0, 0}, 200, "No other players", .left)); | ||
| } | ||
| } | ||
| list.finish(.center); | ||
| window.rootComponent = list.toComponent(); | ||
| window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding)); | ||
| gui.updateWindowPositions(); | ||
| } | ||
|
|
||
| pub fn onClose() void { | ||
| if (main.server.world != null) { | ||
| for (userList) |user| { | ||
| user.decreaseRefCount(); | ||
| } | ||
| main.globalAllocator.free(userList); | ||
| userList = &.{}; | ||
| } | ||
| if (window.rootComponent) |*comp| { | ||
| comp.deinit(); | ||
| } | ||
| } | ||
|
|
||
| pub fn update() void { | ||
| if (main.server.world == null) { | ||
| if (main.client.entity_manager.entities.len != entityCount) { | ||
| onClose(); | ||
| onOpen(); | ||
| } | ||
| } else { | ||
| main.server.connectionManager.mutex.lock(); | ||
| const serverListLen = main.server.connectionManager.connections.items.len; | ||
| main.server.connectionManager.mutex.unlock(); | ||
| if (userList.len != serverListLen) { | ||
| onClose(); | ||
| onOpen(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.