From 94f7f68bf9153d39fcdb38d614f1774cdb2fc33f Mon Sep 17 00:00:00 2001 From: Emma Miler <27428383+emma-miler@users.noreply.github.com> Date: Mon, 7 Feb 2022 00:28:10 +0100 Subject: Server-side code for chathooks --- .../scripts/vscripts/_custom_codecallbacks.gnut | 44 ++++++++++++++++++++++ .../mod/scripts/vscripts/sh_utility_all.gnut | 15 ++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut (limited to 'Northstar.CustomServers/mod') diff --git a/Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut b/Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut new file mode 100644 index 00000000..b535f327 --- /dev/null +++ b/Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut @@ -0,0 +1,44 @@ +untyped + +globalize_all_functions + +global struct ClServer_MessageStruct { + string message + entity player + int channelId + bool shouldBlock +} + +struct { + array< ClServer_MessageStruct functionref( ClServer_MessageStruct ) > OnRecievedSayTextMessageCallbacks +} NsCustomCallbacks + +void function CServerGameDLL_ProcessMessageStartThread() +{ + thread CServerGameDLL_OnRecievedSayTextMessageCallback() +} + +void function CServerGameDLL_OnRecievedSayTextMessageCallback() +{ + ClServer_MessageStruct localMessage + localMessage.message = NSChatGetCurrentMessage() + localMessage.player = GetPlayerByIndex(NSChatGetCurrentPlayer()) + localMessage.channelId = NSChatGetCurrentChannel() + localMessage.shouldBlock = false + + foreach ( callbackFunc in NsCustomCallbacks.OnRecievedSayTextMessageCallbacks ) + { + ClServer_MessageStruct returnStruct = callbackFunc(localMessage) + localMessage.message = returnStruct.message + localMessage.player = returnStruct.player + localMessage.channelId = returnStruct.channelId + localMessage.shouldBlock = localMessage.shouldBlock || returnStruct.shouldBlock + } + + NSSetMessage(localMessage.message, localMessage.player.GetPlayerIndex(), localMessage.channelId, localMessage.shouldBlock) +} + +void function AddCallback_OnRecievedSayTextMessage( ClServer_MessageStruct functionref (ClServer_MessageStruct) callbackFunc ) +{ + NsCustomCallbacks.OnRecievedSayTextMessageCallbacks.append(callbackFunc) +} \ No newline at end of file diff --git a/Northstar.CustomServers/mod/scripts/vscripts/sh_utility_all.gnut b/Northstar.CustomServers/mod/scripts/vscripts/sh_utility_all.gnut index a6044762..1c509660 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/sh_utility_all.gnut +++ b/Northstar.CustomServers/mod/scripts/vscripts/sh_utility_all.gnut @@ -348,16 +348,23 @@ string function GetMapDisplayDesc( string mapname ) return "#" + mapname + "_CLASSIC_DESC" } -string function StringReplace( string baseString, string searchString, string replaceString ) +string function StringReplace( string baseString, string searchString, string replaceString, bool replaceAll = false, bool caseInsensitive = false ) { - var findResult = baseString.find( searchString ) - - if ( findResult != null ) + bool loopedOnce = false + string source = caseInsensitive ? baseString.tolower() : baseString + var findResult = source.find( searchString ) + while ( findResult != null && !(loopedOnce && !replaceAll)) { string part1 = baseString.slice( 0, findResult ) string part2 = baseString.slice( findResult + searchString.len(), baseString.len() ) baseString = part1 + replaceString + part2 + source = part1 + replaceString + part2 + + loopedOnce = true + findResult = source.find( searchString ) + print("LOOPED ONCE") + print(findResult) } return baseString -- cgit v1.2.3