module OMCL

Constants

VERSION

Public Class Methods

launchMC(name, path) click to toggle source
# 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_conf() click to toggle source
# 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: nickolay02@inbox.ru
  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