diff --git a/modules/structs/WebClient.go b/modules/structs/WebClient.go index c663698..460e09e 100644 --- a/modules/structs/WebClient.go +++ b/modules/structs/WebClient.go @@ -22,29 +22,21 @@ type A struct { } type WebClient struct { - Uuid string - MobileConn *websocket.Conn - mobileConnMu sync.Mutex - //MobileCmdIDs []int // cache for received cmdIDs - //mobileCmdIDMu sync.Mutex - //MobileCmdIDsByBackend []*A - //mobileCmdIDsByBackendMu sync.Mutex + Uuid string + MobileConn *websocket.Conn + mobileConnMu sync.Mutex CurrentMobileSendMessageCmdIDIndexByBackend int VoiceConn *websocket.Conn voiceConnMu sync.Mutex - //VoiceCmdIDs []int // cache for received cmdIDs - //voiceCmdIDMu sync.Mutex - //VoiceCmdIDsByBackend []*A // messages from backend to voice, when response from voice then response to target requester - //voiceCmdIDsByBackendMu sync.Mutex - CurrentVoiceSendMessageCmdIDIndexByBackend int - SendVoiceQueueMessages []*SendQueueMessage - sendVoiceQueueMessagesMu sync.Mutex - SendMobileQueueMessages []*SendQueueMessage - sendMobileQueueMessagesMu sync.Mutex - ReceivedVoiceQueueMessages []*ReceivedQueueMessage - receivedVoiceQueueMessagesMu sync.Mutex - ReceivedMobileQueueMessages []*ReceivedQueueMessage - receivedMobileQueueMessagesMu sync.Mutex + CurrentVoiceSendMessageCmdIDIndexByBackend int + SendVoiceQueueMessages []*SendQueueMessage + sendVoiceQueueMessagesMu sync.Mutex + SendMobileQueueMessages []*SendQueueMessage + sendMobileQueueMessagesMu sync.Mutex + ReceivedVoiceQueueMessages []*ReceivedQueueMessage + receivedVoiceQueueMessagesMu sync.Mutex + ReceivedMobileQueueMessages []*ReceivedQueueMessage + receivedMobileQueueMessagesMu sync.Mutex } func (webClient *WebClient) AddMessageToVoiceSendQueue(originDest int, originCmdID int, messageRaw []byte, cmdID int) { @@ -217,80 +209,6 @@ func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) return err } -/* -func (webClient *WebClient) RemoveVoiceCmdID(cmdID int) { - webClient.voiceCmdIDMu.Lock() - defer webClient.voiceCmdIDMu.Unlock() - - newArr, err := removeCmdIDFromList(webClient.VoiceCmdIDs, cmdID) - - if err != nil { - logger.WebVoice.Warnln("removeCmdIDFromList:", err) - } else { - webClient.VoiceCmdIDs = newArr - } -} - -func (webClient *WebClient) RemoveMobileCmdID(cmdID int) { - webClient.mobileCmdIDMu.Lock() - defer webClient.mobileCmdIDMu.Unlock() - - newArr, err := removeCmdIDFromList(webClient.MobileCmdIDs, cmdID) - - if err != nil { - logger.WebMobile.Warnln("removeCmdIDFromList:", err) - } else { - webClient.MobileCmdIDs = newArr - } -} - -func (webClient *WebClient) RemoveVoiceCmdIDByBackend(cmdID int) { - webClient.voiceCmdIDsByBackendMu.Lock() - defer webClient.voiceCmdIDsByBackendMu.Unlock() - - for i, data := range webClient.VoiceCmdIDsByBackend { - if data.WebCmdID == cmdID { - newArr := append(webClient.VoiceCmdIDsByBackend[:i], webClient.VoiceCmdIDsByBackend[i+1:]...) - webClient.VoiceCmdIDsByBackend = newArr - return - } - } -} - -func (webClient *WebClient) RemoveMobileCmdIDByBackend(cmdID int) { - webClient.mobileCmdIDsByBackendMu.Lock() - defer webClient.mobileCmdIDsByBackendMu.Unlock() - - for i, data := range webClient.MobileCmdIDsByBackend { - if data.WebCmdID == cmdID { - newArr := append(webClient.MobileCmdIDsByBackend[:i], webClient.MobileCmdIDsByBackend[i+1:]...) - webClient.MobileCmdIDsByBackend = newArr - return - } - } -} - -func removeCmdIDFromList(arr []int, cmdID int) ([]int, error) { - index := getCmdIDIndexFromList(arr, cmdID) - - if index == -1 { - return []int{}, errors.New("index not found") - } - - newArr := append(arr[:index], arr[index+1:]...) - - return newArr, nil -} - -func getCmdIDIndexFromList(arr []int, cmdID int) int { - for i := 0; i < len(arr); i++ { - if arr[i] == cmdID { - return i - } - } - return -1 -} -*/ func GenerateWebCmdID(currentIndex int) int { if currentIndex >= 250 || currentIndex < 10 { return 10 diff --git a/serverCommunication/minecraft.go b/serverCommunication/minecraft.go index 1ed046f..75bfd76 100644 --- a/serverCommunication/minecraft.go +++ b/serverCommunication/minecraft.go @@ -264,6 +264,8 @@ func SendMessageToMinecraftServer(originDest int, originCmdID int, status int, d return errors.New("mcClient nil") } + logger.Minecraft.Warnln("status is get", status == kraProtocol.StatusGet) + if status == kraProtocol.StatusGet { cmdID = mcClient.GenerateMinecraftCmdID() }