コード例 #1
0
ファイル: letter_logic.go プロジェクト: mysll/flynet
//删除信件
func (l *LetterSystem) DeleteLetter(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 len(args.Mails) == 0 {
		return 0, nil
	}

	for _, sno := range args.Mails {
		row := player.MailBox_r.FindSerial_no(uint64(sno))
		if row == -1 {
			return 0, nil
		}
		player.MailBox_r.Del(row)
	}
	return 0, nil
}
コード例 #2
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
	}
}
コード例 #3
0
ファイル: account.go プロジェクト: mysll/flynet
func (a *Account) CreatePlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Create{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}

	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		//角色没有找到
		return 0, nil
	}
	if player.State != STATE_LOGGED {
		log.LogWarning("player state not logged")
		return 0, nil
	}
	obj, err := App.CreateRole("Player", args)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}

	save := share.GetSaveData(obj)
	server.Check(App.DbBridge.createRole(mailbox, obj, player.Account, args.GetName(), int(args.GetIndex()), save))
	App.Destroy(obj.GetObjId())
	return 0, nil
}
コード例 #4
0
ファイル: task_logic.go プロジェクト: mysll/flynet
func (t *TaskLogic) Submit(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Reqreceivetask{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	p := App.Players.GetPlayer(mailbox.Id)
	if p == nil || p.Entity == nil {
		log.LogError("player not found")
		return 0, nil
	}
	player := p.Entity.(*entity.Player)

	taskid := args.GetTaskid()

	server.Check(App.tasksystem.Submit(player, taskid))
	return 0, nil
}
コード例 #5
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
}
コード例 #6
0
ファイル: account.go プロジェクト: mysll/flynet
func (a *Account) SelectUser(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Selectuser{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		//角色没有找到
		return 0, nil
	}
	if player.State != STATE_LOGGED {
		log.LogWarning("player state not logged")
		return 0, nil
	}

	player.ChooseRole = args.GetRolename()
	err := App.DbBridge.selectUser(mailbox, player.Account, args.GetRolename(), int(args.GetRoleindex()))
	if err != nil {
		log.LogError(err)
	}

	return 0, nil
}
コード例 #7
0
ファイル: letter_logic.go プロジェクト: mysll/flynet
//接收附件
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
}