Fix keybinds

This commit is contained in:
Vortrex
2022-01-04 20:01:56 -06:00
parent 9e3cca3481
commit dd484c23ea

View File

@@ -1019,6 +1019,8 @@ function initClient(client) {
let sessionId = saveConnectionToDatabase(client); let sessionId = saveConnectionToDatabase(client);
getServerData().clients[client.index].session = sessionId; getServerData().clients[client.index].session = sessionId;
getServerData().clients[client.index].connectTime = Math.ceil(sdl.ticks); getServerData().clients[client.index].connectTime = Math.ceil(sdl.ticks);
getServerData().clients[client.index].keyBinds = loadAccountKeybindsFromDatabase(tempAccountData.databaseId);
sendAccountKeyBindsToClient(client);
if(tempAccountData != false) { if(tempAccountData != false) {
if(isAccountAutoIPLoginEnabled(tempAccountData) && getPlayerData(client).accountData.ipAddress == client.ip) { if(isAccountAutoIPLoginEnabled(tempAccountData) && getPlayerData(client).accountData.ipAddress == client.ip) {
@@ -1033,13 +1035,11 @@ function initClient(client) {
messagePlayerNormal(client, `Welcome back to ${getServerName()}, ${getPlayerName(client)}! Please /login to continue.`, getColourByName("softGreen")); messagePlayerNormal(client, `Welcome back to ${getServerName()}, ${getPlayerName(client)}! Please /login to continue.`, getColourByName("softGreen"));
} }
playRadioStreamForPlayer(client, getServerIntroMusicURL(), true, getPlayerStreamingRadioVolume(client)); playRadioStreamForPlayer(client, getServerIntroMusicURL(), true, getPlayerStreamingRadioVolume(client));
loadAccountKeybindsFromDatabase(tempAccountData.databaseId);
} }
} else { } else {
if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) { if(getServerConfig().useGUI && doesPlayerHaveGUIEnabled(client)) {
logToConsole(LOG_DEBUG, `[VRR.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI.`); logToConsole(LOG_DEBUG, `[VRR.Account] ${getPlayerDisplayForConsole(client)} is being shown the register GUI.`);
showPlayerRegistrationGUI(client); showPlayerRegistrationGUI(client);
addPlayerKeyBind(client, getKeyIdFromParams("insert"), "gui", "");
} else { } else {
logToConsole(LOG_DEBUG, `[VRR.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled).`); logToConsole(LOG_DEBUG, `[VRR.Account] ${getPlayerDisplayForConsole(client)} is being shown the register message (GUI disabled).`);
messagePlayerNormal(client, `Welcome to ${getServerName()}, ${getPlayerName(client)}! Please /register to continue.`, getColourByName("softGreen")); messagePlayerNormal(client, `Welcome to ${getServerName()}, ${getPlayerName(client)}! Please /register to continue.`, getColourByName("softGreen"));
@@ -1059,7 +1059,6 @@ function saveConnectionToDatabase(client) {
let dbQueryString = `INSERT INTO conn_main (conn_when_connect, conn_server, conn_script_version, conn_game_version, conn_client_version, conn_name, conn_ip) VALUES (NOW(), ${getServerConfig().databaseId}, '${scriptVersion}', '${client.gameVersion}', '0.0.0', '${safeName}', '${client.ip}')`; let dbQueryString = `INSERT INTO conn_main (conn_when_connect, conn_server, conn_script_version, conn_game_version, conn_client_version, conn_name, conn_ip) VALUES (NOW(), ${getServerConfig().databaseId}, '${scriptVersion}', '${client.gameVersion}', '0.0.0', '${safeName}', '${client.ip}')`;
queryDatabase(dbConnection, dbQueryString); queryDatabase(dbConnection, dbQueryString);
let connectionId = getDatabaseInsertId(dbConnection); let connectionId = getDatabaseInsertId(dbConnection);
setEntityData(client, "vrr.connection", connectionId, false);
getPlayerData(client).connectionId = connectionId; getPlayerData(client).connectionId = connectionId;
requestClientInfo(client); requestClientInfo(client);
} }
@@ -1093,19 +1092,21 @@ function loadAccountKeybindsFromDatabase(accountDatabaseID) {
tempAccountKeybinds.push(tempKeyBindData); tempAccountKeybinds.push(tempKeyBindData);
} }
if(dbConnection) { if(accountDatabaseID != 0) {
dbQuery = queryDatabase(dbConnection, `SELECT * FROM acct_hotkey WHERE acct_hotkey_enabled = 1 AND acct_hotkey_acct = ${accountDatabaseID} AND acct_hotkey_server = ${getServerId()}`); if(dbConnection) {
if(dbQuery) { dbQuery = queryDatabase(dbConnection, `SELECT * FROM acct_hotkey WHERE acct_hotkey_enabled = 1 AND acct_hotkey_acct = ${accountDatabaseID} AND acct_hotkey_server = ${getServerId()}`);
if(dbQuery.numRows > 0) { if(dbQuery) {
while(dbAssoc = fetchQueryAssoc(dbQuery)) { if(dbQuery.numRows > 0) {
let tempAccountKeyBindData = new KeyBindData(dbAssoc); while(dbAssoc = fetchQueryAssoc(dbQuery)) {
tempAccountKeybinds.push(tempAccountKeyBindData); let tempAccountKeyBindData = new KeyBindData(dbAssoc);
logToConsole(LOG_DEBUG, `[VRR.Account]: Account keybind '${tempAccountKeyBindData.databaseId}' (Key ${tempAccountKeyBindData.key} '${toUpperCase(getKeyNameFromId(tempAccountKeyBindData.key))}') loaded from database successfully!`); tempAccountKeybinds.push(tempAccountKeyBindData);
logToConsole(LOG_DEBUG, `[VRR.Account]: Account keybind '${tempAccountKeyBindData.databaseId}' (Key ${tempAccountKeyBindData.key} '${toUpperCase(getKeyNameFromId(tempAccountKeyBindData.key))}') loaded from database successfully!`);
}
} }
freeDatabaseQuery(dbQuery);
} }
freeDatabaseQuery(dbQuery); disconnectFromDatabase(dbConnection);
} }
disconnectFromDatabase(dbConnection);
} }
logToConsole(LOG_DEBUG, `[VRR.Account]: ${tempAccountKeybinds.length} account keybinds for account ${accountDatabaseID} loaded from database successfully!`); logToConsole(LOG_DEBUG, `[VRR.Account]: ${tempAccountKeybinds.length} account keybinds for account ${accountDatabaseID} loaded from database successfully!`);