示例#1
0
文件: db_raw.go 项目: mysll/flynet
func (this *Database) RecvLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var uid uint64
	var serial_no uint64
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &uid, &serial_no, &callback, &callbackparams)) {
		return 0, nil
	}

	letter, err := this.recvLetterBySerial(uid, serial_no)
	if err != nil {
		log.LogError(err)
		return share.ERR_REPLY_FAILED, nil
	}

	if callback == "_" {
		return 0, nil
	}
	callbackparams["result"] = false
	if letter != nil {
		callbackparams["result"] = true
		callbackparams["letter"] = letter
	}

	server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	return 0, nil
}
示例#2
0
文件: baseproxy.go 项目: mysll/flynet
func (b *BaseProxy) SyncPlayerBak(mailbox rpc.Mailbox, info map[ObjectID]ObjectID) error {
	//同步数据
	player := App.players.GetPlayer(mailbox)
	if player == nil {
		log.LogError("player not found")
	}

	for k, v := range info {
		ent := App.GetEntity(k)
		if ent == nil {
			log.LogError("object not found")
			continue
		}
		ent.SetExtraData("linkObj", v)
	}

	var err error
	if player.Quit {
		App.players.RemovePlayer(mailbox)
		err = server.MailTo(&mailbox,
			&player.Base,
			"AreaBridge.RemovePlayerBak",
			"ok",
		)
	}

	return err
}
示例#3
0
文件: area.go 项目: mysll/flynet
func (a *AreaBridge) AddPlayerBak(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	res, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	if res == "ok" {
		player := App.Players.GetPlayer(mailbox.Id)
		if player == nil {
			log.LogFatalf("can not be nil")
			return 0, nil
		}

		if player.State != STATE_ENTERAREA { //可能客户端已经断开了,则让玩家下线
			player.Leave()
			return 0, nil
		}

		player.EnterScene()
		return 0, nil
	} else {
		err := &s2c.Error{}
		err.ErrorNo = proto.Int32(share.ERROR_ROLE_ENTERAREA_ERROR)
		server.Check(server.MailTo(nil, &mailbox, "error", err))
		return 0, nil
	}

}
示例#4
0
文件: sync.go 项目: mysll/flynet
func (s *Sync) SyncPlayer(src rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	infos := make(map[string]interface{})
	if server.Check(r.ReadObject(&infos)) {
		return 0, nil
	}
	mb := infos["mailbox"].(rpc.Mailbox)
	info := infos["data"].(*EntityInfo)
	playerid := info.ObjId
	player := App.GetEntity(playerid)
	if player == nil || player.ObjType() != PLAYER {
		log.LogError("sync player player not found", playerid)
		return 0, nil
	}
	for k := range s.childs {
		delete(s.childs, k)
	}
	for k := range s.newobj {
		delete(s.newobj, k)
	}
	s.getAllChilds(player)
	s.sync(info)
	for k := range s.childs { //剩余的表示需要删除
		App.Destroy(k)
	}

	server.Check(server.MailTo(&mb, &src, "BaseProxy.SyncPlayerBak", s.newobj))
	return 0, nil
}
示例#5
0
文件: account.go 项目: mysll/flynet
func (a *Account) Login(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Enterbase{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	if App.Login.checkClient(args.GetUser(), args.GetKey()) {
		if pl := App.Players.AddPlayer(mailbox.Id); pl != nil {
			log.LogMessage("add player:", mailbox)
			pl.Account = args.GetUser()
			pl.State = STATE_LOGGED
			if args.GetRolename() != "" {
				pl.ChooseRole = args.GetRolename()
				server.Check(App.DbBridge.selectUser(mailbox, pl.Account, args.GetRolename(), int(args.GetRoleindex())))
				return 0, nil
			}
			server.Check(App.DbBridge.getUserInfo(mailbox, args.GetUser()))
			return 0, nil
		}
		log.LogError("player add failed", mailbox)
		return 0, nil
	} else {
		log.LogDebug(args.GetUser(), args.GetKey())
		err := &s2c.Error{}
		err.ErrorNo = proto.Int32(share.ERROR_LOGIN_FAILED)
		server.Check(server.MailTo(nil, &mailbox, "Login.Error", err))
		return 0, nil
	}
}
示例#6
0
文件: baseproxy.go 项目: mysll/flynet
func (b *BaseProxy) RemovePlayer(mailbox rpc.Mailbox, reason int) error {
	//同步数据
	player := App.players.GetPlayer(mailbox)
	if player == nil {
		log.LogError("player not found")
	}
	player.Save(true)

	var err error
	if player.Entity.GetExtraData("saveData") == nil {
		log.LogError("player save data is nil")
		return err
	}

	err = server.MailTo(&App.MailBox,
		&player.Base,
		"Sync.SyncPlayer",
		map[string]interface{}{
			"mailbox": player.Mailbox,
			"data":    player.Entity.GetExtraData("saveData")},
	)

	player.Entity.RemoveExtraData("saveData")

	return err
}
示例#7
0
文件: db_raw.go 项目: mysll/flynet
func (this *Database) SendSystemLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var source_name string
	var recvacc, recvrole string
	var typ int32
	var title, content, appendix string
	var callback string
	var callbackparams share.DBParams
	if server.Check(server.ParseArgs(msg, &source_name, &recvacc, &recvrole, &typ, &title, &content, &appendix, &callback, &callbackparams)) {
		return 0, nil
	}

	var roleid uint64
	if recvacc == "" && recvrole == "" {
		roleid = 0
	} else {
		var err error
		roleid, err = GetRoleUid(recvacc, recvrole)
		if err != nil {
			callbackparams["result"] = false
			callbackparams["err"] = "role not found"
			if callback != "_" {
				server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
			}
			log.LogError(err)
			return 0, nil
		}
	}

	serial_no, err := this.systemLetter(source_name, roleid, recvacc, recvrole, typ, title, content, appendix)
	if err != nil {
		if callback != "_" {
			callbackparams["result"] = false
			callbackparams["err"] = err.Error()
			server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
		}
		log.LogError(err)
		return 0, nil
	}

	if callback != "_" {
		callbackparams["result"] = true
		callbackparams["serial_no"] = serial_no
		server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	}
	return 0, nil

}
示例#8
0
文件: account.go 项目: mysll/flynet
func (a *Account) SavePlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	var data share.UpdateUser
	if server.Check(r.ReadObject(&data)) {
		return 0, nil
	}
	if data.SaveData.Data == nil {
		log.LogError("save data is nil")
		return 0, nil
	}

	sqlconn := db.sql
	base := rpc.NewMailBox(0, 0, mailbox.App)
	infos := make([]share.ObjectInfo, 0, 128)
	if err := UpdateItem(sqlconn, data.SaveData.Data.DBId, data.SaveData.Data); err != nil {
		log.LogError(err)
		server.Check(server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", err.Error()))
		return 0, nil
	}

	if data.Type == share.SAVETYPE_OFFLINE {
		_, err := db.sql.Exec("UPDATE `role_info` SET `status`=?, `serverid`=?, `scene`=?, `scene_x`=?, `scene_y`=?, `scene_z`=?, `scene_dir`=?, `roleinfo`=? WHERE `account`=? and `rolename`=?",
			0,
			"",
			data.Scene, data.X, data.Y, data.Z, data.Dir,
			data.SaveData.RoleInfo,
			data.Account,
			data.Name,
		)
		if err != nil {
			log.LogError(err)
			server.Check(server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", err.Error()))
			return 0, nil
		}

		server.Check(server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", "ok"))
		return 0, nil
	}

	bakinfo := share.UpdateUserBak{}
	bakinfo.Infos = infos
	server.Check(server.MailTo(&mailbox, &base, "DbBridge.UpdateUserInfo", bakinfo))
	return 0, nil
}
示例#9
0
文件: account.go 项目: mysll/flynet
func (a *Account) SavePlayer(mailbox rpc.Mailbox, data share.UpdateUser) error {
	return a.process("SavePlayer", func() error {
		base := rpc.NewMailBox(0, 0, mailbox.App)

		//save
		if err := SaveToDb(db.DB, 0, &data.SaveData); err != nil {
			log.LogError(err)
			return server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", err.Error())
		}

		if data.Type == share.SAVETYPE_OFFLINE {
			if err := a.ClearPlayerStatus(mailbox, share.ClearUser{Account: data.Account, Name: data.Name}); err != nil {
				log.LogError(err)
				return server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", err.Error())
			}
		}
		log.LogMessage("player:", data.Name, " save succeed")
		return server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", "ok")
	})
}
示例#10
0
func (p *BasePlayer) EnterScene() error {
	p.State = STATE_GAMING
	enter := &s2c.EnterScene{}
	enter.Name = proto.String(p.ChooseRole)
	err := server.MailTo(nil, &p.Mailbox, "Login.EnterScene", enter)
	if err != nil {
		log.LogError(err)
	}

	return err
}
示例#11
0
func (p *PlayerList) CheckNewDay() {
	if util.IsSameDay(p.lasttime, time.Now()) {
		return
	}

	newday := &s2c.Respnewday{}
	for _, pl := range p.players {
		if !pl.Deleted {
			server.MailTo(nil, &pl.Mailbox, "SyncTime.RespNewDay", newday)
		}
	}

	p.lasttime = time.Now()
}
示例#12
0
文件: db_raw.go 项目: mysll/flynet
func (this *Database) QueryLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var uid uint64
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &uid, &callback, &callbackparams)) {
		return 0, nil
	}

	count, _ := this.queryLetter(uid)
	callbackparams["count"] = count
	server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	return 0, nil
}
示例#13
0
func (p *BasePlayer) PlayerReady() {
	//同步用户信息
	player := p.Entity.(*entity.Player)

	p.CheckNewDay()
	App.tasksystem.CheckTaskInfo(player)
	//检查邮件心跳
	p.updateid = App.AddTimer(time.Minute, -1, p.updatemin, nil)
	//清理过期的邮件
	DeleteExpiredLetter(player)
	if p.LandTimes == 0 {
		App.Command(p.Entity.GetObjId(), p.Entity.GetObjId(), share.PLAYER_FIRST_LAND, nil)
	}

	server.MailTo(nil, &p.Mailbox, "Role.Ready", &s2c.Void{})
}
示例#14
0
文件: login.go 项目: mysll/flynet
func (l *Login) SwitchPlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	user, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	serial := rand.Int31()
	log.LogMessage("client serial:", serial)
	l.Cached[user] = cacheUser{serial, time.Now()}

	ret := &s2c.Loginsucceed{}
	ret.Host = proto.String(App.ClientHost)
	ret.Port = proto.Int32(int32(App.ClientPort))
	ret.Key = proto.Int32(serial)
	server.Check(server.MailTo(nil, &mailbox, "Login.SwitchBase", ret))
	return 0, nil
}
示例#15
0
文件: account.go 项目: mysll/flynet
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
}
示例#16
0
文件: account.go 项目: mysll/flynet
func (a *Account) GetUserInfo(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	reader := server.NewMessageReader(msg)
	account, err := reader.ReadString()
	if server.Check(err) {
		return 0, nil
	}

	s := db.sql
	r, err := s.Query(`SELECT rolename, roleindex, roleinfo, locktime, locked 
FROM role_info
WHERE account=? and deleted =0`, account)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}
	defer r.Close()

	var rolename string
	var roleindex int32
	var roleinfo string
	var locktime mysql.NullTime
	var locked int

	info := &s2c.RoleInfo{}
	info.UserInfo = make([]*s2c.Role, 0, 4)
	for r.Next() {
		err = r.Scan(&rolename, &roleindex, &roleinfo, &locktime, &locked)
		if err != nil {
			log.LogError(err)
			return 0, nil
		}
		if locked == 0 {
			role := &s2c.Role{}
			role.Name = proto.String(rolename)
			role.Index = proto.Int32(roleindex)
			role.Roleinfo = proto.String(roleinfo)

			info.UserInfo = append(info.UserInfo, role)
		}
	}
	server.Check(server.MailTo(nil, &mailbox, "Role.RoleInfo", info))
	return 0, nil
}
示例#17
0
文件: account.go 项目: mysll/flynet
func (a *Account) Login(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	logindata := &c2s.Loginuser{}
	if server.Check(server.ParseProto(msg, logindata)) {
		return 0, nil
	}
	if logindata.GetPassword() == "123" {
		apps := server.GetAppByName("basemgr")
		if apps != nil {
			server.Check(apps.Call(&mailbox, "Session.GetBaseAndId", logindata.GetUser()))
			return 0, nil
		}
	} else {
		e := &s2c.Error{}
		e.ErrorNo = proto.Int32(share.ERROR_LOGIN_FAILED)
		server.MailTo(nil, &mailbox, "Login.Error", e)
	}

	return 0, nil
}
示例#18
0
文件: account.go 项目: mysll/flynet
func (a *Account) GetUserInfo(mailbox rpc.Mailbox, account string) error {
	return a.process("GetUserInfo", func() error {

		c := db.DB.C(ROLEINFO)
		roleinfos := []RoleInfo{}
		c.Find(bson.M{"account": account, "deleted": 0}).All(&roleinfos)

		info := &s2c.RoleInfo{}
		info.UserInfo = make([]*s2c.Role, 0, 4)

		for _, r := range roleinfos {
			if r.Locked == 0 {
				role := &s2c.Role{}
				role.Name = proto.String(r.Rolename)
				role.Index = proto.Int32(int32(r.Roleindex))
				role.Roleinfo = proto.String(r.Roleinfo)
				info.UserInfo = append(info.UserInfo, role)
			}
		}

		return server.MailTo(nil, &mailbox, "roleinfo", info)
	})
}
示例#19
0
文件: db_raw.go 项目: mysll/flynet
func (this *Database) LookLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var uid uint64
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &uid, &callback, &callbackparams)) {
		return 0, nil
	}

	letters, err := this.lookLetter(uid)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}

	callbackparams["result"] = false
	if letters != nil {
		callbackparams["result"] = true
		callbackparams["letters"] = letters
	}

	server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	return 0, nil
}
示例#20
0
文件: account.go 项目: mysll/flynet
func (a *Account) CreateUser(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	reader := server.NewMessageReader(msg)
	var info share.CreateUser
	if server.Check(reader.ReadObject(&info)) {
		return 0, nil
	}
	if info.SaveData.Data == nil {
		log.LogError("save data is nil")
		return 0, nil
	}

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

	if r, err = sqlconn.Query("SELECT count(*) FROM `role_info` WHERE `account`=?", info.Account); err != nil {
		log.LogError(err)
		server.Check(app.Call(&mailbox, "DbBridge.CreateRoleBack", err.Error()))
		return 0, nil
	}
	var count int
	if r.Next() {
		r.Scan(&count)
	}
	r.Close()

	if count >= db.limit {
		errmsg := &s2c.Error{}
		errmsg.ErrorNo = proto.Int32(share.ERROR_ROLE_LIMIT)
		server.MailTo(&mailbox, &mailbox, "Role.Error", errmsg)
		return 0, nil
	}

	if db.nameunique { //名称是否唯一
		if r, err = sqlconn.Query("SELECT `uid` FROM `role_info` WHERE `account`=? and `rolename`=? LIMIT 1", info.Account, info.Name); err != nil {
			log.LogError(err)
			server.Check(app.Call(&mailbox, "DbBridge.CreateRoleBack", err.Error()))
			return 0, nil
		}
		if r.Next() {
			log.LogError("name conflict")
			r.Close()
			errmsg := &s2c.Error{}
			errmsg.ErrorNo = proto.Int32(share.ERROR_NAME_CONFLIT)
			server.Check(server.MailTo(&mailbox, &mailbox, "Role.Error", errmsg))
			return 0, nil
		}
		r.Close()
	}

	uid, err := sqlconn.GetUid("userid")
	if err != nil {
		log.LogError(err)
		server.Check(app.Call(&mailbox, "DbBridge.CreateRoleBack", err.Error()))
		return 0, nil
	}

	if err = CreateUser(sqlconn, uid, info.Account, info.Name, info.Index, info.Scene, info.X, info.Y, info.Z, info.Dir, info.SaveData.Data.Typ, &info.SaveData); err != nil {
		log.LogError(err)
		server.Check(app.Call(&mailbox, "DbBridge.CreateRoleBack", err.Error()))
		return 0, nil
	}

	server.Check(server.GetLocalApp().Call(&mailbox, "Account.GetUserInfo", info.Account))

	return 0, nil
	//return app.Call(&mailbox, "DbBridge.CreateRoleBack", "ok")
}
示例#21
0
文件: account.go 项目: mysll/flynet
func (a *Account) CreateUser(mailbox rpc.Mailbox, info share.CreateUser) error {
	if info.SaveData.Data == nil {
		return errors.New("save data is nil")
	}
	return a.process("CreateUser", func() error {
		app := server.GetAppById(mailbox.App)
		if app == nil {
			return server.ErrAppNotFound
		}

		c := db.DB.C(ROLEINFO)
		result := RoleInfo{}
		if count, err := c.Find(bson.M{"account": info.Account}).Count(); err == nil {
			if count >= db.limit {
				errmsg := &s2c.Error{}
				errmsg.ErrorNo = proto.Int32(share.ERROR_ROLE_LIMIT)
				server.MailTo(&mailbox, &mailbox, "Role.Error", errmsg)
				return nil
			}
		}

		if err := c.Find(bson.M{"rolename": info.Name}).One(&result); err == nil {
			log.LogError("name conflict")
			err := &s2c.Error{}
			err.ErrorNo = proto.Int32(share.ERROR_NAME_CONFLIT)
			return server.MailTo(nil, &mailbox, "Role.Error", err)
		}

		uid := db.getNextSequence("userid")
		if uid == 0 {
			err := errors.New("uid is zero")
			log.LogError(err)
			return err
		}

		user := RoleInfo{
			Uid:           uid,
			Account:       info.Account,
			Rolename:      info.Name,
			Createtime:    time.Now(),
			Lastlogintime: time.Time{},
			Locktime:      time.Time{},
			Roleindex:     int8(info.Index),
			Roleinfo:      "",
			Entity:        info.SaveData.Data.Typ,
			Deleted:       0,
			Locked:        0,
			Status:        0,
			Serverid:      "",
			Scene:         info.Scene,
			Scene_x:       info.X,
			Scene_y:       info.Y,
			Scene_z:       info.Z,
		}

		if err := c.Insert(user); err != nil {
			log.LogError(err)
			return app.Call(&mailbox, "DbBridge.CreateRoleBack", err.Error())
		}

		if err := SaveToDb(db.DB, uid, &info.SaveData); err != nil {
			c.Remove(bson.M{"_id": uid})
			log.LogError(err)
			return app.Call(&mailbox, "DbBridge.CreateRoleBack", err.Error())

		}

		log.LogMessage("player:", info.Name, " create succeed")
		return app.Call(&mailbox, "DbBridge.CreateRoleBack", "ok")
	})

}