Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
4649797bad
@ -4,5 +4,5 @@ Website = "http://legu.cc"
|
|||||||
Icon = "app.png"
|
Icon = "app.png"
|
||||||
Name = "RobotGUI"
|
Name = "RobotGUI"
|
||||||
ID = "cc.legu.app"
|
ID = "cc.legu.app"
|
||||||
Version = "1.2.3"
|
Version = "1.2.4"
|
||||||
Build = 31
|
Build = 32
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go_dreamfactory/lego/base"
|
"go_dreamfactory/lego/base"
|
||||||
@ -55,6 +56,8 @@ type User struct {
|
|||||||
configure *configureComp
|
configure *configureComp
|
||||||
globalConf *cfg.GameGlobalData
|
globalConf *cfg.GameGlobalData
|
||||||
modelSign *ModelSign // 签到
|
modelSign *ModelSign // 签到
|
||||||
|
timerLock sync.Mutex
|
||||||
|
timerMap map[string]*time.Ticker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *User) GetType() core.M_Modules {
|
func (this *User) GetType() core.M_Modules {
|
||||||
@ -64,6 +67,7 @@ func (this *User) GetType() core.M_Modules {
|
|||||||
func (this *User) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
func (this *User) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||||
err = this.ModuleBase.Init(service, module, options)
|
err = this.ModuleBase.Init(service, module, options)
|
||||||
this.service = service.(base.IRPCXService)
|
this.service = service.(base.IRPCXService)
|
||||||
|
this.timerMap = make(map[string]*time.Ticker)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +82,7 @@ func (this *User) Start() (err error) {
|
|||||||
if this.globalConf == nil {
|
if this.globalConf == nil {
|
||||||
err = errors.New("global config not found")
|
err = errors.New("global config not found")
|
||||||
}
|
}
|
||||||
|
this.ResetSession()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,8 +137,20 @@ func (this *User) GetUserSession(uid string) *pb.CacheUser {
|
|||||||
return this.modelSession.getUserSession(uid)
|
return this.modelSession.getUserSession(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *User) ResetSession() {
|
||||||
|
us, err := this.UserOnlineList()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range us {
|
||||||
|
this.modelSession.DelListlds(comm.RDS_EMPTY, v.Uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 清除session
|
// 清除session
|
||||||
func (this *User) CleanSession(session comm.IUserSession) {
|
func (this *User) CleanSession(session comm.IUserSession) {
|
||||||
|
this.stopTicker(session.GetUserId())
|
||||||
if !this.IsCross() {
|
if !this.IsCross() {
|
||||||
this.modelUser.updateOfflineTime(session.GetUserId())
|
this.modelUser.updateOfflineTime(session.GetUserId())
|
||||||
}
|
}
|
||||||
@ -615,9 +632,29 @@ func (this *User) BingoSetUserLv(session comm.IUserSession, lv int32) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *User) Update() {
|
||||||
|
if this.IsCross() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cu, err := this.UserOnlineList()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range cu {
|
||||||
|
if isession, ok := this.ModuleBase.GetUserSession(v.Uid); ok {
|
||||||
|
//del session
|
||||||
|
log.Debug("del session", log.Field{Key: "uid", Value: v.Uid}, log.Field{Key: "isLogin", Value: isession.IsLogin()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (this *User) RecoverUserVitStart(uid string) {
|
func (this *User) RecoverUserVitStart(uid string) {
|
||||||
go func(uid string) {
|
go func(uid string) {
|
||||||
timeSec := time.NewTicker(time.Second * 30)
|
timeSec := time.NewTicker(time.Second * 30)
|
||||||
|
this.timerLock.Lock()
|
||||||
|
this.timerMap[uid] = timeSec
|
||||||
|
this.timerLock.Unlock()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeSec.C:
|
case <-timeSec.C:
|
||||||
@ -627,6 +664,15 @@ func (this *User) RecoverUserVitStart(uid string) {
|
|||||||
}(uid)
|
}(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *User) stopTicker(uid string) {
|
||||||
|
if t, ok := this.timerMap[uid]; ok {
|
||||||
|
if t != nil {
|
||||||
|
t.Stop()
|
||||||
|
delete(this.timerMap, uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 玩家体力恢复
|
// 玩家体力恢复
|
||||||
func (this *User) recoverUserVit(uid string) {
|
func (this *User) recoverUserVit(uid string) {
|
||||||
if this.IsCross() {
|
if this.IsCross() {
|
||||||
@ -642,7 +688,11 @@ func (this *User) recoverUserVit(uid string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var yu int32
|
var (
|
||||||
|
yu int32
|
||||||
|
add int32
|
||||||
|
changed int32
|
||||||
|
)
|
||||||
cur := time.Now().Unix()
|
cur := time.Now().Unix()
|
||||||
if u.LastRecoverVitSec == 0 {
|
if u.LastRecoverVitSec == 0 {
|
||||||
update := map[string]interface{}{
|
update := map[string]interface{}{
|
||||||
@ -660,19 +710,31 @@ func (this *User) recoverUserVit(uid string) {
|
|||||||
if pconf == nil {
|
if pconf == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if u.Ps < pconf.PsCeiling {
|
||||||
total := u.Ps + yu
|
total := u.Ps + yu
|
||||||
if total <= pconf.PsCeiling {
|
if total > pconf.PsCeiling {
|
||||||
|
add = pconf.PsCeiling - u.Ps
|
||||||
|
changed = pconf.PsCeiling
|
||||||
|
} else {
|
||||||
|
add = yu
|
||||||
|
changed = total
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
add = 0
|
||||||
|
}
|
||||||
|
|
||||||
if isession, ok := this.ModuleBase.GetUserSession(u.Uid); ok {
|
if isession, ok := this.ModuleBase.GetUserSession(u.Uid); ok {
|
||||||
if code := this.AddAttributeValue(isession, comm.ResPs, yu, false); code == pb.ErrorCode_Success {
|
if code := this.AddAttributeValue(isession, comm.ResPs, add, false); code == pb.ErrorCode_Success {
|
||||||
update := map[string]interface{}{
|
update := map[string]interface{}{
|
||||||
"lastRecoverVitSec": cur,
|
"lastRecoverVitSec": cur,
|
||||||
}
|
}
|
||||||
if err := this.modelUser.Change(u.Uid, update); err == nil {
|
if err := this.modelUser.Change(u.Uid, update); err == nil {
|
||||||
|
if changed > 0 {
|
||||||
if err := this.SendMsgToUser(string(this.GetType()), "vitchanged",
|
if err := this.SendMsgToUser(string(this.GetType()), "vitchanged",
|
||||||
&pb.UserVitChangedPush{Ps: total}, u.Uid); err != nil {
|
&pb.UserVitChangedPush{Ps: changed}, u.Uid); err != nil {
|
||||||
this.Error("玩家体力变化 UserVitChangedPush推送失败",
|
this.Error("玩家体力变化 UserVitChangedPush推送失败",
|
||||||
log.Field{Key: "uid", Value: u.Uid},
|
log.Field{Key: "uid", Value: u.Uid},
|
||||||
log.Field{Key: comm.ResPs, Value: total},
|
log.Field{Key: comm.ResPs, Value: changed},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user