--
Aaj781/T3gaLhbVyDpX
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Tue, 2006-03-21 at 02:48 +0900, James Edward Gray II wrote:
> On Mar 20, 2006, at 11:41 AM, Ross Bamford wrote:
> 
> > Anyway, the problem with that was that, since Sector handles most  
> > of the
> > output (and will probably just call puts) the output all goes to the
> > server's terminal :(
> 
> Could you have the client pass you $stdout and $stdin, then set them  
> on the server?

I had a go with this, but couldn't get it to work. However, in the
process I figured out what I was doing wrong and got it working (I
think), so thanks :)

Two disclaimers: This is only basic, and untested, and I've not used DRb
until this so it's probably not as well put together as it might be...

-- 
Ross Bamford - rosco / roscopeco.REMOVE.co.uk

--
Aaj781/T3gaLhbVyDpX
Content-Disposition: attachment; filename=smclient.rb
Content-Type: text/plain; name=smclient.rb; charset=utf-8
Content-Transfer-Encoding: 7bit

require 'singleton'
require 'drb/drb'
require 'main'

module SpaceMerchant
  class Player
    include DRb::DRbUndumped
    
    def read
      gets
    end

    def write(*args)
      puts(*args)
    end
  end
end

puts
puts "Welcome to Space Merchant #{SpaceMerchant::VERSION}, " + 
     "the Ruby Quiz game!"
puts

print "What would you like to be called, pilot?  "
while true
  name  ets.chomp
  
  if name /\S/
    player  paceMerchant::Player.instance
    player[:name]  ame
    puts "#{player[:name]} it is."
    puts
    
    puts "May you find fame and fortune here in the Ruby Galaxy..."
    puts
    
    break
  else
    print "Please enter a name:  "
  end
end

SERVER_URI  ARGV.empty? ? ARGV.join('+') : 'druby://localhost:8787'
DRb.start_service

front  RbObject.new_with_uri(SERVER_URI)
galaxy  ront.galaxy

player[:credits]  000
player[:location]  alaxy.starting_location
front.register(DRbObject.new(player))

begin
  catch(:quit) do  # use throw(:quit) to exit the game
    # primary event loop
    loop { player[:location].handle_event(DRbObject.new(player)) } #current_server.uri)) }
  end
ensure
  front.quit(DRbObject.new(player))
end


--
Aaj781/T3gaLhbVyDpX
Content-Disposition: attachment; filename=smserver.rb
Content-Type: text/plain; name=smserver.rb; charset=utf-8
Content-Transfer-Encoding: 7bit

require 'singleton'
require 'drb/drb'
require 'galaxy'
require 'sector'
require 'planet'
require 'station'

$SAFE  

module Kernel
  alias :lputs :puts
  alias :lgets :gets

  def puts(*args)
    if player  hread.current[:player]
      player.write(*args)
    else
      lputs(*args)
    end
  end

  def gets
    if player  hread.current[:player]
      player.read
    else
      lgets
    end
  end
end
    
module SpaceMerchant
  class Controller
    include Singleton

    def initialize
      @players  ]
    end

    def register(player)
      Thread.current[:player]  layer     
      @players << player      
      lputs "Registered #{player[:name]} (on #{player.__drburi})"
    end

    def quit(player)
      Thread.current[:player]  il
      @players.delete(player)
      lputs "#{player[:name]} has quit"
    end

    def players
      @players
    end

    def galaxy
      Galaxy.instance
    end
  end

  [Galaxy, Sector, Station, Planet, Controller].each do |clz|
    clz.class_eval { include DRb::DRbUndumped }
  end
end

DRb.start_service('druby://localhost:8787',SpaceMerchant::Controller.instance)
DRb.thread.join


--
Aaj781/T3gaLhbVyDpX--