S_PacketBox.java :  » Game » l1j-tw-99nets » l1j » server » server » serverpackets » Java Open Source

Java Open Source » Game » l1j tw 99nets 
l1j tw 99nets » l1j » server » server » serverpackets » S_PacketBox.java
/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package l1j.server.server.serverpackets;

import java.util.Calendar;
import java.util.Iterator;
import java.util.TimeZone;

import l1j.server.Config;
import l1j.server.server.Account;
import l1j.server.server.Opcodes;
import l1j.server.server.model.L1World;
import l1j.server.server.model.Instance.L1PcInstance;

/**
 * 
 */
public class S_PacketBox extends ServerBasePacket {
  private static final String S_PACKETBOX = "[S] S_PacketBox";

  private byte[] _byte = null;

  // *** S_107 sub code list ***
  /** Updating */
  public static final int UPDATE_OLD_PART_MEMBER = 104;

  /** 3.3 () */
  public static final int PATRY_UPDATE_MEMBER = 105;

  /** 3.3() */
  public static final int PATRY_SET_MASTER = 106;

  /** 3.3 (,) */
  public static final int PATRY_MEMBERS = 110;

  // 1:Kent 2:Orc 3:WW 4:Giran 5:Heine 6:Dwarf 7:Aden 8:Diad 9:9 ...
  /** C(id) H(?): %s */
  public static final int MSG_WAR_BEGIN = 0;

  /** C(id) H(?): %s */
  public static final int MSG_WAR_END = 1;

  /** C(id) H(?): %s */
  public static final int MSG_WAR_GOING = 2;

  /** -:  () */
  public static final int MSG_WAR_INITIATIVE = 3;

  /** -:  */
  public static final int MSG_WAR_OCCUPY = 4;

  /** ?:  () */
  public static final int MSG_DUEL = 5;

  /** C(count): SMS / %d */
  public static final int MSG_SMS_SENT = 6;

  /** -: 2 () */
  public static final int MSG_MARRIED = 9;

  /** C(weight): (30) */
  public static final int WEIGHT = 10;

  /** C(food): (30) */
  public static final int FOOD = 11;

  /** C(0) C(level): %d (0~49) */
  public static final int MSG_LEVEL_OVER = 12;

  /** UBHTML */
  public static final int HTML_UB = 14;

  /**
   * C(id)<br>
   * 1:<br>
   * 2:<br>
   * 3:<br>
   * 4:<br>
   * 5:<br>
   */
  public static final int MSG_ELF = 15;

  /** C(count) S(name)...:  */
  public static final int ADD_EXCLUDE2 = 17;

  /** S(name):  */
  public static final int ADD_EXCLUDE = 18;

  /** S(name):  */
  public static final int REM_EXCLUDE = 19;

  /**  */
  public static final int ICONS1 = 20;

  /**  */
  public static final int ICONS2 = 21;

  /**  */
  public static final int ICON_AURA = 22;

  /** S(name): %s */
  public static final int MSG_TOWN_LEADER = 23;

  /**
   * C(id): %s<br>
   * id - 1: 2: 3:
   */
  public static final int MSG_RANK_CHANGED = 27;

  /** D(?) S(name) S(clanname): %s%s */
  public static final int MSG_WIN_LASTAVARD = 30;

  /** -: \f1 */
  public static final int MSG_FEEL_GOOD = 31;

  /** C_30 */
  public static final int SOMETHING1 = 33;

  /** H(time):  */
  public static final int ICON_BLUEPOTION = 34;

  /** H(time):  */
  public static final int ICON_POLYMORPH = 35;

  /** H(time):  */
  public static final int ICON_CHATBAN = 36;

  /** C_7C_7 */
  public static final int SOMETHING2 = 37;

  /** HTML */
  public static final int HTML_CLAN1 = 38;

  /** H(time):  */
  public static final int ICON_I2H = 40;

  /**  */
  public static final int CHARACTER_CONFIG = 41;

  /**  */
  public static final int LOGOUT = 42;

  /**  */
  public static final int MSG_CANT_LOGOUT = 43;

  /**
   * C(count) D(time) S(name) S(info):<br>
   * [CALL] BOT
   * C_RequestWho
   * bot_list.txt+
   */
  public static final int CALL_SOMETHING = 45;

  /**
   * C(id):  <br>
   * id - 1: 2: 3:
   */
  public static final int MSG_COLOSSEUM = 49;

  /** HTML */
  public static final int HTML_CLAN2 = 51;

  /**  */
  public static final int COOK_WINDOW = 52;

  /** C(type) H(time):  */
  public static final int ICON_COOKING = 53;

  /**  */
  public static final int FISHING = 55;

