Exemple #1
0
func Register(registerInfo_proto *protocol.S2SSystem_RegisterInfo) error {
	player := new(player.Player)

	//查询玩家名字是否被占用
	err := redis.Find("player:"+registerInfo_proto.GetName(), player)
	if err == nil {
		return errors.New("same nick")
	}
	//玩家id 增加1 读取现在最大玩家数据
	id, err := redis.Incr("Register:MaxId")
	if err != nil {
		return err
	}

	player.Info.ID = fmt.Sprintf("%s", id)
	player.Info.Name = registerInfo_proto.GetName()
	player.Info.Age = registerInfo_proto.GetAge()
	player.Info.Sex = registerInfo_proto.GetSex()

	player.Money = 0
	player.Exp = 0
	player.Password = registerInfo_proto.GetPassworld()
	player.Conn = nil

	//存储现在的玩家数据
	redis.Add("player:"+registerInfo_proto.GetName(), player)
	return err
}
Exemple #2
0
func (this *AccountInfo) Register(name string, pwd string, server_id string) (int, int) {
	this.accountMutex.Lock()
	defer this.accountMutex.Unlock()

	//通过内存数据库 先检查是否username相同
	redis_login_base := new(LoginBase)
	err := redis.Find("PlayerName:"+name, redis_login_base)
	if err != nil { //没有查到数据
		//写内存数据库与mysql
		this.config.count += 1
		user := LoginBase{PlayerId: this.config.count, PlayerName: name, PlayerPwd: pwd, Gold: 0, ServerId: server_id, IsForBid: false}

		//内存数据库
		err_redis := redis.Add("PlayerName:"+name, user)
		//mysql
		_, err_mysql := O.Insert(&user)

		if err_redis == nil && err_mysql == nil {
			return global.REGISTERSUCCESS, this.config.count
		} else {
			redis.Del("PlayerName:" + name)
			O.Delete(&user)
		}
	}

	Log.Trace("name = %s pwd = %s have same SAMENICK", name, pwd)
	return global.SAMENICK, 0
}
Exemple #3
0
//防外挂 逻辑更严密
func (this *Deal2A) NoteGame(player_id int32) {
	this.deal2amx.Lock()
	defer this.deal2amx.Unlock()

	id := this.server_id + player_id

	key := "role:" + strconv.Itoa(int(id))
	is_exists, _ := redis.Exists(key)

	if !is_exists {
		redis.Add(key, "")
	}
}