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

import java.util.*;

public class PracticeCommand extends Command {
  PracticeCommand() {
    super("practice", 2, "TABLE [on|off]",
          "For TABLE, set practice mode on or off.\n"+
	  "In practice mode, no rules are checked.\n"+
	  "Can only be set by lead player before game start.");
  }
  public void process(StringTokenizer args, Client c) {
    Member current = c.getMember();  
    String name = args.nextToken();
    String val = args.nextToken();
    boolean state;
    if (val.equalsIgnoreCase("on"))
      state = true;
    else if (val.equalsIgnoreCase("off"))
      state = false;
    else {
      c.send("? practice");
      return;
    }
    
    Table table = Table.findIt(name);
    if (table==null) {
      c.send("! practice "+name+": No such table.");
      return;
    }
    Game game = table.getGame();
    if (game==null || game.gameState!='b') {
      c.send("! practice "+name+": No opening game.");      
      return;
    }
    if (!current.isPlayer(table) || current.getRole()!=0) {
      c.send("! practice "+name+": You are not lead player.");
      return;
    }
    if (!table.practice(current,state))
      c.send("! practice "+name);
  }
}

