From 0ae8ab2418a1585d749d7c57f243fbfeb1a8ed19 Mon Sep 17 00:00:00 2001 From: Resaec Date: Mon, 13 Apr 2026 21:28:44 +0200 Subject: [PATCH] TimeOfDayMessage broadcast and fixup broadcast TimeOfDayMessage to all players in the zone fix input allows single minute digit times (0:0) fix set time(speed) before packet creation fix GetTimeOfDay return seconds, not millis fix SetTimeOfDay write correct integer type --- .../session/support/ChatOperations.scala | 32 +++++++++++++++---- .../net/psforever/objects/zones/Zone.scala | 6 ++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/scala/net/psforever/actors/session/support/ChatOperations.scala b/src/main/scala/net/psforever/actors/session/support/ChatOperations.scala index 814958bb0..ebb569428 100644 --- a/src/main/scala/net/psforever/actors/session/support/ChatOperations.scala +++ b/src/main/scala/net/psforever/actors/session/support/ChatOperations.scala @@ -15,6 +15,8 @@ import net.psforever.objects.sourcing.PlayerSource import net.psforever.objects.zones.{Zone, ZoneInfo} import net.psforever.packet.game.TimeOfDayMessage.GetTimeOfDayValue import net.psforever.packet.game.{SetChatFilterMessage, TimeOfDayMessage} +import net.psforever.services.Service +import net.psforever.services.avatar.{AvatarAction, AvatarServiceMessage} import net.psforever.services.chat.{DefaultChannel, OutfitChannel, SquadChannel} import net.psforever.services.local.{LocalAction, LocalServiceMessage} import net.psforever.services.teamwork.{SquadResponse, SquadService, SquadServiceResponse} @@ -1421,19 +1423,27 @@ class ChatOperations( } def commandSetTime(session: Session, contents: String): Unit = { - val TimePattern = """([01]?\d|2[0-3]):([0-5]\d)""".r + val TimePattern = """([01]?\d|2[0-3]):([0-5]?\d)""".r TimePattern.findFirstMatchIn(contents) match { case Some(m) => val hh = m.group(1).toInt % 24 val mm = m.group(2).toInt % 60 val requestedTimeOfDay = GetTimeOfDayValue(hh, mm) - val msg = TimeOfDayMessage(requestedTimeOfDay) + val zone = session.zone // update zone - session.zone.SetTimeOfDay(requestedTimeOfDay) + zone.SetTimeOfDay(requestedTimeOfDay) + + // build update message + val msg = TimeOfDayMessage(zone.GetTimeOfDay(), zone.GetTimeOfDaySpeed()) + + // update players in zone + zone.AvatarEvents ! AvatarServiceMessage( + zone.id, + AvatarAction.SendResponse(Service.defaultPlayerGUID, msg) + ) - sendResponse(msg) sendResponse(ChatMsg(messageType = UNK_227, contents = s"@CMT_SETTIME_OK^$hh~^$mm~")) case _ => sendResponse(ChatMsg(messageType = UNK_229, contents = "@CMT_SETTIME_usage")) @@ -1448,12 +1458,20 @@ class ChatOperations( var timeSpeed = m.matched.toFloat if (timeSpeed < -1000.0f) timeSpeed = -1000.0f if (timeSpeed > 1000.0f) timeSpeed = 1000.0f - val msg = TimeOfDayMessage(GetTimeOfDayValue(), timeSpeed) + val zone = session.zone // update zone - session.zone.SetTimeOfDaySpeed(timeSpeed) + zone.SetTimeOfDaySpeed(timeSpeed) + + // build update message + val msg = TimeOfDayMessage(zone.GetTimeOfDay(), zone.GetTimeOfDaySpeed()) + + // update players in zone + zone.AvatarEvents ! AvatarServiceMessage( + zone.id, + AvatarAction.SendResponse(Service.defaultPlayerGUID, msg) + ) - sendResponse(msg) sendResponse(ChatMsg(messageType = UNK_227, contents = s"@CMT_SETTIMESPEED_OK^$timeSpeed~")) case _ => sendResponse(ChatMsg(messageType = UNK_229, contents = "@CMT_SETTIMESPEED_usage")) diff --git a/src/main/scala/net/psforever/objects/zones/Zone.scala b/src/main/scala/net/psforever/objects/zones/Zone.scala index 10c99dcea..8cad4927f 100644 --- a/src/main/scala/net/psforever/objects/zones/Zone.scala +++ b/src/main/scala/net/psforever/objects/zones/Zone.scala @@ -576,9 +576,9 @@ class Zone(val id: String, val map: ZoneMap, zoneNumber: Int) { // get time since origin val timeDiff = System.currentTimeMillis() - timeOfDayOrigin // get seconds - limit to 24h - val diffSeconds = timeDiff / 1000 % 86400 + val diffSeconds = (timeDiff / 1000) % 86400 - timeDiff.toFloat + diffSeconds.toFloat } def SetTimeOfDay(requestedTime: Float) = { @@ -590,7 +590,7 @@ class Zone(val id: String, val map: ZoneMap, zoneNumber: Int) { // substract requestedMillis from now to get new origin val newOrigin = now - requestMillis - timeOfDayOrigin = newOrigin.toInt + timeOfDayOrigin = newOrigin.toLong } def GetTimeOfDaySpeed(): Float = {