dragongoserver 0.3.1 → 0.4.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.
@@ -0,0 +1,16 @@
1
+ ---
2
+ :number_of_games: 3
3
+ :size: 19
4
+ :main_time:
5
+ - 15
6
+ - :days
7
+ :japanese_byoyomi:
8
+ - 1
9
+ - :hours
10
+ - 24
11
+ - :extra_periods
12
+ :rated_game: true
13
+ :clock_runs_on_weekend: false
14
+ :require_rated_opponent: true
15
+ :relative_range: 9
16
+ :comment: added by dragongoserver ruby gem
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.4.0 2009-07-13
2
+
3
+ * 1 enhancement:
4
+ * new option --add-game (add a game in the waiting room)
5
+
1
6
  == 0.3.1 2009-07-10
2
7
 
3
8
  * 1 bug-fix:
data/Manifest.txt ADDED
@@ -0,0 +1,60 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ README.txt
7
+ Rakefile
8
+ TODO
9
+ bin/dgs
10
+ config/hoe.rb
11
+ config/requirements.rb
12
+ examples/example1.rb
13
+ examples/id.dat
14
+ examples/userlist.out
15
+ examples/userlist.rb
16
+ examples/userlist2.rb
17
+ lib/dragongoserver.rb
18
+ lib/dragongoserver/dragongoserver.rb
19
+ lib/dragongoserver/game.rb
20
+ lib/dragongoserver/version.rb
21
+ log/debug.log
22
+ pkg/dragongoserver-0.3.0.gem
23
+ pkg/dragongoserver-0.3.0.tgz
24
+ pkg/dragongoserver-0.3.0/History.txt
25
+ pkg/dragongoserver-0.3.0/License.txt
26
+ pkg/dragongoserver-0.3.0/Manifest.txt
27
+ pkg/dragongoserver-0.3.0/README.txt
28
+ pkg/dragongoserver-0.3.0/Rakefile
29
+ pkg/dragongoserver-0.3.0/bin/dgs
30
+ pkg/dragongoserver-0.3.0/config/hoe.rb
31
+ pkg/dragongoserver-0.3.0/config/requirements.rb
32
+ pkg/dragongoserver-0.3.0/examples/example1.rb
33
+ pkg/dragongoserver-0.3.0/lib/dragongoserver.rb
34
+ pkg/dragongoserver-0.3.0/lib/dragongoserver/dragongoserver.rb
35
+ pkg/dragongoserver-0.3.0/lib/dragongoserver/game.rb
36
+ pkg/dragongoserver-0.3.0/lib/dragongoserver/version.rb
37
+ pkg/dragongoserver-0.3.0/log/debug.log
38
+ pkg/dragongoserver-0.3.0/script/destroy
39
+ pkg/dragongoserver-0.3.0/script/generate
40
+ pkg/dragongoserver-0.3.0/setup.rb
41
+ pkg/dragongoserver-0.3.0/tasks/deployment.rake
42
+ pkg/dragongoserver-0.3.0/tasks/environment.rake
43
+ pkg/dragongoserver-0.3.0/tasks/website.rake
44
+ pkg/dragongoserver-0.3.0/test/test_dragongoserver.rb
45
+ pkg/dragongoserver-0.3.0/test/test_helper.rb
46
+ script/console
47
+ script/destroy
48
+ script/generate
49
+ script/txt2html
50
+ setup.rb
51
+ tasks/deployment.rake
52
+ tasks/environment.rake
53
+ tasks/website.rake
54
+ test/test_dragongoserver.rb
55
+ test/test_helper.rb
56
+ website/index.html
57
+ website/index.txt
58
+ website/javascripts/rounded_corners_lite.inc.js
59
+ website/stylesheets/screen.css
60
+ website/template.rhtml
data/README.txt CHANGED
@@ -1,44 +1,48 @@
1
- # some example how you can use this gem within your programs
1
+ dragongoserver
2
+ by Thomas Preymesser
3
+ http://dragongoserver.rubyforge.org/
2
4
 
3
- require 'rubygems'
4
- require 'dragongoserver'
5
- require 'gorank'
5
+ == DESCRIPTION:
6
6
 
