|
|
|
@ -91,7 +91,7 @@ func (ga *gameManageImpl) CopyUnit(ctx context.Context, req *game.CopyUnitReq) (
|
|
|
|
|
return res, errors.New("区服不存在!") |
|
|
|
|
} |
|
|
|
|
filename := "Unit" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
storeFilename := "storeComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
storeFilename := "StoreComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
deadFilename := "DeadVillagerManagerComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
decorationFilename := "DecorationManagerComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
//userDir := "./download/" + filename
|
|
|
|
@ -163,17 +163,48 @@ func (ga *gameManageImpl) UpdateUnit(ctx context.Context, req *game.UpdateUnitRe
|
|
|
|
|
|
|
|
|
|
destId, err1 := internal.GetIdToUid(ctx, int64(req.DestName)) |
|
|
|
|
if err1 != nil { |
|
|
|
|
return res, err1 |
|
|
|
|
err = err1 |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
userDir := "./download/Unit" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
srcUserDir := "./download/" + req.Filename |
|
|
|
|
srcId, err1 := writeFile1(destId, userDir, req.Filename, req.DestName) |
|
|
|
|
if err1 != nil { |
|
|
|
|
err = err1 |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
log.Printf("copyUnit srcid: %s, destid: %d, DestName: %d", srcId, destId, req.DestName) |
|
|
|
|
userStoreDir := "./download/StoreComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
err = writeFile(destId, srcId, userStoreDir, req.StoreFilename) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
userDeadDir := "./download/DeadVillagerManagerComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
err = writeFile(destId, srcId, userDeadDir, req.DeadFilename) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
userDecorationDir := "./download/DecorationManagerComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
err = writeFile(destId, srcId, userDecorationDir, req.DecorationFilename) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
mongoimportCommand(ctx, "Unit", userDir, mongoConfig) |
|
|
|
|
mongoimportCommand(ctx, "StoreComponent", userStoreDir, mongoConfig) |
|
|
|
|
mongoimportCommand(ctx, "DeadVillagerManagerComponent", userDeadDir, mongoConfig) |
|
|
|
|
mongoimportCommand(ctx, "DecorationManagerComponent", userDecorationDir, mongoConfig) |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func writeFile1(destId int64, userDir string, fileName string, destName int) (srcId string, err error) { |
|
|
|
|
srcUserDir := "./download/" + fileName |
|
|
|
|
writeByte, err1 := os.ReadFile(srcUserDir) |
|
|
|
|
if err1 != nil { |
|
|
|
|
return res, err1 |
|
|
|
|
return "", err1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
srcUid := "" |
|
|
|
|
srcId := "" |
|
|
|
|
var v1 map[string]interface{} |
|
|
|
|
if strings.HasPrefix(string(writeByte), "[") { |
|
|
|
|
user := []interface{}{} |
|
|
|
@ -192,103 +223,45 @@ func (ga *gameManageImpl) UpdateUnit(ctx context.Context, req *game.UpdateUnitRe
|
|
|
|
|
srcId = fmt.Sprint(UniqueId["$numberLong"]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.Printf("copyUnit srcid: %s, uid: %s, destid: %d, uid: %d", srcId, srcUid, destId, req.DestName) |
|
|
|
|
log.Printf("copyUnit srcid: %s, uid: %s, destId: %d, destName: %d", srcId, srcUid, destId, destName) |
|
|
|
|
if srcId == "" || srcUid == "" { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
writeUnitString := strings.ReplaceAll(gjson.MustEncodeString(v1), srcId, fmt.Sprint(destId)) |
|
|
|
|
writeUnitString = internal.ReplaceLastOccurrence(writeUnitString, srcUid, fmt.Sprint(req.DestName)) |
|
|
|
|
writeUnitString = internal.ReplaceLastOccurrence(writeUnitString, srcUid, fmt.Sprint(destName)) |
|
|
|
|
if err = os.WriteFile(userDir, []byte(writeUnitString), 0666); err != nil { |
|
|
|
|
log.Println(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
userStoreDir := "./download/storeComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
srcStoreDir := "./download/" + req.StoreFilename |
|
|
|
|
writeStoreByte, err1 := os.ReadFile(srcStoreDir) |
|
|
|
|
if err1 != nil { |
|
|
|
|
return res, err1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var v2 map[string]interface{} |
|
|
|
|
if strings.HasPrefix(string(writeStoreByte), "[") { |
|
|
|
|
user := []interface{}{} |
|
|
|
|
json.Unmarshal(writeStoreByte, &user) |
|
|
|
|
if len(user) != 0 { |
|
|
|
|
v2 = user[0].(map[string]interface{}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
json.Unmarshal(writeStoreByte, &v2) |
|
|
|
|
} |
|
|
|
|
writeStoreString := strings.ReplaceAll(gjson.MustEncodeString(v2), srcId, fmt.Sprint(destId)) |
|
|
|
|
if err = os.WriteFile(userStoreDir, []byte(writeStoreString), 0666); err != nil { |
|
|
|
|
log.Println(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
userDeadDir := "./download/DeadVillagerManagerComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
srcDeadDir := "./download/" + req.DeadFilename |
|
|
|
|
writeDeadByte, err1 := os.ReadFile(srcDeadDir) |
|
|
|
|
if err1 != nil { |
|
|
|
|
return res, err1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var v3 map[string]interface{} |
|
|
|
|
if strings.HasPrefix(string(writeDeadByte), "[") { |
|
|
|
|
user := []interface{}{} |
|
|
|
|
json.Unmarshal(writeDeadByte, &user) |
|
|
|
|
if len(user) != 0 { |
|
|
|
|
v3 = user[0].(map[string]interface{}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
json.Unmarshal(writeDeadByte, &v3) |
|
|
|
|
} |
|
|
|
|
if len(v3) != 0 { |
|
|
|
|
writeDeadString := strings.ReplaceAll(gjson.MustEncodeString(v3), srcId, fmt.Sprint(destId)) |
|
|
|
|
if err = os.WriteFile(userDeadDir, []byte(writeDeadString), 0666); err != nil { |
|
|
|
|
log.Println(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
userDecorationDir := "./download/DecorationManagerComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
srcDecorationDir := "./download/" + req.DecorationFilename |
|
|
|
|
writeDecorationByte, err1 := os.ReadFile(srcDecorationDir) |
|
|
|
|
func writeFile(destId int64, srcId string, userDir string, fileName string) (err error) { |
|
|
|
|
srcDir := "./download/" + fileName |
|
|
|
|
writeByte, err1 := os.ReadFile(srcDir) |
|
|
|
|
if err1 != nil { |
|
|
|
|
return res, err1 |
|
|
|
|
return err1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var v4 map[string]interface{} |
|
|
|
|
if strings.HasPrefix(string(writeDecorationByte), "[") { |
|
|
|
|
var v map[string]interface{} |
|
|
|
|
if strings.HasPrefix(string(writeByte), "[") { |
|
|
|
|
user := []interface{}{} |
|
|
|
|
json.Unmarshal(writeDecorationByte, &user) |
|
|
|
|
json.Unmarshal(writeByte, &user) |
|
|
|
|
if len(user) != 0 { |
|
|
|
|
v4 = user[0].(map[string]interface{}) |
|
|
|
|
v = user[0].(map[string]interface{}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
json.Unmarshal(writeDecorationByte, &v4) |
|
|
|
|
json.Unmarshal(writeByte, &v) |
|
|
|
|
} |
|
|
|
|
if len(v4) != 0 { |
|
|
|
|
writeDecorationString := strings.ReplaceAll(gjson.MustEncodeString(v4), srcId, fmt.Sprint(destId)) |
|
|
|
|
if err = os.WriteFile(userDecorationDir, []byte(writeDecorationString), 0666); err != nil { |
|
|
|
|
if len(v) != 0 { |
|
|
|
|
writeString := strings.ReplaceAll(gjson.MustEncodeString(v), srcId, fmt.Sprint(destId)) |
|
|
|
|
if err = os.WriteFile(userDir, []byte(writeString), 0666); err != nil { |
|
|
|
|
log.Println(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//writeUnitCmd := fmt.Sprintf("mongoimport --uri=\"%s\" --authenticationDatabase=%s --collection=Unit --file=\"%s\" --type=json --mode=upsert",
|
|
|
|
|
// mongoConfig.Link1, mongoConfig.Auth, userDir)
|
|
|
|
|
//writeStoreCmd := fmt.Sprintf("mongoimport --uri=\"%s\" --authenticationDatabase=%s --collection=StoreComponent --file=\"%s\" --type=json --mode=upsert",
|
|
|
|
|
// mongoConfig.Link1, mongoConfig.Auth, userStoreDir)
|
|
|
|
|
//log.Println("sh Unit: ", writeUnitCmd)
|
|
|
|
|
//log.Println("sh StoreComponent: ", writeStoreCmd)
|
|
|
|
|
g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
mongoimportCommand(ctx, "Unit", userDir, mongoConfig) |
|
|
|
|
mongoimportCommand(ctx, "StoreComponent", userStoreDir, mongoConfig) |
|
|
|
|
mongoimportCommand(ctx, "DeadVillagerManagerComponent", userDeadDir, mongoConfig) |
|
|
|
|
mongoimportCommand(ctx, "DecorationManagerComponent", userDecorationDir, mongoConfig) |
|
|
|
|
}) |
|
|
|
|
//fmt.Println("UpdateUnit GetRoleDelta", gjson.MustEncodeString(req))
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|