mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-11 22:44:37 +00:00
Finally fix list_players command
Originally I made list_players return the full avatar object rather than just the name string. Which was kind of a bad idea because certain contents were unserializable which caused the command to break (sometimes). Weeks later, I attempted to fix it by returning to the original behaviour of only returning names. By that point I had forgotten that PSFPortal was changed to expect an object. So here's the final fix. player_list now returns a very simple object made up of the name and faction id.
This commit is contained in:
parent
bfe0ce91fe
commit
dbdcaeb751
2 changed files with 5 additions and 10 deletions
|
|
@ -6,6 +6,8 @@ import net.psforever.services.{InterstellarClusterService, ServiceManager}
|
||||||
import scala.collection.mutable.Map
|
import scala.collection.mutable.Map
|
||||||
import akka.actor.typed.scaladsl.adapter._
|
import akka.actor.typed.scaladsl.adapter._
|
||||||
|
|
||||||
|
private case class Player(name: String, faction_id: Int)
|
||||||
|
|
||||||
class CmdListPlayers(args: Array[String], services: Map[String, ActorRef]) extends Actor {
|
class CmdListPlayers(args: Array[String], services: Map[String, ActorRef]) extends Actor {
|
||||||
private[this] val log = org.log4s.getLogger(self.path.name)
|
private[this] val log = org.log4s.getLogger(self.path.name)
|
||||||
|
|
||||||
|
|
@ -22,19 +24,13 @@ class CmdListPlayers(args: Array[String], services: Map[String, ActorRef]) exten
|
||||||
|
|
||||||
case InterstellarClusterService.PlayersResponse(players) =>
|
case InterstellarClusterService.PlayersResponse(players) =>
|
||||||
val data = Map[String, Any]()
|
val data = Map[String, Any]()
|
||||||
data {
|
data("player_count") = players.size
|
||||||
"player_count"
|
data("player_list") = Array[Player]()
|
||||||
} = players.size
|
|
||||||
data {
|
|
||||||
"player_list"
|
|
||||||
} = Array[String]()
|
|
||||||
|
|
||||||
if (players.isEmpty) {
|
if (players.isEmpty) {
|
||||||
context.parent ! CommandGoodResponse("No players currently online!", data)
|
context.parent ! CommandGoodResponse("No players currently online!", data)
|
||||||
} else {
|
} else {
|
||||||
data {
|
data("player_list") = players.map(a => Player(a.name, a.faction.id))
|
||||||
"player_list"
|
|
||||||
} = players.map(_.name)
|
|
||||||
context.parent ! CommandGoodResponse(s"${players.length} players online\n", data)
|
context.parent ! CommandGoodResponse(s"${players.length} players online\n", data)
|
||||||
}
|
}
|
||||||
case default => log.error(s"Unexpected message $default")
|
case default => log.error(s"Unexpected message $default")
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ class InterstellarClusterService(context: ActorContext[InterstellarClusterServic
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onMessage(msg: Command): Behavior[Command] = {
|
override def onMessage(msg: Command): Behavior[Command] = {
|
||||||
log.info(s"$msg")
|
|
||||||
msg match {
|
msg match {
|
||||||
case GetPlayers(replyTo) =>
|
case GetPlayers(replyTo) =>
|
||||||
replyTo ! PlayersResponse(zones.flatMap(_.Players).toSeq)
|
replyTo ! PlayersResponse(zones.flatMap(_.Players).toSeq)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue