aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut
diff options
context:
space:
mode:
authorEmma Miler <27428383+emma-miler@users.noreply.github.com>2022-02-07 00:28:10 +0100
committerBarichello <artur@barichello.me>2022-02-12 15:45:10 -0300
commit94f7f68bf9153d39fcdb38d614f1774cdb2fc33f (patch)
tree53fc9eff2ca3e294b0d19b11cd4a355203b7cdf7 /Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut
parent7e11339956c4e51a9d3901e963de0b8d5562f9d8 (diff)
downloadNorthstarMods-94f7f68bf9153d39fcdb38d614f1774cdb2fc33f.tar.gz
NorthstarMods-94f7f68bf9153d39fcdb38d614f1774cdb2fc33f.zip
Server-side code for chathooks
Diffstat (limited to 'Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut')
-rw-r--r--Northstar.CustomServers/mod/scripts/vscripts/_custom_codecallbacks.gnut44
1 files changed, 44 insertions, 0 deletions
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 000000000..b535f327c
--- /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