reply handling
parent
a2ac6a66d5
commit
8fe0e0c60d
|
@ -21,17 +21,17 @@ 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
|
||||||
VoiceConn *websocket.Conn
|
VoiceConn *websocket.Conn
|
||||||
voiceConnMu sync.Mutex
|
voiceConnMu sync.Mutex
|
||||||
VoiceCmdIDs []int
|
VoiceCmdIDs []int
|
||||||
voiceCmdIDMu sync.Mutex
|
voiceCmdIDMu sync.Mutex
|
||||||
VoiceCMDIDsByBackend []*A
|
VoiceCMDIDsByBackend map[int]*A // messages from backend to voice, when response from voice then response to target requester
|
||||||
voiceCMDIDsByBackendMu sync.Mutex
|
//voiceCMDIDsByBackendMu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error {
|
func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error {
|
||||||
|
|
|
@ -77,12 +77,12 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
||||||
if status == kraProtocol.StatusGet {
|
if status == kraProtocol.StatusGet {
|
||||||
webClient := GetWebClientByUuid(playerUuid)
|
webClient := GetWebClientByUuid(playerUuid)
|
||||||
|
|
||||||
a := &structs.A{CmdID: 20, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
|
a := &structs.A{CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
|
||||||
|
|
||||||
webClient.VoiceCMDIDsByBackend = append(webClient.VoiceCMDIDsByBackend, a)
|
|
||||||
|
|
||||||
cmdID = 20
|
cmdID = 20
|
||||||
|
|
||||||
|
webClient.VoiceCMDIDsByBackend[cmdID] = a
|
||||||
|
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, cmdID, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, cmdID, cmdNumber, args)
|
||||||
} else {
|
} else {
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusSend, 0, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusSend, 0, cmdNumber, args)
|
||||||
|
|
|
@ -45,7 +45,19 @@ func HandleWebMessage(isVoice bool, conn *websocket.Conn, uuid string, msg []byt
|
||||||
|
|
||||||
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusReply, data.CmdIDFromMinecraftServer, 0, webClient.Uuid, 0, "")
|
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusReply, data.CmdIDFromMinecraftServer, 0, webClient.Uuid, 0, "")
|
||||||
|
|
||||||
mcClient.SendBinaryMessage(raw)
|
err = mcClient.SendBinaryMessage(raw)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Web.Warnln("write:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove cmdID from VoiceCMDIDsByBackend list
|
||||||
|
delete(webClient.VoiceCMDIDsByBackend, cmdID)
|
||||||
|
|
||||||
|
// remove cmdID from voiceCmdIDs
|
||||||
|
webClient.RemoveVoiceCmdID(cmdID)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue