Esempio n. 1
0
func (this *UserManager) LoadUser() error {
	proxy := sqlproxy.NewSqlProxy("root", "123456", "111.59.24.181", "3306", "game")
	err := proxy.Connect()
	if err != nil {
		return err
	}

	fieldNames := make([]string, 0, 16)
	fieldNames = append(fieldNames, "user_name")
	fieldNames = append(fieldNames, "password")
	fieldNames = append(fieldNames, "uuid")
	fieldNames = append(fieldNames, "mac_addr")
	fieldNames = append(fieldNames, "last_update_day")
	fieldNames = append(fieldNames, "gold_count")
	fieldNames = append(fieldNames, "diamond_count")

	fieldNames = append(fieldNames, "gold_rank")
	fieldNames = append(fieldNames, "gold_win_amount")
	fieldNames = append(fieldNames, "gold_lose_amount")
	fieldNames = append(fieldNames, "diamond_rank")
	fieldNames = append(fieldNames, "diamond_win_amount")
	fieldNames = append(fieldNames, "diamond_lose_amount")

	fieldNames = append(fieldNames, "diamond_available_buy_count")
	fieldNames = append(fieldNames, "gold_available_buy_count")

	queryCmd := &sqlproxy.QueryCmd{
		TableName:  "users",
		FieldNames: fieldNames[:],
	}

	dataMapList, err := proxy.LoadData(queryCmd)
	if err != nil {
		return err
	}

	var maxUuid uint64 = 0
	for _, dataMap := range dataMapList {
		newUser := new(User)

		newUser.UserName = dataMap["user_name"]
		newUser.PasswordSum = dataMap["password"]
		newUser.MacAddr = dataMap["mac_addr"]

		//last update time
		temp, err := strconv.ParseUint(dataMap["last_update_day"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.LastUpdateDay = uint(temp)

		//gold count
		temp, err = strconv.ParseUint(dataMap["gold_count"], 10, 8)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.GoldCount = uint8(temp)

		//diamond count
		temp, err = strconv.ParseUint(dataMap["diamond_count"], 10, 8)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.DiamondCount = uint8(temp)

		temp, err = strconv.ParseUint(dataMap["gold_rank"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.GoldRank = uint(temp)

		temp, err = strconv.ParseUint(dataMap["gold_win_amount"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.GoldWinAmount = uint(temp)

		temp, err = strconv.ParseUint(dataMap["gold_lose_amount"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.GoldLoseAmount = uint(temp)

		temp, err = strconv.ParseUint(dataMap["diamond_rank"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.DiamondRank = uint(temp)

		temp, err = strconv.ParseUint(dataMap["diamond_win_amount"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.DiamondWinAmount = uint(temp)

		temp, err = strconv.ParseUint(dataMap["diamond_lose_amount"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.DiamondLoseAmount = uint(temp)

		temp, err = strconv.ParseUint(dataMap["gold_available_buy_count"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.GoldAvailableBuyCount = uint(temp)

		temp, err = strconv.ParseUint(dataMap["diamond_available_buy_count"], 10, 32)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		newUser.DiamondAvailableBuyCount = uint(temp)

		//uuid
		uuid, err := strconv.ParseUint(dataMap["uuid"], 10, 64)
		if err != nil {
			this.userMap = make(map[string]*User)
			this.userUuidMap = make(map[uint64]*User)
			return err
		}

		if maxUuid < uuid {
			maxUuid = uuid
		}

		newUser.Uuid = uuid
		newUser.FixLevel = 0
		this.userMap[newUser.UserName] = newUser
		this.userUuidMap[uuid] = newUser
	}

	this.maxUserId = maxUuid
	this.sqlProxy = proxy
	return nil
}
Esempio n. 2
0
func (this *ResultManager) LoadData() error {
	proxy := sqlproxy.NewSqlProxy("root", "123456", "111.59.24.181", "3306", "game")
	err := proxy.Connect()
	if err != nil {
		return err
	}

	fieldNames := make([]string, 0, 16)
	fieldNames = append(fieldNames, "user_name")
	fieldNames = append(fieldNames, "enemy_name")
	fieldNames = append(fieldNames, "uuid")
	fieldNames = append(fieldNames, "enemy_uuid")
	fieldNames = append(fieldNames, "scores")
	fieldNames = append(fieldNames, "enemy_scores")
	fieldNames = append(fieldNames, "reward_type")
	fieldNames = append(fieldNames, "amount")
	fieldNames = append(fieldNames, "type")

	queryCmd := &sqlproxy.QueryCmd{
		TableName:  "result",
		FieldNames: fieldNames[:],
	}

	dataMapList, err := proxy.LoadData(queryCmd)
	if err != nil {
		return err
	}

	for _, dataMap := range dataMapList {
		result := &Result{
			UserName:  dataMap["user_name"],
			EnemyName: dataMap["enemy_name"],
		}

		var value int
		value, err = strconv.Atoi(dataMap["uuid"])
		if err != nil {
			return err
		}
		result.Uuid = uint64(value)

		value, err = strconv.Atoi(dataMap["enemy_uuid"])
		if err != nil {
			return err
		}
		result.EnemyUuid = uint64(value)

		value, err = strconv.Atoi(dataMap["scores"])
		if err != nil {
			return err
		}
		result.Scores = uint(value)

		value, err = strconv.Atoi(dataMap["enemy_scores"])
		if err != nil {
			return err
		}
		result.EnemyScores = uint(value)

		value, err = strconv.Atoi(dataMap["reward_type"])
		if err != nil {
			return err
		}
		result.RewardType = uint8(value)

		value, err = strconv.Atoi(dataMap["amount"])
		if err != nil {
			return err
		}
		result.Amount = uint(value)

		value, err = strconv.Atoi(dataMap["type"])
		if err != nil {
			return err
		}

		result.Type = uint(value)

		dataMap := this.dataMap
		list := dataMap[result.UserName]
		if list == nil {
			list = make([]*Result, 0, defaultResultSize)
		}

		dataMap[result.UserName] = append(list, result)
	}

	this.sqlProxy = proxy
	return nil
}
Esempio n. 3
0
func (this *RecordManager) LoadData() error {
	proxy := sqlproxy.NewSqlProxy("root", "123456", "111.59.24.181", "3306", "game")
	err := proxy.Connect()
	if err != nil {
		return err
	}

	config, err := configmanager.GetInstance().GetConfig("config/const.csv")
	if err != nil {
		return err
	}

	zoneConfig, err := configmanager.GetInstance().GetConfig("config/zone.csv")
	if err != nil {
		return err
	}

	if len(zoneConfig) == 0 {
		return errors.New("zone config data empty")
	}

	fieldNames := make([]string, 0, 16)
	fieldNames = append(fieldNames, "user_name")
	fieldNames = append(fieldNames, "role_id")
	fieldNames = append(fieldNames, "pet_id")
	fieldNames = append(fieldNames, "mount_id")
	fieldNames = append(fieldNames, "weapon_id")
	fieldNames = append(fieldNames, "equipment_id")
	fieldNames = append(fieldNames, "uuid")
	fieldNames = append(fieldNames, "scores")
	fieldNames = append(fieldNames, "records")
	fieldNames = append(fieldNames, "total_day")
	fieldNames = append(fieldNames, "type")

	queryCmd := &sqlproxy.QueryCmd{
		TableName:  "record",
		FieldNames: fieldNames[:],
	}

	dataMapList, err := proxy.LoadData(queryCmd)
	if err != nil {
		return err
	}

	for _, dataMap := range dataMapList {
		record := &Record{
			UserName: dataMap["user_name"],
			Records:  dataMap["records"],
		}

		var value int
		value, err = strconv.Atoi(dataMap["role_id"])
		if err != nil {
			return err
		}
		record.RoleId = uint(value)

		v, err := strconv.ParseInt(dataMap["total_day"], 10, 32)
		if err != nil {
			return err
		}
		record.TotalDay = v

		value, err = strconv.Atoi(dataMap["pet_id"])
		if err != nil {
			return err
		}
		record.PetId = uint(value)

		value, err = strconv.Atoi(dataMap["mount_id"])
		if err != nil {
			return err
		}
		record.MountId = uint(value)

		value, err = strconv.Atoi(dataMap["weapon_id"])
		if err != nil {
			return err
		}
		record.WeaponId = uint(value)

		value, err = strconv.Atoi(dataMap["equipment_id"])
		if err != nil {
			return err
		}
		record.EquipmentId = uint(value)

		value_new, err := strconv.ParseUint(dataMap["uuid"], 10, 64)
		if err != nil {
			return err
		}
		record.Uuid = value_new

		value_new, err = strconv.ParseUint(dataMap["type"], 10, 32)
		if err != nil {
			return err
		}
		record.Type = uint(value_new)

		value, err = strconv.Atoi(dataMap["scores"])
		if err != nil {
			return err
		}
		record.Scores = uint(value)

		zoneLen := config["ZoneRange"]["value"].Uint(1)
		zoneMax := uint(len(zoneConfig) - 1)
		i := record.Scores / zoneLen
		if i > zoneMax {
			i = zoneMax
		}
		key := strconv.FormatUint(uint64(i), 10)
		index := zoneConfig[key]["level"].Uint(0)

		var zoneRecords map[uint][]*Record
		var userRecords map[uint64][]*Record

		if record.Type == goldType {
			zoneRecords = this.zoneRecords
			userRecords = this.userRecords
		} else if record.Type == diamondType {
			zoneRecords = this.diamonZoneRecords
			userRecords = this.diamonUserRecords
		} else {
			continue
		}

		if zoneRecords[index] == nil {
			zoneRecords[index] = make([]*Record, 0, defaultZoneRecordSize)
		}

		zoneRecords[index] = append(zoneRecords[index], record)

		uuid := record.Uuid
		if userRecords[uuid] == nil {
			userRecords[uuid] = make([]*Record, 0, defaultUserRecordSize)
		}
		userRecords[uuid] = append(userRecords[uuid], record)
	}

	this.sqlProxy = proxy
	return nil
}