-
Notifications
You must be signed in to change notification settings - Fork 17
/
hpp.go
128 lines (94 loc) · 3.22 KB
/
hpp.go
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
)
var hppServer *nex.HPPServer
// * Took these structs out of the protocols lib for convenience
type dataStoreGetNotificationURLParam struct {
types.Structure
PreviousURL *types.String
}
func (d *dataStoreGetNotificationURLParam) ExtractFrom(readable types.Readable) error {
var err error
if err = d.ExtractHeaderFrom(readable); err != nil {
return fmt.Errorf("Failed to extract DataStoreGetNotificationURLParam header. %s", err.Error())
}
err = d.PreviousURL.ExtractFrom(readable)
if err != nil {
return fmt.Errorf("Failed to extract DataStoreGetNotificationURLParam.PreviousURL. %s", err.Error())
}
return nil
}
type dataStoreReqGetNotificationURLInfo struct {
types.Structure
URL *types.String
Key *types.String
Query *types.String
RootCACert *types.Buffer
}
func (d *dataStoreReqGetNotificationURLInfo) WriteTo(writable types.Writable) {
contentWritable := writable.CopyNew()
d.URL.WriteTo(contentWritable)
d.Key.WriteTo(contentWritable)
d.Query.WriteTo(contentWritable)
d.RootCACert.WriteTo(contentWritable)
content := contentWritable.Bytes()
d.WriteHeaderTo(writable, uint32(len(content)))
writable.Write(content)
}
func passwordFromPID(pid *types.PID) (string, uint32) {
return "notmypassword", 0
}
func startHPPServer() {
fmt.Println("Starting HPP")
hppServer = nex.NewHPPServer()
hppServer.OnData(func(packet nex.PacketInterface) {
if packet, ok := packet.(*nex.HPPPacket); ok {
request := packet.RMCMessage()
fmt.Println("[HPP]", request.ProtocolID, request.MethodID)
if request.ProtocolID == 0x73 { // * DataStore
if request.MethodID == 0xD {
getNotificationURL(packet)
}
}
}
})
hppServer.LibraryVersions().SetDefault(nex.NewLibraryVersion(2, 4, 1))
hppServer.SetAccessKey("76f26496")
hppServer.AccountDetailsByPID = accountDetailsByPID
hppServer.AccountDetailsByUsername = accountDetailsByUsername
hppServer.Listen(12345)
}
func getNotificationURL(packet *nex.HPPPacket) {
request := packet.RMCMessage()
response := nex.NewRMCMessage(hppServer)
parameters := request.Parameters
parametersStream := nex.NewByteStreamIn(parameters, hppServer.LibraryVersions(), hppServer.ByteStreamSettings())
param := &dataStoreGetNotificationURLParam{}
param.PreviousURL = types.NewString("")
err := param.ExtractFrom(parametersStream)
if err != nil {
fmt.Println("[HPP]", err)
return
}
fmt.Println("[HPP]", param.PreviousURL)
responseStream := nex.NewByteStreamOut(hppServer.LibraryVersions(), hppServer.ByteStreamSettings())
info := &dataStoreReqGetNotificationURLInfo{}
info.URL = types.NewString("https://example.com")
info.Key = types.NewString("whatever/key")
info.Query = types.NewString("?pretendo=1")
info.RootCACert = types.NewBuffer(nil)
info.WriteTo(responseStream)
response.IsSuccess = true
response.IsRequest = false
response.ErrorCode = 0x00010001
response.ProtocolID = request.ProtocolID
response.CallID = request.CallID
response.MethodID = request.MethodID
response.Parameters = responseStream.Bytes()
// * We replace the RMC message so that it can be delivered back
packet.SetRMCMessage(response)
hppServer.Send(packet)
}