dragongoserver 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ == 0.4.1 2009-08-02
2
+
3
+ * 4 bug-fixes:
4
+ * rescued the Timeout-Error at #gameinfo (retry in 30 seconds)
5
+ * added the config file for new waiting room games to the gem files
6
+ * Link 'finished games' was changed at dgs
7
+ * fixed bug String#each to each_line in Ruby 1.9
8
+
1
9
  == 0.4.0 2009-07-13
2
10
 
3
11
  * 1 enhancement:
@@ -9,6 +9,7 @@ TODO
9
9
  bin/dgs
10
10
  config/hoe.rb
11
11
  config/requirements.rb
12
+ .dgs_default_add_game.yml
12
13
  examples/example1.rb
13
14
  examples/id.dat
14
15
  examples/userlist.out
data/README.txt CHANGED
@@ -1,4 +1,3 @@
1
- dragongoserver
2
1
  by Thomas Preymesser
3
2
  http://dragongoserver.rubyforge.org/
4
3
 
@@ -8,25 +7,187 @@ The dragongoserver gem allows you to use the Go Server (http://www.dragongoserve
8
7
 
9
8
  == FEATURES/PROBLEMS:
10
9
 
11
- * test (list of features or problems)
10
+ You can access various features of Dragongoserver either within your own
11
+ Ruby programs or via a command line tool (dgs).
12
+
13
+ * get your user info
14
+ * get user infos of other users
15
+ * list waiting games
16
+ * add a game to the waiting room
17
+ * ...
12
18
 
13
19
  == SYNOPSIS:
14
20
 
15
- test (code sample of usage)
21
+ First you have to set the following environment variables:
22
+
23
+ DGS_USERNAME="myname"
24
+ DGS_PASSWORD="mypassword"
25
+
26
+ This can be done by inserting the following two line into your .bashrc file (or a similar startup file for your preferred shell).
27
+
28
+ export DGS_USERNAME="myname"
29
+ export DGS_PASSWORD="mypassword"
30
+
31
+ Alternatively you can pass the username and password to every call of the
32
+ Dgs.new method:
33
+
34
+ mydgs = Dgs.new("myname","mypassword")
35
+
36
+ === Within your ruby code:
37
+
38
+ # some example how you can use this gem within your programs
39
+
40
+ require 'rubygems'
41
+ require 'dragongoserver'
42
+ require 'gorank'
43
+
44
+ dgs = Dgs.new
45
+
46
+ # get own user id at DGS
47
+
48
+ id = dgs.userid
49
+ puts "your user-id: #{id}"
50
+
51
+ # your rank
52
+
53
+ rank = dgs.get_rank
54
+
55
+ puts "your rank:"
56
+ p rank.to_s
57
+
58
+ # your user infos
59
+
60
+ infos = dgs.userinfo(id)
61
+
62
+ puts "your attributes at DGS:"
63
+ p infos
64
+
65
+ # waiting games
66
+
67
+ wg = dgs.waiting_games
68
+
69
+ puts 'waiting games:'
70
+ p wg
71
+
72
+ # you can get info for every other user
73
+ # user with user id 8000
74
+ user_8000 = dgs.userinfo(8000)
75
+
76
+ puts "user 8000:"
77
+ p user_8000
78
+
79
+ # see also the homepage of this gem for examples to use the
80
+ # command line script 'dgs'
81
+
82
+ require 'rubygems'
83
+ require 'dragongoserver'
84
+
85
+ dgs = Dgs.new
86
+ dgs.username # prints your username at DGS
87
+
88
+ dgs.waiting_games # prints your waiting games:
89
+ # => [369607, 369303, 369412]
90
+
91
+ dgs.get_rank # your rank as a GoRank object
92
+ # => #<GoRank:0xb7a66514 @kd=:kyu, @num="26">
93
+
94
+ dgs.get_rank.to_s # your rank as a string
95
+ # => "26 kyu"
96
+
97
+ dgs.add_game # adds one or more game in the waiting room
98
+ # take the values from the file
99
+ # ~/.dgs_default_add_game.yml if it exists
100
+
101
+ === The 'dgs' command line tool:
102
+
103
+ $ dgs -v
104
+ dgs 0.0.3
105
+
106
+ outputs the version of the installed dragongoserver gem
107
+
108
+ $ dgs --help
109
+
110
+ outputs a help of the dgs-script with all current implemented options
111
+
112
+ dgs --waiting
113
+
114
+ prints a list of games where you have to make your next move
115
+
116
+ You can open a shell, type in the following commands and watch when you have to move in a waiting game.
117
+ Of course you can also write a shellscript with these commands.
118
+
119
+ while true
120
+ do
121
+ dgs --waiting
122
+ date
123
+ sleep 300
124
+ done
125
+
126
+ Instead of the script above you can use the '--waiting-loop' feature of this gem:
127
+
128
+ $ dgs --waiting-loop
129
+
130
+ in an endless loop prints a list of games where you have to make your next move.
131
+ The duration until the next request is made at DGS will be dynamically adjusted. It starts with every 60 seconds and will be increased if there are no new moves in this period.
132
+
133
+ If you want the messages display in big red letters as an On-Screen-Display:
134
+
135
+ $ dgs --waiting-loop --osd
136
+
137
+ To add a new game to the waiting room use
138
+
139
+ xxx.add_game
140
+
141
+ in your Ruby code or
142
+
143
+ $ dgs --add-game
144
+
145
+ at the command line.
146
+ The add_game method looks up for a file ~/.dgs_default_add_game.yml where the game parameters will be taken from. If this file does not exists dragongoserver will just submit the new game form at dragongoserver.net without any changes (i.e. 1 game, main time 90 days, ... etc.).
147
+
148
+ ==== Example of this config file
149
+
150
+ ---
151
+ :number_of_games: 3
152
+ :size: 19
153
+ :main_time:
154
+ - 15
155
+ - :days
156
+ :japanese_byoyomi:
157
+ - 1
158
+ - :hours
159
+ - 24
160
+ - :extra_periods
161
+ :rated_game: true
162
+ :clock_runs_on_weekend: false
163
+ :require_rated_opponent: true
164
+ :relative_range: 9
165
+ :comment: added by dragongoserver ruby gem
166
+
167
+ It should be relatively clear what every parameter is meant for.
168
+ If you omit some of these values the corresponding part in the DGS
169
+ form will not be changed.
170
+ Currently there is only the japanese byoyomi implemented.
171
+ Please don't change the indentation in this file, it is important
172
+ in the YAML format.
173
+
174
+ There is a sample file .dgs_default_add_game.yml delivered with this gem, which you can copy to your home directory and modify it to your own needs.
175
+
176
+ $ cp /your/gem/installation/path/.dgs_default_add_game.yml ~
16
177
 
17
178
  == REQUIREMENTS:
18
179
 
19
- * test (list of requirements)
180
+ None. All dependent gems are installed automatically. If you want to use the --osd flag you have to install the osd package for your system.
20
181
 
21
182
  == INSTALL:
22
183
 
23
- * sudo gem install dragongoserver
184
+ sudo gem install dragongoserver
24
185
 
25
186
  == LICENSE:
26
187
 
27
188
  (The MIT License)
28
189
 
29
- Copyright (c) 2007,2008,2009
190
+ Copyright (c) 2007-2009
30
191
 
31
192
  Permission is hereby granted, free of charge, to any person obtaining
32
193
  a copy of this software and associated documentation files (the
data/bin/dgs CHANGED
@@ -100,7 +100,7 @@ Choice.options do
100
100
  end
101
101
 
102
102
  if Choice.choices['check_timeout_finished']
103
- puts "timeout check für user #{Choice.choices['check_timeout_finished']} ausgewählt"
103
+ puts "timeout check for user #{Choice.choices['check_timeout_finished']}"
104
104
  dgs_username = ENV['DGS_USERNAME']
105
105
  dgs_password = ENV['DGS_PASSWORD']
106
106
  @dgs = Dgs.new(dgs_username, dgs_password)
@@ -115,7 +115,7 @@ if Choice.choices['check_timeout_finished']
115
115
  end
116
116
  }
117
117
  puts "at least #{finished.size} finished games"
118
- puts "#{count} games finished with timeout"
118
+ puts "#{count} games finished with timeout (#{count.to_f/finished.size.to_f*100.0} %)"
119
119
  exit
120
120
  end
121
121
 
@@ -212,7 +212,14 @@ def new_moves?(dgs)
212
212
  print "[c] "
213
213
  end
214
214
  unless gi
215
- gi = dgs.gameinfo(game)
215
+ begin
216
+ gi = dgs.gameinfo(game)
217
+ rescue Timeout::Error
218
+ puts "timeout error. retrying in 30 secs"
219
+ sleep 30
220
+ retry
221
+ end
222
+
216
223
  @cache_gameinfos[game] = gi
217
224
  end
218
225
  print gi[:white][:name]+' ' unless gi[:white][:name].include? "(#{dgs.username})"
@@ -2,7 +2,7 @@
2
2
  module Dragongoserver
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -18,9 +18,10 @@ class Dgs
18
18
  # User agent
19
19
  USER_AGENT_ALIAS = 'Mac Safari' # should work with every browser type
20
20
 
21
- SAVE_WAIT = 15 # wait n seconds before each request
22
21
  # if we are doing too many requests at DGS the account (YOUR ACCOUNT)
23
22
  # will be temporarily blocked (for about 1 day)
23
+ # wait n seconds before each request
24
+ SAVE_WAIT = 15
24
25
 
25
26
  attr_reader :username
26
27
 
@@ -201,12 +202,13 @@ class Dgs
201
202
  end
202
203
  form = page.forms.first
203
204
  form.sf1 = user_id.to_s
204
-
205
+ form.checkbox_with(:name => "active").uncheck # auch inaktive User beruecksichtigen
205
206
  page = agent.submit(form)
206
207
  # page = agent.click page.links.text("#{user_id}")
207
208
  page = agent.click page.link_with(:text => "#{user_id}")
208
209
  # page = agent.click page.links.text("Show finished games")
209
- page = agent.click page.link_with(:text => "Show finished games")
210
+ # page = agent.click page.link_with(:text => "Show finished games")
211
+ page = agent.click page.link_with(:text => "Finished games")
210
212
  end
211
213
  if !page.body.include?("Finished games for")
212
214
  #p page.body
@@ -214,7 +216,7 @@ class Dgs
214
216
  end
215
217
  #page = agent.click page.links.text('Show finished games')
216
218
  one_game = {}
217
- page.body.each {|line|
219
+ page.body.each_line {|line|
218
220
  # p line
219
221
  #p one_game
220
222
  if line =~ /gid=([0-9]+)"/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragongoserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Preymesser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-15 00:00:00 +02:00
12
+ date: 2009-08-02 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency