Class: LibSL::NetworkManager
- Inherits:
-
Object
- Object
- LibSL::NetworkManager
- Defined in:
- lib/network.rb
Constant Summary collapse
- GRIDS =
{ :agni => "https://login.agni.lindenlab.com/cgi-bin/login.cgi", :aditi => "https://login.aditi.lindenlab.com/cgi-bin/login.cgi" }
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#circuit_code ⇒ Object
readonly
Returns the value of attribute circuit_code.
-
#client ⇒ Object
Returns the value of attribute client.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#message_of_the_day ⇒ Object
readonly
Returns the value of attribute message_of_the_day.
-
#ready_handler ⇒ Object
readonly
Returns the value of attribute ready_handler.
-
#secure_session_id ⇒ Object
readonly
Returns the value of attribute secure_session_id.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#sims ⇒ Object
Returns the value of attribute sims.
Instance Method Summary collapse
-
#activate_simulator(sim) ⇒ Object
Activates a simulator as the main simulator.
-
#connect_to_simulator(ip, port) ⇒ Object
Connects to a simulator.
-
#initialize(client) ⇒ NetworkManager
constructor
Initialize the network manager.
-
#login(first, last, pass, start = "last", grid = :agni) ⇒ Object
Login to the grid.
-
#logout ⇒ Object
Logout the client and disconnect from each connected simulator.
-
#send_packet(packet, reliable = false, sim = nil) ⇒ Object
Send a packet to a specific simulator.
- #setup_handlers ⇒ Object
Constructor Details
#initialize(client) ⇒ NetworkManager
Initialize the network manager
195 196 197 198 |
# File 'lib/network.rb', line 195 def initialize(client) @client = client @sims = [] end |
Instance Attribute Details
#agent_id ⇒ Object (readonly)
Returns the value of attribute agent_id.
189 190 191 |
# File 'lib/network.rb', line 189 def agent_id @agent_id end |
#circuit_code ⇒ Object (readonly)
Returns the value of attribute circuit_code.
189 190 191 |
# File 'lib/network.rb', line 189 def circuit_code @circuit_code end |
#client ⇒ Object
Returns the value of attribute client.
188 189 190 |
# File 'lib/network.rb', line 188 def client @client end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
189 190 191 |
# File 'lib/network.rb', line 189 def first_name @first_name end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
189 190 191 |
# File 'lib/network.rb', line 189 def last_name @last_name end |
#message_of_the_day ⇒ Object (readonly)
Returns the value of attribute message_of_the_day.
189 190 191 |
# File 'lib/network.rb', line 189 def @message_of_the_day end |
#ready_handler ⇒ Object (readonly)
Returns the value of attribute ready_handler.
189 190 191 |
# File 'lib/network.rb', line 189 def ready_handler @ready_handler end |
#secure_session_id ⇒ Object (readonly)
Returns the value of attribute secure_session_id.
189 190 191 |
# File 'lib/network.rb', line 189 def secure_session_id @secure_session_id end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
189 190 191 |
# File 'lib/network.rb', line 189 def session_id @session_id end |
#sims ⇒ Object
Returns the value of attribute sims.
188 189 190 |
# File 'lib/network.rb', line 188 def sims @sims end |
Instance Method Details
#activate_simulator(sim) ⇒ Object
Activates a simulator as the main simulator
314 315 316 317 318 319 320 321 322 323 |
# File 'lib/network.rb', line 314 def activate_simulator(sim) return if @active_sim == sim @sims << sim unless @sims.include? sim if sim.connected? AgentManager.move_to_sim sim else sim.connect end @active_sim = sim end |
#connect_to_simulator(ip, port) ⇒ Object
Connects to a simulator
302 303 304 305 306 307 308 309 310 |
# File 'lib/network.rb', line 302 def connect_to_simulator(ip, port) sim = Simulator.new(@client, ip, port, @circuit_code, @session_id, @agent_id) unless @sims.include? sim @sims << sim @sims.last.connect @active_sim = @sims.last end sim end |
#login(first, last, pass, start = "last", grid = :agni) ⇒ Object
Login to the grid
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/network.rb', line 206 def login(first, last, pass, start="last", grid=:agni) client = XMLRPC::Client.new2(GRIDS[grid]) client.http_header_extra = {"Content-Type" => "text/xml"} os = "Win" os = "Mac" if RUBY_PLATFORM.downcase.include?("darwin") os = "Lin" if RUBY_PLATFORM.downcase.include?("linux") res = client.call("login_to_simulator", { "first" => first, "last" => last, "passwd" => "$1$" + Digest::MD5.hexdigest(pass), "start" => start, "channel" => "libsl", "version" => "1.0", "platform" => os, "mac" => 6.times.map{sprintf("%02x", rand(255))}.join(":"), "options" => [], "id0" => LLUUID.new.to_s, "agree_to_tos" => "true", "read_critical" => "true", "viewer_digest" => "00000000-0000-0000-0000-000000000000"}) unless res["login"] == "true" case res["reason"] when "presence" then raise SessionNotTimedoutError, res["message"] when "update" then raise RequiredUpdateError, res["message"] when "optional" then raise OptionalUpdateError, res["message"] when "key" then raise LoginFailureError, res["message"] when "ban" then raise AccountBannedError, res["message"] else raise LoginError, res["message"] end end @circuit_code = LLU32.new(res["circuit_code"]) @session_id = LLUUID.new res["session_id"] @secure_session_id = LLUUID.new res["secure_session_id"] @agent_id = LLUUID.new res["agent_id"] @first_name = res["first_name"] @last_name = res["last_name"] @message_of_the_day = res["message"] setup_handlers connect_to_simulator res["sim_ip"], res["sim_port"] end |
#logout ⇒ Object
Logout the client and disconnect from each connected simulator
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/network.rb', line 252 def logout EventManager::register_handler(EventHandler.new(Proc.new do |type, sim| sim.client.network_manager.sims.delete sim end, :disconnected)) EventManager::register_handler(EventHandler.new(Proc.new do |type, packet, sim| sim.client.network_manager.sims.each { |sim| sim.disconnect } EventManager::fire_event(:logout) end, :LogoutReplyPacket_Received)) packet = LogoutRequestPacket.new({ :AgentData => { :AgentID => @agent_id, :SessionID => @session_id } }) send_packet packet, true end |
#send_packet(packet, reliable = false, sim = nil) ⇒ Object
Send a packet to a specific simulator
329 330 331 332 |
# File 'lib/network.rb', line 329 def send_packet(packet, reliable=false, sim=nil) sim = @active_sim if sim.nil? @active_sim.send_packet packet, reliable end |
#setup_handlers ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/network.rb', line 272 def setup_handlers() # PacketAck handler EventManager::register_handler(EventHandler.new(Proc.new do |type, packet, sim| packet.Packets.each{|b| sim.packets_sent_reliably.delete(b.ID.value)} end, :PacketAckPacket_Received)) # Handle acks on received packets EventManager::register_handler(EventHandler.new(Proc.new do |type, packet, sim| packet.acks.each{|ack| sim.packets_sent_reliably.delete(ack)} end, :PacketReceived)) # Ready handler @ready_handler = EventManager::register_handler(EventHandler.new(Proc.new do |type, sim| EventManager::remove_handler(sim.client.network_manager.ready_handler) EventManager::fire_event(:ready, sim.client) end, :movement_complete)) # Teleport Finish handler EventManager::register_handler(EventHandler.new(Proc.new do |type, packet, sim| @active_sim.disconnect sim = connect_to_simulator(packet.Info.SimIP.ip, packet.Info.SimPort.port) activate_simulator(sim) end, :TeleportFinishPacket_Received)) # Teleport Local handler EventManager::register_handler(EventHandler.new(Proc.new do |type, packet, sim| @client.agent_manager.position = packet.Info.Position @client.agent_manager.look_at = packet.Info.LookAt end, :TeleportLocalPacket_Received)) end |