gambit 0.1.0
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.
- data/AUTHORS +2 -0
- data/CHANGELOG +7 -0
- data/COPYING +340 -0
- data/INSTALL +23 -0
- data/LICENSE +7 -0
- data/README +25 -0
- data/Rakefile +87 -0
- data/TODO +6 -0
- data/examples/bird_wars/game.rb +434 -0
- data/examples/bird_wars/html/chest.rhtml +37 -0
- data/examples/bird_wars/html/combat.rhtml +38 -0
- data/examples/bird_wars/html/fight.rhtml +71 -0
- data/examples/bird_wars/html/fridge.rhtml +31 -0
- data/examples/bird_wars/html/help.rhtml +30 -0
- data/examples/bird_wars/html/house.rhtml +36 -0
- data/examples/bird_wars/html/images/albatross.jpg +0 -0
- data/examples/bird_wars/html/images/alka_seltzer_small.png +0 -0
- data/examples/bird_wars/html/images/bazooka_small.png +0 -0
- data/examples/bird_wars/html/images/bb_gun_small.png +0 -0
- data/examples/bird_wars/html/images/cat_small.png +0 -0
- data/examples/bird_wars/html/images/combat.png +0 -0
- data/examples/bird_wars/html/images/crossbow_small.png +0 -0
- data/examples/bird_wars/html/images/cuckoo.jpg +0 -0
- data/examples/bird_wars/html/images/fridge.png +0 -0
- data/examples/bird_wars/html/images/gull.jpg +0 -0
- data/examples/bird_wars/html/images/house.jpg +0 -0
- data/examples/bird_wars/html/images/items.png +0 -0
- data/examples/bird_wars/html/images/not_found.png +0 -0
- data/examples/bird_wars/html/images/note.jpg +0 -0
- data/examples/bird_wars/html/images/oil_small.png +0 -0
- data/examples/bird_wars/html/images/one_stone_small.png +0 -0
- data/examples/bird_wars/html/images/owl.jpg +0 -0
- data/examples/bird_wars/html/images/poisoned_seeds_small.png +0 -0
- data/examples/bird_wars/html/images/rice_small.png +0 -0
- data/examples/bird_wars/html/images/shotgun_small.png +0 -0
- data/examples/bird_wars/html/images/slingshot_small.png +0 -0
- data/examples/bird_wars/html/images/soda_rings_small.png +0 -0
- data/examples/bird_wars/html/images/spear_small.png +0 -0
- data/examples/bird_wars/html/images/stork.jpg +0 -0
- data/examples/bird_wars/html/images/weapons.png +0 -0
- data/examples/bird_wars/html/images/woodpecker.jpg +0 -0
- data/examples/bird_wars/html/images/you.jpg +0 -0
- data/examples/bird_wars/html/index.rhtml +13 -0
- data/examples/bird_wars/html/weapons.rhtml +35 -0
- data/examples/cli/blackjack.rb +86 -0
- data/examples/cli/go.rb +93 -0
- data/examples/cli/space_trader2/planet_data +12280 -0
- data/examples/cli/space_trader2/space_trader2.rb +248 -0
- data/examples/cli/space_trader2/world.rb +127 -0
- data/examples/cli/spacetrader.rb +262 -0
- data/examples/cli/yahtzee.rb +161 -0
- data/examples/galactic_courier/Rakefile +9 -0
- data/examples/galactic_courier/bin/galactic_courier.rb +44 -0
- data/examples/galactic_courier/html/console.rhtml +15 -0
- data/examples/galactic_courier/html/images/barren.jpg +0 -0
- data/examples/galactic_courier/html/images/industrial.jpg +0 -0
- data/examples/galactic_courier/html/images/jungle.jpg +0 -0
- data/examples/galactic_courier/html/images/oceanic.jpg +0 -0
- data/examples/galactic_courier/html/images/tundra.jpg +0 -0
- data/examples/galactic_courier/html/images/volcanic.jpg +0 -0
- data/examples/galactic_courier/lib/galaxy.rb +64 -0
- data/examples/galactic_courier/lib/planet.rb +30 -0
- data/examples/galactic_courier/lib/sector.rb +84 -0
- data/examples/galactic_courier/lib/station.rb +18 -0
- data/examples/galactic_courier/test/tc_galaxy.rb +24 -0
- data/examples/galactic_courier/test/tc_planet.rb +22 -0
- data/examples/galactic_courier/test/tc_sector.rb +55 -0
- data/examples/galactic_courier/test/ts_all.rb +12 -0
- data/examples/gambit_mail/html/compose.rhtml +39 -0
- data/examples/gambit_mail/html/index.rhtml +3 -0
- data/examples/gambit_mail/html/mailbox.rhtml +47 -0
- data/examples/gambit_mail/html/message.rhtml +34 -0
- data/examples/gambit_mail/mail.rb +75 -0
- data/lib/gambit.rb +10 -0
- data/lib/gambit/server.rb +269 -0
- data/lib/gambit/server/gambiterror.rb +28 -0
- data/lib/gambit/server/game.rb +185 -0
- data/lib/gambit/server/game/eventform.rb +174 -0
- data/lib/gambit/server/message.rb +85 -0
- data/lib/gambit/server/player.rb +40 -0
- data/lib/gambit/tools.rb +13 -0
- data/lib/gambit/tools/board.rb +275 -0
- data/lib/gambit/tools/cards.rb +11 -0
- data/lib/gambit/tools/cards/card.rb +158 -0
- data/lib/gambit/tools/cards/deck.rb +99 -0
- data/lib/gambit/tools/cards/hand.rb +86 -0
- data/lib/gambit/tools/cards/pile.rb +107 -0
- data/lib/gambit/tools/currency.rb +148 -0
- data/lib/gambit/tools/dice.rb +219 -0
- data/lib/gambit/tools/movehistory.rb +164 -0
- data/lib/gambit/tools/scorecard.rb +333 -0
- data/lib/gambit/viewable.rb +71 -0
- data/setup.rb +1360 -0
- data/test/tc_board.rb +167 -0
- data/test/tc_cards.rb +182 -0
- data/test/tc_currency.rb +99 -0
- data/test/tc_dice.rb +83 -0
- data/test/tc_error.rb +34 -0
- data/test/tc_event.rb +367 -0
- data/test/tc_game.rb +29 -0
- data/test/tc_message.rb +35 -0
- data/test/tc_movehistory.rb +38 -0
- data/test/tc_player.rb +60 -0
- data/test/tc_scorecard.rb +112 -0
- data/test/tc_views.rb +353 -0
- data/test/test_game.rb +19 -0
- data/test/test_view.rhtml +2 -0
- data/test/ts_all.rb +12 -0
- data/test/ts_server.rb +14 -0
- data/test/ts_tools.rb +14 -0
- metadata +183 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
# gambiterror.rb
|
|
4
|
+
#
|
|
5
|
+
# Created by James Edward Gray II on 2005-06-03.
|
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
|
7
|
+
|
|
8
|
+
require "webrick"
|
|
9
|
+
require "gambit/viewable"
|
|
10
|
+
|
|
11
|
+
module Gambit
|
|
12
|
+
class Server < WEBrick::HTTPServer
|
|
13
|
+
class GambitError < RuntimeError
|
|
14
|
+
include Gambit::Viewable
|
|
15
|
+
register_view(:error_page, <<-END_ERROR.gsub(/^\t{3}/, ""))
|
|
16
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
17
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
18
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
19
|
+
<head>
|
|
20
|
+
<title>GambitError</title>
|
|
21
|
+
</head><body>
|
|
22
|
+
<h1>Gambit Has Thrown An Error</h1>
|
|
23
|
+
<p><%= message %></p>
|
|
24
|
+
</body></html>
|
|
25
|
+
END_ERROR
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
# game.rb
|
|
4
|
+
#
|
|
5
|
+
# Created by James Edward Gray II on 2005-06-03.
|
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
|
7
|
+
|
|
8
|
+
require "webrick"
|
|
9
|
+
require "optparse"
|
|
10
|
+
require "gambit/viewable"
|
|
11
|
+
require "gambit/server"
|
|
12
|
+
require "gambit/server/game/eventform"
|
|
13
|
+
require "gambit/server/gambiterror"
|
|
14
|
+
|
|
15
|
+
module Gambit
|
|
16
|
+
class Server < WEBrick::HTTPServer
|
|
17
|
+
class Game
|
|
18
|
+
@@gambit_game = nil
|
|
19
|
+
@@gambit_game_run = false
|
|
20
|
+
def self.inherited( game )
|
|
21
|
+
if @@gambit_game.nil?
|
|
22
|
+
@@gambit_game = game
|
|
23
|
+
else
|
|
24
|
+
raise RuntimeError, "There can only be one game class."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
def self.run?( )
|
|
28
|
+
@@gambit_game_run
|
|
29
|
+
end
|
|
30
|
+
def self.run=( true_or_false )
|
|
31
|
+
@@gambit_game_run = true_or_false
|
|
32
|
+
end
|
|
33
|
+
def self.run( )
|
|
34
|
+
@@gambit_game_run = true
|
|
35
|
+
|
|
36
|
+
port = 80
|
|
37
|
+
html = "html"
|
|
38
|
+
daemon = false
|
|
39
|
+
test_mode = false
|
|
40
|
+
|
|
41
|
+
ARGV.options do |opts|
|
|
42
|
+
opts.banner = "Usage: #{File.basename($0)} [OPTIONS]"
|
|
43
|
+
|
|
44
|
+
opts.separator ""
|
|
45
|
+
opts.separator "Specific Options:"
|
|
46
|
+
|
|
47
|
+
opts.on( "-p", "--port PORT", Integer,
|
|
48
|
+
"Set the PORT to server pages on." ) do |p|
|
|
49
|
+
port = p
|
|
50
|
+
end
|
|
51
|
+
opts.on( "-h", "--html_dir DIR",
|
|
52
|
+
"The DIR holding your game views." ) do |h|
|
|
53
|
+
html = h
|
|
54
|
+
end
|
|
55
|
+
opts.on( "-d", "--[no-]daemon",
|
|
56
|
+
"Run server as daemon." ) do |d|
|
|
57
|
+
daemon = d
|
|
58
|
+
end
|
|
59
|
+
opts.on( "-t", "--[no-]test",
|
|
60
|
+
"Create test game and player." ) do |t|
|
|
61
|
+
test_mode = t
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
opts.separator "Common Options:"
|
|
65
|
+
|
|
66
|
+
opts.on("-?", "--help", "Show this message.") do
|
|
67
|
+
puts opts
|
|
68
|
+
return 0
|
|
69
|
+
end
|
|
70
|
+
end.parse!
|
|
71
|
+
|
|
72
|
+
server = Gambit::Server.new(@@gambit_game, port, html, daemon)
|
|
73
|
+
server.test_mode if test_mode
|
|
74
|
+
server.start
|
|
75
|
+
|
|
76
|
+
0
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
include Gambit::Viewable
|
|
80
|
+
register_view(:login, <<-END_LOGIN.gsub(/^\t{3}/, ""))
|
|
81
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
82
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
83
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
84
|
+
<head>
|
|
85
|
+
<title>Login</title>
|
|
86
|
+
</head><body>
|
|
87
|
+
<%= event(nil, "login") do
|
|
88
|
+
text "login"
|
|
89
|
+
password "password"
|
|
90
|
+
submit "Login"
|
|
91
|
+
end %>
|
|
92
|
+
</body></html>
|
|
93
|
+
END_LOGIN
|
|
94
|
+
register_view(:configure, <<-END_CONFIGURE.gsub(/^\t{3}/, ""))
|
|
95
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
96
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
97
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
98
|
+
<head>
|
|
99
|
+
<title>Configure Game</title>
|
|
100
|
+
</head><body>
|
|
101
|
+
<%= event(nil, "configure") do
|
|
102
|
+
text "game_name"
|
|
103
|
+
submit "Create"
|
|
104
|
+
end %>
|
|
105
|
+
</body></html>
|
|
106
|
+
END_CONFIGURE
|
|
107
|
+
|
|
108
|
+
def initialize( )
|
|
109
|
+
@name = "Game number: #{object_id}."
|
|
110
|
+
|
|
111
|
+
@player = nil
|
|
112
|
+
@event = nil
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
attr_accessor :player
|
|
116
|
+
attr_reader :name
|
|
117
|
+
|
|
118
|
+
def do_configure( player, details = Hash.new )
|
|
119
|
+
unless details["game_name"].nil? or details["game_name"].empty?
|
|
120
|
+
@name = details["game_name"]
|
|
121
|
+
end
|
|
122
|
+
"index.rhtml"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def do_event( player, event, details = Hash.new )
|
|
126
|
+
@player = player
|
|
127
|
+
@event = event
|
|
128
|
+
|
|
129
|
+
event_method = "do_#{event}"
|
|
130
|
+
if respond_to? event_method
|
|
131
|
+
send("do_#{event}", player, details)
|
|
132
|
+
else
|
|
133
|
+
raise Gambit::Server::GambitError,
|
|
134
|
+
"Method #{event_method} not implemented."
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def do_login( player, details = Hash.new )
|
|
139
|
+
"index.rhtml"
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def event( label, name, parameters = Hash.new, &form )
|
|
143
|
+
url = "/event/#{object_id}/#{name}"
|
|
144
|
+
if form.nil?
|
|
145
|
+
details = parameters.sort_by { |(key, value)| key }.
|
|
146
|
+
map { |(n, v)| "#{u(n)}=#{u(v)}" }.
|
|
147
|
+
join("&")
|
|
148
|
+
url += "?#{details}" unless details.empty?
|
|
149
|
+
|
|
150
|
+
if label.nil?
|
|
151
|
+
url
|
|
152
|
+
else
|
|
153
|
+
"<a class=\"event\" href=\"#{url}\">#{label}</a>"
|
|
154
|
+
end
|
|
155
|
+
else
|
|
156
|
+
Gambit::Server::Game::EventForm.new( url, label,
|
|
157
|
+
parameters,
|
|
158
|
+
&form ).view(:event)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def event_binding( )
|
|
163
|
+
binding
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def notify( )
|
|
167
|
+
if @player.nil? or @player.notes.empty?
|
|
168
|
+
""
|
|
169
|
+
else
|
|
170
|
+
notes = "<ul class=\"notification\">\n"
|
|
171
|
+
until @player.notes.empty?
|
|
172
|
+
notes += "\t<li>#{@player.notes.shift}</li>\n"
|
|
173
|
+
end
|
|
174
|
+
notes += "</ul>\n"
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
at_exit do
|
|
182
|
+
unless $! or Gambit::Server::Game.run?
|
|
183
|
+
exit Gambit::Server::Game.run
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
# eventform.rb
|
|
4
|
+
#
|
|
5
|
+
# Created by James Edward Gray II on 2005-06-03.
|
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
|
7
|
+
|
|
8
|
+
require "webrick"
|
|
9
|
+
require "gambit/viewable"
|
|
10
|
+
|
|
11
|
+
module Gambit
|
|
12
|
+
class Server < WEBrick::HTTPServer
|
|
13
|
+
class Game
|
|
14
|
+
class EventForm
|
|
15
|
+
include Gambit::Viewable
|
|
16
|
+
register_view(:event, <<-END_EVENT_VIEW.gsub(/^\t{4}/, ""))
|
|
17
|
+
<form class="event" method="post" action="<%= @url %>">
|
|
18
|
+
% unless @intro.nil? or @intro.empty?
|
|
19
|
+
% if @intro.is_a? Array
|
|
20
|
+
<p class="intro"><%= @intro.
|
|
21
|
+
join("</p>\\n\\t<p class=\\"intro\\">") %></p>
|
|
22
|
+
% else
|
|
23
|
+
<p class="intro"><%= @intro %></p>
|
|
24
|
+
% end
|
|
25
|
+
% end
|
|
26
|
+
% unless @elements.empty?
|
|
27
|
+
<%= view((@element_style.to_s + "_elements").to_sym) %>
|
|
28
|
+
% end
|
|
29
|
+
% @hidden_fields.each do |hidden|
|
|
30
|
+
<%= hidden %>
|
|
31
|
+
% end
|
|
32
|
+
<p><%= @submit %> <%= @reset %></p>
|
|
33
|
+
</form>
|
|
34
|
+
END_EVENT_VIEW
|
|
35
|
+
register_view( :dl_elements,
|
|
36
|
+
<<-END_DL_ELEMENTS_VIEW.gsub(/^\t{4}/, "") )
|
|
37
|
+
<dl>
|
|
38
|
+
% @elements.each do |element|
|
|
39
|
+
% name = element[/name="[^"]+"/][6..-2]
|
|
40
|
+
% if element =~ /^<input type="(?:checkbox|radio)"/
|
|
41
|
+
<dt><%= name.capitalize.tr("_", " ") %>:</dt>
|
|
42
|
+
<dd><%= element %></dd>
|
|
43
|
+
% else
|
|
44
|
+
<dt><label for="<%= name %>"><%=
|
|
45
|
+
name.capitalize.tr("_", " ") %>:</label></dt>
|
|
46
|
+
<dd><%= element %></dd>
|
|
47
|
+
% end
|
|
48
|
+
% end
|
|
49
|
+
</dl>
|
|
50
|
+
END_DL_ELEMENTS_VIEW
|
|
51
|
+
register_view( :p_elements,
|
|
52
|
+
<<-END_P_ELEMENTS_VIEW.gsub(/^\t{4}/, "") )
|
|
53
|
+
% @elements.each do |element|
|
|
54
|
+
% if element =~ /^<(?:input|textarea|select)/
|
|
55
|
+
% name = element[/name="[^"]+"/][6..-2]
|
|
56
|
+
% if element =~ /^<input type="(?:checkbox|radio)"/
|
|
57
|
+
<p><%= name.capitalize.tr("_", " ") %>: <%= element %></p>
|
|
58
|
+
% else
|
|
59
|
+
<p><label for="<%= name %>"><%=
|
|
60
|
+
name.capitalize.tr("_", " ") %>:</label> <%=
|
|
61
|
+
element %></p>
|
|
62
|
+
% end
|
|
63
|
+
% else
|
|
64
|
+
<%= element %>
|
|
65
|
+
% end
|
|
66
|
+
% end
|
|
67
|
+
END_P_ELEMENTS_VIEW
|
|
68
|
+
|
|
69
|
+
def initialize( url, intro, hidden, &init )
|
|
70
|
+
@url = url
|
|
71
|
+
@intro = intro
|
|
72
|
+
|
|
73
|
+
@elements = Array.new
|
|
74
|
+
@hidden_fields = Array.new
|
|
75
|
+
submit("Submit")
|
|
76
|
+
reset("Reset")
|
|
77
|
+
|
|
78
|
+
@element_style = :dl
|
|
79
|
+
|
|
80
|
+
hidden.each { |(name, value)| hidden(name, value) }
|
|
81
|
+
self.instance_eval(&init)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def checks( group, names, options = Hash.new )
|
|
85
|
+
tags = ""
|
|
86
|
+
names.each do |name|
|
|
87
|
+
tags << " <input type=\"checkbox\" " +
|
|
88
|
+
"id=\"#{name}\" " +
|
|
89
|
+
"name=\"#{group}\" value=\"#{name}\"" +
|
|
90
|
+
"#{htmlify(options[name])} />" +
|
|
91
|
+
"<label for=\"#{name}\">" +
|
|
92
|
+
"#{name.capitalize.tr("_", " ")}</label>"
|
|
93
|
+
end
|
|
94
|
+
@elements << tags.strip
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def document( name, default_text = nil, options = Hash.new )
|
|
98
|
+
@elements << "<textarea id=\"#{name}\" name=\"#{name}\"" +
|
|
99
|
+
"#{htmlify(options)}>" +
|
|
100
|
+
"#{default_text || ''}</textarea>"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def hidden( name, value )
|
|
104
|
+
@hidden_fields << "<input type=\"hidden\" " +
|
|
105
|
+
"name=\"#{name}\" " +
|
|
106
|
+
"value=\"#{value}\" />"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def html( tags )
|
|
110
|
+
@element_style = :p
|
|
111
|
+
|
|
112
|
+
@elements << tags
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def menu( name, values, options = Hash.new,
|
|
116
|
+
menu_options = Hash.new )
|
|
117
|
+
tags = "<select id=\"#{name}\" name=\"#{name}\"" +
|
|
118
|
+
"#{htmlify(menu_options)}>"
|
|
119
|
+
tags << values.map do |value|
|
|
120
|
+
"<option value=\"#{value}\"" +
|
|
121
|
+
"#{htmlify(options[value])}>" +
|
|
122
|
+
"#{value.capitalize.tr("_", " ")}</option>"
|
|
123
|
+
end.join
|
|
124
|
+
tags << "</select>"
|
|
125
|
+
@elements << tags.strip
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def password( name, options = Hash.new )
|
|
129
|
+
@elements << "<input type=\"password\" " +
|
|
130
|
+
"id=\"#{name}\" name=\"#{name}\"" +
|
|
131
|
+
"#{htmlify(options)} />"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def radios( group, names, options = Hash.new )
|
|
135
|
+
tags = ""
|
|
136
|
+
names.each do |name|
|
|
137
|
+
tags << " <input type=\"radio\" " +
|
|
138
|
+
"id=\"#{name}\" " +
|
|
139
|
+
"name=\"#{group}\" value=\"#{name}\"" +
|
|
140
|
+
"#{htmlify(options[name])} />" +
|
|
141
|
+
"<label for=\"#{name}\">" +
|
|
142
|
+
"#{name.capitalize.tr("_", " ")}</label>"
|
|
143
|
+
end
|
|
144
|
+
@elements << tags.strip
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def reset( name, options = Hash.new )
|
|
148
|
+
@reset = "<input type=\"reset\" value=\"#{name}\"" +
|
|
149
|
+
"#{htmlify(options)} />"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def submit( name, options = Hash.new )
|
|
153
|
+
@submit = "<input type=\"submit\" value=\"#{name}\"" +
|
|
154
|
+
"#{htmlify(options)} />"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def text( name, options = Hash.new )
|
|
158
|
+
@elements << "<input type=\"text\" " +
|
|
159
|
+
"id=\"#{name}\" name=\"#{name}\"" +
|
|
160
|
+
"#{htmlify(options)} />"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
private
|
|
164
|
+
|
|
165
|
+
def htmlify( options )
|
|
166
|
+
return "" if options.nil?
|
|
167
|
+
options.inject("") do |str, (key, value)|
|
|
168
|
+
str << " #{key}=\"#{value.to_s.gsub(/"/, '"')}\""
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
|
2
|
+
|
|
3
|
+
# message.rb
|
|
4
|
+
#
|
|
5
|
+
# Created by Gregory Brown on 2005-06-04
|
|
6
|
+
# Copyright 2005 smtose.org. All rights reserved.
|
|
7
|
+
|
|
8
|
+
require "webrick"
|
|
9
|
+
require "gambit/viewable"
|
|
10
|
+
require "net/smtp"
|
|
11
|
+
|
|
12
|
+
module Gambit
|
|
13
|
+
class Server < WEBrick::HTTPServer
|
|
14
|
+
class Message
|
|
15
|
+
include Gambit::Viewable
|
|
16
|
+
register_view(:gambit_text, <<-END_TEXT_FULL.gsub(/^\t{3}/,""))
|
|
17
|
+
From: <%= @from %>
|
|
18
|
+
To: <%= @to %>
|
|
19
|
+
% unless @cc.empty?
|
|
20
|
+
CC: <%= @cc.join(', ') %>
|
|
21
|
+
% end
|
|
22
|
+
Subject: <%= @subject %>
|
|
23
|
+
|
|
24
|
+
<%= @body+ "\\n"%>
|
|
25
|
+
|
|
26
|
+
Sent: <%= @time %>
|
|
27
|
+
END_TEXT_FULL
|
|
28
|
+
register_view(:gambit_text_short,
|
|
29
|
+
<<-END_TEXT_SHORT.gsub(/^\t{3}/,""))
|
|
30
|
+
<%= @from %> <%= @subject %> Sent: <%= @time %>
|
|
31
|
+
END_TEXT_SHORT
|
|
32
|
+
register_view(:gambit_html, <<-END_HTML_FULL.gsub(/^\t{3}/,""))
|
|
33
|
+
<table class="message">
|
|
34
|
+
<tr>
|
|
35
|
+
<td colspan="2" id="time"><%= @time %></td>
|
|
36
|
+
</tr>
|
|
37
|
+
<tr>
|
|
38
|
+
<td colspan="2" id="subject">
|
|
39
|
+
<%= @subject %>
|
|
40
|
+
</td>
|
|
41
|
+
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
<td colspan="2" id="body"><%= @body %></td>
|
|
44
|
+
</tr>
|
|
45
|
+
<tr>
|
|
46
|
+
<td id="from">From: <%= @from %></td>
|
|
47
|
+
<td id="to">To: <%= @to %></td>
|
|
48
|
+
</tr>
|
|
49
|
+
</table>
|
|
50
|
+
END_HTML_FULL
|
|
51
|
+
register_view(:gambit_html_short,
|
|
52
|
+
<<-END_HTML_SHORT.gsub(/^\t{3}/,""))
|
|
53
|
+
<ul class="message_short">
|
|
54
|
+
<li class="from_short"> <%= @from %> </li>
|
|
55
|
+
<li class="subject_short">
|
|
56
|
+
<%= @subject %>
|
|
57
|
+
</li>
|
|
58
|
+
<li class="time_short"> <%= @time %> </li>
|
|
59
|
+
</ul>
|
|
60
|
+
END_HTML_SHORT
|
|
61
|
+
|
|
62
|
+
def initialize(from,to,subject,body)
|
|
63
|
+
@from = from
|
|
64
|
+
@to = to
|
|
65
|
+
@subject = subject
|
|
66
|
+
@body = body
|
|
67
|
+
@time = Time.now
|
|
68
|
+
@cc = Array.new
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
attr_reader :cc, :time, :from, :to, :subject, :body
|
|
72
|
+
|
|
73
|
+
def smtp_send(smtp_host)
|
|
74
|
+
Net::SMTP.start(smtp_host) do |smtp|
|
|
75
|
+
smtp.send_message(@body,@from,@to)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def send(other_player)
|
|
80
|
+
#lookup player in server
|
|
81
|
+
#player.add_message(self)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|