7
- dgs = Dgs.new
7
+ The dragongoserver gem allows you to use the Go Server (http://www.dragongoserver.net) from ruby programs.
8
8
 
9
- # get own user id at DGS
9
+ == FEATURES/PROBLEMS:
10
10
 
11
- id = dgs.userid
12
- puts "your user-id: #{id}"
11
+ * test (list of features or problems)
13
12
 
14
- # your rank
13
+ == SYNOPSIS:
15
14
 
16
- rank = dgs.get_rank
15
+ test (code sample of usage)
17
16
 
18
- puts "your rank:"
19
- p rank.to_s
17
+ == REQUIREMENTS:
20
18
 
21
- # your user infos
19
+ * test (list of requirements)
22
20
 
23
- infos = dgs.userinfo(id)
21
+ == INSTALL:
24
22
 
25
- puts "your attributes at DGS:"
26
- p infos
23
+ * sudo gem install dragongoserver
27
24
 
28
- # waiting games
25
+ == LICENSE:
29
26
 
30
- wg = dgs.waiting_games
27
+ (The MIT License)
31
28
 
32
- puts 'waiting games:'
33
- p wg
29
+ Copyright (c) 2007,2008,2009
34
30
 
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
35
38
 
36
- # you can get info for every other user
37
- # user with user id 8000
38
- user_8000 = dgs.userinfo(8000)
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
39
41
 
40
- puts "user 8000:"
41
- p user_8000
42
-
43
- # see also the homepage of this gem for examples to use the
44
- # command line script 'dgs'
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'dragongoserver'
18
+
19
+ task :default => 'spec:run'
20
+
21
+ PROJ.name = 'dragongoserver'
22
+ PROJ.authors = 'Thomas Preymesser'
23
+ PROJ.email = 'thopre@gmail.com'
24
+ PROJ.url = 'http://dragongoserver.rubyforge.org/'
25
+ PROJ.version = Dragongoserver::VERSION
26
+ PROJ.rubyforge.name = 'dragongoserver'
27
+ PROJ.gem.executables = ['dgs']
28
+ PROJ.gem.dependencies = [
29
+ ['mechanize', '>= 0.9.2'],
30
+ ['go-rank', '>= 0.0.1'],
31
+ ['choice', '>= 0.1.2'],
32
+ ['hpricot', '>= 0.6'],
33
+ ]
34
+
35
+ PROJ.spec.opts << '--color'
36
+
37
+ # EOF
data/bin/dgs CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
5
5
  require 'dragongoserver'
6
6
  require 'choice'
7
7
 
8
- version = Dragongoserver::VERSION::STRING
8
+ version = Dragongoserver::VERSION
9
9
  Choice.options do
10
10
  # header ''
11
11
  # header 'Specific options:'
@@ -91,6 +91,12 @@ Choice.options do
91
91
  default 1
92
92
  end
93
93
 
94
+ option :add_game do
95
+ short '-a'
96
+ long '--add-game'
97
+ desc 'Add a new game in the waiting room'
98
+ end
99
+
94
100
  end
95
101
 
96
102
  if Choice.choices['check_timeout_finished']
@@ -121,6 +127,7 @@ opt_finished_games = Choice.choices['finished_games'] # true/false
121
127
  $opt_with_name = Choice.choices['with_name'] # true/false
122
128
  @opt_osd = Choice.choices['osd'] # true/false
123
129
  opt_waitingloop = Choice.choices['waitingloop'] # true/false
130
+ opt_add_game = Choice.choices['add_game'] # true/false
124
131
  if opt_waiting
125
132
  dgs = Dgs.new
126
133
  waiting_games = dgs.waiting_games
@@ -322,3 +329,9 @@ if opt_waitingloop
322
329
  end
323
330
 
324
331
  end
332
+
333
+ if opt_add_game
334
+ dgs = Dgs.new
335
+ dgs.add_game
336
+ puts "1 Game(s) added to the waiting room"
337
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib dragongoserver]))
5
+
6
+ # Put your code here
7
+
8
+ # EOF
@@ -5,10 +5,17 @@ require 'hpricot'
5
5
  #require 'pp'
6
6
 
7
7
  class Dgs
8
+ # text if not logged in
8
9
  LOGGED_IN="Sorry, you have to be logged in to do that"
10
+ # your turn message
9
11
  YOUR_TURN="Your turn to move in the following games"
12
+ # DGS Status page
10
13
  DGS_STATUS_PAGE = 'http://www.dragongoserver.net/status.php/'
