This commit is contained in:
殷勇 2023-11-08 10:48:10 +08:00
parent cb551a45b5
commit 083cf00b02
17 changed files with 314 additions and 101 deletions

29
database/accountdb.sql Normal file
View File

@ -0,0 +1,29 @@
DROP TABLE IF EXISTS `t_announcement`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_announcement` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '标题',
`version` varchar(32) NOT NULL DEFAULT '' COMMENT '版本',
`model` int(11) NOT NULL DEFAULT '0' COMMENT '型号 1:Android 2:ios',
`type` int(11) NOT NULL DEFAULT '0' COMMENT ' 1:停服公告 2:普通公告',
`is_effect` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效',
`content` text DEFAULT '' COMMENT '内容',
PRIMARY KEY (`idx`),
UNIQUE KEY `model_type` (`model`,`type`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `t_audit`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_audit` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`version` varchar(32) NOT NULL DEFAULT '' COMMENT '版本',
`model` int(11) NOT NULL DEFAULT '0' COMMENT '型号 1:Android 2:ios',
`is_auditing` int(11) NOT NULL DEFAULT '0' COMMENT '是否审核中',
PRIMARY KEY (`idx`),
UNIQUE KEY `model` (`model`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -22,34 +22,3 @@ PRIMARY KEY (`idx`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `t_announcement`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_announcement` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '标题',
`version` varchar(32) NOT NULL DEFAULT '' COMMENT '版本',
`model` int(11) NOT NULL DEFAULT '0' COMMENT '型号 1:Android 2:ios',
`type` int(11) NOT NULL DEFAULT '0' COMMENT ' 1:停服公告 2:普通公告',
`is_effect` int(11) NOT NULL DEFAULT '0' COMMENT '是否生效',
`content` text DEFAULT '' COMMENT '内容',
PRIMARY KEY (`idx`),
UNIQUE KEY `model_type` (`model`,`type`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `t_audit`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_audit` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`version` varchar(32) NOT NULL DEFAULT '' COMMENT '版本',
`model` int(11) NOT NULL DEFAULT '0' COMMENT '型号 1:Android 2:ios',
`is_auditing` int(11) NOT NULL DEFAULT '0' COMMENT '是否审核中',
PRIMARY KEY (`idx`),
UNIQUE KEY `model` (`model`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -14,7 +14,7 @@ type AnncApi struct {
func (this *AnncApi) AnncList(c *gin.Context) {
var anncList []system.Annc
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Find(&anncList).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Find(&anncList).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -39,7 +39,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
return
}
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_announcement").Where("model = ?", annc.Model).Where("type = ?", annc.Type).Count(&count)
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_announcement").Where("model = ?", annc.Model).Where("type = ?", annc.Type).Count(&count)
if count > 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -48,7 +48,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
return
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Create(&annc).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&annc).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -65,7 +65,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
func (this *AnncApi) UpdateAnnc(c *gin.Context) {
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_announcement").Where("idx = ?", idx).Count(&count)
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_announcement").Where("idx = ?", idx).Count(&count)
if count < 1 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -81,7 +81,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
})
return
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&annc).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&annc).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,

View File

@ -1,10 +1,10 @@
package system
import (
"adminsever/constant"
"adminsever/model/system"
"f5"
"github.com/gin-gonic/gin"
"main/constant"
"main/model/system"
"net/http"
"strconv"
)
@ -14,7 +14,7 @@ type AuditApi struct {
func (this *AuditApi) AuditList(c *gin.Context) {
var auditList []system.Audit
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Find(&auditList).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Find(&auditList).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -39,7 +39,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
return
}
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_audit").Where("model = ?", audit.Model).Count(&count)
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_audit").Where("model = ?", audit.Model).Count(&count)
if count > 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -48,7 +48,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
return
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Create(&audit).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&audit).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -65,7 +65,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
func (this *AuditApi) UpdateAudit(c *gin.Context) {
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table("t_audit").Where("idx = ?", idx).Count(&count)
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_audit").Where("idx = ?", idx).Count(&count)
if count < 1 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -81,7 +81,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
})
return
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&audit).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&audit).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,

View File

