void MyStringTable::keyPressEvent(QKeyEvent* event) { QTableView::keyPressEvent(event); QItemSelectionModel *sel = selectionModel(); if(!sel->hasSelection()) return; // QModelIndexList list = sel->selectedRows(); // if(list.count()<1) return ; // int row = list.at(0).row(); int key = event->key(); if(key==Qt::Key_Enter || key==Qt::Key_Return) { int r = currentIndex().row(); int c = currentIndex().column(); if(ColEdit(c)) { if(this->state()!=QAbstractItemView::EditingState) { edit(currentIndex()); } } else { emit rowEvent(r, 2); } } else if(key==Qt::Key_Home) { QApplication::beep(); QModelIndex index = _model->index(0,0, QModelIndex()); sel->clearSelection(); setCurrentIndex(index); } else if(key==Qt::Key_End) { QModelIndex index = _model->index(RowCount()-1,0, QModelIndex()); sel->clearSelection(); setCurrentIndex(index); } }
//AndMetal: this may now be obsolete since we have Zone::GetTotalAALevels() uint8 ZoneDatabase::GetTotalAALevels(uint32 skill_id) { std::string query = StringFormat("SELECT count(slot) FROM aa_effects WHERE aaid = %i", skill_id); auto results = QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]); }
int ZoneDatabase::GetHighestGrid(uint32 zoneid) { std::string query = StringFormat("SELECT COALESCE(MAX(id), 0) FROM grid WHERE zoneid = %i", zoneid); auto results = QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in GetHighestGrid query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]); }
uint32 ZoneDatabase::CountAAs(){ const std::string query = "SELECT count(title_sid) FROM altadv_vars"; auto results = QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]);; }
uint32 ZoneDatabase::CountAAEffects() { const std::string query = "SELECT count(id) FROM aa_effects"; auto results = QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]); }
int ZoneDatabase::GetHighestWaypoint(uint32 zoneid, uint32 gridid) { std::string query = StringFormat("SELECT COALESCE(MAX(number), 0) FROM grid_entries " "WHERE zoneid = %i AND gridid = %i", zoneid, gridid); auto results = QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]); }
int GetSkill(SharedDatabase *db, int skill_id, int class_id, int level) { std::string query = StringFormat("SELECT cap FROM skill_caps WHERE class=%d AND skillID=%d AND level=%d", class_id, skill_id, level); auto results = db->QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() == 0) return 0; auto row = results.begin(); return atoi(row[0]); }
QString MyStringTable::Cell(int r, int c) { if(r<0 || r>=RowCount()) return ""; if(c<0 || c>=ColCount()) return ""; int rc = receivers(SIGNAL(cellDataRequest(int, int, QString&))); if(rc<1) return _rows[r].cells[c].text; QString v; emit cellDataRequest(r,c,v); return v; }
bool ZoneDatabase::CheckGuildDoor(uint8 doorid, uint16 guild_id, const char* zone) { std::string query = StringFormat("SELECT guild FROM doors WHERE doorid = %i AND zone = '%s'", doorid-128, zone); auto results = QueryDatabase(query); if (!results.Success()) { return false; } if (results.RowCount() != 1) return false; auto row = results.begin(); return atoi(row[0]) == guild_id; }
bool WorldDatabase::GetStartZone(PlayerProfile_Struct* in_pp, CharCreate_Struct* in_cc,bool isTitanium) { // SoF doesn't send the player_choice field in character creation, it now sends the real zoneID instead. // // For SoF, search for an entry in start_zones with a matching zone_id, class, race and deity. // // For now, if no row matching row is found, send them to Crescent Reach, as that is probably the most likely // reason for no match being found. // if(!in_pp || !in_cc) return false; in_pp->x = in_pp->y = in_pp->z = in_pp->heading = in_pp->zone_id = 0; in_pp->binds[0].x = in_pp->binds[0].y = in_pp->binds[0].z = in_pp->binds[0].zoneId = in_pp->binds[0].instance_id = 0; // see if we have an entry for start_zone. We can support both titanium & SOF+ by having two entries per class/race/deity combo with different zone_ids std::string query = StringFormat("SELECT x, y, z, heading, start_zone, bind_id FROM start_zones WHERE zone_id = %i " "AND player_class = %i AND player_deity = %i AND player_race = %i", in_cc->start_zone, in_cc->class_, in_cc->deity, in_cc->race); auto results = QueryDatabase(query); if(!results.Success()) { return false; } Log.Out(Logs::General, Logs::Status, "SoF Start zone query: %s\n", query.c_str()); if (results.RowCount() == 0) { printf("No start_zones entry in database, using defaults\n"); isTitanium ? SetTitaniumDefaultStartZone(in_pp, in_cc) : SetSoFDefaultStartZone(in_pp, in_cc); } else { Log.Out(Logs::General, Logs::Status, "Found starting location in start_zones"); auto row = results.begin(); in_pp->x = atof(row[0]); in_pp->y = atof(row[1]); in_pp->z = atof(row[2]); in_pp->heading = atof(row[3]); in_pp->zone_id = atoi(row[4]); in_pp->binds[0].zoneId = atoi(row[5]); } if(in_pp->x == 0 && in_pp->y == 0 && in_pp->z == 0) database.GetSafePoints(in_pp->zone_id, 0, &in_pp->x, &in_pp->y, &in_pp->z); if(in_pp->binds[0].x == 0 && in_pp->binds[0].y == 0 && in_pp->binds[0].z == 0) database.GetSafePoints(in_pp->binds[0].zoneId, 0, &in_pp->binds[0].x, &in_pp->binds[0].y, &in_pp->binds[0].z); return true; }
const NPCType *Horse::BuildHorseType(uint16 spell_id) { const char* fileName = spells[spell_id].teleport_zone; std::string query = StringFormat("SELECT race, gender, texture, mountspeed FROM horses WHERE filename = '%s'", fileName); auto results = database.QueryDatabase(query); if (!results.Success()) { return nullptr; } if (results.RowCount() != 1) { Log.Out(Logs::General, Logs::Error, "No Database entry for mount: %s, check the horses table", fileName); return nullptr; } auto row = results.begin(); NPCType* npc_type = new NPCType; memset(npc_type, 0, sizeof(NPCType)); strcpy(npc_type->name,"Unclaimed_Mount"); //this should never get used strcpy(npc_type->special_abilities, "19,1^20,1^24,1"); npc_type->cur_hp = 1; npc_type->max_hp = 1; npc_type->race = atoi(row[0]); npc_type->gender = atoi(row[1]); // Drogmor's are female horses. Yuck. npc_type->class_ = 1; npc_type->deity= 1; npc_type->level = 1; npc_type->npc_id = 0; npc_type->loottable_id = 0; npc_type->texture = atoi(row[2]); // mount color npc_type->helmtexture = atoi(row[2]); // mount color npc_type->runspeed = atof(row[3]); npc_type->light = 0; npc_type->STR = 75; npc_type->STA = 75; npc_type->DEX = 75; npc_type->AGI = 75; npc_type->INT = 75; npc_type->WIS = 75; npc_type->CHA = 75; npc_type->trackable = 1; horses_auto_delete.Insert(npc_type); return npc_type; }
uint32 ZoneDatabase::GetMacToEmuAA(uint8 eqmacid) { std::string query = StringFormat("SELECT skill_id from altadv_vars where eqmacid=%i", eqmacid); auto results = QueryDatabase(query); if (!results.Success() || results.RowCount() == 0) { Log.Out(Logs::Detail, Logs::Error, "Error in GetMacToEmuAA"); return 0; } auto row = results.begin(); Log.Out(Logs::Detail, Logs::Debug, "GetMacToEmuAA is returning: %i", atoi(row[0])); return atoi(row[0]); }
uint8 ZoneDatabase::GetGridType2(uint32 grid, uint16 zoneid) { int type2 = 0; std::string query = StringFormat("SELECT type2 FROM grid WHERE id = %i AND zoneid = %i", grid, zoneid); auto results = QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]); }
std::string RuleManager::GetRulesetName(Database *db, int id) { std::string query = StringFormat("SELECT name FROM rule_sets WHERE ruleset_id=%d", id); auto results = db->QueryDatabase(query); if (!results.Success()) { return ""; } if (results.RowCount() == 0) return ""; auto row = results.begin(); return row[0]; }
void Database::SendBody(Client *client, int messageNumber) { int characterID = FindCharacter(client->MailBoxName().c_str()); _log(UCS__TRACE, "SendBody: MsgID %i, to %s, CharID is %i", messageNumber, client->MailBoxName().c_str(), characterID); if(characterID <= 0) return; std::string query = StringFormat("SELECT `msgid`, `body`, `to` FROM `mail` " "WHERE `charid`=%i AND `msgid`=%i", characterID, messageNumber); auto results = QueryDatabase(query); if (!results.Success()) return; if (results.RowCount() != 1) return; auto row = results.begin(); _log(UCS__TRACE, "Message: %i body (%i bytes)", messageNumber, strlen(row[1])); int packetLength = 12 + strlen(row[0]) + strlen(row[1]) + strlen(row[2]); EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailSendBody,packetLength); char *packetBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber()); VARSTRUCT_ENCODE_STRING(packetBuffer,row[0]); VARSTRUCT_ENCODE_STRING(packetBuffer,row[1]); VARSTRUCT_ENCODE_STRING(packetBuffer,"1"); VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0); VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a); VARSTRUCT_ENCODE_STRING(packetBuffer, "TO:"); packetBuffer--; VARSTRUCT_ENCODE_STRING(packetBuffer, row[2]); packetBuffer--; // Overwrite the null terminator VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a); _pkt(UCS__PACKETS, outapp); client->QueuePacket(outapp); safe_delete(outapp); }
bool Database::DBSetup_SetEmailDefault() { std::string check_query = StringFormat("SHOW COLUMNS FROM `tblloginserveraccounts` LIKE 'AccountEmail'"); auto results = QueryDatabase(check_query); if (results.RowCount() != 0) { std::string create_query = StringFormat("ALTER TABLE `tblloginserveraccounts` CHANGE `AccountEmail` `AccountEmail` varchar(100) not null default '0'"); auto create_results = QueryDatabase(create_query); if (!create_results.Success()) { server_log->Log(log_database_error, "Error adjusting AccountEmail column."); return false; } } server_log->Log(log_database, "Adjusted AccountEmail column."); return true; }
std::string RuleManager::GetRulesetName(Database *db, int id) { std::string query = StringFormat("SELECT name FROM rule_sets WHERE ruleset_id=%d", id); auto results = db->QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in LoadRules query %s: %s", query.c_str(), results.ErrorMessage().c_str()); return ""; } if (results.RowCount() == 0) return ""; auto row = results.begin(); return row[0]; }
uint32 ZoneDatabase::GetFreeGrid(uint16 zoneid) { std::string query = StringFormat("SELECT max(id) FROM grid WHERE zoneid = %i", zoneid); auto results = QueryDatabase(query); if (!results.Success()) { return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); uint32 freeGridID = 1; freeGridID = atoi(row[0]) + 1; return freeGridID; }
bool WorldDatabase::GetCharacterLevel(const char *name, int &level) { std::string query = StringFormat("SELECT level FROM character_data WHERE name = '%s'", name); auto results = QueryDatabase(query); if (!results.Success()) { Log.Out(Logs::General, Logs::Error, "WorldDatabase::GetCharacterLevel: %s", results.ErrorMessage().c_str()); return false; } if (results.RowCount() == 0) return false; auto row = results.begin(); level = atoi(row[0]); return true; }
uint8 ZoneDatabase::GetGridType2(uint32 grid, uint16 zoneid) { int type2 = 0; std::string query = StringFormat("SELECT type2 FROM grid WHERE id = %i AND zoneid = %i", grid, zoneid); auto results = QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in GetGridType2 query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); return atoi(row[0]); }
void Client::TradeskillSearchResults(const std::string query, unsigned long objtype, unsigned long someid) { auto results = database.QueryDatabase(query); if (!results.Success()) { return; } if(results.RowCount() < 1) return; //search gave no results... not an error if(results.ColumnCount() != 6) { Log.Out(Logs::General, Logs::Error, "Error in TradeskillSearchResults query '%s': Invalid column count in result", query.c_str()); return; } for(auto row = results.begin(); row != results.end(); ++row) { if(row == nullptr || row[0] == nullptr || row[1] == nullptr || row[2] == nullptr || row[3] == nullptr || row[5] == nullptr) continue; uint32 recipe = (uint32)atoi(row[0]); const char *name = row[1]; uint32 trivial = (uint32) atoi(row[2]); uint32 comp_count = (uint32) atoi(row[3]); uint32 tradeskill = (uint16) atoi(row[5]); // Skip the recipes that exceed the threshold in skill difference // Recipes that have either been made before or were // explicitly learned are excempt from that limit if (RuleB(Skills, UseLimitTradeskillSearchSkillDiff) && ((int32)trivial - (int32)GetSkill((SkillUseTypes)tradeskill)) > RuleI(Skills, MaxTradeskillSearchSkillDiff) && row[4] == nullptr) continue; EQApplicationPacket* outapp = new EQApplicationPacket(OP_RecipeReply, sizeof(RecipeReply_Struct)); RecipeReply_Struct *reply = (RecipeReply_Struct *) outapp->pBuffer; reply->object_type = objtype; reply->some_id = someid; reply->component_count = comp_count; reply->recipe_id = recipe; reply->trivial = trivial; strn0cpy(reply->recipe_name, name, sizeof(reply->recipe_name)); FastQueuePacket(&outapp); } }
uint32 BaseGuildManager::_GetFreeGuildID() { if(m_db == nullptr) { _log(GUILDS__DB, "Requested find a free guild ID when we have no database object."); return(GUILD_NONE); } std::string query; //this has got to be one of the more retarded things I have seen. //none the less, im too lazy to rewrite it right now. //possibly: // // SELECT t1.id + 1 // FROM guilds t1 // WHERE NOT EXISTS ( // SELECT * // FROM guilds t2 // WHERE t2.id = t1.id + 1 // ) // LIMIT 1 // // Seems likely what we should be doing is auto incrementing the guild table // inserting, then getting the id. NOT getting a free id then inserting. // could be a race condition. for (auto index = 1; index < MAX_NUMBER_GUILDS; ++index) { query = StringFormat("SELECT id FROM guilds where id=%i;", index); auto results = m_db->QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in _GetFreeGuildID query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); continue; } if (results.RowCount() == 0) { _log(GUILDS__DB, "Located free guild ID %d in the database", index); return index; } } _log(GUILDS__ERROR, "Unable to find a free guild ID when requested."); return GUILD_NONE; }
uint32 ZoneDatabase::GetFreeGrid(uint16 zoneid) { std::string query = StringFormat("SELECT max(id) FROM grid WHERE zoneid = %i", zoneid); auto results = QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in GetFreeGrid query '%s': %s", query.c_str(), results.ErrorMessage().c_str()); return 0; } if (results.RowCount() != 1) return 0; auto row = results.begin(); uint32 freeGridID = 1; freeGridID = atoi(row[0]) + 1; return freeGridID; }
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) { std::string query = StringFormat("SELECT `value` FROM `variables` WHERE `varname` = '%s'", varname); auto results = QueryDatabase(query); if (!results.Success()) { _log(UCS__ERROR, "Unable to get message count from database. %s %s", query.c_str(), results.ErrorMessage().c_str()); return false; } if (results.RowCount() != 1) return false; auto row = results.begin(); snprintf(varvalue, varvalue_len, "%s", row[0]); return true; }
/** * Checks for bucket existence by bucket_name key * @param bucket_key * @return */ uint64 DataBucket::DoesBucketExist(std::string bucket_key) { std::string query = StringFormat( "SELECT `id` from `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0) LIMIT 1", EscapeString(bucket_key).c_str(), (long long) std::time(nullptr) ); auto results = database.QueryDatabase(query); if (!results.Success()) { return 0; } auto row = results.begin(); if (results.RowCount() != 1) return 0; return std::stoull(row[0]); }
bool ON_Matrix::Transpose() { bool rc = false; int i, j; double t; const int row_count = RowCount(); const int col_count = ColCount(); if ( row_count > 0 && col_count > 0 ) { double** this_m = ThisM(); if ( row_count == col_count ) { rc = true; for ( i = 0; i < row_count; i++ ) for ( j = i+1; j < row_count; j++ ) { t = this_m[i][j]; this_m[i][j] = this_m[j][i]; this_m[j][i] = t; } } else if ( this_m == m_rowmem.Array() ) { ON_Matrix A(*this); rc = Create(col_count,row_count) && m_row_count == A.ColCount() && m_col_count == A.RowCount(); if (rc) { double const*const* Am = A.ThisM(); this_m = ThisM(); // Create allocates new memory for ( i = 0; i < row_count; i++ ) for ( j = 0; j < col_count; j++ ) { this_m[j][i] = Am[i][j]; } m_row_offset = A.m_col_offset; m_col_offset = A.m_row_offset; } else { // attempt to put values back *this = A; } } } return rc; }
int32 ZoneDatabase::GetDoorsCountPlusOne(const char *zone_name, int16 version) { std::string query = StringFormat("SELECT MAX(id) FROM doors " "WHERE zone = '%s' AND version = %u", zone_name, version); auto results = QueryDatabase(query); if (!results.Success()) { return -1; } if (results.RowCount() != 1) return -1; auto row = results.begin(); if (!row[0]) return 0; return atoi(row[0]) + 1; }
void Raid::GetRaidDetails() { std::string query = StringFormat("SELECT locked, loottype, motd FROM raid_details WHERE raidid = %lu", (unsigned long)GetID()); auto results = database.QueryDatabase(query); if (!results.Success()) return; if (results.RowCount() == 0) { LogFile->write(EQEMuLog::Error, "Error getting raid details for raid %lu: %s", (unsigned long)GetID(), results.ErrorMessage().c_str()); return; } auto row = results.begin(); locked = atoi(row[0]); LootType = atoi(row[1]); motd = std::string(row[2]); }
int RuleManager::GetRulesetID(Database *database, const char *ruleset_name) { uint32 len = strlen(ruleset_name); auto rst = new char[2 * len + 1]; database->DoEscapeString(rst, ruleset_name, len); std::string query = StringFormat("SELECT ruleset_id FROM rule_sets WHERE name='%s'", rst); safe_delete_array(rst); auto results = database->QueryDatabase(query); if (!results.Success()) return -1; if (results.RowCount() == 0) return -1; auto row = results.begin(); return atoi(row[0]); }
/** * Retrieves data expires time via bucket_name as key * @param bucket_key * @return */ std::string DataBucket::GetDataExpires(std::string bucket_key) { std::string query = StringFormat( "SELECT `expires` from `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0) LIMIT 1", bucket_key.c_str(), (long long) std::time(nullptr) ); auto results = database.QueryDatabase(query); if (!results.Success()) { return std::string(); } if (results.RowCount() != 1) return std::string(); auto row = results.begin(); return std::string(row[0]); }