From: Daigo Moriwaki Date: Sun, 31 Mar 2013 05:15:47 +0000 (+0900) Subject: command.rb: More elaborate error messages for the %%GAME command. X-Git-Tag: 20170902~34^2~8^2~2 X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=440981d016ebd22a8b8c9912b9d19f5087f0cb39;p=shogi-server%2Fshogi-server.git command.rb: More elaborate error messages for the %%GAME command. --- diff --git a/changelog b/changelog index 8b31f4b..eb0c731 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ The new_buoy_game parameter is now optional. If it is not supplied, Shogi-server generates a new buoy game name from source_game. + - command.rb: More elaborate error messages for the %%GAME command. 2013-02-23 Daigo Moriwaki diff --git a/shogi_server/command.rb b/shogi_server/command.rb index 9ce0d6b..8a2b38c 100644 --- a/shogi_server/command.rb +++ b/shogi_server/command.rb @@ -69,6 +69,9 @@ module ShogiServer my_sente_str = $3 cmd = GameChallengeCommand.new(str, player, command_name, game_name, my_sente_str) + when /^%%(GAME|CHALLENGE)\s+(\S+)/ + msg = "A turn identifier is required" + cmd = ErrorCommand.new(str, player, msg) when /^%%CHAT\s+(.+)/ message = $1 cmd = ChatCommand.new(str, player, message, $league.players) @@ -494,7 +497,16 @@ module ShogiServer def call if (! Login::good_game_name?(@game_name)) - @player.write_safe(sprintf("##[ERROR] bad game name\n")) + @player.write_safe(sprintf("##[ERROR] bad game name: %s.\n", @game_name)) + if (/^(.+)-\d+-\d+$/ =~ @game_name) + if Login::good_identifier?($1) + # do nothing + else + @player.write_safe(sprintf("##[ERROR] invalid identifiers are found or too many characters are used.\n")) + end + else + @player.write_safe(sprintf("##[ERROR] game name should consist of three parts like game-1500-60.\n")) + end return :continue elsif ((@player.status == "connected") || (@player.status == "game_waiting")) ## continue @@ -679,9 +691,9 @@ module ShogiServer # Command for an error # class ErrorCommand < Command - def initialize(str, player) - super - @msg = nil + def initialize(str, player, msg=nil) + super(str, player) + @msg = msg || "unknown command" end attr_reader :msg @@ -689,7 +701,7 @@ module ShogiServer cmd = @str.chomp # Aim to hide a possible password cmd.gsub!(/LOGIN\s*(\w+)\s+.*/i, 'LOGIN \1...') - @msg = "##[ERROR] unknown command %s\n" % [cmd] + @msg = "##[ERROR] %s: %s\n" % [@msg, cmd] @player.write_safe(@msg) log_error(@msg) return :continue