示例#1
0
void IPFilterFrame::slotCheckBoxClick() {
    bool b = checkBox_ENABLE->isChecked();

    pushButton_EXPORT->setEnabled(b);
    pushButton_IMPORT->setEnabled(b);
    treeView_RULES->setEnabled(b);
    groupBox_DIRECTION->setEnabled(b);
    lineEdit_RULE->setEnabled(b);
    pushButton_ADD->setEnabled(b);
    pushButton_DOWN->setEnabled(b);
    pushButton_UP->setEnabled(b);

    if (b) {
        if (!IPFilter::getInstance()){
            IPFilter::newInstance();

            IPFilter::getInstance()->loadList();
        }

        loadItems();

        connect(IPFilter::getInstance(), SIGNAL(ruleAdded(QString,eDIRECTION)), this, SLOT(slotRuleAdded(QString,eDIRECTION)));

    } else {
        if (IPFilter::getInstance()) {
            IPFilter::getInstance()->saveList();

            IPFilter::deleteInstance();

            model->clearModel();
        }
    }

    WBSET(WB_IPFILTER_ENABLED, b);
}
示例#2
0
Allocations::Allocations(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Allocations)
{
    ui->setupUi(this);
    ui->dateEdit->setDateTime(QDateTime::currentDateTime());

    setEditMode(false);
    setAllocationId(0);
    setItemId(0);

    ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);

    items_model = 0;
    locations_model = 0;
    operators_model = 0;
    logger = 0;

    loadItems();
    loadLocations();
    loadOperators();

    ui->to_operator_comboBox->completer()->setCompletionMode(QCompleter::PopupCompletion);
    ui->to_location_comboBox->completer()->setCompletionMode(QCompleter::PopupCompletion);

    connect(ui->filter_lineEdit, SIGNAL(textChanged(QString)), this, SLOT(setItemsFilter(QString)));
}
示例#3
0
void HiRes5Engine::initGameState() {
	_state.vars.resize(40);

	insertDisk(2);

	StreamPtr stream(_disk->createReadStream(0x5, 0x1, 0x00, 3));
	loadItems(*stream);

	// A combined total of 1213 rooms
	static const byte rooms[kRegions] = {
		6, 16, 24, 57, 40, 30, 76, 40,
		54, 38, 44, 21, 26, 42, 49, 32,
		59, 69, 1, 1, 1, 1, 1, 18,
		25, 13, 28, 28, 11, 23, 9, 31,
		6, 29, 29, 34, 9, 10, 95, 86,
		1
	};

	initRegions(rooms, kRegions);

	loadRegion(1);
	_state.room = 5;

	_doAnimation  = false;
}
示例#4
0
void Globals::init ()
{	
  try
  {
	YAML::Node config(YAML::LoadFile("assets/config.yml"));
	config = config["game"];

	sf::Vector2u window_size(config["graphic"]["window"]["size"][0].as<unsigned>(),
		config["graphic"]["window"]["size"][1].as<unsigned>());

	window.reset(new sf::RenderWindow(sf::VideoMode(window_size.x, window_size.y), "Vegetable Crush Saga", sf::Style::Default & ~sf::Style::Resize));
	window->setFramerateLimit(60);

	YAML::Node paths(config["system"]["paths"]);
	loadTextures(config["graphic"]["textures"], paths["texture_pack"].as<std::string>());
	loadFonts(config["graphic"]["fonts"], paths["font_pack"].as<std::string>());

	YAML::Node items(config["gameplay"]["items"]);
	loadItems(items);
  }
  catch (YAML::ParserException e)
  {
	std::cerr << "Le fichier de config n'est pas aux normes !" << std::endl;
	std::cerr << e.what() << std::endl;
	exit(EXIT_FAILURE);
  }
}
示例#5
0
文件: itemsync.cpp 项目: hluk/CopyQ
ItemSaverPtr ItemSyncLoader::loadItems(const QString &tabName, QAbstractItemModel *model, QIODevice *file, int maxItems)
{
    QVariantMap config;
    if ( !readConfig(file, &config) )
        return nullptr;

    const QStringList files = config.value(tabConfigSavedFiles).toStringList();
    return loadItems(tabName, model, files, maxItems);
}
示例#6
0
void Initialize(Neighborhoods &nb, KdTreeBB &kdtree)
{
	//Create KDTree
  int size;
  KdTreeBB::Item* items;
  loadItems("converted_shapefile/bbox.csv", items, size);
  kdtree.createKdTree(items, size);

	nb.loadFromFile("converted_shapefile/point.txt");
}
示例#7
0
void HiRes4Engine_Atari::initGameState() {
	_state.vars.resize(IDI_HR4_NUM_VARS);

	StreamPtr stream(createReadStream(_boot, 0x03, 0x1, 0x0e, 9));
	loadRooms(*stream, IDI_HR4_NUM_ROOMS);

	stream.reset(createReadStream(_boot, 0x02, 0xc, 0x00, 12));
	loadItems(*stream);

	// FIXME
	_display->moveCursorTo(Common::Point(0, 23));
}
void KonqCombo::init( KCompletion *completion )
{
    setCompletionObject( completion, false ); //KonqMainWindow handles signals
    setAutoDeleteCompletionObject( false );
    setCompletionMode( completion->completionMode() );

    // We use Ctrl+T for new tab, so we need something else for substring completion
    // TODO: how to make that shortcut configurable? If we add a KAction we need to
    // call the KLineEdit code, which we can't do. Well, we could send a keyevent...
    setKeyBinding(KCompletionBase::SubstringCompletion, KShortcut(Qt::Key_F7));

    loadItems();
}
示例#9
0
void IPFilterFrame::slotImport() {
    if (!IPFilter::getInstance() || !model)
        return;

    QString fname = QFileDialog::getOpenFileName(this, tr("Import list"), QDir::homePath());

    if (fname != ""){
        fname = QDir::toNativeSeparators(fname);

        model->clearModel();

        IPFilter::getInstance()->importFrom(fname);

        loadItems();
    }
}
示例#10
0
int levelSwitch(int id)
{
    fprintf(stderr, "Loading level %d:\n", id);

    /* Checking for new id isn`t null */
    if(!id)
    {
        fprintf(stderr, "%s: attempted to load 0th level.\n", __FUNCTION__);
        return 1;
    }

    /* Makin` sure that input ID`s not equal to current ID */
    if(id == currentLevel.id)
    {
        fprintf(stderr, "%s: attempted to load the same level\n", __FUNCTION__);
        return 1;
    }

    /* Cleanup first */
    levelReset();

    currentLevel.id = id;

    /* Let`s load config files first */
    if(loadConf(id) | loadItems(id) | loadTraps(id))
    {
        fprintf(stderr, "%s: failed to load level's configuration file(s).\n"
                        "Please make sure that all fields in the files are correct and there are no side entries.\n",
                        __FUNCTION__);
        return 1;
    }

    if(loadBitmaps(id) | loadCollision(id))
    {
        fprintf(stderr, "%s: some critical level's bitmaps has failed to load.\n", __FUNCTION__);
        return 1;
    }

    fprintf(stderr, " > Resetting objects\n");
    playerReset();
    bossReset();

    fprintf(stderr, "Done.\n");
    return 0;
}
示例#11
0
LogListModel::LogListModel(const QSqlDatabase& db, QObject *parent)
    : QAbstractListModel(parent)
    , _serviceHandler(new ServiceHandler)
{
    _db = db;

    QHash<int, QByteArray> roles;
    roles[WorkoutLogListIdRole] = "logid";
    roles[WorkoutLogListNameRole] = "logname";
    roles[WorkoutLogListDateRole] = "logdate";
    roles[WorkoutLogListDescriptionRole] = "logdesc";
    roles[WorkoutLogListHandlestampRole] = "loghandlestamp";
    setRoleNames(roles);

    loadItems();

    connect(_serviceHandler, SIGNAL(putListItemsRequestFineshed(int)), this, SLOT(listBackedUp(int)));
    connect(_serviceHandler, SIGNAL(handlerError(int)), this, SLOT(listBackupError(int)));
}
示例#12
0
文件: reader.c 项目: knusbaum/Wily
int
setWinList(rdWin *w, char **items)
{
	assert(w);
	assert(items);

	if (w->wintype != rdList) {
		DPRINT("setWinList() called for non-list window");
		return 1;
	}
	freeItems(w);
	if (w->bodylen) {
		if (rpc_delete(wilyq, w->id, 0, w->bodylen)) {
			DPRINT("Could not delete list body");
			return 1;
		}
		w->bodylen = 0;
	}
	return loadItems(w, items);
}
示例#13
0
bool Ingridients::loadData(QString& fileName) {
    QFile loadFile(fileName);

    PRINT_DEBUG("Loading new ingridients");

    if ( !loadFile.open(QIODevice::ReadOnly) ) {
        PRINT_WARN("Couldn't open save file.");

        return false;
    }

    QByteArray saveData = loadFile.readAll();

    QJsonDocument loadDoc((!fileName.right(5).compare(".json")) ?
                           QJsonDocument::fromJson(saveData) :
                           QJsonDocument::fromBinaryData(saveData));

    loadDish(loadDoc.object()["dishList"].toArray());
    loadFood(loadDoc.object()["foodList"].toArray());
    loadItems(loadDoc.object()["itemList"].toArray());

    return true;
}
示例#14
0
MenuColumn::MenuColumn( QWidget* parent,
                        const QString& name,
                        const QColor& bg,
                        const QColor& hl )
    : QFrame( parent, name ? name : "GenericMenuColumn" ), m_name( name )
{
    setFrameStyle( QFrame::Plain | QFrame::MenuBarPanel );
    m_mainLay = new QVBoxLayout( this );
    m_compLay = new QVBoxLayout();
    m_mainLay->addLayout( m_compLay );

    if( !m_name.isNull() )
        loadItems();

    // override color
    if( bg.isValid() )
        setBackgroundColor( bg );
    if( hl.isValid() )
        setHighlightColor( hl );


    setPaletteBackgroundColor( backgroundColor() );
}
bool IOMapSerialize::loadMapRelational(Map* map)
{
	Database* db = Database::getInstance();
	DBQuery query; //lock mutex!

	House* house = NULL;
	for(HouseMap::iterator it = Houses::getInstance()->getHouseBegin(); it != Houses::getInstance()->getHouseEnd(); ++it)
	{
		if(!(house = it->second))
			continue;

		query.str("");
		query << "SELECT * FROM `tiles` WHERE `house_id` = " << house->getId() <<
			" AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
		if(DBResult* result = db->storeQuery(query.str()))
		{
			do
			{
				query.str("");
				query << "SELECT * FROM `tile_items` WHERE `tile_id` = " << result->getDataInt("id") << " AND `world_id` = "
					<< g_config.getNumber(ConfigManager::WORLD_ID) << " ORDER BY `sid` DESC";
				if(DBResult* itemsResult = db->storeQuery(query.str()))
				{
					if(house->hasPendingTransfer())
					{
						if(Player* player = g_game.getPlayerByGuidEx(house->getOwner()))
						{
							loadItems(itemsResult, player->getInbox(), true);
							if(player->isVirtual())
							{
								IOLoginData::getInstance()->savePlayer(player);
								delete player;
							}
						}
					}
					else
					{
						Position pos(result->getDataInt("x"), result->getDataInt("y"), result->getDataInt("z"));
						if(Tile* tile = map->getTile(pos))
							loadItems(itemsResult, tile, false);
						else
							std::clog << "[Error - IOMapSerialize::loadMapRelational] Unserialization"
								<< " of invalid tile at position "<< pos << std::endl;
					}

					itemsResult->free();
				}
			}
			while(result->next());
			result->free();
		}
		else //backward compatibility
		{
			for(HouseTileList::iterator it = house->getHouseTileBegin(); it != house->getHouseTileEnd(); ++it)
			{
				query.str("");
				query << "SELECT `id` FROM `tiles` WHERE `x` = " << (*it)->getPosition().x << " AND `y` = "
					<< (*it)->getPosition().y << " AND `z` = " << (*it)->getPosition().z << " AND `world_id` = "
					<< g_config.getNumber(ConfigManager::WORLD_ID) << " LIMIT 1";
				if(DBResult* result = db->storeQuery(query.str()))
				{
					query.str("");
					query << "SELECT * FROM `tile_items` WHERE `tile_id` = " << result->getDataInt("id") << " AND `world_id` = "
						<< g_config.getNumber(ConfigManager::WORLD_ID) << " ORDER BY `sid` DESC";
					if(DBResult* itemsResult = db->storeQuery(query.str()))
					{
						if(house->hasPendingTransfer())
						{
							if(Player* player = g_game.getPlayerByGuidEx(house->getOwner()))
							{
								loadItems(itemsResult, player->getInbox(), true);
								if(player->isVirtual())
								{
									IOLoginData::getInstance()->savePlayer(player);
									delete player;
								}
							}
						}
						else
							loadItems(itemsResult, (*it), false);

						itemsResult->free();
					}

					result->free();
				}
			}
		}
	}

	return true;
}
示例#16
0
CSItemsList::CSItemsList(char *protoName)
{
	m_list = new List< StatusItem >(compareItems);
	loadItems(protoName);
}
bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
{
	if (!result) {
		return false;
	}

	Database* db = Database::getInstance();

	uint32_t accno = result->getDataInt("account_id");
	Account acc = loadAccount(accno);

	player->setGUID(result->getDataInt("id"));
	player->name = result->getDataString("name");
	player->accountNumber = accno;

	player->accountType = acc.accountType;

	if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) {
		player->premiumDays = std::numeric_limits<uint16_t>::max();
	} else {
		player->premiumDays = acc.premiumDays;
	}

	Group* group = g_game.getGroup(result->getDataInt("group_id"));
	if (!group) {
		std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Group ID " << result->getDataInt("group_id") << " which doesn't exist." << std::endl;
		return false;
	}
	player->setGroup(group);

	player->bankBalance = result->getNumber<uint64_t>("balance");

	player->setSex(static_cast<PlayerSex_t>(result->getDataInt("sex")));
	player->level = std::max<uint32_t>(1, result->getDataInt("level"));

	uint64_t experience = result->getNumber<uint64_t>("experience");

	uint64_t currExpCount = Player::getExpForLevel(player->level);
	uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
	if (experience < currExpCount || experience > nextExpCount) {
		experience = currExpCount;
	}

	player->experience = experience;

	if (currExpCount < nextExpCount) {
		player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
	} else {
		player->levelPercent = 0;
	}

	player->soul = result->getDataInt("soul");
	player->capacity = result->getDataInt("cap") * 100;
	player->blessings = result->getDataInt("blessings");

	unsigned long conditionsSize;
	const char* conditions = result->getDataStream("conditions", conditionsSize);
	PropStream propStream;
	propStream.init(conditions, conditionsSize);

	Condition* condition = Condition::createCondition(propStream);
	while (condition) {
		if (condition->unserialize(propStream)) {
			player->storedConditionList.push_front(condition);
		} else {
			delete condition;
		}
		condition = Condition::createCondition(propStream);
	}

	if (!player->setVocation(result->getDataInt("vocation"))) {
		std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Vocation ID " << result->getDataInt("vocation") << " which doesn't exist." << std::endl;
		return false;
	}

	player->mana = result->getDataInt("mana");
	player->manaMax = result->getDataInt("manamax");
	player->magLevel = result->getDataInt("maglevel");

	uint64_t nextManaCount = player->vocation->getReqMana(player->magLevel + 1);
	uint64_t manaSpent = result->getNumber<uint64_t>("manaspent");
	if (manaSpent > nextManaCount) {
		manaSpent = 0;
	}

	player->manaSpent = manaSpent;
	player->magLevelPercent = Player::getPercentLevel(player->manaSpent, nextManaCount);

	player->health = result->getDataInt("health");
	player->healthMax = result->getDataInt("healthmax");

	player->defaultOutfit.lookType = result->getDataInt("looktype");
	player->defaultOutfit.lookHead = result->getDataInt("lookhead");
	player->defaultOutfit.lookBody = result->getDataInt("lookbody");
	player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
	player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
	player->defaultOutfit.lookAddons = result->getDataInt("lookaddons");
	player->currentOutfit = player->defaultOutfit;

	if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
		const int32_t skullSeconds = result->getDataInt("skulltime") - time(nullptr);
		if (skullSeconds > 0) {
			//ensure that we round up the number of ticks
			player->skullTicks = (skullSeconds + 2) * 1000;
			int32_t skull = result->getDataInt("skull");

			if (skull == SKULL_RED) {
				player->skull = SKULL_RED;
			} else if (skull == SKULL_BLACK) {
				player->skull = SKULL_BLACK;
			}
		}
	}

	player->loginPosition.x = result->getDataInt("posx");
	player->loginPosition.y = result->getDataInt("posy");
	player->loginPosition.z = result->getDataInt("posz");

	player->lastLoginSaved = result->getNumber<uint64_t>("lastlogin");
	player->lastLogout = result->getNumber<uint64_t>("lastlogout");

	player->offlineTrainingTime = result->getDataInt("offlinetraining_time") * 1000;
	player->offlineTrainingSkill = result->getDataInt("offlinetraining_skill");

	Town* town = Towns::getInstance().getTown(result->getDataInt("town_id"));
	if (!town) {
		std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Town ID " << result->getDataInt("town_id") << " which doesn't exist." << std::endl;
		return false;
	}

	player->town = town;

	const Position& loginPos = player->loginPosition;
	if (loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0) {
		player->loginPosition = player->getTemplePosition();
	}

	player->staminaMinutes = result->getDataInt("stamina");

	static const std::string skillNames[] = {"skill_fist", "skill_club", "skill_sword", "skill_axe", "skill_dist", "skill_shielding", "skill_fishing"};
	static const std::string skillNameTries[] = {"skill_fist_tries", "skill_club_tries", "skill_sword_tries", "skill_axe_tries", "skill_dist_tries", "skill_shielding_tries", "skill_fishing_tries"};
	static const size_t size = sizeof(skillNames) / sizeof(std::string);
	for (uint8_t i = 0; i < size; ++i) {
		uint16_t skillLevel = result->getNumber<uint16_t>(skillNames[i]);
		uint64_t skillTries = result->getNumber<uint64_t>(skillNameTries[i]);
		uint64_t nextSkillTries = player->vocation->getReqSkillTries(i, skillLevel + 1);
		if (skillTries > nextSkillTries) {
			skillTries = 0;
		}

		player->skills[i].level = skillLevel;
		player->skills[i].tries = skillTries;
		player->skills[i].percent = Player::getPercentLevel(skillTries, nextSkillTries);
	}

	std::ostringstream query;
	query << "SELECT `guild_id`, `rank_id`, `nick` FROM `guild_membership` WHERE `player_id` = " << player->getGUID();
	if ((result = db->storeQuery(query.str()))) {
		uint32_t guildId = result->getDataInt("guild_id");
		uint32_t playerRankId = result->getDataInt("rank_id");
		player->guildNick = result->getDataString("nick");

		Guild* guild = g_game.getGuild(guildId);
		if (!guild) {
			query.str("");
			query << "SELECT `name` FROM `guilds` WHERE `id` = " << guildId;
			if ((result = db->storeQuery(query.str()))) {
				guild = new Guild(guildId, result->getDataString("name"));
				g_game.addGuild(guild);

				query.str("");
				query << "SELECT `id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " LIMIT 3";

				if ((result = db->storeQuery(query.str()))) {
					do {
						guild->addRank(result->getDataInt("id"), result->getDataString("name"), result->getDataInt("level"));
					} while (result->next());
				}
			}
		}

		if (guild) {
			player->guild = guild;
			GuildRank* rank = guild->getRankById(playerRankId);
			if (rank) {
				player->guildLevel = rank->level;
			} else {
				player->guildLevel = 1;
			}

			IOGuild::getWarList(guildId, player->guildWarList);

			query.str("");
			query << "SELECT COUNT(*) AS `members` FROM `guild_membership` WHERE `guild_id` = " << guildId;
			if ((result = db->storeQuery(query.str()))) {
				guild->setMemberCount(result->getDataInt("members"));
			}
		}
	}

	query.str("");
	query << "SELECT `player_id`, `name` FROM `player_spells` WHERE `player_id` = " << player->getGUID();
	if ((result = db->storeQuery(query.str()))) {
		do {
			player->learnedInstantSpellList.emplace_front(result->getDataString("name"));
		} while (result->next());
	}

	//load inventory items
	ItemMap itemMap;

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if ((result = db->storeQuery(query.str()))) {
		loadItems(itemMap, result);

		for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) {
			const std::pair<Item*, int32_t>& pair = it->second;
			Item* item = pair.first;
			int32_t pid = pair.second;
			if (pid >= 1 && pid <= 10) {
				player->__internalAddThing(pid, item);
			} else {
				ItemMap::const_iterator it2 = itemMap.find(pid);
				if (it2 == itemMap.end()) {
					continue;
				}

				Container* container = it2->second.first->getContainer();
				if (container) {
					container->__internalAddThing(item);
				}
			}
		}
	}

	//load depot items
	itemMap.clear();

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if ((result = db->storeQuery(query.str()))) {
		loadItems(itemMap, result);

		for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) {
			const std::pair<Item*, int32_t>& pair = it->second;
			Item* item = pair.first;

			int32_t pid = pair.second;
			if (pid >= 0 && pid < 100) {
				if (pid == 98) {
					DepotChest* depotChest = player->getPokeStorage(pid, true);
					if (depotChest) {
						depotChest->__internalAddThing(item);
					}
				} else {
					DepotChest* depotChest = player->getDepotChest(pid, true);
					if (depotChest) {
						depotChest->__internalAddThing(item);
					}
				}
			} else {
				ItemMap::const_iterator it2 = itemMap.find(pid);
				if (it2 == itemMap.end()) {
					continue;
				}

				Container* container = it2->second.first->getContainer();
				if (container) {
					container->__internalAddThing(item);
				}
			}
		}
	}

	//load inbox items
	itemMap.clear();

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if ((result = db->storeQuery(query.str()))) {
		loadItems(itemMap, result);

		for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) {
			const std::pair<Item*, int32_t>& pair = it->second;
			Item* item = pair.first;
			int32_t pid = pair.second;

			if (pid >= 0 && pid < 100) {
				player->getInbox()->__internalAddThing(item);
			} else {
				ItemMap::const_iterator it2 = itemMap.find(pid);

				if (it2 == itemMap.end()) {
					continue;
				}

				Container* container = it2->second.first->getContainer();
				if (container) {
					container->__internalAddThing(item);
				}
			}
		}
	}

	//load storage map
	query.str("");
	query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();
	if ((result = db->storeQuery(query.str()))) {
		do {
			player->addStorageValue(result->getDataInt("key"), result->getDataInt("value"), true);
		} while (result->next());
	}

	//load vip
	query.str("");
	query << "SELECT `player_id` FROM `account_viplist` WHERE `account_id` = " << player->getAccount();
	if ((result = db->storeQuery(query.str()))) {
		do {
			player->addVIPInternal(result->getDataInt("player_id"));
		} while (result->next());
	}

	player->updateBaseSpeed();
	player->updateInventoryWeight();
	player->updateItemsLight(true);
	return true;
}
示例#18
0
int main(int argc, char** argv)
{
	if (argc < 2)
		return usage(argc, argv);

	parent = pthread_self();
	sigset_t original, masking;
	sigemptyset(&original);
	sigemptyset(&masking);
	sigaddset(&masking, SIGUSR1);
	pthread_sigmask(SIG_SETMASK, &masking, &original);

	int wakeupThreads = 0;
	try
	{
		wakeupThreads = lexicalCast<int>(argv[argc-1]);
		if (wakeupThreads < 1)
			return usage(argc, argv);

		std::cout << "wakeup threads of " << wakeupThreads << std::endl;
	}
	catch (std::exception& e)
	{
		std::cerr << e.what() << std::endl;
		return usage(argc, argv);
	}

	void* handle = WWWInit();
	std::vector<Item> items = loadItems();
	resetItems(items);
	void* filterManagerContext = FilterManagerCreate(NULL);

	std::map<void*, void*> contextMap;
	

	// create threads.
	for (int count = 0; count != wakeupThreads; ++count)
	{
		std::vector<Item>::iterator itor = find_uncheck_item(items);
		if (itor == items.end())
			break;

		itor->check_flg = true;
		void* thread = ThreadCreate();
		void* httpContext = HTTPCreateContext(itor->url_check.c_str(),
											  NULL, NULL, 20);
		contextMap[thread] = httpContext;
		std::cout << "thread: " << thread <<
			"   context: " << httpContext << std::endl;
		ThreadStart(thread, httpContext, handler);
	}

	try
	{
		std::vector<Item>::iterator itor;
		while ((itor = find_uncheck_item(items)) != items.end())
		{
			itor->check_flg = true;
			
			int signalNum = 0;
			sigwait(&masking, &signalNum);
			if (signalNum == SIGUSR1)
			{
				// signal一回で複数の待ちハンドラを処理した方が良さそう
				ScopedLock<Mutex> lock(syncObject);
				assert (idleThreads.size() > 0);
				void* thread = idleThreads.back();
				idleThreads.pop_back();
				ThreadJoin(thread);

				void* httpContext = contextMap[thread];
				assert(httpContext != NULL);
				contextMap[thread] = NULL;

				{
					char url[2048];
					url[HTTPGetURL(httpContext, url, sizeof(url))] = 0;
					std::vector<Item>::iterator item_itor =
						find_item_from_url(items, url);

					if (item_itor == items.end())
						throw std::runtime_error((std::string("unfind URL: ") +
												  url).c_str());

					char date[256];
					date[HTTPGetLastModified(httpContext,
											 date, sizeof(date))] = 0;
					item_itor->last_updated = date;

					item_itor->crc32 = HTTPGetFilteredCRC32(httpContext,
													   filterManagerContext);
				
					item_itor->content_length =
						HTTPGetContentsLength(httpContext);

					HTTPClose(httpContext);
				}
				HTTPCreateContext(itor->url_check.c_str(),
								  NULL, NULL, 20);
				contextMap[thread] = httpContext;
				std::cout << "thread: " << thread <<
					"   context: " << httpContext << std::endl;
				ThreadStart(thread, httpContext, handler);
			}
		}

		// 稼働中のスレッドがwakeupThreads個存在する
		for (int count = 0; count != wakeupThreads; ++count)
		{
			int signalNum = 0;
			// signal一回で複数の待ちハンドラを処理した方が良さそう
			sigwait(&masking, &signalNum);
			ScopedLock<Mutex> lock(syncObject);
			ThreadClose(idleThreads.back());
			idleThreads.pop_back();
		}
	}
	catch (std::exception& e)
	{
		std::cerr << "raise exception: " << e.what() << std::endl;
	}
	catch (...)
	{
		std::cerr << "unknown exception raised." << std::endl;
	}

	saveItems(items);
	FilterManagerTerminate(filterManagerContext);
	WWWTerminate(handle);
	pthread_sigmask(SIG_SETMASK, &original, NULL);

	return 0;
}
示例#19
0
void KyraEngine_LoK::startup() {
	static const uint8 colorMap[] = { 0, 0, 0, 0, 12, 12, 12, 0, 0, 0, 0, 0 };
	_screen->setTextColorMap(colorMap);

	_sound->selectAudioResourceSet(kMusicIngame);
	if (_flags.platform == Common::kPlatformPC98)
		_sound->loadSoundFile("SE.DAT");
	else
		_sound->loadSoundFile(0);

//	_screen->setFont(Screen::FID_6_FNT);
	_screen->setAnimBlockPtr(3750);
	memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable));
	loadMouseShapes();
	_currentCharacter = &_characterList[0];
	for (int i = 1; i < 5; ++i)
		_animator->setCharacterDefaultFrame(i);
	for (int i = 5; i <= 10; ++i)
		setCharactersPositions(i);
	_animator->setCharactersHeight();
	resetBrandonPoisonFlags();
	_screen->_curPage = 0;
	// XXX
	for (int i = 0; i < 12; ++i) {
		int size = _screen->getRectSize(3, 24);
		_shapes[361 + i] = new byte[size];
	}

	_itemBkgBackUp[0] = new uint8[_screen->getRectSize(3, 24)];
	memset(_itemBkgBackUp[0], 0, _screen->getRectSize(3, 24));
	_itemBkgBackUp[1] = new uint8[_screen->getRectSize(4, 32)];
	memset(_itemBkgBackUp[1], 0, _screen->getRectSize(4, 32));

	for (int i = 0; i < _roomTableSize; ++i) {
		for (int item = 0; item < 12; ++item) {
			_roomTable[i].itemsTable[item] = kItemNone;
			_roomTable[i].itemsXPos[item] = 0xFFFF;
			_roomTable[i].itemsYPos[item] = 0xFF;
			_roomTable[i].needInit[item] = 0;
		}
	}

	loadCharacterShapes();
	loadSpecialEffectShapes();
	loadItems();
	loadButtonShapes();
	initMainButtonList();
	loadMainScreen();
	_screen->loadPalette("PALETTE.COL", _screen->getPalette(0));

	if (_flags.platform == Common::kPlatformAmiga)
		_screen->loadPaletteTable("PALETTE.DAT", 6);

	// XXX
	_animator->initAnimStateList();
	setCharactersInDefaultScene();

	if (!_emc->load("_STARTUP.EMC", &_npcScriptData, &_opcodes))
		error("Could not load \"_STARTUP.EMC\" script");
	_emc->init(&_scriptMain, &_npcScriptData);

	if (!_emc->start(&_scriptMain, 0))
		error("Could not start script function 0 of script \"_STARTUP.EMC\"");

	while (_emc->isValid(&_scriptMain))
		_emc->run(&_scriptMain);

	_emc->unload(&_npcScriptData);

	if (!_emc->load("_NPC.EMC", &_npcScriptData, &_opcodes))
		error("Could not load \"_NPC.EMC\" script");

	snd_playTheme(1, -1);
	if (_gameToLoad == -1) {
		enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1);
		if (_abortIntroFlag && _skipIntroFlag && saveFileLoadable(0)) {
			_menuDirectlyToLoad = true;
			_screen->setMouseCursor(1, 1, _shapes[0]);
			_screen->showMouse();
			_gui->buttonMenuCallback(0);
			_menuDirectlyToLoad = false;
		} else if (!shouldQuit()) {
			saveGameStateIntern(0, "New game", 0);
		}
	} else {
		_screen->setFont(_flags.lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT);
		loadGameStateCheck(_gameToLoad);
		_gameToLoad = -1;
	}
}
示例#20
0
文件: itemsync.cpp 项目: hluk/CopyQ
ItemSaverPtr ItemSyncLoader::initializeTab(const QString &tabName, QAbstractItemModel *model, int maxItems)
{
    return loadItems(tabName, model, QStringList(), maxItems);
}
示例#21
0
void ItemManager::init() {
	loadItems();
	loadArmors();
	loadWeapons();
	loadSkills();
}
示例#22
0
WorldYamlSource::WorldYamlSource(std::string dir): currentItemIndex(0), dir(dir) {
	loadPropertySystems();
	loadItemBases();
	loadItems();
}
示例#23
0
void KLSHistoryCombo::init()
{
    loadItems();
}
示例#24
0
bool IOPlayer::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/)
{
	Database* db = Database::instance();
	DBQuery query;
	DBResult* result;

	query << "SELECT `players`.`id` AS `id`, `players`.`name` AS `name`, `account_id`, \
			 `players`.`group_id` as `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, \
			 `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `direction`, `lookbody`, \
			 `lookfeet`, `lookhead`, `looklegs`, `looktype`, `posx`, `posy`, \
			 `posz`, `cap`, `lastlogin`, `lastip`, `save`, `conditions`, `redskulltime`, \
			 `redskull`, `guildnick`, `loss_experience`, `loss_mana`, `loss_skills`, \
			 `loss_items`, `rank_id`, `town_id`, `balance`, `premend` \
			 FROM `players` LEFT JOIN `accounts` ON `account_id` = `accounts`.`id` \
			 WHERE `players`.`name` = " + db->escapeString(name);

	if(!(result = db->storeQuery(query.str()))){
	  	return false;
	}
	query.str("");

	player->setGUID(result->getDataInt("id"));
	player->accountNumber = result->getDataInt("account_id");

	const PlayerGroup* group = getPlayerGroup(result->getDataInt("group_id"));
	if(group){
		player->accessLevel = group->m_access;
		player->maxDepotLimit = group->m_maxDepotItems;
		player->maxVipLimit = group->m_maxVip;
		player->setFlags(group->m_flags);
	}

	if(preload){
		//only loading basic info
		db->freeResult(result);
		return true;
	}

	// Getting all player properties
	player->setSex((playersex_t)result->getDataInt("sex"));
	player->setDirection((Direction)result->getDataInt("direction"));
	player->level = std::max((uint32_t)1, (uint32_t)result->getDataInt("level"));

	uint64_t currExpCount = Player::getExpForLevel(player->level);
	uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
	uint64_t experience = (uint64_t)result->getDataLong("experience");
	if(experience < currExpCount || experience  > nextExpCount){
		experience = currExpCount;
	}
	player->experience = experience;
	player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
	player->soul = result->getDataInt("soul");
	player->capacity = result->getDataInt("cap");
	player->lastLoginSaved = result->getDataInt("lastlogin");

	player->health = result->getDataInt("health");
	player->healthMax = result->getDataInt("healthmax");
	player->defaultOutfit.lookType = result->getDataInt("looktype");
	player->defaultOutfit.lookHead = result->getDataInt("lookhead");
	player->defaultOutfit.lookBody = result->getDataInt("lookbody");
	player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
	player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
	player->currentOutfit = player->defaultOutfit;

#ifdef __SKULLSYSTEM__
	int32_t redSkullSeconds = result->getDataInt("redskulltime") - std::time(NULL);
	if(redSkullSeconds > 0){
		//ensure that we round up the number of ticks
		player->redSkullTicks = (redSkullSeconds + 2)*1000;

		if(result->getDataInt("redskull") == 1){
			player->skull = SKULL_RED;
		}
	}
#endif

	unsigned long conditionsSize = 0;
	const char* conditions = result->getDataStream("conditions", conditionsSize);
	PropStream propStream;
	propStream.init(conditions, conditionsSize);

	Condition* condition;
	while((condition = Condition::createCondition(propStream))){
		if(condition->unserialize(propStream)){
			player->storedConditionList.push_back(condition);
		}
		else{
			delete condition;
		}
	}
	// you need to set the vocation after conditions in order to ensure the proper regeneration rates for the vocation
	player->setVocation(result->getDataInt("vocation"));
	// this stuff has to go after the vocation is set
	player->mana = result->getDataInt("mana");
	player->manaMax = result->getDataInt("manamax");
	player->magLevel = result->getDataInt("maglevel");

	uint32_t nextManaCount = (uint32_t)player->vocation->getReqMana(player->magLevel + 1);
	uint32_t manaSpent = (uint32_t)result->getDataInt("manaspent");
	if(manaSpent > nextManaCount){
		//make sure its not out of bound
		manaSpent = 0;
	}
	player->manaSpent = manaSpent;
	player->magLevelPercent = Player::getPercentLevel(player->manaSpent, nextManaCount);

	player->setLossPercent(LOSS_EXPERIENCE, result->getDataInt("loss_experience"));
	player->setLossPercent(LOSS_MANASPENT, result->getDataInt("loss_mana"));
	player->setLossPercent(LOSS_SKILLTRIES, result->getDataInt("loss_skills"));
	player->setLossPercent(LOSS_ITEMS, result->getDataInt("loss_items"));

	player->loginPosition.x = result->getDataInt("posx");
	player->loginPosition.y = result->getDataInt("posy");
	player->loginPosition.z = result->getDataInt("posz");

	player->town = result->getDataInt("town_id");
	Town* town = Towns::getInstance().getTown(player->town);
	if(town){
		player->masterPos = town->getTemplePosition();
	}

	//if posx == 0 AND posy == 0 AND posz == 0
	// login position is temple position
	Position loginPos = player->loginPosition;
	if (loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0) {
		player->loginPosition = player->masterPos;
	}

	Account acc;
	if (player->getVocationId() && acc.premEnd > 0 && acc.premEnd < std::time(NULL) && (g_config.getNumber(ConfigManager::TEMPLE_TP_ID) != 0)){
		town = Towns::getInstance().getTown(g_config.getNumber(ConfigManager::TEMPLE_TP_ID));
		player->loginPosition = town->getTemplePosition();
	}

	uint32_t rankid = result->getDataInt("rank_id");
	// place it here and now we can drop all additional query instances as all data were loaded
	player->premiumEnd = result->getDataInt("premend");

	player->balance = result->getDataInt("balance");

	player->guildNick = result->getDataString("guildnick");
	db->freeResult(result);

	if(rankid){
		query << "SELECT `guild_ranks`.`name` as `rank`, `guild_ranks`.`guild_id` as `guildid`, `guild_ranks`.`level` as `level`, `guilds`.`name` as `guildname` FROM `guild_ranks`, `guilds` WHERE `guild_ranks`.`id` = " << rankid << " AND `guild_ranks`.`guild_id` = `guilds`.`id`";
		if((result = db->storeQuery(query.str()))){
			player->guildName = result->getDataString("guildname");
			player->guildLevel = result->getDataInt("level");
			player->guildId = result->getDataInt("guildid");
			player->guildRank = result->getDataString("rank");

			db->freeResult(result);
		}
		query.str("");
	}

	//get password
	query << "SELECT `password` FROM `accounts` WHERE `id` = " << player->accountNumber;
	if(!(result = db->storeQuery(query.str()))){
		return false;
	}

	player->password = result->getDataString("password");
	db->freeResult(result);

	// we need to find out our skills
	// so we query the skill table
	query.str("");
	query << "SELECT `skillid`, `value`, `count` FROM `player_skills` WHERE `player_id` = " << player->getGUID();
	if((result = db->storeQuery(query.str()))){
		//now iterate over the skills
		do{
			int skillid = result->getDataInt("skillid");
			if(skillid >= SKILL_FIRST && skillid <= SKILL_LAST){
				uint32_t skillLevel = result->getDataInt("value");
				uint32_t skillCount = result->getDataInt("count");

				uint32_t nextSkillCount = player->vocation->getReqSkillTries(skillid, skillLevel + 1);
				if(skillCount > nextSkillCount){
					//make sure its not out of bound
					skillCount = 0;
				}

				player->skills[skillid][SKILL_LEVEL] = skillLevel;
				player->skills[skillid][SKILL_TRIES] = skillCount;
				player->skills[skillid][SKILL_PERCENT] = Player::getPercentLevel(skillCount, nextSkillCount);
			}
		}while(result->next());

		db->freeResult(result);
	}

	query.str("");
	query << "SELECT `name` FROM `player_spells` WHERE `player_id` = " << player->getGUID();
	if((result = db->storeQuery(query.str()))){
		do{
			std::string spellName = result->getDataString("name");
			player->learnedInstantSpellList.push_back(spellName);
		}while(result->next());

		db->freeResult(result);
	}

	//load inventory items
	ItemMap itemMap;

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if((result = db->storeQuery(query.str()))){
		loadItems(itemMap, result);

		ItemMap::reverse_iterator it;
		ItemMap::iterator it2;

		for(it = itemMap.rbegin(); it != itemMap.rend(); ++it){
			Item* item = it->second.first;
			int pid = it->second.second;
			if(pid >= 1 && pid <= 10){
				player->__internalAddThing(pid, item);
			}
			else{
				it2 = itemMap.find(pid);
				if(it2 != itemMap.end())
					if(Container* container = it2->second.first->getContainer()){
						container->__internalAddThing(item);
					}
			}
		}

		db->freeResult(result);
	}


	//load depot items
	itemMap.clear();

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if((result = db->storeQuery(query.str()))){
		loadItems(itemMap, result);

		ItemMap::reverse_iterator it;
		ItemMap::iterator it2;

		for(it = itemMap.rbegin(); it != itemMap.rend(); ++it){
			Item* item = it->second.first;
			int pid = it->second.second;
			if(pid >= 0 && pid < 100){
				if(Container* c = item->getContainer()){
					if(Depot* depot = c->getDepot())
						player->addDepot(depot, pid);
					else
						std::cout << "Error loading depot "<< pid << " for player " << player->getGUID() << std::endl;
				}
				else{
					std::cout << "Error loading depot "<< pid << " for player " <<
						player->getGUID() << std::endl;
				}
			}
			else{
				it2 = itemMap.find(pid);
				if(it2 != itemMap.end())
					if(Container* container = it2->second.first->getContainer()){
						container->__internalAddThing(item);
					}
			}
		}

		db->freeResult(result);
	}

	//load storage map
	query.str("");
	query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();
	if((result = db->storeQuery(query.str()))){
		do{
			uint32_t key = result->getDataInt("key");
			int32_t value = result->getDataInt("value");
			player->addStorageValue(key,value);
		}while(result->next());
		db->freeResult(result);
	}

	//load vip
	query.str("");
	query << "SELECT `vip_id` FROM `player_viplist` WHERE `player_id` = " << player->getGUID();
	if((result = db->storeQuery(query.str()))){
		do{
			uint32_t vip_id = result->getDataInt("vip_id");
			std::string dummy_str;
			if(storeNameByGuid(*db, vip_id))
				player->addVIP(vip_id, dummy_str, false, true);
		}while(result->next());
		db->freeResult(result);
	}

	player->updateBaseSpeed();
	player->updateInventoryWeigth();
	player->updateItemsLight(true);

	return true;
}
示例#25
0
bool IOLoginData::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/)
{
	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `id`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina` FROM `players` WHERE `name` = " << db->escapeString(name);

	DBResult* result = db->storeQuery(query.str());

	if (!result) {
		return false;
	}

	uint32_t accno = result->getDataInt("account_id");
	Account acc = loadAccount(accno);

	player->setGUID(result->getDataInt("id"));
	player->accountNumber = accno;

	player->accountType = acc.accountType;

	if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) {
		player->premiumDays = 0xFFFF;
	} else {
		player->premiumDays = acc.premiumDays;
	}

	player->setGroupId(result->getDataInt("group_id"));

	if (preload) {
		//only loading basic info
		db->freeResult(result);
		return true;
	}

	player->bankBalance = (uint64_t)result->getDataLong("balance");

	player->setSex((PlayerSex_t)result->getDataInt("sex"));
	player->level = std::max<uint32_t>(1, result->getDataInt("level"));

	uint64_t currExpCount = Player::getExpForLevel(player->level);
	uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
	uint64_t experience = (uint64_t)result->getDataLong("experience");

	if (experience < currExpCount || experience > nextExpCount) {
		experience = currExpCount;
	}

	player->experience = experience;

	if (currExpCount < nextExpCount) {
		player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
	} else {
		player->levelPercent = 0;
	}

	player->soul = result->getDataInt("soul");
	player->capacity = result->getDataInt("cap");
	player->blessings = result->getDataInt("blessings");

	unsigned long conditionsSize = 0;
	const char* conditions = result->getDataStream("conditions", conditionsSize);
	PropStream propStream;
	propStream.init(conditions, conditionsSize);

	Condition* condition = Condition::createCondition(propStream);
	while (condition) {
		if (condition->unserialize(propStream)) {
			player->storedConditionList.push_back(condition);
		} else {
			delete condition;
		}
		condition = Condition::createCondition(propStream);
	}

	player->setVocation(result->getDataInt("vocation"));
	player->mana = result->getDataInt("mana");
	player->manaMax = result->getDataInt("manamax");
	player->magLevel = result->getDataInt("maglevel");

	uint64_t nextManaCount = player->vocation->getReqMana(player->magLevel + 1);
	uint64_t manaSpent = result->getDataLong("manaspent");

	if (manaSpent > nextManaCount) {
		manaSpent = 0;
	}

	player->manaSpent = manaSpent;
	player->magLevelPercent = Player::getPercentLevel(player->manaSpent,
	                          nextManaCount);

	player->health = result->getDataInt("health");
	player->healthMax = result->getDataInt("healthmax");

	player->defaultOutfit.lookType = result->getDataInt("looktype");
	player->defaultOutfit.lookHead = result->getDataInt("lookhead");
	player->defaultOutfit.lookBody = result->getDataInt("lookbody");
	player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
	player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
	player->defaultOutfit.lookAddons = result->getDataInt("lookaddons");
	player->currentOutfit = player->defaultOutfit;

	if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
		int32_t skullSeconds = result->getDataInt("skulltime") - time(NULL);

		if (skullSeconds > 0) {
			//ensure that we round up the number of ticks
			player->skullTicks = (skullSeconds + 2) * 1000;
			int32_t skull = result->getDataInt("skull");

			if (skull == SKULL_RED) {
				player->skull = SKULL_RED;
			} else if (skull == SKULL_BLACK) {
				player->skull = SKULL_BLACK;
			}
		}
	}

	player->loginPosition.x = result->getDataInt("posx");
	player->loginPosition.y = result->getDataInt("posy");
	player->loginPosition.z = result->getDataInt("posz");

	player->lastLoginSaved = result->getDataLong("lastlogin");
	player->lastLogout = result->getDataLong("lastlogout");

	player->offlineTrainingTime = result->getDataInt("offlinetraining_time") * 1000;
	player->offlineTrainingSkill = result->getDataInt("offlinetraining_skill");

	player->town = result->getDataInt("town_id");

	Town* town = Towns::getInstance().getTown(player->town);

	if (town) {
		player->masterPos = town->getTemplePosition();
	}

	Position loginPos = player->loginPosition;

	if (loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0) {
		player->loginPosition = player->masterPos;
	}

	player->staminaMinutes = result->getDataInt("stamina");

	db->freeResult(result);

	query.str("");
	query << "SELECT `guild_id`, `rank_id`, `nick` FROM `guild_membership` WHERE `player_id` = " << player->getGUID();

	if ((result = db->storeQuery(query.str()))) {
		uint32_t guildId = result->getDataInt("guild_id");
		uint32_t playerRankId = result->getDataInt("rank_id");
		player->guildNick = result->getDataString("nick");
		db->freeResult(result);

		Guild* guild = g_game.getGuild(guildId);

		if (!guild) {
			query.str("");
			query << "SELECT `name` FROM `guilds` WHERE `id` = " << guildId;

			if ((result = db->storeQuery(query.str()))) {
				guild = new Guild(guildId, result->getDataString("name"));
				db->freeResult(result);
				g_game.addGuild(guild);

				query.str("");
				query << "SELECT `id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " LIMIT 3";

				if ((result = db->storeQuery(query.str()))) {
					do {
						guild->addRank(result->getDataInt("id"), result->getDataString("name"), result->getDataInt("level"));
					} while (result->next());

					db->freeResult(result);
				}
			}
		}

		if (guild) {
			player->guild = guild;
			GuildRank* rank = guild->getRankById(playerRankId);

			if (rank) {
				player->guildLevel = rank->level;
			} else {
				player->guildLevel = 1;
			}

			IOGuild::getInstance()->getWarList(guildId, player->guildWarList);

			query.str("");
			query << "SELECT COUNT(*) AS `members` FROM `guild_membership` WHERE `guild_id` = " << guildId;

			if ((result = db->storeQuery(query.str()))) {
				guild->setMemberCount(result->getDataInt("members"));
				db->freeResult(result);
			}
		}
	}

	//get password
	query.str("");
	query << "SELECT `password` FROM `accounts` WHERE `id` = " << accno;

	result = db->storeQuery(query.str());
	if (!result) {
		return false;
	}

	player->password = result->getDataString("password");
	db->freeResult(result);

	// we need to find out our skills
	// so we query the skill table
	query.str("");
	query << "SELECT `skillid`, `value`, `count` FROM `player_skills` WHERE `player_id` = " << player->getGUID();

	if ((result = db->storeQuery(query.str()))) {
		//now iterate over the skills
		do {
			int32_t skillid = result->getDataInt("skillid");

			if (skillid >= SKILL_FIRST && skillid <= SKILL_LAST) {
				uint32_t skillLevel = result->getDataInt("value");
				uint64_t skillCount = result->getDataLong("count");

				uint64_t nextSkillCount = player->vocation->getReqSkillTries(skillid, skillLevel + 1);

				if (skillCount > nextSkillCount) {
					skillCount = 0;
				}

				player->skills[skillid][SKILL_LEVEL] = skillLevel;
				player->skills[skillid][SKILL_TRIES] = skillCount;
				player->skills[skillid][SKILL_PERCENT] = Player::getPercentLevel(skillCount, nextSkillCount);
			}
		} while (result->next());

		db->freeResult(result);
	}

	query.str("");
	query << "SELECT `player_id`, `name` FROM `player_spells` WHERE `player_id` = " << player->getGUID();

	if ((result = db->storeQuery(query.str()))) {
		do {
			std::string spellName = result->getDataString("name");
			player->learnedInstantSpellList.push_back(spellName);
		} while (result->next());

		db->freeResult(result);
	}

	//load inventory items
	ItemMap itemMap;

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";

	if ((result = db->storeQuery(query.str()))) {
		loadItems(itemMap, result);
		db->freeResult(result);

		for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) {
			const std::pair<Item*, int32_t>& pair = it->second;
			Item* item = pair.first;
			int32_t pid = pair.second;

			if (pid >= 1 && pid <= 10) {
				player->__internalAddThing(pid, item);
			} else {
				ItemMap::const_iterator it2 = itemMap.find(pid);

				if (it2 == itemMap.end()) {
					continue;
				}

				Container* container = it2->second.first->getContainer();

				if (container) {
					container->__internalAddThing(item);
				}
			}
		}
	}

	//load depot items
	itemMap.clear();

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";

	if ((result = db->storeQuery(query.str()))) {
		loadItems(itemMap, result);
		db->freeResult(result);

		for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) {
			const std::pair<Item*, int32_t>& pair = it->second;
			Item* item = pair.first;
			int32_t pid = pair.second;

			if (pid >= 0 && pid < 100) {
				DepotChest* depotChest = player->getDepotChest(pid, true);

				if (depotChest) {
					depotChest->__internalAddThing(item);
				}
			} else {
				ItemMap::const_iterator it2 = itemMap.find(pid);

				if (it2 == itemMap.end()) {
					continue;
				}

				Container* container = it2->second.first->getContainer();

				if (container) {
					container->__internalAddThing(item);
				}
			}
		}
	}

	//load inbox items
	itemMap.clear();

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";

	if ((result = db->storeQuery(query.str()))) {
		loadItems(itemMap, result);
		db->freeResult(result);

		for (ItemMap::reverse_iterator it = itemMap.rbegin(); it != itemMap.rend(); ++it) {
			const std::pair<Item*, int32_t>& pair = it->second;
			Item* item = pair.first;
			int32_t pid = pair.second;

			if (pid >= 0 && pid < 100) {
				player->getInbox()->__internalAddThing(item);
			} else {
				ItemMap::const_iterator it2 = itemMap.find(pid);

				if (it2 == itemMap.end()) {
					continue;
				}

				Container* container = it2->second.first->getContainer();

				if (container) {
					container->__internalAddThing(item);
				}
			}
		}
	}

	//load storage map
	query.str("");
	query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();

	if ((result = db->storeQuery(query.str()))) {
		do {
			player->addStorageValue(result->getDataInt("key"), result->getDataLong("value"), true);
		} while (result->next());

		db->freeResult(result);
	}

	//load vip
	query.str("");
	query << "SELECT `player_id` FROM `account_viplist` WHERE `account_id` = " << player->getAccount();

	if ((result = db->storeQuery(query.str()))) {
		do {
			player->addVIPInternal(result->getDataInt("player_id"));
		} while (result->next());

		db->freeResult(result);
	}

	player->updateBaseSpeed();
	player->updateInventoryWeight();
	player->updateItemsLight(true);
	return true;
}