forwarding handling

master
Alex 2022-01-01 16:38:18 +01:00
parent ac12707391
commit 897c03192a
2 changed files with 39 additions and 21 deletions

View File

@ -21,20 +21,21 @@ type A struct {
} }
type WebClient struct { type WebClient struct {
Uuid string Uuid string
MobileConn *websocket.Conn MobileConn *websocket.Conn
mobileConnMu sync.Mutex mobileConnMu sync.Mutex
MobileCmdIDs []int MobileCmdIDs []int
mobileCmdIDMu sync.Mutex mobileCmdIDMu sync.Mutex
MobileCmdIDsByBackend []*A MobileCmdIDsByBackend []*A
mobileCmdIDsByBackendMu sync.Mutex mobileCmdIDsByBackendMu sync.Mutex
VoiceConn *websocket.Conn CurrentMobileVoiceCmdIDIndexByBackend int
voiceConnMu sync.Mutex VoiceConn *websocket.Conn
VoiceCmdIDs []int voiceConnMu sync.Mutex
voiceCmdIDMu sync.Mutex VoiceCmdIDs []int
VoiceCmdIDsByBackend []*A // messages from backend to voice, when response from voice then response to target requester voiceCmdIDMu sync.Mutex
voiceCmdIDsByBackendMu sync.Mutex VoiceCmdIDsByBackend []*A // messages from backend to voice, when response from voice then response to target requester
CurrentCmdIDIndexByBackend int voiceCmdIDsByBackendMu sync.Mutex
CurrentVoiceCmdIDIndexByBackend int
} }
func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error { func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error {

View File

@ -21,7 +21,6 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
} }
if status == kraProtocol.StatusReply { if status == kraProtocol.StatusReply {
// TODO:
if isCmdIDInList(mcClient.CmdIDs, cmdID) { if isCmdIDInList(mcClient.CmdIDs, cmdID) {
mcClient.RemoveCmdID(cmdID) mcClient.RemoveCmdID(cmdID)
} }
@ -31,6 +30,7 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
var raw []byte var raw []byte
var err error var err error
// queue handling when message already in process
if status == kraProtocol.StatusGet { if status == kraProtocol.StatusGet {
// cmdID already in queue // cmdID already in queue
logger.Minecraft.Debugln("cmdIDList", mcClient.CmdIDs) logger.Minecraft.Debugln("cmdIDList", mcClient.CmdIDs)
@ -49,6 +49,7 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
mcClient.CmdIDs = append(mcClient.CmdIDs, cmdID) mcClient.CmdIDs = append(mcClient.CmdIDs, cmdID)
} }
// dest handling
if dest == kraProtocol.DestBackend { if dest == kraProtocol.DestBackend {
resArgs := minecraftCommandHandler(cmdNumber, playerUuid) resArgs := minecraftCommandHandler(cmdNumber, playerUuid)
@ -78,17 +79,33 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
if status == kraProtocol.StatusGet { if status == kraProtocol.StatusGet {
webClient := GetWebClientByUuid(playerUuid) webClient := GetWebClientByUuid(playerUuid)
webCmdID := structs.GenerateWebCmdID(webClient.CurrentCmdIDIndexByBackend) var webCmdID int
webClient.CurrentCmdIDIndexByBackend = webCmdID if dest == kraProtocol.DestVoice {
webCmdID = structs.GenerateWebCmdID(webClient.CurrentVoiceCmdIDIndexByBackend)
logger.Minecraft.Debugln("webCmdID", webCmdID) webClient.CurrentVoiceCmdIDIndexByBackend = webCmdID
a := &structs.A{WebCmdID: webCmdID, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10} logger.Minecraft.Debugln("webCmdID", webCmdID)
webClient.VoiceCmdIDsByBackend = append(webClient.VoiceCmdIDsByBackend, a) a := &structs.A{WebCmdID: webCmdID, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
logger.Minecraft.Debugln("VoiceCMDIDsByBackend", webClient.VoiceCmdIDsByBackend) webClient.VoiceCmdIDsByBackend = append(webClient.VoiceCmdIDsByBackend, a)
logger.Minecraft.Debugln("VoiceCMDIDsByBackend", webClient.VoiceCmdIDsByBackend)
} else { // dest mobile
webCmdID = structs.GenerateWebCmdID(webClient.CurrentMobileVoiceCmdIDIndexByBackend)
webClient.CurrentMobileVoiceCmdIDIndexByBackend = webCmdID
logger.Minecraft.Debugln("webCmdID", webCmdID)
a := &structs.A{WebCmdID: webCmdID, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
webClient.MobileCmdIDsByBackend = append(webClient.MobileCmdIDsByBackend, a)
logger.Minecraft.Debugln("MobileCMDIDsByBackend", webClient.MobileCmdIDsByBackend)
}
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, webCmdID, cmdNumber, args) raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, webCmdID, cmdNumber, args)
} else { } else {