This commit is contained in:
aozhiwei 2024-08-10 19:56:45 +08:00
parent 8b2b78dfb1
commit a565eccd43
27 changed files with 0 additions and 1716 deletions

View File

@ -1,67 +0,0 @@
package app
import (
"f5"
//"main/constant"
"main/mt"
"main/middleware"
. "main/global"
)
type app struct {
initCb func()
unInitCb func()
}
func (this *app) GetPkgName() string {
return "mailserver"
}
func (this *app) GetHttpListenPort() int32 {
return mt.Table.MailCluster.GetHttpListenPort()
}
func (this *app) Run(initCb func(), unInitCb func()) {
this.initCb = initCb
this.unInitCb = unInitCb
f5.Run(this)
}
func (this *app) Init() {
f5.LoadMetaTable(mt.Table)
this.registerDataSources()
this.initCb()
f5.GetApp().GetGinEngine().Use(middleware.CaForward, middleware.CaAuth)
}
func (this *app) UnInit() {
this.unInitCb()
}
func (this *app) Update() {
}
func (this *app) registerDataSources() {
/*
f5.GetGoStyleDb().RegisterDataSource(
constant.MAIL_DB,
mt.Table.MailDb.GetById(0).GetHost(),
mt.Table.MailDb.GetById(0).GetPort(),
mt.Table.MailDb.GetById(0).GetUser(),
mt.Table.MailDb.GetById(0).GetPasswd(),
mt.Table.MailDb.GetById(0).GetDatabase(),
3)
f5.GetJsStyleDb().RegisterDataSource(
constant.MAIL_DB,
mt.Table.MailDb.GetById(0).GetHost(),
mt.Table.MailDb.GetById(0).GetPort(),
mt.Table.MailDb.GetById(0).GetUser(),
mt.Table.MailDb.GetById(0).GetPasswd(),
mt.Table.MailDb.GetById(0).GetDatabase(),
1)
*/
}
func (this *app) HasTask() bool {
return GetMailMgr().HasTask()
}

View File

@ -1,12 +0,0 @@
package app
import (
"main/constant"
"main/global"
)
var _app = new(app)
func init() {
global.RegModule(constant.APP_MODULE_IDX, _app)
}

View File

@ -1,62 +0,0 @@
package common
import (
"github.com/gin-gonic/gin"
)
type AttachmentDto struct {
ItemId int32 `json:"itemid"`
ItemNum int32 `json:"itemnum"`
}
type MailDto struct {
MailId string `json:"mailid"`
From string `json:"from"`
To string `json:"to"`
Subject string `json:"subject"`
Content string `json:"content"`
Flags int32 `json:"flags"`
SendTime int32 `json:"sendtime"`
ExpireTime int32 `json:"expiretime"`
MailType int32 `json:"mailtype"`
MailSubType int32 `json:"mailsubtype"`
Ext string `json:"ext"`
Attachments []*AttachmentDto `json:"attachments"`
}
type App interface {
Run(func(), func())
}
type Player interface {
Lock() bool
UnLock()
GetAccountId() string
GetRegisterTime() int32
MarkMails([]Mail) error
GetAttachment([]Mail) error
DeleteMails([]Mail) error
IsReadable(Mail) bool
IsUnread(Mail) bool
}
type PlayerMgr interface {
GetPlayerByAccountId(string) Player
ForceCreatePlayer(string, string) Player
}
type Mail interface {
GetMailId() int64
IsValid(Player) bool
GetExpireTime() int32
}
type MailMgr interface{
CaGetMailList(c *gin.Context)
CaMarkMail(c *gin.Context)
CaGetUnreadMailCnt(c *gin.Context)
CaGetAttachment(c *gin.Context)
CaDeleteMails(c *gin.Context)
HasTask() bool
}

View File

@ -1,29 +0,0 @@
package constant
const (
MAIL_DB = "maildb"
)
const (
APP_MODULE_IDX = iota
PLAYER_MGR_MODULE_IDX
MAIL_MGR_MODULE_IDX
CONTROLLER_MGR_MODULE_IDX
MAX_MODULE_IDX
)
const (
MAIL_TYPE_GROUP = 1
MAIL_TYPE_ALL = 2
)
const (
INBOX_STATE_NONE = 0
INBOX_STATE_READ = 1
INBOX_STATE_DELETED = 2
)
const (
EVENT_MAIL_UPDATE = "mail.update"
EVENT_UPSER_GROUP_UPDATE = "user_group.update"
)

View File

@ -1,5 +0,0 @@
package controller
import (
)

View File

