Hell Let Loose 人间地狱

使用rcon可以用github.com/verocity-gaming/rcon的rcon依赖,新建Go项目,然后导入

import (
    "github.com/verocity-gaming/rcon"
    "log"
)

初始化rcon连接 IP例如127.0.0.1:27015

c, err := rcon.New(ip, password)
        if err != nil {
            println("连接服务器失败!")
            panic(err)
        }

假如我要执行RCON指令来换图 mapName 这个变量就是地图名了

        p := c.SetMap(rcon.MapName(mapName))
        if p == nil {
            fmt.Sprintf("操作成功!")
        } else {
             fmt.Sprintf("%s", p)
        }

然后下面是可用的功能 可以自行实现:

func New(addr string, password string) (*Conn, error)
func (c *Conn) AdminAdd(a Admin) error
func (c *Conn) AdminGroups() ([]string, error)
func (c *Conn) AdminRemove(a Admin) error
func (c *Conn) Admins() ([]Admin, error)
func (c *Conn) AutoBalance() (bool, error)
func (c *Conn) AutoBalanceThreshold() (int, error)
func (c *Conn) BanPermanently(p Player, reason, admin string) error
func (c *Conn) BanRemove(p Player) error
func (c *Conn) BanTemporarily(p Player, hours int, reason, admin string) error
func (c *Conn) Close() error
func (c *Conn) IdleTime() (time.Duration, error)
func (c *Conn) Kick(p Player, reason string) error
func (c *Conn) Map() (Map, error)
func (c *Conn) Maps() ([]Map, error)
func (c *Conn) MaxPing() (time.Duration, error)
func (c *Conn) Name() (string, error)
func (c *Conn) PermanentlyBanned() ([]Ban, error)
func (c *Conn) Player(username string) (Player, error)
func (c *Conn) Players() ([]Player, error)
func (c *Conn) Profanities() ([]string, error)
func (c *Conn) Punish(p Player, reason string) error
func (c *Conn) ResetVoteKickThreshold() error
func (c *Conn) Rotation() ([]Map, error)
func (c *Conn) RotationAdd(n MapName) error
func (c *Conn) RotationRemove(n MapName) error
func (c *Conn) SetAutoBalance(enabled bool) error
func (c *Conn) SetAutoBalanceThreshold(diff int) error
func (c *Conn) SetBroadcast(message string) error
func (c *Conn) SetIdleTime(m time.Duration) error
func (c *Conn) SetMap(n MapName) error
func (c *Conn) SetMaxPing(ms time.Duration) error
func (c *Conn) SetProfanities(words ...string) error
func (c *Conn) SetQueueLength(length int) error
func (c *Conn) SetSwitchTeamCooldown(m time.Duration) error
func (c *Conn) SetSwitchTeamNow(p Player) error
func (c *Conn) SetSwitchTeamOnDeath(p Player) error
func (c *Conn) SetVIPSlots(slots int) error
func (c *Conn) SetVoteKick(enabled bool) error
func (c *Conn) SetVoteKickThreshold(pairs ...VoteKickThreshold) error        
func (c *Conn) Slots() (numerator, denominator int, err error)
func (c *Conn) SwitchTeamCooldown() (time.Duration, error)
func (c *Conn) TemporarilyBanned() ([]Ban, error)
func (c *Conn) UnsetProfanities(words ...string) error
func (c *Conn) VIPAdd(v VIP) error
func (c *Conn) VIPRemove(v VIP) error
func (c *Conn) VIPSlots() (int, error)
func (c *Conn) VIPs() ([]VIP, error)
func (c *Conn) VoteKick() (bool, error)

DEMO:

package main

import (
    "github.com/verocity-gaming/rcon"
    "log"
)

func main() {
    //获取VIP列表使用例子
    c, err := rcon.New("172.0.0.1:8080", "password")
    if err != nil {
        println("连接服务器失败!")
        panic(err)
    }
    p, err := c.VIPs()
    if err != nil {
        panic(err)
    }

    log.Printf("获取VIP列表: %s \n", p)

    //添加VIP例子
    vipObj := rcon.VIP{
        Player: rcon.Player{
            Name: "七龙",
            ID64: "7656....",
        },
    }

    p2 := c.VIPAdd(vipObj)
    if p2 == nil {
        println("添加成功!")
    } else {
        println("%s", p2)

    }
}
最后修改:2022 年 03 月 22 日 04 : 47 AM