func (this *AccountInfo) Register(name string, pwd string, server_id int32) (int32, int32) { this.accountMutex.Lock() defer this.accountMutex.Unlock() //通过内存数据库 先检查是否username相同 err := redis.Find("PlayerName:"+name, this.redis_login_base) if err != nil { //没有查到数据 db_count_max += 1 user := LoginBase{PlayerId: db_count_max, PlayerName: name, PlayerPwd: pwd, ServerId: server_id, IsForBid: false} this.redis_login_base.Servers = append(this.redis_login_base.Servers, server_id) //内存数据库 err_redis_player := redis.Modify("PlayerName:"+name, user) err_redis_count := redis.Modify("PlayerCount", db_count_max) if err_redis_player == nil && err_redis_count == nil { return global.REGISTERSUCCESS, db_count_max } else { fmt.Println("数据写入错误") } } else { Log.Trace("name = %s pwd = %s have same SAMENICK", name, pwd) } return global.SAMENICK, 0 }
//玩家退出 func (this *Player) ExitGame() { this.LastTime = int32(time.Now().Unix()) this.Save() word.ExitWorld(this.PlayerId) global_guaji_players.Exit(this.Guaji_Stage.Now_Guaji_id, this.PlayerId) redis.Modify("uid", Global_Uid) }
func (this *Player) Save() { err := redis.Modify(strconv.Itoa(int(this.PlayerId)), this) if err != nil { Log.Error("Save Database error:%s", err.Error()) } }
//防外挂 逻辑更严密 func (this *Deal2A) NoteGame(player_id int64) { this.deal2amx.Lock() defer this.deal2amx.Unlock() is_exists, _ := redis.Exists(player_id) if !is_exists { redis.Modify(player_id, "") } fmt.Println("通知账号服务", player_id) }
func (this *Player) RegisterRole(player_id int64, nick string, HeroId int32, conn *net.Conn) int32 { //id role id key := strconv.Itoa(int(player_id)) redis.Modify(player_id, "") player := LoadPlayer(key) if player == nil { redis.Modify(player_id, "") //redis.Modify() //return global.REGISTERROLEERROR } if player.CreateTime > 0 { return global.ALREADYHAVE } //检测heroid是否在配置中 读取hero_create表 if _, ok := Csv.create_role[HeroId]; !ok { return global.CSVHEROIDEERROR } //创建player this.Init() //体力 int32_energy := int32(Csv.property[2056].Id_102) //英雄相关 hero := new(HeroStruct) hero_uid, err := hero.CreateHero(HeroId, this) if err == nil { this.Heros[hero_uid] = hero this.Heros[hero_uid].SetHeroPos(2, 1) //默认设置在第一个位置 } //将英雄添加到阵型中 this.StageFomation.OnFomation(1, hero_uid) //添加到1号位置 this.PlayerId = player_id this.ProfessionId = HeroId this.CreateTime = int32(time.Now().Unix()) this.LastTime = this.CreateTime this.Info.Level = 1 this.Info.Exp = 0 this.Info.Hp = int32(hero_uid) this.Info.Nick = nick this.Info.Gold = 0 this.Info.Vip = 0 this.Info.Energy = int32_energy this.Info.EnergyMax = this.Info.Energy this.Info.Diamond = 0 this.Info.Power = 0 this.Info.Signature = "" this.conn = conn //初始化副本关卡 this.Stage.Map_stage_pass[10101] = 1 //初始化挂机关卡 this.Guaji_Stage.Now_Guaji_id = 20101 this.Guaji_Stage.Guaji_Map_stage_pass[20101] = 0 //解锁未通关 this.Guaji_Stage.SetCurrentStage(this.Guaji_Stage.Now_Guaji_id) //初始化背包开启个数 this.Bag_Equip.OpenCount = int32(Csv.property[2018].Id_102) this.Bag_Equip.Max = int32(Csv.property[2019].Id_102) this.Bag_Equip.UseCount = 0 this.Bag_Prop.OpenCount = int32(Csv.property[2018].Id_102) this.Bag_Prop.Max = int32(Csv.property[2019].Id_102) this.Bag_Prop.UseCount = 0 //初始化任务系统 this.Task.CreateNewTask(1, 2001) //写内存数据库 this.Save() Log.Info("HeroId = %d int32_energy = %d this.Bag_Equip.OpenIndex = %d this.Bag_Equip.Max = %d this.Bag_Prop.OpenIndex=%d", HeroId, int32_energy, this.Bag_Equip.OpenCount, this.Bag_Equip.Max, this.Bag_Prop.OpenCount) return global.REGISTERROLESUCCESS }
func (this *Player) Save() error { this.Day = time.Now().Day() err := redis.Modify("role:"+strconv.Itoa(int(this.Info.ID)), this) return err }