func (d *DbBridge) savePlayer(p *BasePlayer, typ int) error { if p == nil || p.Entity == nil { return errors.New("player not created") } App.Save(p.Entity, typ) trans := App.GetLandpos(p.Entity) p.trans = trans save := share.UpdateUser{} save.Account = p.Account save.Name = p.ChooseRole save.Type = typ save.Scene, save.X, save.Y, save.Z, save.Dir = p.trans.Scene, p.trans.Pos.X, p.trans.Pos.Y, p.trans.Pos.Z, p.trans.Dir save.SaveData = *share.GetSaveData(p.Entity) db := server.GetAppByType("database") if db != nil { err := db.Call(&p.Mailbox, "Account.SavePlayer", save) if err == nil { p.Entity.ClearSaveFlag() } return err } return server.ErrAppNotFound }
func (status *StatusApp) OnShutdown() bool { if server.GetAppByType("base") == nil { status.Exit() return false } status.shutdown = 1 return false }
func (d *DbBridge) getUserInfo(mailbox rpc.Mailbox, account string) error { db := server.GetAppByType("database") if db != nil { return db.Call(&mailbox, "Account.GetUserInfo", account) } return server.ErrAppNotFound }
func (d *DbBridge) SelectUserBak(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) { r := server.NewMessageReader(msg) save := share.LoadUserBak{} if server.Check(r.ReadObject(&save)) { return 0, nil } db := server.GetAppByType("database") info := share.ClearUser{save.Account, save.Name} player := App.Players.GetPlayer(mailbox.Id) if player == nil { log.LogError("player not found, id:", mailbox.Id) db.Call(&mailbox, "Account.ClearPlayerStatus", info) //角色没有找到 return 0, nil } if player.State != STATE_LOGGED { log.LogError("player state not logged") db.Call(&mailbox, "Account.ClearPlayerStatus", info) player.Leave() return 0, nil } if save.Data == nil { db.Call(&mailbox, "Account.ClearPlayerStatus", info) server.Check(server.Error(nil, &mailbox, "Login.Error", share.ERROR_SELECT_ROLE_ERROR)) return 0, nil } err := player.LoadPlayer(save) if server.Check(err) { db.Call(&mailbox, "Account.ClearPlayerStatus", info) return 0, nil } status := server.GetAppByType("status") if status != nil { status.Call(&mailbox, "PlayerList.UpdatePlayer", player.Account, player.ChooseRole, App.Name) } //App.AreaBridge.getArea(mailbox, save.Scene) //这里会自动加入场景 return 0, nil }
func (a *AreaBridge) getArea(mailbox rpc.Mailbox, id string) error { app := server.GetAppByType("areamgr") if app == nil { return server.ErrAppNotFound } err := app.Call(&mailbox, "AreaMgr.GetArea", id) if err != nil { log.LogError(err) } return err }
func (p *BasePlayer) updatemin(intervalid server.TimerID, count int32, args interface{}) { p.CheckNewDay() //任务更新 App.tasksystem.OnUpdate(p.Entity.(*entity.Player)) //清理过期的邮件 DeleteExpiredLetter(p.Entity.(*entity.Player)) db := server.GetAppByType("database") if db != nil { server.NewDBWarp(db).LookLetter(nil, p.Entity.GetDbId(), "DbBridge.LookLetterBack", share.DBParams{"mailbox": p.Mailbox}) } }
func (d *DbBridge) selectUser(mailbox rpc.Mailbox, account string, rolename string, index int) error { db := server.GetAppByType("database") if db != nil { loaduser := share.LoadUser{} loaduser.Account = account loaduser.RoleName = rolename loaduser.Index = index return db.Call(&mailbox, "Account.LoadUser", loaduser) } return server.ErrAppNotFound }
func (p *PlayerList) RemovePlayer(session int64) bool { if pl, exist := p.players[session]; exist && !pl.Deleted { status := server.GetAppByType("status") if status != nil { status.Call(nil, "PlayerList.UpdatePlayer", pl.Account, pl.ChooseRole, "") } pl.Deleted = true pl.State = STATE_DELETING log.LogDebug("Remove player:", pl.ChooseRole, " session:", session) return true } return false }
func (d *DbBridge) createRole(mailbox rpc.Mailbox, obj datatype.Entityer, account string, name string, index int, save *share.DbSave) error { db := server.GetAppByType("database") if db != nil { trans := App.GetLandpos(obj) cu := share.CreateUser{} cu.Account = account cu.Name = name cu.Index = index cu.Scene, cu.X, cu.Y, cu.Z, cu.Dir = trans.Scene, trans.Pos.X, trans.Pos.Y, trans.Pos.Z, trans.Dir cu.SaveData = *save return db.Call(&mailbox, "Account.CreateUser", cu) } return server.ErrAppNotFound }
func (d *DbBridge) LookLetterBack(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) { params := share.DBParams{} r := server.NewMessageReader(msg) if server.Check(r.ReadObject(¶ms)) { return 0, nil } if !params["result"].(bool) { return 0, nil } mailbox = params["mailbox"].(rpc.Mailbox) p := App.Players.GetPlayer(mailbox.Id) if p == nil { log.LogError("player not found, id:", mailbox.Id) //角色没有找到 return 0, nil } player := p.Entity.(*entity.Player) db := server.GetAppByType("database") if db == nil { log.LogError(server.ErrAppNotFound) return 0, nil } warp := server.NewDBWarp(db) letters := params["letters"].([]*share.LetterInfo) for _, letter := range letters { idx := player.MailBox_r.AddRowValue(-1, letter.Source, letter.Source_name, util.UTC2Loc(letter.Send_time.Time.UTC()).Unix(), letter.Title, letter.Content, letter.Appendix, 0, letter.Serial_no, letter.Msg_type) if idx == -1 { //邮箱满了 server.Error(nil, &mailbox, "Letter.Error", ERR_MAILBOX_FULL) break } //删信 warp.RecvLetter(nil, player.GetDbId(), letter.Serial_no, "_", share.DBParams{}) } return 0, nil }
func (b *BaseApp) StartInit() { db := server.GetAppByType("database") db.Call(nil, "Account.ClearStatus", b.Name) }
func (status *StatusApp) OnLost(app string) { if server.GetAppByType("base") == nil && status.shutdown == 1 { status.Exit() } }