From b42f0732129cafce4ff5530a9a371a639970955f Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 1 Jan 2022 12:52:32 +0100 Subject: [PATCH] reply handling --- modules/structs/WebClient.go | 37 +++++++++++++++++++++----------- serverCommunication/minecraft.go | 4 +++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/modules/structs/WebClient.go b/modules/structs/WebClient.go index 2037739..46863e0 100644 --- a/modules/structs/WebClient.go +++ b/modules/structs/WebClient.go @@ -21,19 +21,20 @@ type A struct { } type WebClient struct { - Uuid string - MobileConn *websocket.Conn - mobileConnMu sync.Mutex - MobileCmdIDs []int - mobileCmdIDMu sync.Mutex - MobileCmdIDsByBackend []*A - mobileCmdIDsByBackendMu sync.Mutex - VoiceConn *websocket.Conn - voiceConnMu sync.Mutex - VoiceCmdIDs []int - voiceCmdIDMu sync.Mutex - VoiceCmdIDsByBackend []*A // messages from backend to voice, when response from voice then response to target requester - voiceCmdIDsByBackendMu sync.Mutex + Uuid string + MobileConn *websocket.Conn + mobileConnMu sync.Mutex + MobileCmdIDs []int + mobileCmdIDMu sync.Mutex + MobileCmdIDsByBackend []*A + mobileCmdIDsByBackendMu sync.Mutex + VoiceConn *websocket.Conn + voiceConnMu sync.Mutex + VoiceCmdIDs []int + voiceCmdIDMu sync.Mutex + VoiceCmdIDsByBackend []*A // messages from backend to voice, when response from voice then response to target requester + voiceCmdIDsByBackendMu sync.Mutex + CurrentCmdIDIndexByBackend int } func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error { @@ -119,3 +120,13 @@ func getCmdIDIndexFromList(arr []int, cmdID int) int { } return -1 } + +func GenerateWebCmdID(currentIndex int) int { + if currentIndex >= 250 || currentIndex < 10 { + return 10 + } + + currentIndex++ + + return currentIndex +} diff --git a/serverCommunication/minecraft.go b/serverCommunication/minecraft.go index 0068b71..75fc471 100644 --- a/serverCommunication/minecraft.go +++ b/serverCommunication/minecraft.go @@ -78,7 +78,9 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) { if status == kraProtocol.StatusGet { webClient := GetWebClientByUuid(playerUuid) - webCmdID := 20 + webCmdID := structs.GenerateWebCmdID(webClient.CurrentCmdIDIndexByBackend) + + logger.Minecraft.Debugln("webCmdID", webCmdID) a := &structs.A{WebCmdID: webCmdID, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}