60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package history
|
|
|
|
import (
|
|
"q5"
|
|
"cs"
|
|
"main/common"
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
type historyMgr struct {
|
|
userHash map[string]*user
|
|
}
|
|
|
|
func (this *historyMgr) Init() {
|
|
this.userHash = make(map[string]*user)
|
|
}
|
|
|
|
func (this *historyMgr) UnInit() {
|
|
}
|
|
|
|
func (this *historyMgr) AddBattle(accountId string, mapId int32, modeId int32) {
|
|
u := this.getUser(accountId)
|
|
if u == nil {
|
|
u = new(user)
|
|
u.accountId = accountId
|
|
}
|
|
u.addBattle(mapId, modeId)
|
|
}
|
|
|
|
func (this *historyMgr) PushLastBattleInfo(hum common.Player) {
|
|
u := this.getUser(hum.GetAccountId())
|
|
if u == nil {
|
|
return
|
|
}
|
|
msg := new(cs.SMPushLastBattleInfo)
|
|
q5.NewSlice(&msg.BattleList, 0, 10)
|
|
for key, val := range(u.mapAndModeHash) {
|
|
mapId := int32(key)
|
|
modeId := int32(key >> 32)
|
|
p := new(cs.MFLastBattleInfo)
|
|
p.MapId = proto.Int32(mapId)
|
|
p.ModeId = proto.Int32(modeId)
|
|
p.StartTime = proto.Int32(val)
|
|
}
|
|
hum.SendMsg(msg)
|
|
}
|
|
|
|
func (this *historyMgr) getUser(accountId string) *user {
|
|
if u, ok := this.userHash[accountId]; ok {
|
|
return u
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
func (this *historyMgr) removeUser(accountId string) {
|
|
delete(this.userHash, accountId)
|
|
}
|