carps 0.2.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.
Files changed (157) hide show
  1. data/COPYING +674 -0
  2. data/GEM_DESCRIPTION +10 -0
  3. data/History.txt +4 -0
  4. data/Manifest.txt +156 -0
  5. data/PostInstall.txt +20 -0
  6. data/README.rdoc +141 -0
  7. data/Rakefile +28 -0
  8. data/bin/carps +123 -0
  9. data/bin/carps_init +29 -0
  10. data/bin/carps_ipc_test +44 -0
  11. data/bin/carps_mod_saver_test +71 -0
  12. data/bin/carps_mod_test +62 -0
  13. data/config/website.yml +2 -0
  14. data/features/character_sheet.feature +40 -0
  15. data/features/crash.feature +15 -0
  16. data/features/crypt.feature +22 -0
  17. data/features/dice.feature +173 -0
  18. data/features/dm.feature +36 -0
  19. data/features/dmll.feature +51 -0
  20. data/features/edit.feature +10 -0
  21. data/features/email.feature +29 -0
  22. data/features/interface.feature +17 -0
  23. data/features/ipc.feature +10 -0
  24. data/features/mailbox.feature +33 -0
  25. data/features/mod.feature +31 -0
  26. data/features/parser.feature +9 -0
  27. data/features/persistent_protocol.feature +14 -0
  28. data/features/player.feature +22 -0
  29. data/features/player_turn.feature +29 -0
  30. data/features/random.feature +15 -0
  31. data/features/rule.feature +19 -0
  32. data/features/safety.feature +13 -0
  33. data/features/sessions.feature +16 -0
  34. data/features/start_dm.feature +18 -0
  35. data/features/start_player.feature +8 -0
  36. data/features/step_definitions/common_steps.rb +170 -0
  37. data/features/steps/character_sheet.rb +89 -0
  38. data/features/steps/crash.rb +27 -0
  39. data/features/steps/crypt.rb +166 -0
  40. data/features/steps/dice.rb +91 -0
  41. data/features/steps/dm.rb +147 -0
  42. data/features/steps/dmll.rb +47 -0
  43. data/features/steps/edit.rb +7 -0
  44. data/features/steps/email.rb +108 -0
  45. data/features/steps/general.rb +5 -0
  46. data/features/steps/interface.rb +64 -0
  47. data/features/steps/ipc.rb +22 -0
  48. data/features/steps/mailbox.rb +126 -0
  49. data/features/steps/mod.rb +25 -0
  50. data/features/steps/parser.rb +23 -0
  51. data/features/steps/persistent_protocol.rb +29 -0
  52. data/features/steps/player.rb +82 -0
  53. data/features/steps/player_turn.rb +56 -0
  54. data/features/steps/random.rb +47 -0
  55. data/features/steps/rule.rb +53 -0
  56. data/features/steps/safety.rb +17 -0
  57. data/features/steps/sessions.rb +37 -0
  58. data/features/steps/start_dm.rb +46 -0
  59. data/features/steps/start_player.rb +65 -0
  60. data/features/steps/timeout.rb +32 -0
  61. data/features/steps/type_verification.rb +36 -0
  62. data/features/steps/wizard.rb +123 -0
  63. data/features/support/common.rb +29 -0
  64. data/features/support/env.rb +14 -0
  65. data/features/support/matchers.rb +11 -0
  66. data/features/timeout.feature +11 -0
  67. data/features/type_verification.feature +48 -0
  68. data/features/wizard.feature +50 -0
  69. data/lib/carps/crypt/accept_handshake.rb +40 -0
  70. data/lib/carps/crypt/default_messages.rb +29 -0
  71. data/lib/carps/crypt/handshake.rb +41 -0
  72. data/lib/carps/crypt/mailbox.rb +265 -0
  73. data/lib/carps/crypt/mailer.rb +220 -0
  74. data/lib/carps/crypt/peer.rb +123 -0
  75. data/lib/carps/crypt/public_key.rb +60 -0
  76. data/lib/carps/crypt.rb +23 -0
  77. data/lib/carps/email/config.rb +122 -0
  78. data/lib/carps/email/imap.rb +156 -0
  79. data/lib/carps/email/smtp.rb +119 -0
  80. data/lib/carps/email/string.rb +30 -0
  81. data/lib/carps/email.rb +21 -0
  82. data/lib/carps/mod/action.rb +36 -0
  83. data/lib/carps/mod/answers.rb +76 -0
  84. data/lib/carps/mod/client_turn.rb +88 -0
  85. data/lib/carps/mod/dice.rb +360 -0
  86. data/lib/carps/mod/dm/interface.rb +160 -0
  87. data/lib/carps/mod/dm/mod.rb +409 -0
  88. data/lib/carps/mod/dm/reporter.rb +112 -0
  89. data/lib/carps/mod/dm/resource.rb +88 -0
  90. data/lib/carps/mod/dm/room.rb +33 -0
  91. data/lib/carps/mod/interface.rb +73 -0
  92. data/lib/carps/mod/launch.rb +108 -0
  93. data/lib/carps/mod/mod.rb +52 -0
  94. data/lib/carps/mod/player/interface.rb +76 -0
  95. data/lib/carps/mod/player/mod.rb +109 -0
  96. data/lib/carps/mod/question.rb +63 -0
  97. data/lib/carps/mod/rule.rb +112 -0
  98. data/lib/carps/mod/sheet/character.rb +82 -0
  99. data/lib/carps/mod/sheet/editor.rb +97 -0
  100. data/lib/carps/mod/sheet/new_sheet.rb +71 -0
  101. data/lib/carps/mod/sheet/schema.rb +84 -0
  102. data/lib/carps/mod/sheet/type.rb +161 -0
  103. data/lib/carps/mod/sheet/verifier.rb +41 -0
  104. data/lib/carps/mod/status_report.rb +51 -0
  105. data/lib/carps/mod.rb +40 -0
  106. data/lib/carps/protocol/keyword.rb +104 -0
  107. data/lib/carps/protocol/message.rb +138 -0
  108. data/lib/carps/protocol.rb +19 -0
  109. data/lib/carps/service/client_parser.rb +34 -0
  110. data/lib/carps/service/dm/config.rb +76 -0
  111. data/lib/carps/service/dm/mailer.rb +70 -0
  112. data/lib/carps/service/dm/new_game.rb +101 -0
  113. data/lib/carps/service/dm/start.rb +47 -0
  114. data/lib/carps/service/game.rb +101 -0
  115. data/lib/carps/service/interface.rb +174 -0
  116. data/lib/carps/service/invite.rb +79 -0
  117. data/lib/carps/service/mod.rb +43 -0
  118. data/lib/carps/service/player/config.rb +78 -0
  119. data/lib/carps/service/player/mailer.rb +49 -0
  120. data/lib/carps/service/player/start.rb +60 -0
  121. data/lib/carps/service/server_parser.rb +33 -0
  122. data/lib/carps/service/session.rb +96 -0
  123. data/lib/carps/service/start/config.rb +71 -0
  124. data/lib/carps/service/start/interface.rb +101 -0
  125. data/lib/carps/service/start/mailer.rb +46 -0
  126. data/lib/carps/service.rb +35 -0
  127. data/lib/carps/test.rb +34 -0
  128. data/lib/carps/ui/colour.rb +28 -0
  129. data/lib/carps/ui/error.rb +39 -0
  130. data/lib/carps/ui/highlight.rb +32 -0
  131. data/lib/carps/ui/question.rb +63 -0
  132. data/lib/carps/ui/warn.rb +37 -0
  133. data/lib/carps/ui.rb +21 -0
  134. data/lib/carps/util/config.rb +162 -0
  135. data/lib/carps/util/editor.rb +147 -0
  136. data/lib/carps/util/error.rb +75 -0
  137. data/lib/carps/util/files.rb +48 -0
  138. data/lib/carps/util/init.rb +93 -0
  139. data/lib/carps/util/process.rb +150 -0
  140. data/lib/carps/util/timeout.rb +31 -0
  141. data/lib/carps/util/windows.rb +29 -0
  142. data/lib/carps/util.rb +24 -0
  143. data/lib/carps/wizard/dm.rb +41 -0
  144. data/lib/carps/wizard/player.rb +40 -0
  145. data/lib/carps/wizard/steps.rb +494 -0
  146. data/lib/carps/wizard/wizard.rb +126 -0
  147. data/lib/carps/wizard.rb +21 -0
  148. data/lib/carps.rb +45 -0
  149. data/permission +16 -0
  150. data/script/console +10 -0
  151. data/script/destroy +14 -0
  152. data/script/generate +14 -0
  153. data/tasks/readme_site.rake +28 -0
  154. data/test/test_carps.rb +11 -0
  155. data/test/test_helper.rb +3 -0
  156. data/website/index.html +271 -0
  157. metadata +304 -0
