Merge branch 'dev' into permission

This commit is contained in:
yangduo 2024-07-18 11:09:21 +08:00
commit 1ea48b7301
15 changed files with 211 additions and 21 deletions

View File

@ -3,7 +3,7 @@
"port": 3306,
"user": "root",
"passwd": "keji178",
"database": "gamedb2006_dev",
"database": "gamedb2006_dev_1",
"max_open_conns": 100,
"max_idle_conns": 50
}

View File

@ -0,0 +1,5 @@
[
{
"url": "http://127.0.0.1:7672"
}
]

View File

@ -3,6 +3,7 @@ package jccommon
const (
NFT_TYPE_CFHERO = 1
NFT_TYPE_GOLD_BULLION = 11
NFT_TYPE_CFHERO_NORMAL = 12
)
const (

View File

@ -3,7 +3,9 @@ package ingame
import (
"q5"
"f5"
//"mt"
"main/common"
"main/constant"
. "main/global"
"github.com/gin-gonic/gin"
)
@ -34,7 +36,9 @@ func (this *InGameApi) HeroList(c *gin.Context) {
f5.RspErr(c, 401, "params parse error")
return
}
err, heroList := GetCacheMgr().GetIngameHero("")
openId := c.MustGet("open_id").(string)
accountId := openId
err, heroList := GetCacheMgr().GetIngameHero(accountId)
if err != nil {
f5.RspErr(c, 500, "server internal error")
return
@ -52,7 +56,7 @@ func (this *InGameApi) HeroList(c *gin.Context) {
heroList,
q5.SafeToInt32(reqJson.PageSize),
q5.SafeToInt64(reqJson.Cursor),
func (row interface{}) bool {
func (kv interface{}) bool {
return true
},
func (a interface{}, b interface{}) bool {
@ -61,22 +65,82 @@ func (this *InGameApi) HeroList(c *gin.Context) {
func (p *f5.StreamPagination) {
rspObj.Page.FillPage(p)
},
func (row interface{}) {
q5.AppendSlice(&rspObj.Rows, row)
func (kv interface{}) {
q5.AppendSlice(&rspObj.Rows, kv)
})
c.JSON(200, rspObj)
}
func (this *InGameApi) HeroMint(c *gin.Context) {
reqJson := struct {
NetId interface{} `json:"net_id"`
ContractAddress string `json:"contract_address"`
To string `json:"to"`
Tokens struct {
TokenId string `json:"token_id"`
} `json:"tokens"`
HeroUniIds []string `json:"hero_uniids"`
}{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
f5.RspErr(c, 401, "params parse error")
return
}
if reqJson.To == "" {
f5.RspErr(c, 1, "to params error")
return
}
if len(reqJson.HeroUniIds) != 1 {
f5.RspErr(c, 1, "tokens params error")
return
}
uniid := reqJson.HeroUniIds[0]
accountId := c.MustGet("open_id").(string)
accountAddress := c.MustGet("account_address").(string)
f5.GetGoStyleDb().OrmSelectOne(
constant.GAME_DB,
"t_hero",
[][]string{
{"account_id", accountId},
{"idx", uniid},
},
func (err error, ds *f5.DataSet) {
if err != nil {
f5.RspErr(c, 500, "server internal error")
return
}
if ds.Next() {
params := map[string]string{
"c": "OutAppMint",
"a": "mintHero",
"account_id": accountId,
"account_address": accountAddress,
"to_address": reqJson.To,
"uniid": uniid,
}
rspObj := &struct {
ErrCode interface{} `json:"errcode"`
ErrMsg string `json:"errmsg"`
TransId string `json:"trans_id"`
TransReq interface{} `json:"trans_req"`
}{
}
f5.GetHttpCliMgr().SendGoStyleRequest(
"https://game2006api-test.kingsome.cn/webapp/index.php",
params,
func(rsp f5.HttpCliResponse) {
if rsp.GetErr() != nil {
rspObj.ErrCode = 500
rspObj.ErrMsg = "server internal error1"
c.JSON(200, rspObj)
return
}
if q5.DecodeJson(rsp.GetRawData(), &rspObj) != nil {
rspObj.ErrCode = 500
rspObj.ErrMsg = "server internal error2"
c.JSON(200, rspObj)
return
}
c.JSON(200, rspObj)
})
} else {
f5.RspErr(c, 500, "hero not found")
return
}
})
}

View File

@ -29,7 +29,7 @@ func (this *MarketApi) LockList(c *gin.Context) {
HeroRanks []interface{} `json:"hero_ranks"`
} `json:"filter"`
Sort struct {
Fields [] struct {
Fields [] struct {
} `json:"fields"`
} `json:"sort"`
}{}
@ -45,13 +45,14 @@ func (this *MarketApi) LockList(c *gin.Context) {
cursor := q5.SafeToInt64(reqJson.Cursor)
nftLockMeta := mt.Table.Contract.GetByName(jccommon.CONTRACT_NAME_NFTLock)
sql := fmt.Sprintf(`
SELECT * FROM t_nft
WHERE idx > %d AND net_id = %d AND owner_address = '%s' AND last_lock_address = ? `,
cursor, netId, strings.ToLower(nftLockMeta.GetAddress()))
SELECT * FROM t_nft
WHERE idx > %d AND net_id = %d AND owner_address = '%s' AND token_type IN (%d, %d, %d) AND last_lock_address = ? `,
cursor, netId, strings.ToLower(nftLockMeta.GetAddress()),
jccommon.NFT_TYPE_CFHERO, jccommon.NFT_TYPE_CFHERO_NORMAL, jccommon.NFT_TYPE_GOLD_BULLION)
params := []string{owner}
subFilters := []f5.DbQueryFilter{}
{
itemIds := map[int32]int32{}
if reqJson.Search.Name != "" {

View File

@ -62,6 +62,40 @@ func (this *NftApi) Unlock(c *gin.Context) {
f5.RspErr(c, 500, "nft not found")
return
}
params := map[string]string{
"c": "BcService",
"a": "nftUnlock",
"account_address": accountAddress,
"net_id": ds.GetByName("net_id"),
"nft_address": ds.GetByName("contract_address"),
"to_address": reqJson.To,
"token_ids": ds.GetByName("token_id"),
}
rspObj := &struct {
ErrCode interface{} `json:"errcode"`
ErrMsg string `json:"errmsg"`
TransId string `json:"trans_id"`
TransReq interface{} `json:"trans_req"`
}{
}
f5.GetHttpCliMgr().SendGoStyleRequest(
mt.Table.Web3SignCluster.RandElement().GetUrl() + "/webapp/index.php",
params,
func(rsp f5.HttpCliResponse) {
if rsp.GetErr() != nil {
rspObj.ErrCode = 500
rspObj.ErrMsg = "server internal error"
c.JSON(200, rspObj)
return
}
if q5.DecodeJson(rsp.GetRawData(), &rspObj) != nil {
rspObj.ErrCode = 500
rspObj.ErrMsg = "server internal error2"
c.JSON(200, rspObj)
return
}
c.JSON(200, rspObj)
})
} else {
f5.RspErr(c, 500, "nft not found")
return

View File

@ -38,8 +38,37 @@ func (this *cacheMgr) GetNfts(nfts []*common.NftDto) {
}
}
func (this *cacheMgr) GetIngameHero(string) (error, []interface{}) {
return nil, nil
func (this *cacheMgr) GetIngameHero(accountId string) (error, []interface{}) {
rspObj := struct {
ErrCode interface{} `json:"errcode"`
ErrMsg string `json:"errmsg"`
Rows []interface{}
}{}
var err error
rows := []interface{}{}
f5.GetHttpCliMgr().SendGoStyleRequest(
mt.Table.Config.GetGameApiUrl() + "/webapp/index.php",
map[string]string{
"c": "OutAppNft",
"a": "getHeroList",
"account_id": accountId,
},
func (rsp f5.HttpCliResponse) {
err = rsp.GetErr()
if rsp.GetErr() != nil {
return
}
err = q5.DecodeJson(rsp.GetRawData(), &rspObj)
if err != nil {
return
}
})
if err == nil {
if q5.SafeToInt32(rspObj.ErrCode) == 0 {
rows = rspObj.Rows
}
}
return err, rows
}
func (this *cacheMgr) fastGetNft(dto *common.NftDto) {

View File

@ -93,7 +93,7 @@ func internalImmutJwtAuth(c *gin.Context, jwtToken string) {
rspObj.ErrMsg = jsonRspObj.ErrMsg
if q5.SafeToInt32(rspObj.ErrCode) != 0 {
rspObj.ErrCode = 501
rspObj.ErrMsg = "jwt error"
rspObj.ErrMsg = "jwt expired"
c.JSON(200, rspObj)
c.Abort()
return

View File

@ -0,0 +1,18 @@
package mt
import (
"f5"
"mtb"
)
type Web3SignCluster struct {
mtb.Web3SignCluster
}
type Web3SignClusterTable struct {
f5.IdMetaTable[Web3SignCluster]
}
func (this *Web3SignCluster) Init1() {
}

View File

@ -14,6 +14,7 @@ type table struct {
Language *LanguageTable
Contract *ContractTable
Web3ServiceCluster *Web3ServiceClusterTable
Web3SignCluster *Web3SignClusterTable
}
var Table = f5.New(func(this *table) {
@ -62,4 +63,9 @@ var Table = f5.New(func(this *table) {
this.PrimKey = ""
})
this.Web3SignCluster = f5.New(func(this *Web3SignClusterTable) {
this.FileName = "../config/web3sign.cluster.json"
this.PrimKey = ""
})
})

View File

@ -93,6 +93,13 @@ type Web3ServiceCluster struct {
_flags2_ uint64
}
type Web3SignCluster struct {
url string
_flags1_ uint64
_flags2_ uint64
}
func (this *MarketServerCluster) GetInstanceId() int32 {
return this.instance_id
}
@ -373,6 +380,14 @@ func (this *Web3ServiceCluster) HasUrl() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *Web3SignCluster) GetUrl() string {
return this.url
}
func (this *Web3SignCluster) HasUrl() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *MarketServerCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
@ -435,3 +450,7 @@ func (this *Contract) LoadFromKv(kv map[string]interface{}) {
func (this *Web3ServiceCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.url, "url", &this._flags1_, 1, kv)
}
func (this *Web3SignCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.url, "url", &this._flags1_, 1, kv)
}

View File

@ -72,3 +72,8 @@ message Web3ServiceCluster
{
optional string url = 1;
}
message Web3SignCluster
{
optional string url = 1;
}

View File

@ -3,12 +3,17 @@ package ingame
import (
"f5"
"main/api/v1"
"main/middleware"
)
type IngameRouter struct{}
func (this *IngameRouter) InitRouter() {
api := v1.ApiGroupApp.IngameApiGroup
f5.GetApp().GetGinEngine().GET("/api/ingame/asset/hero/list", api.IngameApi.HeroList)
f5.GetApp().GetGinEngine().POST("/api/ingame/asset/hero/mint", api.IngameApi.HeroMint)
api := v1.ApiGroupApp.InGameApiGroup
f5.GetApp().GetGinEngine().POST("/api/ingame/asset/hero/list",
middleware.JwtAuth,
api.InGameApi.HeroList)
f5.GetApp().GetGinEngine().POST("/api/ingame/asset/hero/mint",
middleware.JwtAuth,
api.InGameApi.HeroMint)
}

View File

@ -9,6 +9,7 @@ import (
"main/router/gold_bullion"
"main/router/shopcart"
"main/router/nft"
"main/router/ingame"
)
type routerMgr struct {
@ -18,6 +19,7 @@ type routerMgr struct {
goldBullion gold_bullion.RouterGroup
shopCart shopcart.RouterGroup
nft nft.RouterGroup
ingame ingame.RouterGroup
}
func (this *routerMgr) Init() {
@ -28,6 +30,7 @@ func (this *routerMgr) Init() {
this.goldBullion.GoldBullionRouter.InitRouter()
this.shopCart.ShopCartRouter.InitRouter()
this.nft.NftRouter.InitRouter()
this.ingame.IngameRouter.InitRouter()
f5.GetSysLog().Info("routerMgr.init")

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit a55bc814287f711be731be3a27badd50fd6bfb35
Subproject commit 7685c13942fc25fc89e49640f0b303e029279c7a