Module: OMCL

Defined in:
lib/omcl.rb,
lib/omcl/dat.rb,
lib/omcl/auth.rb,
lib/omcl/launch.rb,
lib/omcl/version.rb

Defined Under Namespace

Modules: Auth Classes: Account, AuthService

Constant Summary collapse

VERSION =
"0.0.0.1"

Class Method Summary collapse

Class Method Details

.launchMC(name, path) ⇒ Object



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
# File 'lib/omcl/launch.rb', line 2

def self.launchMC(name, path)
  unless $authed
    RG::Log.crash "Did not authenticate!"
  end
  dat = YAML.load_file "#{path}/conf.yml"
  libs = Dir[path+"/libraries/**/*.*"]
  libs = libs.join ":"
  libs = libs + ":#{path}/bin/#{name}.jar"

  p dat

  min_mem = (dat["min_mem"] or "768M")
  max_mem = (dat["max_mem"] or "1G")
  main_class = (dat["mainclass"] or "net.minecraft.client.main.Main")

  opts = (dat["java_options"] or "")

  java_opts = <<-DATA
-server
-d32
-Xms#{min_mem}
-Xmx#{max_mem}
-Djava.library.path=#{path}/bin/natives/
-cp #{libs}
#{main_class}
#{opts}
DATA
  java_opts = java_opts.gsub(/\n/, " ")

  RG::Log.write "Starting..."

  cmd = "java #{java_opts} --username #{$username} --version #{name} --gameDir #{path} --assetsDir #{path}/assets --assetIndex #{dat["assets"].squish} --uuid #{$uid} --accessToken #{$access_token} --userType legacy --versionType #{dat["type"]} --nativeLauncherVersion 307"
  RG::Log.write "Launch command: " + cmd
  exec cmd
end

.load_confObject



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
# File 'lib/omcl.rb', line 14

def self.load_conf
  dirname = File.expand_path "~/omcl/"
  unless Dir.exists? dirname
    RG::Log.warn "No working directory detected! Creating #{dirname}..."
    Dir.mkdir dirname
  end

  cfgfilename = File.expand_path "~/omcl/conf.yml"
  unless File.exist? cfgfilename
    RG::Log.warn "No config file detected! Creating #{cfgfilename}..."
    File.open(cfgfilename, 'w') do |file| 
      file.write <<-YAML
# Basic auth-server entry
auth.serv.mojang: https://authserver.mojang.com/authenticate

# Sample mojang-account entry
account.mojang.handicraftsman:
user: [email protected]
pass: <hidden>
YAML
    end
  end

  $conf     = YAML.load_file cfgfilename
  $auth     = {}
  $profiles = {}

  $conf.each do |name, content|
    if m = /^auth\.(.+)\.(.+)/.match(name)
      case m[1].squish
      when "serv"
        $type = :online
      when "token"
        $type = :offline
      end
      $auth[m[2]] = OMCL::AuthService.new $type, content
    elsif m = /account\.(.+)\.(.+)/.match(name)
      if $auth.include? m[1]
        auth = m[1]
        user = content["user"]
        pass = content["pass"]
        $profiles["#{m[1]}.#{m[2]}"] = OMCL::Account.new auth, user, pass
      else
        RG::Log.err "Unknown auth service: #{m[1]}"
      end
    end
  end 
end