Package org.groovymud.object.alive

Examples of org.groovymud.object.alive.Player


  public void testLoadPlayerData() throws CompilationFailedException, FileNotFoundException, ResourceException, ScriptException {
    final GroovyClassLoader mockClassLoader = new GroovyClassLoader() {

    };
    MockControl playerCtrl = MockControl.createControl(Player.class);
    final Player player = (Player) playerCtrl.getMock();
    final InputStream inputStream = new ByteArrayInputStream(new byte[] { '<', 'x', 'm', 'l', '/', '>' });

    final XStream mockXStream = new XStream() {

      @Override
      public Object fromXML(InputStream input) {
        // TODO Auto-generated method stub
        assertEquals(inputStream, input);
        methodCalled1 = true;
        return player;
      }
    };
    MockControl scriptCtrl = MockClassControl.createControl(GroovyScriptEngine.class, new Class[] { String.class }, new String[] { new String("file://") });
    final GroovyScriptEngine eng = (GroovyScriptEngine) scriptCtrl.getMock();
    eng.getParentClassLoader();
    scriptCtrl.setDefaultReturnValue(null);
    eng.loadScriptByName("player.Impl");
    scriptCtrl.setReturnValue(player.getClass());
    scriptCtrl.replay();
    MudObjectAttendant attend = new MudObjectAttendant() {

      protected InputStream createFileInputStream(File playerFile) throws FileNotFoundException {
        return inputStream;
View Full Code Here


  public void testCreateNewPlayer() throws CompilationFailedException, FileNotFoundException, InstantiationException {
    String username = "wombat";
    String upperuname = username.substring(0, 1).toUpperCase() + username.substring(1);
    String password = "x";
    MockControl mockCtrl = MockControl.createControl(Player.class);
    final Player mockPlayer = (Player) mockCtrl.getMock();
    mockPlayer.setName(username);
    mockCtrl.setVoidCallable();

    mockPlayer.setName(upperuname);
    mockCtrl.setVoidCallable();
    mockPlayer.setName(upperuname);
    mockCtrl.setVoidCallable();
    mockPlayer.getName();
    mockCtrl.setDefaultReturnValue(upperuname);
    mockPlayer.addShortName(upperuname);
    mockCtrl.setVoidCallable();
    mockPlayer.addShortName(upperuname);
    mockCtrl.setVoidCallable();
    mockPlayer.initialise();
    mockCtrl.setVoidCallable();
    MudObjectAttendant attnd = new MudObjectAttendant() {

      @Override
      public MudObject load(ObjectLocation loc) {
View Full Code Here

    return new ActionCallback(username, action);
  }

  protected void confirmDestIfDupeExisted() throws IOException, UnsupportedCallbackException, FailedLoginException {
    Callback[] cb;
    Player dupe = getDupe();
    if (dupe != null) {
      // we need to dest this player if they say yes
      ConfirmationCallback alreadyPlaying = new ConfirmationCallback("You are already playing. Throw the other copy out?", ConfirmationCallback.INFORMATION, ConfirmationCallback.YES_NO_OPTION, ConfirmationCallback.NO);
      cb = createCallbackArray(alreadyPlaying);
      getCallbackHandler().handle(cb);
      if (alreadyPlaying.getSelectedIndex() == ConfirmationCallback.YES) {
        dupe.getRegistry().dest(dupe, true);
      } else {
        throw new FailedLoginException("cannot log in, already logged in!");
      }
    }
  }
View Full Code Here

  public boolean commit() throws LoginException {
    if (!hasSucceeded()) {
      cleanup();
      return false;
    }
    Player p = getPlayer();
    if (p != null) {

      getPlayerPrincipals().addAll(p.getSubject().getPrincipals());
      logger.info("player principals:");
      for (Principal pr : getPlayerPrincipals()) {
        logger.info(pr.getName());
      }
      getSubject().getPrincipals().addAll(getPlayerPrincipals());
      p.setSubject(getSubject()); // update the players principals
      PlayerCredentials playerCredentials = new PlayerCredentials(getUsername(), String.valueOf(getPassword()));
      getSubject().getPrivateCredentials().add(playerCredentials);
      p.setPlayerCredentials(playerCredentials);

      cleanup();
      setCommitSucceeded(true);

    } else {
View Full Code Here

  public void testDoLoadPlayerCallback() throws IOException, UnsupportedCallbackException {
    String username = "test";
    String action = "wombat";
    MockControl playerCtrl = MockControl.createNiceControl(Player.class);
    Player obj = (Player) playerCtrl.getMock();
    final ActionCallback mockCallback = new ActionCallback(username, action);
    mockCallback.setMudObject(obj);
    final Callback[] callbacks = new Callback[1];
    callbacks[0] = mockCallback;
    MockControl callbackHandlerControl = MockControl.createControl(CallbackHandler.class);
View Full Code Here

  private final static Logger logger = Logger.getLogger(MudShell.class);

  public void run(Connection connection) {
    setConnection(connection);
    setExtendedTerminalIO((ExtendedTerminalIO) getConnection().getConnectionData().getEnvironment().get("terminalIO"));
    Player player = (Player) getConnection().getConnectionData().getEnvironment().get("player");
    LoginContext lc = (LoginContext) getConnection().getConnectionData().getEnvironment().get("loginContext");
    getInterpreter().doShellCommand("look", player);
    try {
      while (getObjectRegistry().getMudObject(player.getName()) != null) {
        handleRequest(player);
      }
    } catch (IOException e) {
      logger.error(e, e);
    } finally {
View Full Code Here

  protected Player loadPlayer(String username) throws CompilationFailedException, FileNotFoundException, ResourceException, ScriptException, InstantiationException {
    return getObjectLoader().loadPlayerData(username);
  }

  public Player tryToloadPlayer(String username) {
    Player player = null;
    try {
      player = loadPlayer(username);
    } catch (CompilationFailedException e) {
      logger.error(e, e);
    } catch (InstantiationException e) {
View Full Code Here

      logger.error(e, e);
    }
  }

  public Player loadPlayerData(String username) throws CompilationFailedException, ResourceException, ScriptException, FileNotFoundException {
    Player player = null;
    XStream xstream = getXStream();
    load(playerImpl);
    File playerFile = createFile(username);
    if (playerFile.exists()) {
      InputStream xmlIn = createFileInputStream(playerFile);
View Full Code Here

      logger.error(e, e);
    }
  }

  public Player createNewPlayer(String username) throws InstantiationException, FileNotFoundException, CompilationFailedException {
    Player player = (Player) load(getPlayerImpl());
    String upperName = username.substring(0, 1).toUpperCase() + username.substring(1);

    player.setName(upperName);
    player.addShortName(upperName);
    player.addShortName(username);
    getObjectRegistry().register(player);

    return player;
  }
View Full Code Here

TOP

Related Classes of org.groovymud.object.alive.Player

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.