|
|
|
@ -92,54 +92,51 @@ func (ga *gameManageImpl) CopyUnit(ctx context.Context, req *game.CopyUnitReq) (
|
|
|
|
|
} |
|
|
|
|
filename := "Unit" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
storeFilename := "storeComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
userDir := "./download/" + filename |
|
|
|
|
storeDir := "./download/" + storeFilename |
|
|
|
|
deadFilename := "DeadVillagerManagerComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
decorationFilename := "DecorationManagerComponent" + fmt.Sprint(req.SrcName) + ".json" |
|
|
|
|
//userDir := "./download/" + filename
|
|
|
|
|
//storeDir := "./download/" + storeFilename
|
|
|
|
|
//deadDir := "./download/" + deadFilename
|
|
|
|
|
//decorationDir := "./download/" + decorationFilename
|
|
|
|
|
|
|
|
|
|
g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
name := "mongoexport" |
|
|
|
|
args := []string{} |
|
|
|
|
args1 := []string{} |
|
|
|
|
mongoexportCommand(ctx, filename, "Unit", int64(req.SrcName), mongoConfig, 1) |
|
|
|
|
mongoexportCommand(ctx, storeFilename, "StoreComponent", unit.Uid, mongoConfig, 2) |
|
|
|
|
mongoexportCommand(ctx, deadFilename, "DeadVillagerManagerComponent", unit.Uid, mongoConfig, 2) |
|
|
|
|
mongoexportCommand(ctx, decorationFilename, "DecorationManagerComponent", unit.Uid, mongoConfig, 2) |
|
|
|
|
|
|
|
|
|
res.Filename = filename |
|
|
|
|
res.StoreFilename = storeFilename |
|
|
|
|
res.DeadFilename = deadFilename |
|
|
|
|
res.DecorationFilename = decorationFilename |
|
|
|
|
}) |
|
|
|
|
fmt.Println("CopyUnit GetRoleDelta", gjson.MustEncodeString(res)) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func mongoexportCommand(ctx context.Context, filename string, collection string, uid int64, mongoConfig internal.MongoType, qType int) { |
|
|
|
|
g.Try(ctx, func(ctx context.Context) { |
|
|
|
|
args := []string{} |
|
|
|
|
dir := "./download/" + filename |
|
|
|
|
args = append(args, fmt.Sprintf("--uri=\"%s\"", mongoConfig.Link1)) |
|
|
|
|
args = append(args, fmt.Sprintf("--authenticationDatabase=%s", mongoConfig.Auth)) |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--uri=\"%s\"", mongoConfig.Link1)) |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--authenticationDatabase=%s", mongoConfig.Auth)) |
|
|
|
|
args = append(args, "--collection=Unit") |
|
|
|
|
args = append(args, fmt.Sprintf("--collection=%s", collection)) |
|
|
|
|
args = append(args, "--jsonArray") |
|
|
|
|
args = append(args, fmt.Sprintf("--out=\"%s\"", userDir)) |
|
|
|
|
args = append(args, fmt.Sprintf("--query=\"{\\\"UniqueId\\\":%d}\"", req.SrcName)) |
|
|
|
|
args = append(args, fmt.Sprintf("--out=\"%s\"", dir)) |
|
|
|
|
if qType == 1 { |
|
|
|
|
args = append(args, fmt.Sprintf("--query=\"{\\\"UniqueId\\\":%d}\"", uid)) |
|
|
|
|
} else { |
|
|
|
|
args = append(args, fmt.Sprintf("--query=\"{\\\"_id\\\":%d}\"", uid)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
args = append(args, "--jsonFormat=canonical") |
|
|
|
|
args = append(args, "--type=json") |
|
|
|
|
args1 = append(args1, "--collection=StoreComponent") |
|
|
|
|
args1 = append(args1, "--jsonArray") |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--out=\"%s\"", storeDir)) |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--query=\"{\\\"_id\\\":%d}\"", unit.Uid)) |
|
|
|
|
args1 = append(args1, "--jsonFormat=canonical") |
|
|
|
|
args1 = append(args1, "--type=json") |
|
|
|
|
|
|
|
|
|
err = utils.CmdCommand(ctx, name, args...) |
|
|
|
|
err := utils.CmdCommand(ctx, "mongoexport", args...) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("cmd.Run() args failed with %s\n", err) |
|
|
|
|
log.Printf(" %s cmd.Run() args failed with %s\n", dir, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
err = utils.CmdCommand(ctx, name, args1...) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("cmd.Run() args1 failed with %s\n", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wireteString := fmt.Sprintf("mongoexport --uri=\"%s\" --authenticationDatabase=%s --collection=Unit --out=\"%s\" --query=\"{\\\"UniqueId\\\":%d}\" --jsonArray --jsonFormat=canonical --type=json", |
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, userDir, req.SrcName) |
|
|
|
|
writeString := fmt.Sprintf("mongoexport --uri=\"%s\" --authenticationDatabase=%s --collection=StoreComponent --out=\"%s\" --query=\"{\\\"_id\\\":%d}\" --jsonArray --jsonFormat=canonical --type=json", |
|
|
|
|
mongoConfig.Link1, mongoConfig.Auth, storeDir, unit.Uid) |
|
|
|
|
log.Println(wireteString) |
|
|
|
|
log.Println(writeString) |
|
|
|
|
|
|
|
|
|
res.Filename = filename |
|
|
|
|
res.StoreFilename = storeFilename |
|
|
|
|
}) |
|
|
|
|
fmt.Println("CopyUnit GetRoleDelta", res.Filename) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) UpdateUnit(ctx context.Context, req *game.UpdateUnitReq) (res *game.UpdateUnitRes, err error) { |
|
|
|
@ -195,6 +192,17 @@ 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) |
|
|
|
|
if srcId == "" || srcUid == "" { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
writeUnitString := strings.ReplaceAll(gjson.MustEncodeString(v1), srcId, fmt.Sprint(destId)) |
|
|
|
|
writeUnitString = internal.ReplaceLastOccurrence(writeUnitString, srcUid, fmt.Sprint(req.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) |
|
|
|
@ -206,77 +214,106 @@ func (ga *gameManageImpl) UpdateUnit(ctx context.Context, req *game.UpdateUnitRe
|
|
|
|
|
if strings.HasPrefix(string(writeStoreByte), "[") { |
|
|
|
|
user := []interface{}{} |
|
|
|
|
json.Unmarshal(writeStoreByte, &user) |
|
|
|
|
v2 = user[0].(map[string]interface{}) |
|
|
|
|
if len(user) != 0 { |
|
|
|
|
v2 = user[0].(map[string]interface{}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
json.Unmarshal(writeStoreByte, &v2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.Printf("copyUnit srcid: %s, uid: %s, destid: %d, uid: %d", srcId, srcUid, destId, req.DestName) |
|
|
|
|
if srcId == "" || srcUid == "" { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
writeUnitString := strings.ReplaceAll(gjson.MustEncodeString(v1), srcId, fmt.Sprint(destId)) |
|
|
|
|
writeStoreString := strings.ReplaceAll(gjson.MustEncodeString(v2), srcId, fmt.Sprint(destId)) |
|
|
|
|
writeUnitString = internal.ReplaceLastOccurrence(writeUnitString, srcUid, fmt.Sprint(req.DestName)) |
|
|
|
|
if err = os.WriteFile(userDir, []byte(writeUnitString), 0666); err != nil { |
|
|
|
|
log.Println(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err = os.WriteFile(userStoreDir, []byte(writeStoreString), 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) { |
|
|
|
|
name := "mongoimport" |
|
|
|
|
args := []string{} |
|
|
|
|
args1 := []string{} |
|
|
|
|
args = append(args, fmt.Sprintf("--uri=\"%s\"", mongoConfig.Link1)) |
|
|
|
|
args = append(args, fmt.Sprintf("--authenticationDatabase=%s", mongoConfig.Auth)) |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--uri=\"%s\"", mongoConfig.Link1)) |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--authenticationDatabase=%s", mongoConfig.Auth)) |
|
|
|
|
args = append(args, "--collection=Unit") |
|
|
|
|
args = append(args, fmt.Sprintf("--file=\"%s\"", userDir)) |
|
|
|
|
args = append(args, "--type=json") |
|
|
|
|
args = append(args, "--mode=upsert") |
|
|
|
|
args1 = append(args1, "--collection=StoreComponent") |
|
|
|
|
args1 = append(args1, fmt.Sprintf("--file=\"%s\"", userStoreDir)) |
|
|
|
|
args1 = append(args1, "--type=json") |
|
|
|
|
args1 = append(args1, "--mode=upsert") |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = utils.CmdCommand(ctx, name, args...) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("cmd.Run() failed with %s\n", err) |
|
|
|
|
return |
|
|
|
|
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{}) |
|
|
|
|
} |
|
|
|
|
err = utils.CmdCommand(ctx, name, args1...) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("cmd.Run() failed with %s\n", err) |
|
|
|
|
} 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 |
|
|
|
|
} |
|
|
|
|
err = os.Remove(userDir) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("os.Remove failed with %s\n", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
userDecorationDir := "./download/DecorationManagerComponent" + fmt.Sprint(req.DestName) + fmt.Sprint(time.Now().Unix()) + ".json" |
|
|
|
|
srcDecorationDir := "./download/" + req.DecorationFilename |
|
|
|
|
writeDecorationByte, err1 := os.ReadFile(srcDecorationDir) |
|
|
|
|
if err1 != nil { |
|
|
|
|
return res, err1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var v4 map[string]interface{} |
|
|
|
|
if strings.HasPrefix(string(writeDecorationByte), "[") { |
|
|
|
|
user := []interface{}{} |
|
|
|
|
json.Unmarshal(writeDecorationByte, &user) |
|
|
|
|
if len(user) != 0 { |
|
|
|
|
v4 = user[0].(map[string]interface{}) |
|
|
|
|
} |
|
|
|
|
err = os.Remove(userStoreDir) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("os.Remove failed with %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
json.Unmarshal(writeDecorationByte, &v4) |
|
|
|
|
} |
|
|
|
|
if len(v4) != 0 { |
|
|
|
|
writeDecorationString := strings.ReplaceAll(gjson.MustEncodeString(v4), srcId, fmt.Sprint(destId)) |
|
|
|
|
if err = os.WriteFile(userDecorationDir, []byte(writeDecorationString), 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", req.DestName) |
|
|
|
|
//fmt.Println("UpdateUnit GetRoleDelta", gjson.MustEncodeString(req))
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func mongoimportCommand(ctx context.Context, collection, dir string, mongoConfig internal.MongoType) { |
|
|
|
|
args := []string{} |
|
|
|
|
args = append(args, fmt.Sprintf("--uri=\"%s\"", mongoConfig.Link1)) |
|
|
|
|
args = append(args, fmt.Sprintf("--authenticationDatabase=%s", mongoConfig.Auth)) |
|
|
|
|
args = append(args, fmt.Sprintf("--collection=%s", collection)) |
|
|
|
|
args = append(args, fmt.Sprintf("--file=\"%s\"", dir)) |
|
|
|
|
args = append(args, "--type=json") |
|
|
|
|
args = append(args, "--mode=upsert") |
|
|
|
|
|
|
|
|
|
err := utils.CmdCommand(ctx, "mongoimport", args...) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("%s cmd.Run() failed with %s\n", dir, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err = os.Remove(dir) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("%s os.Remove failed with %s\n", dir, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (ga *gameManageImpl) DelAccount(ctx context.Context, req *game.DelAccountReq) (res *game.DelAccountRes, err error) { |
|
|
|
|
user := service.Context().GetLoginUser(ctx) |
|
|
|
|
fulluser, err1 := service.User().GetUserByUsername(ctx, user.UserName) |
|
|
|
|