Exemple #1
0
func (a *Account) LoadUser(mailbox rpc.Mailbox, info share.LoadUser) error {
	return a.process("LoadUser", func() error {
		bak := share.LoadUserBak{}
		app := server.GetAppById(mailbox.App)
		if app == nil {
			return server.ErrAppNotFound
		}

		c := db.DB.C(ROLEINFO)
		roleinfo := RoleInfo{}
		if err := c.Find(bson.M{"rolename": info.RoleName, "roleindex": info.Index}).One(&roleinfo); err != nil {
			return app.Call(&mailbox, "DbBridge.SelectUserBak", bak)
		}

		if roleinfo.Status == 1 {
			err := &s2c.Error{}
			err.ErrorNo = proto.Int32(share.ERROR_ROLE_USED)
			log.LogError("role inuse", info.RoleName)
			return server.MailTo(nil, &mailbox, "Login.Error", err)
		}

		//Loaduser
		data, err := LoadUser(db.DB, roleinfo.Uid, roleinfo.Entity)
		if err != nil {
			log.LogError(err)
			return err
		}

		c.Update(bson.M{"rolename": roleinfo.Rolename}, bson.M{"$set": bson.M{"lastlogintime": time.Now(), "status": 1, "serverid": mailbox.App}})

		bak.Name = info.RoleName
		bak.Scene = roleinfo.Scene
		bak.X = roleinfo.Scene_x
		bak.Y = roleinfo.Scene_y
		bak.Z = roleinfo.Scene_z
		bak.Data = &data

		log.LogMessage("load role succeed:", info.RoleName)

		return app.Call(&mailbox, "DbBridge.SelectUserBak", bak)
	})
	return nil
}
Exemple #2
0
func (a *Account) LoadUser(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	reader := server.NewMessageReader(msg)
	var info share.LoadUser
	if server.Check(reader.ReadObject(&info)) {
		return 0, nil
	}

	sqlconn := db.sql
	var r *sql.Rows
	var err error
	bak := share.LoadUserBak{}
	bak.Account = info.Account
	app := server.GetAppById(mailbox.App)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
		return 0, nil
	}

	if r, err = sqlconn.Query("SELECT `uid`,`locktime`,`locked`,`entity`, `status`, `serverid`, `scene`, `scene_x`, `scene_y`, `scene_z`, `scene_dir`, `roleinfo`, `landtimes` FROM `role_info` WHERE `account`=? and `rolename`=? and `roleindex`=? LIMIT 1", info.Account, info.RoleName, info.Index); err != nil {
		server.Check(err)
		return 0, nil
	}
	if !r.Next() {
		log.LogError("user not found")
		r.Close()
		server.Check(app.Call(&mailbox, "DbBridge.SelectUserBak", bak))
		return 0, nil
	}
	var uid uint64
	var ltime mysql.NullTime
	var locked int
	var ent string
	var status int
	var serverid string
	var scene string
	var x, y, z, dir float32
	var roleinfo string
	var landtimes int32
	err = r.Scan(&uid, &ltime, &locked, &ent, &status, &serverid, &scene, &x, &y, &z, &dir, &roleinfo, &landtimes)
	if err != nil {
		log.LogError("scan user failed")
		r.Close()
		return 0, nil
	}
	r.Close()

	if status == 1 {
		server.Check(app.Call(&mailbox, "DbBridge.RoleInUse", serverid))
		return 0, nil
	}

	data, err := LoadUser(sqlconn, uid, ent)
	if server.Check(err) {
		server.Check(err)
		return 0, nil
	}

	if _, err = sqlconn.Exec("UPDATE `role_info` set `lastlogintime`=?,`status`=?,`serverid`=?,`landtimes`=`landtimes`+1 WHERE `account`=? and `rolename`=? LIMIT 1", time.Now().Format("2006-01-02 15:04:05"), 1, app.Name, info.Account, info.RoleName); err != nil {
		log.LogError(err)
		return 0, nil
	}
	data.RoleInfo = roleinfo
	bak.Account = info.Account
	bak.Name = info.RoleName
	bak.Scene = scene
	bak.X = x
	bak.Y = y
	bak.Z = z
	bak.Dir = dir
	bak.LandTimes = landtimes
	bak.Data = &data
	server.Check(app.Call(&mailbox, "DbBridge.SelectUserBak", bak))
	return 0, nil
}