-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathauth.go
More file actions
101 lines (88 loc) · 3.4 KB
/
auth.go
File metadata and controls
101 lines (88 loc) · 3.4 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package rlapi
import "fmt"
type AuthPlayerRequest struct {
Platform string `json:"Platform"`
PlayerName string `json:"PlayerName"`
PlayerID string `json:"PlayerID"`
Language string `json:"Language"`
AuthTicket string `json:"AuthTicket"`
BuildRegion string `json:"BuildRegion"`
FeatureSet string `json:"FeatureSet"`
Device string `json:"Device"`
LocalFirstPlayerID string `json:"LocalFirstPlayerID"`
SkipAuth bool `json:"bSkipAuth"`
SetAsPrimaryAccount bool `json:"bSetAsPrimaryAccount"`
EpicAuthTicket string `json:"EpicAuthTicket"`
EpicAccountID string `json:"EpicAccountID"`
}
type AuthPlayerResponse struct {
IsLastChanceAuthBan bool `json:"IsLastChanceAuthBan"`
SessionID string `json:"SessionID"`
VerifiedPlayerName string `json:"VerifiedPlayerName"`
UseWebSocket bool `json:"UseWebSocket"`
PerConURL string `json:"PerConURL"`
PerConURLv2 string `json:"PerConURLv2"`
PsyToken string `json:"PsyToken"`
CountryRestrictions []string `json:"CountryRestrictions"`
}
// AuthPlayer authenticates with PsyNet via EGS and returns a WebSocket connection.
func (p *PsyNet) AuthPlayer(authToken string, accountID string, accountName string) (*PsyNetRPC, error) {
localPlayerId := NewPlayerID(PlatformEpic, accountID)
req := &AuthPlayerRequest{
Platform: string(PlatformEpic),
PlayerName: accountName,
PlayerID: accountID,
Language: "INT",
AuthTicket: authToken,
BuildRegion: "",
FeatureSet: featureSet,
Device: "PC",
LocalFirstPlayerID: localPlayerId.String(),
SkipAuth: false,
SetAsPrimaryAccount: true,
EpicAuthTicket: authToken,
EpicAccountID: accountID,
}
var res AuthPlayerResponse
err := p.postJSON([]string{"Auth", "AuthPlayer", "v2"}, req, &res)
if err != nil {
return nil, fmt.Errorf("failed to authenticate player: %w", err)
}
rpc, err := p.establishSocket(res.PerConURLv2, localPlayerId, res.PsyToken, res.SessionID)
if err != nil {
return nil, fmt.Errorf("failed to establish websocket: %w", err)
}
go rpc.readMessages()
rpc.schedulePing()
return rpc, nil
}
// AuthPlayerSteam authenticates with PsyNet via Steam session ticket and returns a WebSocket connection.
func (p *PsyNet) AuthPlayerSteam(authToken string, epicAccountID string, steamAccountID string, accountName string) (*PsyNetRPC, error) {
localPlayerId := NewPlayerID(PlatformSteam, steamAccountID)
req := &AuthPlayerRequest{
Platform: string(PlatformSteam),
PlayerName: accountName,
PlayerID: steamAccountID,
Language: "INT",
AuthTicket: authToken,
BuildRegion: "",
FeatureSet: featureSet,
Device: "PC",
SkipAuth: false,
SetAsPrimaryAccount: true,
EpicAuthTicket: authToken,
EpicAccountID: epicAccountID,
}
var res AuthPlayerResponse
err := p.postJSON([]string{"Auth", "AuthPlayer", "v2"}, req, &res)
if err != nil {
return nil, fmt.Errorf("failed to authenticate player: %w", err)
}
rpc, err := p.establishSocket(res.PerConURLv2, localPlayerId, res.PsyToken, res.SessionID)
if err != nil {
return nil, fmt.Errorf("failed to establish websocket: %w", err)
}
go rpc.readMessages()
rpc.schedulePing()
return rpc, nil
}