aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/share/ruby/gridserv.rb
blob: 03cb4d18c67d4c65e9d346d2f4bd092382a4c1c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require "webrick"
require "xmlrpc/server"
require 'xmlrpc/client'
require 'pp'
require 'config.rb'

#
# Dummy grid server
#
#

class SimServlet < WEBrick::HTTPServlet::AbstractServlet
  # does actually nothing
  def do_POST(req, res)
    STDERR.print "----\n"
  end
end

$SimUUID = ""

s = XMLRPC::WEBrickServlet.new
s.add_handler("map_block") do |param|
  # does just enough to login.. if you try using "map" you will cause the exception
  # and hang the client
  responseData = Hash.new
  responseData["sim-profiles"] =  [ ]
  responseData
end

s.add_handler("simulator_login") do |param|
  sc = SimConfig.new
  responseData = Hash.new
  STDERR.print "simulator login: " + param.inspect + "\n"
  $SimUUID = param["UUID"]

  responseData["UUID"] = param["UUID"]
  responseData["region_locx"] = sc.cfgSimX
  responseData["region_locy"] = sc.cfgSimY
  responseData["regionname"] = "DalienLand"
  responseData["estate_id"] = "1"
  responseData["neighbours"] = [ ]
  responseData["sim_ip"] = sc.cfgSimIP
  responseData["sim_port"] = sc.cfgSimPort
  responseData["asset_url"] = sc.cfgAssetServerUrl
  responseData["asset_sendkey"] = ""
  responseData["asset_recvkey"] = ""
  responseData["user_url"] = sc.cfgUserServerUrl
  responseData["user_sendkey"] = ""
  responseData["user_recvkey"] = ""
  responseData["authkey"] = ""

  responseData

end

s.set_default_handler do |name, *args|
  STDERR.print "Unknown method #{name}, #{args.inspect}\n\n"
  raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
                                   " or wrong number of parameters!")
end

httpserver = WEBrick::HTTPServer.new(:Port => 8001)    
httpserver.mount("/", s)
httpserver.mount("/sims", SimServlet)

trap(:INT) { httpserver.shutdown }   # use 1 instead of "HUP" on Windows
httpserver.start