OSDN Git Service

- shogi_server/command.rb:
[shogi-server/shogi-server.git] / shogi_server / command.rb
index 55b56f1..571a18d 100644 (file)
@@ -25,7 +25,7 @@ module ShogiServer
   class Command
     # Factory method
     #
   class Command
     # Factory method
     #
-    def Command.factory(str, player)
+    def Command.factory(str, player, time=Time.now)
       cmd = nil
       case str 
       when "" 
       cmd = nil
       case str 
       when "" 
@@ -100,13 +100,16 @@ module ShogiServer
         cmd = ErrorCommand.new(str, player)
       end
 
         cmd = ErrorCommand.new(str, player)
       end
 
+      cmd.time = time
       return cmd
     end
 
     def initialize(str, player)
       @str    = str
       @player = player
       return cmd
     end
 
     def initialize(str, player)
       @str    = str
       @player = player
+      @time   = Time.now # this should be replaced later with a real time
     end
     end
+    attr_accessor :time
   end
 
   # Application-level protocol for Keep-Alive.
   end
 
   # Application-level protocol for Keep-Alive.
@@ -136,12 +139,17 @@ module ShogiServer
       if (@player.status == "game")
         array_str = @str.split(",")
         move = array_str.shift
       if (@player.status == "game")
         array_str = @str.split(",")
         move = array_str.shift
+        if @player.game.last_move &&
+           @player.game.last_move.split(",").first == move
+          log_warning("Received two sequencial identical moves [#{move}] from #{@player.name}. The last one was ignored.")
+          return :continue
+        end
         additional = array_str.shift
         comment = nil
         if /^'(.*)/ =~ additional
           comment = array_str.unshift("'*#{$1.toeuc}")
         end
         additional = array_str.shift
         comment = nil
         if /^'(.*)/ =~ additional
           comment = array_str.unshift("'*#{$1.toeuc}")
         end
-        s = @player.game.handle_one_move(move, @player)
+        s = @player.game.handle_one_move(move, @player, @time)
         @player.game.log_game(Kconv.toeuc(comment.first)) if (comment && comment.first && !s)
         return :return if (s && @player.protocol == LoginCSA::PROTOCOL)
       end
         @player.game.log_game(Kconv.toeuc(comment.first)) if (comment && comment.first && !s)
         return :return if (s && @player.protocol == LoginCSA::PROTOCOL)
       end
@@ -171,7 +179,7 @@ module ShogiServer
     def in_game_status
       rc = :continue
 
     def in_game_status
       rc = :continue
 
-      s = @player.game.handle_one_move(@str, @player)
+      s = @player.game.handle_one_move(@str, @player, @time)
       rc = :return if (s && @player.protocol == LoginCSA::PROTOCOL)
 
       return rc
       rc = :return if (s && @player.protocol == LoginCSA::PROTOCOL)
 
       return rc
@@ -280,8 +288,8 @@ module ShogiServer
     def ==(rhs)
       return rhs != nil &&
              rhs.is_a?(MonitorHandler) &&
     def ==(rhs)
       return rhs != nil &&
              rhs.is_a?(MonitorHandler) &&
-             @player = rhs.player &&
-             @type   = rhs.type
+             @player == rhs.player &&
+             @type   == rhs.type
     end
 
     def write_safe(game_id, str)
     end
 
     def write_safe(game_id, str)
@@ -474,14 +482,13 @@ module ShogiServer
         end
         @player.sente = nil
       else
         end
         @player.sente = nil
       else
-        if (@my_sente_str == "*")
+        if (@my_sente_str == "*") && !Login.handicapped_game_name?(@game_name)
           rival = $league.get_player("game_waiting", @game_name, nil, @player) # no preference
         elsif (@my_sente_str == "+")
           rival = $league.get_player("game_waiting", @game_name, false, @player) # rival must be gote
         elsif (@my_sente_str == "-")
           rival = $league.get_player("game_waiting", @game_name, true, @player) # rival must be sente
         else
           rival = $league.get_player("game_waiting", @game_name, nil, @player) # no preference
         elsif (@my_sente_str == "+")
           rival = $league.get_player("game_waiting", @game_name, false, @player) # rival must be gote
         elsif (@my_sente_str == "-")
           rival = $league.get_player("game_waiting", @game_name, true, @player) # rival must be sente
         else
-          ## never reached
           @player.write_safe(sprintf("##[ERROR] bad game option\n"))
           return :continue
         end
           @player.write_safe(sprintf("##[ERROR] bad game option\n"))
           return :continue
         end
@@ -536,7 +543,8 @@ module ShogiServer
             Game::new(@player.game_name, @player, rival, board)
           end
         else
             Game::new(@player.game_name, @player, rival, board)
           end
         else
-          board = Board.new
+          klass = Login.handicapped_game_name?(@game_name) || Board
+          board = klass.new
           board.initial
           Game::new(@player.game_name, @player, rival, board)
         end
           board.initial
           Game::new(@player.game_name, @player, rival, board)
         end