/** (C) Game Page Network, Inc., Confidential, All Rights Reserved */
// DrawCommand.java
// --paul@gamepage.net, 24nov97

import java.util.*;

public class DrawCommand extends Command {
  DrawCommand() {
    super("draw", 1, "TABLE",
          "Request or accept a draw (tie) at TABLE.\n"+
	  "Both players must issue this command during a game\n"+
	  "to have the game end in a draw.");
  }
  public void process(StringTokenizer args, Client c) {
    Member current = c.getMember();  
    String name = args.nextToken();
    Table table = Table.findIt(name); // BUG: disallow by observer
    if (table==null) {
      c.send("! draw "+name+": No such table.");
      return;
    }
    Game game = table.getGame();
    if (game==null || !game.isActive()) {
      c.send("! draw "+name+": No active game.");      
      return;
    }
    if (!current.isPlayer(table)) {
      c.send("! draw "+name+": You are not a player.");
      return;
    }
    if (!table.draw(current))
      c.send("! draw "+name);
  }
}

