Exemplo n.º 1
0
func testCommon() {
	logger.Info("uuid: %v", common.GenUUID("123"))
	logger.Info("uuid: %v", common.GenUUID("account"))

	passwdhash := common.GenPassword("account", "passwd")
	logger.Info("passwdhash: %v", passwdhash)
	logger.Info("check: %v", common.CheckPassword(passwdhash, "account", "passwd"))

	sessionKey := common.GenSessionKey()
	logger.Info("session: %v", sessionKey)
	logger.Info("check: %v", common.CheckSessionKey(sessionKey))
}
Exemplo n.º 2
0
func (self *FightServer) StartBattle(conn server.RpcConn, player protobuf.PlayerBaseInfo) error {

	logger.Debug("StartBattle")

	id := common.GenUUID(fmt.Sprintf("%d", atomic.AddUint64(&self.id, 1)))
	base := &protobuf.BattleInfo{}
	base.SetBid(id)
	partners := make([]*protobuf.CreatureBaseInfo, 0, 10)
	mosters := make([]*protobuf.CreatureBaseInfo, 0, 10)
	partners = append(partners, ConvertPlayerToCreature(&player))
	mosters = append(mosters, RandomCreature("1"), RandomCreature("2"), RandomCreature("3"), RandomCreature("4"), RandomCreature("5"))
	base.SetPartner(partners)
	base.SetEnemy(mosters)
	base.SetAttackunits(make([]*protobuf.AttackInfo, 0, 10))
	base.SetSpells(make([]*protobuf.SpellInfo, 0, 10))
	b := &Battle{BattleInfo: base}

	//WriteResult(conn, base)
	notify := &protobuf.NotifyBattleStart{}
	notify.SetBid(base.GetBid())
	notify.SetPartner(partners)
	notify.SetEnemy(mosters)
	WriteResult(conn, notify)

	self.addBattle(b)

	return nil
}
Exemplo n.º 3
0
func (self *AuthServer) LA_CheckAccount(req *protobuf.LA_CheckAccount, ret *protobuf.AL_CheckAccountResult) error {

	uid := common.GenUUID(req.GetAccount())

	if len(req.GetUid()) > 0 {
		if req.GetUid() != uid { //客户端伪造uid
			(*ret).SetResult(protobuf.AL_CheckAccountResult_AUTH_FAILED)
			return nil
		}
	}

	account := &protobuf.AccountInfo{}
	result, err := db.Query("AccountInfo", uid, account)

	if err != nil {
		(*ret).SetResult(protobuf.AL_CheckAccountResult_SERVERERROR)
		return nil
	}

	if result == false { //用户注册

		account.SetUid(uid)
		account.SetAccount(req.GetAccount())
		account.SetPassword(common.GenPassword(req.GetAccount(), req.GetPassword()))
		account.SetLanguage(req.GetLanguage())
		account.SetOption(req.GetOption())
		account.SetSessionKey(common.GenSessionKey())
		account.SetUdid(req.GetUdid())
		account.SetCreateTime(uint32(time.Now().Unix()))

		db.Write("AccountInfo", uid, account)
		logger.Info("Auth AccountInfo create")

	} else { //用户登陆
		if !common.CheckPassword(account.GetPassword(), req.GetAccount(), req.GetPassword()) {
			(*ret).SetResult(protobuf.AL_CheckAccountResult_AUTH_FAILED)
			return nil
		}
		account.SetSessionKey(common.GenSessionKey()) //保存进缓存
		db.Write("AccountInfo", uid, account)
		logger.Info("Auth Account find")
	}

	self.maincache.Do("SET", "SessionKey_"+uid, []byte(account.GetSessionKey()))

	(*ret).SetResult(protobuf.AL_CheckAccountResult_OK)
	(*ret).SetSessionKey(account.GetSessionKey())
	(*ret).SetUid(account.GetUid())

	logger.Info("ComeInto AuthServer.Login %v, %v", req, ret)

	return nil
}