reply handling
parent
570ce95091
commit
c69201ff61
|
@ -14,16 +14,23 @@ type WebClientDb struct {
|
||||||
MobileSessionToken string
|
MobileSessionToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type A struct {
|
||||||
|
CmdIDFromMinecraftServer int
|
||||||
|
DestFromMinecraftServer int
|
||||||
|
}
|
||||||
|
|
||||||
type WebClient struct {
|
type WebClient struct {
|
||||||
Uuid string
|
Uuid string
|
||||||
MobileConn *websocket.Conn
|
MobileConn *websocket.Conn
|
||||||
mobileConnMu sync.Mutex
|
mobileConnMu sync.Mutex
|
||||||
VoiceConn *websocket.Conn
|
MobileCmdIDs []int
|
||||||
voiceConnMu sync.Mutex
|
mobileCmdIDMu sync.Mutex
|
||||||
MobileCmdIDs []int
|
VoiceConn *websocket.Conn
|
||||||
mobileCmdIDMu sync.Mutex
|
voiceConnMu sync.Mutex
|
||||||
VoiceCmdIDs []int
|
VoiceCmdIDs []int
|
||||||
voiceCmdIDMu sync.Mutex
|
voiceCmdIDMu sync.Mutex
|
||||||
|
VoiceCMDIDsByBackend map[int]*A // key: cmdID, value: minecraftServerDest
|
||||||
|
voiceCMDIDsByBackendMu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error {
|
func (webClient *WebClient) SendBinaryMessage(conn *websocket.Conn, msg []byte) error {
|
||||||
|
|
|
@ -21,6 +21,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
@ -74,9 +75,15 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if status == kraProtocol.StatusGet {
|
if status == kraProtocol.StatusGet {
|
||||||
|
webClient := GetWebClientByUuid(playerUuid)
|
||||||
|
|
||||||
|
cmdID = 20
|
||||||
|
|
||||||
|
webClient.VoiceCMDIDsByBackend[20] = &structs.A{CmdIDFromMinecraftServer: cmdID, DestFromMinecraftServer: 10}
|
||||||
|
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, cmdID, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusGet, cmdID, cmdNumber, args)
|
||||||
} else {
|
} else {
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusSend, cmdID, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusSend, 0, cmdNumber, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dest == kraProtocol.DestVoice {
|
if dest == kraProtocol.DestVoice {
|
||||||
|
@ -101,7 +108,7 @@ func HandleMinecraftMessage(conn *websocket.Conn, msg []byte) {
|
||||||
if status == kraProtocol.StatusGet {
|
if status == kraProtocol.StatusGet {
|
||||||
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusGet, cmdID, dest, playerUuid, cmdNumber, args)
|
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusGet, cmdID, dest, playerUuid, cmdNumber, args)
|
||||||
} else {
|
} else {
|
||||||
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusSend, cmdID, dest, playerUuid, cmdNumber, args)
|
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusSend, 0, dest, playerUuid, cmdNumber, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.SendBinaryMessage(raw)
|
err = client.SendBinaryMessage(raw)
|
||||||
|
|
|
@ -34,6 +34,22 @@ func HandleWebMessage(isVoice bool, conn *websocket.Conn, uuid string, msg []byt
|
||||||
if status == kraProtocol.StatusReply {
|
if status == kraProtocol.StatusReply {
|
||||||
// TODO: TODO: handling reply - answering message to target dest (ex. GameServer-1)
|
// TODO: TODO: handling reply - answering message to target dest (ex. GameServer-1)
|
||||||
|
|
||||||
|
if isVoice {
|
||||||
|
for vCmdID := range webClient.VoiceCMDIDsByBackend {
|
||||||
|
if vCmdID == cmdID {
|
||||||
|
// forward to target dest
|
||||||
|
targetMcServer := webClient.VoiceCMDIDsByBackend[cmdID]
|
||||||
|
|
||||||
|
mcClient := GetMinecraftClientByName(getMinecraftServerNameByDest(targetMcServer.DestFromMinecraftServer))
|
||||||
|
|
||||||
|
raw = kraProtocol.EncodeJavaMessage(kraProtocol.StatusReply, targetMcServer.CmdIDFromMinecraftServer, 0, webClient.Uuid, 0, "")
|
||||||
|
|
||||||
|
mcClient.SendBinaryMessage(raw)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if isVoice && isCmdIDInList(webClient.VoiceCmdIDs, cmdID) {
|
if isVoice && isCmdIDInList(webClient.VoiceCmdIDs, cmdID) {
|
||||||
webClient.RemoveVoiceCmdID(cmdID)
|
webClient.RemoveVoiceCmdID(cmdID)
|
||||||
} else if isCmdIDInList(webClient.MobileCmdIDs, cmdID) {
|
} else if isCmdIDInList(webClient.MobileCmdIDs, cmdID) {
|
||||||
|
|
Loading…
Reference in New Issue