• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

Revision440981d016ebd22a8b8c9912b9d19f5087f0cb39 (tree)
Zeit2013-03-31 14:15:47
AutorDaigo Moriwaki <daigo@debi...>
CommiterDaigo Moriwaki

Log Message

command.rb: More elaborate error messages for the %%GAME command.

Ändern Zusammenfassung

Diff

--- a/changelog
+++ b/changelog
@@ -5,6 +5,7 @@
55 The new_buoy_game parameter is now optional. If it is not
66 supplied, Shogi-server generates a new buoy game name from
77 source_game.
8+ - command.rb: More elaborate error messages for the %%GAME command.
89
910 2013-02-23 Daigo Moriwaki <daigo at debian dot org>
1011
--- a/shogi_server/command.rb
+++ b/shogi_server/command.rb
@@ -69,6 +69,9 @@ module ShogiServer
6969 my_sente_str = $3
7070 cmd = GameChallengeCommand.new(str, player,
7171 command_name, game_name, my_sente_str)
72+ when /^%%(GAME|CHALLENGE)\s+(\S+)/
73+ msg = "A turn identifier is required"
74+ cmd = ErrorCommand.new(str, player, msg)
7275 when /^%%CHAT\s+(.+)/
7376 message = $1
7477 cmd = ChatCommand.new(str, player, message, $league.players)
@@ -494,7 +497,16 @@ module ShogiServer
494497
495498 def call
496499 if (! Login::good_game_name?(@game_name))
497- @player.write_safe(sprintf("##[ERROR] bad game name\n"))
500+ @player.write_safe(sprintf("##[ERROR] bad game name: %s.\n", @game_name))
501+ if (/^(.+)-\d+-\d+$/ =~ @game_name)
502+ if Login::good_identifier?($1)
503+ # do nothing
504+ else
505+ @player.write_safe(sprintf("##[ERROR] invalid identifiers are found or too many characters are used.\n"))
506+ end
507+ else
508+ @player.write_safe(sprintf("##[ERROR] game name should consist of three parts like game-1500-60.\n"))
509+ end
498510 return :continue
499511 elsif ((@player.status == "connected") || (@player.status == "game_waiting"))
500512 ## continue
@@ -679,9 +691,9 @@ module ShogiServer
679691 # Command for an error
680692 #
681693 class ErrorCommand < Command
682- def initialize(str, player)
683- super
684- @msg = nil
694+ def initialize(str, player, msg=nil)
695+ super(str, player)
696+ @msg = msg || "unknown command"
685697 end
686698 attr_reader :msg
687699
@@ -689,7 +701,7 @@ module ShogiServer
689701 cmd = @str.chomp
690702 # Aim to hide a possible password
691703 cmd.gsub!(/LOGIN\s*(\w+)\s+.*/i, 'LOGIN \1...')
692- @msg = "##[ERROR] unknown command %s\n" % [cmd]
704+ @msg = "##[ERROR] %s: %s\n" % [@msg, cmd]
693705 @player.write_safe(@msg)
694706 log_error(@msg)
695707 return :continue