Compare commits
3 Commits
10b3c83ed5
...
031dd9a8fd
Author | SHA1 | Date |
---|---|---|
|
031dd9a8fd | |
|
0f61a33a36 | |
|
91db91cdab |
|
@ -23,6 +23,8 @@ const (
|
|||
DestPlayersCurrentServer = 11
|
||||
|
||||
DefaultCmdID = 1
|
||||
|
||||
DummyUUID = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
)
|
||||
|
||||
func EncodeWebMessage(status int, cmdID int, cmdNumber int, args interface{}) []byte {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package minecraft
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/websocket/v2"
|
||||
"krakatoa.net/backend/modules/cache"
|
||||
"krakatoa.net/backend/modules/kraProtocol"
|
||||
"krakatoa.net/backend/modules/logger"
|
||||
"krakatoa.net/backend/modules/structs"
|
||||
serverCommunication "krakatoa.net/backend/serverCommunication"
|
||||
|
@ -17,10 +20,21 @@ func RunHub() {
|
|||
select {
|
||||
case connection := <-register:
|
||||
servername := connection.Query("s")
|
||||
dest := serverCommunication.GenerateDestForNewMinecraftClient()
|
||||
|
||||
cache.MinecraftClients[servername] = &structs.MinecraftClient{Name: servername, Dest: serverCommunication.GenerateDestForNewMinecraftClient(), Conn: connection}
|
||||
cache.MinecraftClients[servername] = &structs.MinecraftClient{Name: servername, Dest: dest, Conn: connection}
|
||||
|
||||
logger.Minecraft.Debugln("connection registered ", connection.Query("c"), connection)
|
||||
logger.Minecraft.Debugln("connection registered ", connection.Query("c"), connection, "dest:", dest)
|
||||
|
||||
mcClient := serverCommunication.GetMinecraftClientByConn(connection)
|
||||
|
||||
raw := kraProtocol.EncodeJavaMessage(kraProtocol.StatusGet, mcClient.GenerateMinecraftCmdID(), 0, kraProtocol.DummyUUID, 33767, strconv.Itoa(mcClient.Dest))
|
||||
|
||||
err := mcClient.SendBinaryMessage(raw)
|
||||
|
||||
if err != nil {
|
||||
logger.Minecraft.Warnln("failed to send msg to mc client:", mcClient.Name, "dest:", mcClient.Dest)
|
||||
}
|
||||
|
||||
case data := <-broadcast:
|
||||
logger.Minecraft.Debugln("message received", data.Msg)
|
||||
|
|
Loading…
Reference in New Issue