server

package
v0.0.0-...-bf051c1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecRconCommand

func ExecRconCommand(name string, command string) (string, error)

执行单个RCON命令 - 优化版本

func ExecRconCommands

func ExecRconCommands(name string, commands []string) ([]string, error)

批量执行RCON命令 - 优化版本

func ExecRconCommandsConcurrent

func ExecRconCommandsConcurrent(serverCommands map[string][]string) (map[string][]string, error)

并发执行多个服务器的命令

func FullName

func FullName(name string) string

FullName 生成完整的名称 prefix-name

func GetEnvValue

func GetEnvValue(name string, key string) (string, error)

func ServerSetRouter

func ServerSetRouter(router *gin.Engine)

ServerSetRouter 设置 API 接口路由

func WebServerSetRouter

func WebServerSetRouter(router *gin.Engine)

WebServerSetRouter 设置 Web 静态资源路由

Types

type App

type App struct {
	Config *config.Config
}

App 结构体 包含应用配置

func ServerNewApp

func ServerNewApp() (*App, error)

ServerNewApp 创建并初始化一个新的 Web 应用

func (*App) ServerStart

func (app *App) ServerStart()

ServerStart 启动 API 和 Web 服务(根据配置判断是否分端口)

type ClientInfo

type ClientInfo struct {
	SteamID64 string `json:"steamid64"`
	SteamID   string `json:"steamid"`
	Bot       bool   `json:"bot"`
	Name      string `json:"name"`
}

type MapInfo

type MapInfo struct {
	Name          string   `json:"name"`           // 地图显示名
	InternalName  string   `json:"internal_name"`  // 对应 VMAP/VPK 文件名
	PlayableModes []string `json:"playable_modes"` // 在 CS2 各模式下可玩的模式列表
}

MapInfo 只保留 name、internal_name 和 playable_modes

type PlayerInfo

type PlayerInfo struct {
	ID      int    `json:"id"`
	Time    string `json:"time"`
	Ping    int    `json:"ping"`
	Loss    int    `json:"loss"`
	State   string `json:"state"`
	Rate    int    `json:"rate"`
	Address string `json:"address"`
	Name    string `json:"name"`
}

type PlayerSummary

type PlayerSummary struct {
	Humans       int  `json:"humans"`
	Bots         int  `json:"bots"`
	MaxPlayers   int  `json:"max_players"`
	Hibernating  bool `json:"hibernating"`
	ReservedSlot bool `json:"reserved_slot"`
}

type RconConnection

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

RCON连接封装

type RconPool

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

连接池结构

func NewRconPool

func NewRconPool(maxSize int) *RconPool

func (*RconPool) Close

func (rp *RconPool) Close()

关闭连接池

func (*RconPool) GetConnection

func (rp *RconPool) GetConnection(name, port, passwd string) (*RconConnection, error)

获取或创建连接

func (*RconPool) HealthCheck

func (rp *RconPool) HealthCheck(name, port, passwd string) error

健康检查 - 测试连接是否正常

type ServerInfo

type ServerInfo struct {
	Hibernating               bool         `json:"hibernating"`
	CPUUsage                  float64      `json:"cpu_usage"`
	ClientsBot                int          `json:"clients_bot"`
	ClientsHuman              int          `json:"clients_human"`
	ClientsProxies            int          `json:"clients_proxies"`
	Map                       string       `json:"map"`
	Addon                     string       `json:"addon"`
	UDPPort                   int          `json:"udp_port"`
	Clients                   []ClientInfo `json:"clients"`
	AsyncNetworkingWaitMs     float64      `json:"async_networking_wait_ms"`
	StartupServerModuleInit   int          `json:"startup_ServerModuleInit"`
	StartupGameRulesCreated   int          `json:"startup_GameRulesCreated"`
	StartupSteamLoggedOn      int          `json:"startup_SteamLoggedOn"`
	StartupRequestedGcSession int          `json:"startup_RequestedGcSession"`
	GameVars                  int          `json:"game_vars"`
	GCStatus                  string       `json:"gc_status"`
	SVShutdownRequested       bool         `json:"sv_shutdown_requested"`
	SteamLoggedOn             bool         `json:"steam_loggedon"`
	SteamID64                 string       `json:"steamid64"`
	SteamID                   string       `json:"steamid"`
}

type ServerStatus

type ServerStatus struct {
	ServerAddress string        `json:"server_address"`
	ClientStatus  string        `json:"client_status"`
	CurrentState  string        `json:"current_state"`
	Source        string        `json:"source"`
	Hostname      string        `json:"hostname"`
	SpawnGroup    int           `json:"spawn_group"`
	Version       string        `json:"version"`
	SteamID       string        `json:"steam_id"`
	SteamID64     string        `json:"steam_id_64"`
	LocalIP       string        `json:"local_ip"`
	PublicIP      string        `json:"public_ip"`
	OS            string        `json:"os"`
	PlayerSummary PlayerSummary `json:"player_summary"`
	Spawngroups   []Spawngroup  `json:"spawngroups"`
	PlayerList    []PlayerInfo  `json:"player_list"`
}

====================== 服务器状态相关 ======================

func GetServerStatus

func GetServerStatus(name string) (ServerStatus, error)

获取服务器状态(主函数调用)

func ParseCS2Status

func ParseCS2Status(output string) (ServerStatus, error)

解析 status 输出文本为结构体

type ServerStatusJSON

type ServerStatusJSON struct {
	FrametimeMs         float64    `json:"frametime_ms"`
	FramecomputetimeMs  float64    `json:"framecomputetime_ms"`
	ProcessUptime       int        `json:"process_uptime"`
	BuildVersion        int        `json:"build_version"`
	BuildSourceRevision string     `json:"build_source_revision"`
	MemPhysTotalGb      float64    `json:"mem_phys_total_gb"`
	MemPhysAvailGb      float64    `json:"mem_phys_avail_gb"`
	MemVirtTotalGb      float64    `json:"mem_virt_total_gb"`
	MemVirtAvailGb      float64    `json:"mem_virt_avail_gb"`
	Server              ServerInfo `json:"server"`
}

在适当的位置添加这些结构体定义

func GetServerStatusJSON

func GetServerStatusJSON(name string) (*ServerStatusJSON, error)

修改 GetServerStatusJSON 函数

type Spawngroup

type Spawngroup struct {
	ID    int      `json:"id"`
	Path  string   `json:"path"`
	Type  string   `json:"type"`
	Flags []string `json:"flags"`
}

Jump to

Keyboard shortcuts

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