dstparser

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dstparser

dstparser is a package written in go that provides ability to parse dst information into go type, and reflect go type back into lua script.

install

go get github.com/dstgo/parser@latest

usage

supported usage as follows

  • modinfo.lua
  • modoverride.lua
  • leveldataoverride.lua
  • cluster.ini
  • player.txt
modinfo

parse modinfo.lua directly

import (
	"fmt"
	"github.com/dstgo/dstparser"
	"os"
)

func main() {
	bytes, err := os.ReadFile("workshop-123456789/modinfo.lua")
	if err != nil {
		panic(err)
	}
	info, err := dstparser.ParseModInfo(bytes)
	if err != nil {
		panic(err)
	}
	fmt.Println(info.Name)
}

or use mod env

package main
import (
    "fmt"
    "github.com/dstgo/dstparser"
    "os"
)

func main() {
    bytes, err := os.ReadFile("workshop-123456789/modinfo.lua")
    if err != nil {
        panic(err)
    }
    info, err := dstparser.ParseModInfoWithEnv(bytes, "workshop-123456789", "zh")
        if err != nil {
        panic(err)
    }
    fmt.Println(info.Name)
}

modoverrides

supported parse modoverrides.lua to go type and reflecting back to lua script

package main

import (
	"fmt"
	"github.com/dstgo/dstparser"
	"os"
)

func main() {
	// parse
	bytes, err := os.ReadFile("cluster/master/modoverrides.lua")
	if err != nil {
		panic(err)
	}
	modoverrides, err := dstparser.ParseModOverrides(bytes)
	if err != nil {
		panic(err)
	}
	for _, modoverride := range modoverrides {
		fmt.Println(modoverride.Id, modoverride.Enabled, len(modoverride.Items))
	}

	// serialize
	modOverrideLua, err := dstparser.ToModOverrideLua(modoverrides)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(modOverrideLua))
}
leveldataoverrides

supported parsing leveldataoverrides.lua to go type and reflecting back to lua script

package main

import (
	"fmt"
	"github.com/dstgo/dstparser"
	"os"
)

func main() {
	// parse
	bytes, err := os.ReadFile("cluster/master/leveldataoverrides.lua")
	if err != nil {
		panic(err)
	}
	overrides, err := dstparser.ParseLevelDataOverrides(bytes)
	if err != nil {
		panic(err)
	}
	masterLevelDataOverridesLua, err := dstparser.ToMasterLevelDataOverridesLua(overrides)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(masterLevelDataOverridesLua))
}
cluster ini

supported parsing cluster.ini

package main

import (
	"fmt"
	"github.com/dstgo/dstparser"
	"os"
)

func main() {
	// parse
	bytes, err := os.ReadFile("cluster/cluster/cluster.ini")
	if err != nil {
		panic(err)
	}
	clusterConfig, err := dstparser.ParseClusterInI(bytes)
	if err != nil{
		panic(err)
	}
	clusterInI, err := dstparser.ToClusterInI(clusterConfig)
	if err != nil{
		panic(err)
	}
	fmt.Println(string(clusterInI))
}

or server.ini

package main

import (
	"fmt"
	"github.com/dstgo/dstparser"
	"os"
)

func main() {
	// parse
	bytes, err := os.ReadFile("cluster/cluster/server.ini")
	if err != nil {
		panic(err)
	}
	serverConfig, err := dstparser.ParseServerInI(bytes)
	if err != nil{
		panic(err)
	}
	serverIni, err := dstparser.ToServerInI(serverConfig)
	if err != nil{
		panic(err)
	}
	fmt.Println(string(serverIni))
}
player

supported parsing player.txt and server_chat_log.txt

package main

import (
	"fmt"
	"github.com/dstgo/dstparser"
	"os"
)

