-
Notifications
You must be signed in to change notification settings - Fork 12
/
get_rating.go
61 lines (47 loc) · 1.75 KB
/
get_rating.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
// Package protocol implements the DataStore protocol
package protocol
import (
"fmt"
nex "github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
"github.com/PretendoNetwork/nex-protocols-go/v2/globals"
)
func (protocol *Protocol) handleGetRating(packet nex.PacketInterface) {
if protocol.GetRating == nil {
err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetRating not implemented")
globals.Logger.Warning(err.Message)
globals.RespondError(packet, ProtocolID, err)
return
}
request := packet.RMCMessage()
callID := request.CallID
parameters := request.Parameters
endpoint := packet.Sender().Endpoint()
parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings())
target := datastore_types.NewDataStoreRatingTarget()
accessPassword := types.NewPrimitiveU64(0)
var err error
err = target.ExtractFrom(parametersStream)
if err != nil {
_, rmcError := protocol.GetRating(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
}
return
}
err = accessPassword.ExtractFrom(parametersStream)
if err != nil {
_, rmcError := protocol.GetRating(fmt.Errorf("Failed to read accessPassword from parameters. %s", err.Error()), packet, callID, nil, nil)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
}
return
}
rmcMessage, rmcError := protocol.GetRating(nil, packet, callID, target, accessPassword)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
return
}
globals.Respond(packet, rmcMessage)
}