示例#1
0
文件: db.go 项目: mysll/flynet
func (d *DbBridge) CreateRoleBack(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	errstr, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	if errstr != "ok" {
		server.Check(server.Error(nil, &mailbox, "Role.Error", share.ERROR_CREATE_ROLE_ERROR))
		return 0, nil
	}

	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		log.LogError("player not found, id:", mailbox.Id)
		//角色没有找到
		return 0, nil
	}

	if player.State != STATE_LOGGED {
		log.LogError("player state not logged")
		return 0, nil
	}

	server.Check(d.getUserInfo(mailbox, player.Account))
	return 0, nil
}
示例#2
0
文件: db.go 项目: mysll/flynet
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
}
示例#3
0
文件: db.go 项目: mysll/flynet
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(&params)) {
		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
}
示例#4
0
func (p *PlayerList) SwitchPlayer(player *BasePlayer) error {
	oldsession := player.Session
	//被顶替的玩家
	replace := p.FindPlayer(player.Account, player.ChooseRole, player.Session)
	if replace == nil {
		log.LogError("old player not found")
		return nil
	}

	//交换连接
	App.SwitchConn(replace.Session, player.Session)
	//把原来的玩家踢下线
	server.Error(nil, &player.Mailbox, "Login.Error", share.ERROR_ROLE_REPLACE)
	App.DelayKickUser(oldsession, 5)
	//同步玩家数据
	App.AttachPlayer(replace.Entity, replace.Mailbox)

	player.Account += "*replace*"
	player.ChooseRole += "*replace*"
	log.LogInfo("switch player: old:", oldsession, " new:", replace.Session)
	return nil
}
示例#5
0
//接收附件
func (l *LetterSystem) RecvAppendix(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Reqoperatemail{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	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)

	if player.MailBox_r.GetRows() == 0 {
		return 0, nil
	}

	var mails []uint64
	if len(args.Mails) == 0 {
		mails = make([]uint64, 0, player.MailBox_r.GetRows())
		for i := 0; i < player.MailBox_r.GetRows(); i++ {
			sno, _ := player.MailBox_r.GetSerial_no(i)
			mails = append(mails, sno)
		}
	} else {
		mails = []uint64{uint64(args.Mails[0])}
	}

	for _, serial_no := range mails {
		row := player.MailBox_r.FindSerial_no(serial_no)
		if row == -1 {
			continue
		}
		info, err := player.MailBox_r.GetAppendix(row)
		if err != nil || info == "" {
			continue
		}

		var appendixs []Appendix
		err = json.Unmarshal([]byte(info), &appendixs)
		if err != nil {
			log.LogError(err)
			continue
		}

		flag := false
		index := -1
		var res int32
		for k, appendix := range appendixs {
			item, err := App.CreateFromConfig(appendix.Configid)
			if err != nil { //物品不存在
				log.LogError("appendix not found ", appendix.Configid)
				continue
			}

			item.SetDbId(appendix.UID)
			switch inst := item.(type) {
			case *entity.Item:
				inst.SetAmount(appendix.Amount)
				inst.SetTime(appendix.RemainTime)
			}

			container := GetContainer(player, item)
			if container == nil {
				App.Destroy(item.GetObjId())
				flag = true
				res = share.ERROR_SYSTEMERROR
				break
			}

			_, err = App.AddChild(container.GetObjId(), item.GetObjId(), -1)
			if err != nil {
				App.Destroy(item.GetObjId())
				flag = true
				res = share.ERROR_CONTAINER_FULL
				break
			}
			index = k
		}

		if flag {
			appendixs = appendixs[index+1:]
			data, _ := json.Marshal(appendixs)
			player.MailBox_r.SetAppendix(row, string(data))
			server.Error(nil, &mailbox, "Mail.Error", res)
			continue
		}

		player.MailBox_r.SetAppendix(row, "")
	}

	return 0, nil
}