View Single Post
  #2  
Old 04-24-2008, 01:04 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

I am definitely no coder, but I am hoping to start learning more about it soon. I normally learn pretty quickly, but it looks like teaching myself how to write source is gonna take a while. Either way, I wanted to post some sections of the source that I think might need to be looked at to make a change in the way ports are loaded to multiple zone servers.

Again, I am not a coder, so this could all be completely irrelevant, but it is the stuff that stands out to me as being related to setting up zones on ports. Note that I only added in the sections from these files that I think might be related, so if it looks like something is missing, it is probably because I didn't know to copy it in here:


EQLConfig.cpp
Code:
	if (database.RunQuery(query, MakeAnyLenString(&query,
			"SELECT dynamics FROM launcher WHERE name='%s'",
			namebuf)
		, errbuf, &result))
	{
		while ((row = mysql_fetch_row(result))) {
			m_dynamics = atoi(row[0]);
		}
		mysql_free_result(result);
	} else {
		LogFile->write(EQEMuLog::Error, "EQLConfig::LoadSettings: %s", errbuf);
	}
	safe_delete_array(query);
	
	if (database.RunQuery(query, MakeAnyLenString(&query,
			"SELECT zone,port FROM launcher_zones WHERE launcher='%s'",
			namebuf)
		, errbuf, &result))
	{
		LauncherZone zs;
		while ((row = mysql_fetch_row(result))) {
			zs.name = row[0];
			zs.port = atoi(row[1]);
			m_zones[zs.name] = zs;
		}
		mysql_free_result(result);
	} else {
		LogFile->write(EQEMuLog::Error, "EQLConfig::LoadSettings: %s", errbuf);
	}
	safe_delete_array(query);
}


	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 != NULL) {
		ll->BootZone(short_name, port);
	}
	
	return(true);
}


	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;
LauncherLink.cpp
Code:
			std::vector<LauncherZone>::iterator cur, end;
			cur = result.begin();
			end = result.end();
			ZoneState zs;
			for(; cur != end; cur++) {
				zs.port = cur->port;
				zs.up = false;
				zs.starts = 0;
				_log(WORLD__LAUNCH_TRACE, "%s: Loaded zone '%s' on port %d", m_name.c_str(), cur->name.c_str(), zs.port);
				m_states[cur->name] = zs;
			}


void LauncherLink::BootZone(const char *short_name, uint16 port) {
	ZoneState zs;
	zs.port = port;
	zs.up = false;
	zs.starts = 0;
	_log(WORLD__LAUNCH_TRACE, "%s: Loaded zone '%s' on port %d", m_name.c_str(), short_name, zs.port);
	m_states[short_name] = zs;
	
	StartZone(short_name);
}


void LauncherLink::BootDynamics(uint8 new_count) {
	if(m_dynamicCount == new_count)
		return;
	
	ZoneState zs;
	if(m_dynamicCount < new_count) {
		//we are booting more dynamics.
		
		zs.port = 0;
		zs.up = false;
		zs.starts = 0;
		
		int r;
		char nbuf[20];
		uint8 index;
		//"for each zone we need to boot"
		for(r = m_dynamicCount; r < new_count; r++) {
			//find an idle ID
			for(index = m_dynamicCount+1; index < 255; index++) {
				sprintf(nbuf, "dynamic_%02d", index);
				if(m_states.find(nbuf) != m_states.end())
					continue;
				m_states[nbuf] = zs;
				StartZone(nbuf);
				break;
			}
		}
		m_dynamicCount = new_count;
	} else if(new_count == 0) {
		//kill all zones...
		std::map<std::string, ZoneState>::iterator cur, end;
		cur = m_states.begin();
		end = m_states.end();
		for(; cur != end; cur++) {
			StopZone(cur->first.c_str());
		}
	} else {
		//need to get rid of some zones...
		
		//quick and dirty way to do this.. should do better (like looking for idle zones)
		int found = 0;
		std::map<std::string, ZoneState>::iterator cur, end;
		cur = m_states.begin();
		end = m_states.end();
		for(; cur != end; cur++) {
			if(cur->first.find("dynamic_") == 0) {
				if(found >= new_count) {
					//this zone exceeds the number of allowed booted zones.
					StopZone(cur->first.c_str());
				} else {
					found++;
				}
			}
		}
		
		m_dynamicCount = new_count;
	}
	
}

LauncherLink.h
Code:
	inline bool			HasName() const		{ return(m_name.length() > 0); }
	inline int32		GetIP() const		{ return tcpc->GetrIP(); }
	inline int16		GetPort() const		{ return tcpc->GetrPort(); }
	inline const char * GetName() const		{ return(m_name.c_str()); }
	inline int			CountZones() const  { return(m_states.size()); }
If any coders get a chance to look through this stuff. It doesn't seem like it would be too hard to either add a new setting in the config xml file on the world server that lets you set ports for all zone server names or to just allow the world server to use the port settings in the config files from the xml in the world as well as in any launchers that connect to it when deciding which ports to use to create static or dynamic zones in on each launcher. As it is now, it seems that the port settings any other zone servers besides the one that the world is running on are completely pointless. But, what do I know about how difficult this would be?
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote