Skip to content

Commit

Permalink
Added DataStore::SearchObject
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Apr 4, 2023
1 parent f09e206 commit da826dc
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ type DataStoreProtocol struct {
GetMetasHandler func(err error, client *nex.Client, callID uint32, dataIDs []uint64, param *DataStoreGetMetaParam)
PrepareUpdateObjectHandler func(err error, client *nex.Client, callID uint32, dataStorePrepareUpdateParam *DataStorePrepareUpdateParam)
CompleteUpdateObjectHandler func(err error, client *nex.Client, callID uint32, dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam)
SearchObjectHandler func(err error, client *nex.Client, callID uint32, param *DataStoreSearchParam)
RateObjectHandler func(err error, client *nex.Client, callID uint32, target *DataStoreRatingTarget, param *DataStoreRateObjectParam, fetchRatings bool)
PostMetaBinaryHandler func(err error, client *nex.Client, callID uint32, dataStorePreparePostParam *DataStorePreparePostParam)
PreparePostObjectHandler func(err error, client *nex.Client, callID uint32, dataStorePrepareGetParam *DataStorePreparePostParam)
Expand Down Expand Up @@ -1404,7 +1405,10 @@ func (dataStoreSearchParam *DataStoreSearchParam) ExtractFromStream(stream *nex.
dataStoreSearchParam.ResultRange = resultRange.(*nex.ResultRange)
dataStoreSearchParam.ResultOption = stream.ReadUInt8()
dataStoreSearchParam.MinimalRatingFrequency = stream.ReadUInt32LE()
dataStoreSearchParam.UseCache = (stream.ReadUInt8() == 1)

if stream.Server.NexVersion() >= 30500 {
dataStoreSearchParam.UseCache = (stream.ReadUInt8() == 1)
}

return nil
}
Expand Down Expand Up @@ -1937,6 +1941,8 @@ func (dataStoreProtocol *DataStoreProtocol) Setup() {
go dataStoreProtocol.handlePrepareUpdateObject(packet)
case DataStoreMethodCompleteUpdateObject:
go dataStoreProtocol.handleCompleteUpdateObject(packet)
case DataStoreMethodSearchObject:
go dataStoreProtocol.handleSearchObject(packet)
case DataStoreMethodRateObject:
go dataStoreProtocol.handleRateObject(packet)
case DataStoreMethodPostMetaBinary:
Expand Down Expand Up @@ -1985,6 +1991,11 @@ func (dataStoreProtocol *DataStoreProtocol) PrepareUpdateObject(handler func(err
dataStoreProtocol.PrepareUpdateObjectHandler = handler
}

// SearchObject sets the SearchObject handler function
func (dataStoreProtocol *DataStoreProtocol) SearchObject(handler func(err error, client *nex.Client, callID uint32, param *DataStoreSearchParam)) {
dataStoreProtocol.SearchObjectHandler = handler
}

// CompleteUpdateObject sets the CompleteUpdateObject handler function
func (dataStoreProtocol *DataStoreProtocol) CompleteUpdateObject(handler func(err error, client *nex.Client, callID uint32, dataStoreCompleteUpdateParam *DataStoreCompleteUpdateParam)) {
dataStoreProtocol.CompleteUpdateObjectHandler = handler
Expand Down Expand Up @@ -2165,6 +2176,30 @@ func (dataStoreProtocol *DataStoreProtocol) handleCompleteUpdateObject(packet ne
go dataStoreProtocol.CompleteUpdateObjectHandler(nil, client, callID, dataStoreCompleteUpdateParam.(*DataStoreCompleteUpdateParam))
}

func (dataStoreProtocol *DataStoreProtocol) handleSearchObject(packet nex.PacketInterface) {
if dataStoreProtocol.SearchObjectHandler == nil {
logger.Warning("DataStoreProtocol::SearchObject not implemented")
go respondNotImplemented(packet, DataStoreProtocolID)
return
}

client := packet.Sender()
request := packet.RMCRequest()

callID := request.CallID()
parameters := request.Parameters()

parametersStream := nex.NewStreamIn(parameters, dataStoreProtocol.server)

param, err := parametersStream.ReadStructure(NewDataStoreSearchParam())
if err != nil {
go dataStoreProtocol.SearchObjectHandler(err, client, callID, nil)
return
}

go dataStoreProtocol.SearchObjectHandler(nil, client, callID, param.(*DataStoreSearchParam))
}

func (dataStoreProtocol *DataStoreProtocol) handleRateObject(packet nex.PacketInterface) {
if dataStoreProtocol.RateObjectHandler == nil {
logger.Warning("DataStoreProtocol::RateObject not implemented")
Expand Down

0 comments on commit da826dc

Please sign in to comment.