Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Config Overhaul #112

Open
InusualZ opened this issue Jul 6, 2023 · 1 comment
Open

[RFC] Config Overhaul #112

InusualZ opened this issue Jul 6, 2023 · 1 comment

Comments

@InusualZ
Copy link
Collaborator

InusualZ commented Jul 6, 2023

Seeming that we have reach a limit to the bare bone config system that the server have today (#111). I think it's a good time to introduce TOML to the software.

TOML

A config file format for humans.

TOML aims to be a minimal configuration file format that's easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages.

Why TOML

  • Human readable
  • Useful natives type
    • Key/Value Pairs
    • Arrays
    • Tables
    • Inline tables
    • Arrays of tables
    • Integers & Floats
    • Booleans
    • Dates & Times, with optional offsets
  • Comments
  • Multi Line String
  • Numerical Notations
    • Integers (1,2)
    • Hex (0x)
    • Octal (0o)
    • Binary (0b)
    • Floats (1.1)
    • Exponent
    • Scientific Notation
    • Separators (2_100)
    • Infinity
    • NaN
  • Date and Time

Example

[OpnServer]
CertificatePath = "server.cer"
CertificatePassphrase = "server.key"
Address = "127.0.0.1"
Port = 8200

[LmpServer]
Address = "127.0.0.1"
Port = 8210

[FmpServer]
Address = "127.0.0.1"
Port = 8220

[Database]
Host = "127.0.0.1"
Port = 9000
Username = ""
Password = ""

[Game]
MaxHunterSlots = 4
Timeout1 = 32767
Timeout2 = 32767
Timeout3 = 32767
Timeout4 = 32767
Timeout5 = 32767
Timeout6 = 32767
Timeout7 = 32767
Timeout8 = 32767

	[[Game.ServerType]]
	Name = "Open" # Max Length 23 
	Description = "Hunters of all Ranks\ncan gather here.NEW" # Max Length 167
	MinimumRank = 0
	MaximumRank = 65535

		[[Game.ServerType.Server]]
		Name = "Valor1"

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 1" # Max Length 63 

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1" # Max Length 63
				MaxPopulation = 4

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 2" # Max Length 63
				MaxPopulation = 4

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 3" # Max Length 63
				MaxPopulation = 4

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 2"
			
				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 3"
			
				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 4"

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

		
		[[Game.ServerType.Server]]
		Name = "Valor2"

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 1" # Max Length 63 

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1" # Max Length 63
				MaxPopulation = 4

	[[Game.ServerType]]
	Name = "Rookie" # Max Length 23 
	Description = "Only hunters HR 30\nor lower may enter.NEW" # Max Length 167
	MinimumRank = 0
	MaximumRank = 30

		[[Game.ServerType.Server]]
		Name = "Rookies1"

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 1"

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 2"
			
				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 3"
			
				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 4"

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

		[[Game.ServerType.Server]]
		Name = "Rookies2"

			[[Game.ServerType.Server.Gate]]
			Name = "City Gate 1"

				[[Game.ServerType.Server.Gate.City]]
				Name = "City 1"
				MaxPopulation = 4

	# Up to 4 Server Type

	[[Game.HRLimit]]
	Name = "None"
	Enabled = true
	Minimum = 0
	Maximum = 65535

	[[Game.HRLimit]]
	Name = "Low"
	Enabled = true
	Minimum = 0
	Maximum = 30

	# Up to 8 HRLimit

	[[Game.Seeking]]
	Name = "Everyone welcome!"
	Enabled = true
	Flag = 0xff

	[[Game.Seeking]]
	Name = "Casual play"
	Enabled = true
	Flag = 0xff

	# Up to 31 Seeking Types

	[[Game.Goal]]
	Name = "None" 
	Enabled = true
	RestrictionMode = 0 # None - 0, HR Limit - 1, Unknown - 2
	Minimum = 0
	Maximum = 0

	[[Game.Goal]]
	Name = "HR1~" 
	Enabled = true
	RestrictionMode = 1
	Minimum = 1
	Maximum = 8

	[[Game.Goal]]
	Name = "HR9~" 
	Enabled = true
	RestrictionMode = 1
	Minimum = 9
	Maximum = 17

	# Up to 63 Goals

	[[Game.Event]]
	File = "/path/to/quest/event.bin"

	[[Game.Event]]
	File = "/path/to/quest/event2.bin"

	# Up to 10 Event

From my example you can see that even the most complex relationship can be expressed with this config format. I'm a little bit bias since I have always loved this config format (But not without reason)

@sepalani
Copy link
Owner

I have nothing against TOML, I have been thinking of YAML and JSON too but without a strong preference. Ideally, if we can integrate this dependency in externals without doing anything fancy (to support Python2/3), that would be great.

Regardless of the chosen format, we can take advantage of python format string and named arguments to write:

[[Game.ServerType.Server]]
Name = "Valor {server_index}"
Name_FR = "Valeur {server_index}"

    [[Game.ServerType.Server.Gate]]
    Name = "City Gate {gate_index}"
    Name_FR = "Porte {gate_index}"

        [[Game.ServerType.Server.Gate.City]]
        Name = "City {city_index}"
        Name_FR = "Ville {city_index}"

We can also try to implement i18n by appending a language suffix (_FR in the above example), if the language isn't available we can fallback to the regular value.

I also would like to have some kind of inheritance and/or default values. So we have a way to define, for instance, 40 cities without writing 40 entries but still allow to define specialization. Something like this or similar:

        [[Game.ServerType.Server.Gate.City]]
        Name = "City {city_index}"
        Name_FR = "Ville {city_index}"
        Count = 40

        [Game.ServerType.Server.Gate.City40]
        Name = "Last city"
        Name_FR = "Dernière ville"

Having a way to "split" the config file into several parts could be interesting to organize things such as event/arena quests, network/ssl/db config, server name/ip/settings, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants