From bf5eb191dd11a90a145c74767417f0b5376b33cc Mon Sep 17 00:00:00 2001 From: ScrawnyRonnie Date: Thu, 21 Dec 2023 06:57:16 -0500 Subject: [PATCH] a few tweaks --- .../teamwork/SquadInvitationManager.scala | 6 ++-- .../services/teamwork/SquadService.scala | 32 ++++++------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/main/scala/net/psforever/services/teamwork/SquadInvitationManager.scala b/src/main/scala/net/psforever/services/teamwork/SquadInvitationManager.scala index 9b7f3eb8..3e9fb8a3 100644 --- a/src/main/scala/net/psforever/services/teamwork/SquadInvitationManager.scala +++ b/src/main/scala/net/psforever/services/teamwork/SquadInvitationManager.scala @@ -165,7 +165,7 @@ class SquadInvitationManager(subs: SquadSubscriptionEntity, parent: ActorRef) { val availableForJoiningSquad = notLimitedByEnrollmentInSquad(invitedPlayerSquadOpt, invitedPlayer) acceptedInvite match { case Some(RequestRole(petitioner, features, position)) - if availableForJoiningSquad && canEnrollInSquad(features, petitioner.CharId) => + if canEnrollInSquad(features, petitioner.CharId) => //player requested to join a squad's specific position //invitedPlayer is actually the squad leader; petitioner is the actual "invitedPlayer" if (JoinSquad(petitioner, features, position)) { @@ -174,7 +174,7 @@ class SquadInvitationManager(subs: SquadSubscriptionEntity, parent: ActorRef) { } case Some(IndirectInvite(recruit, features)) - if availableForJoiningSquad && canEnrollInSquad(features, recruit.CharId) => + if canEnrollInSquad(features, recruit.CharId) => //tplayer / invitedPlayer is actually the squad leader val recruitCharId = recruit.CharId HandleVacancyInvite(features, recruitCharId, invitedPlayer, recruit) match { @@ -456,7 +456,7 @@ class SquadInvitationManager(subs: SquadSubscriptionEntity, parent: ActorRef) { (Some(rejectingPlayer), Some(leaderCharId)) case Some(RequestRole(rejected, features, _)) - if notLeaderOfThisSquad(squadsToLeaders, features.Squad.GUID, rejectingPlayer) => + if notLeaderOfThisSquad(squadsToLeaders, features.Squad.GUID, rejected.CharId) => //rejected is the would-be squad member; rejectingPlayer is the squad leader who rejected the request features.DeniedPlayers(rejected.CharId) (Some(rejectingPlayer), None) diff --git a/src/main/scala/net/psforever/services/teamwork/SquadService.scala b/src/main/scala/net/psforever/services/teamwork/SquadService.scala index b2149fa8..c54b5193 100644 --- a/src/main/scala/net/psforever/services/teamwork/SquadService.scala +++ b/src/main/scala/net/psforever/services/teamwork/SquadService.scala @@ -6,7 +6,7 @@ import java.io.{PrintWriter, StringWriter} import scala.collection.concurrent.TrieMap import scala.collection.mutable // -import net.psforever.objects.{Default, LivePlayerList, Player} +import net.psforever.objects.{LivePlayerList, Player} import net.psforever.objects.teamwork.{Member, Squad, SquadFeatures} import net.psforever.objects.avatar.{Avatar, Certification} import net.psforever.objects.definition.converter.StatConverter @@ -902,9 +902,8 @@ class SquadService extends Actor { val squad = features.Squad subs.UserEvents.get(charId) match { case Some(events) - if !memberToSquad.contains(charId) && - squad.Leader.CharId != charId && - squad.isAvailable(position, player.avatar.certifications) => + if squad.isAvailable(position, player.avatar.certifications) && + EnsureEmptySquad(charId) => memberToSquad(charId) = squad.GUID subs.MonitorSquadDetails.subtractOne(charId) invitations.handleCleanup(charId) @@ -1083,6 +1082,7 @@ class SquadService extends Actor { pSquadOpt match { //member of the squad; leave the squad case Some(features) => + LeaveSquad(charId, features) val squad = features.Squad val size = squad.Size subs.UserEvents.remove(charId) match { @@ -1093,25 +1093,11 @@ class SquadService extends Actor { if (size > 2) { GetLeadingSquad(charId, pSquadOpt) match { case Some(_) => - //leader of a squad; search for a suitable substitute leader - squad.Membership.drop(1).find { _.CharId > 0 } match { - case Some(member) => - //leader was shifted into a subordinate position and will retire from duty - SquadActionMembershipPromote( - charId, - member.CharId, - features, - SquadServiceMessage(null, null, SquadAction.Membership(SquadRequestType.Promote, charId, Some(member.CharId), "", None)), - Default.Actor - ) - LeaveSquad(charId, features) - case _ => - //the squad will be disbanded - PanicDisbandSquad( - features, - squad.Membership.collect { case member if member.CharId > 0 && member.CharId != charId => member.CharId } - ) - } + //leader of a squad; the squad will be disbanded. Same logic as when a SL uses /leave and the squad is disband. + PanicDisbandSquad( + features, + squad.Membership.collect { case member if member.CharId > 0 && member.CharId != charId => member.CharId } + ) case None => //not the leader of a full squad; tell other members that we are leaving SquadSwitchboard.PanicLeaveSquad(