summaryrefslogtreecommitdiff
path: root/server/hornchat.profile.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-10 10:38:44 +0200
committerMinteck <contact@minteck.org>2022-08-10 10:38:44 +0200
commitc6dbf0450566c40efc4a26f4f0717452b6ef95cd (patch)
treeb4be2d508223820d0a77d5a3e35e82684da3b6ec /server/hornchat.profile.js
downloadhornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.tar.gz
hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.tar.bz2
hornchat-c6dbf0450566c40efc4a26f4f0717452b6ef95cd.zip
Initial commitHEADmane
Diffstat (limited to 'server/hornchat.profile.js')
-rw-r--r--server/hornchat.profile.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/server/hornchat.profile.js b/server/hornchat.profile.js
new file mode 100644
index 0000000..9b30cf1
--- /dev/null
+++ b/server/hornchat.profile.js
@@ -0,0 +1,59 @@
+require('./hornchat.serverlet.sync')
+
+const WebSocket = require('ws');
+const uuid = require('uuid-v4');
+const _auth = require('./hornchat.serverlet.authentication');
+const _process = require('./hornchat.profile.process');
+
+const informTrackedUsers = require('./hornchat.profile.tracking');
+setInterval(() => {
+ informTrackedUsers();
+}, 50)
+
+const server = new WebSocket.Server({
+ port: 8303
+});
+
+global.data = {};
+
+server.on('connection', function (socket, req) {
+ socket.ip = req.headers['x-forwarded-for'] ? req.headers['x-forwarded-for'].split(',')[0].trim() : req.socket.remoteAddress;
+
+ socket.authenticated = null;
+ socket.id = uuid();
+ console.log("New connection: " + socket.id);
+ data[socket.id] = {};
+ data[socket.id]["socket"] = socket;
+
+ require('./hornchat.serverlet.timeout')(socket);
+
+ socket.on('close', () => {
+ if (socket.id) {
+ delete data[socket.id];
+ }
+ })
+
+ socket.on('message', function (msg) {
+ if (socket.authenticated === null) {
+ _auth(socket, msg);
+ } else {
+ let d;
+ try {
+ d = JSON.parse(msg);
+ } catch (e) {
+ socket.send(JSON.stringify({error:"INVALID_DATA", fatal: false}));
+ console.log("[" + socket.id + "] Received invalid data");
+ return;
+ }
+
+ if (d.username) {
+ _process(socket, d);
+ } else {
+ socket.send(JSON.stringify({error:"MISSING_OPERAND", fatal: false}));
+ console.log("[" + socket.id + "] Missing 'username' value");
+ }
+ }
+ });
+});
+
+console.log("Listening on port 8303"); \ No newline at end of file