fixes
This commit is contained in:
parent
2548330592
commit
3513956558
@ -206,9 +206,10 @@ pub const Handler = struct {
|
|||||||
@panic("zombied conn\n");
|
@panic("zombied conn\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.heartbeat() catch {
|
//do we really have to send this?
|
||||||
@panic("we are fucking cooked didn't send heartbeat fuckfuckfuck");
|
//ctx.heartbeat() catch {
|
||||||
};
|
// @panic("we are fucking cooked didn't send heartbeat fuckfuckfuck");
|
||||||
|
//};
|
||||||
ctx.heart.ack = false;
|
ctx.heart.ack = false;
|
||||||
},
|
},
|
||||||
.ack => {
|
.ack => {
|
||||||
@ -322,32 +323,36 @@ pub const Handler = struct {
|
|||||||
//.ca_bundle = @import("tls12").Certificate.Bundle{},
|
//.ca_bundle = @import("tls12").Certificate.Bundle{},
|
||||||
});
|
});
|
||||||
|
|
||||||
try conn.handshake("/?v=10&encoding=json", .{
|
conn.handshake("/?v=10&encoding=json", .{
|
||||||
.timeout_ms = 1000,
|
.timeout_ms = 1000,
|
||||||
.headers = "host: gateway.discord.gg",
|
.headers = "host: gateway.discord.gg",
|
||||||
});
|
}) catch unreachable;
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Handler) void {
|
pub fn deinit(self: *Handler) void {
|
||||||
defer self.heart_task.deinit();
|
self.heart_task.deinit();
|
||||||
defer self.client.deinit();
|
self.client.deinit();
|
||||||
std.debug.print("killing the whole bot\n", .{});
|
std.debug.print("killing the whole bot\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
// listens for messages
|
// listens for messages
|
||||||
pub fn readMessage(self: *Handler) !void {
|
pub fn readMessage(self: *Handler) !void {
|
||||||
try self.client.readTimeout(std.time.ms_per_s * 1);
|
try self.client.readTimeout(0);
|
||||||
while (true) {
|
while (true) {
|
||||||
const msg = (try self.client.read()) orelse {
|
const msg = self.client.read() catch |err| switch (err) {
|
||||||
// no message after our 1 second
|
error.Closed => return,
|
||||||
|
else => return err,
|
||||||
|
} orelse {
|
||||||
std.debug.print(".", .{});
|
std.debug.print(".", .{});
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
// must be called once you're done processing the request
|
// must be called once you're done processing the request
|
||||||
defer self.client.done(msg);
|
defer self.client.done(msg);
|
||||||
|
|
||||||
|
std.debug.print("type of: {?s}\n", .{@tagName(msg.type)});
|
||||||
|
|
||||||
const DiscordData = struct {
|
const DiscordData = struct {
|
||||||
s: ?u64, //well figure it out
|
s: ?u64, //well figure it out
|
||||||
op: Opcode,
|
op: Opcode,
|
||||||
@ -397,14 +402,13 @@ pub const Handler = struct {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
try self.identify();
|
try self.identify();
|
||||||
try self.heartbeat(); // first hb
|
try self.heartbeat();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Opcode.HeartbeatACK => {
|
Opcode.HeartbeatACK => {
|
||||||
// perhaps lock the thread w a mutex?
|
|
||||||
try self.heart_task.scheduleIn(.ack, 0);
|
try self.heart_task.scheduleIn(.ack, 0);
|
||||||
std.debug.print("got heartbeat\n", .{});
|
std.debug.print("got heartbeat\n", .{});
|
||||||
}, // keep this shit alive otherwise kill it
|
},
|
||||||
Opcode.Heartbeat => {
|
Opcode.Heartbeat => {
|
||||||
try self.heartbeat();
|
try self.heartbeat();
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user