beparser

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: AGPL-3.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(data []byte, cmd string) any

Return struct by passed command:

  • `players` -> []Player
  • `admins` -> []Admin
  • `bans` -> []Bans
  • others -> []string

func ParseWithGeo added in v0.2.0

func ParseWithGeo(data []byte, cmd string, geoReader *geoip2.Reader) (any, error)

Return struct by passed command like Parse with country from IP fields by geoip2.Reader

func ParseWithGeoDB added in v0.2.0

func ParseWithGeoDB(data []byte, cmd string, geoDB string) (any, error)

Return struct by passed command like Parse with country from IP fields by geoDB file path

Types

type Admin

type Admin struct {
	IP      string `json:"ip"`
	Country string `json:"country,omitempty"`
	Port    uint16 `json:"port"`
	ID      byte   `json:"id"`
}

Admin represents a connected RCon admin.

type Admins

type Admins []Admin

Admins represents a []Admin list.

func NewAdmins

func NewAdmins() *Admins

Create new Admins

func (*Admins) Parse

func (a *Admins) Parse(data []byte)

ParseAdmins parses the admin section of the input.

func (*Admins) SetCountryCode

func (a *Admins) SetCountryCode(geoDB *geoip2.Reader)

Set country code from geoDB for admin IP

type BanGUID

type BanGUID struct {
	GUID        string `json:"guid"`
	Reason      string `json:"reason"`
	ID          int    `json:"id"`
	MinutesLeft int    `json:"minutes"`
	Valid       bool   `json:"valid"`
}

BanGUID represents a GUID ban entry.

type BanIP

type BanIP struct {
	IP          string `json:"ip"`
	Reason      string `json:"reason"`
	Country     string `json:"country,omitempty"`
	ID          int    `json:"id"`
	MinutesLeft int    `json:"minutes"`
	Valid       bool   `json:"valid"`
}

BanIP represents an IP ban entry.

type Bans

type Bans struct {
	GUIDBans BansGUID `json:"guid_bans"`
	IPBans   BansIP   `json:"ip_bans"`
}

Bans represents a structure for all types of bans.

func NewBans

func NewBans() *Bans

Create new Bans

func (*Bans) Parse

func (b *Bans) Parse(data []byte)

ParseBans parses the ban section of the input.

func (*Bans) SetCountryCode

func (b *Bans) SetCountryCode(geoDB *geoip2.Reader)

Set country code from geoDB for IP bans in global Bans struct

type BansGUID

type BansGUID []BanGUID

BansGUID represents a []BanGUID list.

func NewBansGUID

func NewBansGUID() *BansGUID

Create new BansGUID

func (*BansGUID) Parse

func (b *BansGUID) Parse(lines []string)

Parse GUID bans data

type BansIP

type BansIP []BanIP

BansIP represents a []BanIP list.

func NewBansIP

func NewBansIP() *BansIP

Create new BansIP

func (*BansIP) Parse

func (b *BansIP) Parse(lines []string, guidCount int)

Parse IP bans data

func (*BansIP) SetCountryCode

func (b *BansIP) SetCountryCode(geoDB *geoip2.Reader)

Set country code from geoDB for IP bans

type Messages

type Messages struct {
	Msg []string `json:"msg"`
}

All other responses

func NewMessage

func NewMessage() *Messages

Create new Messages struct

func (*Messages) Parse

func (m *Messages) Parse(data []byte)

Split other not parsable response to lines in Messages struct

type Player

type Player struct {
	IP      string `json:"ip"`
	GUID    string `json:"guid"`
	Name    string `json:"name"`
	Country string `json:"country,omitempty"`
	Port    uint16 `json:"port"`
	Ping    uint16 `json:"ping"`
	ID      byte   `json:"id"`
	Valid   bool   `json:"valid"`
	Lobby   bool   `json:"lobby"`
}

Player represents a single player.

type Players

type Players []Player

Players represents a []Player list.

func NewPlayers

func NewPlayers() *Players

Create new Players

func (*Players) Parse

func (p *Players) Parse(data []byte)

ParsePlayers parses the player section of the input.

func (*Players) SetCountryCode

func (p *Players) SetCountryCode(geoDB *geoip2.Reader)

Set country code from geoDB for player IP

Jump to

Keyboard shortcuts

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