  public S_PacketBox(int subCode) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case MSG_WAR_INITIATIVE:
      case MSG_WAR_OCCUPY:
      case MSG_MARRIED:
      case MSG_FEEL_GOOD:
      case MSG_CANT_LOGOUT:
      case LOGOUT:
      case FISHING:
        break;
      case CALL_SOMETHING:
        callSomething();
      default:
        break;
    }
  }

  public S_PacketBox(int subCode, int value) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case ICON_BLUEPOTION:
      case ICON_CHATBAN:
      case ICON_I2H:
      case ICON_POLYMORPH:
        writeH(value); // time
        break;
      case MSG_WAR_BEGIN:
      case MSG_WAR_END:
      case MSG_WAR_GOING:
        writeC(value); // castle id
        writeH(0); // ?
        break;
      case MSG_SMS_SENT:
      case WEIGHT:
      case FOOD:
        writeC(value);
        break;
      case MSG_ELF: // %s
      case MSG_RANK_CHANGED: // %s
      case MSG_COLOSSEUM: // 
        writeC(value); // msg id
        writeC(0);
        break;
      case MSG_LEVEL_OVER:
        writeC(0); // ?
        writeC(value); // 0-49
        break;
      case COOK_WINDOW:
        writeC(0xdb); // ?
        writeC(0x31);
        writeC(0xdf);
        writeC(0x02);
        writeC(0x01);
        writeC(value); // level
        break;
      default:
        break;
    }
  }

  public S_PacketBox(int subCode, int type, int time) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case ICON_COOKING:
        if (type == 54) { // 
          writeC(0x12);
          writeC(0x0c);
          writeC(0x0c);
          writeC(0x07);
          writeC(0x12);
          writeC(0x08);
          writeH(0x0000); //  :2000100%
          writeC(type); // 
          writeC(0x2a);
          writeH(time); // 
          writeC(0x0); //  :240100%
        } else if (type != 7) {
          writeC(0x12);
          writeC(0x0b);
          writeC(0x0c);
          writeC(0x0b);
          writeC(0x0f);
          writeC(0x08);
          writeH(0x0000); //  :2000100%
          writeC(type); // 
          writeC(0x24);
          writeH(time); // 
          writeC(0x00); //  :240100%
        } else {
          writeC(0x12);
          writeC(0x0b);
          writeC(0x0c);
          writeC(0x0b);
          writeC(0x0f);
          writeC(0x08);
          writeH(0x0000); //  :2000100%
          writeC(type); // 
          writeC(0x26);
          writeH(time); // 
          writeC(0x00); //  :240100%
        }
        break;
      case MSG_DUEL:
        writeD(type); // ID
        writeD(time); // ID
        break;
      default:
        break;
    }
  }

  public S_PacketBox(int subCode, int[] type) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case 88: // 
      writeC(type[0]);
      writeC(0x00);
        break;
      case 101: // 
        writeC(type[1]);
        break;
      case 21: // 
        writeC(0x00);
        writeC(0x00);
        writeC(0x00);
        writeC(type[2]); // 
        break;
      default:
        break;
    }
  }

  public S_PacketBox(int subCode, String name) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case ADD_EXCLUDE:
      case REM_EXCLUDE:
      case MSG_TOWN_LEADER:
        writeS(name);
        break;
      default:
        break;
    }
  }

  public S_PacketBox(int subCode, int id, String name, String clanName) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case MSG_WIN_LASTAVARD:
        writeD(id); // ID
        writeS(name);
        writeS(clanName);
        break;
      default:
        break;
    }
  }

  public S_PacketBox(int subCode, Object[] names) {
    writeC(Opcodes.S_OPCODE_PACKETBOX);
    writeC(subCode);

    switch (subCode) {
      case ADD_EXCLUDE2:
        writeC(names.length);
        for (Object name : names) {
          writeS(name.toString());
        }
        break;
      default:
        break;
    }
  }

  private void callSomething() {
    Iterator<L1PcInstance> itr = L1World.getInstance().getAllPlayers().iterator();

    writeC(L1World.getInstance().getAllPlayers().size());

    while (itr.hasNext()) {
      L1PcInstance pc = itr.next();
      Account acc = Account.load(pc.getAccountName());

      //  
      if (acc == null) {
        writeD(0);
      }
      else {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Config.TIME_ZONE));
        long lastactive = acc.getLastActive().getTime();
        cal.setTimeInMillis(lastactive);
        cal.set(Calendar.YEAR, 1970);
        int time = (int) (cal.getTimeInMillis() / 1000);
        writeD(time); // JST 1970 1/1 09:00 
      }

      // 
      writeS(pc.getName()); // 12
      writeS(pc.getClanname()); // []12
    }
  }

  @Override
  public byte[] getContent() {
    if (_byte == null) {
      _byte = getBytes();
    }

    return _byte;
  }

  @Override
  public String getType() {
    return S_PACKETBOX;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.