Compare commits

...

53 Commits
v1.0.0 ... main

Author SHA1 Message Date
Ayush Mukherjee 05900b7e46 feat: add more values 1 year ago
Ayush Mukherjee fcb0651579 feat: add stats support in slap 1 year ago
Ayush Mukherjee aca336e8ef feat: add performance pkgs for ws 1 year ago
Ayush Mukherjee 669a5bca18 fix: remove required for matches 1 year ago
Ayush Mukherjee 14513b1c93 fix: remove required 1 year ago
Ayush Mukherjee 4eeca06bbf feat: add more langs to places 1 year ago
Ayush Mukherjee d94f373a3d feat: add secondary names for shit 1 year ago
Ayush Mukherjee c021b9ebe8 chore: test population fix 1 year ago
Ayush Mukherjee 971c21cdee fix: change save behaviour for mongoose models 1 year ago
Ayush Mukherjee 6a1f2d0f61 feat: update deps for new release 1 year ago
Ayush Mukherjee 5c5312ff14 forgot package versioning 4 years ago
Ayush Mukherjee fcdb04683d change back hosts to casters in streams model 4 years ago
Ayush Mukherjee 7f6460ade3 try and fix high cpu usage 4 years ago
Ayush Mukherjee 1ffed1c220 part 2 4 years ago
Ayush Mukherjee fd4cbd01e0 fix random death 4 years ago
Ayush Mukherjee 52d3b33bef change back hosts to hosts for stream 4 years ago
Ayush Mukherjee 22a2783e92 add brackets to crud channels 4 years ago
Ayush Mukherjee 5be1b1fe48 fix brackets model name 4 years ago
Ayush Mukherjee 1c27fa6758 add brackets 4 years ago
Ayush Mukherjee f2445d666d attempt 3 4 years ago
Ayush Mukherjee 1d9ec6bd4f attempt 2 4 years ago
Ayush Mukherjee a5ead194e4 attempt to make streams handler more watertight 4 years ago
Ayush Mukherjee 21c48b2a03 add bracket reset to match 4 years ago
Ayush Mukherjee e67493c13d refactor fix 4 years ago
Ayush Mukherjee eaea84fde0 fix very fatal issue 4 years ago
Ayush Mukherjee de4ab6f395 fix: populate blue and orange roster data from match 4 years ago
Ayush Mukherjee de86df17ae Merge branch 'feat/current-bool' into 'main'
Feat: Add bool for other overlays

See merge request ayushm99/apl-nuke!2
4 years ago
Ayush Mukherjee 8a18c12909 add new bool for showing up on other overlays 4 years ago
Ayush Mukherjee 3a5defdde4 Merge branch 'fix/recvData' into 'main'
Feat: Stream data by stream-id

See merge request ayushm99/apl-nuke!1
4 years ago
Ayush Mukherjee 4d89438955 return name with token for API; version bump 4 years ago
Ayush Mukherjee 2d9a34f8bc idk 4 years ago
Ayush Mukherjee 5ca90f131a idk 4 years ago
Ayush Mukherjee 2faced9d43 idk 4 years ago
Ayush Mukherjee b7856fa42c idk 4 years ago
Ayush Mukherjee 487f97e7e5 idk 4 years ago
Ayush Mukherjee 496a0b9fff console log incoming sub 4 years ago
Ayush Mukherjee 8d5bc05cf7 handle streams:full properly 4 years ago
Ayush Mukherjee c4c1c86249 add option to get populated data for streams 4 years ago
Ayush Mukherjee 1bf671fdfe model issue 4 years ago
Ayush Mukherjee 4b0860cbf4 model issue 4 years ago
Ayush Mukherjee 398eca33e5 model issue 4 years ago
Ayush Mukherjee 584bdc1863 model issue 4 years ago
Ayush Mukherjee 057d8201fa model issue 4 years ago
Ayush Mukherjee b53b50f831 model issue 4 years ago
Ayush Mukherjee c6d1a74988 model issue 4 years ago
Ayush Mukherjee 8d604819fc model issue 4 years ago
Ayush Mukherjee 98bd4f60b6 model issue 4 years ago
Ayush Mukherjee b6103b43d5 stop throwing pls 4 years ago
Ayush Mukherjee b30712a74a change throw to console warning 4 years ago
Ayush Mukherjee b4d4268e6e fix remove populate 4 years ago
Ayush Mukherjee 4be96cf548 remove required attr for caster/host image 4 years ago
Ayush Mukherjee 2064f0036f change stats to per-team instead of per-player 4 years ago
Ayush Mukherjee 99467f229c implemented per-stream data views 4 years ago

