This commit is contained in:
aozhiwei 2023-09-08 19:03:27 +08:00
parent fe1acddcc8
commit 851f2aeead
6 changed files with 110 additions and 109 deletions

8
app.go
View File

@ -61,11 +61,11 @@ func (this *app) init(userApp UserApp) {
this.userApp = userApp this.userApp = userApp
this.nowTime = time.Now() this.nowTime = time.Now()
atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano())
_timer = &Timer{} _timer = new(timer)
_timer.init() _timer.init()
_sysLog = new(SysLog_) _sysLog = new(sysLog)
_sysLog.init() _sysLog.init()
_tgLog = new(TGLog_) _tgLog = new(tgLog)
_tgLog.init() _tgLog.init()
_dbFilter = new(dbFilter) _dbFilter = new(dbFilter)
_dbFilter.init() _dbFilter.init()
@ -73,7 +73,7 @@ func (this *app) init(userApp UserApp) {
_goStyleDb.init(GO_STYLE_DB) _goStyleDb.init(GO_STYLE_DB)
_jsStyleDb = new(dbPool) _jsStyleDb = new(dbPool)
_jsStyleDb.init(JS_STYLE_DB) _jsStyleDb.init(JS_STYLE_DB)
_httpCliMgr = new(HttpCliMgr) _httpCliMgr = new(httpCliMgr)
_httpCliMgr.init() _httpCliMgr.init()
{ {
tmpNodeId, tmpInstanceId := parseArgs() tmpNodeId, tmpInstanceId := parseArgs()

View File

@ -1,10 +1,10 @@
package f5 package f5
var _app *app var _app *app
var _timer *Timer var _timer *timer
var _sysLog *SysLog_ var _sysLog *sysLog
var _tgLog *TGLog_ var _tgLog *tgLog
var _httpCliMgr *HttpCliMgr var _httpCliMgr *httpCliMgr
var _dbFilter *dbFilter var _dbFilter *dbFilter
var _goStyleDb *dbPool var _goStyleDb *dbPool
var _jsStyleDb *dbPool var _jsStyleDb *dbPool
@ -13,19 +13,19 @@ func GetApp() App {
return _app return _app
} }
func GetTimer() *Timer { func GetTimer() *timer {
return _timer return _timer
} }
func GetSysLog() *SysLog_ { func GetSysLog() *sysLog {
return _sysLog return _sysLog
} }
func GetTgLog() *TGLog_ { func GetTgLog() *tgLog {
return _tgLog return _tgLog
} }
func GetHttpCliMgr() *HttpCliMgr { func GetHttpCliMgr() *httpCliMgr {
return _httpCliMgr return _httpCliMgr
} }

View File

@ -32,11 +32,11 @@ type httpCliResponse struct {
isTimeOut bool isTimeOut bool
} }
type HttpCliMgr struct { type httpCliMgr struct {
} }
func (this *HttpCliMgr) init() { func (this *httpCliMgr) init() {
_app.RegisterIMMsgHandle( _app.RegisterIMMsgHandle(
IM_HTTP_CLI_MGR_RESPONSE, IM_HTTP_CLI_MGR_RESPONSE,
func (args q5.Args) { func (args q5.Args) {
@ -46,10 +46,10 @@ func (this *HttpCliMgr) init() {
}) })
} }
func (this *HttpCliMgr) unInit() { func (this *httpCliMgr) unInit() {
} }
func (this *HttpCliMgr) SendGoStyleRequest( func (this *httpCliMgr) SendGoStyleRequest(
url string, params map[string]string, url string, params map[string]string,
cb func (HttpCliResponse)) { cb func (HttpCliResponse)) {
this.internalSendRequest( this.internalSendRequest(
@ -60,7 +60,7 @@ func (this *HttpCliMgr) SendGoStyleRequest(
cb) cb)
} }
func (this *HttpCliMgr) SendJsStyleRequest( func (this *httpCliMgr) SendJsStyleRequest(
url string, params map[string]string, url string, params map[string]string,
cb func (HttpCliResponse)) { cb func (HttpCliResponse)) {
this.internalSendRequest( this.internalSendRequest(
@ -71,7 +71,7 @@ func (this *HttpCliMgr) SendJsStyleRequest(
cb) cb)
} }
func (this *HttpCliMgr) SendQuickChannelGoStyleRequest( func (this *httpCliMgr) SendQuickChannelGoStyleRequest(
url string, params map[string]string, url string, params map[string]string,
cb func (HttpCliResponse)) { cb func (HttpCliResponse)) {
this.internalSendRequest( this.internalSendRequest(
@ -82,7 +82,7 @@ func (this *HttpCliMgr) SendQuickChannelGoStyleRequest(
cb) cb)
} }
func (this *HttpCliMgr) SendQuickChannelJsStyleRequest( func (this *httpCliMgr) SendQuickChannelJsStyleRequest(
url string, params map[string]string, url string, params map[string]string,
cb func (HttpCliResponse)) { cb func (HttpCliResponse)) {
this.internalSendRequest( this.internalSendRequest(
@ -93,15 +93,15 @@ func (this *HttpCliMgr) SendQuickChannelJsStyleRequest(
cb) cb)
} }
func (this *HttpCliMgr) internalSendRequest( func (this *httpCliMgr) internalSendRequest(
style int32, channel int32, style int32, channel int32,
url string, params map[string]string, url string, params map[string]string,
cb func (HttpCliResponse)) { cb func (HttpCliResponse)) {
if !(style == GO_STYLE_REQUEST || style == JS_STYLE_REQUEST) { if !(style == GO_STYLE_REQUEST || style == JS_STYLE_REQUEST) {
panic("HttpCliMgr sytel error") panic("httpCliMgr sytel error")
} }
if !(channel == NORMAL_CHANNEL || channel == QUICK_CHANNEL) { if !(channel == NORMAL_CHANNEL || channel == QUICK_CHANNEL) {
panic("HttpCliMgr channel error") panic("httpCliMgr channel error")
} }
doFunc := func() { doFunc := func() {
data, err := q5.HttpGet(url, params) data, err := q5.HttpGet(url, params)

View File

@ -22,81 +22,81 @@ const (
SYS_LOG_FILENAME = "log_%d_%s.log" SYS_LOG_FILENAME = "log_%d_%s.log"
) )
type LogMsgNode struct { type logMsgNode struct {
category int32 category int32
logMsg string logMsg string
next *LogMsgNode next *logMsgNode
} }
type SysLog_ struct { type sysLog struct {
logLevel int32 logLevel int32
topNode *LogMsgNode topNode *logMsgNode
botNode *LogMsgNode botNode *logMsgNode
msgMutex sync.Mutex msgMutex sync.Mutex
chGoSaveExit chan int chGoSaveExit chan int
} }
func (this *SysLog_) init() { func (this *sysLog) init() {
this.chGoSaveExit = make(chan int) this.chGoSaveExit = make(chan int)
go this.goSaveToFile() go this.goSaveToFile()
} }
func (this *SysLog_) unInit() { func (this *sysLog) unInit() {
this.chGoSaveExit <- 1 this.chGoSaveExit <- 1
} }
func (this *SysLog_) Emergency(format string, args ...interface{}) { func (this *sysLog) Emergency(format string, args ...interface{}) {
if this.logLevel > LOG_EMERGENCY { if this.logLevel > LOG_EMERGENCY {
return return
} }
this.addLog(LOG_EMERGENCY, "[EMERGENCY]", format, args...) this.addLog(LOG_EMERGENCY, "[EMERGENCY]", format, args...)
} }
func (this *SysLog_) Alert(format string, args ...interface{}) { func (this *sysLog) Alert(format string, args ...interface{}) {
if this.logLevel > LOG_ALERT { if this.logLevel > LOG_ALERT {
return return
} }
this.addLog(LOG_ALERT, "[ALERT]", format, args...) this.addLog(LOG_ALERT, "[ALERT]", format, args...)
} }
func (this *SysLog_) Error(format string, args ...interface{}) { func (this *sysLog) Error(format string, args ...interface{}) {
if this.logLevel > LOG_ERROR { if this.logLevel > LOG_ERROR {
return return
} }
this.addLog(LOG_ERROR, "[ERROR]", format, args...) this.addLog(LOG_ERROR, "[ERROR]", format, args...)
} }
func (this *SysLog_) Warning(format string, args ...interface{}) { func (this *sysLog) Warning(format string, args ...interface{}) {
if this.logLevel > LOG_WARNING { if this.logLevel > LOG_WARNING {
return return
} }
this.addLog(LOG_WARNING, "[WARNING]", format, args...) this.addLog(LOG_WARNING, "[WARNING]", format, args...)
} }
func (this *SysLog_) Notice(format string, args ...interface{}) { func (this *sysLog) Notice(format string, args ...interface{}) {
if this.logLevel > LOG_NOTICE { if this.logLevel > LOG_NOTICE {
return return
} }
this.addLog(LOG_NOTICE, "[NOTICE]", format, args...) this.addLog(LOG_NOTICE, "[NOTICE]", format, args...)
} }
func (this *SysLog_) Info(format string, args ...interface{}) { func (this *sysLog) Info(format string, args ...interface{}) {
if this.logLevel > LOG_INFO { if this.logLevel > LOG_INFO {
return return
} }
this.addLog(LOG_INFO, "[INFO]", format, args...) this.addLog(LOG_INFO, "[INFO]", format, args...)
} }
func (this *SysLog_) Debug(format string, args ...interface{}) { func (this *sysLog) Debug(format string, args ...interface{}) {
if this.logLevel > LOG_DEBUG { if this.logLevel > LOG_DEBUG {
return return
} }
this.addLog(LOG_DEBUG, "[DEBUG]", format, args...) this.addLog(LOG_DEBUG, "[DEBUG]", format, args...)
} }
func (this *SysLog_) addLog(category int32, prefixStr string, func (this *sysLog) addLog(category int32, prefixStr string,
format string, args ...interface{}) { format string, args ...interface{}) {
p := &LogMsgNode{} p := &logMsgNode{}
p.category = category p.category = category
p.logMsg = time.Now().Format("2006-01-02 15:04:05") + p.logMsg = time.Now().Format("2006-01-02 15:04:05") +
prefixStr + " " + prefixStr + " " +
@ -115,8 +115,8 @@ func (this *SysLog_) addLog(category int32, prefixStr string,
} }
} }
func (this *SysLog_) goSaveToFile() { func (this *sysLog) goSaveToFile() {
var workNode *LogMsgNode var workNode *logMsgNode
for { for {
select { select {
case <-this.chGoSaveExit: case <-this.chGoSaveExit:

View File

@ -1,61 +1,64 @@
package f5 package f5
//import "os" import (
//import "fmt" "q5"
import "sync" "os"
//import "time" "sync"
//import "q5" "fmt"
"time"
)
const TGLOG_ROOT = "/data/logs/%s/upload/" const TGLOG_ROOT = "/data/logs/%s/upload/"
const POLY_TGLOG_ROOT = "/data/logs/%s/%d/upload/" const POLY_TGLOG_ROOT = "/data/logs/%s/%d/upload/"
const TGLOG_FILENAME = "log_%d_%s.log" const TGLOG_FILENAME = "log_%d_%s.log"
type TGLogMsgNode struct { type tgLogMsgNode struct {
gameId int32 gameId int32
jsonStr string jsonStr string
next *TGLogMsgNode next *tgLogMsgNode
} }
type TGLog_ struct { type tgLog struct {
isPolyLog bool isPolyLog bool
topNode *TGLogMsgNode topNode *tgLogMsgNode
botNode *TGLogMsgNode botNode *tgLogMsgNode
msgMutex sync.Mutex msgMutex sync.Mutex
chGoSaveExit chan int chGoSaveExit chan int
} }
func (this *TGLog_) init() { func (this *tgLog) init() {
this.chGoSaveExit = make(chan int) this.chGoSaveExit = make(chan int)
//go this.goSaveToFile() //go this.goSaveToFile()
} }
func (this *TGLog_) unInit() { func (this *tgLog) unInit() {
this.chGoSaveExit <- 1 this.chGoSaveExit <- 1
} }
func (this *TGLog_) SetPolyLog(isPolyLog bool) { func (this *tgLog) SetPolyLog(isPolyLog bool) {
this.isPolyLog = isPolyLog this.isPolyLog = isPolyLog
} }
/* func (this *tgLog) AddTrackLog(
func (this *TGLog_) AddTrackLog(
gameId int32, gameId int32,
accountId string, accountId string,
remoteAddr string, remoteAddr string,
logClass1 int32, logClass1 int32,
logClass2 int32, logClass2 int32,
prop *q5.XObject) { //prop *q5.XObject) {
eventName := fmt.Sprintf("event_%d_%d", logClass1, logClass2) ) {
this.AddTrackLogEx(gameId, accountId, remoteAddr, eventName, prop) //eventName := fmt.Sprintf("event_%d_%d", logClass1, logClass2)
//this.AddTrackLogEx(gameId, accountId, remoteAddr, eventName, prop)
} }
func (this *TGLog_) AddTrackLogEx( func (this *tgLog) AddTrackLogEx(
gameId int32, gameId int32,
accountId string, accountId string,
remoteAddr string, remoteAddr string,
eventName string, eventName string,
prop *q5.XObject) { //prop *q5.XObject) {
xobj := q5.NewMxoObject() ) {
/*xobj := q5.NewMxoObject()
xobj.SetXValue("#account_id", q5.NewXString(accountId)) xobj.SetXValue("#account_id", q5.NewXString(accountId))
xobj.SetXValue("#type", q5.NewXString("track")) xobj.SetXValue("#type", q5.NewXString("track"))
xobj.SetXValue("#time", q5.NewXString(time.Now().Format("2006-01-02 15:04:05"))) xobj.SetXValue("#time", q5.NewXString(time.Now().Format("2006-01-02 15:04:05")))
@ -64,7 +67,7 @@ func (this *TGLog_) AddTrackLogEx(
xobj.SetXObject("properties", prop) xobj.SetXObject("properties", prop)
p := new(TGLogMsgNode) p := new(tgLogMsgNode)
p.gameId = gameId p.gameId = gameId
p.jsonStr = xobj.ToJsonStr() p.jsonStr = xobj.ToJsonStr()
this.msgMutex.Lock() this.msgMutex.Lock()
@ -76,11 +79,11 @@ func (this *TGLog_) AddTrackLogEx(
this.topNode = p this.topNode = p
this.botNode = p this.botNode = p
} }
//}
*/ */
/* }
func (this *TGLog_) goSaveToFile() {
var workNode *TGLogMsgNode func (this *tgLog) goSaveToFile() {
var workNode *tgLogMsgNode
for { for {
select { select {
case <-this.chGoSaveExit: case <-this.chGoSaveExit:
@ -105,21 +108,19 @@ func (this *TGLog_) goSaveToFile() {
} }
} }
func (this *TGLog_) getLogFile(gameId int32) *os.File { func (this *tgLog) getLogFile(gameId int32) *os.File {
fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102")) fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102"))
logDir := "" logDir := ""
if this.isPolyLog { if this.isPolyLog {
logDir = fmt.Sprintf(POLY_TGLOG_ROOT, App.GetPkgName(), gameId) logDir = fmt.Sprintf(POLY_TGLOG_ROOT, _app.GetPkgName(), gameId)
} else { } else {
logDir = fmt.Sprintf(TGLOG_ROOT, App.GetPkgName()) logDir = fmt.Sprintf(TGLOG_ROOT, _app.GetPkgName())
} }
q5.ForceCreateDir(logDir) q5.ForceCreateDir(logDir)
if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil {
return f return f
} else { } else {
SysLog().Warning("TGLog.goSaveToFile err:%s", err) _sysLog.Warning("tgLog.goSaveToFile err:%s", err)
return nil return nil
} }
} }
*/

View File

@ -12,13 +12,13 @@ type TimerAttacher struct {
*q5.XTimerAttacher *q5.XTimerAttacher
} }
type Timer struct { type timer struct {
timer *q5.XTimer base *q5.XTimer
} }
func (this *Timer) init() { func (this *timer) init() {
this.timer = new(q5.XTimer) this.base = new(q5.XTimer)
this.timer.Init( this.base.Init(
func (context interface{}) int64 { func (context interface{}) int64 {
return q5.GetTickCount() return q5.GetTickCount()
}, },
@ -27,73 +27,73 @@ func (this *Timer) init() {
5000) 5000)
} }
func (this *Timer) update() { func (this *timer) update() {
this.timer.Update() this.base.Update()
} }
func (this *Timer) unInit() { func (this *timer) unInit() {
this.timer.UnInit() this.base.UnInit()
this.timer = nil this.base = nil
} }
func (this *Timer) NewTimerAttacher() *TimerAttacher { func (this *timer) NewTimerAttacher() *TimerAttacher {
ac := TimerAttacher{} ac := TimerAttacher{}
ac.XTimerAttacher = this.timer.NewTimerAttacher() ac.XTimerAttacher = this.base.NewTimerAttacher()
return &ac return &ac
} }
func (this *Timer) SetTimeout(expireTime int32, cb q5.TimerCb) { func (this *timer) SetTimeout(expireTime int32, cb q5.TimerCb) {
this.timer.SetTimeout(expireTime, cb) this.base.SetTimeout(expireTime, cb)
} }
func (this *Timer) SetTimeoutEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { func (this *timer) SetTimeoutEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) {
this.timer.SetTimeoutEx(expireTime, cb, ac.XTimerAttacher) this.base.SetTimeoutEx(expireTime, cb, ac.XTimerAttacher)
} }
func (this *Timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp { func (this *timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp {
wp := TimerWp{} wp := TimerWp{}
wp.XTimerWp = this.timer.SetTimeoutWp(expireTime, cb) wp.XTimerWp = this.base.SetTimeoutWp(expireTime, cb)
return &wp return &wp
} }
func (this *Timer) SetTimeoutExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { func (this *timer) SetTimeoutExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp {
wp := TimerWp{} wp := TimerWp{}
wp.XTimerWp = this.timer.SetTimeoutExWp(expireTime, cb, ac.XTimerAttacher) wp.XTimerWp = this.base.SetTimeoutExWp(expireTime, cb, ac.XTimerAttacher)
return &wp return &wp
} }
func (this *Timer) SetInterval(expireTime int32, cb q5.TimerCb) { func (this *timer) SetInterval(expireTime int32, cb q5.TimerCb) {
this.timer.SetInterval(expireTime, cb) this.base.SetInterval(expireTime, cb)
} }
func (this *Timer) SetIntervalEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { func (this *timer) SetIntervalEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) {
this.timer.SetIntervalEx(expireTime, cb, ac.XTimerAttacher) this.base.SetIntervalEx(expireTime, cb, ac.XTimerAttacher)
} }
func (this *Timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp { func (this *timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp {
wp := TimerWp{} wp := TimerWp{}
wp.XTimerWp = this.timer.SetIntervalWp(expireTime, cb) wp.XTimerWp = this.base.SetIntervalWp(expireTime, cb)
return &wp return &wp
} }
func (this *Timer) SetIntervalExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { func (this *timer) SetIntervalExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp {
wp := TimerWp{} wp := TimerWp{}
wp.XTimerWp = this.timer.SetIntervalExWp(expireTime, cb, ac.XTimerAttacher) wp.XTimerWp = this.base.SetIntervalExWp(expireTime, cb, ac.XTimerAttacher)
return &wp return &wp
} }
func (this *Timer) GetIdleTime() int64 { func (this *timer) GetIdleTime() int64 {
return this.timer.GetIdleTime() return this.base.GetIdleTime()
} }
func (this *Timer) ModifyTimer(timerWp *TimerWp, expireTime int32) { func (this *timer) ModifyTimer(timerWp *TimerWp, expireTime int32) {
this.timer.ModifyTimer(timerWp.XTimerWp, expireTime) this.base.ModifyTimer(timerWp.XTimerWp, expireTime)
} }
func (this *Timer) Delete(timerWp *TimerWp) { func (this *timer) Delete(timerWp *TimerWp) {
this.timer.Delete(timerWp.XTimerWp) this.base.Delete(timerWp.XTimerWp)
} }
func (this *Timer) GetRemainTime(timerWp *TimerWp) int64 { func (this *timer) GetRemainTime(timerWp *TimerWp) int64 {
return this.timer.GetRemainTime(timerWp.XTimerWp) return this.base.GetRemainTime(timerWp.XTimerWp)
} }