예제 #1
0
func (s *Server) LoadPlayerProfile(_playerId int64) (ret bool, p *Player) {
	p = nil
	ret = false

	var queryString string = fmt.Sprintf("SELECT idplayer, name FROM player WHERE idplayer=%d", _playerId)
	result, err := puh.DBQuerySelect(queryString)
	if err != nil {
		return
	}

	row := result.FetchMap()
	if row == nil {
		puh.DBFree()
		return
	}
	idPlayer := puh.DBGetInt(row["idplayer"])
	name := puh.DBGetString(row["name"])
	puh.DBFree()

	value, found := g_game.GetPlayerByName(name)
	if found {
		p = value
		ret = true
	} else {
		p = NewPlayer(name)
		p.dbid = idPlayer
		ret = p.LoadData()
	}

	return
}
예제 #2
0
func (p *Player) loadQuestsProgress() bool {
	var query string = "SELECT idplayer_quests, idquest, status, created, finished FROM player_quests WHERE idplayer=%d"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		dbid := puh.DBGetInt64(row[0])
		questid := puh.DBGetInt64(row[1])
		status := puh.DBGetInt(row[2])
		created := puh.DBGetInt64(row[3])  // Unix seconds
		finished := puh.DBGetInt64(row[4]) // Unix seconds

		if playerQuest := NewPlayerQuestExt(dbid, questid, status, created, finished); playerQuest != nil {
			playerQuest.IsNew = false
			p.Quests[questid] = playerQuest
		}
	}

	return true
}
예제 #3
0
func (p *Player) loadBackpack() bool {
	var query string = "SELECT idplayer_backpack, iditem, count, slot FROM player_backpack WHERE idplayer=%d"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()

	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		dbid := puh.DBGetInt64(row[0])
		itemId := puh.DBGetInt64(row[1])
		count := puh.DBGetInt(row[2])
		slot := puh.DBGetInt(row[3])

		item, _ := g_game.Items.GetItemByItemId(itemId)
		newItem := item.Clone()
		newItem.DbId = dbid
		newItem.SetCount(count)

		p.Backpack.AddItemObject(newItem, slot)
	}

	return true
}
예제 #4
0
func (p *Player) loadFriends() bool {
	var query string = "SELECT idplayer_friends, friend_name FROM player_friends WHERE idplayer=%d"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()

	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		dbid := puh.DBGetInt64(row[0])
		name := puh.DBGetString(row[1])

		_, online := g_game.GetPlayerByName(name)

		friend := &Friend{DbId: dbid,
			Name:   name,
			Online: online}
		p.Friends[name] = friend
	}

	return true
}
예제 #5
0
func (store *LocationStore) Load() error {
	var query string = "SELECT t.idlocation, t.name, t.idmusic, p.position FROM location t LEFT JOIN pokecenter p ON p.idpokecenter = t.idpokecenter"
	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return err
	}

	defer puh.DBFree()
	for {
		row := result.FetchMap()
		if row == nil {
			break
		}

		idlocation := puh.DBGetInt(row["idlocation"])
		name := puh.DBGetString(row["name"])
		music := puh.DBGetInt(row["idmusic"])
		pokecenter := puh.DBGetInt64(row["position"]) // Hash
		pcposition := pos.NewPositionFromHash(pokecenter)

		location := &Location{ID: idlocation,
			Name:       name,
			Music:      music,
			PokeCenter: pcposition}
		store.addLocation(location)
	}

	return nil
}
예제 #6
0
func (io *IOMapDB) LoadMap(_map *Map) error {
	// Spawn a row processor, in a different goroutine.
	go processRows(_map)

	// Fetch the rows:
	var query string = "SELECT t.`x`, t.`y`, t.`z`, t.`idlocation`, t.`movement`, t.`idteleport`," +
		" tl.`sprite`, tl.`layer`, tp.`x` AS `tp_x`, tp.`y` AS `tp_y`, tp.`z` AS `tp_z`" +
		" FROM tile `t`" +
		" INNER JOIN tile_layer `tl` ON tl.`idtile` = t.`idtile`" +
		" LEFT JOIN teleport `tp` ON tp.`idteleport` = t.`idteleport`"

	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return err
	}
	defer puh.DBFree()

	logger.Printf(" - Processing worldmap data from database")
	count := 0
	for {
		count++
		if count%1000 == 0 {
			fmt.Printf("Row %v\r", count)
		}
		row := result.FetchRow()
		if row == nil {
			break
		}
		// Send the row to the processor!
		rowChan <- row
	}
	rowChan <- nil

	return nil
}
예제 #7
0
func (n *NpcManager) Load() bool {
	// Fetch NPCs from database
	var query string = "SELECT idnpc, name, script_name, position FROM npc"
	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		npc := NewNpc()
		if npc.Load(row) {
			if len(npc.script_name) > 0 {
				// Assign script to npc if exists
				npcScript, found := n.npcLib.GetNpcScript(npc.script_name)
				if found {
					npcScript.SetScriptInterface(NewNpcScript(npc))
					npc.script = npcScript
				}
			}

			n.npcList[npc.dbid] = npc
			g_game.AddCreature(npc)
		}
	}

	n.StartAutoWalkNpc()

	return true
}
예제 #8
0
func (p *Player) loadPlayerInfo() bool {
	var query string = "SELECT p.idplayer, p.name, p.position, p.movement, p.idpokecenter, p.money, p.idlocation," +
		" g.group_idgroup, o.head, o.nek, o.upper, o.lower, o.feet FROM player `p`" +
		" INNER JOIN player_outfit `o` ON o.idplayer = p.idplayer" +
		" INNER JOIN player_group `g` ON g.player_idplayer = p.idplayer" +
		" WHERE p.idplayer=%d"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()
	row := result.FetchRow()
	if row == nil {
		logger.Printf("[Error] No player data for %s (DB ID: %d)\n", p.name, p.dbid)
		return false
	}

	p.dbid = puh.DBGetInt(row[0])
	p.name = puh.DBGetString(row[1])
	tile, ok := g_map.GetTile(puh.DBGetInt64(row[2]))
	if !ok {
		logger.Printf("[Warning] Could not load position info for player %s (%d)\n", p.name, p.dbid)
		//tile, _ = g_map.GetTileFrom(-510, -236, 0)
		tile, _ = g_map.GetTileFrom(38, 15, 1)
		if tile == nil {
			logger.Println("[Error] Could not load default position")
			return false
		}
	}
	p.Position = tile
	p.SetDirection(DIR_SOUTH)
	p.Movement = puh.DBGetInt(row[3])
	// TODO: p.LastPokeCenter = row[4].(int)
	p.Money = puh.DBGetInt(row[5])
	location, ok := g_game.Locations.GetLocation(puh.DBGetInt(row[6]))
	if !ok {
		logger.Printf("[Error] Could not load location info for player %s (%d)\n", p.name, p.dbid)
		return false
	}
	p.Location = location

	// Group/Right stuff : row[7].(int)

	p.SetOutfitKey(pul.OUTFIT_HEAD, puh.DBGetInt(row[8]))
	p.SetOutfitKey(pul.OUTFIT_NEK, puh.DBGetInt(row[9]))
	p.SetOutfitKey(pul.OUTFIT_UPPER, puh.DBGetInt(row[10]))
	p.SetOutfitKey(pul.OUTFIT_LOWER, puh.DBGetInt(row[11]))
	p.SetOutfitKey(pul.OUTFIT_FEET, puh.DBGetInt(row[12]))

	return true
}
예제 #9
0
func (p *Player) loadPokemon() bool {
	var query string = "SELECT idpokemon, nickname, bound, experience, iv_hp, iv_attack, iv_attack_spec, iv_defence, iv_defence_spec," +
		" iv_speed, happiness, gender, in_party, party_slot, idplayer_pokemon, shiny, idability, damaged_hp FROM player_pokemon WHERE idplayer='%d' AND in_party=1"
	result, err := puh.DBQuerySelect(fmt.Sprintf(query, p.dbid))
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		pokemon := pkmn.NewPlayerPokemon(p.dbid)
		pokemon.IdDb = puh.DBGetInt(row[14])
		pokemonId := puh.DBGetInt(row[0])
		pokemon.Base = pkmn.GetInstance().GetPokemon(pokemonId)
		pokemon.Nickname = puh.DBGetString(row[1])
		pokemon.IsBound = puh.DBGetInt(row[2])
		pokemon.Experience = float64(puh.DBGetUint64(row[3]))
		pokemon.Stats[pkmn.POKESTAT_HP] = puh.DBGetInt(row[4])             // HP
		pokemon.Stats[pkmn.POKESTAT_ATTACK] = puh.DBGetInt(row[5])         // Attack
		pokemon.Stats[pkmn.POKESTAT_DEFENSE] = puh.DBGetInt(row[7])        // Defence
		pokemon.Stats[pkmn.POKESTAT_SPECIALATTACK] = puh.DBGetInt(row[6])  // Spec Attack
		pokemon.Stats[pkmn.POKESTAT_SPECIALDEFENCE] = puh.DBGetInt(row[8]) // Spec Defence
		pokemon.Stats[pkmn.POKESTAT_SPEED] = puh.DBGetInt(row[9])          // Speed
		pokemon.Happiness = puh.DBGetInt(row[10])
		pokemon.Gender = puh.DBGetInt(row[11])
		pokemon.InParty = puh.DBGetInt(row[12])
		pokemon.Slot = puh.DBGetInt(row[13])
		pokemon.IsShiny = puh.DBGetInt(row[15])
		abilityId := puh.DBGetInt(row[16])
		pokemon.DamagedHp = puh.DBGetInt(row[17])

		pokemon.Ability = pkmn.GetInstance().GetAbilityById(abilityId)
		if pokemon.Ability == nil {
			logger.Printf("[Warning] Pokemon (%d) has an invalid abilityId (%d)\n", pokemon.IdDb, abilityId)
			pokemon.Ability = pkmn.GetInstance().GetAbilityById(96)
		}

		// Add to party if needed
		if pokemon.InParty == 1 {
			p.PokemonParty.AddSlot(pokemon, pokemon.Slot)
		}
	}

	return true
}
예제 #10
0
func (p *Player) AddFriend(_name string) {
	// Cannot add self
	if _name == p.GetName() {
		return
	}

	if f, found := p.GetFriend(_name); found {
		if f.IsRemoved {
			// Friend already exists, but is flagged for removal
			_, online := g_game.GetPlayerByName(_name)
			p.UpdateFriend(_name, online)
		}
	} else {
		isOnline := false

		// Check if player is online
		_, found := g_game.GetPlayerByName(_name)
		if found {
			isOnline = true
		} else {
			// Check if player exists in database
			query := fmt.Sprintf("SELECT idplayer FROM player WHERE name='%s'", _name)
			result, err := puh.DBQuerySelect(query)
			if err == nil {
				defer puh.DBFree()
				found = (result.RowCount() > 0)
			} else {
				found = false
			}
		}

		if found {
			friend := &Friend{DbId: 0,
				Name:      _name,
				Online:    isOnline,
				IsRemoved: false}

			p.Friends[_name] = friend

			p.sendFriendUpdate(_name, isOnline)
		} else {
			p.sendCancelMessage(RET_PLAYERNOTFOUND)
		}
	}
}
예제 #11
0
func (s *QuestStore) Load() bool {
	result, err := puh.DBQuerySelect("SELECT idquests, name, description FROM quests")
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		quest := &Quest{Dbid: puh.DBGetInt64(row[0]),
			Name:        puh.DBGetString(row[1]),
			Description: puh.DBGetString(row[2])}
		s.AddQuest(quest)
	}

	return true
}
예제 #12
0
func (s *ItemStore) Load() bool {
	var query string = "SELECT id, identifier, category_id, cost, fling_power, fling_effect_id FROM items"
	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return false
	}

	defer puh.DBFree()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		itemId := puh.DBGetInt64(row[0])
		identifier := puh.DBGetString(row[1])
		category := puh.DBGetInt(row[2])
		cost := puh.DBGetInt(row[3])
		flingPower := puh.DBGetInt(row[4])
		flingEffectId := puh.DBGetInt(row[5])

		item := &Item{Id: itemId,
			Identifier:    identifier,
			CategoryId:    category,
			Cost:          cost,
			FlingPower:    flingPower,
			FlingEffectId: flingEffectId,
			MaxStack:      0,
			CanBeSold:     true,
			CanBeTraded:   true}

		// Add item to store
		s.Items[itemId] = item
	}

	return true
}
예제 #13
0
func (io *IOMapDB2) loadMapList(_map *Map) error {
	var query string = "SELECT idmap, name FROM map"

	result, err := puh.DBQuerySelect(query)
	if err != nil {
		return err
	}
	defer puh.DBFree()

	logger.Printf(" - Processing map list")
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}

		idmap := puh.DBGetInt(row[0])
		name := puh.DBGetString(row[1])

		_map.AddMap(idmap, name)
	}

	return nil
}
예제 #14
0
func (s *Server) CheckAccountInfo(_username string, _password string) (bool, int64) {
	_username = puh.Escape(_username)
	_password = puh.Escape(_password)

	var queryString string = "SELECT idplayer, password, password_salt FROM player WHERE name='" + _username + "'"
	result, err := puh.DBQuerySelect(queryString)
	if err != nil {
		return false, 0
	}

	row := result.FetchMap()
	defer puh.DBFree()
	if row == nil {
		return false, 0
	}

	idplayer := puh.DBGetInt64(row["idplayer"])
	password := puh.DBGetString(row["password"])
	salt := puh.DBGetString(row["password_salt"])
	_password = _password + salt

	passCheck := s.PasswordTest(_password, password)
	return passCheck, idplayer
}