コード例 #1
0
ファイル: AuthServer.go プロジェクト: bodogbo/OSG-Server-Go
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
}
コード例 #2
0
ファイル: Connector.go プロジェクト: bodogbo/OSG-Server-Go
func (self *Connector) CS_CheckSession(conn server.RpcConn, login protobuf.CS_CheckSession) (err error) {

	rep := protobuf.SC_CheckSessionResult{}
	uid := login.GetUid()
	var rst []byte

	rst, err = redis.Bytes(self.maincache.Do("GET", "SessionKey_"+uid))
	rep.SetResult(protobuf.SC_CheckSessionResult_AUTH_FAILED)
	rep.SetServerTime(uint32(time.Now().Unix()))
	if rst != nil || err == nil {
		if login.GetSessionKey() == string(rst) {
			rep.SetResult(protobuf.SC_CheckSessionResult_OK)
		}
	}

	logger.Debug("SC_CheckSessionResult %v", rep)

	rep.SetResult(rep.GetResult())

	if rep.GetResult() == protobuf.SC_CheckSessionResult_OK {
		WriteResult(conn, &rep)
		if p, ok := self.playersbyid[login.GetUid()]; ok {
			if err := p.conn.Close(); err == nil {
				logger.Info("kick the online player")
			}
		}

		var base protobuf.PlayerBaseInfo
		logger.Info("query db : %v", login.GetUid())
		result, err := db.Query("playerbase", login.GetUid(), &base)
		if result == false {
			base = protobuf.PlayerBaseInfo{}
			base.SetUid(login.GetUid())

			stat := &protobuf.StatusInfo{}
			stat.SetName("test_" + uid)
			stat.SetLevel(1)

			base.SetStat(stat)
			db.Write("playerbase", login.GetUid(), &base)
			logger.Info("playerbase create %v", login.GetUid())
		} else {
			if err != nil {
				logger.Info("err query db : %v", err)
				return err
			}
			logger.Info("playerbase find")
		}

		p := &Player{PlayerBaseInfo: &base, conn: conn}

		p.SetUid(uid)

		//进入服务器全局表

		self.addPlayer(conn.GetId(), p)

	} else {
		WriteResult(conn, &rep)

		go func() {
			time.Sleep(time.Millisecond * 1000)
			defer func() {
				conn.Close()
			}()
		}()
	}

	return nil
}
コード例 #3
0
ファイル: Player.go プロジェクト: bodogbo/OSG-Server-Go
func (p *Player) Save() {
	db.Write("playerbase", p.GetUid(), p.PlayerBaseInfo)
}