Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P L2J_Server_BETA
- Index: java/com/l2jserver/gameserver/network/clientpackets/Say2.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/clientpackets/Say2.java (revision 4848)
- +++ java/com/l2jserver/gameserver/network/clientpackets/Say2.java (working copy)
- @@ -14,10 +14,13 @@
- */
- package com.l2jserver.gameserver.network.clientpackets;
- +import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.LogRecord;
- import java.util.logging.Logger;
- +import javolution.util.FastList;
- +
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.handler.ChatHandler;
- import com.l2jserver.gameserver.handler.IChatHandler;
- @@ -99,6 +102,8 @@
- private int _type;
- private String _target;
- + private List<ItemLink> _links = new FastList<ItemLink>();
- +
- @Override
- protected void readImpl()
- {
- @@ -133,10 +138,22 @@
- return;
- }
- + int length = _text.length();
- +
- + // we dont count the invisible characters in item link, we need only the title length
- + if (_text.indexOf(8) >= 0)
- + {
- + parseItems();
- + for(ItemLink link : _links)
- + {
- + length -= link.getLength() - link.getTitle().length();
- + }
- + }
- +
- // 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.
- // July 11, 2011 - Verified on High Five 4 official client as 105.
- // Allow higher limit if player shift some item (text is longer then).
- - if (!activeChar.isGM() && ((_text.indexOf(8) >= 0 && _text.length() > 500) || (_text.indexOf(8) < 0 && _text.length() > 105)))
- + if (length > 105 && !activeChar.isGM())
- {
- activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DONT_SPAM));
- return;
- @@ -191,10 +208,13 @@
- _logChat.log(record);
- }
- -
- if (_text.indexOf(8) >= 0)
- - if (!parseAndPublishItem(activeChar))
- + {
- + if(!publishItems(activeChar))
- + {
- return;
- + }
- + }
- // Say Filter implementation
- if (Config.USE_SAY_FILTER)
- @@ -225,25 +245,31 @@
- _text = filteredText;
- }
- - private boolean parseAndPublishItem(L2PcInstance owner)
- + private void parseItems()
- {
- int pos1 = -1;
- while ((pos1 = _text.indexOf(8, pos1)) > -1)
- {
- - int pos = _text.indexOf("ID=", pos1);
- - if (pos == -1)
- - return false;
- - StringBuilder result = new StringBuilder(9);
- - pos += 3;
- - while (Character.isDigit(_text.charAt(pos)))
- - result.append(_text.charAt(pos++));
- - int id = Integer.parseInt(result.toString());
- - L2Object item = L2World.getInstance().findObject(id);
- + int end = _text.indexOf(8, pos1+1) + 1;
- + ItemLink link = new ItemLink(_text.substring(pos1, end));
- + if (link.isValid())
- + {
- + _links.add(link);
- + }
- + pos1 = end;
- + }
- + }
- +
- + private boolean publishItems(L2PcInstance owner)
- + {
- + for(ItemLink link : _links)
- + {
- + L2Object item = L2World.getInstance().findObject(link.getId());
- if (item instanceof L2ItemInstance)
- {
- - if (owner.getInventory().getItemByObjectId(id) == null)
- + if (owner.getInventory().getItemByObjectId(link.getId()) == null)
- {
- - _log.info(getClient() + " trying publish item which doesnt own! ID:" + id);
- + _log.info(getClient() + " trying publish item which doesnt own! ID:" + link.getId());
- return false;
- }
- ((L2ItemInstance) item).publish();
- @@ -253,14 +279,113 @@
- _log.info(getClient() + " trying publish object which is not item! Object:" + item);
- return false;
- }
- - pos1 = _text.indexOf(8, pos) + 1;
- - if (pos1 == 0) // missing ending tag
- + }
- +
- + return true;
- + }
- +
- + private final class ItemLink
- + {
- + private int _id;
- + private int _type;
- + private int _color;
- + private boolean _underline;
- + private String _title;
- +
- + private String _text;
- + private boolean _valid = false;
- +
- + //for chat parse
- + public ItemLink(String chatLink)
- + {
- + _text = chatLink;
- + if(_text.contains("Type=") && _text.contains("ID=") && _text.contains("Color=") && _text.contains("Underline=") && _text.contains("Title=") && _text.indexOf(27) > 0)
- {
- - _log.info(getClient() + " sent invalid publish item msg! ID:" + id);
- - return false;
- + try
- + {
- + _id = getIntValue("ID=");
- + _type = getIntValue("Type=");
- + _color = getIntValue("Color=");
- + _underline = getIntValue("Underline=") == 1 ? true : false;
- + _title = _text.substring(_text.indexOf(27) + 1, _text.indexOf(27, _text.indexOf(27) + 1));
- + }
- + catch(StringIndexOutOfBoundsException|NumberFormatException e)
- + {
- + _log.info(getClient() + " sent invalid publish item msg!");
- + return;
- + }
- + _valid = true;
- }
- }
- - return true;
- +
- + @Override
- + public String toString()
- + {
- + StringBuilder sb = new StringBuilder();
- + sb.append((char)8);
- + sb.append("Type=" + getType());
- + sb.append(" ID="+ getId());
- + sb.append(" Color="+ getColor());
- + sb.append(" Underline="+ (isUnderline() ? 1 : 0));
- + sb.append(" Title=" + (char)27 + getTitle() + (char)27);
- + sb.append((char)8);
- +
- + return sb.toString();
- + }
- +
- + private int getIntValue(String key)
- + {
- + int pos = _text.indexOf(key);
- +
- + if (pos == -1)
- + return -1;
- +
- + String result = "";
- +
- + pos += key.length();
- +
- + while (Character.isDigit(_text.charAt(pos)))
- + {
- + result += _text.charAt(pos++);
- + }
- +
- + return Integer.valueOf(result);
- + }
- +
- + public boolean isValid()
- + {
- + return _valid;
- + }
- +
- + public int getLength()
- + {
- + return _text.length();
- + }
- +
- + public boolean isUnderline()
- + {
- + return _underline;
- + }
- +
- + public int getColor()
- + {
- + return _color;
- + }
- +
- + public int getType()
- + {
- + return _type;
- + }
- +
- + public int getId()
- + {
- + return _id;
- + }
- +
- + public String getTitle()
- + {
- + return _title;
- + }
- }
- @Override
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement