aboutsummaryrefslogtreecommitdiff
path: root/src/methods
diff options
context:
space:
mode:
Diffstat (limited to 'src/methods')
-rw-r--r--src/methods/execute_command.zig53
-rw-r--r--src/methods/execute_squirrel.zig42
-rw-r--r--src/methods/list_methods.zig18
3 files changed, 113 insertions, 0 deletions
diff --git a/src/methods/execute_command.zig b/src/methods/execute_command.zig
new file mode 100644
index 0000000..c253738
--- /dev/null
+++ b/src/methods/execute_command.zig
@@ -0,0 +1,53 @@
+const std = @import("std");
+
+const engine = @import("../engine.zig");
+
+const Allocator = std.mem.Allocator;
+
+pub const method = .{
+ .name = "execute_command",
+ .func = execute_command,
+};
+
+fn execute_command(allocator: Allocator, params: ?std.json.Value) !?std.json.Value {
+ if (params == null) {
+ return error.InvalidParameters;
+ }
+
+ const command = blk: {
+ const command_item = switch (params.?) {
+ .array => param_blk: {
+ const command_array = params.?.array;
+
+ if (command_array.capacity < 1) {
+ return error.NoCommand;
+ }
+
+ break :param_blk command_array.items[0];
+ },
+
+ .object => param_blk: {
+ const command_object = params.?.object;
+
+ break :param_blk command_object.get("command") orelse return error.NoCommand;
+ },
+
+ else => return error.NoCommand,
+ };
+
+ if (command_item != .string) {
+ return error.InvalidCommand;
+ }
+
+ break :blk try allocator.dupeZ(u8, command_item.string);
+ };
+
+ if (engine.Cbuf) |Cbuf| {
+ const cur_player = Cbuf.GetCurrentPlayer();
+ Cbuf.AddText(cur_player, command, .kCommandSrcCode);
+ } else {
+ return error.NoEngine;
+ }
+
+ return null;
+}
diff --git a/src/methods/execute_squirrel.zig b/src/methods/execute_squirrel.zig
new file mode 100644
index 0000000..91a975f
--- /dev/null
+++ b/src/methods/execute_squirrel.zig
@@ -0,0 +1,42 @@
+const std = @import("std");
+
+const squirrel = @import("../squirrel.zig");
+
+const Allocator = std.mem.Allocator;
+
+pub const method = .{
+ .name = "execute_squirrel",
+ .func = execute_squirrel,
+};
+
+fn execute_squirrel(allocator: Allocator, params: ?std.json.Value) !?std.json.Value {
+ if (params == null or params.? != .object) {
+ return error.InvalidParameters;
+ }
+
+ const object = params.?.object;
+
+ const context = blk: {
+ const context_object = object.get("context");
+ if (context_object != null and context_object.? == .string) {
+ const context_string = context_object.?.string;
+
+ if (std.mem.eql(u8, context_string, "server")) {
+ break :blk squirrel.ScriptContext.SC_SERVER;
+ } else if (std.mem.eql(u8, context_string, "client")) {
+ break :blk squirrel.ScriptContext.SC_CLIENT;
+ } else if (std.mem.eql(u8, context_string, "ui")) {
+ break :blk squirrel.ScriptContext.SC_UI;
+ }
+
+ return error.InvalidContext;
+ }
+
+ break :blk squirrel.ScriptContext.SC_UI;
+ };
+ _ = context;
+
+ return .{
+ .string = "test",
+ };
+}
diff --git a/src/methods/list_methods.zig b/src/methods/list_methods.zig
new file mode 100644
index 0000000..b396100
--- /dev/null
+++ b/src/methods/list_methods.zig
@@ -0,0 +1,18 @@
+const std = @import("std");
+
+const server = @import("../server.zig");
+const RpcMethods = server.RpcMethods;
+
+const Allocator = std.mem.Allocator;
+
+pub const method = .{
+ .name = "list_methods",
+ .func = list_methods,
+};
+
+fn list_methods(allocator: Allocator, params: ?std.json.Value) !?std.json.Value {
+ _ = allocator;
+ _ = params;
+
+ return null;
+}