14
+ # DGS Index page
11
15
  DGS_INDEX_PAGE = 'http://www.dragongoserver.net/index.php'
16
+ # DGS Waiting room page
17
+ DGS_WAITING_ROOM_PAGE = 'http://www.dragongoserver.net/waiting_room.php'
18
+ # User agent
12
19
  USER_AGENT_ALIAS = 'Mac Safari' # should work with every browser type
13
20
 
14
21
  SAVE_WAIT = 15 # wait n seconds before each request
@@ -196,9 +203,9 @@ class Dgs
196
203
  form.sf1 = user_id.to_s
197
204
 
198
205
  page = agent.submit(form)
199
- # page = agent.click page.links.text("#{user_id}")
206
+ # page = agent.click page.links.text("#{user_id}")
200
207
  page = agent.click page.link_with(:text => "#{user_id}")
201
- # page = agent.click page.links.text("Show finished games")
208
+ # page = agent.click page.links.text("Show finished games")
202
209
  page = agent.click page.link_with(:text => "Show finished games")
203
210
  end
204
211
  if !page.body.include?("Finished games for")
@@ -447,6 +454,129 @@ Time remaining: 9&nbsp;days&nbsp;and&nbsp;6&nbsp;hours</td>
447
454
  def games
448
455
  [4,5,6]
449
456
  end
457
+
458
+ # Create one or more games in the waiting room
459
+ # Default values are taken from the file
460
+ # ~/.dgs_default_add_game.yml if it exists
461
+ # (if not the DGS form is just submitted)
462
+ def add_game
463
+ dgs_default_add_game = File.join(ENV['HOME'],".dgs_default_add_game.yml")
464
+ save_wait
465
+ my_rank = get_rank
466
+ my_rank_org = my_rank.dup
467
+
468
+ @waiting_room = DGS_WAITING_ROOM_PAGE
469
+ agent = WWW::Mechanize.new
470
+ agent.user_agent_alias = USER_AGENT_ALIAS
471
+ default_default_comment = 'added by dragongoserver ruby gem'
472
+ #--
473
+ # default = {
474
+ # :number_of_games => 3,
475
+ # :size => 19,
476
+ # :main_time => [15, :days], # or: :main_time => [15, :days]
477
+ # # or: :main_time => [24, :hours]
478
+ # # or: :main_time => [6, :months]
479
+ # :japanese_byoyomi => [1, :hours, 24, :extra_periods],
480
+ # # :canadian_byoyomi => false
481
+ # # :fischer_time => false
482
+ #
483
+ # :rated_game => true,
484
+ # :clock_runs_on_weekend => false,
485
+ # :require_rated_opponent => true,
486
+ # :relative_range => 9,
487
+ # :comment => default_default_comment,
488
+ # }
489
+ # open(File.join(ENV['HOME'],".dgs_default_add_game.yml"),"w") { |f|
490
+ # YAML.dump(default,f)
491
+ # }
492
+ begin
493
+ default = open(File.join(ENV['HOME'],".dgs_default_add_game.yml")) { |f|
494
+ YAML.load(f)
495
+ }
496
+ rescue Errno::ENOENT
497
+ # Datei nicht vorhanden.
498
+ # Auch nicht schlimm, dann nehmen wir die Default-Werte von DGS
499
+ end
500
+ #--
501
+ page = agent.get(@waiting_room)
502
+ if page.body.include?(LOGGED_IN)
503
+ # dann erst zum Einloggen gehen
504
+ page = login(agent)
505
+ page = agent.get(DGS_WAITING_ROOM_PAGE)
506
+ end
507
+ form = page.form("addgame")
508
+ if default
509
+ # wenn default Konfiguration nicht vorhanden,
510
+ # dann Formular in DGS einfach so lassen und bestätigen
511
+ # => 1 Spiel, 3 Monate, ...
512
+ if default[:number_of_games]
513
+ form.fields.find {|f| f.name == 'nrGames'}.value = default[:number_of_games]
514
+ end
515
+ if default[:size]
516
+ form.fields.find {|f| f.name == 'size'}.value = default[:size]
517
+ end
518
+ if default[:main_time]
519
+ form.fields.find {|f| f.name == 'timevalue'}.value = default[:main_time][0]
520
+ form.fields.find {|f| f.name == 'timeunit'}.value = default[:main_time][1].to_s
521
+ end
522
+ if default[:japanese_byoyomi]
523
+ # form.radiobuttons_with(:name => 'box')[1].check
524
+
525
+ form.radiobuttons_with(:name => 'byoyomitype')[0].check #e = 'JAP'
526
+ form.fields.find {|f| f.name == 'byotimevalue_jap'}.value =
527
+ default[:japanese_byoyomi][0]
528
+ form.fields.find {|f| f.name == 'timeunit_jap'}.value =
529
+ default[:japanese_byoyomi][1].to_s
530
+ form.fields.find {|f| f.name == 'byoperiods_jap'}.value =
531
+ default[:japanese_byoyomi][2]
532
+ # :japanese_byoyomi => [1, :hours, 24, :extra_periods],
533
+
534
+ end
535
+
536
+
537
+ if default[:comment]
538
+ form.fields.find {|f| f.name == 'comment'}.value = default[:comment]
539
+ end
540
+ if default[:require_rated_opponent]
541
+ form.checkbox_with(:name => 'must_be_rated').check
542
+ else
543
+ form.checkbox_with(:name => 'must_be_rated').uncheck
544
+ end
545
+ if default[:clock_runs_on_weekend]
546
+ form.checkbox_with(:name => 'weekendclock').check
547
+ else
548
+ form.checkbox_with(:name => 'weekendclock').uncheck
549
+ end
550
+ if default[:rated_game]
551
+ form.checkbox_with(:name => 'rated').check
552
+ else
553
+ form.checkbox_with(:name => 'rated').uncheck
554
+ end
555
+ if default[:relative_range]
556
+ r = default[:relative_range]
557
+ begin
558
+ rating1 = my_rank - r
559
+ rescue IndexError
560
+ rating1 = GoRank.new 30, :kyu
561
+ end
562
+ my_rank = my_rank_org
563
+ begin
564
+ rating2 = my_rank + r
565
+ rescue IndexError
566
+ rating2 = GoRank.new 6, :dan # go-rank max 6 dan, dgs max 9 dan TODO:
567
+ end
568
+ form.fields.find {|f| f.name == 'rating1'}.value = rating1.to_s
569
+ form.fields.find {|f| f.name == 'rating2'}.value = rating2.to_s
570
+ end
571
+ end # if default
572
+ unless default
573
+ form.fields.find {|f| f.name == 'comment'}.value = default_default_comment
574
+ end
575
+ page = agent.submit(form, form.buttons.first)
576
+ # puts "neue Einladung erstellt" if page.body.include? 'Game added!'
577
+
578
+ page.body.include? 'Game added!'
579
+ end
450
580
 
