initial multi-language concept

This commit is contained in:
wish
2022-11-07 00:35:45 +11:00
parent 6c3be9c32e
commit 7789424a08
5 changed files with 33 additions and 1 deletions

View File

@@ -141,6 +141,8 @@ func handleMsgSysLogin(s *Session, p mhfpacket.MHFPacket) {
s.charID = pkt.CharID0
s.token = pkt.LoginTokenString
s.Unlock()
s.dict = getLangStrings(s)
updateRights(s)
bf := byteframe.NewByteFrame()
bf.WriteUint32(uint32(Time_Current_Adjusted().Unix())) // Unix timestamp

View File

@@ -89,7 +89,8 @@ func handleMsgMhfGetCafeDuration(s *Session, p mhfpacket.MHFPacket) {
}
bf.WriteUint32(cafeTime) // Total cafe time
bf.WriteUint16(0)
ps.Uint16(bf, fmt.Sprintf("Resets on %s %d", cafeReset.Month().String(), cafeReset.Day()), true)
ps.Uint16(bf, fmt.Sprintf(s.dict["cafeReset"], int(cafeReset.Month()), cafeReset.Day()), true)
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}

View File

@@ -0,0 +1,21 @@
package channelserver
import "go.uber.org/zap"
func getLangStrings(s *Session) map[string]string {
var lang string
strings := make(map[string]string)
err := s.server.db.QueryRow(`SELECT language FROM users, characters WHERE characters.id = $1 AND users.id = characters.user_id`, s.charID).Scan(&lang)
if err != nil {
s.logger.Warn("No language set for user", zap.Uint32("CID", s.charID))
}
switch lang {
case "jp":
strings["language"] = "日本語"
strings["cafeReset"] = "%d/%dにリセット"
default:
strings["language"] = "English"
strings["cafeReset"] = "Resets on %d/%d"
}
return strings
}

View File

@@ -47,6 +47,8 @@ type Session struct {
kqf []byte
kqfOverride bool
dict map[string]string
semaphore *Semaphore // Required for the stateful MsgSysUnreserveStage packet.
// A stack containing the stage movement history (push on enter/move, pop on back)