diff --git a/Utils/BitWiseTesting.js b/Utils/BitWiseTesting.js index 3489e30..c837e96 100644 --- a/Utils/BitWiseTesting.js +++ b/Utils/BitWiseTesting.js @@ -1,12 +1,112 @@ -if(Connis_Channel_Perms & View_Channel) +const ChannelBits = require(`./api/BitFlags/PermissionBitfields`).codes; +const { PerformanceObserver, performance } = require('perf_hooks'); +/* + 0th bit = view channel + 1st bit = send messages + 2nd bit = manage messages + 00000000000000000000000000000000 +*/ +function isBitSet(b,pos) { - console.log("COnni can view the channel"); + return (b.field & (1 << pos)) != 0; } -if(Connis_Channel_Perms & Send_Messages) +function setBit(b,pos) { - console.log("COnni can speak in the channel"); + b.field |= (1 << pos); } -if(Connis_Channel_Perms & Ping_Messages) +function clearBit(b,pos) { - console.log("COnni can ping in the channel"); + b.field = ~(1 << pos); } + + + + +var ChannelObj = +{ + ChannelID:"", + Name:"", + Description:"", + RoleOverrides: + [ + { + RoleID:"", + VIEW_CHANNEL: true, + MANAGE_CHANNEL: null, + MANAGE_PERMISSION: null, + CREATE_INVITE: null, + SEND_MESSAGES: true, + } + ] +}; + +var RoleObject = +{ + RoleID:"", + RoleName:"", + Colour:{r:255,g:0,b:255,a:255}, + Permissions: + { + VIEW_CHANNEL: true, + MANAGE_CHANNEL: null, + MANAGE_PERMISSION: null, + CREATE_INVITE: null, + SEND_MESSAGES: true, + } +} + + +/* + + + +*/ + + + + +/* +let start = (new Date()).getTime() +let pog =0; +/*setBit(testing,0); +setBit(testing,1); +var testing = {field:3}; + +for(var i = 0; i < 100000000; ++i) +{ + if(isBitSet(testing,0)) + { + ++pog; + //console.log("Conni can view the channel"); + } + if(isBitSet(testing,1)) + { + ++pog; + //console.log("Conni can Send_Messages in the channel"); + } + if(isBitSet(testing,2)) + { + ++pog; + //console.log("Conni can Manage_Messages the channel"); + } +} +let end = (new Date()).getTime() +var duration = end-start; +console.log(duration, "ms"); +console.log(pog); + + + + +console.log(ConnisChannelPerms.field & 1<<1 ); +setBit(ConnisChannelPerms,2); +clearBit(ConnisChannelPerms,1); +clearBit(ConnisChannelPerms,0); +console.log(`field = ${ConnisChannelPerms.field}`); + +console.log((ConnisChannelPerms.field & ChannelBits.Manage_Messages) ? "can manage messages in the channel" : "cant manage messages"); +setHexBit(ConnisChannelPerms,) +console.log(ConnisChannelPerms.field); +console.log((ConnisChannelPerms.field & ChannelBits.Manage_Messages) ? "can manage messages in the channel" : "cant manage messages"); +*/ + diff --git a/Utils/api/BitFlags/ChannelBits.js b/Utils/api/BitFlags/ChannelBits.js deleted file mode 100644 index 8902d64..0000000 --- a/Utils/api/BitFlags/ChannelBits.js +++ /dev/null @@ -1,5 +0,0 @@ -exports.codes = { - View_Channel : 0x00001, - Send_Messages : 0x00010, - Manage_Messages : 0x00100 -}; \ No newline at end of file diff --git a/Utils/api/BitFlags/PermissionBitfields.js b/Utils/api/BitFlags/PermissionBitfields.js new file mode 100644 index 0000000..5102f18 --- /dev/null +++ b/Utils/api/BitFlags/PermissionBitfields.js @@ -0,0 +1,17 @@ +exports.codes = { + //#region ChannelPerms + View_Channel : { + field :0x1, + pos :0 + }, + Send_Messages : { + field :0x10, + pos :1 + }, + Manage_Messages : { + field :0x100, + pos :2 + }, + //#endregion + +}; \ No newline at end of file diff --git a/Utils/api/controllers/memberController.js b/Utils/api/controllers/memberController.js index 38cd73f..3149364 100644 --- a/Utils/api/controllers/memberController.js +++ b/Utils/api/controllers/memberController.js @@ -30,7 +30,7 @@ exports.createNewMember = (req, res) => { }); }; exports.getMemberRecord = (req, res) => { - Members.find({MemberID: req.params.MemberID}, (err, Response) => { + Members.find({id: req.params.MemberID}, (err, Response) => { if (err) { res.status(codes.Bad_Request); res.send(err); @@ -38,11 +38,10 @@ exports.getMemberRecord = (req, res) => { res.json(Response); }); }; -exports.update_a_member = (req, res) => { +exports.updateMember = (req, res) => { Members.findOneAndUpdate( { - MemberID: req.params.MemberID, - Token: req.body.token + id: req.params.MemberID }, req.body, {new: true}, (err, Response) => { if (err) { res.status(codes.Bad_Request); @@ -53,8 +52,8 @@ exports.update_a_member = (req, res) => { res.json(Response); }); }; -exports.delete_a_member = (req, res) => { - Members.find({MemberID: req.params.MemberID}, (err, Response) => { +exports.deleteMember = (req, res) => { + Members.find({id: req.params.MemberID}, (err, Response) => { if (err) { res.send(err); } @@ -71,7 +70,7 @@ exports.delete_a_member = (req, res) => { } Members.deleteOne( { - MemberID: req.params.MemberID + id: req.params.MemberID }, (err, DeleteResponse) => { if (err) res.send(err); diff --git a/Utils/api/routes/routes.js b/Utils/api/routes/routes.js index 1d31021..0d4f74d 100644 --- a/Utils/api/routes/routes.js +++ b/Utils/api/routes/routes.js @@ -6,10 +6,10 @@ module.exports = (app) => { .post(MemberList.createNewMember); app.route('/api/member/:MemberID') .get(MemberList.getMemberRecord) - .put(MemberList.update_a_member) - .delete(MemberList.delete_a_member); + .put(MemberList.updateMember) + .delete(MemberList.deleteMember); app.route('/api/member/:MemberID') .get(MemberList.getMemberRecord) - .put(MemberList.update_a_member) - .delete(MemberList.delete_a_member); + .put(MemberList.updateMember) + .delete(MemberList.deleteMember); }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 76a0d27..18a6d37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "colors": "^1.4.0", "dotenv": "^8.2.0", "express": "^4.17.1", - "mongoose": "^5.12.2" + "mongoose": "^5.12.2", + "perf_hooks": "^0.0.1" } }, "node_modules/@types/bson": { @@ -514,6 +515,11 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, + "node_modules/perf_hooks": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/perf_hooks/-/perf_hooks-0.0.1.tgz", + "integrity": "sha512-qG/D9iA4KDme+KF4vCObJy6Bouu3BlQnmJ8jPydVPm32NJBD9ZK1ZNgXSYaZKHkVC1sKSqUiLgFvAZPUiIEnBw==" + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -1162,6 +1168,11 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, + "perf_hooks": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/perf_hooks/-/perf_hooks-0.0.1.tgz", + "integrity": "sha512-qG/D9iA4KDme+KF4vCObJy6Bouu3BlQnmJ8jPydVPm32NJBD9ZK1ZNgXSYaZKHkVC1sKSqUiLgFvAZPUiIEnBw==" + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", diff --git a/package.json b/package.json index b4a905e..697f537 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,9 @@ "description": "", "main": "index.js", "scripts": { - "start": "nodemon index.js", - "dev": "nodemon index.js" + "start": "nodemon index.js testing", + "release": "node index.js release", + "dev": "nodemon index.js dev" }, "repository": { "type": "git",