印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

374 lines
10 KiB

1 year ago
package common
import (
"fmt"
"server/util"
"strconv"
"strings"
)
// 平台登录方式
const (
AccountTypeGuest = iota
AccountTypePhone
AccountTypeFacebook
AccountTypeGoogleplay
AccountTypeEmail
AccountTypeAccount
AccountTypeRobot = 100
)
// 账号状态
const (
AccountStatus = iota
AccountStatusNormal // 正常
AccountStatusLimit // 封禁
AccountStatusAll
)
// 对账号进行操作
const (
OptPlayerType = iota
OptPlayerTypeKick // 踢出玩家
OptPlayerTypeDisconnect // 操作玩家断线
OptPlayerTypeAll
)
const (
LanguageEN = iota + 1
LanguageHindi
)
const (
NewUser = iota + 1 // 新用户登录
OldUser // 老用户登录
)
const (
DecimalDigits = 100000000 // 计算时精确到小数点后8位
)
var (
DecimalCounts = 0
OneDay int64 = 24 * 60 * 60 // 一天的秒数
)
func init() {
tmp := DecimalDigits
for {
if tmp <= 1 {
break
}
tmp /= 10
DecimalCounts++
}
}
func CashFloat64ToInt64(value float64) int64 {
negative := value < 0
// 将浮点数转换为字符串
text := fmt.Sprintf("%v", value)
// 查找小数点位置
pointIndex := strings.Index(text, ".")
var left, right string
var big, small int64
if pointIndex != -1 {
left = text[:pointIndex]
// 去除小数点后面尾随的0
right = strings.TrimRight(text[pointIndex+1:], "0")
} else {
left = text
}
diff := len(right) - DecimalCounts
if diff > 0 {
right = right[:DecimalCounts]
} else {
for i := 0; i < -diff; i++ {
right += "0"
}
}
big, _ = strconv.ParseInt(left, 10, 64)
small, _ = strconv.ParseInt(right, 10, 64)
ret := util.Abs(big*DecimalDigits) + small
if negative {
return -ret
}
return ret
}
const (
DeviceType = iota
DeviceTypeMobile
DeviceTypePC
DeviceTypeWebview
DeviceTypeIOSH5
DeviceTypeMac
DeviceTypePWA
DeviceTypeAll
)
func IsPC(t int) bool {
return t == DeviceTypePC
}
func GetAccountPre(t int) string {
switch t {
case AccountTypeGuest:
return "guest"
case AccountTypePhone:
return "phone"
case AccountTypeFacebook:
return "fb"
case AccountTypeGoogleplay:
return "gp"
case AccountTypeEmail:
return "email"
case AccountTypeAccount:
return "account"
case AccountTypeRobot:
return "robot"
}
return ""
}
// 渠道号分区
var (
ChannelRegionGoogle = []int{2, 10000}
ChannelRegionVivo = []int{10001, 11000}
)
const (
BrocastIDAll = iota // 全服广播
BrocastIDWithdraw // tx事件
)
// 平台号
const (
PlatformIDGoogle = iota + 1
PlatformIDVivo
PlatformIDAll
)
func GetRegionByPlatformID(id int) []int {
switch id {
case PlatformIDGoogle:
return ChannelRegionGoogle
case PlatformIDVivo:
return ChannelRegionVivo
default:
return nil
}
}
type AdjustEventType int
// adjust事件顺序
const (
AdjustEventFinishLoad AdjustEventType = iota // 加载完成
AdjustEventFirstPage // 首屏加载
AdjustEventClickDemo // 点击游戏demo
AdjustEventClickPlay // 点击游戏play
AdjustEventNewPay // 新用户付费
AdjustEventAllPay // 所有用户付费
AdjustEventNewPlayer // 注册完成
)
const (
ADZero = iota
ADFB
ADKwai
ADJust
ADAll
)
// Channel 渠道表
// GameControlm 游戏控制,0关闭,1开启
type Channel struct {
ID uint `gorm:"primarykey"`
IgnoreOrganic int `gorm:"column:ignore_organic;type:tinyint(4);default:1;comment:是否屏蔽自然量 1不屏蔽 2屏蔽" json:"ignore_organic"`
AdjustEventID string `gorm:"column:adjust_eventid;type:varchar(256);not null;comment:adjust事件id,按顺序隔开" json:"adjust_eventid"`
AdjustAppToken string `gorm:"column:adjust_app_token;type:varchar(256);not null;comment:adjust应用token" json:"adjust_app_token"`
AdjustAuth string `gorm:"column:adjust_auth;type:varchar(256);not null;comment:adjust验证码" json:"adjust_auth"`
Name string `gorm:"column:name;type:varchar(32);not null;comment:渠道" json:"name"`
PackName string `gorm:"column:pack_name;type:varchar(256);not null;comment:包名" json:"pack_name"`
Version int `gorm:"column:version;type:int(11);not null;comment:审核版本号" json:"version"`
MainVersion int `gorm:"column:main_version;type:int(11);not null;comment:正式服版本号" json:"main_version"`
ChannelID int `gorm:"column:channel_id;type:bigint(20);uniqueIndex:channel_id;comment:渠道id" json:"channel_id"`
PlatformID int `gorm:"column:platform_id;type:int(11);comment:平台id,1 googleplay 2 vivo" json:"platform_id"`
IsHot int `gorm:"column:ishot;type:tinyint(4);default:1;comment:是否热更,1不热更,2热更" json:"ishot"`
URL string `gorm:"column:url;type:varchar(64);not null;default:'';comment:域名" json:"url"`
Show int `gorm:"column:show;type:int(11);default:0;comment:是否打开,1不打开,2打开" json:"show"`
FBPixelID string `gorm:"column:fb_pixelid;type:varchar(256);not null;comment:fb像素id" json:"fb_pixelid"`
FBAccessToken string `gorm:"column:fb_accesstoken;type:varchar(256);not null;comment:fb验证码" json:"fb_accesstoken"`
UP int `gorm:"column:up;type:int(11);default:0;comment:上级渠道" json:"up"`
ADUpload int `gorm:"column:ad_upload;type:int(11);default:0;comment:上报事件的平台" json:"ad_upload"`
}
func (c *Channel) TableName() string {
return "channel"
}
// ServerVersion 服务器版本表
// GameControlm 游戏控制,0关闭,1开启
type ServerVersion struct {
ID uint `gorm:"primarykey"`
ServerID int `gorm:"column:server_id;type:int(11);uniqueIndex:server_id;default:0;comment:服务器id" json:"server_id" redis:"server_id"`
Version int `gorm:"column:version;type:int(11);default:0;comment:服务器最新版本" json:"version" redis:"version"`
}
func (c *ServerVersion) TableName() string {
return "server_version"
}
func (c *Channel) GetAdjustEventID(e int) string {
s := strings.Split(c.AdjustEventID, ",")
if e > len(s)-1 {
return ""
}
return s[e]
}
// 红点提示
const (
RedpointMail = iota + 1 // 邮件
)
// WhiteList 白名单
// ListType 名单类型 1白名单 2黑名单(当为0时,用作系统开关)
// LimitType 限制类型 1ip限制 2设备限制(用作系统开关时 1开启 2关闭)
// Content ip或者设备码
// Platform 平台类型 facebook 2 gooleplay 3
// Channel 渠道号
// Version 版本号
// CreateTime 创建时间
// Operator 操作人
// Powers 权限
//
// 第1位控制 手机/游客/渠道
// 第2位控制 注册账号
// 第3位控制 绑定账号
// 第4位控制 账号充值
// 第5位控制 账号退出
// 第6位控制 游戏玩牌
// 第7位控制 版本热更
type WhiteList struct {
ID string
ListType int
LimitType int
Content string
Platform int
Channel int
Version int
Powers []int
CreateTime int64
Operator string
}
var (
PowerMap = map[string]int{
"/account/phoneCode/login": 0,
"/account/guestLogin": 0,
"/account/gpLogin": 0,
"/account/phoneCode/regist": 1,
"/account/phoneCode/bind": 2,
"/balance/recharge/do": 3,
"/balance/withdraw/do": 4,
"playCard": 5,
// "/sys/hotUpdate": 6,
}
LimitMap = map[string]struct{}{
"/sys/hotUpdate": {},
}
)
func IsLimitMap(path string) bool {
_, ok := LimitMap[path]
return ok
}
// PowerPass 鉴权
func (w *WhiteList) PowerPass(path string) bool {
po, ok := PowerMap[path]
if !ok {
index := -1
for k, v := range PowerMap {
if strings.Contains(path, k) {
index = v
break
}
}
if index == -1 {
return true
}
po = index
}
if po > len(w.Powers) {
return false
}
power := w.Powers[po]
if po == 0 {
index := strings.LastIndex(path, "/")
newStr := path[index:]
switch newStr {
case "/login":
return power&4 == 4
case "/guestLogin":
return power&2 == 2
case "/gpLogin":
return power&1 == 1
default:
return false
}
}
return power == 1
}
// ExamineList 审核人员列表
type ExamineList struct {
Time int64
}
// LoginRecord 玩家登录记录表
type LoginRecord struct {
ID int `gorm:"primarykey"`
FirstTime int64 `gorm:"column:first_time;default:0;type:bigint(20);comment:首次登录时间"`
Time int64 `gorm:"column:time;default:0;type:bigint(20);unixIndex:ut;comment:最后登录时间"`
UID int `gorm:"column:uid;not null;type:int(11);unixIndex:ut;comment:玩家id"`
IP string `gorm:"column:ip;type:varchar(256);comment:玩家登录ip"`
Date string `gorm:"column:date;type:varchar(64);default:'';comment:日期"`
ChannelID int `gorm:"column:channel_id;type:bigint(20);default:0;comment:渠道id"`
Status int `gorm:"column:status;type:int(11);comment:1是新用户,2是老用户"`
Platform int `gorm:"column:platform;type:int(11);default:1;comment:最新登录平台"`
IsRecharge int `gorm:"column:is_recharge;type:tinyint(4);default:1;comment:1未充值,2已充值"`
}
func (c *LoginRecord) TableName() string {
return "login_record"
}
// RedisRealOnline 各场次实时在线
type RedisRealOnline struct {
Total int // 总在线人数
New int // 新用户在线人数
}
// IsShareChannel 是否是分享渠道
func IsShareChannel(cid int) bool {
return cid > 10000
}
// BlackList 黑名单
type BlackList struct {
ID int `gorm:"primarykey"`
Name string `gorm:"column:name;type:varchar(64);default:'';not null;uniqueIndex:black_all;comment:名字" json:"Name" web:"name"`
Phone string `gorm:"column:phone;type:varchar(64);default:'';not null;uniqueIndex:black_all;comment:手机号" json:"Phone" web:"phone"`
Email string `gorm:"column:email;type:varchar(64);default:'';not null;uniqueIndex:black_all;comment:email" json:"Email" web:"email"`
PayAccount string `gorm:"column:pay_account;type:varchar(255);default:'';not null;uniqueIndex:black_all;comment:支付账号" json:"PayAccount" web:"pay_account"`
DeviceID string `gorm:"column:deviceid;type:varchar(255);default:'';not null;uniqueIndex:black_all;comment:设备号" json:"DeviceID" web:"deviceid"`
IP string `gorm:"column:ip;type:varchar(64);default:'';not null;uniqueIndex:black_all;comment:ip" json:"IP" web:"ip"`
}
func (c *BlackList) TableName() string {
return "black_list"
}