smnmpp-server/protocol/n.js

26 lines
1.3 KiB
JavaScript

module.exports.run = async (ws,user,db,msg,fun,users,connections) => {
if (!user.connected || !user.channel) return;
if (!user.quotas.note.try()) return;
var keys = ["a-1","as-1","b-1","c0","cs0","d0","ds0","e0","f0","fs0","g0","gs0","a0","as0","b0","c1","cs1","d1","ds1","e1","f1","fs1","g1","gs1","a1","as1","b1","c2","cs2","d2","ds2","e2","f2","fs2","g2","gs2","a2","as2","b2","c3","cs3","d3","ds3","e3","f3","fs3","g3","gs3","a3","as3","b3","c4","cs4","d4","ds4","e4","f4","fs4","g4","gs4","a4","as4","b4","c5","cs5","d5","ds5","e5","f5","fs5","g5","gs5","a5","as5","b5","c6","cs6","d6","ds6","e6","f6","fs6","g6","gs6","a6","as6","b6","c7"]
if ((msg.n.length > 1000 || msg.n.length == 0) && !users[user._id].notebypass) return;
var currentNotes = []
msg.n.forEach(note => {
try {
if (note.s != 1) {
if (note.v > 1 || note.v <= 0) return;
}
if (!keys.includes(note.n)) return;
if (note.d) {
if (typeof note.d !== "number" || Math.abs(note.d) > 200) return
}
currentNotes.push({n: note.n, v: note.v, s: note.s, d: Math.floor(note.d ? note.d : 0)})
} catch (error) {
//j
}
})
if (currentNotes.length == 0) return;
connections.filter(a => a.user.channel === user.channel && a.user._id !== user._id).forEach(a => a.sendData({m: "n", n: currentNotes,t: Date.now(), p: user._id}))
user.quotas.note.spend(1)
}
module.exports.name = "n"