map language to server instead of session

This commit is contained in:
wish
2022-11-09 23:50:40 +11:00
parent 7789424a08
commit 10b2ddcfd7
7 changed files with 9 additions and 19 deletions

View File

@@ -14,6 +14,7 @@ import (
type Config struct {
Host string `mapstructure:"Host"`
BinPath string `mapstructure:"BinPath"`
Language string
DisableSoftCrash bool // Disables the 'Press Return to exit' dialog allowing scripts to reboot the server automatically
FeaturedWeapons int // Number of Active Feature weapons to generate daily
HideLoginNotice bool // Hide the Erupe notice on login

View File

@@ -1,6 +0,0 @@
BEGIN;
ALTER TABLE IF EXISTS public.users
ADD COLUMN IF NOT EXISTS language text NOT NULL DEFAULT 'en';
END;

View File

@@ -142,7 +142,6 @@ func handleMsgSysLogin(s *Session, p mhfpacket.MHFPacket) {
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,7 @@ func handleMsgMhfGetCafeDuration(s *Session, p mhfpacket.MHFPacket) {
}
bf.WriteUint32(cafeTime) // Total cafe time
bf.WriteUint16(0)
ps.Uint16(bf, fmt.Sprintf(s.dict["cafeReset"], int(cafeReset.Month()), cafeReset.Day()), true)
ps.Uint16(bf, fmt.Sprintf(s.server.dict["cafeReset"], int(cafeReset.Month()), cafeReset.Day()), true)
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}

View File

@@ -1,15 +1,8 @@
package channelserver
import "go.uber.org/zap"
func getLangStrings(s *Session) map[string]string {
var lang string
func getLangStrings(s *Server) map[string]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 {
switch s.erupeConfig.Language {
case "jp":
strings["language"] = "日本語"
strings["cafeReset"] = "%d/%dにリセット"

View File

@@ -52,6 +52,9 @@ type Server struct {
stagesLock sync.RWMutex
stages map[string]*Stage
// Used to map different languages
dict map[string]string
// UserBinary
userBinaryPartsLock sync.RWMutex
userBinaryParts map[userBinaryPartID][]byte
@@ -164,6 +167,8 @@ func NewServer(config *Config) *Server {
// MezFes
s.stages["sl1Ns462p0a0u0"] = NewStage("sl1Ns462p0a0u0")
s.dict = getLangStrings(s)
return s
}

View File

@@ -47,8 +47,6 @@ 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)