451
581
  private
452
582
 
@@ -1,9 +1,49 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
1
 
4
2
  module Dragongoserver
5
- end
6
3
 
7
- require 'dragongoserver/version'
8
- require 'dragongoserver/dragongoserver'
9
- require 'dragongoserver/game'
4
+ # :stopdoc:
5
+ VERSION = '0.4.0'
6
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
+ # :startdoc:
9
+
10
+ # Returns the version string for the library.
11
+ #
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ # Returns the library path for the module. If any arguments are given,
17
+ # they will be joined to the end of the libray path using
18
+ # <tt>File.join</tt>.
19
+ #
20
+ def self.libpath( *args )
21
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
+ end
23
+
24
+ # Returns the lpath for the module. If any arguments are given,
25
+ # they will be joined to the end of the path using
26
+ # <tt>File.join</tt>.
27
+ #
28
+ def self.path( *args )
29
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
+ end
31
+
32
+ # Utility method used to require all files ending in .rb that lie in the
33
+ # directory below this file that has the same name as the filename passed
34
+ # in. Optionally, a specific _directory_ name can be passed in such that
35
+ # the _filename_ does not have to be equivalent to the directory.
36
+ #
37
+ def self.require_all_libs_relative_to( fname, dir = nil )
38
+ dir ||= ::File.basename(fname, '.*')
39
+ search_me = ::File.expand_path(
40
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
+
42
+ Dir.glob(search_me).sort.each {|rb| require rb}
43
+ end
44
+
45
+ end # module Dragongoserver
46
+
47
+ Dragongoserver.require_all_libs_relative_to(__FILE__)
48
+
49
+ # EOF