map<string,string> EQW::GetZoneDetails(Const_char *zone_ref) { map<string,string> res; ZoneServer *zs = zoneserver_list.FindByID(atoi(zone_ref)); if(zs == NULL) { res["error"] = "Invalid zone."; return(res); } res["type"] = zs->IsStaticZone()?"static":"dynamic"; res["zone_id"] = itoa(zs->GetZoneID()); res["launch_name"] = zs->GetLaunchName(); res["launched_name"] = zs->GetLaunchedName(); res["short_name"] = zs->GetZoneName(); res["long_name"] = zs->GetZoneLongName(); res["port"] = itoa(zs->GetCPort()); res["player_count"] = itoa(zs->NumPlayers()); //this isnt gunna work for dynamic zones... res["launcher"] = ""; if(zs->GetZoneID() != 0) { LauncherLink *ll = launcher_list.FindByZone(zs->GetLaunchName()); if(ll != NULL) res["launcher"] = ll->GetName(); } return(res); }
bool EQLConfig::SetDynamicCount(int count) { char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; if (!database.RunQuery(query, MakeAnyLenString(&query, "UPDATE launcher SET dynamics=%d WHERE name='%s'", count, namebuf), errbuf)) { LogFile->write(EQEMuLog::Error, "Error in SetDynamicCount query: %s", errbuf); safe_delete_array(query); return false; } safe_delete_array(query); //update in-memory version. m_dynamics = count; //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->BootDynamics(count); } return(false); }
bool EQLConfig::DeleteStaticZone(Const_char *short_name) { //check internal state std::map<std::string, LauncherZone>::iterator res; res = m_zones.find(short_name); if(res == m_zones.end()) { //not found. Log.Out(Logs::General, Logs::Error, "Update for unknown zone %s", short_name); return false; } char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; char zonebuf[32]; database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 zonebuf[31] = '\0'; std::string query = StringFormat("DELETE FROM launcher_zones WHERE " "launcher = '%s' AND zone = '%s'", namebuf, zonebuf); auto results = database.QueryDatabase(query); if (!results.Success()) { return false; } //internal update. m_zones.erase(res); //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->StopZone(short_name); } return true; }
bool EQLConfig::BootStaticZone(Const_char *short_name, uint16 port) { //make sure the short name is valid. if(database.GetZoneID(short_name) == 0) return false; //database update char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; char zonebuf[32]; database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 zonebuf[31] = '\0'; std::string query = StringFormat("INSERT INTO launcher_zones (launcher, zone, port) " "VALUES('%s', '%s', %d)", namebuf, zonebuf, port); auto results = database.QueryDatabase(query); if (!results.Success()) { return false; } //update our internal state. LauncherZone lz; lz.name = short_name; lz.port = port; m_zones[lz.name] = lz; //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->BootZone(short_name, port); } return true; }
void LauncherList::Process() { //process pending launchers.. std::vector<LauncherLink *>::iterator cur, end; cur = m_pendingLaunchers.begin(); while(cur != m_pendingLaunchers.end()) { LauncherLink *l = *cur; //printf("ProcP %d: %p\n", l->GetID(), l); if(!l->Process()) { //launcher has died before it identified itself. _log(WORLD__LAUNCH, "Removing pending launcher %d", l->GetID()); cur = m_pendingLaunchers.erase(cur); delete l; } else if(l->HasName()) { //launcher has identified itself now. //remove ourself from the pending list cur = m_pendingLaunchers.erase(cur); std::string name = l->GetName(); //kill off anybody else using our name. std::map<std::string, LauncherLink *>::iterator res; res = m_launchers.find(name); if(res != m_launchers.end()) { _log(WORLD__LAUNCH, "Ghosting launcher %s", name.c_str()); delete res->second; } _log(WORLD__LAUNCH, "Removing pending launcher %d. Adding %s to active list.", l->GetID(), name.c_str()); //put the launcher in the list. m_launchers[name] = l; } else { cur++; } } //process active launchers. std::map<std::string, LauncherLink *>::iterator curl, tmp; curl = m_launchers.begin(); while(curl != m_launchers.end()) { LauncherLink *l = curl->second; //printf("Proc %s(%d): %p\n", l->GetName(), l->GetID(), l); if(!l->Process()) { //launcher has died before it identified itself. _log(WORLD__LAUNCH, "Removing launcher %s (%d)", l->GetName(), l->GetID()); tmp = curl; curl++; m_launchers.erase(tmp); delete l; } else { curl++; } } }
std::map<std::string,std::string> EQLConfig::GetZoneDetails(Const_char *zone_ref) { std::map<std::string,std::string> res; LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll == nullptr) { res["name"] = zone_ref; res["up"] = "0"; res["starts"] = "0"; res["port"] = "0"; } else { ll->GetZoneDetails(zone_ref, res); } return(res); }
bool EQLConfig::ChangeStaticZone(Const_char *short_name, uint16 port) { //make sure the short name is valid. if(database.GetZoneID(short_name) == 0) return(false); //check internal state std::map<std::string, LauncherZone>::iterator res; res = m_zones.find(short_name); if(res == m_zones.end()) { //not found. LogFile->write(EQEMuLog::Error, "Update for unknown zone %s", short_name); return(false); } //database update char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; char zonebuf[32]; database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 zonebuf[31] = '\0'; if (!database.RunQuery(query, MakeAnyLenString(&query, "UPDATE launcher_zones SET port=%d WHERE launcher='%s' AND zone='%s'", port, namebuf, zonebuf), errbuf)) { LogFile->write(EQEMuLog::Error, "Error in ChangeStaticZone query: %s", errbuf); safe_delete_array(query); return false; } safe_delete_array(query); //update internal state res->second.port = port; //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->RestartZone(short_name); } return(true); }
std::vector<std::string> EQLConfig::ListZones() { LauncherLink *ll = launcher_list.Get(m_name.c_str()); std::vector<std::string> res; if(ll == nullptr) { //if the launcher isnt connected, use the list from the database. std::map<std::string, LauncherZone>::iterator cur, end; cur = m_zones.begin(); end = m_zones.end(); for(; cur != end; cur++) { res.push_back(cur->first); } } else { //otherwise, use the zone list from the launcher link. ll->GetZoneList(res); } return(res); }
bool EQLConfig::DeleteStaticZone(Const_char *short_name) { //check internal state std::map<std::string, LauncherZone>::iterator res; res = m_zones.find(short_name); if(res == m_zones.end()) { //not found. LogFile->write(EQEMuLog::Error, "Update for unknown zone %s", short_name); return(false); } //database update char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; char zonebuf[32]; database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 zonebuf[31] = '\0'; if (!database.RunQuery(query, MakeAnyLenString(&query, "DELETE FROM launcher_zones WHERE launcher='%s' AND zone='%s'", namebuf, zonebuf), errbuf)) { LogFile->write(EQEMuLog::Error, "Error in DeleteStaticZone query: %s", errbuf); safe_delete_array(query); return false; } safe_delete_array(query); //internal update. m_zones.erase(res); //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->StopZone(short_name); } return true; }
bool EQLConfig::BootStaticZone(Const_char *short_name, uint16 port) { //make sure the short name is valid. if(database.GetZoneID(short_name) == 0) return(false); //database update char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; char zonebuf[32]; database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 zonebuf[31] = '\0'; if (!database.RunQuery(query, MakeAnyLenString(&query, "INSERT INTO launcher_zones (launcher,zone,port) VALUES('%s', '%s', %d)", namebuf, zonebuf, port), errbuf)) { LogFile->write(EQEMuLog::Error, "Error in BootStaticZone query: %s", errbuf); safe_delete_array(query); return false; } safe_delete_array(query); //update our internal state. LauncherZone lz; lz.name = short_name; lz.port = port; m_zones[lz.name] = lz; //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->BootZone(short_name, port); } return(true); }
bool EQLConfig::ChangeStaticZone(Const_char *short_name, uint16 port) { //make sure the short name is valid. if(database.GetZoneID(short_name) == 0) return false; //check internal state std::map<std::string, LauncherZone>::iterator res; res = m_zones.find(short_name); if(res == m_zones.end()) { //not found. Log.Out(Logs::General, Logs::Error, "Update for unknown zone %s", short_name); return false; } char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; char zonebuf[32]; database.DoEscapeString(zonebuf, short_name, strlen(short_name)&0xF); //limit len to 16 zonebuf[31] = '\0'; std::string query = StringFormat("UPDATE launcher_zones SET port=%d WHERE " "launcher = '%s' AND zone = '%s'",port, namebuf, zonebuf); auto results = database.QueryDatabase(query); if (!results.Success()) { return false; } //update internal state res->second.port = port; //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->RestartZone(short_name); } return true; }
bool EQLConfig::SetDynamicCount(int count) { char namebuf[128]; database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F); //limit len to 64 namebuf[127] = '\0'; std::string query = StringFormat("UPDATE launcher SET dynamics=%d WHERE name='%s'", count, namebuf); auto results = database.QueryDatabase(query); if (!results.Success()) { return false; } //update in-memory version. m_dynamics = count; //if the launcher is connected, update it. LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll != nullptr) { ll->BootDynamics(count); } return false; }
void LauncherList::Add(EmuTCPConnection *conn) { LauncherLink *it = new LauncherLink(nextID++, conn); _log(WORLD__LAUNCH, "Adding pending launcher %d", it->GetID()); m_pendingLaunchers.push_back(it); }
void EQLConfig::StartZone(Const_char *zone_ref) { LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll == nullptr) return; ll->StartZone(zone_ref); }
void EQLConfig::RestartZone(Const_char *zone_ref) { LauncherLink *ll = launcher_list.Get(m_name.c_str()); if(ll == NULL) return; ll->RestartZone(zone_ref); }