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.
78 lines
1.2 KiB
78 lines
1.2 KiB
|
1 year ago
|
package hall
|
||
|
|
|
||
|
|
import (
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"sync"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
playerSessionMap sync.Map
|
||
|
|
playerIdMap sync.Map
|
||
|
|
)
|
||
|
|
|
||
|
|
func newPlayer(uid int) *player {
|
||
|
|
p := &player{}
|
||
|
|
p.db.Id = uid
|
||
|
|
ret, err := call.GetUserXInfo(uid, "channel_id", "token", "birth")
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
}
|
||
|
|
p.db.ChannelID = ret.ChannelID
|
||
|
|
p.token = ret.Token
|
||
|
|
p.db.Birth = ret.Birth
|
||
|
|
|
||
|
|
re := &common.RechargeInfo{UID: uid}
|
||
|
|
db.Mysql().Get(re)
|
||
|
|
p.isRecharge = re.TotalRecharge > 0
|
||
|
|
return p
|
||
|
|
}
|
||
|
|
|
||
|
|
func addPlayerBySession(s string, p *player) {
|
||
|
|
playerSessionMap.Store(s, p)
|
||
|
|
}
|
||
|
|
|
||
|
|
func delPlayerBySession(s string) {
|
||
|
|
playerSessionMap.Delete(s)
|
||
|
|
}
|
||
|
|
|
||
|
|
func addPlayerById(id int, p *player) {
|
||
|
|
log.Debug("add player %v", id)
|
||
|
|
playerIdMap.Store(id, p)
|
||
|
|
}
|
||
|
|
|
||
|
|
// func getPlayerBySession(s gate.Session) *player {
|
||
|
|
// p, ok := playerSessionMap.Load(s)
|
||
|
|
// if !ok {
|
||
|
|
// return nil
|
||
|
|
// }
|
||
|
|
|
||
|
|
// return p.(*player)
|
||
|
|
// }
|
||
|
|
|
||
|
|
func getPlayerById(id int) *player {
|
||
|
|
p, ok := playerIdMap.Load(id)
|
||
|
|
if !ok {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
return p.(*player)
|
||
|
|
}
|
||
|
|
|
||
|
|
func delPlayerByID(id int) {
|
||
|
|
log.Debug("del player %v", id)
|
||
|
|
playerIdMap.Delete(id)
|
||
|
|
}
|
||
|
|
|
||
|
|
func playerNumber() (num int) {
|
||
|
|
playerIdMap.Range(func(_, _ interface{}) bool {
|
||
|
|
num++
|
||
|
|
return true
|
||
|
|
})
|
||
|
|
|
||
|
|
return
|
||
|
|
}
|