Fixed list update issues with friend and ignore list, /findfriend now destroys existing wp's, fixed string bug on updating wps

This commit is contained in:
Waverunner
2013-12-17 19:00:24 -05:00
parent c3cf8713bf
commit aea5f3a4b8
13 changed files with 218 additions and 157 deletions
+2 -6
View File
@@ -29,12 +29,8 @@ public class ChatFriendsListUpdate extends SWGMessage {
@Override
public IoBuffer serialize() {
Config config = new Config();
config.setFilePath("nge.cfg");
if (!(config.loadConfigFile())) {
config = DefaultConfig.getConfig();
}
String serverName = config.getString("GALAXY_NAME");
String serverName = NGECore.getInstance().getConfig().getString("GALAXY_NAME");
IoBuffer result = IoBuffer.allocate(50 + friendName.length()).order(ByteOrder.LITTLE_ENDIAN);
result.putShort((short) 3);
+2 -3
View File
@@ -9,6 +9,7 @@ import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.player.PlayerObject;
// This is possibly unused
public class ChatOnGetFriendsList extends SWGMessage {
private List<String> friendList;
@@ -24,8 +25,7 @@ public class ChatOnGetFriendsList extends SWGMessage {
}
@Override
public void deserialize(IoBuffer data) {
// XXX Auto-generated method stub
}
@Override
@@ -51,7 +51,6 @@ public class ChatOnGetFriendsList extends SWGMessage {
int size = buffer.position();
buffer = IoBuffer.allocate(size).put(buffer.array(), 0, size);
buffer.flip();
//System.out.println("ChatOnGetFriendsList: " + buffer.getHexDump());
return buffer;
}
@@ -22,12 +22,12 @@
package resources.objects.player;
import java.nio.ByteOrder;
import java.util.List;
import java.util.Map.Entry;
import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.common.CRC;
import resources.objects.ObjectMessageBuilder;
import resources.objects.waypoint.WaypointObject;
@@ -251,7 +251,7 @@ public class PlayerMessageBuilder extends ObjectMessageBuilder {
if(player.getFriendList().isEmpty()) {
buffer.putInt(0);
buffer.putInt(0);
buffer.putInt(0);
} else {
buffer.putInt(player.getFriendList().size());
buffer.putInt(player.getFriendListUpdateCounter());
@@ -261,7 +261,6 @@ public class PlayerMessageBuilder extends ObjectMessageBuilder {
for(String friend : player.getFriendList()) {
buffer.put(getAsciiString(friend));
}
}
}
@@ -515,60 +514,70 @@ public class PlayerMessageBuilder extends ObjectMessageBuilder {
}
public IoBuffer buildFriendAddDelta(String friend) {
public IoBuffer buildFriendAddDelta(List<String> friends) {
IoBuffer buffer = bufferPool.allocate(13 + (friends.size() * 2), false).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
IoBuffer buffer = bufferPool.allocate(13 + friend.length(), false).order(ByteOrder.LITTLE_ENDIAN);
PlayerObject player = (PlayerObject) object;
buffer.putInt(1);
buffer.putInt(player.getFriendListUpdateCounter());
buffer.put((byte) 1); // updateType (SubType)
buffer.put((byte) 3); // updateType (SubType)
buffer.putShort((short) player.getFriendList().indexOf(friend));
buffer.put(getAsciiString(friend));
buffer.putShort((short) (player.getFriendList().size()));
for (String f : friends) {
buffer.put(getAsciiString(f));
}
int size = buffer.position();
buffer.flip();
buffer = createDelta("PLAY", (byte) 9, (short) 1, (short) 7, buffer, size + 4);
return buffer;
}
public IoBuffer buildFriendRemoveDelta(String friend) {
IoBuffer buffer = bufferPool.allocate(11, false).order(ByteOrder.LITTLE_ENDIAN);
PlayerObject player = (PlayerObject) object;
buffer.putInt(1);
buffer.putInt(player.getFriendListUpdateCounter());
buffer.put((byte) 0); // updateType (SubType)
return buffer;
buffer.putShort((short) player.getFriendList().indexOf(friend));
}
public IoBuffer buildFriendRemoveDelta(List<String> friends) {
IoBuffer buffer = bufferPool.allocate(13 + (friends.size() * 2), false).order(ByteOrder.LITTLE_ENDIAN);
PlayerObject player = (PlayerObject) object;
buffer.putInt(1);
buffer.putInt(player.getFriendListUpdateCounter());
buffer.put((byte) 3); // updateType (SubType)
buffer.putShort((short) friends.size());
for (String f : friends) {
buffer.put(getAsciiString(f));
}
int size = buffer.position();
buffer.flip();
buffer = createDelta("PLAY", (byte) 9, (short) 1, (short) 7, buffer, size + 4);
return buffer;
}
public IoBuffer buildIgnoreAddDelta(String ignoreName) {
IoBuffer buffer = bufferPool.allocate(30, false).order(ByteOrder.LITTLE_ENDIAN);
public IoBuffer buildIgnoreAddDelta(List<String> ignoreList) {
IoBuffer buffer = bufferPool.allocate(13 + (ignoreList.size() * 2) , false).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
PlayerObject player = (PlayerObject) object;
buffer.putInt(1);
buffer.putInt(player.getIgnoreListUpdateCounter());
buffer.put((byte) 1); // updateType (SubType)
buffer.put((byte) 3); // updateType (SubType)
buffer.putShort((short) player.getIgnoreList().indexOf(ignoreName));
buffer.put(getAsciiString(ignoreName));
buffer.putShort((short) ignoreList.size());
for (String ignore : ignoreList) {
buffer.put(getAsciiString(ignore));
}
int size = buffer.position();
buffer.flip();
@@ -578,15 +587,20 @@ public class PlayerMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
public IoBuffer buildIgnoreRemoveDelta(String removeName) {
IoBuffer buffer = bufferPool.allocate(30, false).order(ByteOrder.LITTLE_ENDIAN);
public IoBuffer buildIgnoreRemoveDelta(List<String> ignoreList) {
IoBuffer buffer = bufferPool.allocate(13 + (ignoreList.size() * 2) , false).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
PlayerObject player = (PlayerObject) object;
buffer.putInt(1);
buffer.putInt(player.getIgnoreListUpdateCounter());
buffer.put((byte) 0);
buffer.putShort((short) player.getIgnoreList().indexOf(removeName));
buffer.put((byte) 3); // updateType (SubType)
buffer.putShort((short) ignoreList.size());
for (String ignore : ignoreList) {
buffer.put(getAsciiString(ignore));
}
int size = buffer.position();
buffer.flip();
@@ -427,7 +427,7 @@ public class PlayerObject extends IntangibleObject {
synchronized(objectMutex) {
setFriendListUpdateCounter(getFriendListUpdateCounter() + 1);
friendList.add(friend);
getContainer().getClient().getSession().write(messageBuilder.buildFriendAddDelta(friend));
getContainer().getClient().getSession().write(messageBuilder.buildFriendAddDelta(getFriendList()));
}
}
@@ -435,7 +435,7 @@ public class PlayerObject extends IntangibleObject {
synchronized(objectMutex) {
setFriendListUpdateCounter(getFriendListUpdateCounter() + 1);
friendList.remove(friend);
getContainer().getClient().getSession().write(messageBuilder.buildFriendRemoveDelta(friend));
getContainer().getClient().getSession().write(messageBuilder.buildFriendRemoveDelta(getFriendList()));
}
}
@@ -452,16 +452,16 @@ public class PlayerObject extends IntangibleObject {
public void ignoreAdd(String ignoreName) {
synchronized(objectMutex) {
setIgnoreListUpdateCounter(getIgnoreListUpdateCounter() + 1);
getContainer().getClient().getSession().write(messageBuilder.buildIgnoreAddDelta(ignoreName));
ignoreList.add(ignoreName);
getContainer().getClient().getSession().write(messageBuilder.buildIgnoreAddDelta(getIgnoreList()));
}
}
public void ignoreRemove(String removeName) {
synchronized(objectMutex) {
setIgnoreListUpdateCounter(getIgnoreListUpdateCounter() + 1);
getContainer().getClient().getSession().write(messageBuilder.buildIgnoreRemoveDelta(removeName));
ignoreList.remove(removeName);
getContainer().getClient().getSession().write(messageBuilder.buildIgnoreRemoveDelta(getIgnoreList()));
}
}
+29
View File
@@ -461,5 +461,34 @@ public class CharacterService implements INetworkDispatch {
}
return characters;
}
/**
* Checks the database for if the name of the player exists. The name is
* formated automatically in the method for checking the database, so no conversion is required.
* @param name Name to check for in the database
* @return Returns True if the player exists
*/
public boolean playerExists(String name) {
if (!name.equals("")) {
if (name.contains(" ")) {
name = name.split(" ")[0];
}
name = name.replace("'", "''");
name = name.toLowerCase();
try {
PreparedStatement ps = databaseConnection.preparedStatement("SELECT id FROM characters WHERE LOWER(\"firstName\")=?");
ps.setString(1, name);
ResultSet resultSet = ps.executeQuery();
boolean isDuplicate = resultSet.next();
resultSet.getStatement().close();
if (isDuplicate) { return true; }
else { return false; }
}
catch (SQLException e) { e.printStackTrace(); }
}
return false;
}
}
+75 -91
View File
@@ -339,8 +339,7 @@ public class ChatService implements INetworkDispatch {
ConcurrentHashMap<IoSession, Client> clients = core.getActiveConnectionsMap();
for(Client client : clients.values()) {
if(client.getParent() == null)
continue;
@@ -360,128 +359,113 @@ public class ChatService implements INetworkDispatch {
}
public void removeFriend(PlayerObject actor, String friendName) {
CreatureObject creature = (CreatureObject) actor.getContainer();
friendName = friendName.split(" ")[0].toLowerCase();
friendName = friendName.toLowerCase();
//SWGObject friendObject = getObjectByFirstName(friendName);
if (actor == null || actor.getContainer() == null)
if (actor == null || creature == null || friendName.equals(""))
return;
List<String> friendList = actor.getFriendList();
if(friendList.contains(friendName)) {
actor.friendRemove(friendName);
ChatOnChangeFriendStatus removeMessage = new ChatOnChangeFriendStatus(actor.getContainer().getObjectID(), friendName, 0);
actor.getContainer().getClient().getSession().write(removeMessage.serialize());
ChatOnGetFriendsList sendFriendsList = new ChatOnGetFriendsList(actor);
actor.getContainer().getClient().getSession().write(sendFriendsList.serialize());
if(actor.getFriendList().contains(friendName)) {
ChatOnChangeFriendStatus removeMessage = new ChatOnChangeFriendStatus(actor.getContainer().getObjectID(), friendName, 0);
creature.getClient().getSession().write(removeMessage.serialize());
actor.friendRemove(friendName);
} else {
creature.sendSystemMessage(friendName + " is not a valid friend name.", (byte) 0);
}
}
public void addFriend(PlayerObject actor, String friendName, boolean notify) {
// ChatOnAddFriend, ChatOnChangeFriendStatus, ChatFriendsListUpdate, ChatSystemMessage, ChatOnGetFriendsList
SWGObject friendObject = getObjectByFirstName(friendName);
public void addFriend(PlayerObject actor, String friend) {
CreatureObject creature = (CreatureObject) actor.getContainer();
PlayerObject friend = (PlayerObject) friendObject.getSlottedObject("ghost");
CreatureObject friendCreature = (CreatureObject) friend.getContainer();
List<String> friendList = actor.getFriendList();
if (actor == null || friendObject.getSlottedObject("ghost") == null)
if (actor == null || creature == null || friend.equals(""))
return;
CreatureObject actorCreature = (CreatureObject) actor.getContainer();
if (actorCreature == null)
return;
friend = friend.toLowerCase();
boolean friendIsOnline = friendObject.isInQuadtree();
String friendShortName = friendCreature.getCustomName().toLowerCase();
if (friendCreature.getCustomName().contains(" ")) {
String[] splitName = friendCreature.getCustomName().toLowerCase().split(" ");
friendShortName = splitName[0];
if (friend.contains(" ")) {
friend = friend.split(" ")[0];
}
if (friendList.contains(friendShortName)) {
actorCreature.sendSystemMessage(friendShortName + " is already on your friends list.", (byte) 0);
return;
}
if (notify) {
ChatOnAddFriend init = new ChatOnAddFriend();
actorCreature.getClient().getSession().write(init.serialize());
if(core.characterService.playerExists(friend)) {
ChatOnChangeFriendStatus addMessage = new ChatOnChangeFriendStatus(actorCreature.getObjectID(), friendShortName, 1);
actorCreature.getClient().getSession().write(addMessage.serialize());
if(friendIsOnline) {
ChatFriendsListUpdate updateStatus = new ChatFriendsListUpdate(friendShortName, (byte)1);
actorCreature.getClient().getSession().write(updateStatus.serialize());
if(actor.getIgnoreList().contains(friend)) {
creature.sendSystemMessage(friend + " is being ignored, unable to put in your friends list.", (byte) 0);
}
}
SWGObject friendObj = getObjectByFirstName(friend);
boolean isOnline = false;
if (friendObj != null && friendObj.isInQuadtree())
isOnline = true;
ChatOnAddFriend init = new ChatOnAddFriend();
creature.getClient().getSession().write(init.serialize());
actor.friendAdd(friendShortName);
if (actor.getFriendList().size() != 0) {
ChatOnGetFriendsList sendFriendsList = new ChatOnGetFriendsList(actor);
actorCreature.getClient().getSession().write(sendFriendsList.serialize());
ChatOnChangeFriendStatus addFriend = new ChatOnChangeFriendStatus(creature.getObjectId(), friend, 1);
creature.getClient().getSession().write(addFriend.serialize());
if (isOnline) {
ChatFriendsListUpdate onlineUpdate = new ChatFriendsListUpdate(friend, (byte) 1);
creature.getClient().getSession().write(onlineUpdate.serialize());
}
actor.friendAdd(friend);
creature.sendSystemMessage(friend + " is now your friend.", (byte) 0);
} else {
creature.sendSystemMessage(friend + " is not a valid friend name.", (byte) 0);
}
actorCreature.sendSystemMessage(friendShortName + " has been added to your friends list.", (byte) 0);
}
public void addToIgnoreList(SWGObject actor, String ignoreName) {
ignoreName = ignoreName.split(" ")[0].toLowerCase();
if (actor == null)
return;
PlayerObject ghost = (PlayerObject) actor.getSlottedObject("ghost");
CreatureObject creature = (CreatureObject) actor;
List<String> ignoreList = ghost.getIgnoreList();
if (ignoreList.contains(ignoreName.toLowerCase())) {
if(ghost == null)
return;
if (ghost.getIgnoreList().contains(ignoreName)) {
creature.sendSystemMessage(ignoreName + " is already in your ignore list.", (byte) 0);
return;
} else {
// TODO: Do check for valid names to ignore
AddIgnoreMessage addIgnore = new AddIgnoreMessage(actor, ignoreName.toLowerCase(), true);
actor.getClient().getSession().write(addIgnore.serialize());
Console.println("Sent the add ignore message!");
ghost.ignoreAdd(ignoreName.toLowerCase());
Console.println("Sent the add ignore delta!");
creature.sendSystemMessage(ignoreName + " is now ignored.", (byte) 0);
}
if(!core.characterService.playerExists(ignoreName)) {
creature.sendSystemMessage(ignoreName + " is not a valid ignore name.", (byte) 0);
return;
}
AddIgnoreMessage addIgnore = new AddIgnoreMessage(actor, ignoreName, true);
actor.getClient().getSession().write(addIgnore.serialize());
ghost.ignoreAdd(ignoreName);
creature.sendSystemMessage(ignoreName + " is now ignored.", (byte) 0);
}
public void removeFromIgnoreList(SWGObject actor, String ignoreName) {
if (actor == null)
return;
PlayerObject ghost = (PlayerObject) actor.getSlottedObject("ghost");
CreatureObject creature = (CreatureObject) actor;
List<String> ignoreList = ghost.getIgnoreList();
if (ignoreList.contains(ignoreName.toLowerCase())) {
for (String name : ignoreList) {
if(name.equalsIgnoreCase(ignoreName)) {
//Console.println("Name found!");
AddIgnoreMessage removeIgnore = new AddIgnoreMessage(actor, ignoreName.toLowerCase(), false);
actor.getClient().getSession().write(removeIgnore.serialize());
//Console.println("Sent AddIgnoreMessage to remove friend!");
ghost.ignoreRemove(ignoreName.toLowerCase());
//Console.println("Sent ignoreRemove delta!");
creature.sendSystemMessage(ignoreName + " is no longer ignored.", (byte) 0);
// TODO: Find out why player must click on name twice in list for name to be removed.
break;
}
}
} else { return; }
if (ghost == null || creature == null)
return;
if (ghost.getIgnoreList().contains(ignoreName)) {
AddIgnoreMessage message = new AddIgnoreMessage(actor, ignoreName, false);
creature.getClient().getSession().write(message.serialize());
ghost.ignoreRemove(ignoreName);
creature.sendSystemMessage(ignoreName + " is no longer ignored.", (byte) 0);
}
}
public void sendPersistentMessageHeader(Client client, Mail mail) {
+9 -9
View File
@@ -612,8 +612,8 @@ public class ObjectService implements INetworkDispatch {
PlayerObject ghost = (PlayerObject) creature.getSlottedObject("ghost");
ChatOnGetFriendsList friendsListMessage = new ChatOnGetFriendsList(ghost);
client.getSession().write(friendsListMessage.serialize());
//ChatOnGetFriendsList friendsListMessage = new ChatOnGetFriendsList(ghost);
//client.getSession().write(friendsListMessage.serialize());
if (ghost != null) {
ghost.clearFlagBitmask(PlayerFlags.LD);
@@ -626,19 +626,19 @@ public class ObjectService implements INetworkDispatch {
core.chatService.playerStatusChange(objectShortName, (byte) 1);
if (ghost.getFriendList().isEmpty() == false) {
if (!ghost.getFriendList().isEmpty()) {
// Find out what friends are online/offline
for (String friend : ghost.getFriendList()) {
SWGObject friendObject = (SWGObject) core.chatService.getObjectByFirstName(friend);
if (friendObject == null)
continue;
if(friendObject.isInQuadtree() == true) {
SWGObject friendObject = core.chatService.getObjectByFirstName(friend);
if(friendObject != null && friendObject.isInQuadtree()) {
ChatFriendsListUpdate onlineNotifyStatus = new ChatFriendsListUpdate(friend, (byte) 1);
client.getSession().write(onlineNotifyStatus.serialize());
} else {
ChatOnChangeFriendStatus changeStatus = new ChatOnChangeFriendStatus(creature.getObjectID(), friend, 0);
client.getSession().write(changeStatus.serialize());
ChatFriendsListUpdate onlineNotifyStatus = new ChatFriendsListUpdate(friend, (byte) 0);
client.getSession().write(onlineNotifyStatus.serialize());
}
}
}