forwarding handling
parent
ac12707391
commit
897c03192a
|
@ -21,20 +21,21 @@ 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
|
||||
CurrentCmdIDIndexByBackend int
|
||||
Uuid string
|
||||
MobileConn *websocket.Conn
|
||||
mobileConnMu sync.Mutex
|
||||
MobileCmdIDs []int
|
||||
mobileCmdIDMu sync.Mutex
|
||||
MobileCmdIDsByBackend []*A
|
||||
mobileCmdIDsByBackendMu sync.Mutex
|
||||
CurrentMobileVoiceCmdIDIndexByBackend int
|
||||
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
|
||||
CurrentVoiceCmdIDIndexByBackend int
|
||||
}
|
||||
|
||||
func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error {
|
||||
|
|
|
@ -21,7 +21,6 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
|||
}
|
||||
|
||||
if status == kraProtocol.StatusReply {
|
||||
// TODO:
|
||||
if isCmdIDInList(mcClient.CmdIDs, cmdID) {
|
||||
mcClient.RemoveCmdID(cmdID)
|
||||
}
|
||||
|
@ -31,6 +30,7 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
|||
var raw []byte
|
||||
var err error
|
||||
|
||||
// queue handling when message already in process
|
||||
if status == kraProtocol.StatusGet {
|
||||
// cmdID already in queue
|
||||
logger.Minecraft.Debugln("cmdIDList", mcClient.CmdIDs)
|
||||
|
@ -49,6 +49,7 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
|||
mcClient.CmdIDs = append(mcClient.CmdIDs, cmdID)
|
||||
}
|
||||
|
||||
// dest handling
|
||||
if dest == kraProtocol.DestBackend {
|
||||
resArgs := minecraftCommandHandler(cmdNumber, playerUuid)
|
||||
|
||||
|
@ -78,17 +79,33 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
|||
if status == kraProtocol.StatusGet {
|
||||
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)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue