Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package impl_es
|
||||
|
||||
import "sync"
|
||||
|
||||
const (
|
||||
// 批量保存的消息数量
|
||||
con_MAX_NUMBER_OF_MESSAGE = 20
|
||||
)
|
||||
|
||||
// logCache
|
||||
// @description: 日志缓存
|
||||
type logCache struct {
|
||||
logCacheList []*EsLogModel // logCacheList 日志缓存对象
|
||||
logCacheMutex sync.RWMutex // logCacheMutex 锁
|
||||
}
|
||||
|
||||
// newlogCache
|
||||
// @description: 构造日志缓存
|
||||
// parameter:
|
||||
// return:
|
||||
// @*logCache:
|
||||
func newlogCache() *logCache {
|
||||
m := &logCache{
|
||||
logCacheList: make([]*EsLogModel, 0, 256),
|
||||
logCacheMutex: sync.RWMutex{},
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// 写入在线日志
|
||||
// 参数:
|
||||
// 日志信息对象
|
||||
// 返回值:
|
||||
// 无
|
||||
func (c *logCache) addCacheLog(logObj *EsLogModel) {
|
||||
c.logCacheMutex.Lock()
|
||||
defer c.logCacheMutex.Unlock()
|
||||
|
||||
c.logCacheList = append(c.logCacheList, logObj)
|
||||
}
|
||||
|
||||
// 获取日志数量
|
||||
// 参数:
|
||||
// 无
|
||||
// 返回值:
|
||||
// 缓存中的日志数量
|
||||
func (c *logCache) getCacheLogCount() int {
|
||||
c.logCacheMutex.RLock()
|
||||
defer c.logCacheMutex.RUnlock()
|
||||
|
||||
return len(c.logCacheList)
|
||||
}
|
||||
|
||||
// 获取缓存中的日志
|
||||
// 参数:
|
||||
// 数量
|
||||
// 返回值:
|
||||
// 日志列表对象
|
||||
func (c *logCache) getCacheLog(logCount int) (logList []*EsLogModel) {
|
||||
if logCount > con_MAX_NUMBER_OF_MESSAGE {
|
||||
logCount = con_MAX_NUMBER_OF_MESSAGE
|
||||
}
|
||||
|
||||
c.logCacheMutex.Lock()
|
||||
defer c.logCacheMutex.Unlock()
|
||||
|
||||
logList = c.logCacheList[:logCount]
|
||||
c.logCacheList = c.logCacheList[logCount:]
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
配置包,提供项目的配置信息
|
||||
*/
|
||||
package configYaml
|
||||
|
||||
import (
|
||||
"goutil/debugUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
// 是否是DEBUG模式
|
||||
DEBUG bool
|
||||
|
||||
// web服务监听端口
|
||||
WebServerAddress string
|
||||
|
||||
// gRpc监听地址和端口(内网地址即可)
|
||||
GrpcServerAddress string
|
||||
|
||||
// 战斗服务器地址
|
||||
FightServerAddress string
|
||||
|
||||
// 战区Id
|
||||
BigGroupId int
|
||||
|
||||
// 页签Id
|
||||
TagId int
|
||||
|
||||
// 是否是中心服务器地址
|
||||
PlayerServerCenter bool
|
||||
|
||||
// 数据中心服务器地址
|
||||
DataCenterAddress string
|
||||
|
||||
// es urls
|
||||
EsUrls string
|
||||
|
||||
BaseDay int
|
||||
)
|
||||
|
||||
// initBaseConfig
|
||||
// @description: 初始化基础配置数据
|
||||
// parameter:
|
||||
// @configObj: 基础配置数据
|
||||
// return:
|
||||
// @error: 错误信息
|
||||
func initBaseConfig() {
|
||||
|
||||
root := ConfigYaml.Root
|
||||
|
||||
// 为DEBUG模式赋值
|
||||
DEBUG = root.Debug
|
||||
|
||||
// 设置debugUtil的状态
|
||||
debugUtil.SetDebug(DEBUG)
|
||||
|
||||
// 解析rpcConfig配置
|
||||
WebServerAddress = root.WebServerAddress
|
||||
|
||||
// gRpc监听地址和端口(内网地址即可)
|
||||
GrpcServerAddress = root.GrpcServerAddress
|
||||
|
||||
// 解析BigGroupId配置
|
||||
BigGroupId = root.BigGroupId
|
||||
|
||||
// 解析FightServerAddress配置
|
||||
FightServerAddress = root.FightServerAddress
|
||||
|
||||
EsUrls = root.EsUrls
|
||||
|
||||
BaseDay = root.BaseDay
|
||||
}
|
||||
|
||||
// GetDebug
|
||||
// @description: 获取是否是开发环境
|
||||
// parameter:
|
||||
// return:
|
||||
// @bool:
|
||||
func GetDebug() bool {
|
||||
return ConfigYaml.Root.Debug
|
||||
}
|
||||
|
||||
// GetWebServerAddress 返回Web服务器的地址。
|
||||
// 该函数通过访问ConfigYaml中的配置信息,获取并返回Web服务器的地址。
|
||||
// 主要用于需要与Web服务器建立连接的场景。
|
||||
func GetWebServerAddress() string {
|
||||
return ConfigYaml.Root.WebServerAddress
|
||||
}
|
||||
|
||||
// GetEsUrls 返回配置文件中 Elasticsearch 的 URL 地址。
|
||||
//
|
||||
// 该函数通过访问全局变量 ConfigYaml,获取其 Root 字段下的 EsUrls 属性,
|
||||
// 并将其作为字符串返回。这提供了一种简单的方法来获取 Elasticsearch 数据库的连接信息,
|
||||
// 而无需直接访问配置文件。
|
||||
func GetEsUrls() string {
|
||||
return ConfigYaml.Root.EsUrls
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package managecenterModel
|
||||
|
||||
// 服务器(组)Id区间类型
|
||||
type ServerIdRange struct {
|
||||
Min int32 // 最小值
|
||||
Max int32 // 最大值
|
||||
}
|
||||
|
||||
// 是否包含指定的值
|
||||
// value:指定值
|
||||
// 返回值:
|
||||
// 是否包含指定的值
|
||||
func (this *ServerIdRange) Contains(value int32) bool {
|
||||
return this.Min <= value && value <= this.Max
|
||||
}
|
||||
|
||||
func NewServerIdRange(min, max int32) *ServerIdRange {
|
||||
return &ServerIdRange{
|
||||
Min: min,
|
||||
Max: max,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package stringUtil
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"goutil/securityUtil"
|
||||
)
|
||||
|
||||
// 获取新的GUID字符串
|
||||
// 返回值:
|
||||
// 新的GUID字符串
|
||||
func GetNewGUID() string {
|
||||
b := make([]byte, 48)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return securityUtil.Md5String(base64.URLEncoding.EncodeToString(b), true)
|
||||
}
|
||||
|
||||
// 生成空的GUID字符串
|
||||
// 返回值:
|
||||
// 空的GUID字符串
|
||||
func GetEmptyGUID() string {
|
||||
return "00000000-0000-0000-0000-000000000000"
|
||||
}
|
||||
|
||||
// 判断GUID是否为空
|
||||
// guid:GUID
|
||||
// 返回值:
|
||||
// 是否为空
|
||||
func IsGUIDEmpty(guid string) bool {
|
||||
if guid == "" || guid == "00000000-0000-0000-0000-000000000000" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 获取新的GUID字符串
|
||||
// 返回值:
|
||||
// 新的GUID字符串
|
||||
func GetNewUUID() string {
|
||||
str := GetNewGUID()
|
||||
var builder strings.Builder
|
||||
builder.WriteString(Substring(str, 0, 8))
|
||||
builder.WriteString("-")
|
||||
builder.WriteString(Substring(str, 8, 4))
|
||||
builder.WriteString("-")
|
||||
builder.WriteString(Substring(str, 12, 4))
|
||||
builder.WriteString("-")
|
||||
builder.WriteString(Substring(str, 16, 4))
|
||||
builder.WriteString("-")
|
||||
builder.WriteString(Substring(str, 20, 12))
|
||||
|
||||
return strings.ToLower(builder.String())
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package sensitiveWordsMgr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"Framework/goroutineMgr"
|
||||
. "Framework/managecenterModel"
|
||||
"goutil/dfaUtil"
|
||||
"goutil/logUtil"
|
||||
"goutil/mathUtil"
|
||||
"goutil/webUtil"
|
||||
"goutil/zlibUtil"
|
||||
)
|
||||
|
||||
// const GetForbidWordURL string = "http://10.253.0.186:10090/Query"
|
||||
type ForbidWords struct {
|
||||
//游戏ID
|
||||
GameId int
|
||||
//屏蔽字
|
||||
Words string
|
||||
}
|
||||
|
||||
// 请求屏蔽字库地址
|
||||
const GetForbidWordURL string = "http://forbidword.7qule.com/Query"
|
||||
|
||||
var (
|
||||
mHashValue string
|
||||
mDFAUtil *dfaUtil.DFAUtil
|
||||
mGameId int
|
||||
rand *mathUtil.Rand
|
||||
mGameOnly bool = false
|
||||
)
|
||||
|
||||
// 获取屏蔽字
|
||||
func refreshSensitiveWord() error {
|
||||
//定义参数
|
||||
requestParamMap := make(map[string]string, 0)
|
||||
requestParamMap["GameId"] = strconv.Itoa(mGameId)
|
||||
requestParamMap["HashValue"] = mHashValue
|
||||
requestParamMap["DataType"] = "1"
|
||||
requestParamMap["IsResultCompressed"] = "true"
|
||||
if mGameOnly {
|
||||
requestParamMap["GameOnly"] = "true"
|
||||
}
|
||||
//data, _ := json.Marshal(requestParamMap)
|
||||
|
||||
//请求url,请求头
|
||||
header := webUtil.GetFormHeader()
|
||||
transport := webUtil.NewTransport()
|
||||
transport.DisableKeepAlives = true
|
||||
transport = webUtil.GetTimeoutTransport(transport, 1000)
|
||||
|
||||
statusCode, returnBytesTemp, err := webUtil.PostMapData(GetForbidWordURL, requestParamMap, header, transport)
|
||||
//statusCode, returnBytes, err := webUtil.PostMapData(GetForbidWordURL, requestParamMap, header, nil)
|
||||
if err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取敏感字出错,url:%s,错误信息为:%s", GetForbidWordURL, err))
|
||||
return err
|
||||
}
|
||||
if statusCode != 200 {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取敏感字出错,url:%s,错误码为:%d", GetForbidWordURL, statusCode))
|
||||
return err
|
||||
}
|
||||
|
||||
//解压
|
||||
returnBytes, err := zlibUtil.Decompress(returnBytesTemp)
|
||||
if err != nil {
|
||||
logUtil.ErrorLog("返回结果解压失败")
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析返回值
|
||||
returnObj := new(ReturnObject)
|
||||
if err = json.Unmarshal(returnBytes, &returnObj); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取敏感字反序列化返回值出错,错误信息为:%s, str:%s", err, string(returnBytes)))
|
||||
return err
|
||||
}
|
||||
|
||||
// 判断返回状态是否为成功
|
||||
if returnObj.Code != 0 {
|
||||
msg := fmt.Sprintf("获取敏感字出错,返回状态:%d,信息为:%s", returnObj.Code, returnObj.Message)
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
} else if returnObj.Code == 0 && len(returnObj.HashValue) == 0 { //表示没有更新
|
||||
return nil
|
||||
}
|
||||
|
||||
// 解析Data
|
||||
var tmpSensitiveWordList []*ForbidWords
|
||||
if data, ok := returnObj.Data.(string); !ok {
|
||||
msg := "获取敏感字出错,返回的数据不是string类型"
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
} else {
|
||||
if err = json.Unmarshal([]byte(data), &tmpSensitiveWordList); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取敏感字反序列化数据出错,错误信息为:%s", err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//缓存hasvalue
|
||||
mHashValue = returnObj.HashValue
|
||||
|
||||
//获取敏感字数组
|
||||
var temWordArray []string
|
||||
for _, item := range tmpSensitiveWordList {
|
||||
temWordArray = append(temWordArray, strings.ToUpper(item.Words))
|
||||
}
|
||||
//dfa
|
||||
mDFAUtil = dfaUtil.NewDFAUtil(temWordArray)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 是否包含屏蔽字
|
||||
func IsSensitiveWords(input string) (exist bool) {
|
||||
input = strings.ToUpper(input)
|
||||
exist = mDFAUtil.IsMatch(input)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 取出敏感字及开始位置
|
||||
func SensitiveWords(input string) (words []string, pos []int, exist bool) {
|
||||
input2 := strings.ToUpper(input)
|
||||
inputRune := []rune(input)
|
||||
startIndexList, endIndexList := mDFAUtil.SearchSentence(input2)
|
||||
if len(startIndexList) > 0 {
|
||||
exist = true
|
||||
words = make([]string, 0, len(startIndexList))
|
||||
pos = make([]int, 0, len(startIndexList))
|
||||
for i := 0; i < len(startIndexList); i++ {
|
||||
start := startIndexList[i]
|
||||
end := endIndexList[i]
|
||||
words = append(words, string(inputRune[start:end+1]))
|
||||
pos = append(pos, start)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 取出敏感字及开始及结束位置
|
||||
func SensitiveWordsEndStartPos(input string) (words []string, starts, ends []int, exist bool) {
|
||||
input2 := strings.ToUpper(input)
|
||||
inputRune := []rune(input)
|
||||
startIndexList, endIndexList := mDFAUtil.SearchSentence(input2)
|
||||
if len(startIndexList) > 0 {
|
||||
exist = true
|
||||
words = make([]string, 0, len(startIndexList))
|
||||
starts = startIndexList
|
||||
ends = endIndexList
|
||||
for i := 0; i < len(startIndexList); i++ {
|
||||
start := startIndexList[i]
|
||||
end := endIndexList[i]
|
||||
words = append(words, string(inputRune[start:end+1]))
|
||||
//pos = append(pos, start)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 根据用户输入的替换词替换敏感词
|
||||
func ReplaceSendsitiveWords(input, replaceStr string) (newStr string) {
|
||||
words, _, _, exist := SensitiveWordsEndStartPos(input)
|
||||
newStr = input
|
||||
//如果不存在敏感词,则直接返回
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
//循环替换
|
||||
for _, sendsitiveWord := range words {
|
||||
newStr = strings.Replace(newStr, sendsitiveWord, replaceStr, -1)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 判断服务器是否存在
|
||||
func IfServerExists() (exist bool) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 处理敏感字
|
||||
func HandleSendsitiveWords(input string) (newStr string) {
|
||||
newStr = mDFAUtil.HandleWord(input, rune('*'))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 定时刷新敏感字库
|
||||
func StartRefreshSensitiveWordListTread(gameId int) {
|
||||
rand = mathUtil.GetRand()
|
||||
mGameId = gameId
|
||||
// 定时刷新数据
|
||||
go func() {
|
||||
goroutineName := "sensitiveWordsMgr.StartRefreshSensitiveWordListTread"
|
||||
goroutineMgr.Monitor(goroutineName)
|
||||
defer goroutineMgr.ReleaseMonitor(goroutineName)
|
||||
|
||||
for {
|
||||
// 刷新屏蔽字
|
||||
refreshSensitiveWord()
|
||||
|
||||
// 每5分钟刷新一次
|
||||
time.Sleep(time.Duration(rand.GetRandRangeInt64(120, 300)) * time.Second)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// 定时刷新敏感字库(排除公共字库,只刷新游戏内的)
|
||||
func StartRefreshSensitiveListTreadExcludeComm(gameId int) {
|
||||
rand = mathUtil.GetRand()
|
||||
mGameId = gameId
|
||||
mGameOnly = true
|
||||
// 定时刷新数据
|
||||
go func() {
|
||||
goroutineName := "sensitiveWordsMgr.StartRefreshSensitiveWordListTread"
|
||||
goroutineMgr.Monitor(goroutineName)
|
||||
defer goroutineMgr.ReleaseMonitor(goroutineName)
|
||||
|
||||
for {
|
||||
// 刷新屏蔽字
|
||||
refreshSensitiveWord()
|
||||
|
||||
// 每5分钟刷新一次
|
||||
time.Sleep(time.Duration(rand.GetRandRangeInt64(120, 300)) * time.Second)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user