liliang 7 ماه پیش
والد
کامیت
98b3ab5cb8
3فایلهای تغییر یافته به همراه21 افزوده شده و 47 حذف شده
  1. 1 1
      const/const.go
  2. 15 41
      game/game_cluster/internal/mdb/component.go
  3. 5 5
      game/game_cluster/nodes/game/module/player/actor_player.go

+ 1 - 1
const/const.go

@@ -5,7 +5,7 @@ import (
 )
 
 const (
-	version = "1.0.21"
+	version = "1.0.31"
 )
 
 var logo = `

+ 15 - 41
game/game_cluster/internal/mdb/component.go

@@ -10,8 +10,6 @@ import (
 	cprofile "github.com/mhaya/profile"
 	"go.mongodb.org/mongo-driver/mongo"
 	"strings"
-	"time"
-	"strings"
 )
 
 type ActorDB struct {
@@ -39,60 +37,36 @@ func (p *ActorDB) OnInit() {
 	dbID := p.App().Settings().GetConfig("db_id_list").GetString("game_db_id")
 	MDB = mongo.GetDb(dbID)
 	if MDB == nil {
-		clog.Panicf("game_db_id not found")
+		clog.Panic("game_db_id not found")
 	}
+
 	redisConfig := cprofile.GetConfig("redis")
-	addr := strings.Split(redisConfig.GetString("address"), ",")
-	isTls := redisConfig.GetInt("tls", 0)
-	if isTls == 1 {
+	tlsEnable := redisConfig.GetInt("tls")
+
+	if tlsEnable == 1 {
 		tlsConfig := &tls.Config{
 			MinVersion:               tls.VersionTLS12,
 			PreferServerCipherSuites: true,
 		}
-		/*	RDB = redis.NewUniversalClient(&redis.UniversalOptions{
-			Addrs:     []string{redisConfig.GetString("address")},
+
+		RDB = redis.NewUniversalClient(&redis.UniversalOptions{
+			Addrs:     strings.Split(redisConfig.GetString("address"), ","),
 			Password:  redisConfig.GetString("password"),
 			DB:        redisConfig.GetInt("db"),
 			TLSConfig: tlsConfig,
-		})*/
-
-		clusterOptions := &redis.ClusterOptions{
-			Addrs:        addr,
-			Password:     "",   // 如果启用了身份验证,请提供密码
-			PoolSize:     1000, // 每个节点的最大连接数
-			DialTimeout:  10 * time.Second,
-			ReadTimeout:  30 * time.Second,
-			WriteTimeout: 30 * time.Second,
-			TLSConfig:    tlsConfig,
-		}
-
-		// 创建集群客户端
-		rdb := redis.NewClusterClient(clusterOptions)
-		// 测试连接
-		ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
-		defer cancel()
-
-		pong, err := rdb.Ping(ctx).Result()
-		if err != nil {
-			clog.Panicf("无法连接到Redis集群: %v ,param:%v", err, addr)
-		}
-		clog.Warnf("连接到Redis集群: %v,param:%v", pong, addr)
-		RDB = rdb
+		})
 	} else {
 		RDB = redis.NewUniversalClient(&redis.UniversalOptions{
-			Addrs:    addr,
+			Addrs:    strings.Split(redisConfig.GetString("address"), ","),
 			Password: redisConfig.GetString("password"),
 			DB:       redisConfig.GetInt("db"),
 		})
-		// 测试连接
-		ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
-		defer cancel()
+	}
 
-		pong, err := RDB.Ping(ctx).Result()
-		if err != nil {
-			clog.Panicf("无法连接到Redis: %v ,param:%v", err, addr)
-		}
-		clog.Warnf("连接到Redis: %v,param:%v", pong, addr)
+	clog.Debug("redis address :" + redisConfig.GetString("address"))
+	err := RDB.Set(context.Background(), "test", 0, 0).Err()
+	if err != nil {
+		clog.Errorf("redis client error: %v", err)
 	}
 
 	if p.App().NodeId() == "m-center" {

+ 5 - 5
game/game_cluster/nodes/game/module/player/actor_player.go

@@ -100,19 +100,19 @@ func (p *actorPlayer) OnInit() {
 	p.Remote().Register("unitTest", p.unitTest)
 
 	//p.Timer().Add(10*time.Second, p.refreshRoll)
-	p.Timer().Add(60*time.Second, p.SetRewardToDB)
-	p.Timer().Add(1*time.Minute, p.setRedis)
-	p.Timer().Add(60*time.Second, p.setDb)
+	//p.Timer().Add(60*time.Second, p.SetRewardToDB)
+	//p.Timer().Add(1*time.Minute, p.setRedis)
+	//p.Timer().Add(60*time.Second, p.setDb)
 	//p.Timer().Add(30*time.Second, p.setInviteReward)
 
 	//p.Timer().Add(1*time.Second, p.addRoll)
 
-	p.Timer().Add(30*time.Second, p.playerSessionClose)
+	p.Timer().Add(30*time.Minute, p.playerSessionClose)
 
 	//p.Timer().Add(1*time.Minute, p.upatePlayerLevelStat)
 
 	//在线用户定时刷新
-	p.Timer().Add(1*time.Minute, p.initDaily)
+	//p.Timer().Add(1*time.Minute, p.initDaily)
 	p.Timer().Add(10*time.Second, p.setRedisAll)
 
 	//p.Timer().Add(5*time.Second, p.initHourly)