indexing description: "[ Event that is sent back in response to a EM_NET_SERVER_DISCOVERY from a detected server to the client. ]" date: "$Date$" revision: "$Revision$" class EM_NET_SERVER_DISCOVERY_RESPONSE inherit EM_NET_EVENT_OBJECT redefine out, make_set_type end create {EM_NET_OBJECT_TYPES} make_set_type feature {NONE} -- Initialisation make_set_type (a_type_id: INTEGER) is -- Set `create_type_id' to `a_type_id'. do Precursor {EM_NET_EVENT_OBJECT} (a_type_id) game_name := "" server_name := "" end feature -- Serialization serialize (a_serializer: EM_NET_SERIALIZER) is -- Serialize to the given stream using `a_serializer'. require else server_name_not_void: server_name /= Void game_name_not_void: game_name /= Void do a_serializer.put_integer (game_name.count) a_serializer.put_string (game_name) a_serializer.put_integer (server_name.count) a_serializer.put_string (server_name) a_serializer.put_integer (ip) a_serializer.put_integer (port) end serialization_byte_count: INTEGER is -- Count of bytes needed for a successful serialization require else server_name_not_void: server_name /= Void game_name_not_void: game_name /= Void do Result := 12 + server_name.count + game_name.count end unserialize (an_unserializer: EM_NET_UNSERIALIZER) is -- Unserialize from a given stream using `an_unserializer'. local count: INTEGER do an_unserializer.read_integer count := an_unserializer.last_integer if count = 0 then game_name := "" else an_unserializer.read_string (count) game_name := an_unserializer.last_string end an_unserializer.read_integer count := an_unserializer.last_integer if count = 0 then game_name := "" else an_unserializer.read_string (count) server_name := an_unserializer.last_string end an_unserializer.read_integer ip := an_unserializer.last_integer an_unserializer.read_integer port := an_unserializer.last_integer if port = 0 then set_ip (updating_connection.socket_address.host_ip) set_port (updating_connection.socket_address.port) end end feature -- Element change set_game_name(a_game_name: STRING) is -- Set `game_name' to `a_game_name'. require a_game_name_not_void: a_game_name /= Void do game_name := a_game_name ensure game_name_set: game_name = a_game_name end set_server_name(a_server_name: STRING) is -- Set `server_name' to `a_server_name'. require a_server_name_not_void: a_server_name /= Void do server_name := a_server_name ensure server_name_set: server_name = a_server_name end set_ip(an_ip: INTEGER) is -- Set `ip' to `an_ip'. do ip := an_ip ensure ip_set: ip = an_ip end set_port(a_port:INTEGER) is -- Set `port' to `a_port'. require a_correct_port: 0 < a_port and then a_port < 65536 do port := a_port ensure port_set: port = a_port end set_ping(a_ping: INTEGER) is -- Set `ping' to `a_ping'. require a_positive_ping: a_ping >=0 do ping := a_ping ensure ping_set: ping = a_ping end feature -- Information out: STRING is -- Textual output of the disconvery response do Result:= ping.out + " :: '" + server_name + "' :: '" + game_name + "' " + ip_string + ":" + port.out end ip_string: STRING is -- Textual form of the IP address do create Result.make_empty Result.append (ip.bit_shift_right (24).bit_and (255).out + ".") Result.append (ip.bit_shift_right (16).bit_and (255).out + ".") Result.append (ip.bit_shift_right (8).bit_and (255).out + ".") Result.append (ip.bit_and (255).out) end game_name: STRING -- Game name server_name: STRING -- Server name ip: INTEGER -- IP port: INTEGER -- Port ping: INTEGER -- Ping -- not serialized feature {NONE} -- Implementation invariant invariant_clause: True -- Your invariant here end