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
2 changes: 1 addition & 1 deletion src/server/command/_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions src/server/command/spawn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 <x> <y> <z>
\\/spawn @<playerIndex>
\\/spawn @<playerIndex> <x> <y> <z>
\\/spawn world
\\/spawn world <x> <y> <z>
;

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) {
Expand All @@ -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()});
}
}
Loading