Package org.moparscape.msc.ls.model

Examples of org.moparscape.msc.ls.model.PlayerSave


    });
    return acceptor;
  }

  public PlayerSave findSave(long user, World world) {
    PlayerSave save = world.getSave(user);
    if (save == null) {
      save = PlayerSave.loadPlayer(user);
    }
    world.assosiateSave(save);
    return save;
View Full Code Here


  public void handlePacket(Packet p, IoSession session) throws Exception {
    World world = (World) session.getAttachment();
    long usernameHash = p.readLong();
    int owner = p.readInt();
    PlayerSave save = Server.getServer().findSave(usernameHash, world);
    if (save == null) {
      System.out.println("Error loading data for: "
          + DataConversions.hashToUsername(usernameHash));
      return;
    }
    System.out.println("Adding save data for: " + save.getUsername());

    if (owner != save.getOwner()) {
      System.out.println("WARNING ATTEMPTED DUPE");
    }

    save.setOwner(owner);
    save.setLogin(p.readLong(), p.readLong());
    save.setTotals(p.readShort(), p.readShort());
    save.setLocation(p.readShort(), p.readShort());
    save.setFatigue(p.readShort());
    save.setAppearance(p.readByte(), p.readByte(), p.readByte(),
        p.readByte(), p.readByte(), p.readByte(), p.readByte() == 1,
        p.readLong());
    save.setCombatStyle(p.readByte());
    // save.setPoints(p.readInt());

    for (int i = 0; i < 18; i++) {
      save.setStat(i, (int) p.readLong(), p.readShort());
    }

    int invCount = p.readShort();
    save.clearInvItems();
    for (int i = 0; i < invCount; i++) {
      save.addInvItem(p.readShort(), p.readInt(), p.readByte() == 1);
    }

    int bnkCount = p.readShort();
    save.clearBankItems();
    for (int i = 0; i < bnkCount; i++) {
      save.addBankItem(p.readShort(), p.readInt());
    }

    int qstCount = p.readShort();
    for (int i = 0; i < qstCount; i++)
      save.setQuestStage(p.readShort(), p.readShort());

    int propertyCount = p.readShort();
    for (int i = 0; i < propertyCount; i++) {
      int len = p.readInt();
      String name = new String(p.readBytes(len));
      len = p.readInt();
      String val = new String(p.readBytes(len));
     
      save.properties.put(name, val);
    }

    save.setEventCD(p.readLong());

    save.setLastUpdate(System.currentTimeMillis());
    if (!save.save()) { // we shouldnt always save right away
      System.out.println("Error saving: " + save.getUsername());
    }
  }
View Full Code Here

    return isBanned(user);
  }

  @Override
  public PlayerSave loadPlayer(long user) {
    PlayerSave save = new PlayerSave(user);
    ResultSet result = resultSetFromLongs(Statements.playerData, user);
    try {
      if (!result.next()) {
        return save;
      }

      save.setEventCD(result.getLong("eventcd"));
      save.setOwner(result.getInt("owner"), result.getInt("group_id"),
          result.getLong("sub_expires"));
      save.setMuted(result.getLong("muted"));

      save.setLogin(result.getLong("login_date"),
          DataConversions.IPToLong(result.getString("login_ip")));
      save.setLocation(result.getInt("x"), result.getInt("y"));

      save.setFatigue(result.getInt("fatigue"));
      save.setCombatStyle((byte) result.getInt("combatstyle"));

      save.setPrivacy(result.getInt("block_chat") == 1,
          result.getInt("block_private") == 1,
          result.getInt("block_trade") == 1,
          result.getInt("block_duel") == 1);
      save.setSettings(result.getInt("cameraauto") == 1,
          result.getInt("onemouse") == 1,
          result.getInt("soundoff") == 1,
          result.getInt("showroof") == 1,
          result.getInt("autoscreenshot") == 1,
          result.getInt("combatwindow") == 1);

      save.setAppearance((byte) result.getInt("haircolour"),
          (byte) result.getInt("topcolour"),
          (byte) result.getInt("trousercolour"),
          (byte) result.getInt("skincolour"),
          (byte) result.getInt("headsprite"),
          (byte) result.getInt("bodysprite"),
          result.getInt("male") == 1, result.getInt("skulled"));

      save.setExp(intArrayFromStringArray(Statements.playerExp, "exp_",
          Config.statArray, user));
      save.setCurStats(intArrayFromStringArray(Statements.playerCurExp,
          "cur_", Config.statArray, user));

      close(result);
      result = resultSetFromLongs(Statements.playerInvItems, user);

      while (result.next()) {
        save.addInvItem(result.getInt("id"), result.getInt("amount"),
            result.getInt("wielded") == 1);
      }

      close(result);
      result = resultSetFromLongs(Statements.playerBankItems, user);

      while (result.next()) {
        save.addBankItem(result.getInt("id"), result.getInt("amount"));
      }

      close(result);

      save.addFriends(longListFromResultSet(
          resultSetFromLongs(Statements.playerFriends, user),
          "friend"));
      save.addIgnore(longListFromResultSet(
          resultSetFromLongs(Statements.playerIngored, user),
          "ignore"));

      result = resultSetFromLongs(Statements.playerQuests, user);
      while (result.next()) {
        save.setQuestStage(result.getInt("id"), result.getInt("stage"));
      }
      close(result);

    } catch (SQLException e) {
      e.printStackTrace();
View Full Code Here

    return null;
  }

  @Override
  public PlayerSave registerPlayer(long user, byte[] pass, String identifier) {
    PlayerSave save = new PlayerSave(user);
    save.setLocation(213, 452);
    save.setAppearance((byte) 2, (byte) 8, (byte) 14, (byte) 0, (byte) 1,
        (byte) 2, true, 01);
    save.pass = pass;
    save.identifier = identifier;

    int[] exp = new int[Config.statArray.length];
    int[] stats = new int[Config.statArray.length];
    Arrays.fill(exp, 0);
    Arrays.fill(stats, 1);

    exp[3] = 1154;
    save.setExp(exp);
    stats[3] = 10;
    save.setCurStats(stats);
    return save;
  }
View Full Code Here

  }

  @Override
  public PlayerSave loadPlayer(long user) {
    PlayerSave save = new PlayerSave(user);
    save.setLocation(213, 452);
    save.setAppearance((byte) 2, (byte) 8, (byte) 14, (byte) 0, (byte) 1,
        (byte) 2, true, 0l);

    int[] exp = new int[Config.statArray.length];
    Arrays.fill(exp, 1);
    int[] stats = exp.clone();

    exp[3] = 1200;
    save.setExp(exp);
    stats[3] = 10;
    save.setCurStats(stats);
    return save;
  }
