From ec2d3b5929e1d9cade5c1d168ec0fa4ceec22715 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Tue, 16 Aug 2022 06:23:21 -0400 Subject: [PATCH] e --- package.json | 1 + src/Client.js | 35 +++++++++++++++++++++++++++-------- src/Cow.js | 21 +++++++++++++++++++++ src/Message.js | 1 + src/User.js | 10 +++++++++- yarn.lock | 5 +++++ 6 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/Cow.js diff --git a/package.json b/package.json index 74d8775..677de7c 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "mongoose": "^5.12.7", "mppclone-client": "^1.0.0", "nodemon": "^2.0.15", + "unique-names-generator": "^4.7.1", "ws": "^7.2.3" } } diff --git a/src/Client.js b/src/Client.js index bc2a3f8..1ea9371 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1,8 +1,7 @@ const Channel = require("./Channel.js"); const Quota = require ("./Quota.js"); const quotas = require('../Quotas'); -const RateLimit = require('./Ratelimit.js').RateLimit; -const RateLimitChain = require('./Ratelimit.js').RateLimitChain; +const { RateLimit, RateLimitChain } = require('./Ratelimit.js'); const User = require("./User.js"); const Database = require("./Database.js"); const { EventEmitter } = require('events'); @@ -97,13 +96,13 @@ class Client extends EventEmitter { Database.getUserData(this, this.server).then((usr) => { if (!this.user.hasFlag('freeze_name', true)) { Database.updateUser(this.user._id, this.user); - } - - this.server.rooms.forEach((room) => { - room.updateParticipant(this.user._id, { - name: name + + this.server.rooms.forEach((room) => { + room.updateParticipant(this.user._id, { + name: name + }); }); - }); + } }); } @@ -179,11 +178,31 @@ class Client extends EventEmitter { this.server.rooms.forEach(ch => { channels.push(ch.fetchChannelData()); }); + + let users = []; + this.server.connections.forEach(cl => { + let u = { + p: { + _id: cl.user._id, + name: cl.user.name, + color: cl.user.color, + flags: cl.user.flags, + inventory: cl.user.inventory + }, + id: cl.participantId, + } + + users.push(u); + }); data.channelManager = { channels }; + data.clientManager = { + users + } + this.sendArray([data]); } diff --git a/src/Cow.js b/src/Cow.js new file mode 100644 index 0000000..2557c01 --- /dev/null +++ b/src/Cow.js @@ -0,0 +1,21 @@ +const ung = requre('unique-names-generator'); + +const ung_config = { + dictionaries: [ung.adjectives, ung.colors], + separator: ' ', + length: 2 +} + +class Cow { + static generateRandomName() { + return ung.uniqueNamesGenerator(ung_config); + } + + constructor() { + this['🐄'] = Cow.generateRandomName(); + } +} + +module.exports = { + Cow +} diff --git a/src/Message.js b/src/Message.js index c527eaf..cc3e667 100644 --- a/src/Message.js +++ b/src/Message.js @@ -364,6 +364,7 @@ module.exports = (cl) => { cl.isSubscribedToAdminStream = true; let interval = 8000; if ('interval_ms' in msg) interval = msg['interval_ms']; + cl.sendAdminData(); cl.adminStreamInterval = setInterval(() => { if (cl.isSubscribedToAdminStream == true) cl.sendAdminData(); }, interval); diff --git a/src/User.js b/src/User.js index 507dd09..98735fe 100644 --- a/src/User.js +++ b/src/User.js @@ -19,8 +19,16 @@ class User { this.color = data.color; this.flags = typeof data.flags == "object" ? data.flags : { volume: 100, - "no chat rate limit": false + "no chat rate limit": false, + freeze_name: false } + + this.inventory = { + 'test': { + display_name: 'Test', + count: 1 + } + }; } getPublicUser() { diff --git a/yarn.lock b/yarn.lock index 307a57c..b7c2914 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1539,6 +1539,11 @@ undefsafe@^2.0.5: resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.5.tgz#38733b9327bdcd226db889fb723a6efd162e6e2c" integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA== +unique-names-generator@^4.7.1: + version "4.7.1" + resolved "https://registry.yarnpkg.com/unique-names-generator/-/unique-names-generator-4.7.1.tgz#966407b12ba97f618928f77322cfac8c80df5597" + integrity sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow== + unique-string@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-2.0.0.tgz#39c6451f81afb2749de2b233e3f7c5e8843bd89d"