3511
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
{
"name": "nuke",
"version": "1.0.0",
"version": "1.5.0",
"description": "APL Esports' Nuke Server",
"main": "index.js",
"scripts": {
@ -11,17 +11,19 @@
"author": "",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"axios": "^1",
"bufferutil": "^4.0.8",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.1.0",
"mongoose": "^5.11.19",
"morgan": "^1.10.0",
"uuid": "^8.3.2",
"ws": "^7.4.4"
"dotenv": "^8",
"express": "^4",
"helmet": "^7",
"mongoose": "^8",
"morgan": "^1.10",
"utf-8-validate": "^6.0.3",
"uuid": "^9",
"ws": "^8"
},
"devDependencies": {
"nodemon": "^2.0.4"
"nodemon": "^3.0"
}
}

@ -23,6 +23,7 @@ router.post('/', async (req, res) => {
push(id)
res.json({
session: id,
name: r.data.entries[0].name,
})
} else {
res.status(403).json({

@ -4,26 +4,32 @@ const url = require('url')
const app = require('./app')
const { get } = require('./uuids')
const handler = require('./ws/handler')
const { subscribe } = require('./ws/streams')
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
mongoose.connect(process.env.MONGO_URI)
const db = mongoose.connection
db.once('open', () => console.log('Connected to mongodb instance!'))
const port = process.env.PORT || 5000;
wss = new WebSocket.Server({
wss1 = new WebSocket.Server({
noServer: true,
})
wss2 = new WebSocket.Server({
noServer: true,
})
wss.on('connection', (ws, req) => {
wss1.on('connection', (ws, req) => {
const id = req.id
handler(ws, id)
})
wss2.on('connection', (ws, req) => {
subscribe(ws, req.id, req.type)
})
const server = app.listen(port, () => {
console.log(`Express listening: http://localhost:${port}`)
})
@ -32,9 +38,25 @@ server.on('upgrade', (req, socket, head) => {
const pathname = url.parse(req.url).pathname.split('/')
const token = pathname[2]
if (pathname[1] === 'ws' && get(token)) {
wss.handleUpgrade(req, socket, head, (socket) => {
wss1.handleUpgrade(req, socket, head, (socket) => {
req.id = token
wss.emit('connection', socket, req);
wss1.emit('connection', socket, req)
})
} else if (pathname[1] === 'stream') {
if (token != null || token != '' || token != "") {
wss2.handleUpgrade(req, socket, head, (socket) => {
req.id = token
req.type = 'stream'
wss2.emit('connection', socket, req)
})
}
} else if (pathname[1] === 'bracket') {
if (token != null || token != '' || token != "") {
wss2.handleUpgrade(req, socket, head, (socket) => {
req.id = token
req.type = 'bracket'
wss2.emit('connection', socket, req)
})
}
}
})

@ -0,0 +1,26 @@
const { Schema, model } = require('mongoose')
const brackets = new Schema({
name: {
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
event: {
type: Schema.Types.ObjectId,
ref: 'Event',
},
matches: [{
type: Schema.Types.ObjectId,
ref: 'Matches',
}],
})
const Bracket = model('Brackets', brackets)
module.exports = Bracket

@ -9,14 +9,19 @@ const casters = new Schema({
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
twitter: {
type: String,
required: true,
},
image: {
type: String,
required: true,
},
}
});
const Caster = model('Casters', casters)

@ -6,8 +6,18 @@ const events = new mongoose.Schema({
required: true,
unique: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
streams: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Streams',
}]
});
const Event = mongoose.model('Events', events)
const Event = mongoose.model('Event', events)
module.exports = Event

@ -15,8 +15,7 @@ const hosts = new Schema({
},
image: {
type: String,
required: true,
},
}
});
const Host = model('Hosts', hosts)

@ -3,25 +3,29 @@ const { Schema, model } = require('mongoose')
const gameScores = new Schema({
orange: {
type: Number,
required: true,
default: 0,
},
blue: {
type: Number,
required: true,
default : 0,
},
})
const matches = new Schema({
orange: {
type: Schema.Types.ObjectId,
refs: 'Rosters',
ref: 'Rosters',
required: true,
},
blue: {
type: Schema.Types.ObjectId,
refs: 'Rosters',
ref: 'Rosters',
required: true,
},
current: {
type: Boolean,
default: false,
},
started: {
type: Boolean,
required: true,
@ -30,10 +34,20 @@ const matches = new Schema({
type: Boolean,
required: true,
},
reset: {
type: Boolean,
default: false,
},
type: {
type: String,
required: true,
},
type_arabic: {
type: String,
},
type_jpn: {
type: String,
},
bestOf: {
type: String,
required: true,
@ -41,17 +55,26 @@ const matches = new Schema({
series: {
orange: {
type: Number,
required: true,
default: 0,
},
blue: {
type: Number,
required: true,
default: 0,
},
},
resets: {
orange: {
type: Number,
default: 0,
},
blue: {
type: Number,
default: 0,
},
},
games: {
type: [gameScores],
required: true,
},
}
})
const Match = model('Matches', matches)

@ -3,23 +3,23 @@ const { Schema, model } = require('mongoose')
const stats = new Schema({
goals: {
type: Number,
required: true,
default: 0,
},
assists: {
type: Number,
required: true,
default: 0,
},
saves: {
type: Number,
required: true,
default: 0,
},
shots: {
type: Number,
required: true,
default: 0,
},
demos: {
type: Number,
required: true,
default: 0,
},
})
@ -28,34 +28,39 @@ const players = new Schema({
type: String,
required: true,
},
account: {
name_arabic: {
type: String,
required: true,
},
stats: {
type: [stats],
name_jpn: {
type: String,
},
account: {
type: String,
required: true,
},
})
const rosters = new Schema({
event: {
type: Schema.Types.ObjectId,
ref: 'Events',
required: true,
},
name: {
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
logo: {
type: String,
required: true,
},
players: {
type: [players],
required: true,
},
stats: {
type: stats,
}
})
const Roster = model('Rosters', rosters)

@ -0,0 +1,67 @@
const { Schema, model } = require('mongoose')
const stats = new Schema({
name: {
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
image: {
type: String,
required: true,
},
image_full: {
type: Boolean,
default: false,
required: true,
},
win_name: {
type: String,
required: true,
},
win: {
type: String,
required: true,
},
goals_name: {
type: String,
required: true,
},
goals: {
type: String,
required: true,
},
shots_name: {
type: String,
required: true,
},
shots: {
type: String,
required: true,
},
saves_name: {
type: String,
required: true,
},
saves: {
type: String,
required: true,
},
assists_name: {
type: String,
required: true,
},
assists: {
type: String,
required: true,
},
})
const Stat = model('Stats', stats)
module.exports = Stat

@ -5,16 +5,32 @@ const streams = new Schema({
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
event: {
type: Schema.Types.ObjectId,
refs: 'Events',
requried: true,
},
matches: {
type: [Schema.Types.ObjectId],
refs: 'matches',
requried: true,
ref: 'Event',
},
matches: [{
type: Schema.Types.ObjectId,
ref: 'Matches',
}],
casters: [{
type: Schema.Types.ObjectId,
ref: 'Casters',
}],
hosts: [{
type: Schema.Types.ObjectId,
ref: 'Casters',
}],
stats: [{
type: Schema.Types.ObjectId,
ref: 'Stats'
}],
})
const Stream = model('Streams', streams)

@ -2,9 +2,11 @@ const channels = [
'rosters',
'matches',
'streams',
'stats',
'events',
'casters',
'hosts',
'brackets',
];
const events = [
@ -14,7 +16,9 @@ const events = [
'delete',
];
const channelEvents = [];
const channelEvents = [
'streams:full',
];
channels.forEach((c) => {
events.forEach((e) => {

@ -1,16 +1,18 @@
const events = require('../models/events')
const rosters = require('../models/rosters')
const matches = require('../models/matches')
const stats = require('../models/stats')
const streams = require('../models/streams')
const casters = require('../models/casters')
const hosts = require('../models/hosts')
const brackets = require('../models/brackets')
const eventFns = {
getAll: async () => {
return await events.find().exec()
return await events.find().populate('streams').exec()
},
getById: async (id) => {
return await events.findById(id).exec()
return await events.findById(id).populate('streams').exec()
},
update: async(id, data) => {
return await events.findByIdAndUpdate(id, data).exec()
@ -21,12 +23,9 @@ const eventFns = {
create: async (data) => {
try {
const ev = new events(data)
ev.save((err) => {
if (err)
throw err;
})
await ev.save();
} catch (e) {
throw e;
console.warn(e)
}
}
}
@ -47,22 +46,19 @@ const rosterFns = {
create: async (data) => {
try {
const ev = new rosters(data)
ev.save((err) => {
if (err)
throw err;
})
await ev.save();
} catch (e) {
throw e;
console.warn(e)
}
}
}
const matchFns = {
getAll: async () => {
return await matches.find().exec()
return await matches.find().populate('orange').populate('blue').exec()
},
getById: async (id) => {
return await matches.findById(id).exec()
return await matches.findById(id).populate('orange').populate('blue').exec()
},
update: async(id, data) => {
return await matches.findByIdAndUpdate(id, data).exec()
@ -73,12 +69,32 @@ const matchFns = {
create: async (data) => {
try {
const ev = new matches(data)
ev.save((err) => {
if (err)
throw err;
})
await ev.save();
} catch (e) {
throw e;
console.warn(e)
}
}
}
const statsFns = {
getAll: async () => {
return await stats.find().exec()
},
getById: async (id) => {
return await stats.findById(id).exec()
},
update: async(id, data) => {
return await stats.findByIdAndUpdate(id, data).exec()
},
delete: async (id) => {
return await stats.findByIdAndDelete(id).exec()
},
create: async (data) => {
try {
const ev = new stats(data)
await ev.save();
} catch (e) {
console.warn(e)
}
}
}
@ -87,8 +103,17 @@ const streamFns = {
getAll: async () => {
return await streams.find().exec()
},
getAllPop: async () => {
return await streams.find().populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').populate('stats').lean().exec()
},
getById: async (id) => {
return await streams.findById(id).exec()
return await streams.findById(id).populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').populate('stats').lean().exec()
},
update: async(id, data) => {
return await streams.findByIdAndUpdate(id, data).exec()
@ -99,12 +124,9 @@ const streamFns = {
create: async (data) => {
try {
const ev = new streams(data)
ev.save((err) => {
if (err)
throw err;
})
await ev.save();
} catch (e) {
throw e;
console.warn(e)
}
}
}
@ -125,12 +147,9 @@ const casterFns = {
create: async (data) => {
try {
const ev = new casters(data)
ev.save((err) => {
if (err)
throw err;
})
await ev.save();
} catch (e) {
throw e;
console.warn(e)
}
}
}
@ -151,12 +170,41 @@ const hostFns = {
create: async (data) => {
try {
const ev = new hosts(data)
ev.save((err) => {
if (err)
throw err;
})
await ev.save();
} catch (e) {
console.warn(e)
}
}
}
const bracketFns = {
getAll: async () => {
return await brackets.find().exec()
},
getAllPop: async () => {
return await brackets.find().populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).exec()
},
getById: async (id) => {
return await brackets.findById(id).populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).exec()
},
update: async(id, data) => {
return await brackets.findByIdAndUpdate(id, data).exec()
},
delete: async (id) => {
return await brackets.findByIdAndDelete(id).exec()
},
create: async (data) => {
try {
const ev = new brackets(data)
await ev.save();
} catch (e) {
throw e;
console.warn(e)
}
}
}
@ -165,7 +213,9 @@ module.exports = {
'events': eventFns,
'rosters': rosterFns,
'matches': matchFns,
'stats': statsFns,
'streams': streamFns,
'casters': casterFns,
'hosts': hostFns,
'brackets': bracketFns,
}

@ -1,6 +1,7 @@
const { pop } = require('../uuids')
const { channelEvents } = require('./channels')
const crud = require('./crud')
const { recvUpdate } = require('./streams')
const connections = {};
@ -12,7 +13,7 @@ const handler = (ws, id) => {
ws.send(JSON.stringify({
event: 'info',
data: 'Welcome to APL Nuke v1.0.0!'
data: 'Welcome to APL Nuke v1.1.0!'
}))
ws.on('message', (msg) => handleMsg(msg, id))
@ -26,25 +27,42 @@ const handleMsg = async (msg, id) => {
try {
const d = JSON.parse(msg)
if (d.hasOwnProperty('subscribe') && channelEvents.indexOf(d.subscribe) !== -1) {
console.log('received sub for ', d.subscribe)
const channel = d.subscribe.split(':')[0]
connections[id].events.push(d.subscribe)
connections[id].connection.send(JSON.stringify(await crud[channel].getAll()))
const dm = {
event: `${channel}:read`,
data: await crud[channel].getAll(),
}
if (channel === 'streams' && d.subscribe === 'streams:full') {
dm.event = 'streams:full'
dm.data = await crud[channel].getAllPop()
}
try {
connections[id].connection.send(JSON.stringify(dm))
} catch (e) {
console.warn(e)
}
} else if (d.hasOwnProperty('event') && channelEvents.indexOf(d.event) !== -1) {
const ev = d.event.split(':')
const channel = ev[0]
const event = ev[1]
console.log(`received event for ${channel} with data %s`, d.data)
let dm;
switch (event) {
case 'create':
await crud[channel].create(d.data)
dm = await crud[channel].create(d.data)
recvUpdate(channel, dm)
fanoutMsg(channel, await crud[channel].getAll())
break;
case 'update':
await crud[channel].update(d.data.id, d.data.data)
dm = await crud[channel].update(d.data.id, d.data.data)
recvUpdate(channel, dm)
fanoutMsg(channel, await crud[channel].getAll())
break;
case 'delete':
await crud[channel].delete(d.data.id)
recvUpdate(channel, 'delete')
fanoutMsg(channel, await crud[channel].getAll())
break;
}
@ -55,9 +73,21 @@ const handleMsg = async (msg, id) => {
}
const fanoutMsg = (channel, data) => {
Object.keys(connections).forEach((k) => {
Object.keys(connections).forEach( async (k) => {
if (connections[k].events.indexOf(`${channel}:read`) !== -1) {
connections[k].connection.send(JSON.stringify(data))
const d = {
event: `${channel}:read`,
data,
}
connections[k].connection.send(JSON.stringify(d))
if (connections[k].events.indexOf('streams:full') !== -1) {
const m = await crud['streams'].getAllPop()
const d = {
event: 'streams:full',
data: m,
}
connections[k].connection.send(JSON.stringify(d))
}
}
})
}

@ -0,0 +1,56 @@
const { v4 } = require('uuid')
const crud = require('./crud')
const connections = {}
const subscribe = (ws, tid, type) => {
const id = v4()
connections[id] = {
connection: ws,
tid,
type,
}
ws.send(JSON.stringify({
event: 'info',
data: 'Welcome to APL Nuke v1.1.0!',
}))
sendInitial(id)
ws.on('close', () => {
delete connections[id]
})
}
const recvUpdate = async (channel, data) => {
Object.keys(connections).forEach((k) => {
sendInitial(k)
})
}
const sendInitial = async (id) => {
try {
const c = connections[id]
if (c.type === 'stream') {
const stream = await crud['streams'].getById(c.tid)
c.connection.send(JSON.stringify({
event: 'streams:read',
data: stream,
}))
} else if (c.type === 'bracket') {
const bracket = await crud['brackets'].getById(c.tid)
c.connection.send(JSON.stringify({
event: 'brackets:read',
data: bracket,
}))
}
} catch (e) {
console.warn(e)
}
}
module.exports = {
subscribe,
recvUpdate,
}
Loading…
Cancel
Save