lobbyapi

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 8 Imported by: 0

README

lobby

lobby is a http client of dst lobby server, help you more convenient to get information from lobby.

Note: The HTTP API maybe changed by klei official in the future

install

go get -u github.com/dstgo/lobbyapi

use

Here are some examples as follows

regions

get all the available regions

package main

import (
	"fmt"
	"github.com/dstgo/lobbyapi"
)

func main() {
	lobbyclient := lobbyapi.New("no need klei token")
	capableRegions, err := lobbyclient.GetCapableRegions()
	if err != nil {
		panic(err)
	}
	fmt.Println(capableRegions)
}

output

{[{us-east-1} {eu-central-1} {ap-southeast-1} {ap-east-1}]}
servers

get server list with region and platform, available platforms as follows:

  • Steam
  • PSN
  • Rail
  • XBone
  • Switch

here is an example

package main

import (
	"fmt"
	"github.com/dstgo/lobbyapi"
)

func main() {
	lobbyclient := lobbyapi.New("no need klei token")
	list, err := lobbyclient.GetLobbyServers("ap-east-1","Steam")
	if err != nil {
		panic(err)
	}
	fmt.Println(list)
}
details

get details for specific server

must be used with klei token

package main

import (
	"fmt"
	"github.com/dstgo/lobbyapi"
)

func main() {
	lobbyclient := lobbyapi.New("klei token")
	details, err := lobbyclient.GetServerDetails("ap-east-1","xxxxx")
	if err != nil {
		panic(err)
	}
	fmt.Println(details)
}

Documentation

Index

Constants

View Source
const (
	UsEast1     = "us-east-1"
	EuCentral   = "eu-central-1"
	ApSoutheast = "ap-southeast-1"
	ApEast      = "ap-east-1"
)

Region represents dst lobby server region, it may be updated by klei in the future

View Source
const (
	LobbyRegionURL  = `https://lobby-v2-cdn.klei.com/regioncapabilities-v2.json`
	LobbyServersURL = `https://lobby-v2-cdn.klei.com/{{.region}}-{{.platform}}.json.gz`
	LobbyDetailsURL = "https://lobby-v2-{{.region}}.klei.com/lobby/read"
)

Lobby server urls, may be updated by klei in the future

View Source
const GameId = "DontStarveTogether"

Variables

View Source
var ExplicitPlatforms = []string{Steam.String(), PSN.String(), Rail.String(), XBOne.String(), Switch.String()}

ExplicitPlatforms means that platforms could be used as query params in klei api.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is dst lobby http client, interact with lobby server and returns server information

func New

func New(token string) *Client

New returns a new instance of lobby client with klei token

func NewWith

func NewWith(token string, client *resty.Client) *Client

func (*Client) GetCapableRegions

func (c *Client) GetCapableRegions() (Regions, error)

GetCapableRegions returns a list of available regions that can be used in other api GET https://lobby-v2-cdn.klei.com/regioncapabilities-v2.json

func (*Client) GetLobbyServers

func (c *Client) GetLobbyServers(region string, platform string) (Servers, error)

GetLobbyServers returns a list of lobby servers with specified region and platform GET https://lobby-v2-cdn.klei.com/{region}-{platform}.json.gz

func (*Client) GetServerDetails

func (c *Client) GetServerDetails(region string, rowId string) (ServerDetails, error)

GetServerDetails returns the details information for the specified server by rowId POST https://lobby-v2-{region}.klei.com/lobby/read

type Mod

type Mod struct {
	Id       string
	Name     string
	Version1 string
	Version2 string
	Enabled  bool
}

type Platform

type Platform uint

Platform represents dst server platform, it may be updated by klei in the future

const (
	Steam Platform = 1
	PSN   Platform = 2
	// Rail is alias of WeGame, only serve at ap-east-1
	Rail  Platform = 4
	XBOne Platform = 16
	// PS4Official can not be use in api query params
	PS4Official Platform = 19
	Switch      Platform = 32
)

func (Platform) String

func (p Platform) String() string

type Player

type Player struct {
	Name    string
	Prefab  string
	SteamId string
	// hex color code
	Colour string
	// shard level
	Level int
}

type Regions

type Regions struct {
	Regions []struct {
		Region string `json:"Region"`
	} `json:"LobbyRegions"`
}

type Secondaries

type Secondaries struct {
	Id      string `json:"id"`
	SteamId string `json:"steamid"`
	Address string `json:"__addr"`
	Port    int    `json:"port"`
}

Secondaries represents the secondaries shard among dst servers

type Server

type Server struct {
	// network options
	Guid  string `json:"guid"`
	RowId string `json:"__rowId"`
	// only at steam platform
	SteamId string `json:"steamid"`
	// only for clan server
	SteamClanId string `json:"steamclanid"`
	// only for no password server
	OwnerNetId string   `json:"ownernetid"`
	SteamRoom  string   `json:"steamroom"`
	Session    string   `json:"session"`
	Address    string   `json:"__addr"`
	Port       int      `json:"port"`
	Host       string   `json:"host"`
	Platform   Platform `json:"platform"`

	ClanOnly bool `json:"clanonly"`
	LanOnly  bool `json:"lanonly"`

	// second shard
	Secondaries map[string]Secondaries

	// game options
	Name     string `json:"name"`
	GameMode string `json:"mode"`
	Intent   string `json:"intent"`
	Season   string `json:"season"`
	TagStr   string `json:"tags"`
	Version  int    `json:"v"`
	// max players allowed
	MaxConnections int `json:"maxconnections"`
	// online players number
	Connected int `json:"connected"`

	Mod             bool `json:"mods"`
	Pvp             bool `json:"pvp"`
	HasPassword     bool `json:"password"`
	IsDedicated     bool `json:"dedicated"`
	ClientHosted    bool `json:"clienthosted"`
	AllowNewPlayers bool `json:"allownewplayers"`
	ServerPaused    bool `json:"serverpaused"`
	FriendOnly      bool `json:"fo"`
}

Server includes all the information about single dst server

type ServerDetails

type ServerDetails struct {
	// repeat options
	Server

	Tick          int  `json:"tick"`
	ClientModsOff bool `json:"clientmodsoff"`
	Nat           int  `json:"nat"`

	// raw lua script data
	Data          string `json:"data"`
	WorldGen      string `json:"worldgen"`
	OnlinePlayers string `json:"players"`
	Mods          []any  `json:"mods_info"`

	// parsed lua data
	Details struct {
		Day                int
		DayElapsedInSeason int
		DaysLeftInSeason   int
		Players            []Player
		ModsInfo           []Mod
	}
}

ServerDetails includes some details information

type Servers

type Servers struct {
	List []Server `json:"GET"`
}

Jump to

Keyboard shortcuts

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