@ -20,7 +20,7 @@ func (s *BattleServerApi) Add(c *gin.Context) {
return
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Create(&server).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&server).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -39,7 +39,7 @@ func (s *BattleServerApi) Add(c *gin.Context) {
func (s *BattleServerApi) List(c *gin.Context) {
var battleServers []system.BattleServer
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Find(&battleServers).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Find(&battleServers).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -64,7 +64,7 @@ func (s *BattleServerApi) Update(c *gin.Context) {
return
}
var count int64
f5.GetApp().GetOrmDb(constant.ADMIN_DB).Table(entity.TableName()).Where("idx = ?", entity.Idx).Count(&count)
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table(entity.TableName()).Where("idx = ?", entity.Idx).Count(&count)
if count < 1 {
c.JSON(http.StatusOK, gin.H{
"code": 1,
@ -73,7 +73,7 @@ func (s *BattleServerApi) Update(c *gin.Context) {
return
}
err := f5.GetApp().GetOrmDb(constant.ADMIN_DB).Select("*").Omit("idx").Where("idx = ?", entity.Idx).Updates(&entity).Error
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Select("*").Omit("idx").Where("idx = ?", entity.Idx).Updates(&entity).Error
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": 1,

View File

@ -75,6 +75,14 @@ func (this *app) registerDataSources() {
mt.Table.FriendDb.GetById(0).GetPasswd(),
"admindb_dev",
)
f5.GetApp().RegisterOrmDb(
constant.ACCOUNT_DB,
mt.Table.AccountDb.GetById(0).GetHost(),
mt.Table.AccountDb.GetById(0).GetPort(),
mt.Table.AccountDb.GetById(0).GetUser(),
mt.Table.AccountDb.GetById(0).GetPasswd(),
mt.Table.AccountDb.GetById(0).GetDatabase(),
)
u := system.SysUser{}
f5.GetApp().GetOrmDb(constant.ADMIN_DB).First(&u)

View File

@ -5,9 +5,10 @@ const (
)
const (
GAME_DB = "gamedb"
FRIEND_DB = "firenddb"
ADMIN_DB = "admindb"
GAME_DB = "gamedb"
FRIEND_DB = "firenddb"
ADMIN_DB = "admindb"
ACCOUNT_DB = "accountdb"
)
const (

View File

@ -0,0 +1,42 @@
package cs
import (
"f5"
proto "github.com/golang/protobuf/proto"
)
type CsNetMsgHandler f5.NetMsgHandler[MsgHandler];
type MsgHandlerImpl struct {
}
var handlers [2000]*CsNetMsgHandler
func GetNetMsgHandler(msgId uint16) *CsNetMsgHandler {
handler := handlers[msgId]
return handler
}
func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
handler.Cb(hdr, msgHandler)
}
func RegHandlerId(msgId int, handlerId int) {
handler := handlers[msgId]
handler.HandlerId = handlerId
}
func ParsePb(msgId uint16, data []byte) interface{} {
handler := handlers[msgId]
if handler == nil {
return nil
}
return handler.ParseCb(data)
}
type MsgHandler interface {
}
func init() {
}

View File

@ -0,0 +1,15 @@
package mt
import (
"f5"
"mtb"
)
type AccountDb struct {
mtb.AccountDb
}
type AccountDbTable struct {
f5.IdMetaTable[AccountDb]
selfConf *AccountDb
}

View File

@ -6,29 +6,35 @@ import (
type table struct {
AdminCluster *AdminClusterTable
GameDb *GameDbTable
FriendDb *FriendDbTable
Config *ConfigTable
GameDb *GameDbTable
FriendDb *FriendDbTable
AccountDb *AccountDbTable
Config *ConfigTable
}
var Table = f5.New(func (this* table) {
this.AdminCluster = f5.New(func (this *AdminClusterTable) {
var Table = f5.New(func(this *table) {
this.AdminCluster = f5.New(func(this *AdminClusterTable) {
this.FileName = "../config/adminserver.cluster.json"
this.PrimKey = "instance_id"
});
})
this.GameDb = f5.New(func (this *GameDbTable) {
this.GameDb = f5.New(func(this *GameDbTable) {
this.FileName = "../config/gamedb.mysql.json"
this.PrimKey = ""
});
})
this.FriendDb = f5.New(func (this *FriendDbTable) {
this.FriendDb = f5.New(func(this *FriendDbTable) {
this.FileName = "../config/frienddb.mysql.json"
this.PrimKey = ""
});
})
this.Config = f5.New(func (this *ConfigTable) {
this.AccountDb = f5.New(func(this *AccountDbTable) {
this.FileName = "../config/accountdb.mysql.json"
this.PrimKey = ""
})
this.Config = f5.New(func(this *ConfigTable) {
this.FileName = "../config/config.json"
this.PrimKey = ""
});
})
})

View File

@ -13,15 +13,6 @@ type AdminCluster struct {
_flags2_ uint64
}
type MasterCluster struct {
instance_id int32
ip string
listen_port int32
_flags1_ uint64
_flags2_ uint64
}
type GameDb struct {
host string
port int32
@ -44,6 +35,28 @@ type FriendDb struct {
_flags2_ uint64
}
type AdminDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type AccountDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type Config struct {
gameapi_url string
@ -75,30 +88,6 @@ func (this *AdminCluster) HasHttpListenPort() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *MasterCluster) GetInstanceId() int32 {
return this.instance_id
}
func (this *MasterCluster) HasInstanceId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *MasterCluster) GetIp() string {
return this.ip
}
func (this *MasterCluster) HasIp() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *MasterCluster) GetListenPort() int32 {
return this.listen_port
}
func (this *MasterCluster) HasListenPort() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *GameDb) GetHost() string {
return this.host
}
@ -179,6 +168,86 @@ func (this *FriendDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *AdminDb) GetHost() string {
return this.host
}
func (this *AdminDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *AdminDb) GetPort() int32 {
return this.port
}
func (this *AdminDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *AdminDb) GetUser() string {
return this.user
}
func (this *AdminDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *AdminDb) GetPasswd() string {
return this.passwd
}
func (this *AdminDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *AdminDb) GetDatabase() string {
return this.database
}
func (this *AdminDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *AccountDb) GetHost() string {
return this.host
}
func (this *AccountDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *AccountDb) GetPort() int32 {
return this.port
}
func (this *AccountDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *AccountDb) GetUser() string {
return this.user
}
func (this *AccountDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *AccountDb) GetPasswd() string {
return this.passwd
}
func (this *AccountDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *AccountDb) GetDatabase() string {
return this.database
}
func (this *AccountDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *Config) GetGameapiUrl() string {
return this.gameapi_url
}
@ -194,12 +263,6 @@ func (this *AdminCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.http_listen_port, "http_listen_port", &this._flags1_, 3, kv)
}
func (this *MasterCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.ip, "ip", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 3, kv)
}
func (this *GameDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
@ -216,6 +279,22 @@ func (this *FriendDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *AdminDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *AccountDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
}
func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv)
}

View File

@ -0,0 +1,3 @@
syntax = "proto2";
package cs;
option go_package = ".;cs";

View File

@ -0,0 +1,3 @@
syntax = "proto2";
package cs;
option go_package = ".;cs";

View File

@ -36,6 +36,15 @@ message AdminDb
optional string database = 5;
}
message AccountDb
{
optional string host = 1;
optional int32 port = 2;
optional string user = 3;
optional string passwd = 4;
optional string database = 5;
}
message Config
{
optional string gameapi_url = 1;

View File

@ -0,0 +1,3 @@
syntax = "proto2";
package ss;
option go_package = ".;ss";

View File

@ -0,0 +1,4 @@
syntax = "proto2";
package ss;
option go_package = ".;ss";

View File

@ -0,0 +1,42 @@
package ss
import (
"f5"
proto "github.com/golang/protobuf/proto"
)
type SsNetMsgHandler f5.NetMsgHandler[MsgHandler];
type MsgHandlerImpl struct {
}
var handlers [2000]*SsNetMsgHandler
func GetNetMsgHandler(msgId uint16) *SsNetMsgHandler {
handler := handlers[msgId]
return handler
}
func DispatchMsg(handler *SsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
handler.Cb(hdr, msgHandler)
}
func RegHandlerId(msgId int, handlerId int) {
handler := handlers[msgId]
handler.HandlerId = handlerId
}
func ParsePb(msgId uint16, data []byte) interface{} {
handler := handlers[msgId]
if handler == nil {
return nil
}
return handler.ParseCb(data)
}
type MsgHandler interface {
}
func init() {
}