vikingio 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82673e848156299dbfd0d031352d52d872435620
4
+ data.tar.gz: cd4dc18085fe19a7794c01d002f0e2789ad84654
5
+ SHA512:
6
+ metadata.gz: 2f998edb0b94f5ac7fe632f4e2bfa07414e8cf21343aafcb89d1aa449c565b34c9b855adb62208c305a515db7616b286b819337dae8e9772ba1e31bcfc23ec12
7
+ data.tar.gz: 64bafd179627a05cadf58aff2da768a1891ff998977551bcb195f7e09359230e3661b88ef4cfa7251b86a8cab66895b4f5d42569fa9c5fe0b9c453ded7580606
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vikingio-cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Campbell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ Command Line Toolkit for VikingIO. Sign up at http://www.vikingio.com
2
+
3
+ Commands:
4
+
5
+ help -
6
+ login - Authenticate with VikingIO
7
+ logout - Clear your authentication credentials
8
+ create - Create a new VikingIO application
9
+ generate - Generate a skeleton VikingIO application
10
+ link - Link the current directory with an existing VikingIO application
11
+ unlink - Unlink the current directory with it's VikingIO application
12
+ deploy - Deploy your application
13
+ shutdown - Shutdown all production servers
14
+ run - Compile and run your application locally
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/vikingio ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # start up the CLI
5
+ require "vikingio/cli"
6
+ VikingIO::CLI.start(*ARGV)
data/dlls/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -0,0 +1,144 @@
1
+ module VikingIO
2
+ module CLI
3
+ module Client
4
+
5
+ BASE_PATH = "https://www.vikingio.com/api/"
6
+ BASE_BUILD_PATH = "http://build1.vikingio.com/"
7
+
8
+ def self.get_status(user_key, app_key)
9
+ uri = URI.join(BASE_PATH, "apps/status")
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ req = Net::HTTP::Get.new(uri.path)
12
+ req['x-vikingio-user-key'] = user_key
13
+ req['x-vikingio-app-key'] = app_key
14
+ resp = http.request(req)
15
+ return JSON.parse(resp.body)
16
+ end
17
+
18
+ def self.deploy_data(user_key, app_key, data_path)
19
+ uri = URI.join(BASE_BUILD_PATH, "deploy_data")
20
+
21
+ req = Net::HTTP::Post::Multipart.new uri.path, {"file" => UploadIO.new(data_path, "application/octet-stream")}
22
+ req['x-vikingio-user-key'] = user_key
23
+ req['x-vikingio-key'] = app_key
24
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
25
+ http.request(req)
26
+ end
27
+ end
28
+
29
+ def self.deploy_servers(user_key, app_key, server_path)
30
+ uri = URI.join(BASE_BUILD_PATH, "deploy_servers")
31
+
32
+ req = Net::HTTP::Post::Multipart.new uri.path, {"file" => UploadIO.new(server_path, "application/octet-stream")}
33
+ req['x-vikingio-user-key'] = user_key
34
+ req['x-vikingio-key'] = app_key
35
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
36
+ http.request(req)
37
+ end
38
+ end
39
+
40
+ def self.deploy_check(user_key, app_key)
41
+ uri = URI.join(BASE_BUILD_PATH, "deploy_check")
42
+ http = Net::HTTP.new(uri.host, uri.port)
43
+ req = Net::HTTP::Get.new(uri.path)
44
+ req['x-vikingio-user-key'] = user_key
45
+ req['x-vikingio-key'] = app_key
46
+ req['x-vikingio-nodefile'] = VikingIO::CLI.get_node_data.to_json
47
+ resp = http.request(req)
48
+ return resp.body
49
+ end
50
+
51
+ def self.deploy(user_key, app_key)
52
+ uri = URI.join(BASE_BUILD_PATH, "deploy")
53
+ http = Net::HTTP.new(uri.host, uri.port)
54
+ req = Net::HTTP::Get.new(uri.path)
55
+ req['x-vikingio-user-key'] = user_key
56
+ req['x-vikingio-key'] = app_key
57
+ req['x-vikingio-nodefile'] = VikingIO::CLI.get_node_data.to_json
58
+ resp = http.request(req)
59
+ return resp.body
60
+ end
61
+
62
+ def self.request_build_job(user_key, app_key)
63
+ uri = URI.join(BASE_BUILD_PATH, "start")
64
+
65
+ http = Net::HTTP.new(uri.host, uri.port)
66
+ req = Net::HTTP::Get.new(uri.path)
67
+ req['x-vikingio-user-key'] = user_key
68
+ req['x-vikingio-key'] = app_key
69
+ http.request(req)
70
+ end
71
+
72
+ def self.synchronize_file(user_key, app_key, file)
73
+ uri = URI.join(BASE_BUILD_PATH, "sync")
74
+
75
+ req = Net::HTTP::Post::Multipart.new uri.path, {"file" => UploadIO.new(file, "application/octet-stream"), "build-rfname" => file.gsub(File.join(Dir.pwd, "VikingIO"), "")}
76
+ req['x-vikingio-user-key'] = user_key
77
+ req['x-vikingio-key'] = app_key
78
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
79
+ http.request(req)
80
+ end
81
+ end
82
+
83
+ def self.compile_server(user_key, app_key, app_name)
84
+ uri = URI.join(BASE_BUILD_PATH, "compile")
85
+
86
+ http = Net::HTTP.new(uri.host, uri.port)
87
+ req = Net::HTTP::Get.new(uri.path)
88
+ req['x-vikingio-user-key'] = user_key
89
+ req['x-vikingio-key'] = app_key
90
+ req['x-vikingio-app-name'] = app_name
91
+ resp = http.request(req)
92
+
93
+ puts resp.body
94
+ end
95
+
96
+ def self.authenticate(email, password)
97
+ uri = URI.join(BASE_PATH, "auth")
98
+
99
+ response = Net::HTTP.post_form(uri, {"email" => email, "password" => password})
100
+
101
+ return nil if response.code == "403"
102
+ puts "Unable to reach server." and return nil if response.code == "401"
103
+
104
+ json = JSON.parse(response.body)
105
+
106
+ return json["key"]
107
+ end
108
+
109
+ def self.create_app(name)
110
+ uri = URI.join(BASE_PATH, "apps")
111
+
112
+ http = Net::HTTP.new(uri.host, uri.port)
113
+ req = Net::HTTP::Post.new(uri.path)
114
+ req['x-vikingio-user-key'] = VikingIO::CLI.get_netrc_key
115
+ req.set_form_data({"name" => name})
116
+ response = http.request(req)
117
+
118
+ return nil if response.code == "403"
119
+ puts "Unable to reach server." and return nil if response.code == "401"
120
+
121
+ return JSON.parse(response.body)
122
+ end
123
+
124
+ def self.create_node(name, app_key)
125
+ return nil if name == "" || name == nil
126
+
127
+ uri = URI.join(BASE_PATH, "nodes")
128
+
129
+ http = Net::HTTP.new(uri.host, uri.port)
130
+ req = Net::HTTP::Post.new(uri.path)
131
+ req['x-vikingio-user-key'] = VikingIO::CLI.get_netrc_key
132
+ req['x-vikingio-app-key'] = app_key
133
+ req.set_form_data({"name" => name})
134
+ response = http.request(req)
135
+
136
+ return nil if response.code == "403"
137
+ puts "Unable to reach server." and return nil if response.code == "401"
138
+
139
+ return JSON.parse(response.body)
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,467 @@
1
+ module VikingIO
2
+ module CLI
3
+ module Commands
4
+
5
+ BASE_PATH = "http://build1.vikingio.com/"
6
+ UNITY_COMPILER_PATH_OSX = "/Applications/Unity/Unity.app/Contents/Frameworks/MonoBleedingEdge/bin/gmcs"
7
+ UNITY_MONO_PATH_OSX = "/Applications/Unity/Unity.app/Contents/Frameworks/MonoBleedingEdge/bin/mono"
8
+ UNITY_MONO_DLL_PATH_OSX = "/Applications/Unity/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/"
9
+ TEMPLATES_DIR = File.join(File.dirname(__FILE__), "../../../templates")
10
+
11
+ COMMANDS = [
12
+ ["help", {:short => "", :full => ""}],
13
+ ["login", {:short => "Authenticate with VikingIO", :full => ""}],
14
+ ["logout", {:short => "Clear your authentication credentials", :full => ""}],
15
+ ["create", {:short => "Create a new VikingIO application", :full => "Ex: vikingio create [app-name]"}],
16
+ ["generate", {:short => "Generate a VikingIO node", :full => "Ex: vikingio generate node GameServer"}],
17
+ #["link", {:short => "Link the current directory with an existing VikingIO application", :full => "Ex: vikingio link [app-name]"}],
18
+ ["unlink", {:short => "Unlink the current directory with it's VikingIO application", :full => "Ex: vikingio unlink"}],
19
+ #["compile", {:short => "Compile your application on the server.", :full => "Once compiled, your application is ready to deploy."}],
20
+ ["deploy", {:short => "Deploy your application", :full => "The latest build will be deployed to our cloud infrastructure. [NOTE: Billing will begin immediately after your application is deployed.]"}],
21
+ #["destroy", {:short => "Destroy all production nodes in the VikingIO cloud", :full => "This will completely shut down and remove all of your production nodes for this application."}],
22
+ ["run", {:short => "Compile and run your application locally", :full => ""}],
23
+ #["status", {:short => "Get status of nodes", :full => ""}],
24
+ #[""]
25
+ ]
26
+
27
+ def self.run(command, args)
28
+ case command
29
+ when "help"
30
+ help(args)
31
+ when "login"
32
+ login(args)
33
+ when "logout"
34
+ logout(args)
35
+ when "create"
36
+ create(args)
37
+ when "generate"
38
+ generate(args)
39
+ when "link"
40
+ link(args)
41
+ when "unlink"
42
+ unlink(args)
43
+ when "run"
44
+ compile_and_run(args)
45
+ when "deploy"
46
+ deploy(args)
47
+ #when "compile"
48
+ # compile_on_server(args)
49
+ when "destroy"
50
+ destroy(args)
51
+ when "status"
52
+ status(args)
53
+ else
54
+ help(args)
55
+ end
56
+ end
57
+
58
+ def self.status(*args)
59
+ app_data = VikingIO::CLI.get_app_data
60
+ user_key = VikingIO::CLI.get_netrc_key
61
+ puts VikingIO::CLI::Client.get_status(user_key, app_data["key"])
62
+ end
63
+
64
+ def self.destroy(*args)
65
+
66
+ puts ""
67
+ puts "****** WARNING *******"
68
+ puts "This will shut down all of the server node instances for this application. You will have to re-deploy from scratch."
69
+ puts ""
70
+
71
+ puts "Proceed? (y/n)"
72
+ y_or_n = STDIN.gets.chomp.downcase
73
+
74
+ if ["y", "yes"].include?(y_or_n)
75
+
76
+ else
77
+ puts "Aborting."
78
+ end
79
+
80
+ end
81
+
82
+ # def self.compile_on_server(*args)
83
+ # args.flatten!
84
+ #
85
+ # app_data = VikingIO::CLI.get_app_data
86
+ # user_key = VikingIO::CLI.get_netrc_key
87
+ #
88
+ # puts "Synchronizing '#{app_data["name"]}' files..."
89
+ #
90
+ # VikingIO::CLI::Client.request_build_job(user_key, app_data["key"])
91
+ #
92
+ # Dir.chdir(File.join(Dir.pwd, "Assets", "VikingIO")) do
93
+ # files = Dir.glob("**/**/**").reject {|x| x.start_with?("Client") }.reject {|x| Dir.exist?(x) }.reject {|x| x.end_with?(".meta") }
94
+ # files.each do |file|
95
+ # puts file + "..."
96
+ # VikingIO::CLI::Client.synchronize_file(user_key, app_data["key"], file)
97
+ # end
98
+ # end
99
+ #
100
+ # puts "Compiling..."
101
+ #
102
+ # VikingIO::CLI::Client.compile_server(user_key, app_data["key"], app_data["name"])
103
+ #
104
+ # puts "done."
105
+ # end
106
+
107
+ def self.deploy(*args)
108
+ args.flatten!
109
+
110
+ app_data = VikingIO::CLI.get_app_data
111
+ user_key = VikingIO::CLI.get_netrc_key
112
+ node_data = VikingIO::CLI.get_node_data
113
+
114
+ tmp_dir = File.join(Dir.tmpdir, "vikingio")
115
+
116
+ compile = !args.include?("--skip-compilation")
117
+ compilation_success = true
118
+
119
+ if args.include?("--check")
120
+ new_node_ct = VikingIO::CLI::Client.deploy_check(user_key, app_data["key"]).to_i
121
+
122
+ if new_node_ct == 0
123
+ puts "No new nodes will be created."
124
+ else
125
+ puts "#{new_node_ct} new node(s) will be created."
126
+ end
127
+ return
128
+ end
129
+
130
+ if compile
131
+ if !self.compile_nodes(tmp_dir, node_data)
132
+ compilation_success = false
133
+ else
134
+ `cd #{File.join(tmp_dir, "VikingIO")} && tar -zcvf Data.tar.gz Data`
135
+ puts "Deploying data..."
136
+ VikingIO::CLI::Client.deploy_data(user_key, app_data["key"], File.join(tmp_dir, "VikingIO", "Data.tar.gz"))
137
+ `rm -rf #{File.join(tmp_dir, "VikingIO", "Data")}*`
138
+ `cd #{File.join(tmp_dir, "VikingIO")} && tar -zcvf #{File.join(tmp_dir, "VikingIO.tar.gz")} .`
139
+ puts "Deploying nodes..."
140
+ VikingIO::CLI::Client.deploy_servers(user_key, app_data["key"], File.join(tmp_dir, "VikingIO.tar.gz"))
141
+ end
142
+ end
143
+
144
+ if compilation_success
145
+
146
+ new_node_ct = VikingIO::CLI::Client.deploy_check(user_key, app_data["key"]).to_i
147
+ deploy = true
148
+
149
+ if new_node_ct != 0
150
+ puts "#{new_node_ct} new node(s) will be created. Continue? (y/n)"
151
+ y_or_n = STDIN.gets.chomp.downcase
152
+
153
+ if !["y", "yes"].include?(y_or_n)
154
+ deploy = false
155
+ puts "Aborting."
156
+ end
157
+
158
+ end
159
+
160
+ if deploy
161
+ puts "Deploying"
162
+ puts VikingIO::CLI::Client.deploy(user_key, app_data["key"])
163
+ end
164
+
165
+ # VikingIO::CLI::Client.deploy(user_key, app_data["key"], node_data.to_json)
166
+ else
167
+ puts "Compilation failed. Aborting deploy."
168
+ end
169
+ end
170
+
171
+ def self.compile_nodes(tmp_dir, node_data)
172
+ begin
173
+ puts File.join(tmp_dir, "VikingIO")
174
+
175
+ FileUtils::rm_rf(tmp_dir)
176
+ FileUtils::mkdir_p(tmp_dir)
177
+ FileUtils::cp_r(File.join(Dir.pwd, "Assets", "VikingIO"), tmp_dir)
178
+ FileUtils::rm_rf(File.join(tmp_dir, "VikingIO", "Client"))
179
+
180
+ meta_files = Dir["#{tmp_dir}/VikingIO/**/*.meta"]
181
+ meta_files.each {|x| FileUtils.rm_rf(x) }
182
+
183
+ templates_dir = File.join(File.dirname(__FILE__), "../../../templates")
184
+ program_template = File.read(File.join(templates_dir, "Program.cs"))
185
+
186
+ app_data = VikingIO::CLI.get_app_data
187
+
188
+ #dlls_dir = File.join(File.dirname(__FILE__), "../../../dlls")
189
+ #viking_dll_path = File.join(dlls_dir, "VikingIO.Network.dll")
190
+ #FileUtils::cp(viking_dll_path, File.join(tmp_dir, "VikingIO"))
191
+
192
+ cs_files = Dir["#{tmp_dir}/VikingIO/**/*.cs"]
193
+
194
+ references = Dir["#{tmp_dir}/VikingIO/Server/External/**/*.dll"]
195
+ reference_str = references.map{|x| "-reference:#{x}" }.join(" ")
196
+
197
+ log_file = File.join(tmp_dir, "VikingIO", "log")
198
+
199
+ node_data.each do |node|
200
+ @exit_status = nil
201
+ @exit_msg = ""
202
+ puts "Compiling '" + node["node_class"] + "' node"
203
+ node_class = node["node_class"]
204
+
205
+ program_path = File.join(tmp_dir, "VikingIO", node_class + ".cs")
206
+
207
+ puts app_data["name"]
208
+ File.open(program_path, "w") do |f|
209
+ f << program_template.gsub("[MODULE_NAME]", node_class).gsub("[APP_NAME]", app_data["name"])
210
+ end
211
+
212
+ all_files = cs_files + [program_path]
213
+ out_file = "#{tmp_dir}/VikingIO/#{node_class}.exe"
214
+
215
+ Open3.popen3("#{UNITY_COMPILER_PATH_OSX} #{reference_str} -lib:#{File.join(tmp_dir, "VikingIO", "Server", "External")} -optimize #{all_files.join(" ")} -out:#{out_file}") {|stdin, stdout, stderr, wait_thr|
216
+ pid = wait_thr.pid # pid of the started process.
217
+
218
+ @exit_status = wait_thr.value # Process::Status object returned.
219
+
220
+ stderr.each do |x|
221
+ @exit_msg << x
222
+ end
223
+ }
224
+
225
+ references.each {|x| FileUtils.cp x, File.join(tmp_dir, "VikingIO") }
226
+
227
+ if @exit_status.success? == false
228
+ puts "ERROR COMPILING: #{@exit_msg}"
229
+ return false;
230
+ end
231
+ end
232
+
233
+ node_data.each {|x| FileUtils.rm_rf File.join(tmp_dir, "VikingIO", "#{x}.cs") }
234
+
235
+ src_files = Dir.glob("#{tmp_dir}/VikingIO/**").reject {|x| x.end_with?("exe") || x.end_with?("Data") || x.end_with?("dll") }
236
+ src_files.each {|x| FileUtils.rm_rf x }
237
+
238
+ rescue Exception => e
239
+ puts "Error compiling: #{e}"
240
+ return false
241
+ end
242
+ end
243
+
244
+ def self.compile_and_run(*args)
245
+
246
+ tmp_dir = File.join(Dir.tmpdir, "vikingio")
247
+ node_data = VikingIO::CLI.get_node_data
248
+ default_port = 14242
249
+
250
+ if self.compile_nodes(tmp_dir, node_data)
251
+ pids = []
252
+
253
+ node_data.each do |node|
254
+ default_port += 1
255
+ exe_file = "#{tmp_dir}/VikingIO/#{node["node_class"]}.exe"
256
+ pids << spawn("DYLD_LIBRARY_PATH=#{UNITY_MONO_DLL_PATH_OSX} #{UNITY_MONO_PATH_OSX} #{exe_file} #{default_port}")
257
+ end
258
+
259
+ begin
260
+ puts "Press ctrl-C to stop"
261
+ while true do
262
+ sleep 0.1
263
+ end
264
+ rescue Interrupt => e
265
+ pids.each {|pid| Process.kill("HUP",pid) }
266
+ puts "Stopped processes: #{pids.join(",")}."
267
+ end
268
+ else
269
+
270
+ end
271
+ end
272
+
273
+ def self.link(*args)
274
+ end
275
+
276
+ def self.unlink(*args)
277
+ VikingIO::CLI.unlink_app
278
+ puts "Application data cleared."
279
+ end
280
+
281
+ def self.create(*args)
282
+ args.flatten!
283
+
284
+ if !VikingIO::CLI.authenticated?
285
+ puts "Please login first."
286
+ return
287
+ end
288
+
289
+ if VikingIO::CLI.linked?
290
+ puts "A VikingIO application is already linked to this directory. Use 'vikingio unlink' to clear the application data for this directory."
291
+ return
292
+ end
293
+
294
+ app_name = args.shift.join(" ") rescue nil
295
+
296
+ app = VikingIO::CLI::Client.create_app(app_name)
297
+
298
+ VikingIO::CLI.link_app(app)
299
+
300
+ puts "Created application '#{app['name']}'."
301
+
302
+ self.generate("--force")
303
+ end
304
+
305
+ def self.generate(*args)
306
+ args.flatten!
307
+
308
+ assets_path = File.join(Dir.pwd, "Assets")
309
+ viking_assets_path = File.join(assets_path, "VikingIO")
310
+ app_data = VikingIO::CLI.get_app_data
311
+
312
+ if args[0] == "node"
313
+ if args[1] == "" || args[1] == nil
314
+ puts "Please enter a camel cased name for your node. i.e. GameServer"
315
+ return
316
+ end
317
+
318
+ node_data = VikingIO::CLI::Client.create_node(args[1], app_data["key"])
319
+ VikingIO::CLI.save_node_data(node_data["nodes"])
320
+
321
+ puts ""
322
+
323
+
324
+ if node_data["status"] == "error"
325
+ puts node_data["msg"]
326
+ puts "\nIf you want to create a new node, delete your existing node with 'vikingio destroy node #{node_data["nodes"][0]["node_class"]}'. \nThis will shut down any deployed and running node instances.\n\n"
327
+ end
328
+
329
+ node_output_path = File.join(viking_assets_path, "Server", "#{args[1]}.cs")
330
+ if File.exist?(node_output_path)
331
+ puts "#{node_output_path} already exists. Ignoring template generation. Delete the file first if you want to override it."
332
+ else
333
+ server_node_template = File.read(File.join(TEMPLATES_DIR, "ServerNodeTemplate.cs")).gsub("[SERVER_NAME]", args[1])
334
+ File.open(node_output_path, 'w') { |file| file.write(server_node_template) }
335
+ end
336
+
337
+ return
338
+
339
+ node_output_path = File.join(viking_assets_path, "Server", "#{args[1]}.cs")
340
+
341
+ if !File.exist?(node_output_path)
342
+ server_node_template = File.read(File.join(TEMPLATES_DIR, "ServerNodeTemplate.cs")).gsub("[SERVER_NAME]", args[1])
343
+ File.open(node_output_path, 'w') { |file| file.write(server_node_template) }
344
+ node_data = VikingIO::CLI.get_node_data
345
+ node_data << args[1]
346
+ VikingIO::CLI.save_node_data(node_data)
347
+ end
348
+
349
+ puts "Node '#{args[1]}' created."
350
+ return
351
+ end
352
+
353
+ if args[0] == "message"
354
+ puts "Message '#{args[1]}' created."
355
+ server_node_template = File.read(File.join(TEMPLATES_DIR, "MessageTemplate.cs")).gsub("[MESSAGE_NAME]", args[1])
356
+ File.open(File.join(viking_assets_path, "Shared", "Messages", "#{args[1]}.cs"), 'w') { |file| file.write(server_node_template) }
357
+ return
358
+ end
359
+
360
+ if File.exist?(viking_assets_path) && !args.include?("--force")
361
+ puts "VikingIO already exists in your Assets folder. Run this command again with the --force command to overwrite."
362
+ return
363
+ end
364
+
365
+ puts "Generating skeleton application"
366
+
367
+ # puts "Generating folder structure..."
368
+ FileUtils::mkdir_p(File.join(viking_assets_path, "Client", "External"))
369
+ FileUtils::mkdir_p(File.join(viking_assets_path, "Server", "External"))
370
+ FileUtils::mkdir_p(File.join(viking_assets_path, "Shared", "Messages"))
371
+ FileUtils::mkdir_p(File.join(viking_assets_path, "Data"))
372
+
373
+ dlls_dir = File.join(File.dirname(__FILE__), "../../../dlls")
374
+
375
+ config_dest = File.join(viking_assets_path, "Client", "VikingIO.Config.cs")
376
+
377
+ # puts "Copying template files..."
378
+ FileUtils.cp(File.join(TEMPLATES_DIR, "NetworkManager.cs"), File.join(viking_assets_path, "Client", "NetworkManager.cs"))
379
+ FileUtils.cp(File.join(TEMPLATES_DIR, "VikingIO.Config.cs"), config_dest)
380
+
381
+ contents = File.read(config_dest).gsub("[APP_NAME]", app_data["name"]).gsub("[APP_ID]", app_data["id"].to_s)
382
+
383
+ File.open(config_dest, 'w') { |file| file.write(contents) }
384
+
385
+ File.open(File.join(viking_assets_path, "Nodefile"), "w") do |f|
386
+ f << [].to_json
387
+ end
388
+
389
+ # puts "Copying dlls..."
390
+ FileUtils.cp(File.join(dlls_dir, "VikingIO.Network.dll"), File.join(viking_assets_path, "Server", "External", "VikingIO.Network.dll"))
391
+ FileUtils.cp(File.join(dlls_dir, "VikingIO.Network.Client.dll"), File.join(viking_assets_path, "Client", "External", "VikingIO.Network.Client.dll"))
392
+ # puts "Done."
393
+ end
394
+
395
+ def self.help(*args)
396
+ args.flatten!
397
+ if args.size == 0
398
+ puts "\nCommands: \n\n"
399
+
400
+ COMMANDS.each do |cmd|
401
+ if cmd[1][:short].nil?
402
+ puts cmd[0]
403
+ else
404
+ puts "#{cmd[0]} - #{cmd[1][:short]}"
405
+ end
406
+ end
407
+
408
+ puts ""
409
+ else
410
+ cmd = COMMANDS.find {|x| x[0] == args[0] }
411
+
412
+ puts "\n=========== " + cmd[0] + " ===========\n\n"
413
+ puts cmd[1][:short] + "\n\n"
414
+ puts cmd[1][:full]
415
+ end
416
+ puts ""
417
+ end
418
+
419
+ def self.login(*args)
420
+ email = ""
421
+ password = ""
422
+
423
+ puts "Enter your email:"
424
+ email = STDIN.gets.chomp
425
+
426
+ puts ""
427
+ puts "Enter your password:"
428
+ password = STDIN.noecho(&:gets).chomp
429
+
430
+ if email.nil? || email == "" || password.nil? || password == ""
431
+ puts "Email or Password empty"
432
+ return
433
+ end
434
+
435
+ app_key = VikingIO::CLI::Client.authenticate(email, password)
436
+
437
+ if app_key.nil?
438
+ puts "Invalid authentication."
439
+ return
440
+ end
441
+
442
+ if VikingIO::CLI.netrc_exist?
443
+ if VikingIO::CLI.in_netrc?
444
+ VikingIO::CLI.update_netrc_key(app_key)
445
+ else
446
+ VikingIO::CLI.add_netrc_key(email, app_key)
447
+ end
448
+ puts "Authenticated #{email}."
449
+ else
450
+
451
+ end
452
+
453
+ end
454
+
455
+ def self.logout(*args)
456
+ VikingIO::CLI.remove_netrc_key
457
+
458
+ puts "Authentication cleared."
459
+ end
460
+
461
+ end
462
+ end
463
+ end
464
+
465
+
466
+
467
+
@@ -0,0 +1,110 @@
1
+ module VikingIO
2
+ module CLI
3
+ NETRC_PATH = File.join(Dir.home, ".netrc")
4
+ NETRC_ENTRY_RX = /machine\s+vikingio.com\s+login\s+(.*)\s+password\s+(.*)[\s+]?/i
5
+ APP_DATA_FILENAME = ".vikingio"
6
+ NODE_DATA_FILENAME = "Nodefile"
7
+
8
+ def self.node_data_path
9
+ File.join(Dir.pwd, "Assets", "VikingIO", NODE_DATA_FILENAME)
10
+ end
11
+
12
+ def self.get_node_data
13
+ return unless File.exist?(self.node_data_path)
14
+ d = File.read(self.node_data_path)
15
+ return JSON.parse(d)
16
+ end
17
+
18
+ def self.save_node_data(data)
19
+ File.open(self.node_data_path, 'w') do |f|
20
+ f << data.to_json
21
+ end
22
+ end
23
+
24
+ def self.get_app_data
25
+ return unless File.exist?(self.app_data_path)
26
+ d = File.read(self.app_data_path)
27
+ return JSON.parse(d)
28
+ end
29
+
30
+ def self.link_app(app)
31
+ File.open(self.app_data_path, 'w') do |f|
32
+ f << app.to_json
33
+ end
34
+ end
35
+
36
+ def self.unlink_app
37
+ return unless File.exist?(self.app_data_path)
38
+ FileUtils.rm_rf(app_data_path)
39
+ end
40
+
41
+ def self.linked?
42
+ File.exist?(self.app_data_path)
43
+ end
44
+
45
+ def self.authenticated?
46
+ return true if VikingIO::CLI.netrc_exist? && VikingIO::CLI.in_netrc?
47
+ return false
48
+ end
49
+
50
+ def self.app_data_path
51
+ File.join(Dir.pwd, APP_DATA_FILENAME)
52
+ end
53
+
54
+ def self.netrc_contents
55
+ File.read(NETRC_PATH)
56
+ end
57
+
58
+ def self.netrc_exist?()
59
+ File.exist?(NETRC_PATH)
60
+ end
61
+
62
+ def self.in_netrc?()
63
+ netrc_contents =~ /machine\s+vikingio.com/i
64
+ end
65
+
66
+ def self.get_netrc_key
67
+ data = NETRC_ENTRY_RX.match(netrc_contents)
68
+
69
+ email = data[1]
70
+ key = data[2]
71
+
72
+ return key
73
+ end
74
+
75
+ def self.update_netrc_key(new_password)
76
+ netrc = netrc_contents
77
+
78
+ data = NETRC_ENTRY_RX.match(netrc)
79
+
80
+ existing_email = data[1]
81
+ existing_password = data[2]
82
+
83
+ netrc.gsub!(existing_password, new_password)
84
+
85
+ save_netrc(netrc)
86
+ end
87
+
88
+ def self.add_netrc_key(email, key)
89
+ netrc = netrc_contents
90
+
91
+ netrc += "machine vikingio.com\n login " + email + "\n password " + key + "\n"
92
+
93
+ save_netrc(netrc)
94
+ end
95
+
96
+ def self.remove_netrc_key
97
+ netrc = netrc_contents
98
+
99
+ netrc.gsub!(NETRC_ENTRY_RX, "")
100
+
101
+ save_netrc(netrc)
102
+ end
103
+
104
+ def self.save_netrc(netrc_contents)
105
+ File.open(NETRC_PATH, 'w') { |file| file.write(netrc_contents) }
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,5 @@
1
+ module VikingIO
2
+ module CLI
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'io/console'
4
+ require 'json'
5
+ require 'fileutils'
6
+ require 'yaml'
7
+ require 'tmpdir'
8
+ require 'open3'
9
+ require 'net/http/post/multipart'
10
+
11
+ lib = File.dirname(File.expand_path(__FILE__))
12
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
13
+
14
+ require "vikingio/cli/version"
15
+ require "vikingio/cli/helpers"
16
+ require "vikingio/cli/client"
17
+ require "vikingio/cli/commands"
18
+
19
+ module VikingIO
20
+ module CLI
21
+
22
+ def self.start(*args)
23
+ begin
24
+ if $stdin.isatty
25
+ $stdin.sync = true
26
+ end
27
+ if $stdout.isatty
28
+ $stdout.sync = true
29
+ end
30
+
31
+ command = args.shift.strip rescue "help"
32
+ args.flatten!
33
+
34
+ VikingIO::CLI::Commands.run(command, args)
35
+
36
+ rescue Interrupt
37
+ puts "Command cancelled."
38
+ rescue => error
39
+ puts error
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ using System.Collections;
2
+
3
+ using VikingIO.Network;
4
+ using VikingIO.Network.Messaging;
5
+
6
+ public class [MESSAGE_NAME] : BaseNetworkMessage
7
+ {
8
+
9
+ public [MESSAGE_NAME]()
10
+ {
11
+
12
+ }
13
+
14
+ public override void Deserialize(INetIncomingMessage serializedMessage)
15
+ {
16
+ GetMessageInformation(serializedMessage);
17
+ // Deserialize your message data here
18
+ }
19
+
20
+ public override void Serialize(INetOutgoingMessage message)
21
+ {
22
+ // Serialize your message data here
23
+ }
24
+
25
+ }
@@ -0,0 +1,34 @@
1
+ using UnityEngine;
2
+ using System;
3
+ using System.Collections;
4
+
5
+ using VikingIO.Network;
6
+ using VikingIO.Network.Messaging;
7
+
8
+ public class NetworkManager : VikingSingleton<NetworkManager>
9
+ {
10
+ protected NetworkManager()
11
+ {
12
+ }
13
+
14
+ private VikingClient m_NetClient;
15
+
16
+ public VikingClient Client
17
+ {
18
+ get { return m_NetClient; }
19
+ }
20
+
21
+ void Awake()
22
+ {
23
+ m_NetClient = new VikingClient(VikingIOConfig.APP_NAME, VikingIOConfig.APP_ID);
24
+
25
+ Instance.Client.Start(true);
26
+
27
+ Debug.LogWarning("VikingIO NetworkManager started");
28
+ }
29
+
30
+ void Update()
31
+ {
32
+ Instance.Client.Update();
33
+ }
34
+ }
@@ -0,0 +1,22 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Text;
4
+
5
+ using VikingIO.Network;
6
+
7
+ namespace VikingIO.ServerNode
8
+ {
9
+ class Program
10
+ {
11
+ static void Main(string[] args)
12
+ {
13
+ if (args.Length == 0)
14
+ {
15
+ Console.WriteLine("Supply port as first argument.");
16
+ return;
17
+ }
18
+ VikingServer.Instance.SetNode(new [MODULE_NAME]());
19
+ VikingServer.Instance.Start("[APP_NAME]", int.Parse(args[0]));
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,43 @@
1
+ using System;
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+
5
+ using VikingIO.Network;
6
+ using VikingIO.Network.Messaging;
7
+
8
+ public class [SERVER_NAME] : IVikingNode
9
+ {
10
+ int tick = 0;
11
+ VikingServer server;
12
+
13
+ public void Start(VikingServer server)
14
+ {
15
+ Console.WriteLine("[[SERVER_NAME]] Start");
16
+ this.server = server;
17
+ }
18
+
19
+ public void OnConnect(NetConnection conn)
20
+ {
21
+ Console.WriteLine(conn.RemoteEndPoint.ToString () + " connected.");
22
+ }
23
+
24
+ public void OnDisconnect(NetConnection conn)
25
+ {
26
+ Console.WriteLine(conn.RemoteEndPoint.ToString () + " disconnected.");
27
+ }
28
+
29
+ public void Stop()
30
+ {
31
+ Console.WriteLine("[[SERVER_NAME]] Stop");
32
+ }
33
+
34
+ public void Update(float dt)
35
+ {
36
+
37
+ }
38
+
39
+ public void FixedUpdate(float dt)
40
+ {
41
+
42
+ }
43
+ }
@@ -0,0 +1,9 @@
1
+ using UnityEngine;
2
+ using System.Collections;
3
+
4
+ public class VikingIOConfig {
5
+
6
+ public const string APP_NAME = "[APP_NAME]";
7
+ public const int APP_ID = [APP_ID];
8
+
9
+ }
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vikingio/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vikingio"
8
+ spec.version = VikingIO::CLI::VERSION
9
+ spec.authors = ["Eric Campbell"]
10
+ spec.email = ["info@vikingio.com"]
11
+ spec.summary = %q{VikingIO command line toolkit.}
12
+ spec.description = %q{VikingIO command line toolkit.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["vikingio"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vikingio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Eric Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: VikingIO command line toolkit.
42
+ email:
43
+ - info@vikingio.com
44
+ executables:
45
+ - vikingio
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .DS_Store
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/vikingio
56
+ - dlls/.DS_Store
57
+ - dlls/VikingIO.Network.Client.dll
58
+ - dlls/VikingIO.Network.dll
59
+ - lib/vikingio/cli.rb
60
+ - lib/vikingio/cli/client.rb
61
+ - lib/vikingio/cli/commands.rb
62
+ - lib/vikingio/cli/helpers.rb
63
+ - lib/vikingio/cli/version.rb
64
+ - templates/MessageTemplate.cs
65
+ - templates/NetworkManager.cs
66
+ - templates/Program.cs
67
+ - templates/ServerNodeTemplate.cs
68
+ - templates/VikingIO.Config.cs
69
+ - vikingio-cli.gemspec
70
+ homepage: ''
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: VikingIO command line toolkit.
94
+ test_files: []