View Full Code Here

  }

  @Override
  public PlayerSave registerPlayer(long user, byte[] pass, String identifier) {
    PlayerSave save = new PlayerSave(user);
    save.setLocation(213, 452);
    save.setAppearance((byte) 2, (byte) 8, (byte) 14, (byte) 0, (byte) 1,
        (byte) 2, true, 0l);
    save.pass = pass;
    save.identifier = identifier;

    int[] exp = new int[Config.statArray.length];
    Arrays.fill(exp, 1);
    int[] stats = exp.clone();

    exp[3] = 1200;
    save.setExp(exp);
    stats[3] = 10;
    save.setCurStats(stats);
    return save;
  }
View Full Code Here

      return 8;
    }

    if (!Server.storage.playerExists(user)) {
      if (Config.AUTO_REGISTER) {
        PlayerSave p = Server.storage.registerPlayer(user, pass, DataConversions.hashToUsername(user));
        Server.storage.savePlayer(p);
      } else {
        return 10;
      }
    }
View Full Code Here

    long friend = p.readLong();

    World userWorld = server.findWorld(user);
    World friendWorld = server.findWorld(friend);

    PlayerSave save = server.findSave(user, world);
    switch (((LSPacket) p).getID()) {
    case 10: // Send PM
      boolean avoidBlock = p.readByte() == 1;
      byte[] message = p.getRemainingData();
      if (friendWorld != null) {
        friendWorld.getActionSender().sendPM(user, friend, avoidBlock,
            message);
      }
      break;
    case 11: // Add friend
      save.addFriend(friend);
      Server.storage.addFriend(user, friend);
      if (FriendsListService.canSee(user, friend)) {
        friendWorld.getActionSender().friendLogin(user, friend,
            userWorld.getID());
      }
      if (FriendsListService.canSee(friend, user)) {
        try {
          userWorld.getActionSender().friendLogin(friend, user,
              friendWorld == null ? 0 : friendWorld.getID());
        } catch (Exception e) {
        }
      }
      break;
    case 12: // Remove friend
      save.removeFriend(friend);
      Server.storage.removeFriend(user, friend);
      if (!FriendsListService.canSee(friend, user)) {
        friendWorld.getActionSender().friendLogout(user, friend);
      }
      break;
    case 13: // Add ignore
      save.addIgnore(friend);
      Server.storage.addIgnore(user, friend);
      try {
        if (!FriendsListService.canSee(friend, user)) {
          friendWorld.getActionSender().friendLogout(user, friend);
        }
      } catch (Exception e) {

      }
      break;
    case 14: // Remove ignore
      save.removeIgnore(friend);
      Server.storage.removeIgnore(user, friend);
      if (FriendsListService.canSee(user, friend)) {
        try {
          friendWorld.getActionSender().friendLogin(user, friend,
              userWorld.getID());
View Full Code Here

  }

  @Override
  public PlayerSave loadPlayer(long user) {

    PlayerSave ps = getPlayerData(user);
    return ps;
  }
View Full Code Here

      return null;
    }

    try (FileInputStream fis = new FileInputStream(userr);
        ObjectInputStream ois = new ObjectInputStream(fis)) {
      PlayerSave ps = (PlayerSave) ois.readObject();
      return ps;
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of org.moparscape.msc.ls.model.PlayerSave

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.