/** (C) Game Page Network, Inc., Confidential, All Rights Reserved */
// HelpCommand.java
// --paul@gamepage.net, 21jul97

import java.util.*;

public class HelpCommand extends Command {
  HelpCommand() {
    super("help", -1, null,
	  "Show list of GPN commands or help for a given command.");
  }

  public void process(StringTokenizer args, Client c) {
    if ( args.countTokens() > 1 ) {
      c.send("? help");
      return;
    }
    Member current = c.getMember();
    boolean isCoach = Club.coach(current);
    
    if ( args.hasMoreTokens() ) {
      String name = args.nextToken();
      Command command = Command.find(name);
      if (command == null) {
	c.send("! help "+name+": No such command");
        return;
      } else if (command.coach && !isCoach) {
	c.send("! help "+name+": Only for Club Coaches");
      } else {
	//if (command.args!=null)
	//c.send("# "+command.args+"\n");
	StringTokenizer st = new StringTokenizer(command.help,"\n");
	while (st.hasMoreTokens())
	  c.send("# "+st.nextToken());
	if (command.coach==true)
	  c.send("# Can only be used by a Club Coach.");
        return;
      }
    } else if (isCoach) {
      c.send("# Game Page Network server commands:\n"+
	     "# help, login, who, tables, quit, log, eject, ban\n"+
	     "# talk, whisper, kibitz, shout, sound, mute, unmute\n"+
	     "# observe, open, join, timer, practice, start, reset\n"+
	     "# move, list, display, draw, resign, save");
    } else {
      c.send("# Game Page Network server commands:\n"+
	     "# help, login, who, tables, quit, mute, unmute\n"+
	     "# observe, open, join, timer, practice, start, reset\n"+
	     "# move, list, display, draw, resign, save");
    }
  }
}

