Add optional chatbox timestamps
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
let chatBoxTimeStampsEnabled = false;
|
||||
let chatBoxHistory = [];
|
||||
let bottomMessageIndex = 0;
|
||||
let maxChatBoxHistory = 500;
|
||||
@@ -56,11 +57,20 @@ function receiveChatBoxMessageFromServer(messageString, colour) {
|
||||
|
||||
let colouredString = replaceColoursInMessage(messageString);
|
||||
|
||||
let date = new Date();
|
||||
let timeStampText = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
|
||||
|
||||
logToConsole(LOG_DEBUG, `[VRR.ChatBox]: Changed colours in string: ${colouredString}`);
|
||||
|
||||
addToChatBoxHistory(colouredString, colour);
|
||||
addToChatBoxHistory(colouredString, colour, timeStampText);
|
||||
//if(bottomMessageIndex >= chatBoxHistory.length-1) {
|
||||
message(colouredString, colour);
|
||||
|
||||
let outputText = colouredString;
|
||||
if (chatBoxTimeStampsEnabled) {
|
||||
outputText = `{TIMESTAMPCOLOUR}[${timeStampText}]{MAINCOLOUR} ${colouredString}`;
|
||||
}
|
||||
|
||||
message(outputText, colour);
|
||||
bottomMessageIndex = chatBoxHistory.length - 1;
|
||||
//}
|
||||
|
||||
@@ -75,6 +85,13 @@ function setChatScrollLines(amount) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setChatBoxTimeStampsState(state) {
|
||||
chatBoxTimeStampsEnabled = state;
|
||||
updateChatBox();
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setChatAutoHideDelay(delay) {
|
||||
chatAutoHideDelay = delay * 1000;
|
||||
}
|
||||
@@ -117,7 +134,12 @@ function updateChatBox() {
|
||||
clearChatBox();
|
||||
for (let i = bottomMessageIndex - maxChatBoxLines; i <= bottomMessageIndex; i++) {
|
||||
if (typeof chatBoxHistory[i] != "undefined") {
|
||||
message(chatBoxHistory[i][0], chatBoxHistory[i][1]);
|
||||
let outputText = chatBoxHistory[i][0];
|
||||
if (chatBoxTimeStampsEnabled) {
|
||||
outputText = `{TIMESTAMPCOLOUR}[${timeStampText}]{MAINCOLOUR} ${chatBoxHistory[i][0]}`;
|
||||
}
|
||||
|
||||
message(outputText, chatBoxHistory[i][1]);
|
||||
} else {
|
||||
message("", COLOUR_WHITE);
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ function initServerScript() {
|
||||
function addAllNetworkHandlers() {
|
||||
logToConsole(LOG_DEBUG, "[VRR.Server]: Adding network handlers ...");
|
||||
|
||||
// Chat history
|
||||
// Chat Box
|
||||
addNetworkEventHandler("m", receiveChatBoxMessageFromServer); // Not prefixed with VRR to make it as small as possible
|
||||
addNetworkEventHandler("vrr.chatScrollLines", setChatScrollLines);
|
||||
addNetworkEventHandler("vrr.chatAutoHideDelay", setChatAutoHideDelay);
|
||||
addNetworkEventHandler("vrr.chatTimeStamps", setChatBoxTimeStampsState);
|
||||
|
||||
// Messaging (like textdraws and stuff)
|
||||
addNetworkEventHandler("vrr.smallGameMessage", showSmallGameMessage);
|
||||
|
||||
@@ -387,6 +387,23 @@ function toggleAccountTwoFactorAuthCommand(command, params, client) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function toggleChatBoxTimeStampsCommand(command, params, client) {
|
||||
let flagValue = getAccountSettingsFlagValue("ChatBoxTimestamps");
|
||||
|
||||
if (hasBitFlag(getPlayerData(client).accountData.settings, flagValue)) {
|
||||
getPlayerData(client).accountData.settings = removeBitFlag(getPlayerData(client).accountData.settings, flagValue);
|
||||
messagePlayerSuccess(client, getLocaleString(client, "ChatBoxTimestampsToggle", `{softRed}${toUpperCase(getLocaleString(client, "Off"))}`));
|
||||
sendPlayerChatBoxTimeStampsState(client, false);
|
||||
} else {
|
||||
getPlayerData(client).accountData.settings = addBitFlag(getPlayerData(client).accountData.settings, flagValue);
|
||||
messagePlayerSuccess(client, getLocaleString(client, "ChatBoxTimestampsToggle", `{softGreen}${toUpperCase(getLocaleString(client, "On"))}`));
|
||||
sendPlayerChatBoxTimeStampsState(client, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function registerCommand(command, params, client) {
|
||||
if (isPlayerRegistered(client)) {
|
||||
messagePlayerError(client, getLocaleString(client, "AccountNameAlreadyRegistered"));
|
||||
|
||||
@@ -117,6 +117,7 @@ let serverBitFlagKeys = {
|
||||
"NoKeyBinds",
|
||||
"NoRandomTips",
|
||||
"NoActionTips",
|
||||
"ChatBoxTimestamps",
|
||||
],
|
||||
|
||||
// Not going to be used. Use trigger, condition, and response stuff in trigger.js
|
||||
|
||||
@@ -1238,3 +1238,9 @@ function clearLocalPickupsForPlayer(client) {
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
|
||||
function sendPlayerChatBoxTimeStampsState(client, state) {
|
||||
sendNetworkEventToPlayer(client, "vrr.chatTimeStamps", state);
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
Reference in New Issue
Block a user