From b65955742289f513b1ba5de1188fe8aa80015178 Mon Sep 17 00:00:00 2001 From: yangduo Date: Tue, 27 Aug 2024 14:11:23 +0800 Subject: [PATCH 01/13] init gameswitch --- server/marketserver/service/gameswitch.go | 7 +++++++ server/marketserver/service/servicemgr.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/server/marketserver/service/gameswitch.go b/server/marketserver/service/gameswitch.go index 0281ba4c..1b87b368 100644 --- a/server/marketserver/service/gameswitch.go +++ b/server/marketserver/service/gameswitch.go @@ -11,6 +11,13 @@ type gameSwitch struct { time int64 } +func (this *gameSwitch) init() { + this.GetSwitchList() +} + +func (this *gameSwitch) unInit() { +} + func (this *gameSwitch) GetSwitchList() map[string]int32 { now := f5.GetApp().GetRealSeconds() if now > this.time+30 { diff --git a/server/marketserver/service/servicemgr.go b/server/marketserver/service/servicemgr.go index 4e9d8baa..eb9394ae 100644 --- a/server/marketserver/service/servicemgr.go +++ b/server/marketserver/service/servicemgr.go @@ -6,9 +6,11 @@ type serviceMgr struct { func (this *serviceMgr) Init() { Contribution.init() User.init() + GameSwitches.init() } func (this *serviceMgr) UnInit() { Contribution.unInit() User.unInit() + GameSwitches.unInit() } From eda06c9952864d3dab15858580cba0af86637d37 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 27 Aug 2024 18:04:13 +0800 Subject: [PATCH 02/13] 1 --- server/marketserver/service/user.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/marketserver/service/user.go b/server/marketserver/service/user.go index 4992acb7..e4eec340 100644 --- a/server/marketserver/service/user.go +++ b/server/marketserver/service/user.go @@ -1,9 +1,9 @@ package service import ( - "f5" - "main/constant" - "q5" + //"f5" + //"main/constant" + //"q5" ) //"strings" @@ -18,6 +18,8 @@ func (this *user) unInit() { } func (this *user) InBlackList(userIdentity string) (bool, error) { + return false, nil + /* if userIdentity == "" { return true, nil } @@ -37,4 +39,5 @@ func (this *user) InBlackList(userIdentity string) (bool, error) { blocked = ds.Next() && q5.SafeToInt32(ds.GetByName("blocked")) != 0 && q5.SafeToInt32(ds.GetByName("deleted")) == 0 }) return blocked, queryerr + */ } From d3cd8f5f887219a16ba4fd4347ab617fe0248f98 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 28 Aug 2024 13:32:39 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=91=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/confdb.sql | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/database/confdb.sql b/database/confdb.sql index f9941580..2d29ba0d 100644 --- a/database/confdb.sql +++ b/database/confdb.sql @@ -135,6 +135,42 @@ CREATE TABLE `t_super_whitelist` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_whitelist` +-- + +DROP TABLE IF EXISTS `t_whitelist`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_whitelist` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `user_identity` varchar(60) NOT NULL COMMENT 'account_id or account_address or email', + `enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `user_identity` (`user_identity`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `t_blacklist` +-- + +DROP TABLE IF EXISTS `t_blacklist`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_blacklist` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `user_identity` varchar(60) NOT NULL COMMENT 'account_id or account_address or email', + `enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `user_identity` (`user_identity`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; From f3e21652694e2370da4958449825cf4212e9daec Mon Sep 17 00:00:00 2001 From: yangduo Date: Wed, 28 Aug 2024 14:35:43 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=BB=91=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminserver/api/v1/system/block_player.go | 156 +++++++------- server/adminserver/api/v1/system/whitelist.go | 196 ++++++++---------- .../adminserver/model/system/block_player.go | 7 +- server/adminserver/model/system/whitelist.go | 10 +- .../adminserver/router/system/block_player.go | 2 +- server/adminserver/router/system/whitelist.go | 4 +- 6 files changed, 171 insertions(+), 204 deletions(-) diff --git a/server/adminserver/api/v1/system/block_player.go b/server/adminserver/api/v1/system/block_player.go index f1b1d9cd..465a44c8 100644 --- a/server/adminserver/api/v1/system/block_player.go +++ b/server/adminserver/api/v1/system/block_player.go @@ -30,10 +30,10 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) { constant.CONF_DB, q5.ToInt32(req.PageDto.PageSize), q5.ToInt32(req.PageDto.Page), - "SELECT * FROM t_blockplayer WHERE 1=1 AND deleted = 0", + "SELECT * FROM t_blacklist WHERE 1=1", []string{}, f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), - " ORDER BY account_id ", + " ORDER BY user_identity ", func(err error, pg *f5.Pagination) { if err != nil { c.JSON(http.StatusOK, gin.H{ @@ -45,8 +45,8 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) { for pg.Rows.Next() { p := new(system.BlockPlayer) - p.Blocked = q5.SafeToInt32(pg.Rows.GetByName("blocked")) - p.Account = pg.Rows.GetByName("account_id") + p.Enable = q5.SafeToInt32(pg.Rows.GetByName("enable")) + p.Identity = pg.Rows.GetByName("user_identity") p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime")) p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime")) q5.AppendSlice(&result, p) @@ -64,7 +64,8 @@ func (bpa *BlockPlayerApi) List(c *gin.Context) { func (bpa *BlockPlayerApi) Add(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -74,34 +75,20 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) { return } - info := new(system.BlockPlayer) - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - var count int64 = 0 - db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blockplayer").Where("account_id =?", req.Account) + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_blacklist").Where("user_identity =?", req.Identity) if err := db.Count(&count).Error; err == nil && count > 0 { - db.Take(info) - if info.Deleted == 0 { - c.JSON(http.StatusOK, gin.H{ - "code": 1, - "message": "数据存在", - }) - } else { - info.Blocked = 1 - info.Deleted = 0 - info.ModifyTime = nowDaySeconds - db.Save(info) - - c.JSON(http.StatusOK, gin.H{ - "code": 0, - "message": "添加成功", - }) - } + c.JSON(http.StatusOK, gin.H{ + "code": 1, + "message": "数据存在", + }) return } - info.Account = req.Account - info.Blocked = 1 + info := new(system.BlockPlayer) + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + info.Identity = req.Identity + info.Enable = req.Enable info.CreateTime = nowDaySeconds info.ModifyTime = nowDaySeconds if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil { @@ -119,8 +106,8 @@ func (bpa *BlockPlayerApi) Add(c *gin.Context) { func (bpa *BlockPlayerApi) Edit(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` - Blocked int32 `json:"blocked"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -132,7 +119,7 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) { blockplayer := new(system.BlockPlayer) db := f5.GetApp().GetOrmDb(constant.CONF_DB) - if err := db.Take(blockplayer, "account_id = ? AND deleted = 0", req.Account).Error; err != nil { + if err := db.Take(blockplayer, "user_identity = ?", req.Identity).Error; err != nil { if !f5.IsOrmErrRecordNotFound(err) { c.JSON(http.StatusOK, gin.H{ "code": 500, @@ -148,15 +135,16 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) { } } - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - blockplayer.Blocked = req.Blocked - blockplayer.ModifyTime = nowDaySeconds - if err := db.Where("account_id = ?", req.Account).Save(blockplayer).Error; err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return + if blockplayer.Enable != req.Enable { + blockplayer.Enable = req.Enable + blockplayer.ModifyTime = int32(f5.GetApp().GetRealSeconds()) + if err := db.Where("user_identity = ?", req.Identity).Save(blockplayer).Error; err != nil { + c.JSON(http.StatusOK, gin.H{ + "code": 500, + "message": "sever internal error:" + err.Error(), + }) + return + } } c.JSON(http.StatusOK, gin.H{ "code": 0, @@ -165,49 +153,49 @@ func (bpa *BlockPlayerApi) Edit(c *gin.Context) { } func (bpa *BlockPlayerApi) Del(c *gin.Context) { - req := struct { - Account string `binding:"required" json:"account_id"` - }{} - if err := c.ShouldBindJSON(&req); err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 1, - "message": err.Error(), - }) - return - } + // req := struct { + // Identity string `binding:"required" json:"user_identity"` + // }{} + // if err := c.ShouldBindJSON(&req); err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 1, + // "message": err.Error(), + // }) + // return + // } - blockplayer := new(system.BlockPlayer) - db := f5.GetApp().GetOrmDb(constant.CONF_DB) - if err := db.Take(blockplayer, "account_id = ? AND deleted = 0", req.Account).Error; err != nil { - if !f5.IsOrmErrRecordNotFound(err) { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return - } else { - c.JSON(http.StatusOK, gin.H{ - "code": 2, - "message": "无法查到记录", - }) - return - } - } else { - } - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - blockplayer.Deleted = 1 - blockplayer.ModifyTime = nowDaySeconds - if err := db.Where("account_id = ?", req.Account).Save(blockplayer).Error; err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return - } - c.JSON(http.StatusOK, gin.H{ - "code": 0, - "message": "", - }) + // blockplayer := new(system.BlockPlayer) + // db := f5.GetApp().GetOrmDb(constant.CONF_DB) + // if err := db.Take(blockplayer, "user_identity = ?", req.Identity).Error; err != nil { + // if !f5.IsOrmErrRecordNotFound(err) { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } else { + // c.JSON(http.StatusOK, gin.H{ + // "code": 2, + // "message": "无法查到记录", + // }) + // return + // } + // } else { + // } + // nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + // blockplayer.Deleted = 1 + // blockplayer.ModifyTime = nowDaySeconds + // if err := db.Where("user_identity = ?", req.Identity).Save(blockplayer).Error; err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } + // c.JSON(http.StatusOK, gin.H{ + // "code": 0, + // "message": "", + // }) } func (bpa *BlockPlayerApi) UploadExcel(c *gin.Context) { @@ -242,8 +230,8 @@ func (bpa *BlockPlayerApi) UploadExcel(c *gin.Context) { continue } member := new(system.BlockPlayer) - member.Account = row[0] - member.Blocked = 1 + member.Identity = row[0] + member.Enable = 1 member.CreateTime = nowDaySeconds member.ModifyTime = nowDaySeconds blockplayers = append(blockplayers, member) diff --git a/server/adminserver/api/v1/system/whitelist.go b/server/adminserver/api/v1/system/whitelist.go index b45fa2f1..a0c15e33 100644 --- a/server/adminserver/api/v1/system/whitelist.go +++ b/server/adminserver/api/v1/system/whitelist.go @@ -16,7 +16,6 @@ type WhiteListApi struct { func (bpa *WhiteListApi) List(c *gin.Context) { req := struct { - Type string `json:"type"` PageDto system.PageDto `json:"page_dto"` }{} if err := c.ShouldBindJSON(&req); err != nil { @@ -26,12 +25,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) { }) return } - sql := "SELECT * FROM t_whitelist WHERE 1=1 AND deleted = 0" - params := []string{} - if req.Type != "" { - sql += " AND type = ?" - params = append(params, req.Type) - } + sql := "SELECT * FROM t_whitelist WHERE 1=1" + params := []string{} result := []*system.WhiteListItem{} f5.GetGoStyleDb().PageQuery( constant.CONF_DB, @@ -40,7 +35,7 @@ func (bpa *WhiteListApi) List(c *gin.Context) { sql, params, f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), - " ORDER BY account_id ", + " ORDER BY user_identity ", func(err error, pg *f5.Pagination) { if err != nil { c.JSON(http.StatusOK, gin.H{ @@ -52,8 +47,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) { for pg.Rows.Next() { p := new(system.WhiteListItem) - p.Type = pg.Rows.GetByName("type") - p.Account = pg.Rows.GetByName("account_id") + p.Enable = q5.SafeToInt32(pg.Rows.GetByName("enable")) + p.Identity = pg.Rows.GetByName("user_identity") p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime")) p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime")) q5.AppendSlice(&result, p) @@ -71,8 +66,8 @@ func (bpa *WhiteListApi) List(c *gin.Context) { func (bpa *WhiteListApi) Add(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` - Type string `binding:"required" json:"type"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -86,29 +81,17 @@ func (bpa *WhiteListApi) Add(c *gin.Context) { nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) var count int64 = 0 - db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_whitelist").Where("account_id = ? AND type = ?", req.Account, req.Type) + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table("t_whitelist").Where("user_identity = ?", req.Identity) if err := db.Count(&count).Error; err == nil && count > 0 { - db.Take(info) - if info.Deleted == 0 { - c.JSON(http.StatusOK, gin.H{ - "code": 1, - "message": "数据存在", - }) - } else { - info.Deleted = 0 - info.ModifyTime = nowDaySeconds - db.Save(info) - - c.JSON(http.StatusOK, gin.H{ - "code": 0, - "message": "添加成功", - }) - } + c.JSON(http.StatusOK, gin.H{ + "code": 1, + "message": "数据存在", + }) return } - info.Account = req.Account - info.Type = req.Type + info.Identity = req.Identity + info.Enable = req.Enable info.CreateTime = nowDaySeconds info.ModifyTime = nowDaySeconds if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil { @@ -125,56 +108,9 @@ func (bpa *WhiteListApi) Add(c *gin.Context) { } func (bpa *WhiteListApi) Edit(c *gin.Context) { - // req := struct { - // Account string `binding:"required" json:"account_id"` - // Type string `json:"type"` - // }{} - // if err := c.ShouldBindJSON(&req); err != nil { - // c.JSON(http.StatusOK, gin.H{ - // "code": 1, - // "message": err.Error(), - // }) - // return - // } - - // whitelistitem := new(system.WhiteListItem) - // db := f5.GetApp().GetOrmDb(constant.CONF_DB) - // if err := db.Take(whitelistitem, "account_id =?", req.Account).Error; err != nil { - // if !f5.IsOrmErrRecordNotFound(err) { - // c.JSON(http.StatusOK, gin.H{ - // "code": 500, - // "message": "sever internal error:" + err.Error(), - // }) - // return - // } else { - // c.JSON(http.StatusOK, gin.H{ - // "code": 2, - // "message": "无法查到记录", - // }) - // return - // } - // } - - // nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - // whiteListItem.Blocked = req.Blocked - // whiteListItem.ModifyTime = nowDaySeconds - // if err := db.Where("account_id = ?", req.Account).Save(whiteListItem).Error; err != nil { - // c.JSON(http.StatusOK, gin.H{ - // "code": 500, - // "message": "sever internal error:" + err.Error(), - // }) - // return - // } - // c.JSON(http.StatusOK, gin.H{ - // "code": 0, - // "message": "", - // }) -} - -func (bpa *WhiteListApi) Del(c *gin.Context) { req := struct { - Account string `binding:"required" json:"account_id"` - Type string `json:"type"` + Identity string `binding:"required" json:"user_identity"` + Enable int32 `json:"enable"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -185,12 +121,8 @@ func (bpa *WhiteListApi) Del(c *gin.Context) { } whiteListItem := new(system.WhiteListItem) - db := f5.GetApp().GetOrmDb(constant.CONF_DB).Where("account_id = ?", req.Account) - if req.Type != "" { - db = db.Where("type = ?", req.Type) - } - - if err := db.Take(whiteListItem).Error; err != nil { + db := f5.GetApp().GetOrmDb(constant.CONF_DB) + if err := db.Take(whiteListItem, "user_identity =?", req.Identity).Error; err != nil { if !f5.IsOrmErrRecordNotFound(err) { c.JSON(http.StatusOK, gin.H{ "code": 500, @@ -204,33 +136,86 @@ func (bpa *WhiteListApi) Del(c *gin.Context) { }) return } - } else { - if whiteListItem.Deleted == 1 { - c.JSON(http.StatusOK, gin.H{ - "code": 2, - "message": "无法查到记录", - }) + } + if whiteListItem.Enable != req.Enable { + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + whiteListItem.Enable = req.Enable + whiteListItem.ModifyTime = nowDaySeconds + if err := db.Where("user_identity = ?", req.Identity).Save(whiteListItem).Error; err != nil { + c.JSON(http.StatusOK, gin.H{ + "code": 500, + "message": "sever internal error:" + err.Error(), + }) return } } - nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) - whiteListItem.Deleted = 1 - whiteListItem.ModifyTime = nowDaySeconds - - if err := db.Save(whiteListItem).Error; err != nil { - c.JSON(http.StatusOK, gin.H{ - "code": 500, - "message": "sever internal error:" + err.Error(), - }) - return - } c.JSON(http.StatusOK, gin.H{ "code": 0, "message": "", }) } +func (bpa *WhiteListApi) Del(c *gin.Context) { + // req := struct { + // Account string `binding:"required" json:"user_identity"` + // Type string `json:"type"` + // }{} + // if err := c.ShouldBindJSON(&req); err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 1, + // "message": err.Error(), + // }) + // return + // } + + // whiteListItem := new(system.WhiteListItem) + // db := f5.GetApp().GetOrmDb(constant.CONF_DB).Where("user_identity = ?", req.Account) + // if req.Type != "" { + // db = db.Where("type = ?", req.Type) + // } + + // if err := db.Take(whiteListItem).Error; err != nil { + // if !f5.IsOrmErrRecordNotFound(err) { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } else { + // c.JSON(http.StatusOK, gin.H{ + // "code": 2, + // "message": "无法查到记录", + // }) + // return + // } + // } else { + // if whiteListItem.Deleted == 1 { + // c.JSON(http.StatusOK, gin.H{ + // "code": 2, + // "message": "无法查到记录", + // }) + + // return + // } + // } + // nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + // whiteListItem.Deleted = 1 + // whiteListItem.ModifyTime = nowDaySeconds + + // if err := db.Save(whiteListItem).Error; err != nil { + // c.JSON(http.StatusOK, gin.H{ + // "code": 500, + // "message": "sever internal error:" + err.Error(), + // }) + // return + // } + // c.JSON(http.StatusOK, gin.H{ + // "code": 0, + // "message": "", + // }) +} + func (bpa *WhiteListApi) UploadExcel(c *gin.Context) { file, _, err := c.Request.FormFile("file") if err != nil { @@ -263,9 +248,8 @@ func (bpa *WhiteListApi) UploadExcel(c *gin.Context) { continue } member := new(system.WhiteListItem) - member.Account = row[0] - member.Type = row[1] - member.Deleted = 0 + member.Identity = row[0] + member.Enable = 1 member.CreateTime = nowDaySeconds member.ModifyTime = nowDaySeconds whitelist = append(whitelist, member) diff --git a/server/adminserver/model/system/block_player.go b/server/adminserver/model/system/block_player.go index 4b3b5f1e..e3af4ed8 100644 --- a/server/adminserver/model/system/block_player.go +++ b/server/adminserver/model/system/block_player.go @@ -1,13 +1,12 @@ package system type BlockPlayer struct { - Account string `gorm:"column:account_id" json:"account_id"` - Blocked int32 `gorm:"column:blocked" json:"blocked"` - Deleted int32 `gorm:"column:deleted" json:"deleted"` + Identity string `gorm:"column:user_identity" json:"user_identity"` + Enable int32 `gorm:"column:enable" json:"enable"` CreateTime int32 `gorm:"column:createtime" json:"createtime"` ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` } func (BlockPlayer) TableName() string { - return "t_blockplayer" + return "t_blacklist" } diff --git a/server/adminserver/model/system/whitelist.go b/server/adminserver/model/system/whitelist.go index fb528b1e..7038942b 100644 --- a/server/adminserver/model/system/whitelist.go +++ b/server/adminserver/model/system/whitelist.go @@ -1,9 +1,8 @@ package system type WhiteListItem struct { - Account string `gorm:"column:account_id" json:"account_id"` - Type string `gorm:"column:type" json:"type"` - Deleted int32 `gorm:"column:deleted" json:"deleted"` + Identity string `gorm:"column:user_identity" json:"user_identity"` + Enable int32 `gorm:"column:enable" json:"enable"` CreateTime int32 `gorm:"column:createtime" json:"createtime"` ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` } @@ -13,10 +12,7 @@ func (WhiteListItem) TableName() string { } type SuperWhiteListItem struct { - Identity string `gorm:"column:user_identity" json:"user_identity"` - Enable int32 `gorm:"column:enable" json:"enable"` - CreateTime int32 `gorm:"column:createtime" json:"createtime"` - ModifyTime int32 `gorm:"column:modifytime" json:"modifytime"` + WhiteListItem } func (SuperWhiteListItem) TableName() string { diff --git a/server/adminserver/router/system/block_player.go b/server/adminserver/router/system/block_player.go index e38cb9bf..74b428e2 100644 --- a/server/adminserver/router/system/block_player.go +++ b/server/adminserver/router/system/block_player.go @@ -16,7 +16,7 @@ func (this *BlockPlayerRoute) InitBlockPlayerRouter(priRouter *gin.RouterGroup) { group.POST("add", middleware.Permission("api/v1/block_player/add", api.Add)) group.POST("edit", middleware.Permission("api/v1/block_player/edit", api.Edit)) - group.POST("del", middleware.Permission("api/v1/block_player/del", api.Del)) + // group.POST("del", middleware.Permission("api/v1/block_player/del", api.Del)) group.POST("list", middleware.Permission("api/v1/block_player/list", api.List)) group.POST("uploadExcel", middleware.Permission("api/v1/block_player/uploadExcel", api.UploadExcel)) } diff --git a/server/adminserver/router/system/whitelist.go b/server/adminserver/router/system/whitelist.go index 731008f3..64e7c99e 100644 --- a/server/adminserver/router/system/whitelist.go +++ b/server/adminserver/router/system/whitelist.go @@ -15,8 +15,8 @@ func (this *WhiteListRoute) InitWhiteListRouter(priRouter *gin.RouterGroup) { api := v1.ApiGroupApp.SystemApiGroup.WhiteListApi { group.POST("add", middleware.Permission("api/v1/white_list/add", api.Add)) - //group.POST("edit", middleware.Permission("api/v1/white_list/edit", api.Edit)) - group.POST("del", middleware.Permission("api/v1/white_list/del", api.Del)) + group.POST("edit", middleware.Permission("api/v1/white_list/edit", api.Edit)) + // group.POST("del", middleware.Permission("api/v1/white_list/del", api.Del)) group.POST("list", middleware.Permission("api/v1/white_list/list", api.List)) group.POST("uploadExcel", middleware.Permission("api/v1/white_list/uploadExcel", api.UploadExcel)) } From c5f61f32877828d0b1647b866c249382495928dd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Aug 2024 11:17:48 +0800 Subject: [PATCH 05/13] 1 --- server/marketserver/api/v1/recharge/recharge.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/marketserver/api/v1/recharge/recharge.go b/server/marketserver/api/v1/recharge/recharge.go index 17ec91ff..0eefbc1a 100644 --- a/server/marketserver/api/v1/recharge/recharge.go +++ b/server/marketserver/api/v1/recharge/recharge.go @@ -239,6 +239,14 @@ func (this *RechargeApi) internalBuy(c *gin.Context, f5.RspErr(c, 500, "server internal error") return } + f5.GetSysLog().Info("recharge net_id:%d currency_name:%s decimal:%d srcPrice:%d bnPrice:%s calls.len:%d jsonRsp:%s", + netId, + currencyMeta.GetCurrencyName(), + currencyMeta.GetCurrencyDecimal(), + srcPrice, + bnPrice.String(), + len(jsonRspObj.Calls), + q5.EncodeJson(&jsonRspObj)); c.JSON(200, jsonRspObj) }) } From cc25d722b077e54d4d8a5af5bbcb0b9859754997 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Aug 2024 14:05:58 +0800 Subject: [PATCH 06/13] 1 --- bin/adminserver/config/game_switch.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/adminserver/config/game_switch.json b/bin/adminserver/config/game_switch.json index 7f573b9b..9cd3b08d 100644 --- a/bin/adminserver/config/game_switch.json +++ b/bin/adminserver/config/game_switch.json @@ -99,6 +99,10 @@ "switch_name": "ui.contribution.show", "switch_desc": "25-贡献点是否显示" }, + { + "switch_name": "ui.activationCode", + "switch_desc": "26-激活码是否显示" + }, { "switch_name": "only.allowed.superWhiteList", "switch_desc": "100-只允许至尊白名单用户登录登录" From 481529614e32ee4e18261787730d09d80376167e Mon Sep 17 00:00:00 2001 From: yangduo Date: Thu, 29 Aug 2024 15:05:42 +0800 Subject: [PATCH 07/13] active code --- .../adminserver/api/v1/system/activecode.go | 180 ++++++++++++++++++ server/adminserver/api/v1/system/enter.go | 1 + server/adminserver/model/system/activecode.go | 12 ++ server/adminserver/router/routermgr.go | 1 + .../adminserver/router/system/activecode.go | 21 ++ server/adminserver/router/system/enter.go | 1 + 6 files changed, 216 insertions(+) create mode 100644 server/adminserver/api/v1/system/activecode.go create mode 100644 server/adminserver/model/system/activecode.go create mode 100644 server/adminserver/router/system/activecode.go diff --git a/server/adminserver/api/v1/system/activecode.go b/server/adminserver/api/v1/system/activecode.go new file mode 100644 index 00000000..bef693aa --- /dev/null +++ b/server/adminserver/api/v1/system/activecode.go @@ -0,0 +1,180 @@ +package system + +import ( + "f5" + "fmt" + "main/constant" + "main/model/system" + "net/http" + "q5" + "strings" + + "math/rand" + + "github.com/gin-gonic/gin" +) + +type ActiveCodeApi struct { +} + +func (aca *ActiveCodeApi) GenCode(c *gin.Context) { + var batchid int32 = 0 + var maxbatchid int32 = 0 + db := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_activation_code").Select("max(batch_id)") + err := db.Error + if err != nil { + if !f5.IsOrmErrRecordNotFound(err) { + f5.RspErr2(c, 1, err.Error()) + return + } + } else { + var count int64 = 0 + if db.Count(&count); count > 0 { + db.Scan(&maxbatchid) + } + } + + if maxbatchid >= 0xFFF { + f5.RspErr2(c, 1, "batchid overflow") + return + } + + batchid = maxbatchid + 1 + + count := q5.SafeToInt32(c.DefaultQuery("count", "1")) + if count < 1 { + count = 1 + } + if count > 5000 { + count = 5000 + } + + tryCount := 0 + postfix := fmt.Sprintf("%03x", batchid) + codelist := map[string]int{} + nowsecs := int32(f5.GetApp().GetRealSeconds()) + batchcodeinfo := []*system.ActiveCode{} + for i := 0; i < int(count); { + if tryCount > 10000*10 { + f5.RspErr2(c, 1, "internal error") + return + } + + code := aca.genCode(7) + postfix + _, exist := codelist[code] + if exist { + tryCount++ + continue + } + + codelist[code] = 1 + i++ + p := new(system.ActiveCode) + p.Batch_id = batchid + p.Code = code + p.CreateTime = nowsecs + p.ModifyTime = nowsecs + batchcodeinfo = append(batchcodeinfo, p) + } + + err = f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_activation_code").Create(batchcodeinfo).Error + if err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "成功生成", + "batchid": batchid, + }) +} + +const strpol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz" + +func (this *ActiveCodeApi) genCode(n int) string { + var sb strings.Builder + k := len(strpol) + + for i := 0; i < n; i++ { + c := strpol[rand.Intn(k)] + sb.WriteByte(c) + } + + return sb.String() +} + +func (this *ActiveCodeApi) List(c *gin.Context) { + req := struct { + BatchId int32 `json:"batch_id"` + PageDto system.PageDto `json:"page_dto"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + sql := fmt.Sprintf("SELECT * FROM t_activation_code WHERE 1=1 AND batch_id = %d", req.BatchId) + params := []string{} + result := []*system.ActiveCode{} + f5.GetGoStyleDb().PageQuery( + constant.ACCOUNT_DB, + q5.ToInt32(req.PageDto.PageSize), + q5.ToInt32(req.PageDto.Page), + sql, + params, + f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), + "", + func(err error, pg *f5.Pagination) { + if err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + f5.UnmarshalModelList(pg.Rows, &result) + + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "获取成功", + "data": result, + "total": pg.Total, + "total_page": pg.TotalPages, + "cur_page": pg.CurrentPage, + }) + }) +} + +func (this *ActiveCodeApi) DownloadFile(c *gin.Context) { + batchid := q5.SafeToInt32(c.DefaultQuery("batchid", "")) + if batchid < 1 { + f5.RspErr2(c, 1, "batchid error") + return + } + + sql := fmt.Sprintf("SELECT * FROM t_activation_code WHERE 1=1 AND batch_id = %d", batchid) + f5.GetGoStyleDb().RawQuery( + constant.ACCOUNT_DB, + sql, + []string{}, + func(err error, ds *f5.DataSet) { + if err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + data := []struct { + BatchId int32 `json:"batch_id"` + Code string `json:"activation_code"` + }{} + for ds.Next() { + p := q5.NewSliceElement(&data) + p.BatchId = q5.SafeToInt32(ds.GetByName("batch_id")) + p.Code = ds.GetByName("activation_code") + } + + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "", + "data": data, + }) + }) +} diff --git a/server/adminserver/api/v1/system/enter.go b/server/adminserver/api/v1/system/enter.go index a3781d1e..110464ab 100644 --- a/server/adminserver/api/v1/system/enter.go +++ b/server/adminserver/api/v1/system/enter.go @@ -13,4 +13,5 @@ type ApiGroup struct { GameSwitchApi BlockPlayerApi WhiteListApi + ActiveCodeApi } diff --git a/server/adminserver/model/system/activecode.go b/server/adminserver/model/system/activecode.go new file mode 100644 index 00000000..59105fbc --- /dev/null +++ b/server/adminserver/model/system/activecode.go @@ -0,0 +1,12 @@ +package system + +type ActiveCode struct { + Code string `gorm:"column:activation_code" json:"activation_code"` + Batch_id int32 `gorm:"column:batch_id" json:"batch_id"` + CreateTime int32 `gorm:"column:createtime" json:"-"` + ModifyTime int32 `gorm:"column:modifytime" json:"-"` +} + +func (ac *ActiveCode) TableName() string { + return "t_activation_code" +} diff --git a/server/adminserver/router/routermgr.go b/server/adminserver/router/routermgr.go index dd22a7e7..be8fa175 100644 --- a/server/adminserver/router/routermgr.go +++ b/server/adminserver/router/routermgr.go @@ -29,6 +29,7 @@ func (this *routerMgr) Init() { this.system.InitGameSwitchRouter(priGroup) this.system.InitBlockPlayerRouter(priGroup) this.system.InitWhiteListRouter(priGroup) + this.system.InitActiveCodeRouter(priGroup) f5.GetSysLog().Info("routerMgr.init") } diff --git a/server/adminserver/router/system/activecode.go b/server/adminserver/router/system/activecode.go new file mode 100644 index 00000000..412ddb8b --- /dev/null +++ b/server/adminserver/router/system/activecode.go @@ -0,0 +1,21 @@ +package system + +import ( + v1 "main/api/v1" + "main/middleware" + + "github.com/gin-gonic/gin" +) + +type ActiveCodeRoute struct { +} + +func (this *ActiveCodeRoute) InitActiveCodeRouter(priRouter *gin.RouterGroup) { + group := priRouter.Group("active_code") + api := v1.ApiGroupApp.SystemApiGroup.ActiveCodeApi + { + group.GET("gen", middleware.Permission("api/v1/active_code/gen", api.GenCode)) + group.POST("list", middleware.Permission("api/v1/active_code/list", api.List)) + group.GET("download", middleware.Permission("api/v1/active_code/download", api.DownloadFile)) + } +} \ No newline at end of file diff --git a/server/adminserver/router/system/enter.go b/server/adminserver/router/system/enter.go index 5a467cbf..f6acc66f 100644 --- a/server/adminserver/router/system/enter.go +++ b/server/adminserver/router/system/enter.go @@ -13,4 +13,5 @@ type RouterGroup struct { GameSwitchRoute BlockPlayerRoute WhiteListRoute + ActiveCodeRoute } From 43bd0ac3dd6a8ee01de2ff4fc04717513645d233 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Aug 2024 16:00:01 +0800 Subject: [PATCH 08/13] 1 --- server/marketserver/api/v1/recharge/recharge.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/marketserver/api/v1/recharge/recharge.go b/server/marketserver/api/v1/recharge/recharge.go index 0eefbc1a..5055159d 100644 --- a/server/marketserver/api/v1/recharge/recharge.go +++ b/server/marketserver/api/v1/recharge/recharge.go @@ -101,9 +101,13 @@ func (this *RechargeApi) BuyWithEmail(c *gin.Context) { CurrencyAddress string `json:"currency_address"` }{} if err := c.ShouldBindJSON(&reqJson); err != nil { + f5.GetSysLog().Info("BuyWithEmail passport_address:%s err:%s", + passportAddress, err) f5.RspErr(c, 1, err.Error()) return } + f5.GetSysLog().Info("BuyWithEmail passport_address:%s email:%s reqJson:%s", + passportAddress, email, q5.EncodeJson(&reqJson)) if email == "" { f5.RspErr(c, 1, "email is empty") return @@ -119,28 +123,34 @@ func (this *RechargeApi) internalBuy(c *gin.Context, passportAddress = strings.ToLower(passportAddress) currencyMeta := mt.Table.Currency.GetByNetIdAddress(netId, currencyAddress) if currencyMeta == nil { + f5.GetSysLog().Info("internalBuy error:1") f5.RspErr(c, 2, "server internal error") return } currencyContractMeta := currencyMeta.GetContract() if currencyContractMeta == nil { + f5.GetSysLog().Info("internalBuy error:2") f5.RspErr(c, 2, "server internal error") return } goodsMeta := mt.Table.Recharge.GetById(q5.ToInt64(goodsId)) if goodsMeta == nil { + f5.GetSysLog().Info("internalBuy error:3") f5.RspErr(c, 2, "goods id param error") return } if goodsMeta.GetPrice() <= 0 { + f5.GetSysLog().Info("internalBuy error:4") f5.RspErr(c, 2, "goods id param error") return } if goodsNum <= 0 || goodsNum > goodsMeta.GetMaxBuyTimes() { + f5.GetSysLog().Info("internalBuy error:5") f5.RspErr(c, 2, "num param error") return } if email != "" && goodsMeta.GetCanEmailBuy() == 0 { + f5.GetSysLog().Info("internalBuy error:6") f5.RspErr(c, 2, "cant email buy") return } @@ -161,6 +171,7 @@ func (this *RechargeApi) internalBuy(c *gin.Context, var err error orderId, err = transId.ToString() if err != nil { + f5.GetSysLog().Info("internalBuy error:6") f5.RspErr(c, 2, "server internal error") return } @@ -175,13 +186,16 @@ func (this *RechargeApi) internalBuy(c *gin.Context, f5.GetSysLog().Info("recharge net_id:%d currency_name:%s decimal:%d srcPrice:%d bnPrice:%s", netId, currencyMeta.GetCurrencyName(), currencyMeta.GetCurrencyDecimal(), srcPrice, bnPrice.String()); if bnPrice.Cmp(big.NewInt(0)) < 0 || bnPrice.Cmp(big.NewInt(srcPrice)) < 0 { + f5.GetSysLog().Info("internalBuy error:7") f5.RspErr(c, 3, "server internal error") return } if ok, err := service.User.InBlackList(accountAddress); err != nil { + f5.GetSysLog().Info("internalBuy error:8") f5.RspErr(c, 500, "server internal error") return } else if ok { + f5.GetSysLog().Info("internalBuy error:9") f5.RspErr(c, 501, "illegal user") return } @@ -210,10 +224,12 @@ func (this *RechargeApi) internalBuy(c *gin.Context, params, func(rsp f5.HttpCliResponse) { if rsp.GetErr() != nil { + f5.GetSysLog().Info("internalBuy error:a") f5.RspErr(c, 500, "server internal error") return } if q5.DecodeJson(rsp.GetRawData(), &jsonRspObj) != nil { + f5.GetSysLog().Info("internalBuy error:b") f5.RspErr(c, 500, "server internal error") return } @@ -236,6 +252,7 @@ func (this *RechargeApi) internalBuy(c *gin.Context, diamond, presentDiamond, email) { + f5.GetSysLog().Info("internalBuy error:c") f5.RspErr(c, 500, "server internal error") return } From 2172dba6751ecb0a02fb8168fe119e2e48bd4712 Mon Sep 17 00:00:00 2001 From: yangduo Date: Thu, 29 Aug 2024 16:20:48 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/adminserver/api/v1/system/activecode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/adminserver/api/v1/system/activecode.go b/server/adminserver/api/v1/system/activecode.go index bef693aa..e05ae7b0 100644 --- a/server/adminserver/api/v1/system/activecode.go +++ b/server/adminserver/api/v1/system/activecode.go @@ -90,7 +90,7 @@ func (aca *ActiveCodeApi) GenCode(c *gin.Context) { }) } -const strpol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz" +const strpol = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz" func (this *ActiveCodeApi) genCode(n int) string { var sb strings.Builder From 3af19964210aa318501c9ae40dbd4fdbbc7217e1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Aug 2024 16:41:00 +0800 Subject: [PATCH 10/13] 1 --- database/confdb.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/database/confdb.sql b/database/confdb.sql index 2d29ba0d..f19a98d9 100644 --- a/database/confdb.sql +++ b/database/confdb.sql @@ -171,6 +171,25 @@ CREATE TABLE `t_blacklist` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_internal_gameapi_host` +-- + +DROP TABLE IF EXISTS `t_internal_gameapi_host`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_internal_gameapi_host` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `gameapi_host` varchar(60) NOT NULL COMMENT 'gameapi_host(ip)', + `gameapi_port` int(11) NOT NULL DEFAULT '0' COMMENT 'gameapi_port', + `enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `gameapi_host` (`gameapi_host`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; From cad0eae2adb06eeb3f31e0ece85c7277815812fb Mon Sep 17 00:00:00 2001 From: yangduo Date: Thu, 29 Aug 2024 17:20:13 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/adminserver/config/nets | 1 + bin/adminserver/config/nets.json | 1 + server/adminserver/api/v1/system/player.go | 82 +++++++++++++-- server/adminserver/mt/Contract.go | 112 +++++++++++++++++++++ server/adminserver/mt/export.go | 3 + 5 files changed, 191 insertions(+), 8 deletions(-) create mode 120000 bin/adminserver/config/nets create mode 120000 bin/adminserver/config/nets.json create mode 100644 server/adminserver/mt/Contract.go diff --git a/bin/adminserver/config/nets b/bin/adminserver/config/nets new file mode 120000 index 00000000..86cee120 --- /dev/null +++ b/bin/adminserver/config/nets @@ -0,0 +1 @@ +../../backtask/config/nets/ \ No newline at end of file diff --git a/bin/adminserver/config/nets.json b/bin/adminserver/config/nets.json new file mode 120000 index 00000000..73809673 --- /dev/null +++ b/bin/adminserver/config/nets.json @@ -0,0 +1 @@ +../../backtask/config/nets.json \ No newline at end of file diff --git a/server/adminserver/api/v1/system/player.go b/server/adminserver/api/v1/system/player.go index 67e954c9..12e1c711 100644 --- a/server/adminserver/api/v1/system/player.go +++ b/server/adminserver/api/v1/system/player.go @@ -3,8 +3,10 @@ package system import ( "f5" "fmt" + "jccommon" "main/constant" "main/model/system" + "main/mt" "net/http" "q5" "strings" @@ -161,7 +163,7 @@ func (pai *PlayerApi) HeroesQuery(c *gin.Context) { } reqJson := HeroesQueryForm{} - if !checkparam(&reqJson, c) { + if !checkparam(&reqJson, c) || reqJson.Account_id == "" { return } @@ -174,8 +176,72 @@ func (pai *PlayerApi) HeroesQuery(c *gin.Context) { } cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) - filterstr := " account_id = '" + reqJson.Account_id + "' " - sql := fmt.Sprintf(`SELECT * FROM t_hero WHERE idx > %d AND %s `, cursor, filterstr) + filterstr := "account_id = '" + reqJson.Account_id + "' " + { + sql := fmt.Sprintf(`SELECT address FROM t_immutable_account WHERE idx > 1 AND account_id = '%s'`, reqJson.Account_id) + + address := "" + f5.GetGoStyleDb().RawQuery( + constant.ACCOUNT_DB, + sql, + []string{}, + func(err error, ds *f5.DataSet) { + if err != nil { + return + } + + if ds.Next() { + address = ds.GetByIndex(0) + } + }) + + if address != "" { + lockaddrlist := []string{} + mt.Table.Contract.Traverse(func(mtc *mt.Contract) bool { + if mtc.GetName() == jccommon.CONTRACT_NAME_NFTLock { + lockaddrlist = append(lockaddrlist, strings.ToLower(mtc.GetAddress())) + } + return true + }) + sql = fmt.Sprintf(`SELECT token_id FROM t_nft WHERE idx > 1 AND token_type IN (1, 12) AND (owner_address = '%s'`, address) + if len(lockaddrlist) > 0 { + sql += fmt.Sprintf(" OR (last_lock_address = '%s' AND owner_address IN (", address) + for _, addr := range lockaddrlist { + sql += "'" + addr + "'," + } + sql = sql[:len(sql)-1] + sql+="))" + } + sql += ")" + f5.GetSysLog().Debug("tokenid sql:%s", sql) + tokenidlist := []string{} + f5.GetGoStyleDb().RawQuery( + constant.BCNFT_DB, + sql, + []string{}, + func(err error, ds *f5.DataSet) { + if err != nil { + return + } + + for ds.Next() { + tokenidlist = append(tokenidlist, ds.GetByIndex(0)) + } + }) + if len(tokenidlist) > 0 { + tokenfilterstr := "OR token_id IN (" + for _, v := range tokenidlist { + tokenfilterstr += v + "," + } + tokenfilterstr = tokenfilterstr[:len(tokenfilterstr)-1] + tokenfilterstr += ")" + + filterstr += tokenfilterstr + } + } + } + sql := fmt.Sprintf(`SELECT * FROM t_hero WHERE idx > %d AND (%s)`, cursor, filterstr) + f5.GetSysLog().Debug("hero sql:%s", sql) query(constant.GAME_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} { p := new(system.Hero) @@ -300,11 +366,11 @@ func (pai *PlayerApi) RechargeQuery(c *gin.Context) { } cursor := q5.ToInt64(c.DefaultQuery("cursor", "")) - filterstr := - " (receiver_account_id = '" + reqJson.Identity + - "' OR account_address = '" + reqJson.Identity + - "' OR passport_address = '" + reqJson.Identity + - "' OR lower_case_email = '" + reqJson.Identity + "')" + filterstr := + " (receiver_account_id = '" + reqJson.Identity + + "' OR account_address = '" + reqJson.Identity + + "' OR passport_address = '" + reqJson.Identity + + "' OR lower_case_email = '" + reqJson.Identity + "')" sql := fmt.Sprintf(`SELECT * FROM t_recharge_order WHERE idx > %d AND %s `, cursor, filterstr) query(constant.BCNFT_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} { diff --git a/server/adminserver/mt/Contract.go b/server/adminserver/mt/Contract.go new file mode 100644 index 00000000..8d95743c --- /dev/null +++ b/server/adminserver/mt/Contract.go @@ -0,0 +1,112 @@ +package mt + +import ( + "encoding/json" + "f5" + "fmt" + "q5" + "strings" +) + +type Contract struct { + name string + address string +} + +type ContractTable struct { + netIdNameHash *q5.ConcurrentMap[string, *Contract] + netIdAddressHash *q5.ConcurrentMap[string, *Contract] +} + +func (this *Contract) GetName() string { + return this.name +} + +func (this *Contract) GetAddress() string { + return this.address +} + +func (this *ContractTable) IsNoLoad() bool { + return false +} + +func (this *ContractTable) Load() { + this.netIdNameHash = new(q5.ConcurrentMap[string, *Contract]) + this.netIdAddressHash = new(q5.ConcurrentMap[string, *Contract]) + nets := []interface{}{} + { + if jsonStr, err := f5.ReadJsonFile("../config/nets.json"); err == nil { + if err := json.Unmarshal([]byte(jsonStr), &nets); err != nil { + panic(fmt.Sprintf("load metafile json decode error %s %s", "nets.json", err)) + } + } else { + panic(fmt.Sprintf("load metafile error %s %s", "nets.json", err)) + } + } + { + for _, val := range nets { + netId := q5.SafeToInt32(val) + fileName := fmt.Sprintf("../config/nets/%d/contract.json", netId) + if jsonStr, err := f5.ReadJsonFile(fileName); err == nil { + contracts := []struct { + Name string `json:"name"` + Address string `json:"address"` + }{} + if err := json.Unmarshal([]byte(jsonStr), &contracts); err != nil { + panic(fmt.Sprintf("load metafile json decode error %s %s", "contract.json", err)) + } + for _, val2 := range contracts { + p := new(Contract) + p.name = q5.SafeToString(val2.Name) + p.address = strings.ToLower(q5.SafeToString(val2.Address)) + { + key := fmt.Sprintf("%d_%s", netId, p.name) + this.netIdNameHash.Store(key, p) + } + { + key := fmt.Sprintf("%d_%s", netId, p.address) + this.netIdAddressHash.Store(key, p) + } + } + } else { + panic(fmt.Sprintf("load metafile error %s %s", "contract.json", err)) + } + } + } +} + +func (this *ContractTable) PreInit1() { + +} + +func (this *ContractTable) ElementsInit(int) { + +} + +func (this *ContractTable) PostInit1() { + +} + +func (this *ContractTable) GetByNetIdName(netId int32, name string) *Contract { + key := fmt.Sprintf("%d_%s", netId, name) + if v, ok := this.netIdNameHash.Load(key); ok { + return *v + } else { + return nil + } +} + +func (this *ContractTable) GetByNetIdAddress(netId int32, address string) *Contract { + key := fmt.Sprintf("%d_%s", netId, address) + if v, ok := this.netIdAddressHash.Load(key); ok { + return *v + } else { + return nil + } +} + +func (this *ContractTable) Traverse(cb func(*Contract) bool) { + this.netIdNameHash.Range(func(k string, v *Contract) bool { + return cb(v) + }) +} diff --git a/server/adminserver/mt/export.go b/server/adminserver/mt/export.go index 88927028..d8ed25ea 100644 --- a/server/adminserver/mt/export.go +++ b/server/adminserver/mt/export.go @@ -17,6 +17,7 @@ type table struct { Permission *PermissionTable ConfDb *ConfDbTable Item *ItemTable + Contract *ContractTable } var Table = f5.New(func(this *table) { @@ -71,6 +72,8 @@ var Table = f5.New(func(this *table) { this.Permission = new(PermissionTable) + this.Contract = new(ContractTable) + this.Item = f5.New(func(this *ItemTable) { this.FileName = "../res/item@item.json" this.PrimKey = "id" From 028dea0ab46c88d809cdac0c6838619c3ecb3882 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 29 Aug 2024 17:59:38 +0800 Subject: [PATCH 12/13] 1 --- database/confdb.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/database/confdb.sql b/database/confdb.sql index f19a98d9..03b76342 100644 --- a/database/confdb.sql +++ b/database/confdb.sql @@ -190,6 +190,25 @@ CREATE TABLE `t_internal_gameapi_host` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_apigate_host` +-- + +DROP TABLE IF EXISTS `t_apigate_host`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_apigate_host` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `apigate_host` varchar(60) NOT NULL COMMENT 'apigate_host(ip)', + `apigate_port` int(11) NOT NULL DEFAULT '0' COMMENT 'apigate_port', + `enable` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `apigate_host` (`apigate_host`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; From 34a400e7edcdc1ae6fe9bf8bfb9c7b8066d3d2cf Mon Sep 17 00:00:00 2001 From: yangduo Date: Thu, 29 Aug 2024 19:11:59 +0800 Subject: [PATCH 13/13] gameapi host & apigate host --- server/adminserver/api/v1/system/enter.go | 1 + .../adminserver/api/v1/system/workertool.go | 263 ++++++++++++++++++ server/adminserver/model/system/workertool.go | 25 ++ server/adminserver/router/routermgr.go | 1 + server/adminserver/router/system/enter.go | 1 + .../adminserver/router/system/workertool.go | 28 ++ 6 files changed, 319 insertions(+) create mode 100644 server/adminserver/api/v1/system/workertool.go create mode 100644 server/adminserver/model/system/workertool.go create mode 100644 server/adminserver/router/system/workertool.go diff --git a/server/adminserver/api/v1/system/enter.go b/server/adminserver/api/v1/system/enter.go index 110464ab..67d1c89d 100644 --- a/server/adminserver/api/v1/system/enter.go +++ b/server/adminserver/api/v1/system/enter.go @@ -14,4 +14,5 @@ type ApiGroup struct { BlockPlayerApi WhiteListApi ActiveCodeApi + WorkerToolApi } diff --git a/server/adminserver/api/v1/system/workertool.go b/server/adminserver/api/v1/system/workertool.go new file mode 100644 index 00000000..aa1ba149 --- /dev/null +++ b/server/adminserver/api/v1/system/workertool.go @@ -0,0 +1,263 @@ +package system + +import ( + "f5" + "fmt" + "main/constant" + "main/model/system" + "net" + "net/http" + "q5" + "time" + + "github.com/gin-gonic/gin" +) + +type WorkerToolApi struct { +} + +func (bpa *WorkerToolApi) ListGameApi(c *gin.Context) { + req := struct { + PageDto system.PageDto `json:"page_dto"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + sql := "SELECT * FROM t_internal_gameapi_host WHERE 1=1" + params := []string{} + result := []*system.GameApiHostItem{} + f5.GetGoStyleDb().PageQuery( + constant.CONF_DB, + q5.ToInt32(req.PageDto.PageSize), + q5.ToInt32(req.PageDto.Page), + sql, + params, + f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), + "", + func(err error, pg *f5.Pagination) { + if err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + for pg.Rows.Next() { + p := new(system.GameApiHostItem) + f5.UnmarshalModel(pg.Rows, p) + q5.AppendSlice(&result, p) + } + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "获取成功", + "data": result, + "total": pg.Total, + "total_page": pg.TotalPages, + "cur_page": pg.CurrentPage, + }) + }) +} + +func (bpa *WorkerToolApi) AddGameApi(c *gin.Context) { + req := struct { + Host string `binding:"required" json:"gameapi_host"` + Port int32 `binding:"required" json:"gameapi_port"` + Enable int32 `json:"enable"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + if !bpa.testHostport(c, req.Host, req.Port) { + return + } + + info := new(system.GameApiHostItem) + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + + var count int64 = 0 + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("gameapi_host = ?", req.Host).Where("gameapi_port = ?", req.Port) + if err := db.Count(&count).Error; err == nil && count > 0 { + f5.RspErr2(c, 1, "数据存在") + return + } + + info.Host = req.Host + info.Port = req.Port + info.Enable = req.Enable + info.CreateTime = nowDaySeconds + info.ModifyTime = nowDaySeconds + if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + f5.RspErr2(c, 0, "添加成功") +} + +func (bpa *WorkerToolApi) EditGameApi(c *gin.Context) { + req := struct { + Host string `binding:"required" json:"gameapi_host"` + Port int32 `binding:"required" json:"gameapi_port"` + Enable int32 `json:"enable"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + if !bpa.testHostport(c, req.Host, req.Port) { + return + } + + item := new(system.GameApiHostItem) + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName()) + if err := db.Take(item, "gameapi_host = ? AND gameapi_port = ?", req.Host, req.Port).Error; err != nil { + if !f5.IsOrmErrRecordNotFound(err) { + f5.RspErr2(c, 500, "sever internal error:"+err.Error()) + return + } else { + f5.RspErr2(c, 2, "无法查到记录") + return + } + } + + if item.Enable != req.Enable { + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + item.Enable = req.Enable + item.ModifyTime = nowDaySeconds + if err := db.Where("gameapi_host = ?", req.Host).Where("gameapi_port = ?", req.Port).Save(item).Error; err != nil { + f5.RspErr2(c, 500, "sever internal error:"+err.Error()) + return + } + } + f5.RspErr2(c, 0, "") +} + +func (bpa *WorkerToolApi) ListApiGate(c *gin.Context) { + req := struct { + PageDto system.PageDto `json:"page_dto"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + sql := "SELECT * FROM t_apigate_host WHERE 1=1" + params := []string{} + result := []*system.ApiGateHostItem{} + f5.GetGoStyleDb().PageQuery( + constant.CONF_DB, + q5.ToInt32(req.PageDto.PageSize), + q5.ToInt32(req.PageDto.Page), + sql, + params, + f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), + "", + func(err error, pg *f5.Pagination) { + if err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + for pg.Rows.Next() { + p := new(system.ApiGateHostItem) + f5.UnmarshalModel(pg.Rows, p) + q5.AppendSlice(&result, p) + } + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "获取成功", + "data": result, + "total": pg.Total, + "total_page": pg.TotalPages, + "cur_page": pg.CurrentPage, + }) + }) +} + +func (bpa *WorkerToolApi) AddApiGate(c *gin.Context) { + req := struct { + Host string `binding:"required" json:"apigate_host"` + Port int32 `binding:"required" json:"apigate_port"` + Enable int32 `json:"enable"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + if !bpa.testHostport(c, req.Host, req.Port) { + return + } + + info := new(system.ApiGateHostItem) + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + + var count int64 = 0 + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("apigate_host = ?", req.Host).Where("apigate_port = ?", req.Port) + if err := db.Count(&count).Error; err == nil && count > 0 { + f5.RspErr2(c, 1, "数据存在") + return + } + + info.Host = req.Host + info.Port = req.Port + info.Enable = req.Enable + info.CreateTime = nowDaySeconds + info.ModifyTime = nowDaySeconds + if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(info).Error; err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + f5.RspErr2(c, 0, "添加成功") +} + +func (bpa *WorkerToolApi) EditApiGate(c *gin.Context) { + req := struct { + Host string `binding:"required" json:"apigate_host"` + Port int32 `binding:"required" json:"apigate_port"` + Enable int32 `json:"enable"` + }{} + if err := c.ShouldBindJSON(&req); err != nil { + f5.RspErr2(c, 1, err.Error()) + return + } + + if !bpa.testHostport(c, req.Host, req.Port) { + return + } + + item := new(system.ApiGateHostItem) + db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName()) + if err := db.Take(item, "apigate_host = ? AND apigate_port = ?", req.Host, req.Port).Error; err != nil { + if !f5.IsOrmErrRecordNotFound(err) { + f5.RspErr2(c, 500, "sever internal error:"+err.Error()) + return + } else { + f5.RspErr2(c, 2, "无法查到记录") + return + } + } + + if item.Enable != req.Enable { + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) + item.Enable = req.Enable + item.ModifyTime = nowDaySeconds + if err := db.Where("apigate_host = ?", req.Host).Where("apigate_port = ?", req.Port).Save(item).Error; err != nil { + f5.RspErr2(c, 500, "sever internal error:"+err.Error()) + return + } + } + f5.RspErr2(c, 0, "") +} + +func (bpa *WorkerToolApi) testHostport(c *gin.Context, host string, port int32) bool { + addrAndPort := fmt.Sprintf("%s:%d", host, port) + conn, err := net.DialTimeout("tcp", addrAndPort, time.Second) + if err != nil { + f5.RspErr2(c, 2, "host port 连不上") + return false + } else { + conn.Close() + return true + } +} diff --git a/server/adminserver/model/system/workertool.go b/server/adminserver/model/system/workertool.go new file mode 100644 index 00000000..9176416f --- /dev/null +++ b/server/adminserver/model/system/workertool.go @@ -0,0 +1,25 @@ +package system + +type GameApiHostItem struct { + Host string `gorm:"column:gameapi_host" json:"gameapi_host"` + Port int32 `gorm:"column:gameapi_port" json:"gameapi_port"` + Enable int32 `gorm:"column:enable" json:"enable"` + CreateTime int32 `gorm:"column:createtime" json:"-"` + ModifyTime int32 `gorm:"column:modifytime" json:"-"` +} + +func (GameApiHostItem) TableName() string { + return "t_internal_gameapi_host" +} + +type ApiGateHostItem struct { + Host string `gorm:"column:apigate_host" json:"apigate_host"` + Port int32 `gorm:"column:apigate_port" json:"apigate_port"` + Enable int32 `gorm:"column:enable" json:"enable"` + CreateTime int32 `gorm:"column:createtime" json:"-"` + ModifyTime int32 `gorm:"column:modifytime" json:"-"` +} + +func (ApiGateHostItem) TableName() string { + return "t_apigate_host" +} diff --git a/server/adminserver/router/routermgr.go b/server/adminserver/router/routermgr.go index be8fa175..5f7cf312 100644 --- a/server/adminserver/router/routermgr.go +++ b/server/adminserver/router/routermgr.go @@ -30,6 +30,7 @@ func (this *routerMgr) Init() { this.system.InitBlockPlayerRouter(priGroup) this.system.InitWhiteListRouter(priGroup) this.system.InitActiveCodeRouter(priGroup) + this.system.InitWorkerToolRouter(priGroup) f5.GetSysLog().Info("routerMgr.init") } diff --git a/server/adminserver/router/system/enter.go b/server/adminserver/router/system/enter.go index f6acc66f..7a96cfad 100644 --- a/server/adminserver/router/system/enter.go +++ b/server/adminserver/router/system/enter.go @@ -14,4 +14,5 @@ type RouterGroup struct { BlockPlayerRoute WhiteListRoute ActiveCodeRoute + WorkerToolRoute } diff --git a/server/adminserver/router/system/workertool.go b/server/adminserver/router/system/workertool.go new file mode 100644 index 00000000..9173bac4 --- /dev/null +++ b/server/adminserver/router/system/workertool.go @@ -0,0 +1,28 @@ +package system + +import ( + v1 "main/api/v1" + "main/middleware" + + "github.com/gin-gonic/gin" +) + +type WorkerToolRoute struct { +} + +func (this *WorkerToolRoute) InitWorkerToolRouter(priRouter *gin.RouterGroup) { + group := priRouter.Group("gameapihost") + api := v1.ApiGroupApp.SystemApiGroup.WorkerToolApi + { + group.POST("add", middleware.Permission("api/v1/gameapihost/add", api.AddGameApi)) + group.POST("edit", middleware.Permission("api/v1/gameapihost/edit", api.EditGameApi)) + group.POST("list", middleware.Permission("api/v1/gameapihost/list", api.ListGameApi)) + } + + { + supergroup := priRouter.Group("apigate") + supergroup.POST("add", middleware.Permission("api/v1/apigate/add", api.AddApiGate)) + supergroup.POST("list", middleware.Permission("api/v1/apigate/list", api.ListApiGate)) + supergroup.POST("edit", middleware.Permission("api/v1/apigate/edit", api.EditApiGate)) + } +}