indexing
	description: "LinkedList der Battle.Net-Server, zur internen Darstellung"
	author: "Daniel"
	date: "$Date: 2004/05/05 23:31:53 $"
	revision: "$Revision: 1.6 $"

class
	BNET_SERVER_LIST

inherit
	LINKED_LIST[BNET_SERVER]

	APPLICATION_IDS
		export
			{NONE} all
		undefine
			is_equal,
			copy
		end
	
create
	make_with_values
	
feature {NONE} -- Initialization

	make_with_values(ver, def :INTEGER) is
			-- Initialize `Current'.
		require
			pos_version: ver >= 0
			pos_default: def >= 0
			default_range: def < 100
		do
			make
			
			string_version := ver
			default_server := def

		ensure	
			default_set: default_server = def
			version_set: equal(string_version, ver)
		end

feature -- Access

	get_version: INTEGER is
			-- get string version
		do
			Result := string_version
		end
			
	get_default: INTEGER is
			-- get string version
		do
			Result := default_server
		end		

feature -- Status setting

	set_version(ver: INTEGER) is
			-- set Version
		require
			pos_version: ver >= 0
		do
			string_version := ver
		ensure	
			version_set: equal(string_version, ver)
		end
		
	set_default(def: INTEGER) is
			-- set default server
		require
			pos_default: def >= 0
			default_range: def < 100
		do
			default_server := def
		ensure	
			default_set: default_server = def
		end

feature -- Element change

	append_server(a_name: STRING; a_zone: INTEGER; an_url: STRING) is
			-- Creates new BNET_SERVER and appends it to the list
		require
			name_not_void: a_name /= void
			url_not_void: an_url /= Void
			lower_range: a_zone > -13
			upper_range: a_zone < 13
		local
			elem	: BNET_SERVER
		do
			create elem.make_with_values(a_name, a_zone, an_url)
			extend(elem)
		end
		
feature -- Conversion

	to_bnet_string: STRING is
			-- Converts to bnet-structured string.
			-- Returns Void on unknown `string_version'
		local
			i	: INTEGER
		do
			Result := Void
			
			if string_version = 1001 then				
				create Result.make_empty
				Result.append_integer(string_version)
				Result.append_string("%U")
				if default_server < 10 then
					Result.append_string("0")
					Result.append_integer(default_server)
				else
					Result.append_integer(default_server)
				end
				
				from
					i := 1
				invariant
					count - i >= -1
				until
					i > count
				loop
					Result.append_string((Current @ i).to_bnet_string)
					
					i := i + 1
				end
				Result.append_string("%U")
			end
		end

feature -- Basic operations

	parse_bnet_string(ll: LINKED_LIST[STRING]; game_id: INTEGER): BOOLEAN is
			-- Parse String-array to Structure
		local
			i	: INTEGER
		do
			Result := true;
			if ll.count > 2 and (ll @ 1).is_integer and (ll @ 2).is_integer then
				string_version := (ll @ 1).to_integer
				if game_id = Idb_war3 then
					default_server := (ll @ 2).to_integer + 1
				else
					default_server := (ll @ 2).to_integer
				end
				
				from 
					i := 3
					wipe_out
				until
					i+2 > ll.count
				loop
					if (ll @ (i+1)).is_integer then
						append_server(ll @ (i+2), (ll @ (i+1)).to_integer, ll @ i)
					else
						Result := false;
					end
					i := i + 3
				end
			else
				Result := false;
			end
		end

feature {NONE} -- Implementation

	string_version, default_server	: INTEGER

invariant
	pos_version: string_version >= 0
	pos_default: default_server >= 0
	default_range: default_server < 100

end -- class BNET_SERVER_LIST