@ -1,67 +0,0 @@
package global
import (
"fmt"
"main/common"
"main/constant"
"q5"
)
var modules [constant.MAX_MODULE_IDX]q5.Module
var initOrders = []int32{
constant.PLAYER_MGR_MODULE_IDX,
constant.MAIL_MGR_MODULE_IDX,
}
var app common.App
var playerMgr common.PlayerMgr
var mailMgr common.MailMgr
func GetApp() common.App {
return app
}
func GetMailMgr() common.MailMgr {
return mailMgr
}
func GetPlayerMgr() common.PlayerMgr {
return playerMgr
}
func RegModule(idx int32, m q5.Module) {
fmt.Printf("RegModule module %d\n", idx)
modules[idx] = m
switch idx {
case constant.APP_MODULE_IDX:
{
app = m.(common.App)
}
case constant.PLAYER_MGR_MODULE_IDX:
{
playerMgr = m.(common.PlayerMgr)
}
case constant.MAIL_MGR_MODULE_IDX:
{
mailMgr = m.(common.MailMgr)
}
default:
{
panic("unknow module")
}
}
}
func InitModules() {
for _, val := range initOrders {
fmt.Printf("init module %d\n", val)
modules[val].Init()
}
}
func UnInitModules() {
for _, val := range initOrders {
fmt.Printf("unInit module %d", val)
modules[val].UnInit()
}
}

View File

@ -1,51 +0,0 @@
module gateserver
go 1.20
require q5 v1.0.0
require f5 v1.0.0
require main v1.0.0
require github.com/gin-gonic/gin v1.9.1
require (
github.com/bytedance/sonic v1.10.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.4 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gomodule/redigo v1.8.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.1 // indirect
gorm.io/gorm v1.25.4 // indirect
)
replace q5 => ../../third_party/q5
replace f5 => ../../third_party/f5
replace main => ./

View File

@ -1,103 +0,0 @@
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc=
github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.15.4 h1:zMXza4EpOdooxPel5xDqXEdXG5r+WggpvnAKMsalBjs=
github.com/go-playground/validator/v10 v10.15.4/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gomodule/redigo v1.8.3 h1:HR0kYDX2RJZvAup8CsiJwxB4dTCSC0AaUq6S4SiLwUc=
github.com/gomodule/redigo v1.8.3/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y=
golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw=
gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

View File

@ -1,13 +0,0 @@
package initialize
import (
_ "main/app"
. "main/global"
_ "main/mail"
_ "main/player"
_ "main/controller"
)
func Init() {
GetApp().Run(InitModules, UnInitModules)
}

View File

@ -1,12 +0,0 @@
package mail
import (
"main/constant"
"main/global"
)
var _mailMgr = new(mailMgr)
func init() {
global.RegModule(constant.MAIL_MGR_MODULE_IDX, _mailMgr)
}

View File

@ -1,177 +0,0 @@
package mail
import (
"q5"
"f5"
"sync"
"main/common"
"main/constant"
)
type attachment struct {
itemId int32 `json:"itemid"`
itemNum int32 `json:"itemnum"`
}
type mail struct {
mailId int64
mailType int32
subject string
content string
sendTime int32
expireTime int32
userRegStartTime int32
userRegEndTime int32
attachments []*attachment
recipients *sync.Map //account_id, int
userGroups *sync.Map //group_id, *userGroup
}
func (this *mail) init() {
this.attachments = []*attachment{}
}
func (this *mail) loadFromDb(ds *f5.DataSet) {
this.mailId = q5.ToInt64(ds.GetByName("mail_id"))
this.mailType = q5.ToInt32(ds.GetByName("mail_type"))
this.subject = ds.GetByName("subject")
this.content = ds.GetByName("content")
this.sendTime = q5.ToInt32(ds.GetByName("sendtime"))
this.expireTime = q5.ToInt32(ds.GetByName("expiretime"))
this.userRegStartTime = q5.ToInt32(ds.GetByName("user_reg_start_time"))
this.userRegEndTime = q5.ToInt32(ds.GetByName("user_reg_end_time"))
{
attachmentsStr := ds.GetByName("attachments")
if attachmentsStr != "" {
if err := q5.DecodeJson(attachmentsStr, &this.attachments); err != nil {
panic("mail.loadFromDb parse attachments error " + q5.ToString(this.mailId))
}
}
}
{
recipientsStr := ds.GetByName("recipients")
if recipientsStr != "" {
recipientsList := []string{}
if err := q5.DecodeJson(recipientsStr, recipientsList); err != nil {
panic("mail.loadFromDb parse recipients error " + q5.ToString(this.mailId))
}
/*
for _, recipient := range(recipientsList) {
//this.recipients[recipient] = 1
}*/
}
}
}
func (this *mail) isType(mailType int32) bool {
return this.mailType == mailType
}
func (this *mail) IsValid(hum common.Player) bool {
if f5.GetApp().GetRealSeconds() < int64(this.expireTime) &&
hum.GetRegisterTime() >= this.userRegStartTime &&
hum.GetRegisterTime() <= this.userRegEndTime {
if this.mailType == constant.MAIL_TYPE_GROUP {
return this.isMailUser(hum.GetAccountId())
} else if this.mailType == constant.MAIL_TYPE_ALL {
return true
}
}
return false
}
func (this *mail) GetMailId() int64 {
return this.mailId
}
func (this *mail) GetExpireTime() int32 {
return this.expireTime
}
func (this *mail) fillMailDto(hum common.Player, p *common.MailDto) bool {
p.MailId = q5.ToString(this.mailId)
p.From = ""
p.To = ""
p.Subject = this.subject
p.Content = this.content
//p.Flags
if !hum.IsUnread(this) {
p.Flags = 1 << 0
} else {
p.Flags = 0
}
p.SendTime = this.sendTime
p.ExpireTime = this.expireTime
p.MailType = this.mailType
p.MailSubType = 0
p.Ext = ""
p.Attachments = make([]*common.AttachmentDto, 0)
for _, ele := range(this.attachments) {
attachment := new(common.AttachmentDto)
attachment.ItemId = ele.itemId
attachment.ItemNum = ele.itemNum
}
return true
}
func (this* mail) isMailUser(accountId string) bool {
{
p := this.recipients
if p != nil {
if _, ok := p.Load(accountId); ok {
return true
}
}
}
{
found := false
this.traverseUserGroup(
func (groupId int64, group *userGroup) bool {
if group != nil {
if _, ok := group.userHash.Load(accountId); ok {
found = true
return false
}
}
return true
})
if found {
return true
}
}
return false
}
func (this *mail) traverseRecipients(cb func(string) bool) {
p := this.recipients
if p != nil {
p.Range(func (k, v interface{}) bool {
return cb(k.(string))
})
}
}
func (this *mail) traverseUserGroup(cb func(int64, *userGroup) bool) {
p := this.userGroups
if p != nil {
p.Range(func (k, v interface{}) bool {
if v != nil {
return cb(k.(int64), v.(*userGroup))
} else {
g := _mailMgr.getGroup(k.(int64))
if g != nil {
p.Store(k, g)
return cb(k.(int64), g)
} else {
return cb(k.(int64), nil)
}
}
})
}
}
func newMail() *mail {
p := new(mail)
p.init()
return p
}

View File

@ -1,508 +0,0 @@
package mail
import (
"q5"
"f5"
"main/common"
"main/constant"
"sync"
"fmt"
"github.com/gin-gonic/gin"
)
type dbEvent struct {
idx int64
eventName string
param1 string
entry q5.ListHead
}
type userGroup struct {
groupId int64
userHash *sync.Map
}
type mailMgr struct {
idHash sync.Map //int64 => *mail
wholeMails sync.Map //int64 => *mail
groupMails sync.Map //int64 => *mail
personalMails sync.Map //string => sync.Map<int64, *mail>
groupHash sync.Map //int64 => *userGroup
lastSyncEventIdx int64
pullingEvent bool
procingEvent bool
eventQueue q5.Queue
timerWp *f5.TimerWp
}
func (this *mailMgr) Init() {
this.eventQueue.Init()
this.syncEvent()
this.loadMails()
this.loadGroups()
this.loadGroupMembers()
f5.GetApp().RegisterCaHandle("Mail", "getMailList", this.CaGetMailList)
f5.GetApp().RegisterCaHandle("Mail", "markMail", this.CaMarkMail)
f5.GetApp().RegisterCaHandle("Mail", "getUnreadMailCnt", this.CaGetUnreadMailCnt)
f5.GetApp().RegisterCaHandle("Mail", "getAttachment", this.CaGetAttachment)
f5.GetApp().RegisterCaHandle("Mail", "deleteMails", this.CaDeleteMails)
this.timerWp = f5.GetTimer().SetIntervalWp(
300,
func (e int32, args* q5.Args) {
if e == q5.TIMER_EXEC_EVENT {
this.updateDbEvent()
}
})
}
func (this *mailMgr) UnInit() {
f5.GetTimer().Delete(this.timerWp)
this.timerWp = nil
}
func (this *mailMgr) loadMails() {
f5.GetSysLog().Info("mailMgr.loadMails begin")
nowTime := f5.GetApp().GetNowSeconds()
lastIdx := f5.GetGoStyleDb().SyncBatchLoadFullTable(
constant.MAIL_DB,
"SELECT * FROM t_mail WHERE idx > %d AND deleted = 0 AND expiretime > " + q5.ToString(nowTime),
func (ds *f5.DataSet) {
p := newMail()
p.loadFromDb(ds)
this.addMail(p)
},
func (err error) {
panic(fmt.Sprintf("mailMgr.loadMails dberror:%s", err))
})
f5.GetSysLog().Info("mailMgr.loadMails end lastIdx:%d mailNum:%d",
lastIdx,
q5.GetSyncMapSize(this.idHash))
}
func (this *mailMgr) loadGroups() {
f5.GetSysLog().Info("mailMgr.loadGroups begin")
lastIdx := f5.GetGoStyleDb().SyncBatchLoadFullTable(
constant.MAIL_DB,
"SELECT * FROM t_group WHERE idx > %d AND deleted = 0",
func (ds *f5.DataSet) {
groupId := q5.ToInt64(ds.GetByName("group_id"))
if this.getGroup(groupId) != nil {
panic(fmt.Sprintf("mailMgr.loadGroups group_id error"))
}
p := newUserGroup()
p.groupId = groupId
this.addGroup(p)
},
func (err error) {
panic(fmt.Sprintf("mailMgr.loadGroups dberror:%s", err))
})
f5.GetSysLog().Info("mailMgr.loadGroups end lastIdx:%d mailNum:%d",
lastIdx,
q5.GetSyncMapSize(this.idHash))
}
func (this *mailMgr) loadGroupMembers() {
f5.GetSysLog().Info("mailMgr.loadGroupMembers begin")
lastIdx := f5.GetGoStyleDb().SyncBatchLoadFullTable(
constant.MAIL_DB,
"SELECT * FROM t_member WHERE idx > %d AND deleted = 0",
func (ds *f5.DataSet) {
groupId := q5.ToInt64(ds.GetByName("group_id"))
memberId := ds.GetByName("member_id")
p := this.getGroup(groupId)
if p != nil {
p.userHash.Store(memberId, q5.ToInt64(ds.GetByName("idx")))
}
},
func (err error) {
panic(fmt.Sprintf("mailMgr.loadGroupMembers dberror:%s", err))
})
f5.GetSysLog().Info("mailMgr.loadGroupMembers end lastIdx:%d mailNum:%d",
lastIdx,
q5.GetSyncMapSize(this.idHash))
}
func (this *mailMgr) CaGetMailList(c *gin.Context) {
hum := c.MustGet("hum").(common.Player)
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
MailList []*common.MailDto `json:"mail_list"`
}{
MailList: []*common.MailDto{},
}
this.traversePlayerMail(
hum,
func (m *mail) bool {
if m.IsValid(hum) {
if hum.IsReadable(m) {
mailDto := new(common.MailDto)
if m.fillMailDto(hum, mailDto) {
q5.AppendSlice(&rspObj.MailList, mailDto)
}
}
}
return true
})
c.JSON(200, rspObj)
}
func (this *mailMgr) CaMarkMail(c *gin.Context) {
hum := c.MustGet("hum").(common.Player)
mailIds := q5.StrSplit(c.DefaultQuery("mail_ids", ""), ",")
mails := []common.Mail{}
for _, str := range(mailIds) {
m := this.getMail(str)
if m != nil && m.IsValid(hum) {
q5.AppendSlice(&mails, m)
}
}
hum.MarkMails(mails)
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
}{}
c.JSON(200, rspObj)
}
func (this *mailMgr) CaGetUnreadMailCnt(c *gin.Context) {
hum := c.MustGet("hum").(common.Player)
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
UnreadMailCnt int32 `json:"unread_mail_cnt"`
}{}
this.traversePlayerMail(
hum,
func (m *mail) bool {
if m.IsValid(hum) && hum.IsUnread(m) {
rspObj.UnreadMailCnt++
return false
}
return true
})
c.JSON(200, rspObj)
}
func (this *mailMgr) CaGetAttachment(c *gin.Context) {
hum := c.MustGet("hum").(common.Player)
mailIds := q5.StrSplit(c.DefaultQuery("mail_ids", ""), ",")
mails := []common.Mail{}
for _, str := range(mailIds) {
m := this.getMail(str)
if m != nil && m.IsValid(hum) {
q5.AppendSlice(&mails, m)
}
}
hum.GetAttachment(mails)
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
}{}
c.JSON(200, rspObj)
}
func (this *mailMgr) CaDeleteMails(c *gin.Context) {
hum := c.MustGet("hum").(common.Player)
mailIds := q5.StrSplit(c.DefaultQuery("mail_ids", ""), ",")
mails := []common.Mail{}
for _, str := range(mailIds) {
m := this.getMail(str)
if m != nil && m.IsValid(hum) {
q5.AppendSlice(&mails, m)
}
}
hum.DeleteMails(mails)
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
}{}
c.JSON(200, rspObj)
}
func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) {
stop := false
traversedMails := make(map[int64]*mail, 10)
traversFunc := func (k, v interface{}) bool {
m := v.(*mail)
if m.IsValid(hum) {
if _, ok := traversedMails[m.mailId]; ok {
return true
}
if !(cb(m)) {
stop = true
return false
}
traversedMails[m.mailId] = m
}
return true
}
this.wholeMails.Range(traversFunc)
if stop {
return
}
this.groupMails.Range(traversFunc)
if stop {
return
}
if p, ok := this.personalMails.Load(hum.GetAccountId()); ok {
(p.(*sync.Map)).Range(traversFunc)
}
}
func (this *mailMgr) removeMail(m *mail) {
this.idHash.Delete(m.mailId)
if m.isType(constant.MAIL_TYPE_ALL) {
this.wholeMails.Delete(m.mailId)
} else if m.isType(constant.MAIL_TYPE_GROUP) {
m.traverseUserGroup(
func (int64, *userGroup) bool {
this.groupMails.Delete(m.mailId)
return false
})
m.traverseRecipients(
func (accountId string) bool {
if p, ok := this.personalMails.Load(accountId); ok {
(p.(*sync.Map)).Delete(m.mailId)
}
return true
})
}
}
func (this *mailMgr) addMail(m *mail) {
this.idHash.Store(m.mailId, m)
if m.isType(constant.MAIL_TYPE_ALL) {
this.wholeMails.Store(m.mailId, m)
} else if m.isType(constant.MAIL_TYPE_GROUP) {
m.traverseUserGroup(
func (int64, *userGroup) bool {
this.groupMails.Store(m.mailId, m)
return false
})
m.traverseRecipients(
func (accountId string) bool {
if p, ok := this.personalMails.Load(accountId); ok {
(p.(*sync.Map)).Store(m.mailId, m)
} else {
p := new(sync.Map)
p.Store(m.mailId, m)
this.personalMails.Store(accountId, p)
}
return true
})
}
}
func (this *mailMgr) updateMail(m *mail) {
oldM := this.internalGetMail(m.mailId)
if oldM == nil {
this.addMail(m)
return
}
if oldM.mailType != m.mailType {
panic(fmt.Sprintf("updateMail mailType error"));
return
}
this.removeMail(oldM)
this.addMail(m)
}
func (this *mailMgr) addGroup(g *userGroup) {
this.groupHash.Store(g.groupId, g)
}
func (this *mailMgr) getGroup(groupId int64) *userGroup {
if p, ok := this.groupHash.Load(groupId); ok {
return p.(*userGroup)
} else {
return nil
}
}
func (this *mailMgr) getMail(mailId string) common.Mail {
if m := this.internalGetMail(q5.ToInt64(mailId)); m != nil {
return m
} else {
return nil
}
}
func (this *mailMgr) internalGetMail(mailId int64) *mail {
if p, ok := this.idHash.Load(mailId); ok {
return p.(*mail)
} else {
return nil
}
}
func (this *mailMgr) syncEvent() {
f5.GetGoStyleDb().SyncSelectCustomQuery(
constant.MAIL_DB,
"SELECT MAX(idx) FROM t_event;",
func(err error, ds *f5.DataSet) {
if err != nil {
panic("sync event error")
return
}
if ds.Next() {
this.lastSyncEventIdx = q5.ToInt64(ds.GetByIndex(0))
} else {
panic("sync event error")
}
});
f5.GetTimer().SetInterval(
1000 * 2,
func (e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT {
this.pullEvent()
}
})
}
func (this *mailMgr) addDbEvent(e *dbEvent) {
this.eventQueue.Push(&e.entry)
}
func (this *mailMgr) updateDbEvent() {
if this.eventQueue.IsEmpty() {
return
}
if this.procingEvent {
return
}
this.eventQueue.Fetch()
for !this.eventQueue.WorkList.Empty() {
e := this.eventQueue.WorkList.FirstEntry().(*dbEvent)
if e.eventName == constant.EVENT_MAIL_UPDATE {
this.procMailUpdate(e)
break
} else if e.eventName == constant.EVENT_UPSER_GROUP_UPDATE {
this.procGroupUpdate(e)
break
} else {
e.entry.DelInit()
}
}
}
func (this *mailMgr) pullEvent() {
if this.pullingEvent {
return
}
this.pullingEvent = true
f5.GetJsStyleDb().SelectCustomQuery(
constant.MAIL_DB,
fmt.Sprintf("SELECT * FROM t_event WHERE idx > %d;", this.lastSyncEventIdx),
func(err error, ds *f5.DataSet) {
if err != nil {
this.pullingEvent = false
return
}
for ds.Next() {
e := new(dbEvent)
e.idx = q5.ToInt64(ds.GetByName("idx"))
e.eventName = ds.GetByName("event_name")
e.param1 = ds.GetByName("param1")
e.entry.Init(e)
_mailMgr.addDbEvent(e)
this.lastSyncEventIdx = q5.ToInt64(ds.GetByName("idx"))
}
this.pullingEvent = false
})
}
func (this* mailMgr) HasTask() bool {
return false
}
func (this* mailMgr) procMailUpdate(e *dbEvent) {
this.procingEvent = true
f5.GetJsStyleDb().OrmSelectOne(
constant.MAIL_DB,
"t_mail",
[][]string{
{"mail_id", e.param1},
},
func (err error, ds *f5.DataSet) {
this.procingEvent = false
if err != nil {
return
}
if ds.Next() {
p := newMail()
p.loadFromDb(ds)
this.updateMail(p)
} else {
panic(fmt.Sprintf("procMailUpdate error:%s", err));
}
e.entry.DelInit()
this.updateDbEvent()
})
}
func (this* mailMgr) procGroupUpdate(e *dbEvent) {
this.procingEvent = true
fetchMemberFunc := func () {
f5.GetJsStyleDb().OrmSelect(
constant.MAIL_DB,
"t_member",
[][]string{
{"group_id", e.param1},
{"deleted", "0"},
},
func (err error, ds *f5.DataSet) {
this.procingEvent = false
if err != nil {
return
}
groupId := q5.ToInt64(ds.GetByName("group_id"))
g := this.getGroup(groupId)
if g == nil {
p := newUserGroup()
p.groupId = groupId
this.addGroup(g)
} else {
g.userHash = new(sync.Map)
}
if ds.Next() {
memberId := ds.GetByName("member_id")
g.userHash.Store(memberId, q5.ToInt64(ds.GetByName("idx")))
return
} else {
panic(fmt.Sprintf("procGroupUpdate1 error:%s", err));
}
})
}
f5.GetJsStyleDb().OrmSelectOne(
constant.MAIL_DB,
"t_group",
[][]string{
{"group_id", e.param1},
},
func (err error, ds *f5.DataSet) {
if err != nil {
this.procingEvent = false
return
}
if ds.Next() {
deleted := q5.ToInt32(ds.GetByName("deleted"))
if deleted != 0 {
this.procingEvent = false
this.groupHash.Delete(q5.ToInt64(e.param1))
return
}
fetchMemberFunc()
return
} else {
this.procingEvent = false
panic(fmt.Sprintf("procGroupUpdate1 error:%s", err));
}
})
}
func newUserGroup() *userGroup {
g := new(userGroup)
g.userHash = new(sync.Map)
return g
}

View File

@ -1,9 +0,0 @@
package main
import (
"main/initialize"
)
func main() {
initialize.Init()
}

View File

@ -1,17 +0,0 @@
compile:
@. /etc/profile
@export GOPROXY=https://goproxy.io
@go build -gcflags=all="-N -l" -o ../../bin/gateserver/bin
@echo "compile done"
debug:
@. /etc/profile
@export GOPROXY=https://goproxy.io
@go build -gcflags=all="-N -l" -ldflags "-X q5.optDebug=1" -o ../../bin/gateserver/bin
@echo "compile done"
clean:
@rm -f ../../bin/gateserver/bin
@echo "clean done"

View File

@ -1,27 +0,0 @@
package middleware
import (
"github.com/gin-gonic/gin"
. "main/global"
"net/http"
)
func CaAuth(c *gin.Context) {
accountId := c.DefaultQuery("account_id", "")
sessionId := c.DefaultQuery("session_id", "")
hum := GetPlayerMgr().GetPlayerByAccountId(accountId)
if hum == nil {
hum = GetPlayerMgr().ForceCreatePlayer(accountId, sessionId)
}
if !hum.Lock() {
c.JSON(http.StatusOK, gin.H{
"errcode": 500,
"errmsg": "server internal error",
})
c.Abort()
return
}
c.Set("hum", hum)
c.Next()
hum.UnLock()
}

View File

@ -1,8 +0,0 @@
package middleware
import (
"github.com/gin-gonic/gin"
)
func CaForward(c *gin.Context) {
}

View File

@ -1,69 +0,0 @@
package model
import (
"q5"
"f5"
"main/constant"
)
type inbox struct {
}
var Inbox = new(inbox)
func (this *inbox) Mark(accountId string, mailId int64, nowTime int64, expireTime int32) error {
var result error
f5.GetGoStyleDb().Upsert(
constant.MAIL_DB,
"t_inbox",
[][]string{
{"account_id", accountId},
{"mail_id", q5.ToString(mailId)},
},
[][]string{
{"state", q5.ToString(constant.INBOX_STATE_READ)},
{"expiretime", q5.ToString(expireTime)},
{"modifytime", q5.ToString(nowTime)},
},
[][]string{
{"account_id", accountId},
{"mail_id", q5.ToString(mailId)},
{"state", q5.ToString(constant.INBOX_STATE_READ)},
{"expiretime", q5.ToString(expireTime)},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
result = err
})
return result
}
func (this *inbox) Delete(accountId string, mailId int64, nowTime int64, expireTime int32) error {
var result error
f5.GetGoStyleDb().Upsert(
constant.MAIL_DB,
"t_inbox",
[][]string{
{"account_id", accountId},
{"mail_id", q5.ToString(mailId)},
},
[][]string{
{"state", q5.ToString(constant.INBOX_STATE_DELETED)},
{"expiretime", q5.ToString(expireTime)},
{"modifytime", q5.ToString(nowTime)},
},
[][]string{
{"account_id", accountId},
{"mail_id", q5.ToString(mailId)},
{"state", q5.ToString(constant.INBOX_STATE_DELETED)},
{"expiretime", q5.ToString(expireTime)},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
},
func (err error, lastInsertId int64, rowsAffected int64) {
result = err
})
return result
}

View File

@ -1,19 +0,0 @@
package mt
import (
"f5"
"main/mtb"
)
type Config struct {
mtb.Config
}
type ConfigTable struct {
f5.IdMetaTable[Config]
selfConf *Config
}
func (this *ConfigTable) GetGameApiUrl() string {
return this.selfConf.GetGameapiUrl()
}

View File

@ -1,34 +0,0 @@
package mt
import (
"f5"
"main/mtb"
)
type MailCluster struct {
mtb.MailCluster
}
type MailClusterTable struct {
f5.IdMetaTable[MailCluster]
selfConf *MailCluster
}
func (this *MailCluster) Init1() {
}
func (this *MailClusterTable) GetListenPort() int32 {
return this.selfConf.GetListenPort()
}
func (this *MailClusterTable) GetHttpListenPort() int32 {
return this.selfConf.GetHttpListenPort()
}
func (this *MailClusterTable) PostInit1() {
this.selfConf = this.GetById(int64(f5.GetApp().GetInstanceId()))
if this.selfConf == nil {
panic("mailserver集群无法读取本服配置")
}
}

View File

@ -1,17 +0,0 @@
package mt
import (
"f5"
"main/mtb"
)
type MailDb struct {
mtb.MailDb
}
type MailDbTable struct {
f5.IdMetaTable[MailDb]
}
func (this *MailDb) Init1() {
}

