JMud.java

jmud-0.11/src/JMud.java · 3.1 KB

From the archive jmud-0_11.tgz

Download the archive   « Back to the archive contents

/*
  JMud - Servidor de Mud desenvolvido em Java
  Copyright (C) 1998 Éverton da Silva Marques <evertonm@dcc.unicamp.br>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program -- see the file COPYING; if not, write to
  the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA 02111-1307 USA 
*/
  
import util.log.Log;

public class JMud {

  static private final String MAIN_USAGE        = "Uso: JMud [-c configFile] [-p portNumber] [-cmd] [-pleno]";
  static private final String MAIN_REQ_CFG_FILE = "requer configFile";
  static private final String MAIN_REQ_PORT     = "requer portNumber";
  static private final String MAIN_DUP_OPT      = "Opção duplicada: ";
  static private final String MAIN_INV_OPT      = "Opção inválida: ";

  private static void error(String msg) {
    System.err.println("JMud: Erro: " + msg);
  }

  private static void abort(String msg) {
    error(msg);
    System.err.println("Abortando.");
    System.exit(1);
  }

  private static void usage(String msg) {
    error(msg);
    System.err.println(MAIN_USAGE);
    System.exit(1);
  }

  public static void main(String args[]) {

    final String defaultConfig = "jmud.cfg";
    final int    defaultPort   = 1234;

    String configFileName = null;
    int    portNumber     = -1;

    Log.turnConsoleOn(true);
    Log.turnRecipientsOn(true);
    Log.setDefaultPriority(Char.R_GOD);

    for (int i = 0; i < args.length; ++i) {
      String arg = args[i];

      if (arg.equals("-c")) {
	if (configFileName == null) {
	  if (i < args.length - 1)
	    configFileName = args[++i];
	  else
	    usage("-c " + MAIN_REQ_CFG_FILE);
	}
	else
	  usage(MAIN_DUP_OPT + arg);
      }
      else if (arg.equals("-p")) {
	if (portNumber < 0) {
	  if (i < args.length - 1)
	    portNumber = Integer.parseInt(args[++i]);
	  else
	    usage("-p " + MAIN_REQ_PORT);
	}
	else
	  usage(MAIN_DUP_OPT + arg);
      }
      else if (arg.equals("-cmd")) {
	Debug.cmd = true;
      }
      else if (arg.equals("-pleno")) {
	Debug.full = true;
      }
      else
	usage(MAIN_INV_OPT + arg);
    }

    if (Debug.cmd)
      Log.log("Ativando logs de comandos");

    if (Debug.full)
      Log.log("Ativando logs plenos");

    if (configFileName == null)
      configFileName = defaultConfig;

    if (portNumber < 0)
      portNumber = defaultPort;

    Manager theManager = new Manager(configFileName, portNumber);

    Log.insert(theManager);

    Client.setManager(theManager);
    Command.setManager(theManager);
    Char.setManager(theManager);
    Task.setManager(theManager);
    Magic.setManager(theManager);

    theManager.go();
  }
}

Site Stats

Snippets: 1791
Codebases: 571