Skip to content

Commit 60f773c

Browse files
committed
Add type and function docs
1 parent b917928 commit 60f773c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rcon.go

+17
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import (
1313
"github.com/gorcon/rcon"
1414
)
1515

16+
// Client represents a client to a Palword RCON server.
1617
type Client struct {
1718
address string
1819
password string
1920
conn *rcon.Conn
2021
}
2122

23+
// NewClient creates a new [Client] with the given address and password. Note that this function does not attempt to
24+
// connect to the RCON server, so the password is not validated at this time. Instead, the connection is established
25+
// on-demand when a method on the [Client] is called.
2226
func NewClient(address string, password string) *Client {
2327
client := &Client{
2428
address: address,
@@ -58,6 +62,8 @@ func (r *Client) executeWithRetry(command string, retry bool) (string, error) {
5862
return strings.TrimSpace(response), err
5963
}
6064

65+
// KickPlayer instructs the server to ban the player with the given Steam ID from the server. The player must be online
66+
// to be banned.
6167
func (r *Client) BanPlayer(steamID uint64) error {
6268
response, err := r.executeWithRetry(fmt.Sprintf("BanPlayer %d", steamID), true)
6369
if err != nil {
@@ -68,6 +74,7 @@ func (r *Client) BanPlayer(steamID uint64) error {
6874
return nil
6975
}
7076

77+
// Broadcast displays the given message to all online players.
7178
func (r *Client) Broadcast(message string) error {
7279
response, err := r.executeWithRetry(fmt.Sprintf("Broadcast %s", message), true)
7380
if err != nil {
@@ -78,6 +85,7 @@ func (r *Client) Broadcast(message string) error {
7885
return nil
7986
}
8087

88+
// DoExit instructs the server to immediately exit.
8189
func (r *Client) DoExit() error {
8290
response, err := r.executeWithRetry("DoExit", true)
8391
if err != nil {
@@ -88,13 +96,15 @@ func (r *Client) DoExit() error {
8896
return nil
8997
}
9098

99+
// ServerInfo represents the information about the server returned by [Client.Info]().
91100
type ServerInfo struct {
92101
ServerName string
93102
Version string
94103
}
95104

96105
var infoRegex = regexp.MustCompile(`^Welcome to Pal Server\[v([\d\.]+)\]\s*(.*?)$`)
97106

107+
// Info returns information about the server.
98108
func (r *Client) Info() (*ServerInfo, error) {
99109
response, err := r.executeWithRetry("Info", true)
100110
if err != nil {
@@ -110,6 +120,7 @@ func (r *Client) Info() (*ServerInfo, error) {
110120
}, nil
111121
}
112122

123+
// KickPlayer instructs the server to kick the player with the given Steam ID.
113124
func (r *Client) KickPlayer(steamID uint64) error {
114125
response, err := r.executeWithRetry(fmt.Sprintf("KickPlayer %d", steamID), true)
115126
if err != nil {
@@ -120,6 +131,7 @@ func (r *Client) KickPlayer(steamID uint64) error {
120131
return nil
121132
}
122133

134+
// Save instructs the server to save the world to disk.
123135
func (r *Client) Save() error {
124136
response, err := r.executeWithRetry("Save", true)
125137
if err != nil {
@@ -130,12 +142,14 @@ func (r *Client) Save() error {
130142
return nil
131143
}
132144

145+
// Player is the representation of a single player.
133146
type Player struct {
134147
Name string
135148
PlayerUID uint64
136149
SteamID uint64
137150
}
138151

152+
// ShowPlayers returns a list of all players that are currently online.
139153
func (r *Client) ShowPlayers() ([]Player, error) {
140154
players := []Player{}
141155
response, err := r.executeWithRetry("ShowPlayers", true)
@@ -168,10 +182,13 @@ func (r *Client) ShowPlayers() ([]Player, error) {
168182
return players, nil
169183
}
170184

185+
// Shutdown instructs the server to shut down after the given number of seconds.
171186
func (r *Client) Shutdown(seconds int) error {
172187
return r.shutdown(fmt.Sprintf("%d", seconds))
173188
}
174189

190+
// ShutdownWithMessage instructs the server to shut down after the given number of seconds. The message will be
191+
// displayed to all online players.
175192
func (r *Client) ShutdownWithMessage(seconds int, message string) error {
176193
return r.shutdown(fmt.Sprintf("%d %s", seconds, message))
177194
}

0 commit comments

Comments
 (0)