cascaded server rpc call

This commit is contained in:
김도한 [dominick]
2022-12-19 15:36:27 +09:00
parent 3da59e65cf
commit 76c9baeed3
2 changed files with 89 additions and 24 deletions

View File

@ -251,6 +251,25 @@ func (tx *transaction) WriteDB(collection string, raw map[string]interface{}) sh
return shared.MakeRPCReturn(nil, err)
}
func (tx *transaction) WriteMany(collection string, rawArray []interface{}) shared.RPCReturnType {
for _, raw := range rawArray {
parsed := raw.(map[string]interface{})
_, _, err := tx.gs.mongoClient.Update(shared.CollectionName(collection),
bson.M{"_id": parsed["_id"]},
bson.M{
"$currentDate": bson.M{"_ts": true},
"$set": parsed,
}, options.Update().SetUpsert(true))
if err != nil {
shared.MakeRPCReturn(nil, err)
}
}
return shared.MakeRPCReturn(nil, nil)
}
func (tx *transaction) RemoveDB(collection string, keys []interface{}) shared.RPCReturnType {
count, err := tx.gs.mongoClient.DeleteMany(shared.CollectionName(collection), bson.M{"_id": bson.M{"$in": keys}})
@ -296,6 +315,14 @@ func (tx *transaction) RemoveCharInfo(charSlotId int32) shared.RPCReturnType {
bson.M{"$pull": bson.M{"charInfo": bson.M{"slotId": charSlotId}}},
)
if err == nil {
_, err = tx.gs.mongoClient.FindOneAndUpdate(
"Inventory",
bson.M{"_id": playerid},
bson.M{"$pull": bson.M{"inven": bson.M{"charSlotId": charSlotId}}},
)
}
if err == nil {
return shared.MakeRPCReturn("update success", err)
} else {
@ -317,11 +344,11 @@ func (tx *transaction) UpdateCharInfo(charSlotId int32, raw map[string]interface
q, err := tx.gs.mongoClient.FindOne("PlayerInfo", bson.M{"_id": playerid, "charInfo.slotId": charSlotId},
options.FindOne().SetProjection(bson.M{"charInfo.$": 1}))
if q == nil {
info := raw
info["slotId"] = charSlotId
var info map[string]interface{}
tx.gs.Logger.Println("new info", info)
if q == nil {
info = raw
info["slotId"] = charSlotId
_, _, err = tx.gs.mongoClient.Update("PlayerInfo",
bson.M{"_id": playerid},
@ -331,7 +358,7 @@ func (tx *transaction) UpdateCharInfo(charSlotId int32, raw map[string]interface
},
options.Update().SetUpsert(true))
} else {
info := q["charInfo"].(bson.A)[0].(map[string]interface{})
info = q["charInfo"].(bson.A)[0].(map[string]interface{})
tx.gs.Logger.Println("current info", info)
for k, v := range raw {
@ -341,8 +368,6 @@ func (tx *transaction) UpdateCharInfo(charSlotId int32, raw map[string]interface
info[k] = v
}
tx.gs.Logger.Println("new info", info)
_, _, err = tx.gs.mongoClient.Update("PlayerInfo",
bson.M{"_id": playerid, "charInfo.slotId": charSlotId},
bson.M{
@ -351,6 +376,8 @@ func (tx *transaction) UpdateCharInfo(charSlotId int32, raw map[string]interface
})
}
tx.gs.Logger.Println("new info", info)
// _, _, err := tx.gs.mongoClient.Update("PlayerInfo",
// bson.M{"_id": playerid},
// bson.M{
@ -359,7 +386,7 @@ func (tx *transaction) UpdateCharInfo(charSlotId int32, raw map[string]interface
// }, options.Update().SetUpsert(true))
if err == nil {
return shared.MakeRPCReturn("update success", err)
return shared.MakeRPCReturn(info, err)
} else {
return shared.MakeRPCReturn(nil, errors.New("invalid body"))
}