Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Close stale issues and PRs"
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Runs daily at 00:00

permissions:
actions: write
contents: write
issues: read
pull-requests: write

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v10
with:
stale-pr-message: "This PR is stale because it has been open 28 days with no activity. Remove stale label or comment or this will be closed in 7 days."
close-pr-message: "This PR was closed because it has been stalled for 7 days with no activity."
days-before-issue-stale: -1 # Never close issues
days-before-pr-stale: 28
days-before-issue-close: -1
days-before-pr-close: 7
stale-issue-label: stale
stale-pr-label: stale
delete-branch: true
debug-only: true
10 changes: 7 additions & 3 deletions src/Inventory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub const Sync = struct { // MARK: Sync
freeIdList.append(id);
}

pub fn executeCommand(payload: Command.Payload, source: ?*main.server.User) void {
fn executeCommand(payload: Command.Payload, source: ?*main.server.User) void {
var command = Command{
.payload = payload,
};
Expand Down Expand Up @@ -337,15 +337,19 @@ pub const Sync = struct { // MARK: Sync
};
}

pub fn receiveCommand(source: *main.server.User, reader: *utils.BinaryReader) !void {
pub fn executeUserCommand(source: *main.server.User, reader: *utils.BinaryReader) !void {
mutex.lock();
defer mutex.unlock();
const typ = try reader.readEnum(Command.PayloadType);
@setEvalBranchQuota(100000);
const payload: Command.Payload = switch(typ) {
inline else => |_typ| @unionInit(Command.Payload, @tagName(_typ), try @FieldType(Command.Payload, @tagName(_typ)).deserialize(reader, .server, source)),
};
source.receiveCommand(payload);
executeCommand(payload, source);
}

pub fn receiveCommand(source: *main.server.User, reader: *utils.BinaryReader) void {
source.receiveCommand(reader.remaining);
}

pub fn createExternallyManagedInventory(len: usize, typ: Inventory.Type, source: Source, data: *BinaryReader, callbacks: Callbacks) InventoryId {
Expand Down
5 changes: 1 addition & 4 deletions src/network/protocols.zig
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,7 @@ pub const inventory = struct { // MARK: inventory
fn serverReceive(conn: *Connection, reader: *utils.BinaryReader) !void {
const user = conn.user.?;
if(reader.remaining[0] == 0xff) return error.InvalidPacket;
items.Inventory.Sync.ServerSide.receiveCommand(user, reader) catch |err| {
if(err != error.InventoryNotFound) return err;
sendFailure(conn);
};
items.Inventory.Sync.ServerSide.receiveCommand(user, reader);
}
pub fn sendCommand(conn: *Connection, payloadType: items.Inventory.Command.PayloadType, _data: []const u8) void {
std.debug.assert(conn.user == null);
Expand Down
25 changes: 18 additions & 7 deletions src/server/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub const User = struct { // MARK: User

mutex: std.Thread.Mutex = .{},

inventoryCommands: main.ListUnmanaged(main.items.Inventory.Command.Payload) = .{},
inventoryCommands: main.ListUnmanaged([]const u8) = .{},

pub fn initAndIncreaseRefCount(manager: *ConnectionManager, ipPort: []const u8) !*User {
const self = main.globalAllocator.create(User);
Expand Down Expand Up @@ -163,6 +163,9 @@ pub const User = struct { // MARK: User
self.unloadOldChunk(.{0, 0, 0}, 0);
self.conn.deinit();
main.globalAllocator.free(self.name);
for(self.inventoryCommands.items) |commandData| {
main.globalAllocator.free(commandData);
}
self.inventoryCommands.deinit(main.globalAllocator);
main.globalAllocator.destroy(self);
}
Expand Down Expand Up @@ -259,10 +262,18 @@ pub const User = struct { // MARK: User
self.inventoryCommands = .{};
self.mutex.unlock();

for(commands.items) |commandPayload| {
main.items.Inventory.Sync.ServerSide.mutex.lock();
main.items.Inventory.Sync.ServerSide.executeCommand(commandPayload, self);
main.items.Inventory.Sync.ServerSide.mutex.unlock();
for(commands.items) |commandData| {
defer main.globalAllocator.free(commandData);
var reader: BinaryReader = .init(commandData);
main.items.Inventory.Sync.ServerSide.executeUserCommand(self, &reader) catch |err| {
if(err == error.InventoryNotFound) {
main.network.protocols.inventory.sendFailure(self.conn);
} else {
std.log.err("Got error while executing user command: {s}. Disconnecting.", .{@errorName(err)});
std.log.debug("Command data: {any}", .{commandData});
self.conn.disconnect();
}
};
}

self.mutex.lock();
Expand All @@ -283,10 +294,10 @@ pub const User = struct { // MARK: User
self.loadUnloadChunks();
}

pub fn receiveCommand(self: *User, commandPayload: main.items.Inventory.Command.Payload) void {
pub fn receiveCommand(self: *User, commandData: []const u8) void {
self.mutex.lock();
defer self.mutex.unlock();
self.inventoryCommands.append(main.globalAllocator, commandPayload);
self.inventoryCommands.append(main.globalAllocator, main.globalAllocator.dupe(u8, commandData));
}

pub fn receiveData(self: *User, reader: *BinaryReader) !void {
Expand Down
Loading