Compare commits

..

21 Commits
v1.3.1 ... main

3511
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
{
"name": "nuke",
"version": "1.1.9",
"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"
}
}

@ -6,11 +6,7 @@ const { get } = require('./uuids')
const handler = require('./ws/handler')
const { subscribe } = require('./ws/streams')
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
mongoose.connect(process.env.MONGO_URI)
const db = mongoose.connection
db.once('open', () => console.log('Connected to mongodb instance!'))
@ -31,8 +27,7 @@ wss1.on('connection', (ws, req) => {
})
wss2.on('connection', (ws, req) => {
const id = req.id
subscribe(ws, id)
subscribe(ws, req.id, req.type)
})
const server = app.listen(port, () => {
@ -51,6 +46,15 @@ server.on('upgrade', (req, socket, head) => {
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,6 +9,12 @@ const casters = new Schema({
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
twitter: {
type: String,
required: true,

@ -5,7 +5,17 @@ const events = new mongoose.Schema({
type: String,
required: true,
unique: true,
}
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
streams: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Streams',
}]
});
const Event = mongoose.model('Event', events)

@ -42,6 +42,12 @@ const matches = new Schema({
type: String,
required: true,
},
type_arabic: {
type: String,
},
type_jpn: {
type: String,
},
bestOf: {
type: String,
required: true,

@ -28,6 +28,12 @@ const players = new Schema({
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
account: {
type: String,
required: true,
@ -39,6 +45,12 @@ const rosters = new Schema({
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
logo: {
type: String,
required: true,

@ -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,6 +5,12 @@ const streams = new Schema({
type: String,
required: true,
},
name_arabic: {
type: String,
},
name_jpn: {
type: String,
},
event: {
type: Schema.Types.ObjectId,
ref: 'Event',
@ -19,7 +25,11 @@ const streams = new Schema({
}],
hosts: [{
type: Schema.Types.ObjectId,
ref: 'Hosts',
ref: 'Casters',
}],
stats: [{
type: Schema.Types.ObjectId,
ref: 'Stats'
}],
})

@ -2,9 +2,11 @@ const channels = [
'rosters',
'matches',
'streams',
'stats',
'events',
'casters',
'hosts',
'brackets',
];
const events = [

@ -1,9 +1,11 @@
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 () => {
@ -21,10 +23,7 @@ const eventFns = {
create: async (data) => {
try {
const ev = new events(data)
ev.save((err) => {
if (err)
console.warn(err)
})
await ev.save();
} catch (e) {
console.warn(e)
}
@ -47,10 +46,7 @@ const rosterFns = {
create: async (data) => {
try {
const ev = new rosters(data)
ev.save((err) => {
if (err)
console.warn(err)
})
await ev.save();
} catch (e) {
console.warn(e)
}
@ -73,10 +69,30 @@ const matchFns = {
create: async (data) => {
try {
const ev = new matches(data)
ev.save((err) => {
if (err)
console.warn(err)
})
await ev.save();
} catch (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)
}
@ -91,13 +107,13 @@ const streamFns = {
return await streams.find().populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').exec()
}).populate('casters').populate('hosts').populate('stats').lean().exec()
},
getById: async (id) => {
return await streams.findById(id).populate('event').populate({
path: 'matches',
populate: [{ path: 'orange' }, { path: 'blue' }],
}).populate('casters').populate('hosts').exec()
}).populate('casters').populate('hosts').populate('stats').lean().exec()
},
update: async(id, data) => {
return await streams.findByIdAndUpdate(id, data).exec()
@ -108,10 +124,7 @@ const streamFns = {
create: async (data) => {
try {
const ev = new streams(data)
ev.save((err) => {
if (err)
console.warn(err)
})
await ev.save();
} catch (e) {
console.warn(e)
}
@ -134,10 +147,7 @@ const casterFns = {
create: async (data) => {
try {
const ev = new casters(data)
ev.save((err) => {
if (err)
console.warn(err)
})
await ev.save();
} catch (e) {
console.warn(e)
}
@ -160,10 +170,39 @@ const hostFns = {
create: async (data) => {
try {
const ev = new hosts(data)
ev.save((err) => {
if (err)
console.warn(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) {
console.warn(e)
}
@ -174,7 +213,9 @@ module.exports = {
'events': eventFns,
'rosters': rosterFns,
'matches': matchFns,
'stats': statsFns,
'streams': streamFns,
'casters': casterFns,
'hosts': hostFns,
'brackets': bracketFns,
}

@ -38,7 +38,11 @@ const handleMsg = async (msg, id) => {
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]

@ -3,11 +3,12 @@ const crud = require('./crud')
const connections = {}
const subscribe = (ws, sid) => {
const subscribe = (ws, tid, type) => {
const id = v4()
connections[id] = {
connection: ws,
streamid: sid,
tid,
type,
}
ws.send(JSON.stringify({
@ -22,13 +23,6 @@ const subscribe = (ws, sid) => {
})
}
const cModel = {
'events': 'event',
'matches': 'matches',
'casters': 'casters',
'hosts': 'hosts',
}
const recvUpdate = async (channel, data) => {
Object.keys(connections).forEach((k) => {
sendInitial(k)
@ -36,12 +30,24 @@ const recvUpdate = async (channel, data) => {
}
const sendInitial = async (id) => {
try {
const c = connections[id]
const stream = await crud['streams'].getById(c.streamid)
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 = {

Loading…
Cancel
Save