CharacterSelect.java 6.1 KB

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