View File

@ -1,28 +0,0 @@
package mt
import (
"f5"
)
type table struct {
MailCluster *MailClusterTable
MailDb *MailDbTable
Config *ConfigTable
}
var Table = f5.New(func(this *table) {
this.MailCluster = f5.New(func(this *MailClusterTable) {
this.FileName = "../config/mailserver.cluster.json"
this.PrimKey = "instance_id"
})
this.MailDb = f5.New(func(this *MailDbTable) {
this.FileName = "../config/maildb.mysql.json"
this.PrimKey = ""
})
this.Config = f5.New(func(this *ConfigTable) {
this.FileName = "../config/config.json"
this.PrimKey = ""
})
})

View File

@ -1,123 +0,0 @@
package mtb
import (
"f5"
)
type MailCluster struct {
instance_id int32
listen_port int32
http_listen_port int32
_flags1_ uint64
_flags2_ uint64
}
type MailDb struct {
host string
port int32
user string
passwd string
database string
_flags1_ uint64
_flags2_ uint64
}
type Config struct {
gameapi_url string
_flags1_ uint64
_flags2_ uint64
}
func (this *MailCluster) GetInstanceId() int32 {
return this.instance_id
}
func (this *MailCluster) HasInstanceId() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *MailCluster) GetListenPort() int32 {
return this.listen_port
}
func (this *MailCluster) HasListenPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *MailCluster) GetHttpListenPort() int32 {
return this.http_listen_port
}
func (this *MailCluster) HasHttpListenPort() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *MailDb) GetHost() string {
return this.host
}
func (this *MailDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *MailDb) GetPort() int32 {
return this.port
}
func (this *MailDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *MailDb) GetUser() string {
return this.user
}
func (this *MailDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *MailDb) GetPasswd() string {
return this.passwd
}
func (this *MailDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *MailDb) GetDatabase() string {
return this.database
}
func (this *MailDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *Config) GetGameapiUrl() string {
return this.gameapi_url
}
func (this *Config) HasGameapiUrl() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *MailCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.http_listen_port, "http_listen_port", &this._flags1_, 3, kv)
}
func (this *MailDb) 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

@ -1,12 +0,0 @@
package player
import (
"main/constant"
"main/global"
)
var _playerMgr = new(playerMgr)
func init() {
global.RegModule(constant.PLAYER_MGR_MODULE_IDX, _playerMgr)
}

View File

