Kick reason

This commit is contained in:
Vortrex
2022-06-12 09:20:18 -05:00
parent 519928bf6b
commit 230a623210

View File

@@ -12,13 +12,13 @@
// =========================================================================== // ===========================================================================
function getPositionArea(position) { function getPositionArea(position) {
if(typeof position == "Vec3") { if (typeof position == "Vec3") {
position = vec3ToVec2(position); position = vec3ToVec2(position);
} }
let gameAreas = getGameAreas(getGame()); let gameAreas = getGameAreas(getGame());
for(let i in gameAreas) { for (let i in gameAreas) {
if(isPositionInArea(position, gameAreas[i][1])) { if (isPositionInArea(position, gameAreas[i][1])) {
return i; return i;
} }
} }
@@ -30,7 +30,7 @@ function getPositionArea(position) {
function getAreaName(position) { function getAreaName(position) {
let areaId = getPositionArea(position); let areaId = getPositionArea(position);
if(!areaId) { if (!areaId) {
return false; return false;
} }
@@ -50,8 +50,8 @@ function getGameAreas(gameId) {
* @return {ClientData} The player/client's data (class instancee) * @return {ClientData} The player/client's data (class instancee)
*/ */
function getPlayerData(client) { function getPlayerData(client) {
if(client != null) { if (client != null) {
if(isClientInitialized(client)) { if (isClientInitialized(client)) {
return getServerData().clients[getPlayerId(client)]; return getServerData().clients[getPlayerId(client)];
} }
} }
@@ -61,7 +61,7 @@ function getPlayerData(client) {
// =========================================================================== // ===========================================================================
function initAllClients() { function initAllClients() {
getClients().forEach(function(client) { getClients().forEach(function (client) {
initClient(client); initClient(client);
}); });
} }
@@ -72,17 +72,17 @@ function updateServerRules() {
logToConsole(LOG_DEBUG, `[VRR.Utilities]: Updating all server rules ...`); logToConsole(LOG_DEBUG, `[VRR.Utilities]: Updating all server rules ...`);
logToConsole(LOG_DEBUG, `[VRR.Utilities]: Time support: ${isTimeSupported()}`); logToConsole(LOG_DEBUG, `[VRR.Utilities]: Time support: ${isTimeSupported()}`);
if(isTimeSupported()) { if (isTimeSupported()) {
if(getServerConfig() != false) { if (getServerConfig() != false) {
let value = makeReadableTime(getServerConfig().hour, getServerConfig().minute); let value = makeReadableTime(getServerConfig().hour, getServerConfig().minute);
logToConsole(LOG_DEBUG, `[VRR.Utilities]: Setting server rule "Time" as ${value}`); logToConsole(LOG_DEBUG, `[VRR.Utilities]: Setting server rule "Time" as ${value}`);
server.setRule("Time", value); server.setRule("Time", value);
} }
} }
if(isWeatherSupported()) { if (isWeatherSupported()) {
if(getServerConfig() != false) { if (getServerConfig() != false) {
if(typeof getGameConfig().weatherNames[getGame()] != "undefined") { if (typeof getGameConfig().weatherNames[getGame()] != "undefined") {
let value = getGameConfig().weatherNames[getGame()][getServerConfig().weather]; let value = getGameConfig().weatherNames[getGame()][getServerConfig().weather];
logToConsole(LOG_DEBUG, `[VRR.Utilities]: Setting server rule "Weather" as ${value}`); logToConsole(LOG_DEBUG, `[VRR.Utilities]: Setting server rule "Weather" as ${value}`);
server.setRule("Weather", value); server.setRule("Weather", value);
@@ -90,8 +90,8 @@ function updateServerRules() {
} }
} }
if(isSnowSupported()) { if (isSnowSupported()) {
if(getServerConfig() != false) { if (getServerConfig() != false) {
let value = getYesNoFromBool(getServerConfig().fallingSnow); let value = getYesNoFromBool(getServerConfig().fallingSnow);
logToConsole(LOG_DEBUG, `[VRR.Utilities]: Setting server rule "Snowing" as ${value}`); logToConsole(LOG_DEBUG, `[VRR.Utilities]: Setting server rule "Snowing" as ${value}`);
server.setRule("Snowing", value); server.setRule("Snowing", value);
@@ -103,14 +103,14 @@ function updateServerRules() {
// =========================================================================== // ===========================================================================
function getWeatherFromParams(params) { function getWeatherFromParams(params) {
if(isNaN(params)) { if (isNaN(params)) {
for(let i in getGameConfig().weatherNames[getGame()]) { for (let i in getGameConfig().weatherNames[getGame()]) {
if(toLowerCase(getGameConfig().weatherNames[getGame()][i]).indexOf(toLowerCase(params)) != -1) { if (toLowerCase(getGameConfig().weatherNames[getGame()][i]).indexOf(toLowerCase(params)) != -1) {
return i; return i;
} }
} }
} else { } else {
if(typeof getGameConfig().weatherNames[getGame()][params] != "undefined") { if (typeof getGameConfig().weatherNames[getGame()][params] != "undefined") {
return toInteger(params); return toInteger(params);
} }
} }
@@ -121,14 +121,14 @@ function getWeatherFromParams(params) {
// =========================================================================== // ===========================================================================
function getFightStyleFromParams(params) { function getFightStyleFromParams(params) {
if(isNaN(params)) { if (isNaN(params)) {
for(let i in getGameConfig().fightStyles[getGame()]) { for (let i in getGameConfig().fightStyles[getGame()]) {
if(toLowerCase(getGameConfig().fightStyles[getGame()][i][0]).indexOf(toLowerCase(params)) != -1) { if (toLowerCase(getGameConfig().fightStyles[getGame()][i][0]).indexOf(toLowerCase(params)) != -1) {
return i; return i;
} }
} }
} else { } else {
if(typeof getGameConfig().fightStyles[getGame()][params] != "undefined") { if (typeof getGameConfig().fightStyles[getGame()][params] != "undefined") {
return toInteger(params); return toInteger(params);
} }
} }
@@ -139,12 +139,12 @@ function getFightStyleFromParams(params) {
// =========================================================================== // ===========================================================================
function getClosestHospital(position) { function getClosestHospital(position) {
if(typeof getGameConfig().hospitals[getGame()] == "undefined") { if (typeof getGameConfig().hospitals[getGame()] == "undefined") {
return {position: getServerConfig().newCharacter.spawnPosition}; return { position: getServerConfig().newCharacter.spawnPosition };
} else { } else {
let closest = 0; let closest = 0;
for(let i in getGameConfig().hospitals[getGame()]) { for (let i in getGameConfig().hospitals[getGame()]) {
if(getDistance(getGameConfig().hospitals[getGame()][i].position, position) < getDistance(getGameConfig().hospitals[getGame()][closest].position, position)) { if (getDistance(getGameConfig().hospitals[getGame()][i].position, position) < getDistance(getGameConfig().hospitals[getGame()][closest].position, position)) {
closest = i; closest = i;
} }
} }
@@ -156,12 +156,12 @@ function getClosestHospital(position) {
// =========================================================================== // ===========================================================================
function getClosestPoliceStation(position) { function getClosestPoliceStation(position) {
if(typeof getGameConfig().policeStations[getGame()] == "undefined") { if (typeof getGameConfig().policeStations[getGame()] == "undefined") {
return {position: getServerConfig().newCharacter.spawnPosition}; return { position: getServerConfig().newCharacter.spawnPosition };
} else { } else {
let closest = 0; let closest = 0;
for(let i in getGameConfig().policeStations[getGame()]) { for (let i in getGameConfig().policeStations[getGame()]) {
if(getDistance(getGameConfig().policeStations[getGame()][i].position, position) < getDistance(getGameConfig().policeStations[getGame()][closest].position, position)) { if (getDistance(getGameConfig().policeStations[getGame()][i].position, position) < getDistance(getGameConfig().policeStations[getGame()][closest].position, position)) {
closest = i; closest = i;
} }
} }
@@ -173,7 +173,7 @@ function getClosestPoliceStation(position) {
// =========================================================================== // ===========================================================================
function getPlayerDisplayForConsole(client) { function getPlayerDisplayForConsole(client) {
if(isNull(client)) { if (isNull(client)) {
return "(Unknown client)"; return "(Unknown client)";
} }
return `${getPlayerName(client)}[${getPlayerId(client)}]`; return `${getPlayerName(client)}[${getPlayerId(client)}]`;
@@ -182,7 +182,7 @@ function getPlayerDisplayForConsole(client) {
// =========================================================================== // ===========================================================================
function getPlayerNameForNameTag(client) { function getPlayerNameForNameTag(client) {
if(isPlayerSpawned(client)) { if (isPlayerSpawned(client)) {
return `${getPlayerCurrentSubAccount(client).firstName} ${getPlayerCurrentSubAccount(client).lastName}`; return `${getPlayerCurrentSubAccount(client).firstName} ${getPlayerCurrentSubAccount(client).lastName}`;
} }
return getPlayerName(client); return getPlayerName(client);
@@ -191,7 +191,7 @@ function getPlayerNameForNameTag(client) {
// =========================================================================== // ===========================================================================
function isPlayerSpawned(client) { function isPlayerSpawned(client) {
if(!getPlayerData(client)) { if (!getPlayerData(client)) {
return false; return false;
} }
return getPlayerData(client).spawned; return getPlayerData(client).spawned;
@@ -206,8 +206,8 @@ function getPlayerIsland(client) {
// =========================================================================== // ===========================================================================
function isAtPayAndSpray(position) { function isAtPayAndSpray(position) {
for(let i in getGameConfig().payAndSprays[getGame()]) { for (let i in getGameConfig().payAndSprays[getGame()]) {
if(getDistance(position, getGameConfig().payAndSprays[getGame()][i]) <= getGlobalConfig().payAndSprayDistance) { if (getDistance(position, getGameConfig().payAndSprays[getGame()][i]) <= getGlobalConfig().payAndSprayDistance) {
return true; return true;
} }
} }
@@ -220,15 +220,15 @@ function isAtPayAndSpray(position) {
function resetClientStuff(client) { function resetClientStuff(client) {
logToConsole(LOG_DEBUG, `[VRR.Utilities] Resetting client data for ${getPlayerDisplayForConsole(client)}`); logToConsole(LOG_DEBUG, `[VRR.Utilities] Resetting client data for ${getPlayerDisplayForConsole(client)}`);
if(!getPlayerData(client)) { if (!getPlayerData(client)) {
return false; return false;
} }
if(isPlayerOnJobRoute(client)) { if (isPlayerOnJobRoute(client)) {
stopJobRoute(client, false, false); stopJobRoute(client, false, false);
} }
if(getPlayerData(client).rentingVehicle) { if (getPlayerData(client).rentingVehicle) {
stopRentingVehicle(client); stopRentingVehicle(client);
} }
@@ -241,9 +241,9 @@ function resetClientStuff(client) {
function getPlayerFromCharacterId(subAccountId) { function getPlayerFromCharacterId(subAccountId) {
let clients = getClients(); let clients = getClients();
for(let i in clients) { for (let i in clients) {
for(let j in getPlayerData(clients[i]).subAccounts) { for (let j in getPlayerData(clients[i]).subAccounts) {
if(getPlayerData(clients[i]).subAccounts[j].databaseId == subAccountId) { if (getPlayerData(clients[i]).subAccounts[j].databaseId == subAccountId) {
return clients[i]; return clients[i];
} }
} }
@@ -256,11 +256,11 @@ function getPlayerFromCharacterId(subAccountId) {
function checkPlayerPedStates() { function checkPlayerPedStates() {
let clients = getClients(); let clients = getClients();
for(let i in clients) { for (let i in clients) {
if(getPlayerData(clients[i])) { if (getPlayerData(clients[i])) {
if(getPlayerData(clients[i]).pedState) { if (getPlayerData(clients[i]).pedState) {
if(isPlayerInAnyVehicle(clients[i])) { if (isPlayerInAnyVehicle(clients[i])) {
if(getPlayerData(clients[i]).pedState == VRR_PEDSTATE_EXITINGVEHICLE) { if (getPlayerData(clients[i]).pedState == VRR_PEDSTATE_EXITINGVEHICLE) {
getPlayerData(clients[i]).pedState == VRR_PEDSTATE_READY; getPlayerData(clients[i]).pedState == VRR_PEDSTATE_READY;
} }
} }
@@ -272,11 +272,11 @@ function checkPlayerPedStates() {
// =========================================================================== // ===========================================================================
function showConnectCameraToPlayer(client) { function showConnectCameraToPlayer(client) {
if(isFadeCameraSupported()) { if (isFadeCameraSupported()) {
fadeCamera(client, true, 1); fadeCamera(client, true, 1);
} }
if(isCustomCameraSupported()) { if (isCustomCameraSupported()) {
//setPlayerInterior(client, 0); //setPlayerInterior(client, 0);
//setPlayerDimension(client, 0); //setPlayerDimension(client, 0);
setPlayerCameraLookAt(client, getServerConfig().connectCameraPosition, getServerConfig().connectCameraLookAt); setPlayerCameraLookAt(client, getServerConfig().connectCameraPosition, getServerConfig().connectCameraLookAt);
@@ -295,9 +295,9 @@ function showCharacterSelectCameraToPlayer(client) {
function getClosestPlayer(position, exemptPlayer) { function getClosestPlayer(position, exemptPlayer) {
let clients = getClients(); let clients = getClients();
let closest = 0; let closest = 0;
for(let i in clients) { for (let i in clients) {
if(exemptClient != clients[i]) { if (exemptClient != clients[i]) {
if(getDistance(getPlayerPosition(clients[i]), position) < getDistance(getPlayerPosition(clients[closest]), position)) { if (getDistance(getPlayerPosition(clients[i]), position) < getDistance(getPlayerPosition(clients[closest]), position)) {
closest = i; closest = i;
} }
} }
@@ -315,20 +315,20 @@ function isPlayerMuted(client) {
function getPlayerFromParams(params) { function getPlayerFromParams(params) {
let clients = getClients(); let clients = getClients();
if(isNaN(params)) { if (isNaN(params)) {
for(let i in clients) { for (let i in clients) {
if(!clients[i].console) { if (!clients[i].console) {
if(toLowerCase(clients[i].name).indexOf(toLowerCase(params)) != -1) { if (toLowerCase(clients[i].name).indexOf(toLowerCase(params)) != -1) {
return clients[i]; return clients[i];
} }
if(toLowerCase(getCharacterFullName(clients[i])).indexOf(toLowerCase(params)) != -1) { if (toLowerCase(getCharacterFullName(clients[i])).indexOf(toLowerCase(params)) != -1) {
return clients[i]; return clients[i];
} }
} }
} }
} else { } else {
if(typeof clients[toInteger(params)] != "undefined") { if (typeof clients[toInteger(params)] != "undefined") {
return clients[toInteger(params)]; return clients[toInteger(params)];
} }
} }
@@ -339,7 +339,7 @@ function getPlayerFromParams(params) {
// =========================================================================== // ===========================================================================
function updateConnectionLogOnQuit(client, quitReasonId) { function updateConnectionLogOnQuit(client, quitReasonId) {
if(getPlayerData(client) != false) { if (getPlayerData(client) != false) {
quickDatabaseQuery(`UPDATE conn_main SET conn_when_disconnect=NOW(), conn_how_disconnect=${quitReasonId} WHERE conn_id = ${getPlayerData(client).sessionId}`); quickDatabaseQuery(`UPDATE conn_main SET conn_when_disconnect=NOW(), conn_how_disconnect=${quitReasonId} WHERE conn_id = ${getPlayerData(client).sessionId}`);
} }
} }
@@ -353,12 +353,12 @@ function updateConnectionLogOnAuth(client, authId) {
// =========================================================================== // ===========================================================================
function updateConnectionLogOnClientInfoReceive(client, clientVersion, screenWidth, screenHeight) { function updateConnectionLogOnClientInfoReceive(client, clientVersion, screenWidth, screenHeight) {
if(getPlayerData(client) != false) { if (getPlayerData(client) != false) {
getPlayerData(client).clientVersion = clientVersion; getPlayerData(client).clientVersion = clientVersion;
} }
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if(dbConnection) { if (dbConnection) {
let safeClientVersion = escapeDatabaseString(dbConnection, clientVersion); let safeClientVersion = escapeDatabaseString(dbConnection, clientVersion);
let safeScreenWidth = escapeDatabaseString(dbConnection, toString(screenWidth)); let safeScreenWidth = escapeDatabaseString(dbConnection, toString(screenWidth));
let safeScreenHeight = escapeDatabaseString(dbConnection, toString(screenHeight)); let safeScreenHeight = escapeDatabaseString(dbConnection, toString(screenHeight));
@@ -377,8 +377,8 @@ function generateRandomPhoneNumber() {
function doesNameContainInvalidCharacters(name) { function doesNameContainInvalidCharacters(name) {
let disallowedCharacters = getGlobalConfig().subAccountNameAllowedCharacters; let disallowedCharacters = getGlobalConfig().subAccountNameAllowedCharacters;
name = toLowerCase(name); name = toLowerCase(name);
for(let i = 0; i < name.length; i++) { for (let i = 0; i < name.length; i++) {
if(disallowedCharacters.toLowerCase().indexOf(name.charAt(i)) == -1) { if (disallowedCharacters.toLowerCase().indexOf(name.charAt(i)) == -1) {
return true; return true;
} }
} }
@@ -394,36 +394,12 @@ function getClientFromSyncerId(syncerId) {
// =========================================================================== // ===========================================================================
function triggerWebHook(messageString, serverId = getServerId(), type = VRR_DISCORD_WEBHOOK_LOG) {
if(!getGlobalConfig().discord.webhook.enabled) {
return false;
}
let tempURL = getGlobalConfig().discord.webhook.webhookBaseURL;
tempURL = tempURL.replace("{0}", encodeURI(messageString));
tempURL = tempURL.replace("{1}", serverId);
tempURL = tempURL.replace("{2}", type);
tempURL = tempURL.replace("{3}", getGlobalConfig().discord.webhook.pass);
httpGet(
tempURL,
"",
function(data) {
},
function(data) {
}
);
}
// ===========================================================================
function clearTemporaryVehicles() { function clearTemporaryVehicles() {
let vehicles = getElementsByType(ELEMENT_VEHICLE); let vehicles = getElementsByType(ELEMENT_VEHICLE);
for(let i in vehicles) { for (let i in vehicles) {
if(!getVehicleData(vehicles[i])) { if (!getVehicleData(vehicles[i])) {
let occupants = vehicles[i].getOccupants(); let occupants = vehicles[i].getOccupants();
for(let j in occupants) { for (let j in occupants) {
destroyGameElement(occupants[j]); destroyGameElement(occupants[j]);
} }
destroyGameElement(vehicles[i]); destroyGameElement(vehicles[i]);
@@ -435,11 +411,11 @@ function clearTemporaryVehicles() {
function clearTemporaryPeds() { function clearTemporaryPeds() {
let peds = getElementsByType(ELEMENT_PED); let peds = getElementsByType(ELEMENT_PED);
for(let i in peds) { for (let i in peds) {
if(peds[i].owner == -1) { if (peds[i].owner == -1) {
if(!peds[i].isType(ELEMENT_PLAYER)) { if (!peds[i].isType(ELEMENT_PLAYER)) {
if(peds[i].vehicle == null) { if (peds[i].vehicle == null) {
if(!getNPCData(peds[i])) { if (!getNPCData(peds[i])) {
destroyElement(peds[i]); destroyElement(peds[i]);
} }
} }
@@ -452,6 +428,7 @@ function clearTemporaryPeds() {
function kickAllClients() { function kickAllClients() {
getClients().forEach((client) => { getClients().forEach((client) => {
getPlayerData(client).customDisconnectReason = `Kicked - All clients are being disconnected`;
disconnectPlayer(client); disconnectPlayer(client);
}) })
} }
@@ -459,7 +436,7 @@ function kickAllClients() {
// =========================================================================== // ===========================================================================
function updateTimeRule() { function updateTimeRule() {
if(isTimeSupported()) { if (isTimeSupported()) {
server.setRule("Time", makeReadableTime(game.time.hour, game.time.minute)); server.setRule("Time", makeReadableTime(game.time.hour, game.time.minute));
} }
} }
@@ -473,7 +450,7 @@ function isClientInitialized(client) {
// =========================================================================== // ===========================================================================
function getPedForNetworkEvent(ped) { function getPedForNetworkEvent(ped) {
if(getGame() == VRR_GAME_GTA_IV) { if (getGame() == VRR_GAME_GTA_IV) {
return ped; return ped;
} else { } else {
return ped.id; return ped.id;
@@ -485,10 +462,10 @@ function getPedForNetworkEvent(ped) {
// Get how many times a player connected in the last month by name // Get how many times a player connected in the last month by name
function getPlayerConnectionsInLastMonthByName(name) { function getPlayerConnectionsInLastMonthByName(name) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if(dbConnection) { if (dbConnection) {
let safeName = escapeDatabaseString(dbConnection, name); let safeName = escapeDatabaseString(dbConnection, name);
let result = quickDatabaseQuery(`SELECT COUNT(*) AS count FROM conn_main WHERE conn_when_connect >= NOW() - INTERVAL 1 MONTH AND conn_name = '${safeName}'`); let result = quickDatabaseQuery(`SELECT COUNT(*) AS count FROM conn_main WHERE conn_when_connect >= NOW() - INTERVAL 1 MONTH AND conn_name = '${safeName}'`);
if(result) { if (result) {
return result[0].count; return result[0].count;
} }
} }
@@ -500,7 +477,7 @@ function getPlayerConnectionsInLastMonthByName(name) {
function addPrefixNumberFill(number, amount) { function addPrefixNumberFill(number, amount) {
let numberString = toString(number); let numberString = toString(number);
while(numberString.length < amount) { while (numberString.length < amount) {
numberString = toString(`0${numberString}`); numberString = toString(`0${numberString}`);
} }
return toString(numberString); return toString(numberString);