-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
|
||
|
||
pub const help = @import("help.zig"); | ||
pub const help = @import("help.zig"); | ||
pub const time = @import("time.zig"); | ||
pub const tp = @import("tp.zig"); |
This file contains 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 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,36 @@ | ||
const std = @import("std"); | ||
|
||
const main = @import("root"); | ||
const User = main.server.User; | ||
|
||
pub const description = "Get or set the server time."; | ||
pub const usage = "/time\n/time <day/night>\n/time <time>"; | ||
|
||
pub fn execute(args: []const u8, source: *User) void { | ||
var split = std.mem.splitScalar(u8, args, ' '); | ||
if(split.next()) |arg| blk: { | ||
if(arg.len == 0) break :blk; | ||
var gameTime: i64 = undefined; | ||
if(std.ascii.eqlIgnoreCase(arg, "day")) { | ||
gameTime = 0; | ||
} else if(std.ascii.eqlIgnoreCase(arg, "night")) { | ||
gameTime = main.server.ServerWorld.dayCycle/2; | ||
} else { | ||
gameTime = std.fmt.parseInt(i64, arg, 0) catch { | ||
const msg = std.fmt.allocPrint(main.stackAllocator.allocator, "#ff0000Expected i64 number, found \"{s}\"", .{arg}) catch unreachable; | ||
defer main.stackAllocator.free(msg); | ||
source.sendMessage(msg); | ||
return; | ||
}; | ||
} | ||
if(split.next() != null) { | ||
source.sendMessage("#ff0000Too many arguments for command /time"); | ||
return; | ||
} | ||
main.server.world.?.gameTime = gameTime; | ||
return; | ||
} | ||
const msg = std.fmt.allocPrint(main.stackAllocator.allocator, "#ffff00{}", .{main.server.world.?.gameTime}) catch unreachable; | ||
defer main.stackAllocator.free(msg); | ||
source.sendMessage(msg); | ||
} |
This file contains 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,40 @@ | ||
const std = @import("std"); | ||
|
||
const main = @import("root"); | ||
const User = main.server.User; | ||
|
||
pub const description = "Teleport to location."; | ||
pub const usage = "/tp <x> <y>\n/tp <x> <y> <z>"; | ||
|
||
pub fn execute(args: []const u8, source: *User) void { | ||
var x: ?f64 = null; | ||
var y: ?f64 = null; | ||
var z: ?f64 = null; | ||
var split = std.mem.splitScalar(u8, args, ' '); | ||
while(split.next()) |arg| { | ||
const num: f64 = std.fmt.parseFloat(f64, arg) catch { | ||
const msg = std.fmt.allocPrint(main.stackAllocator.allocator, "#ff0000Expected number, found \"{s}\"", .{arg}) catch unreachable; | ||
defer main.stackAllocator.free(msg); | ||
source.sendMessage(msg); | ||
return; | ||
}; | ||
if(x == null) { | ||
x = num; | ||
} else if(y == null) { | ||
y = num; | ||
} else if(z == null) { | ||
z = num; | ||
} else { | ||
source.sendMessage("#ff0000Too many arguments for command /tp"); | ||
return; | ||
} | ||
} | ||
if(x == null or y == null) { | ||
source.sendMessage("#ff0000Too few arguments for command /tp"); | ||
return; | ||
} | ||
if(z == null) { | ||
z = source.player.pos[2]; | ||
} | ||
main.network.Protocols.genericUpdate.sendTPCoordinates(source.conn, .{x.?, y.?, z.?}); | ||
} |