-
Notifications
You must be signed in to change notification settings - Fork 13
/
rate_object_with_posting.go
77 lines (60 loc) · 2.87 KB
/
rate_object_with_posting.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
// Package protocol implements the DataStore protocol
package protocol
import (
"fmt"
nex "github.com/PretendoNetwork/nex-go"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
"github.com/PretendoNetwork/nex-protocols-go/globals"
)
// RateObjectWithPosting sets the RateObjectWithPosting handler function
func (protocol *Protocol) RateObjectWithPosting(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, rateParam *datastore_types.DataStoreRateObjectParam, postParam *datastore_types.DataStorePreparePostParam, fetchRatings bool) uint32) {
protocol.rateObjectWithPostingHandler = handler
}
func (protocol *Protocol) handleRateObjectWithPosting(packet nex.PacketInterface) {
var errorCode uint32
if protocol.rateObjectWithPostingHandler == nil {
globals.Logger.Warning("DataStore::RateObjectWithPosting not implemented")
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented)
return
}
request := packet.RMCRequest()
callID := request.CallID()
parameters := request.Parameters()
parametersStream := nex.NewStreamIn(parameters, protocol.Server)
target, err := parametersStream.ReadStructure(datastore_types.NewDataStoreRatingTarget())
if err != nil {
errorCode = protocol.rateObjectWithPostingHandler(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil, nil, false)
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
return
}
rateParam, err := parametersStream.ReadStructure(datastore_types.NewDataStoreRateObjectParam())
if err != nil {
errorCode = protocol.rateObjectWithPostingHandler(fmt.Errorf("Failed to read rateParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, false)
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
return
}
postParam, err := parametersStream.ReadStructure(datastore_types.NewDataStorePreparePostParam())
if err != nil {
errorCode = protocol.rateObjectWithPostingHandler(fmt.Errorf("Failed to read postParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, false)
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
return
}
fetchRatings, err := parametersStream.ReadBool()
if err != nil {
errorCode = protocol.rateObjectWithPostingHandler(fmt.Errorf("Failed to read fetchRatings from parameters. %s", err.Error()), packet, callID, nil, nil, nil, false)
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
return
}
errorCode = protocol.rateObjectWithPostingHandler(nil, packet, callID, target.(*datastore_types.DataStoreRatingTarget), rateParam.(*datastore_types.DataStoreRateObjectParam), postParam.(*datastore_types.DataStorePreparePostParam), fetchRatings)
if errorCode != 0 {
globals.RespondError(packet, ProtocolID, errorCode)
}
}