omcl 0.0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25088691d72a09c9f553aeaa15c809e75886fd91
4
+ data.tar.gz: 9601270f138f743550cd2566447393e3663f6121
5
+ SHA512:
6
+ metadata.gz: 17ddb913b78dcf2913c119177f5c24d5ad90d5959784af0b9b747aee085c6f200d0d964fc7e9dfe66aef580c0c12296e7ad710ac421038c326a1dbdd41c1ecf5
7
+ data.tar.gz: 6ac00673dd4edcb82aa1046bccd86aae83d5afef12a1de72ff3255574420a09ad4d771e299db1b87243cc5423dbc80cd36a7d2965addaef0ed072c9422281d1d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nickolay02@inbox.ru. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby "2.4.0"
4
+
5
+ # Specify your gem's dependencies in omcl.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nickolay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # OMCL
2
+ Open-Source Minecraft Launcher for *nixes
3
+
4
+ ## Installation
5
+
6
+ 1. Install ruby (if you already have it - skip this step)
7
+ 2. Install OMCL: `$ gem install omcl`
8
+
9
+ ## Usage
10
+ Version list: `omcl versions`
11
+ Install game: `omcl versions get <game version> <instance name>`
12
+ Run game: `omcl run <instance name>`
13
+
14
+ ## ToDo
15
+ 1. Implement instance-version changer
16
+ 2. Implement instance renamer
17
+ 3. Refactor code
18
+
19
+ ## License
20
+
21
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
22
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omcl"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env ruby
2
+ require "omcl"
3
+
4
+ require "fileutils"
5
+ require "optparse"
6
+
7
+ OMCL.load_conf
8
+ $options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: example.rb [options]"
11
+
12
+ opts.on("-aNAME", "--auth=NAME", "Use given profile") do |arg|
13
+ $options[:auth] = arg
14
+ end
15
+
16
+ opts.on("-h", "--help", "Prints this help") do
17
+ puts opts
18
+ exit
19
+ end
20
+ end.parse!
21
+
22
+ # ------
23
+ # |Auth|
24
+ # ------
25
+
26
+ $authed = false
27
+ if $options[:auth]
28
+ dat = $profiles[$options[:auth]]
29
+ auth = $auth[dat.auth]
30
+ if auth.type == :online
31
+ $type = auth.type
32
+ $state = OMCL::Auth.authenticate(auth.url, dat.user, dat.pass).body.to_s
33
+ $state = JSON.load $state
34
+ $access_token = $state["accessToken"]
35
+ $uid = $state["selectedProfile"]["id"]
36
+ $username = $state["selectedProfile"]["name"]
37
+ RG::Log.write "Successfully authenticated for #{$username}!"
38
+ else
39
+ $access_token = auth.token
40
+ end
41
+ $authed = true
42
+ end
43
+
44
+ # ----------
45
+ # |Commands|
46
+ # ----------
47
+
48
+ case ARGV[0].downcase
49
+ when "versions"
50
+ # Version-Manager
51
+ data = HTTP.get "https://launchermeta.mojang.com/mc/game/version_manifest.json"
52
+ data = JSON.load data
53
+ $versions = {}
54
+ data["versions"].each do |v|
55
+ $versions[v["id"]] = v["url"]
56
+ end
57
+ case ARGV[1].downcase
58
+ when nil
59
+ # Lister
60
+ puts "Latest release: #{data["latest"]["release"]}\nLatest snapshot: #{data["latest"]["snapshot"]}"
61
+ data["versions"].reverse.each do |v|
62
+ puts "\nID: #{v["id"]}\nType: #{v["type"]}\n"
63
+ end
64
+
65
+ when "get"
66
+ # Getter
67
+ if ARGV[2].downcase == nil
68
+ RG::Log.crash "Version name is not set!"
69
+ end
70
+ if ARGV[3].downcase == nil
71
+ RG::Log.crash "Instance name is not set!"
72
+ end
73
+ RG::Log.write "Loading JSON data..."
74
+ unless $versions.include? ARGV[2].downcase
75
+ RG::Log.err "Invalid version!"
76
+ end
77
+ $ver_data_raw = HTTP.get $versions[ARGV[2]]
78
+ $ver_data = JSON.load $ver_data_raw.body.to_s
79
+ RG::Log.write "Installing minecraft..."
80
+ if Dir.exist? File.expand_path "~/omcl/#{ARGV[3].downcase}"
81
+ print "Instance #{ARGV[3]} already exists. Rewrite? [y/N] "
82
+ answer = STDIN.gets[0].downcase
83
+ if answer == "y"
84
+ FileUtils.remove_dir File.expand_path "~/omcl/#{ARGV[3].downcase}"
85
+ else
86
+ exit
87
+ end
88
+ end
89
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}"
90
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}/bin"
91
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}/bin/natives"
92
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}/assets"
93
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}/assets/indexes"
94
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}/assets/objects"
95
+ Dir.mkdir File.expand_path "~/omcl/#{ARGV[3].downcase}/libraries"
96
+ jar_data = HTTP.get $ver_data["downloads"]["client"]["url"]
97
+ File.open(File.expand_path("~/omcl/#{ARGV[3].downcase}/bin/#{ARGV[2]}.json"), 'w') do |file|
98
+ file.write $ver_data_raw
99
+ end
100
+ File.open(File.expand_path("~/omcl/#{ARGV[3].downcase}/bin/#{ARGV[2]}.jar"), 'w') do |file|
101
+ file.write jar_data
102
+ end
103
+ RG::Log.write "Finished downloading minecraft.jar"
104
+
105
+ thrs = []
106
+ $ver_data["libraries"].each do |lib|
107
+ thrs << Thread.new do
108
+ unless lib.include? "extract"
109
+ dat = HTTP.get(lib["downloads"]["artifact"]["url"]).body.to_s
110
+ path = File.expand_path("~/omcl/#{ARGV[3].downcase}/libraries/" +
111
+ lib["downloads"]["artifact"]["path"])
112
+ FileUtils.mkpath File.dirname path
113
+ File.open(path, 'w') do |file|
114
+ file.write dat
115
+ end
116
+ RG::Log.write "Finished downloading #{path}"
117
+ else
118
+ if lib["downloads"]["classifiers"]["natives-linux"]
119
+ url = lib["downloads"]["classifiers"]["natives-linux"]["url"]
120
+ path = File.expand_path("~/omcl/#{ARGV[3].downcase}/bin/natives/" +
121
+ (File.basename lib["downloads"]["classifiers"]["natives-linux"]["path"]))
122
+ dat = HTTP.get(url).body.to_s
123
+ File.open(path, 'w') do |file|
124
+ file.write dat
125
+ end
126
+ RG::Log.write "Finished downloading native #{path}"
127
+ end
128
+ end
129
+ end
130
+ sleep 0.01
131
+ end
132
+ thrs.each do |t| t.join end
133
+
134
+ ["", "_util"].each do |a|
135
+ pth = File.expand_path "~/omcl/#{ARGV[2].downcase}/libraries/org/lwjgl/lwjgl/lwjgl#{a}/*"
136
+ x = Dir[pth]
137
+ x = x.map do |o| /.*\/(\d\.\d\.\d).*/.match(o)[1] end
138
+ x = x.map do |o| Gem::Version.new o end
139
+ $m = x.max.to_s
140
+ x = Dir[pth]
141
+ x.each do |o|
142
+ unless o[/#{File.dirname pth}\/#{$m.gsub(/\./, "\\.")}.*/]
143
+ FileUtils.remove_dir o
144
+ end
145
+ end
146
+ end
147
+
148
+ RG::Log.write "Finished 'patching' lwjgl"
149
+
150
+ lwjgled = false
151
+ Dir[File.expand_path "#{File.expand_path "~/omcl/#{ARGV[3].downcase}/bin/natives"}/*.jar"].each do |f|
152
+ if ((f.include? $m[0,$m.length-2]) and (f.include? "lwjgl") and !lwjgled) or !(f.include? "lwjgl")
153
+ if f.include? "lwjgl"
154
+ lwjgled = true
155
+ end
156
+ `unzip -d #{File.expand_path "~/omcl/#{ARGV[3].downcase}/bin/natives"} #{f}`
157
+ if File.exist? File.expand_path "~/omcl/#{ARGV[3].downcase}/bin/natives/META-INF"
158
+ FileUtils.remove_dir File.expand_path "~/omcl/#{ARGV[3].downcase}/bin/natives/META-INF"
159
+ end
160
+ RG::Log.write "Finished unpacking native #{f}"
161
+ end
162
+ end
163
+ RG::Log.write "Finished unpacking natives"
164
+
165
+ aindex = HTTP.get $ver_data["assetIndex"]["url"]
166
+ aindex_data = JSON.load aindex
167
+ File.open(File.expand_path("~/omcl/#{ARGV[2].downcase}/assets/indexes/#{$ver_data["assetIndex"]["id"]}.json"), 'w') do |file|
168
+ file.write aindex
169
+ end
170
+ RG::Log.write "Finished downloading asset index"
171
+
172
+ thrs = []
173
+ if $ver_data["assetIndex"]["id"] == "legacy"
174
+ aindex_data["objects"].each do |name, content|
175
+ thrs << Thread.new do
176
+ path = File.expand_path "~/omcl/#{ARGV[2]}/assets/objects/#{name}"
177
+ FileUtils.mkdir_p File.dirname path
178
+ dat = HTTP.get "http://resources.download.minecraft.net/#{content["hash"][0,2]}/#{content["hash"]}"
179
+ File.open(path, 'w') do |file|
180
+ file.write dat
181
+ end
182
+ RG::Log.write "Finished downloading asset #{path}"
183
+ end
184
+ sleep 0.01
185
+ end
186
+ else
187
+ aindex_data["objects"].each do |_, content|
188
+ thrs << Thread.new do
189
+ path = File.expand_path "~/omcl/#{ARGV[2]}/assets/objects/#{content["hash"][0,2]}/#{content["hash"]}"
190
+ FileUtils.mkdir_p File.dirname path
191
+ dat = HTTP.get "http://resources.download.minecraft.net/#{content["hash"][0,2]}/#{content["hash"]}"
192
+ File.open(path, 'w') do |file|
193
+ file.write dat
194
+ end
195
+ RG::Log.write "Finished downloading asset #{path}"
196
+ end
197
+ sleep 0.01
198
+ end
199
+ end
200
+ thrs.each do |t| t.join end
201
+ RG::Log.write "Finished downloading assets!"
202
+
203
+ File.open(File.expand_path("~/omcl/#{ARGV[3].downcase}/conf.yml"), 'w') do |file|
204
+ dat = {
205
+ "version" => ARGV[2].downcase,
206
+ "mainclass" => $ver_data["mainClass"],
207
+ "assets" => $ver_data["assets"],
208
+ "type" => $ver_data["type"],
209
+ "java_options" => ""
210
+ }
211
+ file.write YAML.dump dat
212
+ end
213
+ RG::Log.write "Finished writing launcher config"
214
+ end
215
+
216
+ when "run"
217
+ # Runner
218
+ unless ARGV[1].downcase
219
+ RG::Log.crash "No instance name!"
220
+ end
221
+ unless File.exist? File.expand_path "~/omcl/#{ARGV[1].downcase}"
222
+ RG::Log.crash "Given instance does not exist!"
223
+ end
224
+ OMCL.launchMC(ARGV[1].downcase, File.expand_path("~/omcl/#{ARGV[1].downcase}"))
225
+ end
226
+
227
+ # YAY: "mainClass": "net.minecraft.client.main.Main",
@@ -0,0 +1,62 @@
1
+ require "rubygoods"
2
+
3
+ require "yaml"
4
+ require "http"
5
+
6
+ require "omcl/version"
7
+ require "omcl/auth"
8
+ require "omcl/dat"
9
+ require "omcl/launch"
10
+
11
+ class NilClass; def downcase; nil; end; end;
12
+
13
+ module OMCL
14
+ def self.load_conf
15
+ dirname = File.expand_path "~/omcl/"
16
+ unless Dir.exists? dirname
17
+ RG::Log.warn "No working directory detected! Creating #{dirname}..."
18
+ Dir.mkdir dirname
19
+ end
20
+
21
+ cfgfilename = File.expand_path "~/omcl/conf.yml"
22
+ unless File.exist? cfgfilename
23
+ RG::Log.warn "No config file detected! Creating #{cfgfilename}..."
24
+ File.open(cfgfilename, 'w') do |file|
25
+ file.write <<-YAML
26
+ # Basic auth-server entry
27
+ auth.serv.mojang: https://authserver.mojang.com/authenticate
28
+
29
+ # Sample mojang-account entry
30
+ account.mojang.handicraftsman:
31
+ user: nickolay02@inbox.ru
32
+ pass: <hidden>
33
+ YAML
34
+ end
35
+ end
36
+
37
+ $conf = YAML.load_file cfgfilename
38
+ $auth = {}
39
+ $profiles = {}
40
+
41
+ $conf.each do |name, content|
42
+ if m = /^auth\.(.+)\.(.+)/.match(name)
43
+ case m[1].squish
44
+ when "serv"
45
+ $type = :online
46
+ when "token"
47
+ $type = :offline
48
+ end
49
+ $auth[m[2]] = OMCL::AuthService.new $type, content
50
+ elsif m = /account\.(.+)\.(.+)/.match(name)
51
+ if $auth.include? m[1]
52
+ auth = m[1]
53
+ user = content["user"]
54
+ pass = content["pass"]
55
+ $profiles["#{m[1]}.#{m[2]}"] = OMCL::Account.new auth, user, pass
56
+ else
57
+ RG::Log.err "Unknown auth service: #{m[1]}"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end