@@ -0,0 +1,494 @@
1
+ # Copyright 2010 John Morrice
2
+
3
+ # This file is part of CARPS.
4
+
5
+ # CARPS is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # CARPS is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with CARPS. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "carps/email/config"
19
+
20
+ require "carps/service/interface"
21
+
22
+ require "carps/util/process"
23
+ require "carps/util/editor"
24
+
25
+ require "carps/ui"
26
+
27
+ module CARPS
28
+
29
+ module Setup
30
+
31
+ # Base class for configuration steps
32
+ #
33
+ # Subclasses must:
34
+ #
35
+ # * do all real work in a 'test' method, after ensuring that the configuration is valid.
36
+ #
37
+ # * define a 'required' method which returns an array of 2 cell arrays pairing instance variables
38
+ # with the name of a command which would instantiate that variable. This is so the mandatory command
39
+ # can detect which options the user still needs to fill in.
40
+ class Interface < CARPS::QuitInterface
41
+
42
+ include ControlInterface
43
+
44
+ def initialize
45
+ super
46
+ add_command :skip, "Skip this step."
47
+ add_command :test, "Test that your settings are correct."
48
+ add_command :done, "Proceed to the next step."
49
+ end
50
+
51
+ protected
52
+
53
+ # Skip this step
54
+ def skip
55
+ @run = false
56
+ end
57
+
58
+ # An array of pairs of instance variables with the command required to fill that variable
59
+ def required
60
+ []
61
+ end
62
+
63
+ # See if all required files have been filled
64
+ def mandatory testing=true
65
+ not_present = required.reject do |var, name|
66
+ var
67
+ end
68
+ missing_names = not_present.map {|var, name| name}
69
+ if missing_names.empty?
70
+ return true
71
+ else
72
+ msg = "You must run the following commands: " + missing_names.join(", ")
73
+ if testing
74
+ test_failed msg
75
+ else
76
+ UI::highlight msg
77
+ end
78
+ return false
79
+ end
80
+ end
81
+
82
+ def help
83
+ UI::highlight description
84
+ super
85
+ mandatory false
86
+ end
87
+
88
+ # This completes the configuration.
89
+ #
90
+ # Cannot be executed unless a test has just been passed.
91
+ def done
92
+ if @passed
93
+ @run = false
94
+ else
95
+ UI::put_error "The test must pass before configuration can continue."
96
+ end
97
+ end
98
+
99
+ # The test has passed.
100
+ def test_passed
101
+ UI::highlight "Test passed!"
102
+ puts "If you are finished, you may proceed by running 'done'."
103
+ @passed = true
104
+ end
105
+
106
+ # The test has failed.
107
+ def test_failed reason=nil
108
+ UI::put_error "Test failed."
109
+ if reason
110
+ puts reason
111
+ end
112
+ @passed = false
113
+ end
114
+
115
+ # There can sometimes be more than one reason why the test has failed.
116
+ #
117
+ # DEPRICATED use Test::multi_fail
118
+ def multi_fail *reasons
119
+ Test::multi_fail reasons
120
+ end
121
+
122
+ def repl
123
+ @run = true
124
+ while @run
125
+ rep
126
+ end
127
+ end
128
+
129
+ # The argument must be either yes or no. Pass the argument and two procs, the first is executed on yes.
130
+ def yes_no opt, yes, no
131
+ if opt == "yes"
132
+ yes.call
133
+ elsif opt == "no"
134
+ no.call
135
+ else
136
+ UI::put_error "Argument must be either 'yes' or 'no'"
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ # Configure email
143
+ class Email < Interface
144
+
145
+ def initialize
146
+ super
147
+ add_command "address", "Set your email address", "ADDRESS"
148
+ add_command "user", "Sets your username for both SMTP and IMAP.", "USERNAME"
149
+ add_command "server", "Sets your server for both SMTP and IMAP.", "SERVER"
150
+ add_command "same_password", "You use the same password for both SMTP and IMAP. Default: yes.", "yes/no"
151
+ add_command "smtp_server", "Sets your SMTP server.", "SERVER_ADDRESS"
152
+ add_command "smtp_port", "The SMTP server's port. Default is 25.", "PORT"
153
+ add_command "smtp_user", "Sets your username for SMTP only.", "USERNAME"
154
+ add_command "smtp_auth",
155
+ "Configure authentication mechanism for your SMTP account\n" + options("plain", "plain", "login", "cram_md5"), "AUTHENTICATION"
156
+ add_command "smtp_crypt", "Configure encryption for your SMTP account\n" + options("none", "none", "tls", "starttls"), "SECURITY"
157
+ add_command "imap_server", "Sets your IMAP server.", "SERVER_ADDRESS"
158
+ add_command "imap_port", "The IMAP server's port. Default is 143." , "PORT"
159
+ add_command "imap_user", "Sets your username for IMAP only.", "USERNAME"
160
+ add_command "imap_auth",
161
+ "Configure authentication mechanism for your IMAP account\n" + options("plain", "plain", "login", "cram_md5"), "AUTHENTICATION"
162
+
163
+ add_command "imap_crypt",
164
+ "Configure encryption for your IMAP account.\n" + options("none", "none", "tls"),
165
+ "SECURITY"
166
+ add_command "imap_cert", "Set the certificate for your IMAP account.", "PATH_TO_CERTIFICATE"
167
+ add_command "imap_no_cert", "Don't use a certificate for your IMAP account."
168
+ add_command "imap_verify", "Verify the authenticity of your IMAP provider using certificates. Default: no.", "yes/no"
169
+ @same_pass = true
170
+ @smtp_port = 25
171
+ @smtp_starttls = false
172
+ @smtp_tls = false
173
+ @smtp_login = false
174
+ @smtp_cram_md5 = false
175
+ @imap_port = 143
176
+ @imap_tls = false
177
+ @imap_login = false
178
+ @imap_cram_md5 = false
179
+ @imap_verify = false
180
+ end
181
+
182
+ def description
183
+ "Configure your email account settings."
184
+ end
185
+
186
+ protected
187
+
188
+ # Provide a string of options
189
+ def options defa, *opts
190
+ out = "Options are:\n\t"
191
+ out += opts.join("\n\t\tor\n\t")
192
+ out += "\nDefault: #{defa}"
193
+ out
194
+ end
195
+
196
+ # Run the block if the string matches a valid authentication mechanism
197
+ def with_valid_auth mech
198
+ mech.downcase!
199
+ if mech == "plain"
200
+ yield :plain
201
+ elsif mech == "login"
202
+ yield :login
203
+ elsif mech == "cram_md5"
204
+ yield :cram_md5
205
+ else
206
+ UI::put_error "Unsupported mechanism. Supported: plain, login, cram_md5"
207
+ end
208
+ end
209
+
210
+ def smtp_auth mech
211
+ with_valid_auth mech do |type|
212
+ if type == :plain
213
+ @smtp_login = false
214
+ @smtp_cram_md5 = false
215
+ elsif type == :login
216
+ @smtp_login = true
217
+ @smtp_cram_md5 = false
218
+ elsif type == :cram_md5
219
+ @smtp_login = false
220
+ @smtp_cram_md5 = true
221
+ end
222
+ end
223
+ end
224
+
225
+ def imap_auth mech
226
+ with_valid_auth mech do |type|
227
+ if type == :plain
228
+ @imap_login = false
229
+ @imap_cram_md5 = false
230
+ elsif type == :login
231
+ @imap_login = true
232
+ @imap_cram_md5 = false
233
+ elsif type == :cram_md5
234
+ @imap_login = false
235
+ @imap_cram_md5 = true
236
+ end
237
+ end
238
+ end
239
+
240
+ def imap_no_cert
241
+ @imap_cert = nil
242
+ end
243
+
244
+ def imap_cert filepath
245
+ @imap_cert = filepath
246
+ end
247
+
248
+ def imap_verify opt
249
+ yes_no opt, lambda {@imap_verify = true}, lambda {@imap_verify = false}
250
+ end
251
+
252
+ def server serv
253
+ @smtp_server = serv
254
+ @imap_server = serv
255
+ end
256
+
257
+ def same_password opt
258
+ yes_no opt, lambda {@same_pass = true}, lambda {@same_pass = false}
259
+ end
260
+
261
+ def help
262
+ super
263
+ end
264
+
265
+ def required
266
+ [[@address, "address"], [@smtp_user, "user or smtp_user"], [@smtp_server, "server or smtp_server"], [@imap_user, "user or imap_user"], [@imap_server, "server or imap_server"]]
267
+ end
268
+
269
+ def test
270
+ if mandatory
271
+ smtp_options = {
272
+ "user" => @smtp_user,
273
+ "server" => @smtp_server,
274
+ "tls" => @smtp_tls,
275
+ "starttls" => @smtp_starttls,
276
+ "port" => @smtp_port,
277
+ "login" => @smtp_login,
278
+ "cram_md5" => @smtp_cram_md5
279
+ }
280
+ imap_options = {
281
+ "user" => @imap_user,
282
+ "server" => @imap_server,
283
+ "tls" => @imap_tls,
284
+ "port" => @imap_port,
285
+ "login" => @imap_login,
286
+ "cram_md5" => @imap_cram_md5,
287
+ "certificate" => @imap_cert,
288
+ "verify" => @imap_verify
289
+ }
290
+ config = EmailConfig.new @address, @same_pass, imap_options, smtp_options
291
+ puts config.emit.to_yaml
292
+ good = UI::confirm "Are the above settings correct?"
293
+ if good
294
+ if config.imap.ok? and config.smtp.ok?
295
+ config.save
296
+ test_passed
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ def imap_server server
303
+ @imap_server = server
304
+ end
305
+
306
+ def smtp_server server
307
+ @smtp_server = server
308
+ end
309
+
310
+ def imap_port pst
311
+ with_valid_port pst do |port|
312
+ @imap_port = port
313
+ end
314
+ end
315
+
316
+ def smtp_port pst
317
+ with_valid_port pst do |port|
318
+ @smtp_port = port
319
+ end
320
+ end
321
+
322
+ def imap_crypt option
323
+ option.downcase!
324
+ if option == "tls"
325
+ @imap_tls = true
326
+ elsif option == "none"
327
+ @imap_tls = false
328
+ else
329
+ UI::put_error "Unsupported encryption scheme."
330
+ end
331
+ end
332
+
333
+ def smtp_crypt option
334
+ option.downcase!
335
+ if option == "tls"
336
+ @smtp_starttls = false
337
+ @smtp_tls = true
338
+ elsif option == "starttls"
339
+ @smtp_starttls = true
340
+ @smtp_tls = false
341
+ elsif option == "none"
342
+ @smtp_starttls = false
343
+ @smtp_tls = false
344
+ else
345
+ UI::put_error "Unsupported encryption scheme."
346
+ end
347
+
348
+ end
349
+
350
+ def smtp_user user
351
+ @smtp_user = user
352
+ end
353
+
354
+ def imap_user user
355
+ @imap_user = user
356
+ end
357
+
358
+ def address addr
359
+ valid = addr.match /^.+\@(.+)$/
360
+ if valid
361
+ @address = addr
362
+ else
363
+ UI::put_error "Invalid email address."
364
+ end
365
+ end
366
+
367
+ def user login
368
+ smtp_user login
369
+ imap_user login
370
+ end
371
+
372
+ end
373
+
374
+ # Configure processing
375
+ class Process < Interface
376
+
377
+ def initialize
378
+ super
379
+ add_raw_command :terminal, "Specify a command used to launch interactive CARPS sub-programs, typically in another window.\n\tIE., a command which would run a program in a new X-windows terminal editor, or Screen session.\n\tUse %cmd in place of the sub-program to be executed\n\tExamples:\n\t\turxvt -e %cmd", "TERMINAL"
380
+ add_command :port, "Specify a TCP port which will be used for local inter-process communication.\n\tDefault: 51000", "PORT"
381
+ add_command :wait, "The user states when the process is complete.\n\tUse this if you use screen, or if your terminal emulator forks into the background, as gnome-terminal does.\n\tDefault: no", "yes/no"
382
+ @confirm = false
383
+ @port = 51000
384
+ @term = "%cmd"
385
+ end
386
+
387
+ def description
388
+ "Choose a shell for launching sub-processes, and setup inter-process communication."
389
+ end
390
+
391
+ protected
392
+
393
+ def wait onoff
394
+ yes_no onoff,
395
+ lambda {@confirm = true},
396
+ lambda {@confirm = false}
397
+ end
398
+
399
+ def test
400
+ if mandatory
401
+ shell = CARPS::Process.new @term, @port, @confirm
402
+ puts "You should see 'It works!' in the new window."
403
+ mut = Test::Mutate.new
404
+ test_ipc shell, mut
405
+ if mut.working?
406
+ UI::highlight mut.works?
407
+ good = UI::confirm "Did it say 'It works!' in the new window?"
408
+ if good
409
+ shell.save
410
+ test_passed
411
+ else
412
+ general_fail
413
+ end
414
+ else
415
+ general_fail
416
+ end
417
+ end
418
+ end
419
+
420
+ def port pst
421
+ with_valid_port pst do |port|
422
+ @port = port
423
+ end
424
+ end
425
+
426
+ def terminal term
427
+ @term = term
428
+ end
429
+
430
+ private
431
+
432
+ def general_fail
433
+ multi_fail "The new terminal is detaching itself into the background.", "Port #{@port} is unavailable."
434
+ end
435
+
436
+ end
437
+
438
+ # Configure editor
439
+ class Editor < Interface
440
+
441
+ def initialize
442
+ super
443
+ add_raw_command :editor, "Specify a text editor.\n\tUse %f in place of the filepath.\n\t\tExample:\n\t\tvim %f", "COMMAND"
444
+ add_command :wait, "Wait until the user says the editor is finished. This may be useful if your editor forks into the background.\nDefault: no", "yes/no"
445
+ @confirm = false
446
+ end
447
+
448
+ def description
449
+ "Choose a text editor for editing character sheets, etc."
450
+ end
451
+
452
+ protected
453
+
454
+ def wait onoff
455
+ yes_no onoff,
456
+ lambda {@confirm = true},
457
+ lambda {@confirm = false}
458
+ end
459
+
460
+ def editor command
461
+ @editor = CARPS::Editor.new command, @confirm
462
+ end
463
+
464
+ def required
465
+ [[@editor, "editor"]]
466
+ end
467
+
468
+ def test
469
+ if mandatory
470
+ pass = CARPS::Test::editor @editor
471
+ if pass
472
+ @editor.save
473
+ test_passed
474
+ end
475
+ end
476
+ end
477
+
478
+ private
479
+
480
+ end
481
+
482
+ end
483
+
484
+ end
485
+
486
+ # Perform an action if the string describes a valid port number
487
+ def with_valid_port pst
488
+ port = pst.to_i
489
+ if port > 0 and port <= 65535
490
+ yield port
491
+ else
492
+ puts "The port must be a natural number, greater than zero and less than 65535."
493
+ end
494
+ end
@@ -0,0 +1,126 @@
1
+ # Copyright 2010 John Morrice
2
+
3
+ # This file is part of CARPS.
4
+
5
+ # CARPS is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # CARPS is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with CARPS. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "carps/service/interface"
19
+
20
+ require "carps/util"
21
+
22
+ require "carps/ui"
23
+
24
+ require "fileutils"
25
+
26
+ # A wizard is composed of a number of Interfaces.
27
+ # Each interface corresponds to a single configuration step.
28
+ # Each step is run in sequence.
29
+ # The wizard is complete after all its steps have completed.
30
+ module CARPS
31
+
32
+ # A wizard
33
+ class Wizard
34
+
35
+ def initialize files, dirs
36
+ @files = files
37
+ @dirs = dirs
38
+ @steps = []
39
+ end
40
+
41
+ # Run the wizard
42
+ def run
43
+ UI::highlight "Welcome to the CARPS Configuration Wizard"
44
+ puts ""
45
+ puts "This program will configure CARPS, under your instructions."
46
+ puts "There are a number of steps:"
47
+ puts ""
48
+ @steps.each_index do |step_num|
49
+ puts "#{step_num + 1}: #{@steps[step_num].description}"
50
+ end
51
+ puts ""
52
+ @steps.each do |step|
53
+ step.run
54
+ puts ""
55
+ end
56
+ UI::highlight "Tada! Wizard complete."
57
+ end
58
+
59
+ # Would this be the first time the wizard has run?
60
+ def first_time?
61
+ fs = @files.all? do |file|
62
+ real_file = $CONFIG + "/" + file
63
+ if File.exists? real_file
64
+ File.ftype(real_file) == "file"
65
+ else
66
+ false
67
+ end
68
+ end
69
+ ds = @dirs.all? do |dir|
70
+ real_dir = $CONFIG + "/" + dir
71
+ if File.exists? real_dir
72
+ File.ftype(real_dir) == "directory"
73
+ else
74
+ false
75
+ end
76
+ end
77
+ not (fs and ds)
78
+ end
79
+
80
+ # Create files
81
+ def create_files
82
+ create_all @files, "file" do |path|
83
+ FileUtils.touch path
84
+ end
85
+ end
86
+
87
+ # Create directories
88
+ def create_directories
89
+ create_all @dirs, "directory", do |path|
90
+ FileUtils.mkdir path
91
+ end
92
+ end
93
+
94
+ protected
95
+
96
+ # Set the files we are going to use
97
+ def set_files *files
98
+ @files = files
99
+ end
100
+
101
+ # Set the directories to create upon starting the wizard
102
+ def set_dirs *dirs
103
+ @dirs = dirs
104
+ end
105
+
106
+ # Set the steps the wizard is to use.
107
+ def set_steps *steps
108
+ @steps = steps
109
+ end
110
+
111
+ def create_all files, type
112
+ files.each do |dir|
113
+ real_dir = $CONFIG + "/" + dir
114
+ if File.exists? real_dir
115
+ unless File.ftype(real_dir) == type
116
+ CARPS::fatal "#{real_dir} was not a #{type}. CARPS needs this space: move it elsewhere!"
117
+ end
118
+ else
119
+ yield real_dir
120
+ end
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright 2010 John Morrice
2
+
3
+ # This file is part of CARPS.
4
+
5
+ # CARPS is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # CARPS is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with CARPS. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "carps/wizard/player"
19
+ require "carps/wizard/dm"
20
+ require "carps/wizard/steps"
21
+ require "carps/wizard/wizard"
data/lib/carps.rb ADDED
@@ -0,0 +1,45 @@
1
+ # Copyright 2010 John Morrice
2
+
3
+ # This file is part of CARPS.
4
+
5
+ # CARPS is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # CARPS is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with CARPS. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ $:.unshift(File.dirname(__FILE__)) unless
19
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
20
+
21
+ require "carps/util"
22
+ require "carps/protocol"
23
+ require "carps/email"
24
+ require "carps/crypt"
25
+ require "carps/service"
26
+ require "carps/mod"
27
+ require "carps/wizard"
28
+
29
+
30
+ # CARPS, the Computer Assisted Role-Playing Game System,
31
+ # is a tool for playing pen and paper RPGs over the internet.
32
+ #
33
+ # CARPS is:
34
+ #
35
+ # extensible; game rules are provided by extensions to CARPS.
36
+ #
37
+ # decentralized; CARPS' protocol is a layer on top of email.
38
+ #
39
+ # secure; CARPS messages are cryptographically signed to prevent spoofing
40
+ #
41
+ #
42
+ # The CARPS module which functions as a namespace for CARPS classes.
43
+ module CARPS
44
+ VERSION = '0.2.1'
45
+ end
data/permission ADDED
@@ -0,0 +1,16 @@
1
+ # Copyright 2010 John Morrice
2
+
3
+ # This file is part of CARPS.
4
+
5
+ # CARPS is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # CARPS is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with CARPS. If not, see <http://www.gnu.org/licenses/>.