CharacterSelect.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.network.L2GameClient.GameClientState;
  20. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  21. import net.sf.l2j.gameserver.serverpackets.CharSelected;
  22. import net.sf.l2j.gameserver.serverpackets.SSQInfo;
  23. /**
  24. * This class ...
  25. *
  26. * @version $Revision: 1.5.2.1.2.5 $ $Date: 2005/03/27 15:29:30 $
  27. */
  28. public class CharacterSelect extends L2GameClientPacket
  29. {
  30. private static final String _C__0D_CHARACTERSELECT = "[C] 0D CharacterSelect";
  31. private static Logger _log = Logger.getLogger(CharacterSelect.class.getName());
  32. // cd
  33. private int _charSlot;
  34. @SuppressWarnings("unused")
  35. private int _unk1; // new in C4
  36. @SuppressWarnings("unused")
  37. private int _unk2; // new in C4
  38. @SuppressWarnings("unused")
  39. private int _unk3; // new in C4
  40. @SuppressWarnings("unused")
  41. private int _unk4; // new in C4
  42. @Override
  43. protected void readImpl()
  44. {
  45. _charSlot = readD();
  46. _unk1 = readH();
  47. _unk2 = readD();
  48. _unk3 = readD();
  49. _unk4 = readD();
  50. }
  51. @Override
  52. protected void runImpl()
  53. {
  54. // if there is a playback.dat file in the current directory, it will
  55. // be sent to the client instead of any regular packets
  56. // to make this work, the first packet in the playback.dat has to
  57. // be a [S]0x21 packet
  58. // after playback is done, the client will not work correct and need to exit
  59. //playLogFile(getConnection()); // try to play log file
  60. // we should always be abble to acquire the lock
  61. // but if we cant lock then nothing should be done (ie repeated packet)
  62. if (this.getClient().getActiveCharLock().tryLock())
  63. {
  64. try
  65. {
  66. // should always be null
  67. // but if not then this is repeated packet and nothing should be done here
  68. if (this.getClient().getActiveChar() == null)
  69. {
  70. // The L2PcInstance must be created here, so that it can be attached to the L2GameClient
  71. if (Config.DEBUG)
  72. {
  73. _log.fine("selected slot:" + _charSlot);
  74. }
  75. //load up character from disk
  76. L2PcInstance cha = getClient().loadCharFromDisk(_charSlot);
  77. if (cha == null)
  78. {
  79. _log.severe("Character could not be loaded (slot:"+_charSlot+")");
  80. sendPacket(ActionFailed.STATIC_PACKET);
  81. return;
  82. }
  83. if (cha.getAccessLevel().getLevel() < 0)
  84. {
  85. cha.closeNetConnection();
  86. return;
  87. }
  88. cha.setClient(this.getClient());
  89. getClient().setActiveChar(cha);
  90. sendPacket(new SSQInfo());
  91. this.getClient().setState(GameClientState.IN_GAME);
  92. CharSelected cs = new CharSelected(cha, getClient().getSessionId().playOkID1);
  93. sendPacket(cs);
  94. }
  95. }
  96. finally
  97. {
  98. this.getClient().getActiveCharLock().unlock();
  99. }
  100. }
  101. }
  102. /*
  103. private void playLogFile(Connection connection)
  104. {
  105. long diff = 0;
  106. long first = -1;
  107. try
  108. {
  109. LineNumberReader lnr =
  110. new LineNumberReader(new FileReader("playback.dat"));
  111. String line = null;
  112. while ((line = lnr.readLine()) != null)
  113. {
  114. if (line.length() > 0 && line.substring(0, 1).equals("1"))
  115. {
  116. String timestamp = line.substring(0, 13);
  117. long time = Long.parseLong(timestamp);
  118. if (first == -1)
  119. {
  120. long start = System.currentTimeMillis();
  121. first = time;
  122. diff = start - first;
  123. }
  124. String cs = line.substring(14, 15);
  125. // read packet definition
  126. ByteArrayOutputStream bais = new ByteArrayOutputStream();
  127. while (true)
  128. {
  129. String temp = lnr.readLine();
  130. if (temp.length() < 53)
  131. {
  132. break;
  133. }
  134. String bytes = temp.substring(6, 53);
  135. StringTokenizer st = new StringTokenizer(bytes);
  136. while (st.hasMoreTokens())
  137. {
  138. String b = st.nextToken();
  139. int number = Integer.parseInt(b, 16);
  140. bais.write(number);
  141. }
  142. }
  143. if (cs.equals("S"))
  144. {
  145. //wait for timestamp and send packet
  146. int wait =
  147. (int) (time + diff - System.currentTimeMillis());
  148. if (wait > 0)
  149. {
  150. if (Config.DEBUG) _log.fine("waiting"+ wait);
  151. Thread.sleep(wait);
  152. }
  153. if (Config.DEBUG) _log.fine("sending:"+ time);
  154. byte[] data = bais.toByteArray();
  155. if (data.length != 0)
  156. {
  157. //connection.sendPacket(data);
  158. }
  159. else
  160. {
  161. if (Config.DEBUG) _log.fine("skipping broken data");
  162. }
  163. }
  164. else
  165. {
  166. // skip packet
  167. }
  168. }
  169. }
  170. }
  171. catch (FileNotFoundException f)
  172. {
  173. // should not happen
  174. }
  175. catch (Exception e)
  176. {
  177. _log.log(Level.SEVERE, "Error:", e);
  178. }
  179. }
  180. */
  181. /* (non-Javadoc)
  182. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  183. */
  184. @Override
  185. public String getType()
  186. {
  187. return _C__0D_CHARACTERSELECT;
  188. }
  189. }