-
Notifications
You must be signed in to change notification settings - Fork 11
/
change_metas_v1.go
74 lines (58 loc) · 2.25 KB
/
change_metas_v1.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
// 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) handleChangeMetasV1(packet nex.PacketInterface) {
if protocol.ChangeMetasV1 == nil {
err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ChangeMetasV1 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())
dataIDs := types.NewList[*types.PrimitiveU64]()
dataIDs.Type = types.NewPrimitiveU64(0)
params := types.NewList[*datastore_types.DataStoreChangeMetaParamV1]()
params.Type = datastore_types.NewDataStoreChangeMetaParamV1()
transactional := types.NewPrimitiveBool(false)
var err error
err = dataIDs.ExtractFrom(parametersStream)
if err != nil {
_, rmcError := protocol.ChangeMetasV1(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil, nil, nil)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
}
return
}
err = params.ExtractFrom(parametersStream)
if err != nil {
_, rmcError := protocol.ChangeMetasV1(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil, nil)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
}
return
}
err = transactional.ExtractFrom(parametersStream)
if err != nil {
_, rmcError := protocol.ChangeMetasV1(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil, nil)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
}
return
}
rmcMessage, rmcError := protocol.ChangeMetasV1(nil, packet, callID, dataIDs, params, transactional)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
return
}
globals.Respond(packet, rmcMessage)
}