diff --git a/src/server/command/_command.zig b/src/server/command/_command.zig index 25d124f399..2ea8a34703 100644 --- a/src/server/command/_command.zig +++ b/src/server/command/_command.zig @@ -102,7 +102,7 @@ pub const Target = struct { source.sendMessage("#ff0000Too few arguments for command", .{}); return error.TooFewArguments; }; - if (userIndex[0] == '@') { + if (userIndex.len > 0 and userIndex[0] == '@') { const user = parsePlayerIndexAndIncreaseRefCount(userIndex, source) catch return error.InvalidArgs; increasedRefCount = true; _ = split.next(); diff --git a/src/server/command/spawn.zig b/src/server/command/spawn.zig index f1efbee694..f417180407 100644 --- a/src/server/command/spawn.zig +++ b/src/server/command/spawn.zig @@ -5,17 +5,21 @@ const User = main.server.User; const command = @import("_command.zig"); -pub const description = "Get or set the player / world spawn point"; +pub const description = "Get or set a player's / the world spawn point"; pub const usage = \\/spawn \\/spawn + \\/spawn @ + \\/spawn @ \\/spawn world \\/spawn world ; pub fn execute(args: []const u8, source: *User) void { var split = std.mem.splitScalar(u8, args, ' '); - if (split.peek().?.len > 0) { + const target = command.Target.init(&split, source) catch return; + defer target.deinit(); + if (split.peek() != null and split.peek().?.len > 0) { if (std.mem.eql(u8, split.peek().?, "world")) { _ = split.next(); if (split.peek() == null or split.peek().?.len == 0) { @@ -38,8 +42,8 @@ pub fn execute(args: []const u8, source: *User) void { source.sendMessage("#ff0000Too many arguments for command /spawn", .{}); return; } - source.spawnPos = pos; + target.user.spawnPos = pos; } else { - source.sendMessage("#ffff00{}", .{source.getSpawnPos()}); + source.sendMessage("#ffff00{}", .{target.user.getSpawnPos()}); } }