reply handling
parent
134c30fa9c
commit
e92f715da7
|
@ -26,12 +26,14 @@ type WebClient struct {
|
||||||
mobileConnMu sync.Mutex
|
mobileConnMu sync.Mutex
|
||||||
MobileCmdIDs []int
|
MobileCmdIDs []int
|
||||||
mobileCmdIDMu sync.Mutex
|
mobileCmdIDMu sync.Mutex
|
||||||
|
MobileCmdIDsByBackend []*A
|
||||||
|
mobileCmdIDsByBackendMu 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 // messages from backend to voice, when response from voice then response to target requester
|
VoiceCmdIDsByBackend []*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 {
|
||||||
|
@ -71,13 +73,27 @@ func (webClient *WebClient) RemoveMobileCmdID(cmdID int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (webClient *WebClient) RemoveVoiceCMDIDsByBackend(cmdID int) {
|
func (webClient *WebClient) RemoveVoiceCmdIDByBackend(cmdID int) {
|
||||||
logger.Web.Debugln("before", webClient.VoiceCMDIDsByBackend)
|
webClient.voiceCmdIDsByBackendMu.Lock()
|
||||||
for i, data := range webClient.VoiceCMDIDsByBackend {
|
defer webClient.voiceCmdIDsByBackendMu.Unlock()
|
||||||
|
|
||||||
|
for i, data := range webClient.VoiceCmdIDsByBackend {
|
||||||
if data.WebCmdID == cmdID {
|
if data.WebCmdID == cmdID {
|
||||||
newArr := append(webClient.VoiceCMDIDsByBackend[:i], webClient.VoiceCMDIDsByBackend[i+1:]...)
|
newArr := append(webClient.VoiceCmdIDsByBackend[:i], webClient.VoiceCmdIDsByBackend[i+1:]...)
|
||||||
webClient.VoiceCMDIDsByBackend = newArr
|
webClient.VoiceCmdIDsByBackend = newArr
|
||||||
logger.Web.Debugln("after", webClient.VoiceCMDIDsByBackend)
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,24 +103,17 @@ func removeCmdIDFromList(arr []int, cmdID int) ([]int, error) {
|
||||||
index := getCmdIDIndexFromList(arr, cmdID)
|
index := getCmdIDIndexFromList(arr, cmdID)
|
||||||
|
|
||||||
if index == -1 {
|
if index == -1 {
|
||||||
logger.Web.Warnln("index", index)
|
|
||||||
return []int{}, errors.New("index not found")
|
return []int{}, errors.New("index not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Web.Debugln("removeFromList before append", arr)
|
|
||||||
|
|
||||||
newArr := append(arr[:index], arr[index+1:]...)
|
newArr := append(arr[:index], arr[index+1:]...)
|
||||||
|
|
||||||
logger.Web.Debugln("removeFromList after append", newArr)
|
|
||||||
|
|
||||||
return newArr, nil
|
return newArr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCmdIDIndexFromList(arr []int, cmdID int) int {
|
func getCmdIDIndexFromList(arr []int, cmdID int) int {
|
||||||
for i := 0; i < len(arr); i++ {
|
for i := 0; i < len(arr); i++ {
|
||||||
logger.Minecraft.Info("getCmdIDIndexFromList", i, arr[i], cmdID)
|
|
||||||
if arr[i] == cmdID {
|
if arr[i] == cmdID {
|
||||||
logger.Web.Debugln("getCmdIDIndexFromList", i)
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,9 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
||||||
|
|
||||||
a := &structs.A{WebCmdID: webCmdID, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
|
a := &structs.A{WebCmdID: webCmdID, CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
|
||||||
|
|
||||||
webClient.VoiceCMDIDsByBackend = append(webClient.VoiceCMDIDsByBackend, a)
|
webClient.VoiceCmdIDsByBackend = append(webClient.VoiceCmdIDsByBackend, a)
|
||||||
|
|
||||||
logger.Minecraft.Debugln("VoiceCMDIDsByBackend", webClient.VoiceCMDIDsByBackend)
|
logger.Minecraft.Debugln("VoiceCMDIDsByBackend", webClient.VoiceCmdIDsByBackend)
|
||||||
|
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, webCmdID, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, webCmdID, cmdNumber, args)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,18 +29,10 @@ func HandleWebMessage(isVoice bool, conn *websocket.Conn, uuid string, msg []byt
|
||||||
|
|
||||||
status, cmdID, dest, cmdNumber, args := kraProtocol.DecodeWebMessage(msg)
|
status, cmdID, dest, cmdNumber, args := kraProtocol.DecodeWebMessage(msg)
|
||||||
|
|
||||||
logger.Web.Debugln("kraProtocol", status, cmdID, dest, cmdNumber, args)
|
|
||||||
|
|
||||||
if status == kraProtocol.StatusReply {
|
if status == kraProtocol.StatusReply {
|
||||||
// TODO: TODO: handling reply - answering message to target dest (ex. GameServer-1)
|
|
||||||
|
|
||||||
if isVoice {
|
if isVoice {
|
||||||
for i, data := range webClient.VoiceCMDIDsByBackend {
|
for _, data := range webClient.VoiceCmdIDsByBackend {
|
||||||
logger.Web.Debugln("vCmdID range", i, data, cmdID)
|
if data.WebCmdID == cmdID { // forward to target dest
|
||||||
if data.WebCmdID == cmdID {
|
|
||||||
// forward to target dest
|
|
||||||
|
|
||||||
logger.Web.Debugln("forward to target dest", data)
|
|
||||||
mcClient := GetMinecraftClientByName(getMinecraftServerNameByDest(data.DestFromMinecraftServer))
|
mcClient := GetMinecraftClientByName(getMinecraftServerNameByDest(data.DestFromMinecraftServer))
|
||||||
|
|
||||||
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusReply, data.CmdIDFromMinecraftServer, 0, webClient.Uuid, 0, "")
|
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusReply, data.CmdIDFromMinecraftServer, 0, webClient.Uuid, 0, "")
|
||||||
|
@ -53,7 +45,7 @@ func HandleWebMessage(isVoice bool, conn *websocket.Conn, uuid string, msg []byt
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove cmdID from VoiceCMDIDsByBackend list
|
// remove cmdID from VoiceCMDIDsByBackend list
|
||||||
webClient.RemoveVoiceCMDIDsByBackend(cmdID)
|
webClient.RemoveVoiceCmdIDByBackend(cmdID)
|
||||||
|
|
||||||
// remove cmdID from minecraftCmdIDs
|
// remove cmdID from minecraftCmdIDs
|
||||||
mcClient.RemoveCmdID(data.CmdIDFromMinecraftServer)
|
mcClient.RemoveCmdID(data.CmdIDFromMinecraftServer)
|
||||||
|
|
Loading…
Reference in New Issue