vikingio 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +22 -22
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +13 -13
- data/Rakefile +2 -2
- data/bin/vikingio +10 -5
- data/dlls/VikingIO.Network.Client.dll +0 -0
- data/dlls/VikingIO.Network.dll +0 -0
- data/lib/vikingio/cli/client.rb +157 -153
- data/lib/vikingio/cli/commands.rb +512 -467
- data/lib/vikingio/cli/helpers.rb +115 -110
- data/lib/vikingio/cli/version.rb +5 -5
- data/lib/vikingio/cli.rb +49 -44
- data/templates/MessageTemplate.cs +25 -25
- data/templates/NetworkManager.cs +33 -33
- data/templates/Program.cs +21 -21
- data/templates/ServerNodeTemplate.cs +39 -39
- data/templates/VikingIO.Config.cs +8 -8
- data/vikingio-cli.gemspec +23 -23
- metadata +3 -3
@@ -1,467 +1,512 @@
|
|
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__), "
|
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
|
-
puts ""
|
70
|
-
|
71
|
-
puts "
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
`
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
FileUtils::
|
177
|
-
FileUtils::
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
if args
|
398
|
-
puts "
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
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.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "templates")) #File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "templates"))
|
10
|
+
CSC_V35_64_PATH = File.expand_path("c:/Windows/Microsoft.Net/Framework64/v3.5/csc.exe")
|
11
|
+
|
12
|
+
COMMANDS = [
|
13
|
+
["help", {:short => "", :full => ""}],
|
14
|
+
["login", {:short => "Authenticate with VikingIO", :full => ""}],
|
15
|
+
["logout", {:short => "Clear your authentication credentials", :full => ""}],
|
16
|
+
["create", {:short => "Create a new VikingIO application", :full => "Ex: vikingio create [app-name]"}],
|
17
|
+
["generate", {:short => "Generate a VikingIO node", :full => "Ex: vikingio generate node GameServer"}],
|
18
|
+
#["link", {:short => "Link the current directory with an existing VikingIO application", :full => "Ex: vikingio link [app-name]"}],
|
19
|
+
["unlink", {:short => "Unlink the current directory with it's VikingIO application", :full => "Ex: vikingio unlink"}],
|
20
|
+
#["compile", {:short => "Compile your application on the server.", :full => "Once compiled, your application is ready to deploy."}],
|
21
|
+
["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.]"}],
|
22
|
+
#["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."}],
|
23
|
+
["run", {:short => "Compile and run your application locally", :full => ""}],
|
24
|
+
#["status", {:short => "Get status of nodes", :full => ""}],
|
25
|
+
#[""]
|
26
|
+
]
|
27
|
+
|
28
|
+
def self.run(command, args)
|
29
|
+
puts "VikingIO Version: #{VikingIO::CLI::VERSION}"
|
30
|
+
|
31
|
+
case command
|
32
|
+
when "help"
|
33
|
+
help(args)
|
34
|
+
when "login"
|
35
|
+
login(args)
|
36
|
+
when "logout"
|
37
|
+
logout(args)
|
38
|
+
when "create"
|
39
|
+
create(args)
|
40
|
+
when "generate"
|
41
|
+
generate(args)
|
42
|
+
when "link"
|
43
|
+
link(args)
|
44
|
+
when "unlink"
|
45
|
+
unlink(args)
|
46
|
+
when "run"
|
47
|
+
compile_and_run(args)
|
48
|
+
when "deploy"
|
49
|
+
deploy(args)
|
50
|
+
#when "compile"
|
51
|
+
# compile_on_server(args)
|
52
|
+
when "destroy"
|
53
|
+
destroy(args)
|
54
|
+
when "status"
|
55
|
+
status(args)
|
56
|
+
else
|
57
|
+
help(args)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.status(*args)
|
62
|
+
app_data = VikingIO::CLI.get_app_data
|
63
|
+
user_key = VikingIO::CLI.get_netrc_key
|
64
|
+
puts VikingIO::CLI::Client.get_status(user_key, app_data["key"])
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.destroy(*args)
|
68
|
+
|
69
|
+
puts ""
|
70
|
+
puts "****** WARNING *******"
|
71
|
+
puts "This will shut down all of the server node instances for this application. You will have to re-deploy from scratch."
|
72
|
+
puts ""
|
73
|
+
|
74
|
+
puts "Proceed? (y/n)"
|
75
|
+
y_or_n = STDIN.gets.chomp.downcase
|
76
|
+
|
77
|
+
if ["y", "yes"].include?(y_or_n)
|
78
|
+
|
79
|
+
else
|
80
|
+
puts "Aborting."
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
# def self.compile_on_server(*args)
|
86
|
+
# args.flatten!
|
87
|
+
#
|
88
|
+
# app_data = VikingIO::CLI.get_app_data
|
89
|
+
# user_key = VikingIO::CLI.get_netrc_key
|
90
|
+
#
|
91
|
+
# puts "Synchronizing '#{app_data["name"]}' files..."
|
92
|
+
#
|
93
|
+
# VikingIO::CLI::Client.request_build_job(user_key, app_data["key"])
|
94
|
+
#
|
95
|
+
# Dir.chdir(File.join(Dir.pwd, "Assets", "VikingIO")) do
|
96
|
+
# files = Dir.glob("**/**/**").reject {|x| x.start_with?("Client") }.reject {|x| Dir.exist?(x) }.reject {|x| x.end_with?(".meta") }
|
97
|
+
# files.each do |file|
|
98
|
+
# puts file + "..."
|
99
|
+
# VikingIO::CLI::Client.synchronize_file(user_key, app_data["key"], file)
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
# puts "Compiling..."
|
104
|
+
#
|
105
|
+
# VikingIO::CLI::Client.compile_server(user_key, app_data["key"], app_data["name"])
|
106
|
+
#
|
107
|
+
# puts "done."
|
108
|
+
# end
|
109
|
+
|
110
|
+
def self.deploy(*args)
|
111
|
+
args.flatten!
|
112
|
+
|
113
|
+
app_data = VikingIO::CLI.get_app_data
|
114
|
+
user_key = VikingIO::CLI.get_netrc_key
|
115
|
+
node_data = VikingIO::CLI.get_node_data
|
116
|
+
|
117
|
+
tmp_dir = File.join(Dir.tmpdir, "vikingio")
|
118
|
+
|
119
|
+
compile = !args.include?("--skip-compilation")
|
120
|
+
compilation_success = true
|
121
|
+
|
122
|
+
if args.include?("--check")
|
123
|
+
new_node_ct = VikingIO::CLI::Client.deploy_check(user_key, app_data["key"]).to_i
|
124
|
+
|
125
|
+
if new_node_ct == 0
|
126
|
+
puts "No new nodes will be created."
|
127
|
+
else
|
128
|
+
puts "#{new_node_ct} new node(s) will be created."
|
129
|
+
end
|
130
|
+
return
|
131
|
+
end
|
132
|
+
|
133
|
+
if compile
|
134
|
+
if !self.compile_nodes(tmp_dir, node_data)
|
135
|
+
compilation_success = false
|
136
|
+
else
|
137
|
+
`cd #{File.join(tmp_dir, "VikingIO")} && tar -zcvf Data.tar.gz Data`
|
138
|
+
puts "Deploying data..."
|
139
|
+
VikingIO::CLI::Client.deploy_data(user_key, app_data["key"], File.join(tmp_dir, "VikingIO", "Data.tar.gz"))
|
140
|
+
`rm -rf #{File.join(tmp_dir, "VikingIO", "Data")}*`
|
141
|
+
`cd #{File.join(tmp_dir, "VikingIO")} && tar -zcvf #{File.join(tmp_dir, "VikingIO.tar.gz")} .`
|
142
|
+
puts "Deploying nodes..."
|
143
|
+
VikingIO::CLI::Client.deploy_servers(user_key, app_data["key"], File.join(tmp_dir, "VikingIO.tar.gz"))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
if compilation_success
|
148
|
+
|
149
|
+
new_node_ct = VikingIO::CLI::Client.deploy_check(user_key, app_data["key"]).to_i
|
150
|
+
deploy = true
|
151
|
+
|
152
|
+
if new_node_ct != 0
|
153
|
+
puts "#{new_node_ct} new node(s) will be created. Continue? (y/n)"
|
154
|
+
y_or_n = STDIN.gets.chomp.downcase
|
155
|
+
|
156
|
+
if !["y", "yes"].include?(y_or_n)
|
157
|
+
deploy = false
|
158
|
+
puts "Aborting."
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
if deploy
|
164
|
+
puts "Deploying"
|
165
|
+
puts VikingIO::CLI::Client.deploy(user_key, app_data["key"])
|
166
|
+
end
|
167
|
+
|
168
|
+
# VikingIO::CLI::Client.deploy(user_key, app_data["key"], node_data.to_json)
|
169
|
+
else
|
170
|
+
puts "Compilation failed. Aborting deploy."
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.compile_nodes(tmp_dir, node_data)
|
175
|
+
begin
|
176
|
+
FileUtils::rm_rf(tmp_dir)
|
177
|
+
FileUtils::mkdir_p(tmp_dir)
|
178
|
+
|
179
|
+
if IS_WINDOWS
|
180
|
+
working_directory = `echo %cd%`
|
181
|
+
else
|
182
|
+
working_directory = Dir.pwd
|
183
|
+
end
|
184
|
+
|
185
|
+
puts "Copying project"
|
186
|
+
FileUtils::cp_r(File.join(working_directory, "Assets", "VikingIO"), tmp_dir)
|
187
|
+
|
188
|
+
puts "Removing Client directory"
|
189
|
+
FileUtils::rm_rf(File.join(tmp_dir, "VikingIO", "Client"))
|
190
|
+
|
191
|
+
puts "Removing meta files"
|
192
|
+
meta_files = Dir["#{tmp_dir}/VikingIO/**/*.meta"]
|
193
|
+
meta_files.each {|x| FileUtils.rm_rf(x) }
|
194
|
+
|
195
|
+
puts "Loading Main class"
|
196
|
+
templates_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "templates")
|
197
|
+
program_template = File.read(File.join(templates_dir, "Program.cs"))
|
198
|
+
|
199
|
+
app_data = VikingIO::CLI.get_app_data
|
200
|
+
|
201
|
+
puts "Loading App Data: #{app_data}"
|
202
|
+
#dlls_dir = File.join(File.dirname(__FILE__), "../../../dlls")
|
203
|
+
#viking_dll_path = File.join(dlls_dir, "VikingIO.Network.dll")
|
204
|
+
#FileUtils::cp(viking_dll_path, File.join(tmp_dir, "VikingIO"))
|
205
|
+
|
206
|
+
cs_files = Dir["#{tmp_dir}/VikingIO/**/*.cs"]
|
207
|
+
|
208
|
+
references = Dir["#{tmp_dir}/VikingIO/Server/External/**/*.dll"]
|
209
|
+
reference_str = references.map{|x| "-reference:#{x}" }.join(" ")
|
210
|
+
|
211
|
+
log_file = File.join(tmp_dir, "VikingIO", "log")
|
212
|
+
|
213
|
+
node_data.each do |node|
|
214
|
+
@exit_status = nil
|
215
|
+
@exit_msg = ""
|
216
|
+
puts "Compiling '" + node["node_class"] + "' node"
|
217
|
+
node_class = node["node_class"]
|
218
|
+
|
219
|
+
program_path = File.join(tmp_dir, "VikingIO", node_class + ".Main.cs")
|
220
|
+
|
221
|
+
puts app_data["name"]
|
222
|
+
File.open(program_path, "w") do |f|
|
223
|
+
f << program_template.gsub("[MODULE_NAME]", node_class).gsub("[APP_NAME]", app_data["name"])
|
224
|
+
end
|
225
|
+
|
226
|
+
all_files = cs_files + [program_path]
|
227
|
+
out_file = "#{tmp_dir}/VikingIO/#{node_class}.exe"
|
228
|
+
|
229
|
+
|
230
|
+
library_path = File.join(tmp_dir, "VikingIO", "Server", "External")
|
231
|
+
csc_path = "c:\\Windows\\Microsoft.Net\\Framework64\\v3.5\\csc.exe"
|
232
|
+
|
233
|
+
if IS_WINDOWS
|
234
|
+
references = Dir["#{tmp_dir}/VikingIO/Server/External/**/*.dll"]
|
235
|
+
reference_str = references.map {|x| "/r:#{File.expand_path(x)}" }.join(" ")
|
236
|
+
cs_files = Dir["#{tmp_dir}/VikingIO/**/*.cs"]
|
237
|
+
cs_files_str = cs_files.map {|x| File.expand_path(x) }.join(" ")
|
238
|
+
|
239
|
+
Open3.popen3("cd #{tmp_dir}/VikingIO && #{CSC_V35_64_PATH} #{reference_str} /out:#{node_class}.exe /recurse:Server\\*.cs /recurse:Shared\\.cs #{node_class}.Main.cs") {|stdin, stdout, stderr, wait_thr|
|
240
|
+
pid = wait_thr.pid # pid of the started process.
|
241
|
+
|
242
|
+
@exit_status = wait_thr.value # Process::Status object returned.
|
243
|
+
|
244
|
+
stderr.each do |x|
|
245
|
+
@exit_msg << x
|
246
|
+
end
|
247
|
+
}
|
248
|
+
else
|
249
|
+
Open3.popen3("#{UNITY_COMPILER_PATH_OSX} #{reference_str} -lib:#{library_path} -optimize #{all_files.join(" ")} -out:#{out_file}") {|stdin, stdout, stderr, wait_thr|
|
250
|
+
pid = wait_thr.pid # pid of the started process.
|
251
|
+
|
252
|
+
@exit_status = wait_thr.value # Process::Status object returned.
|
253
|
+
|
254
|
+
stderr.each do |x|
|
255
|
+
@exit_msg << x
|
256
|
+
end
|
257
|
+
}
|
258
|
+
end
|
259
|
+
|
260
|
+
references.each {|x| FileUtils.cp x, File.join(tmp_dir, "VikingIO") }
|
261
|
+
|
262
|
+
if @exit_status.success? == false
|
263
|
+
puts "ERROR COMPILING: #{@exit_msg}"
|
264
|
+
return false;
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
node_data.each {|x| FileUtils.rm_rf File.join(tmp_dir, "VikingIO", "#{x}.cs") }
|
269
|
+
|
270
|
+
src_files = Dir.glob("#{tmp_dir}/VikingIO/**").reject {|x| x.end_with?("exe") || x.end_with?("Data") || x.end_with?("dll") }
|
271
|
+
src_files.each {|x| FileUtils.rm_rf x }
|
272
|
+
|
273
|
+
rescue Exception => e
|
274
|
+
puts "Error compiling: #{e}"
|
275
|
+
return false
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def self.compile_and_run(*args)
|
280
|
+
|
281
|
+
tmp_dir = File.join(Dir.tmpdir, "vikingio")
|
282
|
+
node_data = VikingIO::CLI.get_node_data
|
283
|
+
default_port = 14242
|
284
|
+
|
285
|
+
if self.compile_nodes(tmp_dir, node_data)
|
286
|
+
pids = []
|
287
|
+
|
288
|
+
node_data.each do |node|
|
289
|
+
exe_file = "#{tmp_dir}/VikingIO/#{node["node_class"]}.exe"
|
290
|
+
if IS_WINDOWS
|
291
|
+
pids << spawn("#{exe_file} #{default_port}")
|
292
|
+
else
|
293
|
+
pids << spawn("DYLD_LIBRARY_PATH=#{UNITY_MONO_DLL_PATH_OSX} #{UNITY_MONO_PATH_OSX} #{exe_file} #{default_port}")
|
294
|
+
end
|
295
|
+
default_port += 1
|
296
|
+
end
|
297
|
+
|
298
|
+
begin
|
299
|
+
puts "Press ctrl-C to stop"
|
300
|
+
while true do
|
301
|
+
sleep 0.1
|
302
|
+
end
|
303
|
+
rescue Interrupt => e
|
304
|
+
pids.each {|pid| Process.kill("INT", pid) }
|
305
|
+
puts "Stopped processes: #{pids.join(",")}."
|
306
|
+
end
|
307
|
+
else
|
308
|
+
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def self.link(*args)
|
313
|
+
end
|
314
|
+
|
315
|
+
def self.unlink(*args)
|
316
|
+
VikingIO::CLI.unlink_app
|
317
|
+
puts "Application data cleared."
|
318
|
+
end
|
319
|
+
|
320
|
+
def self.create(*args)
|
321
|
+
#args.flatten!
|
322
|
+
|
323
|
+
#if !VikingIO::CLI.authenticated?
|
324
|
+
# puts "Please login first."
|
325
|
+
# return
|
326
|
+
#end
|
327
|
+
|
328
|
+
#if VikingIO::CLI.linked?
|
329
|
+
# puts "A VikingIO application is already linked to this directory. Use 'vikingio unlink' to clear the application data for this directory."
|
330
|
+
# return
|
331
|
+
#end
|
332
|
+
|
333
|
+
#app_name = args.join(" ") rescue nil
|
334
|
+
|
335
|
+
#app = VikingIO::CLI::Client.create_app(app_name)
|
336
|
+
|
337
|
+
#if app["status"] == "error"
|
338
|
+
# puts app["message"]
|
339
|
+
# return;
|
340
|
+
#end
|
341
|
+
|
342
|
+
#VikingIO::CLI.link_app(app)
|
343
|
+
|
344
|
+
#puts "Created application '#{app['name']}'."
|
345
|
+
|
346
|
+
self.generate("--force")
|
347
|
+
end
|
348
|
+
|
349
|
+
def self.generate(*args)
|
350
|
+
args.flatten!
|
351
|
+
|
352
|
+
assets_path = File.join(Dir.pwd, "Assets")
|
353
|
+
viking_assets_path = File.join(assets_path, "VikingIO")
|
354
|
+
app_data = VikingIO::CLI.get_app_data
|
355
|
+
|
356
|
+
if args[0] == "node"
|
357
|
+
if args[1] == "" || args[1] == nil
|
358
|
+
puts "Please enter a camel cased name for your node. i.e. GameServer"
|
359
|
+
return
|
360
|
+
end
|
361
|
+
|
362
|
+
node_data = VikingIO::CLI::Client.create_node(args[1], app_data["key"])
|
363
|
+
VikingIO::CLI.save_node_data(node_data["nodes"])
|
364
|
+
|
365
|
+
puts ""
|
366
|
+
|
367
|
+
|
368
|
+
if node_data["status"] == "error"
|
369
|
+
puts node_data["msg"]
|
370
|
+
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"
|
371
|
+
end
|
372
|
+
|
373
|
+
node_output_path = File.join(viking_assets_path, "Server", "#{args[1]}.cs")
|
374
|
+
if File.exist?(node_output_path)
|
375
|
+
puts "#{node_output_path} already exists. Ignoring template generation. Delete the file first if you want to override it."
|
376
|
+
else
|
377
|
+
server_node_template = File.read(File.join(TEMPLATES_DIR, "ServerNodeTemplate.cs")).gsub("[SERVER_NAME]", args[1])
|
378
|
+
File.open(node_output_path, 'w') { |file| file.write(server_node_template) }
|
379
|
+
end
|
380
|
+
|
381
|
+
return
|
382
|
+
|
383
|
+
node_output_path = File.join(viking_assets_path, "Server", "#{args[1]}.cs")
|
384
|
+
|
385
|
+
if !File.exist?(node_output_path)
|
386
|
+
server_node_template = File.read(File.join(TEMPLATES_DIR, "ServerNodeTemplate.cs")).gsub("[SERVER_NAME]", args[1])
|
387
|
+
File.open(node_output_path, 'w') { |file| file.write(server_node_template) }
|
388
|
+
node_data = VikingIO::CLI.get_node_data
|
389
|
+
node_data << args[1]
|
390
|
+
VikingIO::CLI.save_node_data(node_data)
|
391
|
+
end
|
392
|
+
|
393
|
+
puts "Node '#{args[1]}' created."
|
394
|
+
return
|
395
|
+
end
|
396
|
+
|
397
|
+
if args[0] == "message"
|
398
|
+
puts "Message '#{args[1]}' created."
|
399
|
+
server_node_template = File.read(File.join(TEMPLATES_DIR, "MessageTemplate.cs")).gsub("[MESSAGE_NAME]", args[1])
|
400
|
+
File.open(File.join(viking_assets_path, "Shared", "Messages", "#{args[1]}.cs"), 'w') { |file| file.write(server_node_template) }
|
401
|
+
return
|
402
|
+
end
|
403
|
+
|
404
|
+
if File.exist?(viking_assets_path) && !args.include?("--force")
|
405
|
+
puts "VikingIO already exists in your Assets folder. Run this command again with the --force command to overwrite."
|
406
|
+
return
|
407
|
+
end
|
408
|
+
|
409
|
+
puts "Generating skeleton application"
|
410
|
+
|
411
|
+
# puts "Generating folder structure..."
|
412
|
+
FileUtils::mkdir_p(File.join(viking_assets_path, "Client", "External"))
|
413
|
+
FileUtils::mkdir_p(File.join(viking_assets_path, "Server", "External"))
|
414
|
+
FileUtils::mkdir_p(File.join(viking_assets_path, "Shared", "Messages"))
|
415
|
+
FileUtils::mkdir_p(File.join(viking_assets_path, "Data"))
|
416
|
+
|
417
|
+
dlls_dir = File.join(File.dirname(__FILE__), "..", "..", "..", "dlls")
|
418
|
+
|
419
|
+
config_dest = File.join(viking_assets_path, "Client", "VikingIO.Config.cs")
|
420
|
+
|
421
|
+
# puts "Copying template files..."
|
422
|
+
FileUtils.cp(File.join(TEMPLATES_DIR, "NetworkManager.cs"), File.join(viking_assets_path, "Client", "NetworkManager.cs"))
|
423
|
+
FileUtils.cp(File.join(TEMPLATES_DIR, "VikingIO.Config.cs"), config_dest)
|
424
|
+
|
425
|
+
contents = File.read(config_dest).gsub("[APP_NAME]", app_data["name"]).gsub("[APP_ID]", app_data["id"].to_s)
|
426
|
+
|
427
|
+
File.open(config_dest, 'w') { |file| file.write(contents) }
|
428
|
+
|
429
|
+
File.open(File.join(viking_assets_path, "Nodefile"), "w") do |f|
|
430
|
+
f << [].to_json
|
431
|
+
end
|
432
|
+
|
433
|
+
# puts "Copying dlls..."
|
434
|
+
FileUtils.cp(File.join(dlls_dir, "VikingIO.Network.dll"), File.join(viking_assets_path, "Server", "External", "VikingIO.Network.dll"))
|
435
|
+
FileUtils.cp(File.join(dlls_dir, "VikingIO.Network.Client.dll"), File.join(viking_assets_path, "Client", "External", "VikingIO.Network.Client.dll"))
|
436
|
+
puts "Done."
|
437
|
+
end
|
438
|
+
|
439
|
+
def self.help(*args)
|
440
|
+
args.flatten!
|
441
|
+
if args.size == 0
|
442
|
+
puts "\nCommands: \n\n"
|
443
|
+
|
444
|
+
COMMANDS.each do |cmd|
|
445
|
+
if cmd[1][:short].nil?
|
446
|
+
puts cmd[0]
|
447
|
+
else
|
448
|
+
puts "#{cmd[0]} - #{cmd[1][:short]}"
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
puts ""
|
453
|
+
else
|
454
|
+
cmd = COMMANDS.find {|x| x[0] == args[0] }
|
455
|
+
|
456
|
+
puts "\n=========== " + cmd[0] + " ===========\n\n"
|
457
|
+
puts cmd[1][:short] + "\n\n"
|
458
|
+
puts cmd[1][:full]
|
459
|
+
end
|
460
|
+
puts ""
|
461
|
+
end
|
462
|
+
|
463
|
+
def self.login(*args)
|
464
|
+
email = ""
|
465
|
+
password = ""
|
466
|
+
|
467
|
+
puts "Enter your email:"
|
468
|
+
email = STDIN.gets.chomp
|
469
|
+
|
470
|
+
puts ""
|
471
|
+
puts "Enter your password:"
|
472
|
+
password = STDIN.noecho(&:gets).chomp
|
473
|
+
|
474
|
+
if email.nil? || email == "" || password.nil? || password == ""
|
475
|
+
puts "Email or Password empty"
|
476
|
+
return
|
477
|
+
end
|
478
|
+
|
479
|
+
app_key = VikingIO::CLI::Client.authenticate(email, password)
|
480
|
+
|
481
|
+
if app_key.nil?
|
482
|
+
puts "Invalid authentication."
|
483
|
+
return
|
484
|
+
end
|
485
|
+
|
486
|
+
if VikingIO::CLI.netrc_exist?
|
487
|
+
if VikingIO::CLI.in_netrc?
|
488
|
+
VikingIO::CLI.update_netrc_key(app_key)
|
489
|
+
else
|
490
|
+
VikingIO::CLI.add_netrc_key(email, app_key)
|
491
|
+
end
|
492
|
+
puts "Authenticated #{email}."
|
493
|
+
else
|
494
|
+
VikingIO::CLI.create_netrc(email, app_key)
|
495
|
+
puts "Authenticated #{email}."
|
496
|
+
end
|
497
|
+
|
498
|
+
end
|
499
|
+
|
500
|
+
def self.logout(*args)
|
501
|
+
VikingIO::CLI.remove_netrc_key
|
502
|
+
|
503
|
+
puts "Authentication cleared."
|
504
|
+
end
|
505
|
+
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|