|
@@ -5,6 +5,7 @@ import type { Socket } from "net";
|
|
|
const countAndSlice = require("./utils/countAndSlice");
|
|
const countAndSlice = require("./utils/countAndSlice");
|
|
|
const Queue = require("./utils/Queue");
|
|
const Queue = require("./utils/Queue");
|
|
|
const db = require("./db");
|
|
const db = require("./db");
|
|
|
|
|
+const telegraf = require("./telegraf");
|
|
|
|
|
|
|
|
// All connections stored by id
|
|
// All connections stored by id
|
|
|
const Connections = {};
|
|
const Connections = {};
|
|
@@ -13,6 +14,7 @@ const Connections = {};
|
|
|
const secureOp = [
|
|
const secureOp = [
|
|
|
"register",
|
|
"register",
|
|
|
"login",
|
|
"login",
|
|
|
|
|
+ "notify",
|
|
|
"ping",
|
|
"ping",
|
|
|
"close"];
|
|
"close"];
|
|
|
|
|
|
|
@@ -76,11 +78,11 @@ class Connection {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async login() {
|
|
async login() {
|
|
|
|
|
+ const auth = await this.queue.remove();
|
|
|
if (typeof this.session !== "undefined") {
|
|
if (typeof this.session !== "undefined") {
|
|
|
this.write("error:session is logged;");
|
|
this.write("error:session is logged;");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- const auth = await this.queue.remove();
|
|
|
|
|
const user = await db.App.findOne({
|
|
const user = await db.App.findOne({
|
|
|
where: {
|
|
where: {
|
|
|
auth,
|
|
auth,
|
|
@@ -97,6 +99,16 @@ class Connection {
|
|
|
this.write("info:loggedin;");
|
|
this.write("info:loggedin;");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async notify() {
|
|
|
|
|
+ const message = await this.queue.remove();
|
|
|
|
|
+ if (typeof this.session === "undefined") {
|
|
|
|
|
+ this.write("error:need to be logged;");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let messageFormatted = `[${this.session.user.name}] - ${message}`;
|
|
|
|
|
+ telegraf.send(messageFormatted);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ping() {
|
|
ping() {
|
|
|
this.write("pong;");
|
|
this.write("pong;");
|
|
|
}
|
|
}
|