2020-11-03 02:08:57 +00:00
const StatusUpdate = require ( "./Packets/StatusUpdate.js" ) ;
2020-08-27 13:09:35 +01:00
module . exports = class {
constructor ( id , username , uuid , connectTime ) {
this . id = id ;
this . username = username ;
this . uuid = uuid ;
this . connectTime = connectTime ;
this . queue = new Buffer . alloc ( 0 ) ;
this . playMode = 0 ;
this . countryID = 0 ;
this . spectators = [ ] ;
this . spectating = 0 ;
this . location = [ 0 , 0 ] ;
this . joinedChannels = [ ] ;
// Presence data
this . actionID = 0 ;
this . actionText = "" ;
this . actionMods = 0 ;
this . beatmapChecksum = "" ;
this . beatmapID = 0 ;
this . currentMods = 0 ;
// Cached db data
this . rankedScore = 0 ;
this . accuracy = 0 ;
this . playCount = 0 ;
this . totalScore = 0 ;
this . rank = 0 ;
this . pp = 0 ;
2021-01-26 14:55:25 +00:00
// Multiplayer data
this . currentMatch = null ;
this . matchSlotId = - 1 ;
2020-08-27 13:09:35 +01:00
}
// Adds new actions to the user's queue
addActionToQueue ( newData ) {
this . queue = Buffer . concat ( [ this . queue , newData ] , this . queue . length + newData . length ) ;
}
// Updates the user's current action
updatePresence ( action ) {
this . actionID = action . status ;
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
getNewUserInformationFromDatabase ( ) {
2020-09-07 19:23:06 +01:00
const userScoreDB = global . DatabaseHelper . getFromDB ( ` SELECT * FROM users_modes_info WHERE user_id = ${ this . id } AND mode_id = ${ this . playMode } LIMIT 1 ` ) ;
2020-11-03 02:08:57 +00:00
const userRankDB = global . DatabaseHelper . getFromDB ( ` SELECT user_id, pp_raw, ROW_NUMBER() OVER(ORDER BY pp_raw DESC) AS rank FROM users_modes_info WHERE mode_id = ${ this . playMode } ORDER BY pp_raw DESC ` ) ;
2020-08-27 13:09:35 +01:00
if ( userScoreDB == null || userRankDB == null ) throw "fuck" ;
2020-11-03 02:08:57 +00:00
let userScoreUpdate = false ;
if ( this . pp != userScoreDB . pp _raw ) {
userScoreUpdate = true ;
}
2020-08-27 13:09:35 +01:00
this . rankedScore = userScoreDB . ranked _score ;
this . totalScore = userScoreDB . total _score ;
this . accuracy = userScoreDB . avg _accuracy ;
this . playCount = userScoreDB . playcount ;
2020-11-03 02:08:57 +00:00
for ( let userRank of userRankDB )
if ( userRank [ "user_id" ] == this . id ) this . rank = userRank . rank ;
2020-08-27 13:09:35 +01:00
this . pp = userScoreDB . pp _raw ;
2020-11-03 02:08:57 +00:00
if ( userScoreUpdate ) {
StatusUpdate ( this , this . id ) ;
}
2020-08-27 13:09:35 +01:00
}
// Clears out the user's queue
clearQueue ( ) {
this . queue = new Buffer . alloc ( 0 ) ;
}
}