Exemple #1
0
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
}
Exemple #2
0
func ConvertPlayerToCreature(p *protobuf.PlayerBaseInfo) *protobuf.CreatureBaseInfo {
	creature := &protobuf.CreatureBaseInfo{}
	creature.SetUid(p.GetUid())
	creature.SetStat(p.GetStat())
	creature.SetBp(p.GetBp())
	creature.SetProperty(p.GetProperty())
	creature.SetRevise(p.GetRevise())
	creature.SetAgainst(p.GetAgainst())
	return creature
}