-
Notifications
You must be signed in to change notification settings - Fork 12
/
prepare_update_object.go
47 lines (36 loc) · 1.38 KB
/
prepare_update_object.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
// Package protocol implements the DataStore protocol
package protocol
import (
"fmt"
nex "github.com/PretendoNetwork/nex-go/v2"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types"
"github.com/PretendoNetwork/nex-protocols-go/v2/globals"
)
func (protocol *Protocol) handlePrepareUpdateObject(packet nex.PacketInterface) {
if protocol.PrepareUpdateObject == nil {
err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PrepareUpdateObject 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())
param := datastore_types.NewDataStorePrepareUpdateParam()
err := param.ExtractFrom(parametersStream)
if err != nil {
_, rmcError := protocol.PrepareUpdateObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
}
return
}
rmcMessage, rmcError := protocol.PrepareUpdateObject(nil, packet, callID, param)
if rmcError != nil {
globals.RespondError(packet, ProtocolID, rmcError)
return
}
globals.Respond(packet, rmcMessage)
}