OSDN Git Service

mytime should be updated in start method for 2nd game
[shogi-server/shogi-server.git] / shogi-server
index 9bce429..c82597d 100755 (executable)
@@ -116,7 +116,7 @@ class Player
     @eol = "\m"                 # favorite eol code
     @game = nil
     @game_name = ""
-    @mytime = Total_Time
+    @mytime = Total_Time        # set in start method also
     @sente = nil
     @watchdog_thread = nil
 
@@ -182,6 +182,7 @@ class Player
   end
     
   def run
+    write_safe(sprintf("LOGIN:%s OK\n", @name))
     if (@protocol != "CSA")
       log_message(sprintf("user %s run in %s mode", @name, @protocol))
       write_safe(sprintf("##[LOGIN] +OK %s\n", @protocol))
@@ -217,7 +218,7 @@ class Player
               @game.gote.status = "game"
             end
           else
-            write_safe("## you are in %s status. AGREE is valid in agree_waiting status\n", @status)
+            write_safe("##[ERROR] you are in %s status. AGREE is valid in agree_waiting status\n", @status)
             next
           end
         when /^%%HELP/
@@ -226,7 +227,7 @@ class Player
           if ((@status == "connected") || (@status == "game_waiting"))
             @status = "game_waiting"
           else
-            write_safe(sprintf("## you are in %s status. GAME is valid in connected or game_waiting status\n", @status))
+            write_safe(sprintf("##[ERROR] you are in %s status. GAME is valid in connected or game_waiting status\n", @status))
             next
           end
           @status = "game_waiting"
@@ -280,11 +281,12 @@ class Player
           end
           buf.push("##[WHO] +OK\n")
           write_safe(buf.join)
-        when /^%%LOGOUT/
+        when /^LOGOUT/
+          write_safe("LOGOUT:completed\n")
           finish
           return
         else
-          write_safe(sprintf("## unknown command %s\n", str))
+          write_safe(sprintf("##[ERROR] unknown command %s\n", str))
         end
       ensure
         $mutex.unlock
@@ -388,6 +390,7 @@ class Game
     log_message(sprintf("game started %s %s %s", game_name, sente.name, gote.name))
     @sente.write_safe(sprintf("START:%s\n", @id))
     @gote.write_safe(sprintf("START:%s\n", @id))
+    @mytime = Total_Time    
     @start_time = Time::new
   end
 
@@ -568,6 +571,7 @@ def main
           if (good_login?(str))
             player = Player::new(str, client)
             if (LEAGUE.duplicated?(player))
+              client.write_safe("LOGIN:incorrect" + eol)
               client.write_safe(sprintf("username %s is already connected%s", player.name, eol))
               client.close
               Thread::kill(Thread::current)
@@ -575,6 +579,7 @@ def main
             LEAGUE.add(player)
             break
           else
+            client.write_safe("LOGIN:incorrect" + eol)
             client.write_safe("type 'LOGIN name password' or 'LOGIN name password x1'" + eol)
             client.close
             Thread::kill(Thread::current)