party: send join on reconnect
If the server expires the membership before the client in the party reconnects, it will falsely assume it is in a party when it isn't. Additionally since users are resynced on reconnect, this was duplicating members as it would get joins for already joined members.
This commit is contained in:
@@ -53,6 +53,7 @@ import net.runelite.client.events.PartyMemberAvatar;
|
||||
import net.runelite.client.party.messages.Join;
|
||||
import net.runelite.client.party.messages.Part;
|
||||
import net.runelite.client.party.messages.PartyChatMessage;
|
||||
import net.runelite.client.party.messages.PartyMessage;
|
||||
import net.runelite.client.party.messages.UserJoin;
|
||||
import net.runelite.client.party.messages.UserPart;
|
||||
import net.runelite.client.party.messages.UserSync;
|
||||
@@ -180,6 +181,22 @@ public class PartyService
|
||||
wsClient.send(new Join(partyId, USERNAME));
|
||||
}
|
||||
|
||||
public <T extends PartyMessage> void send(T message)
|
||||
{
|
||||
if (!wsClient.isOpen())
|
||||
{
|
||||
log.debug("Reconnecting to server");
|
||||
|
||||
PartyMember local = getLocalMember();
|
||||
members.removeIf(m -> m != local);
|
||||
|
||||
wsClient.connect();
|
||||
wsClient.send(new Join(partyId, USERNAME));
|
||||
}
|
||||
|
||||
wsClient.send(message);
|
||||
}
|
||||
|
||||
@Subscribe(priority = 1) // run prior to plugins so that the member is joined by the time the plugins see it.
|
||||
public void onUserJoin(final UserJoin message)
|
||||
{
|
||||
@@ -190,13 +207,17 @@ public class PartyService
|
||||
return;
|
||||
}
|
||||
|
||||
final PartyMember partyMember = new PartyMember(message.getMemberId(), cleanUsername(message.getName()));
|
||||
members.add(partyMember);
|
||||
PartyMember partyMember = getMemberById(message.getMemberId());
|
||||
if (partyMember == null)
|
||||
{
|
||||
partyMember = new PartyMember(message.getMemberId(), cleanUsername(message.getName()));
|
||||
members.add(partyMember);
|
||||
log.debug("User {} joins party, {} members", partyMember, members.size());
|
||||
}
|
||||
|
||||
final PartyMember localMember = getLocalMember();
|
||||
|
||||
// Send info to other clients that this user successfully finished joining party
|
||||
if (localMember != null && message.getMemberId().equals(localMember.getMemberId()))
|
||||
if (localMember != null && localMember == partyMember)
|
||||
{
|
||||
final UserSync userSync = new UserSync();
|
||||
userSync.setMemberId(message.getMemberId());
|
||||
@@ -207,7 +228,10 @@ public class PartyService
|
||||
@Subscribe(priority = 1) // run prior to plugins so that the member is removed by the time the plugins see it.
|
||||
public void onUserPart(final UserPart message)
|
||||
{
|
||||
members.removeIf(member -> member.getMemberId().equals(message.getMemberId()));
|
||||
if (members.removeIf(member -> member.getMemberId().equals(message.getMemberId())))
|
||||
{
|
||||
log.debug("User {} leaves party, {} members", message.getMemberId(), members.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -96,7 +96,7 @@ public class WSClient extends WebSocketListener implements AutoCloseable
|
||||
}
|
||||
}
|
||||
|
||||
private void connect()
|
||||
void connect()
|
||||
{
|
||||
if (sessionId == null)
|
||||
{
|
||||
@@ -115,6 +115,11 @@ public class WSClient extends WebSocketListener implements AutoCloseable
|
||||
send(handshake);
|
||||
}
|
||||
|
||||
boolean isOpen()
|
||||
{
|
||||
return webSocket != null;
|
||||
}
|
||||
|
||||
public void registerMessage(final Class<? extends WebsocketMessage> message)
|
||||
{
|
||||
if (messages.add(message))
|
||||
|
||||
@@ -281,7 +281,7 @@ public class DiscordPlugin extends Plugin
|
||||
discordUser.avatar
|
||||
);
|
||||
userInfo.setMemberId(localMember.getMemberId());
|
||||
wsClient.send(userInfo);
|
||||
partyService.send(userInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class DpsCounterPlugin extends Plugin
|
||||
{
|
||||
final DpsUpdate dpsUpdate = new DpsUpdate(hit, isBoss);
|
||||
dpsUpdate.setMemberId(localMember.getMemberId());
|
||||
wsClient.send(dpsUpdate);
|
||||
partyService.send(dpsUpdate);
|
||||
}
|
||||
|
||||
if (dpsConfig.bossDamage() && !isBoss)
|
||||
|
||||
@@ -104,9 +104,6 @@ public class PartyPlugin extends Plugin
|
||||
@Inject
|
||||
private PartyService party;
|
||||
|
||||
@Inject
|
||||
private WSClient ws;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@@ -266,7 +263,7 @@ public class PartyPlugin extends Plugin
|
||||
event.consume();
|
||||
final TilePing tilePing = new TilePing(selectedSceneTile.getWorldLocation());
|
||||
tilePing.setMemberId(party.getLocalMember().getMemberId());
|
||||
wsClient.send(tilePing);
|
||||
party.send(tilePing);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -326,7 +323,7 @@ public class PartyPlugin extends Plugin
|
||||
|
||||
final LocationUpdate locationUpdate = new LocationUpdate(location);
|
||||
locationUpdate.setMemberId(localMember.getMemberId());
|
||||
wsClient.send(locationUpdate);
|
||||
party.send(locationUpdate);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -342,7 +339,7 @@ public class PartyPlugin extends Plugin
|
||||
// Request sync
|
||||
final UserSync userSync = new UserSync();
|
||||
userSync.setMemberId(party.getLocalMember().getMemberId());
|
||||
ws.send(userSync);
|
||||
party.send(userSync);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,21 +439,21 @@ public class PartyPlugin extends Plugin
|
||||
{
|
||||
final SkillUpdate update = new SkillUpdate(Skill.HITPOINTS, currentHealth, realHealth);
|
||||
update.setMemberId(localMember.getMemberId());
|
||||
ws.send(update);
|
||||
party.send(update);
|
||||
}
|
||||
|
||||
if (forceSend || currentPrayer != lastPray)
|
||||
{
|
||||
final SkillUpdate update = new SkillUpdate(Skill.PRAYER, currentPrayer, realPrayer);
|
||||
update.setMemberId(localMember.getMemberId());
|
||||
ws.send(update);
|
||||
party.send(update);
|
||||
}
|
||||
|
||||
if (forceSend || !characterName.equals(lastCharacterName))
|
||||
{
|
||||
final CharacterNameUpdate update = new CharacterNameUpdate(characterName);
|
||||
update.setMemberId(localMember.getMemberId());
|
||||
ws.send(update);
|
||||
party.send(update);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@ import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.party.PartyMember;
|
||||
import net.runelite.client.party.PartyService;
|
||||
import net.runelite.client.party.WSClient;
|
||||
import net.runelite.client.party.messages.PartyChatMessage;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
@@ -156,9 +155,6 @@ public class RaidsPlugin extends Plugin
|
||||
@Inject
|
||||
private PartyService party;
|
||||
|
||||
@Inject
|
||||
private WSClient ws;
|
||||
|
||||
@Inject
|
||||
private ChatCommandManager chatCommandManager;
|
||||
|
||||
@@ -494,7 +490,7 @@ public class RaidsPlugin extends Plugin
|
||||
{
|
||||
final PartyChatMessage message = new PartyChatMessage(layoutMessage);
|
||||
message.setMemberId(localMember.getMemberId());
|
||||
ws.send(message);
|
||||
party.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ public class SpecialCounterPlugin extends Plugin
|
||||
{
|
||||
final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(interactingId, specialWeapon, hit, client.getWorld(), localPlayerId);
|
||||
specialCounterUpdate.setMemberId(party.getLocalMember().getMemberId());
|
||||
wsClient.send(specialCounterUpdate);
|
||||
party.send(specialCounterUpdate);
|
||||
}
|
||||
|
||||
playerInfoDrops.add(createSpecInfoDrop(specialWeapon, hit, localPlayerId));
|
||||
|
||||
@@ -34,11 +34,10 @@ import net.runelite.client.Notifier;
|
||||
import net.runelite.client.chat.ChatClient;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.client.party.PartyService;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
import net.runelite.client.util.ImageCapture;
|
||||
import net.runelite.client.party.PartyService;
|
||||
import net.runelite.client.party.WSClient;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
@@ -92,10 +91,6 @@ public class RaidsPluginTest
|
||||
@Bind
|
||||
OverlayManager overlayManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
WSClient wsClient;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
RaidsConfig raidsConfig;
|
||||
|
||||
Reference in New Issue
Block a user