format changes; fixing one known source of exceptions at the start of the search algorithm

This commit is contained in:
Fate-JH 2024-09-03 12:48:56 -04:00
parent f74da61fa5
commit d15e916f46

View file

@ -2,7 +2,9 @@
package net.psforever.services.teamwork package net.psforever.services.teamwork
import akka.actor.{Actor, ActorRef, Terminated} import akka.actor.{Actor, ActorRef, Terminated}
import java.io.{PrintWriter, StringWriter} import java.io.{PrintWriter, StringWriter}
import scala.annotation.unused
import scala.collection.concurrent.TrieMap import scala.collection.concurrent.TrieMap
import scala.collection.mutable import scala.collection.mutable
// //
@ -294,7 +296,7 @@ class SquadService extends Actor {
subs.UserEvents find { case (_, subscription) => subscription.path.equals(sender.path) } match { subs.UserEvents find { case (_, subscription) => subscription.path.equals(sender.path) } match {
case Some((to, _)) => case Some((to, _)) =>
LeaveService(to, sender) LeaveService(to, sender)
case _ => ; case _ => ()
} }
} }
@ -303,7 +305,7 @@ class SquadService extends Actor {
subs.UserEvents find { case (_, subscription) => subscription eq requestee } match { subs.UserEvents find { case (_, subscription) => subscription eq requestee } match {
case Some((to, _)) => case Some((to, _)) =>
LeaveService(to, requestee) LeaveService(to, requestee)
case _ => ; case _ => ()
} }
} }
@ -343,7 +345,7 @@ class SquadService extends Actor {
def SquadActionInitCharId(tplayer: Player): Unit = { def SquadActionInitCharId(tplayer: Player): Unit = {
val charId = tplayer.CharId val charId = tplayer.CharId
GetParticipatingSquad(charId) match { GetParticipatingSquad(charId) match {
case None => ; case None => ()
case Some(features) => case Some(features) =>
features.Switchboard ! SquadSwitchboard.Join(tplayer, 0, sender()) features.Switchboard ! SquadSwitchboard.Join(tplayer, 0, sender())
} }
@ -376,13 +378,15 @@ class SquadService extends Actor {
case SquadAction.Membership(SquadRequestType.Cancel, cancellingPlayer, _, _, _) => case SquadAction.Membership(SquadRequestType.Cancel, cancellingPlayer, _, _, _) =>
SquadActionMembershipCancel(cancellingPlayer) SquadActionMembershipCancel(cancellingPlayer)
case SquadAction.Membership(SquadRequestType.Promote, promotingPlayer, Some(_promotedPlayer), promotedName, _) => case SquadAction.Membership(SquadRequestType.Promote, _, _, _, _) =>
//SquadActionMembershipPromote(promotingPlayer, _promotedPlayer, promotedName, SquadServiceMessage(tplayer, zone, action), sender()) ()
// case SquadAction.Membership(SquadRequestType.Promote, promotingPlayer, Some(_promotedPlayer), promotedName, _) =>
// SquadActionMembershipPromote(promotingPlayer, _promotedPlayer, promotedName, SquadServiceMessage(tplayer, zone, action), sender())
case SquadAction.Membership(event, _, _, _, _) => case SquadAction.Membership(event, _, _, _, _) =>
debug(s"SquadAction.Membership: $event is not yet supported") debug(s"SquadAction.Membership: $event is not yet supported")
case _ => ; case _ => ()
} }
} }
@ -397,19 +401,16 @@ class SquadService extends Actor {
//validate player with name exists //validate player with name exists
LivePlayerList LivePlayerList
.WorldPopulation({ case (_, a: Avatar) => a.name.equalsIgnoreCase(invitedName) && a.faction == tplayer.Faction }) .WorldPopulation({ case (_, a: Avatar) => a.name.equalsIgnoreCase(invitedName) && a.faction == tplayer.Faction })
.headOption match {
case Some(a) => subs.UserEvents.keys.find(_ == a.id)
case None => None
}
} else { } else {
//validate player with id exists //validate player with id exists
LivePlayerList LivePlayerList
.WorldPopulation({ case (_, a: Avatar) => a.id == _invitedPlayer && a.faction == tplayer.Faction }) .WorldPopulation({ case (_, a: Avatar) => a.id == _invitedPlayer && a.faction == tplayer.Faction })
.headOption match { })
case Some(_) => Some(_invitedPlayer) .headOption
case None => None .collectFirst {
} //important: squads must know about the person too
}) match { a => subs.UserEvents.keys.find(_ == a.id)
}.flatten match {
case Some(invitedPlayer) if invitingPlayer != invitedPlayer => case Some(invitedPlayer) if invitingPlayer != invitedPlayer =>
(GetParticipatingSquad(invitingPlayer), GetParticipatingSquad(invitedPlayer)) match { (GetParticipatingSquad(invitingPlayer), GetParticipatingSquad(invitedPlayer)) match {
case (Some(features1), Some(features2)) case (Some(features1), Some(features2))
@ -448,9 +449,9 @@ class SquadService extends Actor {
//neither the invited player nor the inviting player belong to any squad //neither the invited player nor the inviting player belong to any squad
invitations.createSpontaneousInvite(tplayer, invitedPlayer) invitations.createSpontaneousInvite(tplayer, invitedPlayer)
case _ => ; case _ => ()
} }
case _ => ; case _ => ()
} }
} }
@ -458,7 +459,7 @@ class SquadService extends Actor {
GetLeadingSquad(invitingPlayer, None) match { GetLeadingSquad(invitingPlayer, None) match {
case Some(features) => case Some(features) =>
invitations.handleProximityInvite(zone, invitingPlayer, features) invitations.handleProximityInvite(zone, invitingPlayer, features)
case _ => ; case _ => ()
} }
} }
@ -533,9 +534,9 @@ class SquadService extends Actor {
} }
} }
case _ => ; case _ => ()
} }
case _ => ; case _ => ()
} }
} }
@ -551,7 +552,7 @@ class SquadService extends Actor {
GetLeadingSquad(charId, None) match { GetLeadingSquad(charId, None) match {
case Some(features) => case Some(features) =>
DisbandSquad(features) DisbandSquad(features)
case None => ; case None => ()
} }
} }
@ -582,7 +583,7 @@ class SquadService extends Actor {
(GetLeadingSquad(sponsoringPlayer, None), GetParticipatingSquad(promotedPlayer)) match { (GetLeadingSquad(sponsoringPlayer, None), GetParticipatingSquad(promotedPlayer)) match {
case (Some(features), Some(features2)) if features.Squad.GUID == features2.Squad.GUID => case (Some(features), Some(features2)) if features.Squad.GUID == features2.Squad.GUID =>
SquadActionMembershipPromote(sponsoringPlayer, promotedPlayer, features, msg, ref) SquadActionMembershipPromote(sponsoringPlayer, promotedPlayer, features, msg, ref)
case _ => ; case _ => ()
} }
} }
@ -649,14 +650,14 @@ class SquadService extends Actor {
GetLeadingSquad(tplayer, None) match { GetLeadingSquad(tplayer, None) match {
case Some(features) => case Some(features) =>
invitations.handleDefinitionAction(tplayer, action, features) invitations.handleDefinitionAction(tplayer, action, features)
case _ => ; case _ => ()
} }
None None
case CancelFind() => case CancelFind() =>
GetLeadingSquad(tplayer, None) match { GetLeadingSquad(tplayer, None) match {
case Some(features) => case Some(features) =>
invitations.handleDefinitionAction(tplayer, action, features) invitations.handleDefinitionAction(tplayer, action, features)
case _ => ; case _ => ()
} }
None None
case SelectRoleForYourself(_) => case SelectRoleForYourself(_) =>
@ -674,7 +675,7 @@ class SquadService extends Actor {
GetSquad(guid) match { GetSquad(guid) match {
case Some(features) => case Some(features) =>
invitations.handleDefinitionAction(tplayer, action, features) invitations.handleDefinitionAction(tplayer, action, features)
case _ => ; case _ => ()
} }
None None
} }
@ -682,10 +683,10 @@ class SquadService extends Actor {
GetSquad(guid) match { GetSquad(guid) match {
case Some(features) => case Some(features) =>
invitations.handleDefinitionAction(tplayer, action, features) invitations.handleDefinitionAction(tplayer, action, features)
case _ => ; case _ => ()
} }
None None
case search: SearchForSquadsWithParticularRole => case _/*search*/: SearchForSquadsWithParticularRole =>
// SquadActionDefinitionSearchForSquadsWithParticularRole(tplayer, search) // SquadActionDefinitionSearchForSquadsWithParticularRole(tplayer, search)
None None
case _: CancelSquadSearch => case _: CancelSquadSearch =>
@ -706,7 +707,7 @@ class SquadService extends Actor {
GetSquad(guid) GetSquad(guid)
}) match { }) match {
case Some(features) => features.Switchboard.tell(message, sender()) case Some(features) => features.Switchboard.tell(message, sender())
case None => ; case None => ()
} }
} }
@ -717,7 +718,7 @@ class SquadService extends Actor {
): Unit = { ): Unit = {
GetParticipatingSquad(char_id) match { GetParticipatingSquad(char_id) match {
case Some(features) => features.Switchboard.tell(message, replyTo) case Some(features) => features.Switchboard.tell(message, replyTo)
case None => ; case None => ()
} }
} }
@ -739,7 +740,7 @@ class SquadService extends Actor {
): Unit = { ): Unit = {
val charId = tplayer.CharId val charId = tplayer.CharId
searchData.get(charId) match { searchData.get(charId) match {
case Some(_) => ; case Some(_) => ()
//already searching, so do nothing(?) //already searching, so do nothing(?)
case None => case None =>
val data = SquadService.SearchCriteria(tplayer.Faction, criteria) val data = SquadService.SearchCriteria(tplayer.Faction, criteria)
@ -769,7 +770,7 @@ class SquadService extends Actor {
def SquadActionDefinitionCancelSquadSearch(charId: Long): Unit = { def SquadActionDefinitionCancelSquadSearch(charId: Long): Unit = {
searchData.remove(charId) match { searchData.remove(charId) match {
case None => ; case None => ()
case Some(data) => case Some(data) =>
SearchForSquadsResults(data).foreach { guid => SearchForSquadsResults(data).foreach { guid =>
subs.Publish(charId, SquadResponse.SquadDecoration(guid, squadFeatures(guid).Squad)) subs.Publish(charId, SquadResponse.SquadDecoration(guid, squadFeatures(guid).Squad))
@ -781,30 +782,32 @@ class SquadService extends Actor {
criteria: SearchCriteria, criteria: SearchCriteria,
guid: PlanetSideGUID guid: PlanetSideGUID
): Option[PlanetSideGUID] = { ): Option[PlanetSideGUID] = {
val squad = squadFeatures(guid).Squad squadFeatures
val positions = if (criteria.mode == SquadRequestAction.SearchMode.AnyPositions) { .get(guid)
//includes occupied positions and closed positions that retain assignment information .map { features =>
squad.Membership val squad = features.Squad
} else { val positions = if (criteria.mode == SquadRequestAction.SearchMode.AnyPositions) {
squad.Membership.zipWithIndex.filter { case (_, b) => squad.Availability(b) }.map { _._1 } //includes occupied positions and closed positions that retain assignment information
} squad.Membership
if ( } else {
positions.nonEmpty && squad.Membership.zipWithIndex.filter { case (_, b) => squad.Availability(b) }.map { _._1 }
(criteria.zoneId == 0 || criteria.zoneId == squad.ZoneId) && }
(criteria.role.isEmpty || positions.exists(_.Role.equalsIgnoreCase(criteria.role))) && (squad, positions)
(criteria.requirements.isEmpty || positions.exists { p => }
val results = p.Requirements.intersect(criteria.requirements) .collect {
if (criteria.mode == SquadRequestAction.SearchMode.SomeCertifications) { case (squad, positions) if positions.nonEmpty &&
results.size > 1 (criteria.zoneId == 0 || criteria.zoneId == squad.ZoneId) &&
} else { (criteria.role.isEmpty || positions.exists(_.Role.equalsIgnoreCase(criteria.role))) &&
results == criteria.requirements (criteria.requirements.isEmpty || positions.exists { p =>
} val results = p.Requirements.intersect(criteria.requirements)
}) if (criteria.mode == SquadRequestAction.SearchMode.SomeCertifications) {
) { results.size > 1
Some(guid) } else {
} else { results == criteria.requirements
None }
} }) =>
guid
}
} }
/** the following action can be performed by anyone */ /** the following action can be performed by anyone */
@ -831,14 +834,14 @@ class SquadService extends Actor {
log.warn(s"${tplayer.Name} has a potential squad issue; might be exchanging information $reason") log.warn(s"${tplayer.Name} has a potential squad issue; might be exchanging information $reason")
} }
def CleanUpSquadFeatures(removed: List[Long], guid: PlanetSideGUID, position: Int): Unit = { def CleanUpSquadFeatures(removed: List[Long], guid: PlanetSideGUID, @unused position: Int): Unit = {
GetSquad(guid) match { GetSquad(guid) match {
case Some(features) => case Some(features) =>
features.ProxyInvites = features.ProxyInvites.filterNot(removed.contains) features.ProxyInvites = features.ProxyInvites.filterNot(removed.contains)
if (features.ProxyInvites.isEmpty) { if (features.ProxyInvites.isEmpty) {
features.SearchForRole = None features.SearchForRole = None
} }
case None => ; case None => ()
} }
} }
@ -1098,7 +1101,7 @@ class SquadService extends Actor {
subs.UserEvents.remove(charId) match { subs.UserEvents.remove(charId) match {
case Some(events) => case Some(events) =>
subs.SquadEvents.unsubscribe(events, s"/${features.ToChannel}/Squad") subs.SquadEvents.unsubscribe(events, s"/${features.ToChannel}/Squad")
case _ => ; case _ => ()
} }
if (size > 2) { if (size > 2) {
GetLeadingSquad(charId, pSquadOpt) match { GetLeadingSquad(charId, pSquadOpt) match {