add ranking mode switching
This commit is contained in:
parent
1dc1742fa0
commit
17f9605e8f
3 changed files with 157 additions and 76 deletions
|
@ -15,19 +15,26 @@ module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false
|
||||||
case "!help":
|
case "!help":
|
||||||
// This is terrible
|
// This is terrible
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
responseMessage = "Commands:" +
|
responseMessage = "Commands with an * next to them have a sub help section" +
|
||||||
"\n!help - Shows this message" +
|
"\n!help - Shows this message" +
|
||||||
"\n!roll - Rolls a random number or a number between 0 and a given number" +
|
"\n!roll - Rolls a random number or a number between 0 and a given number" +
|
||||||
"\n - Submenus:" +
|
"\n!ranking* - Sets your perfered ranking type" +
|
||||||
"\n mp - Shows information about all multiplayer commands" +
|
"\n!mp* - Shows information about all multiplayer commands" +
|
||||||
"\n admin - Shows information about all admin commands";
|
"\n!admin* - Shows information about all admin commands";
|
||||||
} else {
|
} else {
|
||||||
switch (args[1]) {
|
switch (args[1]) {
|
||||||
|
case "ranking":
|
||||||
|
responseMessage = "Ranking Commands:" +
|
||||||
|
"\n!ranking pp - Sets your ranking type to pp" +
|
||||||
|
"\n!ranking score - Sets your ranking type to score" +
|
||||||
|
"\n!ranking acc - Sets your ranking type to accuracy";
|
||||||
|
break;
|
||||||
|
|
||||||
case "mp":
|
case "mp":
|
||||||
responseMessage = "Multiplayer Commands:" +
|
responseMessage = "Multiplayer Commands:" +
|
||||||
"\n!mp start - Starts a multiplayer match with a delay" +
|
"\n!mp start - Starts a multiplayer match with a delay" +
|
||||||
"\n!mp abort - Aborts the currently running multiplayer match" +
|
"\n!mp abort - Aborts the currently running multiplayer match" +
|
||||||
"\n!mp obr - Enables Battle Royale mode";
|
"\n!mp obr - Enables Battle Royale mode";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "admin":
|
case "admin":
|
||||||
|
@ -41,6 +48,32 @@ module.exports = function(User, Message, Stream, IsCalledFromMultiplayer = false
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "!ranking":
|
||||||
|
if (args.length == 1) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
switch (args[1]) {
|
||||||
|
case "pp":
|
||||||
|
responseMessage = "Set ranking mode to pp";
|
||||||
|
User.rankingMode = 0;
|
||||||
|
User.getNewUserInformationFromDatabase();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "score":
|
||||||
|
responseMessage = "Set ranking mode to score";
|
||||||
|
User.rankingMode = 1;
|
||||||
|
User.getNewUserInformationFromDatabase();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "acc":
|
||||||
|
responseMessage = "Set ranking mode to accuracy";
|
||||||
|
User.rankingMode = 2;
|
||||||
|
User.getNewUserInformationFromDatabase();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "!roll":
|
case "!roll":
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
responseMessage = User.username + " rolled " + maths.randInt(0, 65535);
|
responseMessage = User.username + " rolled " + maths.randInt(0, 65535);
|
||||||
|
|
|
@ -25,7 +25,7 @@ module.exports = function(currentUser, id = 0, sendImmidiate = true) {
|
||||||
playCount: User.playCount,
|
playCount: User.playCount,
|
||||||
totalScore: User.totalScore,
|
totalScore: User.totalScore,
|
||||||
rank: User.rank,
|
rank: User.rank,
|
||||||
performance: User.pp
|
performance: (currentUser.rankingMode == 0 ? User.pp : 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
osuPacketWriter.HandleOsuUpdate(UserStatusObject);
|
osuPacketWriter.HandleOsuUpdate(UserStatusObject);
|
||||||
|
|
188
server/User.js
188
server/User.js
|
@ -1,87 +1,135 @@
|
||||||
const StatusUpdate = require("./Packets/StatusUpdate.js");
|
const StatusUpdate = require("./Packets/StatusUpdate.js");
|
||||||
|
|
||||||
module.exports = class {
|
module.exports = class {
|
||||||
constructor(id, username, uuid, connectTime, isTourneyUser = false) {
|
constructor(id, username, uuid, connectTime, isTourneyUser = false) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.connectTime = connectTime;
|
this.connectTime = connectTime;
|
||||||
this.queue = new Buffer.alloc(0);
|
this.queue = new Buffer.alloc(0);
|
||||||
|
|
||||||
this.playMode = 0;
|
// Binato specific
|
||||||
this.countryID = 0;
|
this.rankingMode = 0;
|
||||||
this.spectators = [];
|
|
||||||
this.spectating = 0;
|
|
||||||
this.location = [0,0];
|
|
||||||
this.joinedChannels = [];
|
|
||||||
|
|
||||||
// Presence data
|
this.playMode = 0;
|
||||||
this.actionID = 0;
|
this.countryID = 0;
|
||||||
this.actionText = "";
|
this.spectators = [];
|
||||||
this.actionMods = 0;
|
this.spectating = 0;
|
||||||
this.beatmapChecksum = "";
|
this.location = [0,0];
|
||||||
this.beatmapID = 0;
|
this.joinedChannels = [];
|
||||||
this.currentMods = 0;
|
|
||||||
|
|
||||||
// Cached db data
|
// Presence data
|
||||||
this.rankedScore = 0;
|
this.actionID = 0;
|
||||||
this.accuracy = 0;
|
this.actionText = "";
|
||||||
this.playCount = 0;
|
this.actionMods = 0;
|
||||||
this.totalScore = 0;
|
this.beatmapChecksum = "";
|
||||||
this.rank = 0;
|
this.beatmapID = 0;
|
||||||
this.pp = 0;
|
this.currentMods = 0;
|
||||||
|
|
||||||
// Multiplayer data
|
// Cached db data
|
||||||
this.currentMatch = null;
|
this.rankedScore = 0;
|
||||||
this.matchSlotId = -1;
|
this.accuracy = 0;
|
||||||
|
this.playCount = 0;
|
||||||
|
this.totalScore = 0;
|
||||||
|
this.rank = 0;
|
||||||
|
this.pp = 0;
|
||||||
|
|
||||||
this.isTourneyUser = isTourneyUser;
|
// Multiplayer data
|
||||||
}
|
this.currentMatch = null;
|
||||||
|
this.matchSlotId = -1;
|
||||||
|
|
||||||
// Adds new actions to the user's queue
|
this.isTourneyUser = isTourneyUser;
|
||||||
addActionToQueue(newData) {
|
}
|
||||||
this.queue = Buffer.concat([this.queue, newData], this.queue.length + newData.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updates the user's current action
|
// Adds new actions to the user's queue
|
||||||
updatePresence(action) {
|
addActionToQueue(newData) {
|
||||||
this.actionID = action.status;
|
this.queue = Buffer.concat([this.queue, newData], this.queue.length + newData.length);
|
||||||
this.actionText = action.statusText;
|
}
|
||||||
this.beatmapChecksum = action.beatmapChecksum;
|
|
||||||
this.currentMods = action.currentMods;
|
|
||||||
this.actionMods = action.currentMods;
|
|
||||||
this.playMode = action.playMode;
|
|
||||||
this.beatmapID = action.beatmapId;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the user's score information from the database and caches it
|
// Updates the user's current action
|
||||||
async getNewUserInformationFromDatabase() {
|
updatePresence(action) {
|
||||||
const userScoreDB = await global.DatabaseHelper.query(`SELECT * FROM users_modes_info WHERE user_id = ${this.id} AND mode_id = ${this.playMode} LIMIT 1`);
|
this.actionID = action.status;
|
||||||
const userRankDB = await global.DatabaseHelper.query(`SELECT user_id, pp_raw FROM users_modes_info WHERE mode_id = ${this.playMode} ORDER BY pp_raw DESC`);
|
this.actionText = action.statusText;
|
||||||
|
this.beatmapChecksum = action.beatmapChecksum;
|
||||||
|
this.currentMods = action.currentMods;
|
||||||
|
this.actionMods = action.currentMods;
|
||||||
|
this.playMode = action.playMode;
|
||||||
|
this.beatmapID = action.beatmapId;
|
||||||
|
}
|
||||||
|
|
||||||
if (userScoreDB == null || userRankDB == null) throw "fuck";
|
// Gets the user's score information from the database and caches it
|
||||||
|
async getNewUserInformationFromDatabase(forceUpdate = false) {
|
||||||
|
const userScoreDB = await global.DatabaseHelper.query(`SELECT * FROM users_modes_info WHERE user_id = ${this.id} AND mode_id = ${this.playMode} LIMIT 1`);
|
||||||
|
let userRankDB = null;
|
||||||
|
switch (this.rankingMode) {
|
||||||
|
case 0:
|
||||||
|
userRankDB = await global.DatabaseHelper.query(`SELECT user_id, pp_raw FROM users_modes_info WHERE mode_id = ${this.playMode} ORDER BY pp_raw DESC`);
|
||||||
|
break;
|
||||||
|
|
||||||
let userScoreUpdate = false;
|
case 1:
|
||||||
if (this.pp != userScoreDB.pp_raw) {
|
userRankDB = await global.DatabaseHelper.query(`SELECT user_id, ranked_score FROM users_modes_info WHERE mode_id = ${this.playMode} ORDER BY ranked_score DESC`);
|
||||||
userScoreUpdate = true;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
this.rankedScore = userScoreDB.ranked_score;
|
case 2:
|
||||||
this.totalScore = userScoreDB.total_score;
|
userRankDB = await global.DatabaseHelper.query(`SELECT user_id, avg_accuracy FROM users_modes_info WHERE mode_id = ${this.playMode} ORDER BY avg_accuracy DESC`);
|
||||||
this.accuracy = userScoreDB.avg_accuracy;
|
break;
|
||||||
this.playCount = userScoreDB.playcount;
|
}
|
||||||
for (let i = 0; i < userRankDB.length; i++) {
|
|
||||||
if (userRankDB[i]["user_id"] == this.id) this.rank = i + 1;
|
|
||||||
}
|
|
||||||
this.pp = userScoreDB.pp_raw;
|
|
||||||
|
|
||||||
if (userScoreUpdate) {
|
if (userScoreDB == null || userRankDB == null) throw "fuck";
|
||||||
StatusUpdate(this, this.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clears out the user's queue
|
let userScoreUpdate = false;
|
||||||
clearQueue() {
|
if (forceUpdate) {
|
||||||
this.queue = new Buffer.alloc(0);
|
userScoreUpdate = true;
|
||||||
}
|
} else {
|
||||||
|
switch (this.rankingMode) {
|
||||||
|
case 0:
|
||||||
|
if (this.pp != userScoreDB.pp_raw) {
|
||||||
|
userScoreUpdate = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
if (this.rankedScore != userScoreDB.ranked_score) {
|
||||||
|
userScoreUpdate = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if (this.accuracy != userScoreDB.avg_accuracy) {
|
||||||
|
userScoreUpdate = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rankedScore = userScoreDB.ranked_score;
|
||||||
|
this.totalScore = userScoreDB.total_score;
|
||||||
|
this.accuracy = userScoreDB.avg_accuracy;
|
||||||
|
this.playCount = userScoreDB.playcount;
|
||||||
|
for (let i = 0; i < userRankDB.length; i++) {
|
||||||
|
if (userRankDB[i]["user_id"] == this.id) this.rank = i + 1;
|
||||||
|
}
|
||||||
|
switch (this.rankingMode) {
|
||||||
|
case 0:
|
||||||
|
this.pp = userScoreDB.pp_raw;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
this.pp = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
this.pp = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userScoreUpdate) {
|
||||||
|
StatusUpdate(this, this.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clears out the user's queue
|
||||||
|
clearQueue() {
|
||||||
|
this.queue = new Buffer.alloc(0);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue