Skip to content

Commit 04bd7d0

Browse files
committed
fix player updating for better-sqlite
1 parent a050172 commit 04bd7d0

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/handlers/player.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ const sleep = require('sleep-promise');
66
const bcryptCompare = promisify(bcrypt.compare);
77
const bcryptHash = promisify(bcrypt.hash);
88

9+
const PLAYER_BOOLEAN_PROPERTIES = [
10+
'cameraAuto',
11+
'oneMouseButton',
12+
'soundOn',
13+
'blockChat',
14+
'blockPrivateChat',
15+
'blockTrade',
16+
'blockDuel'
17+
];
18+
919
async function throttleAttempt(queryHandler, ip) {
1020
let { attempts, lastDate } = queryHandler.getLoginAttempts(ip);
1121

@@ -79,8 +89,6 @@ async function playerLogin({ token, username, password, ip, reconnecting }) {
7989
return this.socket.sendMessage(message);
8090
}
8191

82-
queryHandler.setLoginAttempts(ip, 0);
83-
8492
const rounds = bcrypt.getRounds(hash);
8593
const passwordHashRounds = this.server.config.passwordHashRounds;
8694

@@ -213,7 +221,7 @@ async function playerRegister({ token, username, password, ip }) {
213221
return this.socket.sendMessage(message);
214222
}
215223

216-
const lastCreationDate = +(queryHandler.lastCreationDate(ip));
224+
const lastCreationDate = +queryHandler.lastCreationDate(ip);
217225

218226
if (Date.now() - lastCreationDate < 1000 * 60 * 5) {
219227
message.code = 7;
@@ -250,18 +258,17 @@ async function playerUpdate(player) {
250258
delete player.token;
251259
delete player.handler;
252260

261+
for (const property of PLAYER_BOOLEAN_PROPERTIES) {
262+
player[property] = +player[property];
263+
}
264+
253265
queryHandler.updatePlayer(player);
254266

255267
message.success = true;
256268
this.socket.sendMessage(message);
257269
}
258270

259-
async function playerMessage({
260-
token,
261-
toUsername,
262-
fromUsername,
263-
message
264-
}) {
271+
async function playerMessage({ token, toUsername, fromUsername, message }) {
265272
try {
266273
const worldID = this.server.getPlayerWorld(toUsername);
267274
const world = this.server.worlds[worldID];
@@ -299,8 +306,6 @@ async function webLogin({ token, username, password, ip }) {
299306
return this.socket.sendMessage({ token, success: false });
300307
}
301308

302-
queryHandler.setLoginAttempts(ip, 0);
303-
304309
const player = queryHandler.getWebPlayer(username);
305310

306311
return this.socket.sendMessage({ token, success: true, player });

0 commit comments

Comments
 (0)