shogi-server source
Revision | 440981d016ebd22a8b8c9912b9d19f5087f0cb39 (tree) |
---|---|
Zeit | 2013-03-31 14:15:47 |
Autor | Daigo Moriwaki <daigo@debi...> |
Commiter | Daigo Moriwaki |
@@ -5,6 +5,7 @@ | ||
5 | 5 | The new_buoy_game parameter is now optional. If it is not |
6 | 6 | supplied, Shogi-server generates a new buoy game name from |
7 | 7 | source_game. |
8 | + - command.rb: More elaborate error messages for the %%GAME command. | |
8 | 9 | |
9 | 10 | 2013-02-23 Daigo Moriwaki <daigo at debian dot org> |
10 | 11 |
@@ -69,6 +69,9 @@ module ShogiServer | ||
69 | 69 | my_sente_str = $3 |
70 | 70 | cmd = GameChallengeCommand.new(str, player, |
71 | 71 | 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) | |
72 | 75 | when /^%%CHAT\s+(.+)/ |
73 | 76 | message = $1 |
74 | 77 | cmd = ChatCommand.new(str, player, message, $league.players) |
@@ -494,7 +497,16 @@ module ShogiServer | ||
494 | 497 | |
495 | 498 | def call |
496 | 499 | 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 | |
498 | 510 | return :continue |
499 | 511 | elsif ((@player.status == "connected") || (@player.status == "game_waiting")) |
500 | 512 | ## continue |
@@ -679,9 +691,9 @@ module ShogiServer | ||
679 | 691 | # Command for an error |
680 | 692 | # |
681 | 693 | 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" | |
685 | 697 | end |
686 | 698 | attr_reader :msg |
687 | 699 |
@@ -689,7 +701,7 @@ module ShogiServer | ||
689 | 701 | cmd = @str.chomp |
690 | 702 | # Aim to hide a possible password |
691 | 703 | 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] | |
693 | 705 | @player.write_safe(@msg) |
694 | 706 | log_error(@msg) |
695 | 707 | return :continue |