palworldapi

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Palworld API Wrapper

GitHub License Codacy Badge Go Report Card

Easy to use wrapper for the Palworld REST API

Set up a Palworld Server

Read the API Docs

Installation

You can install the package by using go get in your Go Project.

go get -u github.com/Ju0x/palworldapi

This will pull the latest release.

Usage

First you need to initialize a new PalworldAPI instance with credentials.

pal := palworldapi.New("http://localhost:8212", "admin", "admin password")

Typically the username is admin.

The AdminPassword is set in the Server Configuration. (How to configure the Palworld Server)

The REST API must be activated on the server with the RESTAPIEnabled=True option.

First Hello World

With the palworldapi instance you are now able to use the wrapper functions.

package main

import "github.com/Ju0x/palworldapi"

func main() {
    pal := palworldapi.New("http://localhost:8212", os.Getenv("USERNAME"), os.Getenv("ADMIN_PASSWORD"))

    // Sends the message to the server globally
    pal.Announce("Hello World!")
}

Then run it

USERNAME=admin ADMIN_PASSWORD=your_admin_password go run .

The result should look like this:

Examples

You can find some examples here

Documentation

Index

Constants

View Source
const (
	Endpoint = "/v1/api"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Announce

type Announce struct {
	Message string `json:"message"`
}

type BanPlayer

type BanPlayer struct {
	UserID  string `json:"userid"`
	Message string `json:"message"`
}

type KickPlayer

type KickPlayer struct {
	UserID  string `json:"userid"`
	Message string `json:"message"`
}

type PalworldAPI

type PalworldAPI struct {
	Host          string // Defaults to localhost:8212
	Username      string // Defaults to "admin"
	AdminPassword string
	// contains filtered or unexported fields
}

func New

func New(host, username, password string) *PalworldAPI

func (*PalworldAPI) Announce

func (p *PalworldAPI) Announce(message string) (err error)

Announces a message to the server Palworld docs: https://tech.palworldgame.com/api/rest-api/announce

func (*PalworldAPI) Ban

func (p *PalworldAPI) Ban(user_id string, message string) (err error)

Bans a player from the server Palworld docs: https://tech.palworldgame.com/api/rest-api/ban

func (*PalworldAPI) BanList added in v0.0.3

func (p *PalworldAPI) BanList() (bannedPlayers []string, err error)

Gets a list of banned players by requesting the banlist provided in the server settings Not documented, this is just a helper function WARNING: This could request external sources, for example the default banlist located at https://api.palworldgame.com/api/banlist.txt, be sure to query these not too fast

func (*PalworldAPI) ForceStop

func (p *PalworldAPI) ForceStop() (err error)

Force stops the server Palworld docs: https://tech.palworldgame.com/api/rest-api/stop

func (*PalworldAPI) Info

func (p *PalworldAPI) Info() (info *ServerInfo, err error)

Gets the server info Palworld docs: https://tech.palworldgame.com/api/rest-api/info

func (*PalworldAPI) Kick

func (p *PalworldAPI) Kick(user_id string, message string) (err error)

Kicks a player from the server Palworld docs: https://tech.palworldgame.com/api/rest-api/kick

func (*PalworldAPI) Metrics

func (p *PalworldAPI) Metrics() (metrics *ServerMetrics, err error)

Gets the server metrics Palworld docs: https://tech.palworldgame.com/api/rest-api/metrics

func (*PalworldAPI) Players

func (p *PalworldAPI) Players() (players []*Player, err error)

Gets the player list Palworld docs: https://tech.palworldgame.com/api/rest-api/players

func (*PalworldAPI) SaveWorld

func (p *PalworldAPI) SaveWorld() (err error)

Saves the world Palworld docs: https://tech.palworldgame.com/api/rest-api/save

func (*PalworldAPI) Settings

func (p *PalworldAPI) Settings() (settings *ServerSettings, err error)

Gets the server settings Palworld docs: https://tech.palworldgame.com/api/rest-api/settings

func (*PalworldAPI) Shutdown

func (p *PalworldAPI) Shutdown(waittime time.Duration, message string) (err error)

Shuts the server down Palworld docs: https://tech.palworldgame.com/api/rest-api/shutdown

func (*PalworldAPI) Unban

func (p *PalworldAPI) Unban(user_id string) (err error)

Unbans a player from the server Palworld docs: https://tech.palworldgame.com/api/rest-api/unban

type Player

type Player struct {
	Name        string  `json:"name"`
	AccountName string  `json:"accountName"`
	PlayerID    string  `json:"playerId"`
	UserID      string  `json:"userId"`
	IP          string  `json:"ip"`
	Ping        float64 `json:"ping"`
	LocationX   float64 `json:"location_x"`
	LocationY   float64 `json:"location_y"`
	Level       int     `json:"level"`
}

type PlayerList

type PlayerList struct {
	Players []*Player `json:"players"`
}

type ServerInfo

type ServerInfo struct {
	Version     string `json:"version"`
	ServerName  string `json:"servername"`
	Description string `json:"description"`
}

type ServerMetrics

type ServerMetrics struct {
	FPS              int `json:"serverfps"`
	CurrentPlayerNum int `json:"currentplayernum"`
	MaxPlayerNum     int `json:"maxplayernum"`
	Uptime           int `json:"uptime"`
}

type ServerSettings

type ServerSettings struct {
	Difficulty                          string `json:"Difficulty"`
	DayTimeSpeedRate                    int    `json:"DayTimeSpeedRate"`
	NightTimeSpeedRate                  int    `json:"NightTimeSpeedRate"`
	ExpRate                             int    `json:"ExpRate"`
	PalCaptureRate                      int    `json:"PalCaptureRate"`
	PalSpawnNumRate                     int    `json:"PalSpawnNumRate"`
	PalDamageRateAttack                 int    `json:"PalDamageRateAttack"`
	PalDamageRateDefense                int    `json:"PalDamageRateDefense"`
	PlayerDamageRateAttack              int    `json:"PlayerDamageRateAttack"`
	PlayerDamageRateDefense             int    `json:"PlayerDamageRateDefense"`
	PlayerStomachDecreaceRate           int    `json:"PlayerStomachDecreaceRate"`
	PlayerStaminaDecreaceRate           int    `json:"PlayerStaminaDecreaceRate"`
	PlayerAutoHPRegeneRate              int    `json:"PlayerAutoHPRegeneRate"`
	PlayerAutoHpRegeneRateInSleep       int    `json:"PlayerAutoHpRegeneRateInSleep"`
	PalStomachDecreaceRate              int    `json:"PalStomachDecreaceRate"`
	PalStaminaDecreaceRate              int    `json:"PalStaminaDecreaceRate"`
	PalAutoHPRegeneRate                 int    `json:"PalAutoHPRegeneRate"`
	PalAutoHpRegeneRateInSleep          int    `json:"PalAutoHpRegeneRateInSleep"`
	BuildObjectDamageRate               int    `json:"BuildObjectDamageRate"`
	BuildObjectDeteriorationDamageRate  int    `json:"BuildObjectDeteriorationDamageRate"`
	CollectionDropRate                  int    `json:"CollectionDropRate"`
	CollectionObjectHpRate              int    `json:"CollectionObjectHpRate"`
	CollectionObjectRespawnSpeedRate    int    `json:"CollectionObjectRespawnSpeedRate"`
	EnemyDropItemRate                   int    `json:"EnemyDropItemRate"`
	DeathPenalty                        string `json:"DeathPenalty"`
	EnablePlayerToPlayerDamage          bool   `json:"bEnablePlayerToPlayerDamage"`
	EnableFriendlyFire                  bool   `json:"bEnableFriendlyFire"`
	EnableInvaderEnemy                  bool   `json:"bEnableInvaderEnemy"`
	ActiveUNKO                          bool   `json:"bActiveUNKO"`
	EnableAimAssistPad                  bool   `json:"bEnableAimAssistPad"`
	EnableAimAssistKeyboard             bool   `json:"bEnableAimAssistKeyboard"`
	DropItemMaxNum                      int    `json:"DropItemMaxNum"`
	DropItemMaxNum_UNKO                 int    `json:"DropItemMaxNum_UNKO"`
	BaseCampMaxNum                      int    `json:"BaseCampMaxNum"`
	BaseCampWorkerMaxNum                int    `json:"BaseCampWorkerMaxNum"`
	DropItemAliveMaxHours               int    `json:"DropItemAliveMaxHours"`
	AutoResetGuildNoOnlinePlayers       bool   `json:"bAutoResetGuildNoOnlinePlayers"`
	AutoResetGuildTimeNoOnlinePlayers   int    `json:"AutoResetGuildTimeNoOnlinePlayers"`
	GuildPlayerMaxNum                   int    `json:"GuildPlayerMaxNum"`
	PalEggDefaultHatchingTime           int    `json:"PalEggDefaultHatchingTime"`
	WorkSpeedRate                       int    `json:"WorkSpeedRate"`
	IsMultiplay                         bool   `json:"bIsMultiplay"`
	IsPvP                               bool   `json:"bIsPvP"`
	CanPickupOtherGuildDeathPenaltyDrop bool   `json:"bCanPickupOtherGuildDeathPenaltyDrop"`
	EnableNonLoginPenalty               bool   `json:"bEnableNonLoginPenalty"`
	EnableFastTravel                    bool   `json:"bEnableFastTravel"`
	IsStartLocationSelectByMap          bool   `json:"bIsStartLocationSelectByMap"`
	ExistPlayerAfterLogout              bool   `json:"bExistPlayerAfterLogout"`
	EnableDefenseOtherGuildPlayer       bool   `json:"bEnableDefenseOtherGuildPlayer"`
	CoopPlayerMaxNum                    int    `json:"CoopPlayerMaxNum"`
	ServerPlayerMaxNum                  int    `json:"ServerPlayerMaxNum"`
	ServerName                          string `json:"ServerName"`
	ServerDescription                   string `json:"ServerDescription"`
	PublicPort                          int    `json:"PublicPort"`
	PublicIP                            string `json:"PublicIP"`
	RCONEnabled                         bool   `json:"RCONEnabled"`
	RCONPort                            int    `json:"RCONPort"`
	Region                              string `json:"Region"`
	UseAuth                             bool   `json:"bUseAuth"`
	BanListURL                          string `json:"BanListURL"`
	RESTAPIEnabled                      bool   `json:"RESTAPIEnabled"`
	RESTAPIPort                         int    `json:"RESTAPIPort"`
	BShowPlayerList                     bool   `json:"bShowPlayerList"`
	AllowConnectPlatform                string `json:"AllowConnectPlatform"`
	IsUseBackupSaveData                 bool   `json:"bIsUseBackupSaveData"`
	LogFormatType                       string `json:"LogFormatType"`
}

type ServerShutdown

type ServerShutdown struct {
	WaitTime int    `json:"waittime"` // Use custom datatype which converts time.Duration to the WaitTime
	Message  string `json:"string"`
}

type UnbanPlayer

type UnbanPlayer struct {
	UserID string `json:"userid"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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