Skip to content

Commit

Permalink
simplify config
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiwish committed Dec 31, 2023
1 parent 52082aa commit 0ea0dc2
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 123 deletions.
2 changes: 1 addition & 1 deletion common/mhfcourse/mhfcourse.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func CourseExists(ID uint16, c []Course) bool {
// GetCourseStruct returns a slice of Course(s) from a rights integer
func GetCourseStruct(rights uint32) ([]Course, uint32) {
var resp []Course
for _, c := range _config.ErupeConfig.DevModeOptions.DefaultCourses {
for _, c := range _config.ErupeConfig.DefaultCourses {
resp = append(resp, Course{ID: c})
}
s := Courses()
Expand Down
31 changes: 15 additions & 16 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
"DeleteOnSaveCorruption": false,
"ClientMode": "ZZ",
"QuestCacheExpiry": 300,
"ProxyPort": 0,
"CommandPrefix": "!",
"DevMode": true,
"DevModeOptions": {
"AutoCreateAccount": true,
"AutoCreateAccount": true,
"DefaultCourses": [1, 23, 24],
"EarthStatus": 0,
"EarthID": 0,
"EarthMonsters": [0, 0, 0, 0],
"SaveDumps": {
"Enabled": true,
"RawEnabled": false,
"OutputDir": "save-backups"
},
"DebugOptions": {
"CleanDB": false,
"MaxLauncherHR": false,
"LogInboundMessages": false,
Expand All @@ -28,16 +35,8 @@
"FestaEvent": -1,
"TournamentEvent": 0,
"DisableTokenCheck": false,
"QuestDebugTools": false,
"DefaultCourses": [1, 23, 24],
"EarthStatusOverride": 0,
"EarthIDOverride": 0,
"EarthMonsterOverride": [0, 0, 0, 0],
"SaveDumps": {
"Enabled": true,
"RawEnabled": false,
"OutputDir": "save-backups"
},
"QuestTools": false,
"ProxyPort": 0,
"CapLink": {
"Values": [51728, 20000, 51729, 1, 20000],
"Key": "",
Expand All @@ -58,8 +57,6 @@
"ClanMemberLimits": [[0, 30], [3, 40], [7, 50], [10, 60]],
"BonusQuestAllowance": 3,
"DailyQuestAllowance": 1,
"MezfesSoloTickets": 10,
"MezfesGroupTickets": 4,
"LowLatencyRaviente": false,
"RegularRavienteMaxPlayers": 8,
"ViolentRavienteMaxPlayers": 8,
Expand All @@ -74,6 +71,8 @@
"MaterialMultiplier": 1.00,
"ExtraCarves": 0,
"DisableHunterNavi": false,
"MezFesSoloTickets": 5,
"MezFesGroupTickets": 1,
"MezFesDuration": 172800,
"MezFesSwitchMinigame": false,
"EnableKaijiEvent": false,
Expand Down
72 changes: 35 additions & 37 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,23 @@ type Config struct {
ClientMode string
RealClientMode Mode
QuestCacheExpiry int // Number of seconds to keep quest data cached
ProxyPort uint16 // Forces the game to connect to a channel server proxy
CommandPrefix string // The prefix for commands
DevMode bool

DevModeOptions DevModeOptions
GameplayOptions GameplayOptions
Discord Discord
Commands []Command
Courses []Course
Database Database
Sign Sign
SignV2 SignV2
Channel Channel
Entrance Entrance
}

// DevModeOptions holds various debug/temporary options for use while developing Erupe.
type DevModeOptions struct {
AutoCreateAccount bool // Automatically create accounts if they don't exist
CleanDB bool // Automatically wipes the DB on server reset.
MaxLauncherHR bool // Sets the HR returned in the launcher to HR7 so that you can join non-beginner worlds.
LogInboundMessages bool // Log all messages sent to the server
LogOutboundMessages bool // Log all messages sent to the clients
LogMessageData bool // Log all bytes transferred as a hexdump
MaxHexdumpLength int // Maximum number of bytes printed when logs are enabled
DivaEvent int // Diva Defense event status
FestaEvent int // Hunter's Festa event status
TournamentEvent int // VS Tournament event status
DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!)
QuestDebugTools bool // Enable various quest debug logs
DefaultCourses []uint16
EarthStatusOverride int32
EarthIDOverride int32
EarthMonsterOverride []int32
SaveDumps SaveDumpOptions
CapLink CapLinkOptions
AutoCreateAccount bool // Automatically create accounts if they don't exist
DefaultCourses []uint16
EarthStatus int32
EarthID int32
EarthMonsters []int32
SaveDumps SaveDumpOptions
DebugOptions DebugOptions
GameplayOptions GameplayOptions
Discord Discord
Commands []Command
Courses []Course
Database Database
Sign Sign
SignV2 SignV2
Channel Channel
Entrance Entrance
}

type SaveDumpOptions struct {
Expand All @@ -124,6 +105,23 @@ type SaveDumpOptions struct {
OutputDir string
}

// DebugOptions holds various debug/temporary options for use while developing Erupe.
type DebugOptions struct {
CleanDB bool // Automatically wipes the DB on server reset.
MaxLauncherHR bool // Sets the HR returned in the launcher to HR7 so that you can join non-beginner worlds.
LogInboundMessages bool // Log all messages sent to the server
LogOutboundMessages bool // Log all messages sent to the clients
LogMessageData bool // Log all bytes transferred as a hexdump
MaxHexdumpLength int // Maximum number of bytes printed when logs are enabled
DivaEvent int // Diva Defense event status
FestaEvent int // Hunter's Festa event status
TournamentEvent int // VS Tournament event status
DisableTokenCheck bool // Disables checking login token exists in the DB (security risk!)
QuestTools bool // Enable various quest debug logs
ProxyPort uint16 // Forces the game to connect to a channel server proxy
CapLink CapLinkOptions
}

type CapLinkOptions struct {
Values []uint16
Key string
Expand All @@ -146,8 +144,6 @@ type GameplayOptions struct {
ClanMemberLimits [][]uint8 // Array of maximum Clan Members -> [Rank, Members]
BonusQuestAllowance uint32 // Number of Bonus Point Quests to allow daily
DailyQuestAllowance uint32 // Number of Daily Quests to allow daily
MezfesSoloTickets uint32 // Number of solo tickets given weekly
MezfesGroupTickets uint32 // Number of group tickets given weekly
LowLatencyRaviente bool // Toggles low latency mode for Raviente, can be network intensive
RegularRavienteMaxPlayers uint8
ViolentRavienteMaxPlayers uint8
Expand All @@ -162,6 +158,8 @@ type GameplayOptions struct {
MaterialMultiplier float32 // Adjusts the multiplier of Monster Materials rewarded for quest completion
ExtraCarves uint16 // Grant n extra chances to carve ALL carcasses
DisableHunterNavi bool // Disables the Hunter Navi
MezFesSoloTickets uint32 // Number of solo tickets given weekly
MezFesGroupTickets uint32 // Number of group tickets given weekly
MezFesDuration int // Seconds that MezFes will last for weekly (from 12AM Mon backwards)
MezFesSwitchMinigame bool // Swaps out Volpakkun Together for Tokotoko Partnya
EnableKaijiEvent bool // Enables the Kaiji event in the Rasta Bar
Expand Down
17 changes: 5 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ import (
)

// Temporary DB auto clean on startup for quick development & testing.
func cleanDB(db *sqlx.DB, config *_config.Config) {
func cleanDB(db *sqlx.DB) {
_ = db.MustExec("DELETE FROM guild_characters")
_ = db.MustExec("DELETE FROM guilds")
_ = db.MustExec("DELETE FROM characters")
if config.ProxyPort == 0 {
_ = db.MustExec("DELETE FROM sign_sessions")
}
_ = db.MustExec("DELETE FROM users")
}

Expand All @@ -48,11 +45,7 @@ func main() {

var zapLogger *zap.Logger
config := _config.ErupeConfig
if config.DevMode {
zapLogger, _ = zap.NewDevelopment()
} else {
zapLogger, _ = zap.NewProduction()
}
zapLogger, _ = zap.NewDevelopment()

defer zapLogger.Sync()
logger := zapLogger.Named("main")
Expand Down Expand Up @@ -126,16 +119,16 @@ func main() {
logger.Info("Database: Started successfully")

// Clear stale data
if config.ProxyPort == 0 {
if config.DebugOptions.ProxyPort == 0 {
_ = db.MustExec("DELETE FROM sign_sessions")
}
_ = db.MustExec("DELETE FROM servers")
_ = db.MustExec(`UPDATE guild_characters SET treasure_hunt=NULL`)

// Clean the DB if the option is on.
if config.DevMode && config.DevModeOptions.CleanDB {
if config.DebugOptions.CleanDB {
logger.Info("Database: Started clearing...")
cleanDB(db, config)
cleanDB(db)
logger.Info("Database: Finished clearing")
}

Expand Down
10 changes: 5 additions & 5 deletions server/channelserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func stubEnumerateNoResults(s *Session, ackHandle uint32) {

func doAckEarthSucceed(s *Session, ackHandle uint32, data []*byteframe.ByteFrame) {
bf := byteframe.NewByteFrame()
bf.WriteUint32(uint32(s.server.erupeConfig.DevModeOptions.EarthIDOverride))
bf.WriteUint32(uint32(s.server.erupeConfig.EarthID))
bf.WriteUint32(0)
bf.WriteUint32(0)
bf.WriteUint32(uint32(len(data)))
Expand Down Expand Up @@ -127,7 +127,7 @@ func handleMsgSysTerminalLog(s *Session, p mhfpacket.MHFPacket) {
func handleMsgSysLogin(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgSysLogin)

if !s.server.erupeConfig.DevModeOptions.DisableTokenCheck {
if !s.server.erupeConfig.DebugOptions.DisableTokenCheck {
var token string
err := s.server.db.QueryRow("SELECT token FROM sign_sessions ss INNER JOIN public.users u on ss.user_id = u.id WHERE token=$1 AND ss.id=$2 AND u.id=(SELECT c.user_id FROM characters c WHERE c.id=$3)", pkt.LoginTokenString, pkt.LoginTokenNumber, pkt.CharID0).Scan(&token)
if err != nil {
Expand Down Expand Up @@ -1147,9 +1147,9 @@ func handleMsgMhfGetEarthStatus(s *Session, p mhfpacket.MHFPacket) {
bf := byteframe.NewByteFrame()
bf.WriteUint32(uint32(TimeWeekStart().Unix())) // Start
bf.WriteUint32(uint32(TimeWeekNext().Unix())) // End
bf.WriteInt32(s.server.erupeConfig.DevModeOptions.EarthStatusOverride)
bf.WriteInt32(s.server.erupeConfig.DevModeOptions.EarthIDOverride)
for i, m := range s.server.erupeConfig.DevModeOptions.EarthMonsterOverride {
bf.WriteInt32(s.server.erupeConfig.EarthStatus)
bf.WriteInt32(s.server.erupeConfig.EarthID)
for i, m := range s.server.erupeConfig.EarthMonsters {
if _config.ErupeConfig.RealClientMode <= _config.G9 {
if i == 3 {
break
Expand Down
2 changes: 1 addition & 1 deletion server/channelserver/handlers_cast_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
}
}

if s.server.erupeConfig.DevModeOptions.QuestDebugTools == true && s.server.erupeConfig.DevMode {
if s.server.erupeConfig.DebugOptions.QuestTools {
if pkt.BroadcastType == 0x03 && pkt.MessageType == 0x02 && len(pkt.RawDataPayload) > 32 {
// This is only correct most of the time
tmp.ReadBytes(20)
Expand Down
8 changes: 4 additions & 4 deletions server/channelserver/handlers_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func handleMsgMhfSavedata(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
return
}
if s.server.erupeConfig.DevModeOptions.SaveDumps.RawEnabled {
if s.server.erupeConfig.SaveDumps.RawEnabled {
dumpSaveData(s, saveData, "raw-savedata")
}
s.logger.Info("Updating save with blob")
Expand Down Expand Up @@ -112,11 +112,11 @@ func grpToGR(n int) uint16 {
}

func dumpSaveData(s *Session, data []byte, suffix string) {
if !s.server.erupeConfig.DevModeOptions.SaveDumps.Enabled {
if !s.server.erupeConfig.SaveDumps.Enabled {
return
} else {
dir := filepath.Join(s.server.erupeConfig.DevModeOptions.SaveDumps.OutputDir, fmt.Sprintf("%d", s.charID))
path := filepath.Join(s.server.erupeConfig.DevModeOptions.SaveDumps.OutputDir, fmt.Sprintf("%d", s.charID), fmt.Sprintf("%d_%s.bin", s.charID, suffix))
dir := filepath.Join(s.server.erupeConfig.SaveDumps.OutputDir, fmt.Sprintf("%d", s.charID))
path := filepath.Join(s.server.erupeConfig.SaveDumps.OutputDir, fmt.Sprintf("%d", s.charID), fmt.Sprintf("%d_%s.bin", s.charID, suffix))
_, err := os.Stat(dir)
if err != nil {
if os.IsNotExist(err) {
Expand Down
6 changes: 3 additions & 3 deletions server/channelserver/handlers_diva.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ func handleMsgMhfGetUdSchedule(s *Session, p mhfpacket.MHFPacket) {
}

var timestamps []uint32
if s.server.erupeConfig.DevMode && s.server.erupeConfig.DevModeOptions.DivaEvent >= 0 {
if s.server.erupeConfig.DevModeOptions.DivaEvent == 0 {
if s.server.erupeConfig.DebugOptions.DivaEvent >= 0 {
if s.server.erupeConfig.DebugOptions.DivaEvent == 0 {
if s.server.erupeConfig.RealClientMode >= _config.Z2 {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 36))
} else {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 32))
}
return
}
timestamps = generateDivaTimestamps(s, uint32(s.server.erupeConfig.DevModeOptions.DivaEvent), true)
timestamps = generateDivaTimestamps(s, uint32(s.server.erupeConfig.DebugOptions.DivaEvent), true)
} else {
timestamps = generateDivaTimestamps(s, start, false)
}
Expand Down
8 changes: 4 additions & 4 deletions server/channelserver/handlers_festa.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func handleMsgMhfLoadMezfesData(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfEnumerateRanking(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateRanking)
bf := byteframe.NewByteFrame()
state := s.server.erupeConfig.DevModeOptions.TournamentEvent
state := s.server.erupeConfig.DebugOptions.TournamentEvent
// Unk
// Unk
// Start?
Expand Down Expand Up @@ -173,12 +173,12 @@ func handleMsgMhfInfoFesta(s *Session, p mhfpacket.MHFPacket) {
}

var timestamps []uint32
if s.server.erupeConfig.DevMode && s.server.erupeConfig.DevModeOptions.FestaEvent >= 0 {
if s.server.erupeConfig.DevModeOptions.FestaEvent == 0 {
if s.server.erupeConfig.DebugOptions.FestaEvent >= 0 {
if s.server.erupeConfig.DebugOptions.FestaEvent == 0 {
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
return
}
timestamps = generateFestaTimestamps(s, uint32(s.server.erupeConfig.DevModeOptions.FestaEvent), true)
timestamps = generateFestaTimestamps(s, uint32(s.server.erupeConfig.DebugOptions.FestaEvent), true)
} else {
timestamps = generateFestaTimestamps(s, start, false)
}
Expand Down
2 changes: 1 addition & 1 deletion server/channelserver/handlers_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func handleMsgSysDeleteObject(s *Session, p mhfpacket.MHFPacket) {}

func handleMsgSysPositionObject(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgSysPositionObject)
if s.server.erupeConfig.DevMode && s.server.erupeConfig.DevModeOptions.LogInboundMessages {
if s.server.erupeConfig.DebugOptions.LogInboundMessages {
fmt.Printf("[%s] with objectID [%d] move to (%f,%f,%f)\n\n", s.Name, pkt.ObjID, pkt.X, pkt.Y, pkt.Z)
}
s.stage.Lock()
Expand Down
4 changes: 2 additions & 2 deletions server/channelserver/handlers_quest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgSysGetFile)

if pkt.IsScenario {
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
if s.server.erupeConfig.DebugOptions.QuestTools {
s.logger.Debug(
"Scenario",
zap.Uint8("CategoryID", pkt.ScenarioIdentifer.CategoryID),
Expand All @@ -40,7 +40,7 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
}
doAckBufSucceed(s, pkt.AckHandle, data)
} else {
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
if s.server.erupeConfig.DebugOptions.QuestTools {
s.logger.Debug(
"Quest",
zap.String("Filename", pkt.Filename),
Expand Down
6 changes: 3 additions & 3 deletions server/channelserver/handlers_tower.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func handleMsgMhfGetTowerInfo(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfPostTowerInfo(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfPostTowerInfo)

if s.server.erupeConfig.DevModeOptions.QuestDebugTools {
if s.server.erupeConfig.DebugOptions.QuestTools {
s.logger.Debug(
p.Opcode().String(),
zap.Uint32("InfoType", pkt.InfoType),
Expand Down Expand Up @@ -328,7 +328,7 @@ func handleMsgMhfGetTenrouirai(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfPostTenrouirai(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfPostTenrouirai)

if s.server.erupeConfig.DevModeOptions.QuestDebugTools {
if s.server.erupeConfig.DebugOptions.QuestTools {
s.logger.Debug(
p.Opcode().String(),
zap.Uint8("Unk0", pkt.Unk0),
Expand Down Expand Up @@ -442,7 +442,7 @@ func handleMsgMhfGetGemInfo(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfPostGemInfo(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfPostGemInfo)

if s.server.erupeConfig.DevModeOptions.QuestDebugTools {
if s.server.erupeConfig.DebugOptions.QuestTools {
s.logger.Debug(
p.Opcode().String(),
zap.Uint32("Op", pkt.Op),
Expand Down
Loading

0 comments on commit 0ea0dc2

Please sign in to comment.