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,93 @@
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/util/windows"
19
+ require "carps/util/process"
20
+ require "carps/util/config"
21
+
22
+ require "erb"
23
+
24
+ # Don't do this if you're building the program
25
+ unless $IN_RAKE
26
+ # Requiring this file cripples ERB
27
+ #
28
+ # This is because it does not work with $SAFE = 1
29
+ # and this is not checked by highline
30
+ class ERB
31
+
32
+ def initialize str, *args
33
+ @res = str
34
+ end
35
+
36
+ def result *args
37
+ @res
38
+ end
39
+
40
+ end
41
+ end
42
+
43
+ module CARPS
44
+
45
+ # Set up multi-threading
46
+ #
47
+ # Can be called more than once
48
+ def CARPS::init_threading
49
+ Thread.abort_on_exception = true
50
+ end
51
+
52
+ # The root config directory
53
+ #
54
+ # This performs an untaint operation
55
+ def CARPS::root_config
56
+ loc = nil
57
+ # If it's windows
58
+ if CARPS::windows?
59
+ loc = ENV["USERPROFILE"]
60
+ else
61
+ # Otherwise assume it's a unix-like system
62
+ loc = ENV["HOME"]
63
+ end
64
+ if loc
65
+ loc += "/carps/"
66
+ loc.untaint
67
+ else
68
+ CARPS::fatal "Could not find home directory."
69
+ end
70
+ end
71
+
72
+ # Set the configuration directory
73
+ def CARPS::config_dir dir
74
+ $CONFIG = CARPS::root_config + dir + "/"
75
+ end
76
+
77
+ # Initialize carps
78
+ #
79
+ # Optionally set the config_dir at the same time
80
+ #
81
+ # Sets $SAFE to safe, default 1
82
+ #
83
+ # FIXME: instead of setting a global variable, should use the singleton pattern
84
+ def CARPS::init safe=1, dir=nil
85
+
86
+ $SAFE = safe
87
+ if dir
88
+ config_dir dir
89
+ end
90
+ CARPS::init_threading
91
+ end
92
+
93
+ end
@@ -0,0 +1,150 @@
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/util/config"
19
+
20
+ require "carps/ui/error"
21
+
22
+ require "drb"
23
+ require "drb/acl"
24
+
25
+ require "set"
26
+
27
+ module CARPS
28
+
29
+ # Responsible for launching other CARP processes
30
+ class Process < SystemConfig
31
+
32
+ # Get the process singleton
33
+ def Process.singleton
34
+ unless @process
35
+ @process = Process.load
36
+ end
37
+ @process
38
+ end
39
+
40
+ def Process.filepath
41
+ "process.yaml"
42
+ end
43
+
44
+ def initialize term, port, confirm = false
45
+ load_resources term, port, confirm
46
+ end
47
+
48
+ def parse_yaml conf
49
+ term = read_conf conf, "launch_terminal"
50
+ port = read_conf(conf, "port").to_i
51
+ confirm = read_conf conf, "wait"
52
+ [term, port, confirm]
53
+ end
54
+
55
+ def load_resources term, port, confirm
56
+ @port = port
57
+ @term = term
58
+ @semaphore = Mutex.new
59
+ @confirm = confirm
60
+ end
61
+
62
+ # Launch a ruby program in another terminal window, which can access the resource over drb
63
+ def launch resource, program
64
+ @semaphore.synchronize do
65
+ uri = share resource
66
+ if uri
67
+ cmd = shell_cmd program, uri
68
+ puts "Launching: #{cmd}"
69
+ system cmd
70
+ stop_sharing
71
+ end
72
+ end
73
+ end
74
+
75
+ # Stop sharing a resource.
76
+ def stop_sharing
77
+ if @confirm
78
+ UI::question "Press enter when the sub-program has completed."
79
+ end
80
+ begin
81
+ DRb.stop_service
82
+ rescue StandardError => e
83
+ UI::put_error "Could not stop IPC: #{e}"
84
+ end
85
+ end
86
+
87
+ # Run a block in a new process, allowing access the first argument by passing it a URI referring to a DRb object.
88
+ #
89
+ # If already running, then the process will not launch until till the first process has completed.
90
+ def share resource
91
+ begin
92
+ local_only = ACL.new %w[deny all allow 127.0.0.1]
93
+ DRb.install_acl local_only
94
+ uri = "druby://localhost:" + @port.to_s
95
+ DRb.start_service uri, resource
96
+ return uri
97
+ rescue StandardError => e
98
+ UI::put_error "Error beginning CARPS-side IPC: #{e}"
99
+ return nil
100
+ end
101
+ end
102
+
103
+ protected
104
+
105
+ # Emit as hash
106
+ def emit
107
+ {"launch_terminal" => @term, "port" => @port, "wait" => @confirm}
108
+ end
109
+
110
+ # The command which would open a new window running the given command
111
+ def shell_cmd program, uri
112
+ program = program + " " + uri
113
+ @term.gsub "%cmd", program
114
+ end
115
+
116
+ end
117
+
118
+ # Testing utilities, for the wizard (also used for unit tests)
119
+ module Test
120
+ class Mutate
121
+
122
+ include DRbUndumped
123
+
124
+ def initialize
125
+ @works = "WORK IT DOES NOT!"
126
+ @working = false
127
+ end
128
+
129
+ def mutate!
130
+ @works = "It works!"
131
+ @working = true
132
+ end
133
+
134
+ def works?
135
+ @works
136
+ end
137
+
138
+ def working?
139
+ @working
140
+ end
141
+
142
+ end
143
+ end
144
+
145
+ end
146
+
147
+ # Test IPC
148
+ def test_ipc process, mut
149
+ process.launch mut, "carps_ipc_test"
150
+ end
@@ -0,0 +1,31 @@
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 "timeout"
19
+
20
+ # Timeout the block after n seconds, raising an error stating that description timed out.
21
+ module CARPS
22
+
23
+ def CARPS::timeout n, description, &todo
24
+ begin
25
+ Timeout::timeout n, &todo
26
+ rescue Timeout::Error => e
27
+ raise Timeout::Error, "'#{description}' timed out after #{n} seconds."
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,29 @@
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
+ module CARPS
19
+
20
+ # Is this windows?
21
+ def CARPS::windows?
22
+ if RUBY_PLATFORM.match(/(win|w)32/)
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ end
data/lib/carps/util.rb ADDED
@@ -0,0 +1,24 @@
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/util/windows"
19
+ require "carps/util/config"
20
+ require "carps/util/editor"
21
+ require "carps/util/files"
22
+ require "carps/util/init"
23
+ require "carps/util/process"
24
+ require "carps/util/timeout"
@@ -0,0 +1,41 @@
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/steps"
19
+
20
+ require "carps/wizard/wizard"
21
+
22
+ module CARPS
23
+
24
+ module DM
25
+
26
+ # A wizard for configuring the Dungeon Master
27
+ class Wizard < CARPS::Wizard
28
+
29
+ def initialize
30
+ files = ["../mods.yaml", "email.yaml", "process.yaml", "editor.yaml"]
31
+ dirs = ["games", ".peers", ".mail", "campaigns"]
32
+ super files, dirs
33
+ set_steps Setup::Editor.new, Setup::Process.new, Setup::Email.new
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,40 @@
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/steps"
19
+
20
+ require "carps/wizard/wizard"
21
+
22
+ module CARPS
23
+
24
+ module Player
25
+
26
+ # A wizard for configuring the player
27
+ class Wizard < CARPS::Wizard
28
+
29
+ def initialize
30
+ files = ["../mods.yaml", "email.yaml", "process.yaml", "editor.yaml"]
31
+ dirs = ["games", ".peers", ".mail"]
32
+ super files, dirs
33
+ set_steps Setup::Editor.new, Setup::Process.new, Setup::Email.new
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end