Advertisement
mochitto

Untitled

Aug 25th, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.03 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Server_BETA
  3. Index: java/com/l2jserver/gameserver/network/clientpackets/Say2.java
  4. ===================================================================
  5. --- java/com/l2jserver/gameserver/network/clientpackets/Say2.java   (revision 4848)
  6. +++ java/com/l2jserver/gameserver/network/clientpackets/Say2.java   (working copy)
  7. @@ -14,10 +14,13 @@
  8.   */
  9.  package com.l2jserver.gameserver.network.clientpackets;
  10.  
  11. +import java.util.List;
  12.  import java.util.logging.Level;
  13.  import java.util.logging.LogRecord;
  14.  import java.util.logging.Logger;
  15.  
  16. +import javolution.util.FastList;
  17. +
  18.  import com.l2jserver.Config;
  19.  import com.l2jserver.gameserver.handler.ChatHandler;
  20.  import com.l2jserver.gameserver.handler.IChatHandler;
  21. @@ -99,6 +102,8 @@
  22.     private int _type;
  23.     private String _target;
  24.    
  25. +   private List<ItemLink> _links = new FastList<ItemLink>();
  26. +  
  27.     @Override
  28.     protected void readImpl()
  29.     {
  30. @@ -133,10 +138,22 @@
  31.             return;
  32.         }
  33.        
  34. +       int length = _text.length();
  35. +      
  36. +       // we dont count the invisible characters in item link, we need only the title length
  37. +       if (_text.indexOf(8) >= 0)
  38. +       {
  39. +           parseItems();
  40. +           for(ItemLink link : _links)
  41. +           {
  42. +               length -= link.getLength() - link.getTitle().length();
  43. +           }
  44. +       }
  45. +      
  46.         // Even though the client can handle more characters than it's current limit allows, an overflow (critical error) happens if you pass a huge (1000+) message.
  47.         // July 11, 2011 - Verified on High Five 4 official client as 105.
  48.         // Allow higher limit if player shift some item (text is longer then).
  49. -       if (!activeChar.isGM() && ((_text.indexOf(8) >= 0 && _text.length() > 500) || (_text.indexOf(8) < 0 && _text.length() > 105)))
  50. +       if (length > 105 && !activeChar.isGM())
  51.         {
  52.             activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DONT_SPAM));
  53.             return;
  54. @@ -191,10 +208,13 @@
  55.             _logChat.log(record);
  56.         }
  57.        
  58. -      
  59.         if (_text.indexOf(8) >= 0)
  60. -           if (!parseAndPublishItem(activeChar))
  61. +       {
  62. +           if(!publishItems(activeChar))
  63. +           {
  64.                 return;
  65. +           }
  66. +       }
  67.        
  68.         // Say Filter implementation
  69.         if (Config.USE_SAY_FILTER)
  70. @@ -225,25 +245,31 @@
  71.         _text = filteredText;
  72.     }
  73.    
  74. -   private boolean parseAndPublishItem(L2PcInstance owner)
  75. +   private void parseItems()
  76.     {
  77.         int pos1 = -1;
  78.         while ((pos1 = _text.indexOf(8, pos1)) > -1)
  79.         {
  80. -           int pos = _text.indexOf("ID=", pos1);
  81. -           if (pos == -1)
  82. -               return false;
  83. -           StringBuilder result = new StringBuilder(9);
  84. -           pos += 3;
  85. -           while (Character.isDigit(_text.charAt(pos)))
  86. -               result.append(_text.charAt(pos++));
  87. -           int id = Integer.parseInt(result.toString());
  88. -           L2Object item = L2World.getInstance().findObject(id);
  89. +           int end = _text.indexOf(8, pos1+1) + 1;
  90. +           ItemLink link = new ItemLink(_text.substring(pos1, end));
  91. +           if (link.isValid())
  92. +           {
  93. +               _links.add(link);
  94. +           }
  95. +           pos1 = end;
  96. +       }
  97. +   }
  98. +  
  99. +   private boolean publishItems(L2PcInstance owner)
  100. +   {
  101. +       for(ItemLink link : _links)
  102. +       {
  103. +           L2Object item = L2World.getInstance().findObject(link.getId());
  104.             if (item instanceof L2ItemInstance)
  105.             {
  106. -               if (owner.getInventory().getItemByObjectId(id) == null)
  107. +               if (owner.getInventory().getItemByObjectId(link.getId()) == null)
  108.                 {
  109. -                   _log.info(getClient() + " trying publish item which doesnt own! ID:" + id);
  110. +                   _log.info(getClient() + " trying publish item which doesnt own! ID:" + link.getId());
  111.                     return false;
  112.                 }
  113.                 ((L2ItemInstance) item).publish();
  114. @@ -253,14 +279,113 @@
  115.                 _log.info(getClient() + " trying publish object which is not item! Object:" + item);
  116.                 return false;
  117.             }
  118. -           pos1 = _text.indexOf(8, pos) + 1;
  119. -           if (pos1 == 0) // missing ending tag
  120. +       }
  121. +      
  122. +       return true;
  123. +   }
  124. +  
  125. +   private final class ItemLink
  126. +   {
  127. +       private int _id;
  128. +       private int _type;
  129. +       private int _color;    
  130. +       private boolean _underline;
  131. +       private String _title;
  132. +      
  133. +       private String _text;
  134. +       private boolean _valid = false;
  135. +      
  136. +       //for chat parse
  137. +       public ItemLink(String chatLink)
  138. +       {
  139. +           _text = chatLink;
  140. +           if(_text.contains("Type=") && _text.contains("ID=") && _text.contains("Color=") && _text.contains("Underline=") && _text.contains("Title=") && _text.indexOf(27) > 0)
  141.             {
  142. -               _log.info(getClient() + " sent invalid publish item msg! ID:" + id);
  143. -               return false;
  144. +               try
  145. +               {
  146. +                   _id = getIntValue("ID=");
  147. +                   _type = getIntValue("Type=");
  148. +                   _color = getIntValue("Color=");
  149. +                   _underline = getIntValue("Underline=") == 1 ? true : false;
  150. +                   _title = _text.substring(_text.indexOf(27) + 1, _text.indexOf(27, _text.indexOf(27) + 1));
  151. +               }
  152. +               catch(StringIndexOutOfBoundsException|NumberFormatException e)
  153. +               {
  154. +                   _log.info(getClient() + " sent invalid publish item msg!");
  155. +                   return;
  156. +               }
  157. +               _valid = true;
  158.             }
  159.         }
  160. -       return true;
  161. +      
  162. +       @Override
  163. +       public String toString()
  164. +       {
  165. +           StringBuilder sb = new StringBuilder();
  166. +           sb.append((char)8);
  167. +           sb.append("Type=" + getType());
  168. +           sb.append(" ID="+ getId());
  169. +           sb.append(" Color="+ getColor());
  170. +           sb.append(" Underline="+ (isUnderline() ? 1 : 0));
  171. +           sb.append(" Title=" + (char)27 + getTitle() + (char)27);
  172. +           sb.append((char)8);    
  173. +          
  174. +           return sb.toString();
  175. +       }
  176. +      
  177. +       private int getIntValue(String key)
  178. +       {
  179. +           int pos = _text.indexOf(key);
  180. +          
  181. +           if (pos == -1)
  182. +               return -1;
  183. +          
  184. +           String result = "";
  185. +          
  186. +           pos += key.length();
  187. +          
  188. +           while (Character.isDigit(_text.charAt(pos)))
  189. +           {
  190. +               result += _text.charAt(pos++);
  191. +           }          
  192. +          
  193. +           return Integer.valueOf(result);
  194. +       }
  195. +      
  196. +       public boolean isValid()
  197. +       {
  198. +           return _valid;
  199. +       }
  200. +      
  201. +       public int getLength()
  202. +       {
  203. +           return _text.length();
  204. +       }
  205. +      
  206. +       public boolean isUnderline()
  207. +       {
  208. +           return _underline;
  209. +       }
  210. +      
  211. +       public int getColor()
  212. +       {
  213. +           return _color;
  214. +       }
  215. +      
  216. +       public int getType()
  217. +       {
  218. +           return _type;
  219. +       }
  220. +      
  221. +       public int getId()
  222. +       {
  223. +           return _id;
  224. +       }
  225. +      
  226. +       public String getTitle()
  227. +       {
  228. +           return _title;
  229. +       }
  230.     }
  231.    
  232.     @Override
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement