- Implemented jumping system client packets.
- Reworked friend / block manager to containg memo and show correct data. - Fixed throwing exception, on player login if 2 invisible GMs are next to each other.
This commit is contained in:
@ -21,20 +21,19 @@ package com.l2jserver.gameserver.model;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javolution.util.FastMap;
|
||||
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.BlockListPacket;
|
||||
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
||||
import com.l2jserver.gameserver.network.serverpackets.friend.BlockListPacket;
|
||||
|
||||
/**
|
||||
* This class ...
|
||||
@ -43,10 +42,11 @@ import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
||||
public class BlockList
|
||||
{
|
||||
private static Logger _log = Logger.getLogger(BlockList.class.getName());
|
||||
private static Map<Integer, List<Integer>> _offlineList = new FastMap<Integer, List<Integer>>().shared();
|
||||
private static Map<Integer, HashMap<Integer, String>> _offlineList = new HashMap<>();
|
||||
|
||||
private final L2PcInstance _owner;
|
||||
private List<Integer> _blockList;
|
||||
private HashMap<Integer, String> _blockList;
|
||||
private final ArrayList<Integer> _updateMemos = new ArrayList<>();
|
||||
|
||||
public BlockList(L2PcInstance owner)
|
||||
{
|
||||
@ -60,26 +60,62 @@ public class BlockList
|
||||
|
||||
private void addToBlockList(int target)
|
||||
{
|
||||
_blockList.add(target);
|
||||
_blockList.put(target, "");
|
||||
updateInDB(target, true);
|
||||
}
|
||||
|
||||
private void removeFromBlockList(int target)
|
||||
{
|
||||
_blockList.remove(Integer.valueOf(target));
|
||||
if (_updateMemos.contains(target))
|
||||
{
|
||||
_updateMemos.remove(Integer.valueOf(target));
|
||||
}
|
||||
updateInDB(target, false);
|
||||
}
|
||||
|
||||
public void setBlockMemo(int target, String memo)
|
||||
{
|
||||
if (_blockList.containsKey(target))
|
||||
{
|
||||
_blockList.put(target, memo);
|
||||
_updateMemos.add(target);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBlockMemos()
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection())
|
||||
{
|
||||
for (int target : _updateMemos)
|
||||
{
|
||||
try (PreparedStatement statement = con.prepareStatement("UPDATE character_friends SET memo=? WHERE charId=? AND friendId=? AND relation=1"))
|
||||
{
|
||||
statement.setString(1, _blockList.get(target));
|
||||
statement.setInt(2, _owner.getObjectId());
|
||||
statement.setInt(3, target);
|
||||
statement.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
_blockList.clear();
|
||||
}
|
||||
|
||||
public void playerLogout()
|
||||
{
|
||||
_offlineList.put(_owner.getObjectId(), _blockList);
|
||||
}
|
||||
|
||||
private static List<Integer> loadList(int ObjId)
|
||||
private static HashMap<Integer, String> loadList(int ObjId)
|
||||
{
|
||||
List<Integer> list = new ArrayList<>();
|
||||
HashMap<Integer, String> list = new HashMap<>();
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=? AND relation=1"))
|
||||
PreparedStatement statement = con.prepareStatement("SELECT friendId, memo FROM character_friends WHERE charId=? AND relation=1"))
|
||||
{
|
||||
statement.setInt(1, ObjId);
|
||||
try (ResultSet rset = statement.executeQuery())
|
||||
@ -92,7 +128,8 @@ public class BlockList
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.add(friendId);
|
||||
String memo = rset.getString("memo");
|
||||
list.put(friendId, memo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,12 +172,12 @@ public class BlockList
|
||||
|
||||
public boolean isInBlockList(L2PcInstance target)
|
||||
{
|
||||
return _blockList.contains(target.getObjectId());
|
||||
return _blockList.containsKey(target.getObjectId());
|
||||
}
|
||||
|
||||
public boolean isInBlockList(int targetId)
|
||||
{
|
||||
return _blockList.contains(targetId);
|
||||
return _blockList.containsKey(targetId);
|
||||
}
|
||||
|
||||
public boolean isBlockAll()
|
||||
@ -165,7 +202,7 @@ public class BlockList
|
||||
_owner.setMessageRefusal(state);
|
||||
}
|
||||
|
||||
private List<Integer> getBlockList()
|
||||
public HashMap<Integer, String> getBlockList()
|
||||
{
|
||||
return _blockList;
|
||||
}
|
||||
@ -179,7 +216,7 @@ public class BlockList
|
||||
|
||||
String charName = CharNameTable.getInstance().getNameById(targetId);
|
||||
|
||||
if (listOwner.getFriendList().contains(targetId))
|
||||
if (listOwner.getFriendList().containsKey(targetId))
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.THIS_PLAYER_IS_ALREADY_REGISTERED_ON_YOUR_FRIENDS_LIST);
|
||||
sm.addString(charName);
|
||||
@ -187,7 +224,7 @@ public class BlockList
|
||||
return;
|
||||
}
|
||||
|
||||
if (listOwner.getBlockList().getBlockList().contains(targetId))
|
||||
if (listOwner.getBlockList().getBlockList().containsKey(targetId))
|
||||
{
|
||||
listOwner.sendMessage("Already in ignore list.");
|
||||
return;
|
||||
@ -220,7 +257,7 @@ public class BlockList
|
||||
|
||||
String charName = CharNameTable.getInstance().getNameById(targetId);
|
||||
|
||||
if (!listOwner.getBlockList().getBlockList().contains(targetId))
|
||||
if (!listOwner.getBlockList().getBlockList().containsKey(targetId))
|
||||
{
|
||||
sm = SystemMessage.getSystemMessage(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
listOwner.sendPacket(sm);
|
||||
@ -251,7 +288,7 @@ public class BlockList
|
||||
|
||||
public static void sendListToOwner(L2PcInstance listOwner)
|
||||
{
|
||||
listOwner.sendPacket(new BlockListPacket(listOwner.getBlockList().getBlockList()));
|
||||
listOwner.sendPacket(new BlockListPacket(listOwner));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,6 +307,6 @@ public class BlockList
|
||||
{
|
||||
_offlineList.put(ownerId, loadList(ownerId));
|
||||
}
|
||||
return _offlineList.get(ownerId).contains(targetId);
|
||||
return _offlineList.get(ownerId).containsKey(targetId);
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +190,7 @@ import com.l2jserver.gameserver.model.effects.L2EffectType;
|
||||
import com.l2jserver.gameserver.model.entity.Castle;
|
||||
import com.l2jserver.gameserver.model.entity.Duel;
|
||||
import com.l2jserver.gameserver.model.entity.Fort;
|
||||
import com.l2jserver.gameserver.model.entity.Friend;
|
||||
import com.l2jserver.gameserver.model.entity.Hero;
|
||||
import com.l2jserver.gameserver.model.entity.Instance;
|
||||
import com.l2jserver.gameserver.model.entity.L2Event;
|
||||
@ -7580,6 +7581,8 @@ public final class L2PcInstance extends L2Playable
|
||||
{
|
||||
storeUISettings();
|
||||
}
|
||||
getBlockList().updateBlockMemos();
|
||||
updateMemos();
|
||||
|
||||
final PlayerVariables vars = getScript(PlayerVariables.class);
|
||||
if (vars != null)
|
||||
@ -11530,6 +11533,16 @@ public final class L2PcInstance extends L2Playable
|
||||
{
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerLogout(this), this);
|
||||
|
||||
for (Friend friend : _friendList.values())
|
||||
{
|
||||
L2PcInstance player = friend.getFriend();
|
||||
if (player == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
player.putFriendDetailInfo(this);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (L2ZoneType zone : ZoneManager.getInstance().getZones(this))
|
||||
@ -13593,18 +13606,66 @@ public final class L2PcInstance extends L2Playable
|
||||
/**
|
||||
* list of character friends
|
||||
*/
|
||||
private final List<Integer> _friendList = new FastList<>();
|
||||
private final HashMap<Integer, Friend> _friendList = new HashMap<>();
|
||||
private final ArrayList<Integer> _updateMemos = new ArrayList<>();
|
||||
|
||||
public List<Integer> getFriendList()
|
||||
public HashMap<Integer, Friend> getFriendList()
|
||||
{
|
||||
return _friendList;
|
||||
}
|
||||
|
||||
public Friend getFriend(int friendOID)
|
||||
{
|
||||
if (getFriendList().containsKey(friendOID))
|
||||
{
|
||||
return getFriendList().get(friendOID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateMemo(int friendOID)
|
||||
{
|
||||
if (!_updateMemos.contains(friendOID))
|
||||
{
|
||||
_updateMemos.add(friendOID);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMemos()
|
||||
{
|
||||
final String sqlQuery = "UPDATE character_friends SET memo=? WHERE charId=? AND friendId=? AND relation=0";
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection())
|
||||
{
|
||||
for (int target : _updateMemos)
|
||||
{
|
||||
try (PreparedStatement statement = con.prepareStatement(sqlQuery))
|
||||
{
|
||||
Friend friend = _friendList.get(target);
|
||||
statement.setString(1, friend.getMemo());
|
||||
statement.setInt(2, getObjectId());
|
||||
statement.setInt(3, target);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error found in " + getName() + "'s FriendList: " + e.getMessage(), e);
|
||||
}
|
||||
_updateMemos.clear();
|
||||
}
|
||||
|
||||
public void addFriend(L2PcInstance player)
|
||||
{
|
||||
_friendList.put(player.getObjectId(), new Friend(0, player.getObjectId(), ""));
|
||||
putFriendDetailInfo(player);
|
||||
}
|
||||
|
||||
public void restoreFriendList()
|
||||
{
|
||||
_friendList.clear();
|
||||
|
||||
final String sqlQuery = "SELECT friendId FROM character_friends WHERE charId=? AND relation=0";
|
||||
final String sqlQuery = "SELECT friendId, memo FROM character_friends WHERE charId=? AND relation=0";
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(sqlQuery))
|
||||
{
|
||||
@ -13618,7 +13679,9 @@ public final class L2PcInstance extends L2Playable
|
||||
{
|
||||
continue;
|
||||
}
|
||||
_friendList.add(friendId);
|
||||
String memo = rset.getString("memo");
|
||||
_friendList.put(friendId, new Friend(0, friendId, memo));
|
||||
putFriendDetailInfo(friendId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13628,10 +13691,105 @@ public final class L2PcInstance extends L2Playable
|
||||
}
|
||||
}
|
||||
|
||||
public void putFriendDetailInfo(L2PcInstance player)
|
||||
{
|
||||
Friend friend = _friendList.get(player.getObjectId());
|
||||
friend.setLevel(player.getLevel());
|
||||
friend.setClassId(player.getClassId().getId());
|
||||
if (player.getClan() != null)
|
||||
{
|
||||
friend.setClanId(player.getClan().getId());
|
||||
friend.setClanName(player.getClan().getName());
|
||||
friend.setClanCrestId(player.getClan().getCrestId());
|
||||
friend.setAllyId(player.getClan().getAllyId());
|
||||
friend.setAllyName(player.getClan().getAllyName());
|
||||
friend.setAllyCrestId(player.getClan().getAllyCrestId());
|
||||
}
|
||||
friend.setLastLogin(System.currentTimeMillis());
|
||||
friend.setCreateDate(player.getCreateDate().getTimeInMillis());
|
||||
}
|
||||
|
||||
public void putFriendDetailInfo(int friendId)
|
||||
{
|
||||
Friend friend = _friendList.get(friendId);
|
||||
int bClassId = 0;
|
||||
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM characters WHERE charId=?");)
|
||||
{
|
||||
statement.setInt(1, friendId);
|
||||
ResultSet rset = statement.executeQuery();
|
||||
while (rset.next())
|
||||
{
|
||||
friend.setLevel(rset.getByte("level"));
|
||||
friend.setClassId(rset.getInt("classid"));
|
||||
bClassId = (rset.getInt("base_class"));
|
||||
friend.setClanId(rset.getInt("clanid"));
|
||||
friend.setLastLogin(rset.getLong("lastAccess"));
|
||||
friend.setCreateDate(rset.getLong("createDate"));
|
||||
}
|
||||
statement.execute();
|
||||
|
||||
rset.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed loading character. " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (friend.getClassId() != bClassId)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("SELECT level FROM character_subclasses WHERE charId=? AND class_id=?");)
|
||||
{
|
||||
statement.setInt(1, friendId);
|
||||
statement.setInt(2, friend.getClassId());
|
||||
ResultSet rset = statement.executeQuery();
|
||||
|
||||
while (rset.next())
|
||||
{
|
||||
friend.setLevel(rset.getByte("level"));
|
||||
}
|
||||
|
||||
statement.execute();
|
||||
rset.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed loading character_subclasses. " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (friend.getClanId() != 0)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM clan_data WHERE clan_id=?");)
|
||||
{
|
||||
statement.setInt(1, friend.getClanId());
|
||||
ResultSet rset = statement.executeQuery();
|
||||
while (rset.next())
|
||||
{
|
||||
friend.setClanName(rset.getString("clan_name"));
|
||||
friend.setClanCrestId(rset.getInt("crest_id"));
|
||||
friend.setAllyId(rset.getInt("ally_id"));
|
||||
friend.setAllyName(rset.getString("ally_name"));
|
||||
friend.setAllyCrestId(rset.getInt("ally_crest_id"));
|
||||
}
|
||||
statement.execute();
|
||||
rset.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Failed loading clan_data. " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyFriends(int type)
|
||||
{
|
||||
L2FriendStatus pkt = new L2FriendStatus(this, type);
|
||||
for (int id : _friendList)
|
||||
for (int id : _friendList.keySet())
|
||||
{
|
||||
L2PcInstance friend = L2World.getInstance().getPlayer(id);
|
||||
if (friend != null)
|
||||
@ -14898,5 +15056,4 @@ public final class L2PcInstance extends L2Playable
|
||||
}
|
||||
getSubClasses().get(getClassIndex()).setVitalityPoints(points);
|
||||
}
|
||||
|
||||
}
|
||||
|
177
trunk/java/com/l2jserver/gameserver/model/entity/Friend.java
Normal file
177
trunk/java/com/l2jserver/gameserver/model/entity/Friend.java
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.model.entity;
|
||||
|
||||
import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
/**
|
||||
* @author Erlandys
|
||||
*/
|
||||
public class Friend
|
||||
{
|
||||
int _relation;
|
||||
int _friendOID;
|
||||
String _memo;
|
||||
|
||||
int _level = 1;
|
||||
int _classId = 0;
|
||||
int _clanId = 0;
|
||||
int _clanCrestId = 0;
|
||||
int _allyId = 0;
|
||||
int _allyCrestId = 0;
|
||||
String _name = "";
|
||||
String _clanName = "";
|
||||
String _allyName = "";
|
||||
long _createDate = -1;
|
||||
long _lastLogin = -1;
|
||||
|
||||
public Friend(int relation, int friendOID, String memo)
|
||||
{
|
||||
_relation = relation;
|
||||
_friendOID = friendOID;
|
||||
_memo = memo;
|
||||
}
|
||||
|
||||
public L2PcInstance getFriend()
|
||||
{
|
||||
return L2World.getInstance().getPlayer(_friendOID);
|
||||
}
|
||||
|
||||
public int getFriendOID()
|
||||
{
|
||||
return _friendOID;
|
||||
}
|
||||
|
||||
public String getMemo()
|
||||
{
|
||||
return _memo;
|
||||
}
|
||||
|
||||
public void setMemo(String memo)
|
||||
{
|
||||
_memo = memo;
|
||||
}
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return _level;
|
||||
}
|
||||
|
||||
public void setLevel(int level)
|
||||
{
|
||||
_level = level;
|
||||
}
|
||||
|
||||
public int getClassId()
|
||||
{
|
||||
return _classId;
|
||||
}
|
||||
|
||||
public void setClassId(int classId)
|
||||
{
|
||||
_classId = classId;
|
||||
}
|
||||
|
||||
public int getClanId()
|
||||
{
|
||||
return _clanId;
|
||||
}
|
||||
|
||||
public void setClanId(int clanId)
|
||||
{
|
||||
_clanId = clanId;
|
||||
}
|
||||
|
||||
public int getClanCrestId()
|
||||
{
|
||||
return _clanCrestId;
|
||||
}
|
||||
|
||||
public void setClanCrestId(int clanCrestId)
|
||||
{
|
||||
_clanCrestId = clanCrestId;
|
||||
}
|
||||
|
||||
public int getAllyId()
|
||||
{
|
||||
return _allyId;
|
||||
}
|
||||
|
||||
public void setAllyId(int allyId)
|
||||
{
|
||||
_allyId = allyId;
|
||||
}
|
||||
|
||||
public int getAllyCrestId()
|
||||
{
|
||||
return _allyCrestId;
|
||||
}
|
||||
|
||||
public void setAllyCrestId(int allyCrestId)
|
||||
{
|
||||
_allyCrestId = allyCrestId;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
if (_name == "")
|
||||
{
|
||||
_name = CharNameTable.getInstance().getNameById(_friendOID);
|
||||
}
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String getClanName()
|
||||
{
|
||||
return _clanName;
|
||||
}
|
||||
|
||||
public void setClanName(String clanName)
|
||||
{
|
||||
_clanName = clanName;
|
||||
}
|
||||
|
||||
public String getAllyName()
|
||||
{
|
||||
return _allyName;
|
||||
}
|
||||
|
||||
public void setAllyName(String allyName)
|
||||
{
|
||||
_allyName = allyName;
|
||||
}
|
||||
|
||||
public long getCreateDate()
|
||||
{
|
||||
return _createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(long createDate)
|
||||
{
|
||||
_createDate = createDate;
|
||||
}
|
||||
|
||||
public long getLastLogin()
|
||||
{
|
||||
return _lastLogin;
|
||||
}
|
||||
|
||||
public void setLastLogin(long lastLogin)
|
||||
{
|
||||
_lastLogin = lastLogin;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user