Files
Erupe/config/config.go
SirFist c54811729f more saves, guildcard, road, shops
PARTNER save/load handling
OTOMO_AIROU save/load handling
Basic groundwork for HUNTER_NAVI save/load handling
Basic groundwork for PLATE_BOX save/load handling
Basic groundwork for PLATE_DATA save/load handling
Basic groundwork for PLATE_MYSET save/load handling
Basic groundwork for DECO_MYSET save/load handling
Basic groundwork for RENGOKU_DATA save/load handling
Handling for MSG_MHF_GET_RENGOKU_BINARY, enables road. Place rengoku_data.bin from either /dat/ in install or from a packet capture in the /bin/ folder for this
Handling for MSG_MHF_UPDATE_CAFEPOINT allowing access to guildcard
Handling for MSG_MHF_GET_PAPER_DATA which fixes the issue of all save functionality immediately breaking after loading into town proper
Handling for MSG_MHF_ENUMERATE_SHOP enabling access to all shops
Handling for MSG_MHF_GET_TENROUAIRAI enabling access to duremudira and janky tower
Handling for MSG_MHF_GET_GACHA_POINT, should be added to database as it's functionally a persistent save that's reduced when MSG_MHF_USE_GACHA_POINT is triggered
Handling for MSG_MHF_GET_TREND_WEAPON, stops smith breaking when you're high enough rank for it to pull recommendations
Devmode config option for using a fixed stage ID to allow entry into blacksmith and other areas
Delivered quest file will automatically be replaced if you have a quest_override.bin in the bin folder, keep in mind this will break badly depending on quest counter data for the quest to be replaced
2020-02-26 14:32:12 +00:00

131 lines
3.0 KiB
Go

package config
import (
"log"
"net"
"github.com/spf13/viper"
)
// Config holds the global server-wide config.
type Config struct {
HostIP string `mapstructure:"host_ip"`
BinPath string `mapstructure:"bin_path"`
DevMode bool
DevModeOptions DevModeOptions
Database Database
Launcher Launcher
Sign Sign
Channel Channel
Entrance Entrance
}
// DevModeOptions holds various debug/temporary options for use while developing Erupe.
type DevModeOptions struct {
CleanDB bool // Automatically wipes the DB on server reset.
MaxLauncherHR bool // Sets the HR returned in the launcher to HR9 so that you can join non-beginner worlds.
FixedStageID bool // Causes all move_stage to use the ID sl1Ns200p0a0u0 to get you into all stages
}
// Database holds the postgres database config.
type Database struct {
Host string
Port int
User string
Password string
Database string
}
// Launcher holds the launcher server config.
type Launcher struct {
Port int
UseOriginalLauncherFiles bool
}
// Sign holds the sign server config.
type Sign struct {
Port int
}
// Channel holds the channel server config.
type Channel struct {
Port int
}
// Entrance holds the entrance server config.
type Entrance struct {
Port uint16
Entries []EntranceServerInfo
}
// EntranceServerInfo represents an entry in the serverlist.
type EntranceServerInfo struct {
IP string
Unk2 uint16
Type uint8 // Server type. 0=?, 1=open, 2=cities, 3=newbie, 4=bar
Season uint8 // Server activity. 0 = green, 1 = orange, 2 = blue
Unk6 uint8 // Something to do with server recommendation on 0, 3, and 5.
Name string // Server name, 66 byte null terminated Shift-JIS(JP) or Big5(TW).
// 4096(PC, PS3/PS4)?, 8258(PC, PS3/PS4)?, 8192 == nothing?
// THIS ONLY EXISTS IF Binary8Header.type == "SV2", NOT "SVR"!
AllowedClientFlags uint32
Channels []EntranceChannelInfo
}
// EntranceChannelInfo represents an entry in a server's channel list.
type EntranceChannelInfo struct {
Port uint16
MaxPlayers uint16
CurrentPlayers uint16
Unk4 uint16
Unk5 uint16
Unk6 uint16
Unk7 uint16
Unk8 uint16
Unk9 uint16
Unk10 uint16
Unk11 uint16
Unk12 uint16
Unk13 uint16
}
// getOutboundIP4 gets the preferred outbound ip4 of this machine
// From https://stackoverflow.com/a/37382208
func getOutboundIP4() net.IP {
conn, err := net.Dial("udp4", "8.8.8.8:80")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP.To4()
}
// LoadConfig loads the given config toml file.
func LoadConfig() (*Config, error) {
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
return nil, err
}
c := &Config{}
err = viper.Unmarshal(c)
if err != nil {
return nil, err
}
if c.HostIP == "" {
c.HostIP = getOutboundIP4().To4().String()
}
return c, nil
}