Как включить HTTPS на localhost для Node.js приложения
Порой нам бывает нужно проверить некоторые функции нашего веб приложения,... Читать далее·2 мин. чтения
Данный мутатор сделан на основе CorLogMut от Dr_Killjoy.
В реализации используется класс FileLog, который позволяет работать с записью и чтением файлов.
Пример имени файла: 8007_2022-01-30_14-54_KF-Bank
.
Пример строк чата: 2022.01.30:12-45 Wave=3 Hello World
.
Структура файлов:
- /ChatLoggingMut
-- /Classes
--- /ChatLoggingMut.uc
--- /BroadcastHandlerChatLog.uc
ChatLoggingMut.uc:
class ChatLoggingMut extends Mutator;
var config bool bChatLogEnabled;
function PostBeginPlay()
{
if (bChatLogEnabled)
Spawn(class'BroadcastHandlerChatLog');
}
defaultproperties
{
GroupName="KF-ChatLoggingMut"
FriendlyName="ChatLoggingMut"
Description="cuzus.net"
bChatLogEnabled=True
}
BroadcastHandlerChatLog.uc:
class BroadcastHandlerChatLog extends BroadcastHandler;
var FileLog _fileLogPointer;
var string _fileLogName;
var string _mapName;
var int _serverPort;
function LogStr(string msg)
{
Log("[DEBUG]" @ Class.Name @ msg);
}
function InitServerRules()
{
local array<string> parts;
Split(Level.GetAddressURL(), ":", parts);
_serverPort = int(parts[1]);
}
function PreBeginPlay()
{
local BroadcastHandler BH;
InitServerRules();
_mapName = GetShortUrl(Level.GetLocalURL());
_fileLogName = GetLogFileNamePattern();
if (_fileLogPointer == none)
{
_fileLogPointer = Spawn(class'FileLog');
}
if (Level.Game.BroadcastHandler.class != Level.Game.default.BroadcastClass)
{
LogStr("WARNING: Unexpected broadcast handler `" $ Level.Game.BroadcastHandler.class.name $ "`. Will try to use the original.");
foreach AllActors(class'BroadcastHandler', BH)
{
if (BH.class == Level.Game.default.BroadcastClass)
{
LogStr("Found the original broadcast handler " $ BH.class.name);
BH.RegisterBroadcastHandler(Self);
break;
}
}
if (BH == none)
{
LogStr("Unable to find the original broadcast handler. Will fallback to the current handler and hope it works out.");
Level.Game.BroadcastHandler.RegisterBroadcastHandler(Self);
}
}
else
{
Level.Game.BroadcastHandler.RegisterBroadcastHandler(Self);
}
}
event Destroyed()
{
_fileLogPointer.CloseLog();
super.Destroyed();
}
function string GetLogFileNamePattern()
{
local string s;
s = "Chat_" $ string(_serverPort) $ "_";
s $= string(Level.Year);
s $= "-";
s $= GetNumberIn24hFormat(Level.Month);
s $= "-";
s $= GetNumberIn24hFormat(Level.Day);
s $= "_";
s $= GetNumberIn24hFormat(Level.Hour);
s $= "-";
s $= GetNumberIn24hFormat(Level.Minute);
s $= "_";
s $= _mapName;
return s;
}
function string GetChatLinePrefix()
{
local string s;
s = string(Level.Year);
s $= ".";
s $= GetNumberIn24hFormat(Level.Month);
s $= ".";
s $= GetNumberIn24hFormat(Level.Day);
s $= " ";
s $= GetNumberIn24hFormat(Level.Hour);
s $= ":";
s $= GetNumberIn24hFormat(Level.Minute);
s $= ":";
s $= GetNumberIn24hFormat(Level.Second);
s $= " Wave=";
s $= string(KFGameType(Level.Game).WaveNum + 1);
return s;
}
static function string GetNumberIn24hFormat(int num)
{
local string result;
result = string(num);
if (Len(result) == 1)
result = "0" $ result;
return result;
}
function BroadcastText(PlayerReplicationInfo SenderPRI, PlayerController Receiver, coerce string Msg, optional name Type)
{
local string str;
if (Len(Msg) == 0)
{
return;
}
if (SenderPRI == none)
{
super.BroadcastText(SenderPRI, Receiver, Msg, Type);
return;
}
if (Receiver.PlayerReplicationInfo == SenderPRI)
{
_fileLogPointer.OpenLog(_fileLogName);
str = GetChatLinePrefix();
str $= " ";
str $= SenderPRI.PlayerName;
str $= " ";
str $= ConvertString(Msg);
_fileLogPointer.LogF(str);
_fileLogPointer.CloseLog();
}
super.BroadcastText(SenderPRI, Receiver, Msg, Type);
}
function string ConvertString(string msg)
{
local int i;
local string tmp;
local string result;
local int code;
tmp = msg;
for (i = 0; i < Len(msg); i++)
{
code = Asc(tmp);
if (code > 848)
code -= 848;
if (i == 0)
result = Chr(code);
else
result = result $ Chr(code);
tmp = Mid(tmp, 1);
}
return result;
}
Похожие публикации