From d1d2b4bd4a024ba5f16d79f11cd1bce73c8b6f63 Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 5 Sep 2020 13:55:36 +0200 Subject: [PATCH] made changes --- src/go/tsgo/tsgo.go | 48 +++++++++++++++++++++++++------------------ src/go/tsgo_export.go | 32 +++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/go/tsgo/tsgo.go b/src/go/tsgo/tsgo.go index e06169d..252c65b 100644 --- a/src/go/tsgo/tsgo.go +++ b/src/go/tsgo/tsgo.go @@ -1,29 +1,27 @@ package tsgo -// Ts3pluginName Name of the plugin -func Ts3pluginName() string { - return "Go Plugin Yay" +type AnyId uint16 +type PluginMessageTarget int + +type Ts3FunctionsStruct struct { + PrintMessage func(uint64, string, PluginMessageTarget) } -// Ts3pluginVersion Version of the plugin -func Ts3pluginVersion() string { - return "1.0" -} +const ( + PLUGIN_MESSAGE_TARGET_SERVER PluginMessageTarget = 0 + PLUGIN_MESSAGE_TARGET_CHANNEL PluginMessageTarget = 1 +) -// Ts3pluginAPIVersion API version of the plugin -func Ts3pluginAPIVersion() int { - return 23 -} +const ( + PluginName = "Go Plugin yay" + PluginVersion = "1.0" + PluginAuthor = "Author" + PluginDescription = "Description" +) -// Ts3pluginAuthor Plugin author -func Ts3pluginAuthor() string { - return "Author" -} - -// Ts3pluginDescription Plugin description -func Ts3pluginDescription() string { - return "Description" -} +var ( + Ts3Functions Ts3FunctionsStruct +) //Ts3pluginInit init plugin function func Ts3pluginInit() int { @@ -34,3 +32,13 @@ func Ts3pluginInit() int { func Ts3pluginShutdown() { } + +/* + Events +*/ + +// Ts3onClientPokeEvent event +func Ts3onClientPokeEvent(serverConnectionHandlerID uint64, fromClientID AnyId, pokerName string, pokerUniqueIdentity string, message string, ffIgnored int) int { + Ts3Functions.PrintMessage(serverConnectionHandlerID, "Ayy", PLUGIN_MESSAGE_TARGET_SERVER) + return 1 +} diff --git a/src/go/tsgo_export.go b/src/go/tsgo_export.go index 99959fc..74449c1 100644 --- a/src/go/tsgo_export.go +++ b/src/go/tsgo_export.go @@ -23,31 +23,35 @@ func main() {} // Required if you want to export functions //export GoTs3pluginName func GoTs3pluginName() *C.char { - return C.CString(tsgo.Ts3pluginName()) + return C.CString(tsgo.PluginName) } //export GoTs3pluginVersion func GoTs3pluginVersion() *C.char { - return C.CString(tsgo.Ts3pluginVersion()) + return C.CString(tsgo.PluginVersion) } //export GoTs3pluginAPIVersion func GoTs3pluginAPIVersion() C.int { - return C.int(tsgo.Ts3pluginAPIVersion()) + return C.int(23) } //export GoTs3pluginAuthor func GoTs3pluginAuthor() *C.char { - return C.CString(tsgo.Ts3pluginAuthor()) + return C.CString(tsgo.PluginAuthor) } //export GoTs3pluginDescription func GoTs3pluginDescription() *C.char { - return C.CString(tsgo.Ts3pluginDescription()) + return C.CString(tsgo.PluginDescription) } //export GoTs3pluginInit func GoTs3pluginInit() C.int { + tsgo.Ts3Functions = tsgo.Ts3FunctionsStruct{ + PrintMessage: ts3FncPrintMessage, + } + return C.int(tsgo.Ts3pluginInit()) } @@ -61,7 +65,19 @@ func GoTs3pluginShutdown() { */ //export GoTs3onClientPokeEvent -func GoTs3onClientPokeEvent(serverConnectionHandlerID C.uint64, fromClientID C.anyID, pokerName *C.char, pokerUniqueIdentity *C.char, message *C.char, ffIgnored int) C.int { - C.Ts3FncPrintMessage(serverConnectionHandlerID, C.CString("Ayyyy"), C.PLUGIN_SERVER) - return 1 +func GoTs3onClientPokeEvent(serverConnectionHandlerID C.uint64, fromClientID C.anyID, pokerName *C.char, pokerUniqueIdentity *C.char, message *C.char, ffIgnored C.int) C.int { + return C.int(tsgo.Ts3onClientPokeEvent(uint64(serverConnectionHandlerID), tsgo.AnyId(fromClientID), C.GoString(pokerName), C.GoString(pokerUniqueIdentity), C.GoString(message), int(ffIgnored))) +} + +/* + Ts3 Function wrapper +*/ + +func ts3FncPrintMessage(serverConnectionHandlerID uint64, message string, messageTarget tsgo.PluginMessageTarget) { + switch messageTarget { + case tsgo.PLUGIN_MESSAGE_TARGET_CHANNEL: + C.Ts3FncPrintMessage(C.uint64(serverConnectionHandlerID), C.CString(message), C.PLUGIN_MESSAGE_TARGET_CHANNEL) + case tsgo.PLUGIN_MESSAGE_TARGET_SERVER: + C.Ts3FncPrintMessage(C.uint64(serverConnectionHandlerID), C.CString(message), C.PLUGIN_MESSAGE_TARGET_SERVER) + } }