@ -1,180 +0,0 @@
package player
import (
"q5"
"f5"
"sync"
"main/common"
"main/constant"
"main/model"
)
type inbox struct {
mailId int64
state int32
expireTime int32
}
type player struct {
lock sync.Mutex
accountId string
sessionId string
registerTime int32
loaded bool
inboxHash map[int64]*inbox
}
func (this *player) init() {
this.inboxHash = make(map[int64]*inbox)
}
func (this *player) Lock() bool {
this.lock.Lock()
if !this.loaded {
this.load()
}
ok := this.loaded
if !ok {
this.UnLock()
}
return ok
}
func (this *player) UnLock() {
this.lock.Unlock()
}
func (this *player) GetAccountId() string {
return this.accountId
}
func (this *player) GetRegisterTime() int32 {
return this.registerTime
}
func (this *player) MarkMails(mails []common.Mail) error {
this.checkLock()
var resultErr error
var nowTime = f5.GetApp().GetRealSeconds()
for _, m := range(mails) {
if m.IsValid(this) {
mi := this.getInbox(m.GetMailId())
if mi == nil {
err := model.Inbox.Mark(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil {
resultErr = err
break
}
mi = new(inbox)
mi.mailId = m.GetMailId()
mi.state = constant.INBOX_STATE_READ
mi.expireTime = m.GetExpireTime()
this.inboxHash[mi.mailId] = mi
} else if mi.state != constant.INBOX_STATE_NONE {
err := model.Inbox.Mark(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil {
resultErr = err
break
}
mi.state = constant.INBOX_STATE_READ
mi.expireTime = m.GetExpireTime()
}
}
}
return resultErr
}
func (this *player) GetAttachment(mails []common.Mail) error {
return this.DeleteMails(mails)
}
func (this *player) DeleteMails(mails []common.Mail) error {
this.checkLock()
var resultErr error
var nowTime int64
for _, m := range(mails) {
if m.IsValid(this) {
mi := this.getInbox(m.GetMailId())
if mi == nil {
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil {
resultErr = err
break
}
mi = new(inbox)
mi.mailId = m.GetMailId()
mi.state = constant.INBOX_STATE_DELETED
mi.expireTime = m.GetExpireTime()
this.inboxHash[mi.mailId] = mi
} else if mi.state != constant.INBOX_STATE_DELETED {
err := model.Inbox.Delete(this.GetAccountId(), m.GetMailId(), nowTime, m.GetExpireTime())
if err != nil {
resultErr = err
break
}
mi.state = constant.INBOX_STATE_DELETED
mi.expireTime = m.GetExpireTime()
}
}
}
return resultErr
}
func (this *player) checkLock() {
if this.lock.TryLock() {
panic("player checkLock error")
}
}
func (this *player) load() {
f5.GetGoStyleDb().RawQuery(
constant.MAIL_DB,
"SELECT * FROM t_inbox WHERE account_id=? AND expiretime<?",
[]string{
this.GetAccountId(),
q5.ToString(f5.GetApp().GetRealSeconds() + 3600 * 24 * 7),
},
func (err error, ds *f5.DataSet) {
if err != nil {
return
}
for ds.Next() {
p := new(inbox)
p.mailId = q5.ToInt64(ds.GetByName("mail_id"))
p.state = q5.ToInt32(ds.GetByName("state"))
p.expireTime = q5.ToInt32(ds.GetByName("expiretime"))
this.inboxHash[p.mailId] = p
}
this.loaded = true
})
}
func (this *player) getInbox(mailId int64) *inbox {
if m, ok := this.inboxHash[mailId]; ok {
return m
} else {
return nil
}
}
func (this* player) IsReadable(m common.Mail) bool {
mi := this.getInbox(m.GetMailId())
if mi != nil {
return mi.state != constant.INBOX_STATE_DELETED
}
return true
}
func (this* player) IsUnread(m common.Mail) bool {
mi := this.getInbox(m.GetMailId())
if mi != nil {
return mi.state == constant.INBOX_STATE_NONE
}
return true
}
func newPlayer() *player {
p := new(player)
p.init()
return p
}

View File

@ -1,41 +0,0 @@
package player
import (
"f5"
"sync"
"main/common"
)
type playerMgr struct {
accountIdHash sync.Map
lock sync.Mutex
}
func (this *playerMgr) Init() {
}
func (this *playerMgr) UnInit() {
}
func (this *playerMgr) GetPlayerByAccountId(accountId string) common.Player {
if p, ok := this.accountIdHash.Load(accountId); ok {
return p.(*player)
} else {
return nil
}
}
func (this *playerMgr) ForceCreatePlayer(accountId string, sessionId string) common.Player {
defer this.lock.Unlock()
this.lock.Lock()
hum := this.GetPlayerByAccountId(accountId)
if hum == nil {
p := newPlayer()
p.accountId = accountId
p.sessionId = sessionId
p.registerTime = f5.ExtractRegisterTimeFromSessionId(sessionId)
hum = p
this.accountIdHash.Store(p.accountId, p)
}
return hum
}

View File

@ -1,24 +0,0 @@
package mt;
option go_package = ".;mt";
message MailCluster
{
optional int32 instance_id = 1;
optional int32 listen_port = 2;
optional int32 http_listen_port = 3;
}
message MailDb
{
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

@ -1,2 +0,0 @@
protoc --go_out=..\cs .\cs_*.proto
protoc --go_out=..\ss .\ss_*.proto