func main() {
	bytes, err := os.ReadFile("server_chat_log.txt")
	if err != nil {
		panic(err)
	}
	logs, err := dstparser.ParseServerChatLogs(bytes)
	if err != nil {
		panic(err)
	}
	fmt.Println(logs)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChooseTranslationTable

func ChooseTranslationTable(l *lua.LState, locale string) *lua.LFunction

ChooseTranslationTable returns *lua.LFunction, this function used to choose the translation table in lua state.

func ParsePlayerTxt

func ParsePlayerTxt(content string) []string

ParsePlayerTxt parse player.txt file, returns slice of klei ID

func ToCaveLevelDataOverridesLua

func ToCaveLevelDataOverridesLua(overrides LevelDataOverrides) ([]byte, error)

ToCaveLevelDataOverridesLua converts LevelDataOverrides to lua script

func ToClusterInI

func ToClusterInI(config ClusterConfig) ([]byte, error)

ToClusterInI converts ClusterConfig to cluster.ini

func ToMasterLevelDataOverridesLua

func ToMasterLevelDataOverridesLua(overrides LevelDataOverrides) ([]byte, error)

ToMasterLevelDataOverridesLua converts LevelDataOverrides to lua script

func ToModOverrideLua

func ToModOverrideLua(options []ModOverRideOption) ([]byte, error)

ToModOverrideLua return the lua representation of the modOverride options, the format is same as modoverride.lua

func ToPlayerTxt

func ToPlayerTxt(kleiIDs []string) ([]byte, error)

ToPlayerTxt converts kleiIDs to player.txt

func ToServerInI

func ToServerInI(config ServerConfig) ([]byte, error)

ToServerInI converts ServerConfig to server.ini

Types

type ChatLog

type ChatLog struct {
	Time   string `mapstructure:"time"`
	Type   string `mapstructure:"type"`
	KleiId string `mapstructure:"klei_id"`
	Name   string `mapstructure:"player_name"`
	Msg    string `mapstructure:"msg"`
}

ChatLog represents a chat record in server_chat_log.txt

func ParseServerChatLogs

func ParseServerChatLogs(content []byte) ([]ChatLog, error)

type ClusterConfig

type ClusterConfig struct {
	GamePlay GamePlay       `ini:"GAMEPLAY"`
	NetWork  ClusterNetwork `ini:"NETWORK"`
	Misc     Misc           `ini:"MISC"`
	Shard    ClusterShard   `ini:"SHARD"`
	Steam    ClusterSteam   `ini:"STEAM"`
}

ClusterConfig represents cluster.ini

func ParseClusterInI

func ParseClusterInI(data []byte) (ClusterConfig, error)

ParseClusterInI parses the cluster.ini to ClusterConfig struct type

type ClusterNetwork

type ClusterNetwork struct {
	// basic information
	WhiteListSlots     int    `ini:"whitelist_slots"`
	ClusterPassword    string `ini:"cluster_password"`
	ClusterName        string `ini:"cluster_name"`
	ClusterDescription string `ini:"cluster_description"`
	ClusterLanguage    string `ini:"cluster_language"`
	ClusterCloudId     string `ini:"cluster_cloud_id,omitempty"`

	// network
	Offline   bool `ini:"offline_cluster"`
	TrickRate int  `ini:"tick_rate,omitempty"`
	LanOnly   bool `ini:"lan_only_cluster"`
}

type ClusterShard

type ClusterShard struct {
	ShardEnable bool   `ini:"shard_enabled"`
	BindIP      string `ini:"bind_ip"`
	ClusterKey  string `ini:"cluster_key"`
	MasterIp    string `ini:"master_ip"`
	MasterPort  int    `ini:"master_port"`
}

type ClusterSteam

type ClusterSteam struct {
	GroupOnly  bool   `ini:"steam_group_only"`
	GroupId    string `ini:"steam_group_id"`
	GroupAdmin bool   `ini:"steam_group_admins"`
}

type GamePlay

type GamePlay struct {
	MaxPlayers     int    `ini:"max_players"`
	Pvp            bool   `ini:"pvp"`
	GameMode       string `ini:"game_mode"`
	PauseWhenEmpty bool   `ini:"pause_when_empty"`
	VoteEnable     bool   `ini:"vote_enabled"`
	VoteKickEnable bool   `ini:"vote_kick_enabled"`
}

type LevelDataOverrides

type LevelDataOverrides struct {
	Id                    string  `mapstructure:"id"`
	Name                  string  `mapstructure:"name"`
	Version               float64 `mapstructure:"version"`
	Desc                  string  `mapstructure:"desc"`
	Location              string  `mapstructure:"location"`
	PlayStyle             string  `mapstructure:"playstyle"`
	HideMiniMap           bool    `mapstructure:"hideminimap"`
	MaxPlayerListPosition float64 `mapstructure:"max_playerlist_position"`
	MinPlayerListPosition float64 `mapstructure:"min_playerlist_position"`
	NumRandomSetPieces    int     `mapstructure:"numrandom_set_pieces"`
	OverrideLevelString   bool    `mapstructure:"override_level_string"`

	// setting
	SettingId   string `mapstructure:"settings_id"`
	SettingName string `mapstructure:"settings_name"`
	SettingDesc string `mapstructure:"settings_desc"`

	// worldgen
	WorldGenId   string `mapstructure:"worldgen_id"`
	WorldGenName string `mapstructure:"worldgen_name"`
	WorldGenDesc string `mapstructure:"worldgen_desc"`

	// meta info
	Overrides           []LevelOverrideItem `mapstructure:"overrides"`
	RandomSetPieces     []string            `mapstructure:"random_set_pieces"`
	RequiredPrefabs     []string            `mapstructure:"required_prefabs"`
	RequiredSetPieces   []string            `mapstructure:"required_setpieces"`
	Substitutes         []string            `mapstructure:"substitutes"`
	BackGroundNodeRange []float64           `mapstructure:"background_node_range"`
}

LevelDataOverrides represents level data overrides information

func ParseLevelDataOverrides

func ParseLevelDataOverrides(luaScript []byte) (LevelDataOverrides, error)

ParseLevelDataOverrides parses the leveldataoverrides.lua, returns LevelDataOverrides information

type LevelOverrideItem

type LevelOverrideItem struct {
	Name  string `mapstructure:"name"`
	Value any    `mapstructure:"value"`
}

type Misc

type Misc struct {
	MaxSnapShots  int  `ini:"max_snapshots"`
	ConsoleEnable bool `ini:"console_enabled"`
}

type ModInfo

type ModInfo struct {
	// basic information
	Id          string `mapstructure:"id"`
	Name        string `mapstructure:"name"`
	Description string `mapstructure:"description"`
	Author      string `mapstructure:"author"`
	Version     string `mapstructure:"version"`
	ForumThread string `mapstructure:"forum_thread"`

	// dont starve
	ApiVersion              int  `mapstructure:"api_version"`
	DontStarveCompatible    bool `mapstructure:"dont_starve_compatible"`
	ReignOfGiantsCompatible bool `mapstructure:"reign_of_giants_compatible"`
	ShipWreckedCompatible   bool `mapstructure:"shipwrecked_compatible"`
	HamletCompatible        bool `mapstructure:"hamlet_compatible"`

	// dont starve together
	ApiVersionDst     int  `mapstructure:"api_version_dst"`
	DstCompatible     bool `mapstructure:"dst_compatible"`
	AllClientRequired bool `mapstructure:"all_client_required"`
	ClientOnly        bool `mapstructure:"client_only_mod"`
	ServerOnly        bool `mapstructure:"server_only_mod"`
	ForgeCompatible   bool `mapstructure:"forge_compatible"`

	// meta info
	FilterTags []string `mapstructure:"server_filter_tags"`
	Priority   float64  `mapstructure:"priority"`
	Icon       string   `mapstructure:"icon"`
	IconAtlas  string   `mapstructure:"icon_atlas"`

	// configuration
	ConfigurationOptions []ModOption `mapstructure:"configuration_options"`
}

func ParseModInfo

func ParseModInfo(luaScript []byte) (ModInfo, error)

ParseModInfo returns the parsed modinfo from lua script

func ParseModInfoWithEnv

func ParseModInfoWithEnv(luaScript []byte, folderName, locale string) (ModInfo, error)

ParseModInfoWithEnv parse mod info from lua script with mod environment variables.

type ModOption

type ModOption struct {
	// option name, maybe empty
	Name string `mapstructure:"name"`
	// option label, maybe empty
	Label string `mapstructure:"label"`
	// hover tooltip, maybe empty
	Hover string `mapstructure:"hover"`
	// default value of this option
	Default any      `mapstructure:"default"`
	Client  bool     `mapstructure:"client"`
	Tags    []string `mapstructure:"tags"`
	// options available
	Options []ModOptionItem `mapstructure:"options"`
}

ModOption represents a mod option in 'configuration_options'

type ModOptionItem

type ModOptionItem struct {
	Description string `mapstructure:"description"`
	Data        any    `mapstructure:"data"`
}

type ModOverRideOption

type ModOverRideOption struct {
	Id      string                  `mapstructure:"id"`
	Enabled bool                    `mapstructure:"enabled"`
	Items   []ModOverRideOptionItem `mapstructure:"options"`
}

func ParseModOverrides

func ParseModOverrides(luaScript []byte) ([]ModOverRideOption, error)

ParseModOverrides returns the mod override options from modoverrides.lua

type ModOverRideOptionItem

type ModOverRideOptionItem struct {
	Name  string `mapstructure:"name"`
	Value any    `mapstructure:"value"`
}

type ServerAccount

type ServerAccount struct {
	EncodeUserPath bool `ini:"encode_user_path"`
}

type ServerConfig

type ServerConfig struct {
	Network ServerNetwork `ini:"NETWORK"`
	Shard   ServerShard   `ini:"SHARD"`
	Steam   ServerSteam   `ini:"STEAM"`
	Account ServerAccount `ini:"ACCOUNT"`
}

ServerConfig represents server.ini

func ParseServerInI

func ParseServerInI(data []byte) (ServerConfig, error)

ParseServerInI parses the server.ini to ServerConfig struct type

type ServerNetwork

type ServerNetwork struct {
	ServerPort int `ini:"server_port"`
}

type ServerShard

type ServerShard struct {
	ID       string `ini:"id,omitempty"`
	Name     string `ini:"name,omitempty"`
	IsMaster bool   `ini:"is_master"`
}

type ServerSteam

type ServerSteam struct {
	MasterServerPort   int `ini:"master_server_port"`
	AuthenticationPort int `ini:"authentication_port"`
}

type Table

type Table lua.LTable

func LTable

func LTable(t *lua.LTable) *Table

func (*Table) Get

func (t *Table) Get(key string) lua.LValue

func (*Table) GetBool

func (t *Table) GetBool(key string) bool

func (*Table) GetFloat64

func (t *Table) GetFloat64(key string) float64

func (*Table) GetInt64

func (t *Table) GetInt64(key string) int64

func (*Table) GetString

func (t *Table) GetString(key string) string

func (*Table) GetTable

func (t *Table) GetTable(key string) *Table

func (*Table) T

func (t *Table) T() *lua.LTable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址