-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpopulation.go
More file actions
44 lines (36 loc) · 1.18 KB
/
population.go
File metadata and controls
44 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package rlapi
import "context"
type PlaylistID int
type PlaylistPopulation struct {
PlaylistID PlaylistID `json:"PlaylistID"`
Population int `json:"Population"`
}
type GetPopulationResponse struct {
Playlists []PlaylistPopulation `json:"Playlists"`
Timestamp int `json:"Timestamp"`
}
type UpdatePlayerPlaylistRequest struct {
Playlist PlaylistID `json:"Playlist"`
NumLocalPlayers int `json:"NumLocalPlayers"`
}
// GetPopulation retrieves current game population (player count) by playlists.
func (p *PsyNetRPC) GetPopulation(ctx context.Context) ([]PlaylistPopulation, error) {
var result GetPopulationResponse
err := p.sendRequestSync(ctx, "Population/GetPopulation v1", emptyRequest{}, &result)
if err != nil {
return nil, err
}
return result.Playlists, nil
}
func (p *PsyNetRPC) UpdatePlayerPlaylist(ctx context.Context, playlistID PlaylistID, numLocalPlayers int) error {
request := UpdatePlayerPlaylistRequest{
Playlist: playlistID,
NumLocalPlayers: numLocalPlayers,
}
var result interface{}
err := p.sendRequestSync(ctx, "Population/UpdatePlayerPlaylist v1", request, &result)
if err != nil {
return err
}
return nil
}