mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-09 03:59:53 -04:00
parent
647cd924c5
commit
9d432fbb7b
@ -508,6 +508,7 @@ pub const ConnectionManager = struct {
|
||||
}
|
||||
|
||||
pub fn finishCurrentReceive(self: *ConnectionManager) void {
|
||||
std.debug.assert(self.threadId != std.Thread.getCurrentId()); // WOuld cause deadlock, since we are in a receive.
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.waitingToFinishReceive.wait(&self.mutex);
|
||||
@ -1285,6 +1286,7 @@ pub const Connection = struct {
|
||||
|
||||
pub fn init(manager: *ConnectionManager, ipPort: []const u8, user: ?*main.server.User) !*Connection {
|
||||
const result: *Connection = main.globalAllocator.create(Connection);
|
||||
errdefer main.globalAllocator.destroy(result);
|
||||
result.* = Connection {
|
||||
.manager = manager,
|
||||
.user = user,
|
||||
@ -1295,14 +1297,19 @@ pub const Connection = struct {
|
||||
.congestionControl_lastSendTime = @truncate(std.time.nanoTimestamp()),
|
||||
.congestionControl_sendTimeLimit = @as(i64, @truncate(std.time.nanoTimestamp())) +% timeUnit*21/20,
|
||||
};
|
||||
errdefer main.globalAllocator.free(result.packetMemory);
|
||||
result.unconfirmedPackets = main.List(UnconfirmedPacket).init(main.globalAllocator);
|
||||
errdefer result.unconfirmedPackets.deinit();
|
||||
result.packetQueue = main.utils.CircularBufferQueue(UnconfirmedPacket).init(main.globalAllocator, 1024);
|
||||
errdefer result.packetQueue.deinit();
|
||||
result.receivedPackets = [3]main.List(u32){
|
||||
main.List(u32).init(main.globalAllocator),
|
||||
main.List(u32).init(main.globalAllocator),
|
||||
main.List(u32).init(main.globalAllocator),
|
||||
};
|
||||
errdefer result.deinit();
|
||||
errdefer for(&result.receivedPackets) |*list| {
|
||||
list.deinit();
|
||||
};
|
||||
var splitter = std.mem.split(u8, ipPort, ":");
|
||||
const ip = splitter.first();
|
||||
result.remoteAddress.ip = try Socket.resolveIP(ip);
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
|
||||
pub const help = @import("help.zig");
|
||||
pub const invite = @import("invite.zig");
|
||||
pub const time = @import("time.zig");
|
||||
pub const tp = @import("tp.zig");
|
27
src/server/command/invite.zig
Normal file
27
src/server/command/invite.zig
Normal file
@ -0,0 +1,27 @@
|
||||
const std = @import("std");
|
||||
|
||||
const main = @import("root");
|
||||
const User = main.server.User;
|
||||
|
||||
pub const description = "Invite a player";
|
||||
pub const usage = "/invite <IP>";
|
||||
|
||||
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;
|
||||
if(split.next() != null) {
|
||||
source.sendMessage("#ff0000Too many arguments for command /invite");
|
||||
}
|
||||
const user = main.server.User.initAndIncreaseRefCount(main.server.connectionManager, arg) catch |err| {
|
||||
const msg = std.fmt.allocPrint(main.stackAllocator.allocator, "#ff0000Error while trying to connect: {s}", .{@errorName(err)}) catch unreachable;
|
||||
defer main.stackAllocator.free(msg);
|
||||
std.log.err("{s}", .{msg[7..]});
|
||||
source.sendMessage(msg);
|
||||
return;
|
||||
};
|
||||
user.decreaseRefCount();
|
||||
return;
|
||||
}
|
||||
source.sendMessage("#ff0000Too few arguments for command /tp");
|
||||
}
|
@ -4,7 +4,7 @@ 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 const usage = "/time\n/time <day/night>\n/time <time>\n/time <start/stop>";
|
||||
|
||||
pub fn execute(args: []const u8, source: *User) void {
|
||||
var split = std.mem.splitScalar(u8, args, ' ');
|
||||
@ -15,6 +15,12 @@ pub fn execute(args: []const u8, source: *User) void {
|
||||
gameTime = 0;
|
||||
} else if(std.ascii.eqlIgnoreCase(arg, "night")) {
|
||||
gameTime = main.server.ServerWorld.dayCycle/2;
|
||||
} else if(std.ascii.eqlIgnoreCase(arg, "start")) {
|
||||
main.server.world.?.doGameTimeCycle = true;
|
||||
return;
|
||||
} else if(std.ascii.eqlIgnoreCase(arg, "stop")) {
|
||||
main.server.world.?.doGameTimeCycle = false;
|
||||
return;
|
||||
} 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user