Core/Calendar: Implement different timezone support for ingame calendar

Port From (https://github.com/TrinityCore/TrinityCore/commit/b888b1b09f71a8b8b4a9d45c804a1f164fb65ac3)
This commit is contained in:
hondacrx
2024-02-21 16:36:19 -05:00
parent 47a64b8782
commit 0f4130704a
25 changed files with 831 additions and 322 deletions
@@ -4,11 +4,13 @@
using Bgs.Protocol; using Bgs.Protocol;
using Bgs.Protocol.Authentication.V1; using Bgs.Protocol.Authentication.V1;
using Bgs.Protocol.Challenge.V1; using Bgs.Protocol.Challenge.V1;
using Framework;
using Framework.Constants; using Framework.Constants;
using Framework.Database; using Framework.Database;
using Framework.Realm; using Framework.Realm;
using Google.Protobuf; using Google.Protobuf;
using System; using System;
using System.Text.Json;
namespace BNetServer.Networking namespace BNetServer.Networking
{ {
@@ -39,6 +41,20 @@ namespace BNetServer.Networking
os = logonRequest.Platform; os = logonRequest.Platform;
build = (uint)logonRequest.ApplicationVersion; build = (uint)logonRequest.ApplicationVersion;
_timezoneOffset = TimeSpan.Zero;
if (logonRequest.HasDeviceId)
{
var doc = JsonSerializer.Deserialize<JsonDocument>(logonRequest.DeviceId);
if (doc != null)
{
var itr = doc.RootElement.GetProperty("UTCO");
{
if (itr.TryGetUInt32(out uint value))
_timezoneOffset = Timezone.GetOffsetByHash(value);
}
}
}
ChallengeExternalRequest externalChallenge = new(); ChallengeExternalRequest externalChallenge = new();
externalChallenge.PayloadType = "web_auth_url"; externalChallenge.PayloadType = "web_auth_url";
externalChallenge.Payload = ByteString.CopyFromUtf8($"https://{Global.LoginService.GetHostnameForClient(GetRemoteIpAddress())}:{Global.LoginService.GetPort()}/bnetserver/login/"); externalChallenge.Payload = ByteString.CopyFromUtf8($"https://{Global.LoginService.GetHostnameForClient(GetRemoteIpAddress())}:{Global.LoginService.GetPort()}/bnetserver/login/");
-3
View File
@@ -1,11 +1,8 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved. // Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using BNetServer.Networking;
using Framework.Configuration; using Framework.Configuration;
using Framework.Cryptography;
using Framework.Database; using Framework.Database;
using Framework.Networking;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Timers; using System.Timers;
@@ -93,7 +93,7 @@ public static class Time
public static DateTime UnixTimeToDateTime(long unixTime) public static DateTime UnixTimeToDateTime(long unixTime)
{ {
return DateTimeOffset.FromUnixTimeSeconds(unixTime).LocalDateTime; return DateTimeOffset.FromUnixTimeSeconds(unixTime).DateTime;
} }
public static long DateTimeToUnixTime(DateTime dateTime) public static long DateTimeToUnixTime(DateTime dateTime)
+78
View File
@@ -0,0 +1,78 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Framework
{
public class Timezone
{
static Dictionary<uint, TimeSpan> _timezoneOffsetsByHash = InitTimezoneHashDb();
static Dictionary<uint, TimeSpan> InitTimezoneHashDb()
{
// Generate our hash db to match values sent in client authentication packets
Dictionary<uint, TimeSpan> hashToOffset = new();
foreach (var sysInfo in TimeZoneInfo.GetSystemTimeZones())
{
TimeSpan offsetMinutes = sysInfo.BaseUtcOffset;
hashToOffset.TryAdd(offsetMinutes.TotalMinutes.ToString().HashFnv1a(), offsetMinutes);
}
return hashToOffset;
}
static (TimeSpan, string)[] _clientSupportedTimezones =
{
(TimeSpan.FromMinutes(-480), "America/Los_Angeles"),
( TimeSpan.FromMinutes(-420), "America/Denver" ),
( TimeSpan.FromMinutes(-360), "America/Chicago" ),
( TimeSpan.FromMinutes(-300), "America/New_York" ),
( TimeSpan.FromMinutes(-180), "America/Sao_Paulo" ),
( TimeSpan.FromMinutes(0), "Etc/UTC" ),
( TimeSpan.FromMinutes(60), "Europe/Paris" ),
( TimeSpan.FromMinutes(480), "Asia/Shanghai" ),
( TimeSpan.FromMinutes(480), "Asia/Taipei" ),
( TimeSpan.FromMinutes(540), "Asia/Seoul" ),
( TimeSpan.FromMinutes(600), "Australia/Melbourne" ),
};
public static TimeSpan GetOffsetByHash(uint hash)
{
if (_timezoneOffsetsByHash.TryGetValue(hash, out var offset))
return offset;
return TimeSpan.Zero;
}
public static TimeSpan GetSystemZoneOffsetAt(DateTime date)
{
return TimeZoneInfo.Local.GetUtcOffset(date);
}
public static TimeSpan GetSystemZoneOffset()
{
return DateTimeOffset.Now.Offset;
}
public static string GetSystemZoneName()
{
return TimeZoneInfo.Local.StandardName;
}
public static string FindClosestClientSupportedTimezone(string currentTimezone, TimeSpan currentTimezoneOffset)
{
// try exact match
var pair = _clientSupportedTimezones.FirstOrDefault(tz => tz.Item2 == currentTimezone);
if (!pair.Item2.IsEmpty())
return pair.Item2;
// try closest offset
pair = _clientSupportedTimezones.MinBy(left => left.Item1 - currentTimezoneOffset);
return pair.Item2;
}
}
}
+11
View File
@@ -422,6 +422,17 @@ namespace System
return -1; return -1;
} }
public static uint HashFnv1a(this string data)
{
uint hash = 0x811C9DC5u;
foreach (char c in data)
{
hash ^= c;
hash *= 0x1000193u;
}
return hash;
}
#endregion #endregion
#region BinaryReader #region BinaryReader
+112 -80
View File
@@ -178,9 +178,9 @@ namespace Game.Achievements
public virtual void CompletedAchievement(AchievementRecord entry, Player referencePlayer) { } public virtual void CompletedAchievement(AchievementRecord entry, Player referencePlayer) { }
public Func<KeyValuePair<uint, CompletedAchievementData>, AchievementRecord> VisibleAchievementCheck = value => public Func<uint, AchievementRecord> VisibleAchievementCheck = id =>
{ {
AchievementRecord achievement = CliDB.AchievementStorage.LookupByKey(value.Key); AchievementRecord achievement = CliDB.AchievementStorage.LookupByKey(id);
if (achievement != null && !achievement.Flags.HasAnyFlag(AchievementFlags.Hidden)) if (achievement != null && !achievement.Flags.HasAnyFlag(AchievementFlags.Hidden))
return achievement; return achievement;
return null; return null;
@@ -358,33 +358,35 @@ namespace Game.Achievements
AllAccountCriteria allAccountCriteria = new(); AllAccountCriteria allAccountCriteria = new();
AllAchievementData achievementData = new(); AllAchievementData achievementData = new();
foreach (var pair in _completedAchievements) foreach (var (id, completedAchievement) in _completedAchievements)
{ {
AchievementRecord achievement = VisibleAchievementCheck(pair); AchievementRecord achievement = VisibleAchievementCheck(id);
if (achievement == null) if (achievement == null)
continue; continue;
EarnedAchievement earned = new(); EarnedAchievement earned = new();
earned.Id = pair.Key; earned.Id = id;
earned.Date = pair.Value.Date; earned.Date.SetUtcTimeFromUnixTime(completedAchievement.Date);
if (!achievement.Flags.HasAnyFlag(AchievementFlags.Account)) if (!achievement.Flags.HasAnyFlag(AchievementFlags.Account))
{ {
earned.Owner = _owner.GetGUID(); earned.Owner = _owner.GetGUID();
earned.VirtualRealmAddress = earned.NativeRealmAddress = Global.WorldMgr.GetVirtualRealmAddress(); earned.VirtualRealmAddress = earned.NativeRealmAddress = Global.WorldMgr.GetVirtualRealmAddress();
} }
achievementData.Data.Earned.Add(earned); achievementData.Data.Earned.Add(earned);
} }
foreach (var pair in _criteriaProgress) foreach (var (id, criteriaProgres) in _criteriaProgress)
{ {
Criteria criteria = Global.CriteriaMgr.GetCriteria(pair.Key); Criteria criteria = Global.CriteriaMgr.GetCriteria(id);
CriteriaProgressPkt progress = new(); CriteriaProgressPkt progress = new();
progress.Id = pair.Key; progress.Id = id;
progress.Quantity = pair.Value.Counter; progress.Quantity = criteriaProgres.Counter;
progress.Player = pair.Value.PlayerGUID; progress.Player = criteriaProgres.PlayerGUID;
progress.Flags = 0; progress.Flags = 0;
progress.Date = pair.Value.Date; progress.Date.SetUtcTimeFromUnixTime(criteriaProgres.Date);
progress.Date += _owner.GetSession().GetTimezoneOffset();
progress.TimeFromStart = 0; progress.TimeFromStart = 0;
progress.TimeFromCreate = 0; progress.TimeFromCreate = 0;
achievementData.Data.Progress.Add(progress); achievementData.Data.Progress.Add(progress);
@@ -392,11 +394,12 @@ namespace Game.Achievements
if (criteria.FlagsCu.HasAnyFlag(CriteriaFlagsCu.Account)) if (criteria.FlagsCu.HasAnyFlag(CriteriaFlagsCu.Account))
{ {
CriteriaProgressPkt accountProgress = new(); CriteriaProgressPkt accountProgress = new();
accountProgress.Id = pair.Key; accountProgress.Id = id;
accountProgress.Quantity = pair.Value.Counter; accountProgress.Quantity = criteriaProgres.Counter;
accountProgress.Player = _owner.GetSession().GetBattlenetAccountGUID(); accountProgress.Player = _owner.GetSession().GetBattlenetAccountGUID();
accountProgress.Flags = 0; accountProgress.Flags = 0;
accountProgress.Date = pair.Value.Date; accountProgress.Date.SetUtcTimeFromUnixTime(criteriaProgres.Date);
accountProgress.Date += _owner.GetSession().GetTimezoneOffset();
accountProgress.TimeFromStart = 0; accountProgress.TimeFromStart = 0;
accountProgress.TimeFromCreate = 0; accountProgress.TimeFromCreate = 0;
allAccountCriteria.Progress.Add(accountProgress); allAccountCriteria.Progress.Add(accountProgress);
@@ -414,31 +417,34 @@ namespace Game.Achievements
RespondInspectAchievements inspectedAchievements = new(); RespondInspectAchievements inspectedAchievements = new();
inspectedAchievements.Player = _owner.GetGUID(); inspectedAchievements.Player = _owner.GetGUID();
foreach (var pair in _completedAchievements) foreach (var (id, completedAchievement) in _completedAchievements)
{ {
AchievementRecord achievement = VisibleAchievementCheck(pair); AchievementRecord achievement = VisibleAchievementCheck(id);
if (achievement == null) if (achievement == null)
continue; continue;
EarnedAchievement earned = new(); EarnedAchievement earned = new();
earned.Id = pair.Key; earned.Id = id;
earned.Date = pair.Value.Date; earned.Date.SetUtcTimeFromUnixTime(completedAchievement.Date);
earned.Date += receiver.GetSession().GetTimezoneOffset();
if (!achievement.Flags.HasAnyFlag(AchievementFlags.Account)) if (!achievement.Flags.HasAnyFlag(AchievementFlags.Account))
{ {
earned.Owner = _owner.GetGUID(); earned.Owner = _owner.GetGUID();
earned.VirtualRealmAddress = earned.NativeRealmAddress = Global.WorldMgr.GetVirtualRealmAddress(); earned.VirtualRealmAddress = earned.NativeRealmAddress = Global.WorldMgr.GetVirtualRealmAddress();
} }
inspectedAchievements.Data.Earned.Add(earned); inspectedAchievements.Data.Earned.Add(earned);
} }
foreach (var pair in _criteriaProgress) foreach (var (id, criteriaProgres) in _criteriaProgress)
{ {
CriteriaProgressPkt progress = new(); CriteriaProgressPkt progress = new();
progress.Id = pair.Key; progress.Id = id;
progress.Quantity = pair.Value.Counter; progress.Quantity = criteriaProgres.Counter;
progress.Player = pair.Value.PlayerGUID; progress.Player = criteriaProgres.PlayerGUID;
progress.Flags = 0; progress.Flags = 0;
progress.Date = pair.Value.Date; progress.Date.SetUtcTimeFromUnixTime(criteriaProgres.Date);
progress.Date += receiver.GetSession().GetTimezoneOffset();
progress.TimeFromStart = 0; progress.TimeFromStart = 0;
progress.TimeFromCreate = 0; progress.TimeFromCreate = 0;
inspectedAchievements.Data.Progress.Add(progress); inspectedAchievements.Data.Progress.Add(progress);
@@ -571,7 +577,8 @@ namespace Game.Achievements
if (criteria.Entry.StartTimer != 0) if (criteria.Entry.StartTimer != 0)
criteriaUpdate.Progress.Flags = timedCompleted ? 1 : 0u; // 1 is for keeping the counter at 0 in client criteriaUpdate.Progress.Flags = timedCompleted ? 1 : 0u; // 1 is for keeping the counter at 0 in client
criteriaUpdate.Progress.Date = progress.Date; criteriaUpdate.Progress.Date.SetUtcTimeFromUnixTime(progress.Date);
criteriaUpdate.Progress.Date += _owner.GetSession().GetTimezoneOffset();
criteriaUpdate.Progress.TimeFromStart = (uint)timeElapsed.TotalSeconds; criteriaUpdate.Progress.TimeFromStart = (uint)timeElapsed.TotalSeconds;
criteriaUpdate.Progress.TimeFromCreate = 0; criteriaUpdate.Progress.TimeFromCreate = 0;
SendPacket(criteriaUpdate); SendPacket(criteriaUpdate);
@@ -588,7 +595,8 @@ namespace Game.Achievements
if (criteria.Entry.StartTimer != 0) if (criteria.Entry.StartTimer != 0)
criteriaUpdate.Flags = timedCompleted ? 1 : 0u; // 1 is for keeping the counter at 0 in client criteriaUpdate.Flags = timedCompleted ? 1 : 0u; // 1 is for keeping the counter at 0 in client
criteriaUpdate.CurrentTime = progress.Date; criteriaUpdate.CurrentTime.SetUtcTimeFromUnixTime(progress.Date);
criteriaUpdate.CurrentTime += _owner.GetSession().GetTimezoneOffset();
criteriaUpdate.ElapsedTime = (uint)timeElapsed.TotalSeconds; criteriaUpdate.ElapsedTime = (uint)timeElapsed.TotalSeconds;
criteriaUpdate.CreationTime = 0; criteriaUpdate.CreationTime = 0;
@@ -640,17 +648,26 @@ namespace Game.Achievements
} }
} }
AchievementEarned achievementEarned = new(); var achievementEarnedBuilder = (Player receiver) =>
achievementEarned.Sender = _owner.GetGUID(); {
achievementEarned.Earner = _owner.GetGUID(); AchievementEarned achievementEarned = new();
achievementEarned.EarnerNativeRealm = achievementEarned.EarnerVirtualRealm = Global.WorldMgr.GetVirtualRealmAddress(); achievementEarned.Sender = _owner.GetGUID();
achievementEarned.AchievementID = achievement.Id; achievementEarned.Earner = _owner.GetGUID();
achievementEarned.Time = GameTime.GetGameTime(); achievementEarned.EarnerNativeRealm = achievementEarned.EarnerVirtualRealm = Global.WorldMgr.GetVirtualRealmAddress();
achievementEarned.AchievementID = achievement.Id;
achievementEarned.Time = GameTime.GetUtcWowTime();
achievementEarned.Time += receiver.GetSession().GetTimezoneOffset();
receiver.SendPacket(achievementEarned);
};
if (!achievement.Flags.HasAnyFlag(AchievementFlags.TrackingFlag)) if (!achievement.Flags.HasAnyFlag(AchievementFlags.TrackingFlag))
_owner.SendMessageToSetInRange(achievementEarned, WorldConfig.GetFloatValue(WorldCfg.ListenRangeSay), true); {
float dist = WorldConfig.GetFloatValue(WorldCfg.ListenRangeSay);
MessageDistDeliverer notifier = new(_owner, achievementEarnedBuilder, dist);
Cell.VisitWorldObjects(_owner, notifier, dist);
}
else else
_owner.SendPacket(achievementEarned); achievementEarnedBuilder(_owner);
} }
public override void SendPacket(ServerPacket data) public override void SendPacket(ServerPacket data)
@@ -683,13 +700,17 @@ namespace Game.Achievements
base.Reset(); base.Reset();
ObjectGuid guid = _owner.GetGUID(); ObjectGuid guid = _owner.GetGUID();
foreach (var iter in _completedAchievements) foreach (var (id, _) in _completedAchievements)
{ {
GuildAchievementDeleted guildAchievementDeleted = new(); _owner.BroadcastWorker(receiver =>
guildAchievementDeleted.AchievementID = iter.Key; {
guildAchievementDeleted.GuildGUID = guid; GuildAchievementDeleted guildAchievementDeleted = new();
guildAchievementDeleted.TimeDeleted = GameTime.GetGameTime(); guildAchievementDeleted.AchievementID = id;
SendPacket(guildAchievementDeleted); guildAchievementDeleted.GuildGUID = guid;
guildAchievementDeleted.TimeDeleted = GameTime.GetUtcWowTime();
guildAchievementDeleted.TimeDeleted += receiver.GetSession().GetTimezoneOffset();
receiver.SendPacket(guildAchievementDeleted);
});
} }
_achievementPoints = 0; _achievementPoints = 0;
@@ -831,15 +852,16 @@ namespace Game.Achievements
{ {
AllGuildAchievements allGuildAchievements = new(); AllGuildAchievements allGuildAchievements = new();
foreach (var pair in _completedAchievements) foreach (var (id, completedAchievement) in _completedAchievements)
{ {
AchievementRecord achievement = VisibleAchievementCheck(pair); AchievementRecord achievement = VisibleAchievementCheck(id);
if (achievement == null) if (achievement == null)
continue; continue;
EarnedAchievement earned = new(); EarnedAchievement earned = new();
earned.Id = pair.Key; earned.Id = id;
earned.Date = pair.Value.Date; earned.Date.SetUtcTimeFromUnixTime(completedAchievement.Date);
earned.Date += receiver.GetSession().GetTimezoneOffset();
allGuildAchievements.Earned.Add(earned); allGuildAchievements.Earned.Add(earned);
} }
@@ -856,25 +878,26 @@ namespace Game.Achievements
if (tree != null) if (tree != null)
{ {
CriteriaManager.WalkCriteriaTree(tree, node => CriteriaManager.WalkCriteriaTree(tree, node =>
{
if (node.Criteria != null)
{
var progress = _criteriaProgress.LookupByKey(node.Criteria.Id);
if (progress != null)
{ {
GuildCriteriaProgress guildCriteriaProgress = new(); if (node.Criteria != null)
guildCriteriaProgress.CriteriaID = node.Criteria.Id; {
guildCriteriaProgress.DateCreated = 0; var progress = _criteriaProgress.LookupByKey(node.Criteria.Id);
guildCriteriaProgress.DateStarted = 0; if (progress != null)
guildCriteriaProgress.DateUpdated = progress.Date; {
guildCriteriaProgress.Quantity = progress.Counter; GuildCriteriaProgress guildCriteriaProgress = new();
guildCriteriaProgress.PlayerGUID = progress.PlayerGUID; guildCriteriaProgress.CriteriaID = node.Criteria.Id;
guildCriteriaProgress.Flags = 0; guildCriteriaProgress.DateCreated = 0;
guildCriteriaProgress.DateStarted = 0;
guildCriteriaProgress.DateUpdated.SetUtcTimeFromUnixTime(progress.Date);
guildCriteriaProgress.DateUpdated += receiver.GetSession().GetTimezoneOffset();
guildCriteriaProgress.Quantity = progress.Counter;
guildCriteriaProgress.PlayerGUID = progress.PlayerGUID;
guildCriteriaProgress.Flags = 0;
guildCriteriaUpdate.Progress.Add(guildCriteriaProgress); guildCriteriaUpdate.Progress.Add(guildCriteriaProgress);
} }
} }
}); });
} }
} }
@@ -895,7 +918,8 @@ namespace Game.Achievements
guildCriteriaProgress.CriteriaID = criteriaId; guildCriteriaProgress.CriteriaID = criteriaId;
guildCriteriaProgress.DateCreated = 0; guildCriteriaProgress.DateCreated = 0;
guildCriteriaProgress.DateStarted = 0; guildCriteriaProgress.DateStarted = 0;
guildCriteriaProgress.DateUpdated = progress.Date; guildCriteriaProgress.DateUpdated.SetUtcTimeFromUnixTime(progress.Date);
guildCriteriaProgress.DateUpdated += receiver.GetSession().GetTimezoneOffset();
guildCriteriaProgress.Quantity = progress.Counter; guildCriteriaProgress.Quantity = progress.Counter;
guildCriteriaProgress.PlayerGUID = progress.PlayerGUID; guildCriteriaProgress.PlayerGUID = progress.PlayerGUID;
guildCriteriaProgress.Flags = 0; guildCriteriaProgress.Flags = 0;
@@ -975,20 +999,22 @@ namespace Game.Achievements
public override void SendCriteriaUpdate(Criteria entry, CriteriaProgress progress, TimeSpan timeElapsed, bool timedCompleted) public override void SendCriteriaUpdate(Criteria entry, CriteriaProgress progress, TimeSpan timeElapsed, bool timedCompleted)
{ {
GuildCriteriaUpdate guildCriteriaUpdate = new(); foreach (Player member in _owner.GetMembersTrackingCriteria(entry.Id))
{
GuildCriteriaUpdate guildCriteriaUpdate = new();
GuildCriteriaProgress guildCriteriaProgress = new();
guildCriteriaProgress.CriteriaID = entry.Id;
guildCriteriaProgress.DateCreated = 0;
guildCriteriaProgress.DateStarted = 0;
guildCriteriaProgress.DateUpdated.SetUtcTimeFromUnixTime(progress.Date);
guildCriteriaProgress.DateUpdated += member.GetSession().GetTimezoneOffset();
guildCriteriaProgress.Quantity = progress.Counter;
guildCriteriaProgress.PlayerGUID = progress.PlayerGUID;
guildCriteriaProgress.Flags = 0;
guildCriteriaUpdate.Progress.Add(guildCriteriaProgress);
GuildCriteriaProgress guildCriteriaProgress = new(); member.SendPacket(guildCriteriaUpdate);
guildCriteriaProgress.CriteriaID = entry.Id; }
guildCriteriaProgress.DateCreated = 0;
guildCriteriaProgress.DateStarted = 0;
guildCriteriaProgress.DateUpdated = progress.Date;
guildCriteriaProgress.Quantity = progress.Counter;
guildCriteriaProgress.PlayerGUID = progress.PlayerGUID;
guildCriteriaProgress.Flags = 0;
guildCriteriaUpdate.Progress.Add(guildCriteriaProgress);
_owner.BroadcastPacketIfTrackingAchievement(guildCriteriaUpdate, entry.Id);
} }
public override void SendCriteriaProgressRemoved(uint criteriaId) public override void SendCriteriaProgressRemoved(uint criteriaId)
@@ -1012,11 +1038,17 @@ namespace Game.Achievements
Global.WorldMgr.SendGlobalMessage(serverFirstAchievement); Global.WorldMgr.SendGlobalMessage(serverFirstAchievement);
} }
GuildAchievementEarned guildAchievementEarned = new(); var guildAchievementEarnedBuilder = (Player receiver) =>
guildAchievementEarned.AchievementID = achievement.Id; {
guildAchievementEarned.GuildGUID = _owner.GetGUID(); GuildAchievementEarned guildAchievementEarned = new();
guildAchievementEarned.TimeEarned = GameTime.GetGameTime(); guildAchievementEarned.AchievementID = achievement.Id;
SendPacket(guildAchievementEarned); guildAchievementEarned.GuildGUID = _owner.GetGUID();
guildAchievementEarned.TimeEarned = GameTime.GetUtcWowTime();
guildAchievementEarned.TimeEarned += receiver.GetSession().GetTimezoneOffset();
receiver.SendPacket(guildAchievementEarned);
};
_owner.BroadcastWorker(guildAchievementEarnedBuilder);
} }
public override void SendPacket(ServerPacket data) public override void SendPacket(ServerPacket data)
+6 -3
View File
@@ -1790,9 +1790,12 @@ namespace Game.Achievements
break; break;
case ModifierTreeType.TimeBetween: // 109 case ModifierTreeType.TimeBetween: // 109
{ {
long from = Time.GetUnixTimeFromPackedTime(reqValue); WowTime from = new();
long to = Time.GetUnixTimeFromPackedTime((uint)secondaryAsset); from.SetPackedTime(reqValue);
if (GameTime.GetGameTime() < from || GameTime.GetGameTime() > to) WowTime to = new();
to.SetPackedTime((uint)secondaryAsset);
if (!GameTime.GetWowTime().IsInRange(from, to))
return false; return false;
break; break;
} }
+4 -4
View File
@@ -1547,13 +1547,13 @@ namespace Game
// owner exist (online or offline) // owner exist (online or offline)
if ((owner != null || Global.CharacterCacheStorage.HasCharacterCacheEntry(auction.Owner)))// && !sAuctionBotConfig.IsBotChar(auction.Owner)) if ((owner != null || Global.CharacterCacheStorage.HasCharacterCacheEntry(auction.Owner)))// && !sAuctionBotConfig.IsBotChar(auction.Owner))
{ {
ByteBuffer tempBuffer = new(); WowTime eta = GameTime.GetUtcWowTime();
tempBuffer.WritePackedTime(GameTime.GetGameTime() + WorldConfig.GetIntValue(WorldCfg.MailDeliveryDelay)); eta += TimeSpan.FromSeconds(WorldConfig.GetIntValue(WorldCfg.MailDeliveryDelay));
uint eta = tempBuffer.ReadUInt32(); eta += owner.GetSession().GetTimezoneOffset();
new MailDraft(Global.AuctionHouseMgr.BuildItemAuctionMailSubject(AuctionMailType.Invoice, auction), new MailDraft(Global.AuctionHouseMgr.BuildItemAuctionMailSubject(AuctionMailType.Invoice, auction),
Global.AuctionHouseMgr.BuildAuctionInvoiceMailBody(auction.Bidder, auction.BidAmount, auction.BuyoutOrUnitPrice, (uint)auction.Deposit, Global.AuctionHouseMgr.BuildAuctionInvoiceMailBody(auction.Bidder, auction.BidAmount, auction.BuyoutOrUnitPrice, (uint)auction.Deposit,
CalculateAuctionHouseCut(auction.BidAmount), WorldConfig.GetUIntValue(WorldCfg.MailDeliveryDelay), eta)) CalculateAuctionHouseCut(auction.BidAmount), WorldConfig.GetUIntValue(WorldCfg.MailDeliveryDelay), eta.GetPackedTime()))
.SendMailTo(trans, new MailReceiver(owner, auction.Owner), new MailSender(this), MailCheckMask.Copied); .SendMailTo(trans, new MailReceiver(owner, auction.Owner), new MailSender(this), MailCheckMask.Copied);
} }
} }
+126 -74
View File
@@ -19,7 +19,7 @@ namespace Game
CalendarManager() CalendarManager()
{ {
_events = new List<CalendarEvent>(); _events = new List<CalendarEvent>();
_invites = new MultiMap<ulong,CalendarInvite>(); _invites = new MultiMap<ulong, CalendarInvite>();
} }
public void LoadFromDB() public void LoadFromDB()
@@ -147,7 +147,6 @@ namespace Game
SQLTransaction trans = new(); SQLTransaction trans = new();
PreparedStatement stmt; PreparedStatement stmt;
MailDraft mail = new(calendarEvent.BuildCalendarMailSubject(remover), calendarEvent.BuildCalendarMailBody());
var eventInvites = _invites[calendarEvent.EventId]; var eventInvites = _invites[calendarEvent.EventId];
for (int i = 0; i < eventInvites.Count; ++i) for (int i = 0; i < eventInvites.Count; ++i)
@@ -160,7 +159,10 @@ namespace Game
// guild events only? check invite status here? // guild events only? check invite status here?
// When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki) // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki)
if (!remover.IsEmpty() && invite.InviteeGuid != remover) if (!remover.IsEmpty() && invite.InviteeGuid != remover)
{
MailDraft mail = new(calendarEvent.BuildCalendarMailSubject(remover), calendarEvent.BuildCalendarMailBody(Global.ObjAccessor.FindConnectedPlayer(invite.InviteeGuid)));
mail.SendMailTo(trans, new MailReceiver(invite.InviteeGuid.GetCounter()), new MailSender(calendarEvent), MailCheckMask.Copied); mail.SendMailTo(trans, new MailReceiver(invite.InviteeGuid.GetCounter()), new MailSender(calendarEvent), MailCheckMask.Copied);
}
} }
_invites.Remove(calendarEvent.EventId); _invites.Remove(calendarEvent.EventId);
@@ -436,68 +438,100 @@ namespace Game
uint level = player != null ? player.GetLevel() : Global.CharacterCacheStorage.GetCharacterLevelByGuid(invitee); uint level = player != null ? player.GetLevel() : Global.CharacterCacheStorage.GetCharacterLevelByGuid(invitee);
CalendarInviteAdded packet = new(); var packetBuilder = (Player receiver) =>
packet.EventID = calendarEvent != null ? calendarEvent.EventId : 0; {
packet.InviteGuid = invitee; CalendarInviteAdded packet = new();
packet.InviteID = calendarEvent != null ? invite.InviteId : 0; packet.EventID = calendarEvent != null ? calendarEvent.EventId : 0;
packet.Level = (byte)level; packet.InviteGuid = invitee;
packet.ResponseTime = invite.ResponseTime; packet.InviteID = calendarEvent != null ? invite.InviteId : 0;
packet.Status = invite.Status; packet.Level = (byte)level;
packet.Type = (byte)(calendarEvent != null ? calendarEvent.IsGuildEvent() ? 1 : 0 : 0); // Correct ? packet.ResponseTime.SetUtcTimeFromUnixTime(invite.ResponseTime);
packet.ClearPending = calendarEvent == null || !calendarEvent.IsGuildEvent(); // Correct ? packet.ResponseTime += receiver.GetSession().GetTimezoneOffset();
packet.Status = invite.Status;
packet.Type = (byte)(calendarEvent != null ? calendarEvent.IsGuildEvent() ? 1 : 0 : 0); // Correct ?
packet.ClearPending = calendarEvent != null ? !calendarEvent.IsGuildEvent() : true; // Correct ?
receiver.SendPacket(packet);
};
if (calendarEvent == null) // Pre-invite if (calendarEvent == null) // Pre-invite
{ {
player = Global.ObjAccessor.FindPlayer(invite.SenderGuid); player = Global.ObjAccessor.FindPlayer(invite.SenderGuid);
if (player != null) if (player != null)
player.SendPacket(packet); packetBuilder(player);
} }
else else
{ {
if (calendarEvent.OwnerGuid != invite.InviteeGuid) // correct? if (calendarEvent.OwnerGuid != invite.InviteeGuid) // correct?
SendPacketToAllEventRelatives(packet, calendarEvent); foreach (Player receiver in GetAllEventRelatives(calendarEvent))
packetBuilder(receiver);
} }
} }
public void SendCalendarEventUpdateAlert(CalendarEvent calendarEvent, long originalDate) public void SendCalendarEventUpdateAlert(CalendarEvent calendarEvent, long originalDate)
{ {
CalendarEventUpdatedAlert packet = new(); var packetBuilder = (Player receiver) =>
packet.ClearPending = true; // FIXME {
packet.Date = calendarEvent.Date; CalendarEventUpdatedAlert packet = new();
packet.Description = calendarEvent.Description; packet.ClearPending = true; // FIXME
packet.EventID = calendarEvent.EventId; packet.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
packet.EventName = calendarEvent.Title; packet.Date += receiver.GetSession().GetTimezoneOffset();
packet.EventType = calendarEvent.EventType; packet.Description = calendarEvent.Description;
packet.Flags = calendarEvent.Flags; packet.EventID = calendarEvent.EventId;
packet.LockDate = calendarEvent.LockDate; // Always 0 ? packet.EventName = calendarEvent.Title;
packet.OriginalDate = originalDate; packet.EventType = calendarEvent.EventType;
packet.TextureID = calendarEvent.TextureId; packet.Flags = calendarEvent.Flags;
packet.LockDate.SetUtcTimeFromUnixTime(calendarEvent.LockDate); // Always 0 ?
if (calendarEvent.LockDate != 0)
packet.LockDate += receiver.GetSession().GetTimezoneOffset();
packet.OriginalDate.SetUtcTimeFromUnixTime(originalDate);
packet.OriginalDate += receiver.GetSession().GetTimezoneOffset();
packet.TextureID = calendarEvent.TextureId;
SendPacketToAllEventRelatives(packet, calendarEvent); receiver.SendPacket(packet);
};
foreach (Player receiver in GetAllEventRelatives(calendarEvent))
packetBuilder(receiver);
} }
public void SendCalendarEventStatus(CalendarEvent calendarEvent, CalendarInvite invite) public void SendCalendarEventStatus(CalendarEvent calendarEvent, CalendarInvite invite)
{ {
CalendarInviteStatusPacket packet = new(); var packetBuilder = (Player receiver) =>
packet.ClearPending = true; // FIXME {
packet.Date = calendarEvent.Date; CalendarInviteStatusPacket packet = new();
packet.EventID = calendarEvent.EventId; packet.ClearPending = true; // FIXME
packet.Flags = calendarEvent.Flags; packet.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
packet.InviteGuid = invite.InviteeGuid; packet.Date += receiver.GetSession().GetTimezoneOffset();
packet.ResponseTime = invite.ResponseTime; packet.EventID = calendarEvent.EventId;
packet.Status = invite.Status; packet.Flags = calendarEvent.Flags;
packet.InviteGuid = invite.InviteeGuid;
packet.ResponseTime.SetUtcTimeFromUnixTime(invite.ResponseTime);
packet.ResponseTime += receiver.GetSession().GetTimezoneOffset();
packet.Status = invite.Status;
SendPacketToAllEventRelatives(packet, calendarEvent); receiver.SendPacket(packet);
};
foreach (Player receiver in GetAllEventRelatives(calendarEvent))
packetBuilder(receiver);
} }
void SendCalendarEventRemovedAlert(CalendarEvent calendarEvent) void SendCalendarEventRemovedAlert(CalendarEvent calendarEvent)
{ {
CalendarEventRemovedAlert packet = new(); var packetBuilder = (Player receiver) =>
packet.ClearPending = true; // FIXME {
packet.Date = calendarEvent.Date; CalendarEventRemovedAlert packet = new();
packet.EventID = calendarEvent.EventId; packet.ClearPending = true; // FIXME
packet.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
packet.Date += receiver.GetSession().GetTimezoneOffset();
packet.EventID = calendarEvent.EventId;
SendPacketToAllEventRelatives(packet, calendarEvent); receiver.SendPacket(packet);
};
foreach (Player receiver in GetAllEventRelatives(calendarEvent))
packetBuilder(receiver);
} }
void SendCalendarEventInviteRemove(CalendarEvent calendarEvent, CalendarInvite invite, uint flags) void SendCalendarEventInviteRemove(CalendarEvent calendarEvent, CalendarInvite invite, uint flags)
@@ -524,33 +558,37 @@ namespace Game
void SendCalendarEventInviteAlert(CalendarEvent calendarEvent, CalendarInvite invite) void SendCalendarEventInviteAlert(CalendarEvent calendarEvent, CalendarInvite invite)
{ {
CalendarInviteAlert packet = new(); var packetBuilder = (Player receiver) =>
packet.Date = calendarEvent.Date; {
packet.EventID = calendarEvent.EventId; CalendarInviteAlert packet = new();
packet.EventName = calendarEvent.Title; packet.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
packet.EventType = calendarEvent.EventType; packet.Date += receiver.GetSession().GetTimezoneOffset();
packet.Flags = calendarEvent.Flags; packet.EventID = calendarEvent.EventId;
packet.InviteID = invite.InviteId; packet.EventName = calendarEvent.Title;
packet.InvitedByGuid = invite.SenderGuid; packet.EventType = calendarEvent.EventType;
packet.ModeratorStatus = invite.Rank; packet.Flags = calendarEvent.Flags;
packet.OwnerGuid = calendarEvent.OwnerGuid; packet.InviteID = invite.InviteId;
packet.Status = invite.Status; packet.InvitedByGuid = invite.SenderGuid;
packet.TextureID = calendarEvent.TextureId; packet.ModeratorStatus = invite.Rank;
packet.OwnerGuid = calendarEvent.OwnerGuid;
packet.Status = invite.Status;
packet.TextureID = calendarEvent.TextureId;
packet.EventClubID = calendarEvent.GuildId;
Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId); receiver.SendPacket(packet);
packet.EventGuildID = guild != null ? guild.GetGUID() : ObjectGuid.Empty; };
if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement())
{ {
guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId); Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId);
if (guild != null) if (guild != null)
guild.BroadcastPacket(packet); guild.BroadcastWorker(packetBuilder);
} }
else else
{ {
Player player = Global.ObjAccessor.FindPlayer(invite.InviteeGuid); Player player = Global.ObjAccessor.FindPlayer(invite.InviteeGuid);
if (player != null) if (player != null)
player.SendPacket(packet); packetBuilder(player);
} }
} }
@@ -560,23 +598,23 @@ namespace Game
if (player == null) if (player == null)
return; return;
List<CalendarInvite> eventInviteeList = _invites[calendarEvent.EventId];
CalendarSendEvent packet = new(); CalendarSendEvent packet = new();
packet.Date = calendarEvent.Date; packet.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
packet.Date += player.GetSession().GetTimezoneOffset();
packet.Description = calendarEvent.Description; packet.Description = calendarEvent.Description;
packet.EventID = calendarEvent.EventId; packet.EventID = calendarEvent.EventId;
packet.EventName = calendarEvent.Title; packet.EventName = calendarEvent.Title;
packet.EventType = sendType; packet.EventType = sendType;
packet.Flags = calendarEvent.Flags; packet.Flags = calendarEvent.Flags;
packet.GetEventType = calendarEvent.EventType; packet.GetEventType = calendarEvent.EventType;
packet.LockDate = calendarEvent.LockDate; // Always 0 ? packet.LockDate.SetUtcTimeFromUnixTime(calendarEvent.LockDate); // Always 0 ?
if (calendarEvent.LockDate != 0)
packet.LockDate += player.GetSession().GetTimezoneOffset();
packet.OwnerGuid = calendarEvent.OwnerGuid; packet.OwnerGuid = calendarEvent.OwnerGuid;
packet.TextureID = calendarEvent.TextureId; packet.TextureID = calendarEvent.TextureId;
packet.EventGuildID = calendarEvent.GuildId;
Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId); List<CalendarInvite> eventInviteeList = _invites[calendarEvent.EventId];
packet.EventGuildID = (guild != null ? guild.GetGUID() : ObjectGuid.Empty);
foreach (var calendarInvite in eventInviteeList) foreach (var calendarInvite in eventInviteeList)
{ {
ObjectGuid inviteeGuid = calendarInvite.InviteeGuid; ObjectGuid inviteeGuid = calendarInvite.InviteeGuid;
@@ -607,7 +645,8 @@ namespace Game
if (player != null) if (player != null)
{ {
CalendarInviteRemovedAlert packet = new(); CalendarInviteRemovedAlert packet = new();
packet.Date = calendarEvent.Date; packet.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
packet.Date += player.GetSession().GetTimezoneOffset();
packet.EventID = calendarEvent.EventId; packet.EventID = calendarEvent.EventId;
packet.Flags = calendarEvent.Flags; packet.Flags = calendarEvent.Flags;
packet.Status = status; packet.Status = status;
@@ -620,7 +659,7 @@ namespace Game
{ {
Player player = Global.ObjAccessor.FindPlayer(guid); Player player = Global.ObjAccessor.FindPlayer(guid);
if (player != null) if (player != null)
player.SendPacket(new CalendarClearPendingAction()); player.SendPacket(new CalendarClearPendingAction());
} }
public void SendCalendarCommandResult(ObjectGuid guid, CalendarError err, string param = null) public void SendCalendarCommandResult(ObjectGuid guid, CalendarError err, string param = null)
@@ -647,23 +686,33 @@ namespace Game
void SendPacketToAllEventRelatives(ServerPacket packet, CalendarEvent calendarEvent) void SendPacketToAllEventRelatives(ServerPacket packet, CalendarEvent calendarEvent)
{ {
foreach (Player player in GetAllEventRelatives(calendarEvent))
player.SendPacket(packet);
}
List<Player> GetAllEventRelatives(CalendarEvent calendarEvent)
{
List<Player> relatedPlayers = new();
// Send packet to all guild members // Send packet to all guild members
if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement())
{ {
Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId); Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId);
if (guild != null) if (guild != null)
guild.BroadcastPacket(packet); guild.BroadcastWorker(relatedPlayers.Add);
} }
// Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them) // Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them)
List<CalendarInvite> invites = _invites[calendarEvent.EventId]; var invites = _invites.LookupByKey(calendarEvent.EventId);
foreach (var playerCalendarEvent in invites) foreach (CalendarInvite invite in invites)
{ {
Player player = Global.ObjAccessor.FindPlayer(playerCalendarEvent.InviteeGuid); Player player = Global.ObjAccessor.FindConnectedPlayer(invite.InviteeGuid);
if (player != null) if (player != null)
if (!calendarEvent.IsGuildEvent() || player.GetGuildId() != calendarEvent.GuildId) if (!calendarEvent.IsGuildEvent() || player.GetGuildId() != calendarEvent.GuildId)
player.SendPacket(packet); relatedPlayers.Add(player);
} }
return relatedPlayers;
} }
List<CalendarEvent> _events; List<CalendarEvent> _events;
@@ -780,11 +829,14 @@ namespace Game
return remover + ":" + Title; return remover + ":" + Title;
} }
public string BuildCalendarMailBody() public string BuildCalendarMailBody(Player invitee)
{ {
var now = Time.UnixTimeToDateTime(Date); WowTime time = new();
uint time = Convert.ToUInt32(((now.Year - 1900) - 100) << 24 | (now.Month - 1) << 20 | (now.Day - 1) << 14 | (int)now.DayOfWeek << 11 | now.Hour << 6 | now.Minute); time.SetUtcTimeFromUnixTime(Date);
return time.ToString(); if (invitee != null)
time += invitee.GetSession().GetTimezoneOffset();
return time.GetPackedTime().ToString();
} }
public bool IsGuildEvent() { return Flags.HasAnyFlag(CalendarFlags.GuildEvent); } public bool IsGuildEvent() { return Flags.HasAnyFlag(CalendarFlags.GuildEvent); }
+11 -3
View File
@@ -2224,10 +2224,18 @@ namespace Game
if (condition.Time[0] != 0) if (condition.Time[0] != 0)
{ {
var from = Time.GetUnixTimeFromPackedTime(condition.Time[0]); WowTime time0 = new();
var to = Time.GetUnixTimeFromPackedTime(condition.Time[1]); time0.SetPackedTime(condition.Time[0]);
if (GameTime.GetGameTime() < from || GameTime.GetGameTime() > to) if (condition.Time[1] != 0)
{
WowTime time1 = new();
time1.SetPackedTime(condition.Time[1]);
if (!GameTime.GetWowTime().IsInRange(time0, time1))
return false;
}
else if (GameTime.GetWowTime() != time0)
return false; return false;
} }
+3 -3
View File
@@ -1443,14 +1443,14 @@ namespace Game.Entities
public virtual void SendMessageToSetInRange(ServerPacket data, float dist, bool self) public virtual void SendMessageToSetInRange(ServerPacket data, float dist, bool self)
{ {
PacketSenderRef sender = new(data); PacketSenderRef sender = new(data);
MessageDistDeliverer<PacketSenderRef> notifier = new(this, sender, dist); MessageDistDeliverer notifier = new(this, sender, dist);
Cell.VisitWorldObjects(this, notifier, dist); Cell.VisitWorldObjects(this, notifier, dist);
} }
public virtual void SendMessageToSet(ServerPacket data, Player skip) public virtual void SendMessageToSet(ServerPacket data, Player skip)
{ {
PacketSenderRef sender = new(data); PacketSenderRef sender = new(data);
var notifier = new MessageDistDeliverer<PacketSenderRef>(this, sender, GetVisibilityRange(), false, skip); var notifier = new MessageDistDeliverer(this, sender, GetVisibilityRange(), false, skip);
Cell.VisitWorldObjects(this, notifier, GetVisibilityRange()); Cell.VisitWorldObjects(this, notifier, GetVisibilityRange());
} }
@@ -1462,7 +1462,7 @@ namespace Game.Entities
if (self != null) if (self != null)
combatLogSender.Invoke(self); combatLogSender.Invoke(self);
MessageDistDeliverer<CombatLogSender> notifier = new(this, combatLogSender, GetVisibilityRange()); MessageDistDeliverer notifier = new(this, combatLogSender, GetVisibilityRange());
Cell.VisitWorldObjects(this, notifier, GetVisibilityRange()); Cell.VisitWorldObjects(this, notifier, GetVisibilityRange());
} }
+6 -6
View File
@@ -5557,8 +5557,8 @@ namespace Game.Entities
float TimeSpeed = 0.01666667f; float TimeSpeed = 0.01666667f;
LoginSetTimeSpeed loginSetTimeSpeed = new(); LoginSetTimeSpeed loginSetTimeSpeed = new();
loginSetTimeSpeed.NewSpeed = TimeSpeed; loginSetTimeSpeed.NewSpeed = TimeSpeed;
loginSetTimeSpeed.GameTime = (uint)GameTime.GetGameTime(); loginSetTimeSpeed.GameTime = GameTime.GetWowTime();
loginSetTimeSpeed.ServerTime = (uint)GameTime.GetGameTime(); loginSetTimeSpeed.ServerTime = GameTime.GetWowTime();
loginSetTimeSpeed.GameTimeHolidayOffset = 0; // @todo loginSetTimeSpeed.GameTimeHolidayOffset = 0; // @todo
loginSetTimeSpeed.ServerTimeHolidayOffset = 0; // @todo loginSetTimeSpeed.ServerTimeHolidayOffset = 0; // @todo
SendPacket(loginSetTimeSpeed); SendPacket(loginSetTimeSpeed);
@@ -6176,7 +6176,7 @@ namespace Game.Entities
SendPacket(data); SendPacket(data);
PacketSenderRef sender = new(data); PacketSenderRef sender = new(data);
var notifier = new MessageDistDeliverer<PacketSenderRef>(this, sender, dist); var notifier = new MessageDistDeliverer(this, sender, dist);
Cell.VisitWorldObjects(this, notifier, dist); Cell.VisitWorldObjects(this, notifier, dist);
} }
@@ -6186,7 +6186,7 @@ namespace Game.Entities
SendPacket(data); SendPacket(data);
PacketSenderRef sender = new(data); PacketSenderRef sender = new(data);
var notifier = new MessageDistDeliverer<PacketSenderRef>(this, sender, dist, own_team_only, null, required3dDist); var notifier = new MessageDistDeliverer(this, sender, dist, own_team_only, null, required3dDist);
Cell.VisitWorldObjects(this, notifier, dist); Cell.VisitWorldObjects(this, notifier, dist);
} }
@@ -6198,7 +6198,7 @@ namespace Game.Entities
// we use World.GetMaxVisibleDistance() because i cannot see why not use a distance // we use World.GetMaxVisibleDistance() because i cannot see why not use a distance
// update: replaced by GetMap().GetVisibilityDistance() // update: replaced by GetMap().GetVisibilityDistance()
PacketSenderRef sender = new(data); PacketSenderRef sender = new(data);
var notifier = new MessageDistDeliverer<PacketSenderRef>(this, sender, GetVisibilityRange(), false, skipped_rcvr); var notifier = new MessageDistDeliverer(this, sender, GetVisibilityRange(), false, skipped_rcvr);
Cell.VisitWorldObjects(this, notifier, GetVisibilityRange()); Cell.VisitWorldObjects(this, notifier, GetVisibilityRange());
} }
public override void SendMessageToSet(ServerPacket data, bool self) public override void SendMessageToSet(ServerPacket data, bool self)
@@ -6467,7 +6467,7 @@ namespace Game.Entities
localizer.Invoke(this); localizer.Invoke(this);
// Send to players // Send to players
MessageDistDeliverer<LocalizedDo> notifier = new(this, localizer, range, false, null, true); MessageDistDeliverer notifier = new(this, localizer, range, false, null, true);
Cell.VisitWorldObjects(this, notifier, range); Cell.VisitWorldObjects(this, notifier, range);
} }
+38 -12
View File
@@ -200,7 +200,8 @@ namespace Game.Guilds
{ {
GuildRoster roster = new(); GuildRoster roster = new();
roster.NumAccounts = (int)m_accountsNumber; roster.NumAccounts = (int)m_accountsNumber;
roster.CreateDate = (uint)m_createdDate; roster.CreateDate.SetUtcTimeFromUnixTime(m_createdDate);
roster.CreateDate += session.GetTimezoneOffset();
roster.GuildFlags = 0; roster.GuildFlags = 0;
bool sendOfficerNote = _HasRankRight(session.GetPlayer(), GuildRankRights.ViewOffNote); bool sendOfficerNote = _HasRankRight(session.GetPlayer(), GuildRankRights.ViewOffNote);
@@ -558,7 +559,7 @@ namespace Game.Guilds
return; return;
} }
// Invited player cannot be invited // Invited player cannot be invited
if (pInvitee.GetGuildIdInvited() != 0) if (pInvitee.GetGuildIdInvited() != 0)
{ {
SendCommandResult(session, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInvitedToGuild_S, name); SendCommandResult(session, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInvitedToGuild_S, name);
@@ -1040,7 +1041,10 @@ namespace Game.Guilds
GuildNewsPkt packet = new(); GuildNewsPkt packet = new();
foreach (var newsLogEntry in newsLog) foreach (var newsLogEntry in newsLog)
{
newsLogEntry.WritePacket(packet); newsLogEntry.WritePacket(packet);
packet.NewsEvents.Last().CompletedDate += session.GetTimezoneOffset();
}
session.SendPacket(packet); session.SendPacket(packet);
} }
@@ -1535,17 +1539,20 @@ namespace Game.Guilds
} }
} }
public void BroadcastPacketIfTrackingAchievement(ServerPacket packet, uint criteriaId) public List<Player> GetMembersTrackingCriteria(uint criteriaId)
{ {
foreach (var member in m_members.Values) List<Player> members = new();
foreach (var (_, member) in m_members)
{ {
if (member.IsTrackingCriteriaId(criteriaId)) if (member.IsTrackingCriteriaId(criteriaId))
{ {
Player player = member.FindPlayer(); Player player = member.FindPlayer();
if (player != null) if (player != null)
player.SendPacket(packet); members.Add(player);
} }
} }
return members;
} }
public void MassInviteToEvent(WorldSession session, uint minLevel, uint maxLevel, GuildRankOrder minRank) public void MassInviteToEvent(WorldSession session, uint minLevel, uint maxLevel, GuildRankOrder minRank)
@@ -1717,7 +1724,7 @@ namespace Game.Guilds
player.SetGuildLevel(0); player.SetGuildLevel(0);
foreach (var entry in CliDB.GuildPerkSpellsStorage.Values) foreach (var entry in CliDB.GuildPerkSpellsStorage.Values)
player.RemoveSpell(entry.SpellID, false, false); player.RemoveSpell(entry.SpellID, false, false);
} }
else else
Global.CharacterCacheStorage.UpdateCharacterGuildId(guid, 0); Global.CharacterCacheStorage.UpdateCharacterGuildId(guid, 0);
@@ -1841,7 +1848,7 @@ namespace Game.Guilds
stmt.AddValue(0, m_id); stmt.AddValue(0, m_id);
trans.Append(stmt); trans.Append(stmt);
_CreateRank(trans, Global.ObjectMgr.GetCypherString( CypherStrings.GuildMaster, loc), GuildRankRights.All); _CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildMaster, loc), GuildRankRights.All);
_CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildOfficer, loc), GuildRankRights.All); _CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildOfficer, loc), GuildRankRights.All);
_CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildVeteran, loc), GuildRankRights.GChatListen | GuildRankRights.GChatSpeak); _CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildVeteran, loc), GuildRankRights.GChatListen | GuildRankRights.GChatSpeak);
_CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildMember, loc), GuildRankRights.GChatListen | GuildRankRights.GChatSpeak); _CreateRank(trans, Global.ObjectMgr.GetCypherString(CypherStrings.GuildMember, loc), GuildRankRights.GChatListen | GuildRankRights.GChatSpeak);
@@ -2404,9 +2411,16 @@ namespace Game.Guilds
NewsLogEntry news = m_newsLog.AddEvent(trans, new NewsLogEntry(m_id, m_newsLog.GetNextGUID(), type, guid, flags, value)); NewsLogEntry news = m_newsLog.AddEvent(trans, new NewsLogEntry(m_id, m_newsLog.GetNextGUID(), type, guid, flags, value));
DB.Characters.CommitTransaction(trans); DB.Characters.CommitTransaction(trans);
GuildNewsPkt newsPacket = new(); var packetBuilder = (Player receiver) =>
news.WritePacket(newsPacket); {
BroadcastPacket(newsPacket); GuildNewsPkt newsPacket = new();
news.WritePacket(newsPacket);
newsPacket.NewsEvents.Last().CompletedDate += receiver.GetSession().GetTimezoneOffset();
receiver.SendPacket(newsPacket);
};
BroadcastWorker(packetBuilder);
} }
bool HasAchieved(uint achievementId) bool HasAchieved(uint achievementId)
@@ -2432,6 +2446,7 @@ namespace Game.Guilds
GuildNewsPkt newsPacket = new(); GuildNewsPkt newsPacket = new();
newsLog.WritePacket(newsPacket); newsLog.WritePacket(newsPacket);
newsPacket.NewsEvents.Last().CompletedDate += session.GetTimezoneOffset();
session.SendPacket(newsPacket); session.SendPacket(newsPacket);
} }
@@ -2455,6 +2470,17 @@ namespace Game.Guilds
} }
} }
public void BroadcastWorker(Action<Player> _do, Player except = null)
{
foreach (var member in m_members.Values)
{
Player player = member.FindPlayer();
if (player != null)
if (player != except)
_do.Invoke(player);
}
}
public int GetMembersCount() { return m_members.Count; } public int GetMembersCount() { return m_members.Count; }
public GuildAchievementMgr GetAchievementMgr() { return m_achievementSys; } public GuildAchievementMgr GetAchievementMgr() { return m_achievementSys; }
@@ -3077,7 +3103,7 @@ namespace Game.Guilds
GuildNewsEvent newsEvent = new(); GuildNewsEvent newsEvent = new();
newsEvent.Id = (int)GetGUID(); newsEvent.Id = (int)GetGUID();
newsEvent.MemberGuid = GetPlayerGuid(); newsEvent.MemberGuid = GetPlayerGuid();
newsEvent.CompletedDate = (uint)GetTimestamp(); newsEvent.CompletedDate.SetUtcTimeFromUnixTime(GetTimestamp());
newsEvent.Flags = GetFlags(); newsEvent.Flags = GetFlags();
newsEvent.Type = (int)GetNewsType(); newsEvent.Type = (int)GetNewsType();
@@ -3823,7 +3849,7 @@ namespace Game.Guilds
public override void LogBankEvent(SQLTransaction trans, MoveItemData pFrom, uint count) public override void LogBankEvent(SQLTransaction trans, MoveItemData pFrom, uint count)
{ {
Cypher.Assert(pFrom.GetItem() != null); Cypher.Assert(pFrom.GetItem() != null);
if (pFrom.IsBank()) if (pFrom.IsBank())
// Bank . Bank // Bank . Bank
m_pGuild._LogBankEvent(trans, GuildBankEventLogTypes.MoveItem, pFrom.GetContainer(), m_pPlayer.GetGUID().GetCounter(), m_pGuild._LogBankEvent(trans, GuildBankEventLogTypes.MoveItem, pFrom.GetContainer(), m_pPlayer.GetGUID().GetCounter(),
@@ -1,8 +1,10 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved. // Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Framework;
using Framework.Constants; using Framework.Constants;
using Game.Networking.Packets; using Game.Networking.Packets;
using System;
namespace Game namespace Game
{ {
@@ -68,11 +70,14 @@ namespace Game
public void SendSetTimeZoneInformation() public void SendSetTimeZoneInformation()
{ {
// @todo: replace dummy values TimeSpan timezoneOffset = Timezone.GetSystemZoneOffset();
string realTimezone = Timezone.GetSystemZoneName();
string clientSupportedTZ = Timezone.FindClosestClientSupportedTimezone(realTimezone, timezoneOffset);
SetTimeZoneInformation packet = new(); SetTimeZoneInformation packet = new();
packet.ServerTimeTZ = "Europe/Paris"; packet.ServerTimeTZ = clientSupportedTZ;
packet.GameTimeTZ = "Europe/Paris"; packet.GameTimeTZ = clientSupportedTZ;
packet.ServerRegionalTZ = "Europe/Paris"; packet.ServerRegionalTZ = clientSupportedTZ;
SendPacket(packet);//enabled it SendPacket(packet);//enabled it
} }
+14 -18
View File
@@ -21,10 +21,8 @@ namespace Game
{ {
ObjectGuid guid = GetPlayer().GetGUID(); ObjectGuid guid = GetPlayer().GetGUID();
long currTime = GameTime.GetGameTime();
CalendarSendCalendar packet = new(); CalendarSendCalendar packet = new();
packet.ServerTime = currTime; packet.ServerTime = GameTime.GetWowTime();
var playerInvites = Global.CalendarMgr.GetPlayerInvites(guid); var playerInvites = Global.CalendarMgr.GetPlayerInvites(guid);
foreach (var invite in playerInvites) foreach (var invite in playerInvites)
@@ -47,7 +45,8 @@ namespace Game
{ {
CalendarSendCalendarEventInfo eventInfo = new(); CalendarSendCalendarEventInfo eventInfo = new();
eventInfo.EventID = calendarEvent.EventId; eventInfo.EventID = calendarEvent.EventId;
eventInfo.Date = calendarEvent.Date; eventInfo.Date.SetUtcTimeFromUnixTime(calendarEvent.Date);
eventInfo.Date += GetTimezoneOffset();
eventInfo.EventClubID = calendarEvent.GuildId; eventInfo.EventClubID = calendarEvent.GuildId;
eventInfo.EventName = calendarEvent.Title; eventInfo.EventName = calendarEvent.Title;
eventInfo.EventType = calendarEvent.EventType; eventInfo.EventType = calendarEvent.EventType;
@@ -95,11 +94,10 @@ namespace Game
{ {
ObjectGuid guid = GetPlayer().GetGUID(); ObjectGuid guid = GetPlayer().GetGUID();
calendarAddEvent.EventInfo.Time = Time.LocalTimeToUTCTime(calendarAddEvent.EventInfo.Time); calendarAddEvent.EventInfo.Time -= GetTimezoneOffset();
// prevent events in the past // prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarAddEvent.EventInfo.Time < GameTime.GetUtcWowTime())
if (calendarAddEvent.EventInfo.Time < (GameTime.GetGameTime() - 86400L))
{ {
Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventPassed); Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventPassed);
return; return;
@@ -141,7 +139,7 @@ namespace Game
SetCalendarEventCreationCooldown(GameTime.GetGameTime() + SharedConst.CalendarCreateEventCooldown); SetCalendarEventCreationCooldown(GameTime.GetGameTime() + SharedConst.CalendarCreateEventCooldown);
CalendarEvent calendarEvent = new(Global.CalendarMgr.GetFreeEventId(), guid, 0, (CalendarEventType)calendarAddEvent.EventInfo.EventType, calendarAddEvent.EventInfo.TextureID, CalendarEvent calendarEvent = new(Global.CalendarMgr.GetFreeEventId(), guid, 0, (CalendarEventType)calendarAddEvent.EventInfo.EventType, calendarAddEvent.EventInfo.TextureID,
calendarAddEvent.EventInfo.Time, (CalendarFlags)calendarAddEvent.EventInfo.Flags, calendarAddEvent.EventInfo.Title, calendarAddEvent.EventInfo.Description, 0); calendarAddEvent.EventInfo.Time.GetUnixTimeFromUtcTime(), (CalendarFlags)calendarAddEvent.EventInfo.Flags, calendarAddEvent.EventInfo.Title, calendarAddEvent.EventInfo.Description, 0);
if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement())
calendarEvent.GuildId = _player.GetGuildId(); calendarEvent.GuildId = _player.GetGuildId();
@@ -180,11 +178,10 @@ namespace Game
ObjectGuid guid = GetPlayer().GetGUID(); ObjectGuid guid = GetPlayer().GetGUID();
long oldEventTime; long oldEventTime;
calendarUpdateEvent.EventInfo.Time = Time.LocalTimeToUTCTime(calendarUpdateEvent.EventInfo.Time); calendarUpdateEvent.EventInfo.Time -= GetTimezoneOffset();
// prevent events in the past // prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarUpdateEvent.EventInfo.Time < GameTime.GetUtcWowTime())
if (calendarUpdateEvent.EventInfo.Time < (GameTime.GetGameTime() - 86400L))
return; return;
CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarUpdateEvent.EventInfo.EventID); CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarUpdateEvent.EventInfo.EventID);
@@ -194,7 +191,7 @@ namespace Game
calendarEvent.EventType = (CalendarEventType)calendarUpdateEvent.EventInfo.EventType; calendarEvent.EventType = (CalendarEventType)calendarUpdateEvent.EventInfo.EventType;
calendarEvent.Flags = (CalendarFlags)calendarUpdateEvent.EventInfo.Flags; calendarEvent.Flags = (CalendarFlags)calendarUpdateEvent.EventInfo.Flags;
calendarEvent.Date = calendarUpdateEvent.EventInfo.Time; calendarEvent.Date = calendarUpdateEvent.EventInfo.Time.GetUnixTimeFromUtcTime();
calendarEvent.TextureId = (int)calendarUpdateEvent.EventInfo.TextureID; calendarEvent.TextureId = (int)calendarUpdateEvent.EventInfo.TextureID;
calendarEvent.Title = calendarUpdateEvent.EventInfo.Title; calendarEvent.Title = calendarUpdateEvent.EventInfo.Title;
calendarEvent.Description = calendarUpdateEvent.EventInfo.Description; calendarEvent.Description = calendarUpdateEvent.EventInfo.Description;
@@ -218,11 +215,10 @@ namespace Game
{ {
ObjectGuid guid = GetPlayer().GetGUID(); ObjectGuid guid = GetPlayer().GetGUID();
calendarCopyEvent.Date = Time.LocalTimeToUTCTime(calendarCopyEvent.Date); calendarCopyEvent.Date -= GetTimezoneOffset();
// prevent events in the past // prevent events in the past
// To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarCopyEvent.Date < GameTime.GetUtcWowTime())
if (calendarCopyEvent.Date < (GameTime.GetGameTime() - 86400L))
{ {
Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventPassed); Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventPassed);
return; return;
@@ -275,7 +271,7 @@ namespace Game
SetCalendarEventCreationCooldown(GameTime.GetGameTime() + SharedConst.CalendarCreateEventCooldown); SetCalendarEventCreationCooldown(GameTime.GetGameTime() + SharedConst.CalendarCreateEventCooldown);
CalendarEvent newEvent = new(oldEvent, Global.CalendarMgr.GetFreeEventId()); CalendarEvent newEvent = new(oldEvent, Global.CalendarMgr.GetFreeEventId());
newEvent.Date = calendarCopyEvent.Date; newEvent.Date = calendarCopyEvent.Date.GetUnixTimeFromUtcTime();
Global.CalendarMgr.AddEvent(newEvent, CalendarSendEventType.Copy); Global.CalendarMgr.AddEvent(newEvent, CalendarSendEventType.Copy);
var invites = Global.CalendarMgr.GetEventInvites(calendarCopyEvent.EventID); var invites = Global.CalendarMgr.GetEventInvites(calendarCopyEvent.EventID);
@@ -536,7 +532,7 @@ namespace Game
return; return;
CalendarRaidLockoutUpdated calendarRaidLockoutUpdated = new(); CalendarRaidLockoutUpdated calendarRaidLockoutUpdated = new();
calendarRaidLockoutUpdated.ServerTime = GameTime.GetGameTime(); calendarRaidLockoutUpdated.ServerTime = GameTime.GetWowTime();
calendarRaidLockoutUpdated.MapID = setSavedInstanceExtend.MapID; calendarRaidLockoutUpdated.MapID = setSavedInstanceExtend.MapID;
calendarRaidLockoutUpdated.DifficultyID = setSavedInstanceExtend.DifficultyID; calendarRaidLockoutUpdated.DifficultyID = setSavedInstanceExtend.DifficultyID;
calendarRaidLockoutUpdated.OldTimeRemaining = (int)Math.Max((expiryTimes.Item1 - GameTime.GetSystemTime()).TotalSeconds, 0); calendarRaidLockoutUpdated.OldTimeRemaining = (int)Math.Max((expiryTimes.Item1 - GameTime.GetSystemTime()).TotalSeconds, 0);
@@ -548,7 +544,7 @@ namespace Game
{ {
CalendarRaidLockoutAdded calendarRaidLockoutAdded = new(); CalendarRaidLockoutAdded calendarRaidLockoutAdded = new();
calendarRaidLockoutAdded.InstanceID = instanceLock.GetInstanceId(); calendarRaidLockoutAdded.InstanceID = instanceLock.GetInstanceId();
calendarRaidLockoutAdded.ServerTime = (uint)GameTime.GetGameTime(); calendarRaidLockoutAdded.ServerTime = GameTime.GetWowTime();
calendarRaidLockoutAdded.MapID = (int)instanceLock.GetMapId(); calendarRaidLockoutAdded.MapID = (int)instanceLock.GetMapId();
calendarRaidLockoutAdded.DifficultyID = instanceLock.GetDifficultyId(); calendarRaidLockoutAdded.DifficultyID = instanceLock.GetDifficultyId();
calendarRaidLockoutAdded.TimeRemaining = (int)(instanceLock.GetEffectiveExpiryTime() - GameTime.GetSystemTime()).TotalSeconds; calendarRaidLockoutAdded.TimeRemaining = (int)(instanceLock.GetEffectiveExpiryTime() - GameTime.GetSystemTime()).TotalSeconds;
+16 -3
View File
@@ -387,17 +387,30 @@ namespace Game.Maps
} }
} }
public class MessageDistDeliverer<T> : Notifier where T : IDoWork<Player> public class MessageDistDeliverer : Notifier
{ {
WorldObject i_source; WorldObject i_source;
T i_packetSender; Action<Player> i_packetSender;
PhaseShift i_phaseShift; PhaseShift i_phaseShift;
float i_distSq; float i_distSq;
Team team; Team team;
Player skipped_receiver; Player skipped_receiver;
bool required3dDist; bool required3dDist;
public MessageDistDeliverer(WorldObject src, T packetSender, float dist, bool own_team_only = false, Player skipped = null, bool req3dDist = false) public MessageDistDeliverer(WorldObject src, IDoWork<Player> packetSender, float dist, bool own_team_only = false, Player skipped = null, bool req3dDist = false)
{
i_source = src;
i_packetSender = packetSender.Invoke;
i_phaseShift = src.GetPhaseShift();
i_distSq = dist * dist;
if (own_team_only && src.IsPlayer())
team = src.ToPlayer().GetEffectiveTeam();
skipped_receiver = skipped;
required3dDist = req3dDist;
}
public MessageDistDeliverer(WorldObject src, Action<Player> packetSender, float dist, bool own_team_only = false, Player skipped = null, bool req3dDist = false)
{ {
i_source = src; i_source = src;
i_packetSender = packetSender; i_packetSender = packetSender;
@@ -60,7 +60,7 @@ namespace Game.Networking.Packets
_worldPacket.WritePackedGuid(PlayerGUID); _worldPacket.WritePackedGuid(PlayerGUID);
_worldPacket.WriteUInt32(Unused_10_1_5); _worldPacket.WriteUInt32(Unused_10_1_5);
_worldPacket.WriteUInt32(Flags); _worldPacket.WriteUInt32(Flags);
_worldPacket.WritePackedTime(CurrentTime); CurrentTime.Write(_worldPacket);
_worldPacket.WriteInt64(ElapsedTime); _worldPacket.WriteInt64(ElapsedTime);
_worldPacket.WriteInt64(CreationTime); _worldPacket.WriteInt64(CreationTime);
_worldPacket.WriteBit(RafAcceptanceID.HasValue); _worldPacket.WriteBit(RafAcceptanceID.HasValue);
@@ -75,7 +75,7 @@ namespace Game.Networking.Packets
public ObjectGuid PlayerGUID; public ObjectGuid PlayerGUID;
public uint Unused_10_1_5; public uint Unused_10_1_5;
public uint Flags; public uint Flags;
public long CurrentTime; public WowTime CurrentTime;
public long ElapsedTime; public long ElapsedTime;
public long CreationTime; public long CreationTime;
public ulong? RafAcceptanceID; public ulong? RafAcceptanceID;
@@ -128,7 +128,7 @@ namespace Game.Networking.Packets
_worldPacket.WritePackedGuid(Sender); _worldPacket.WritePackedGuid(Sender);
_worldPacket.WritePackedGuid(Earner); _worldPacket.WritePackedGuid(Earner);
_worldPacket.WriteUInt32(AchievementID); _worldPacket.WriteUInt32(AchievementID);
_worldPacket.WritePackedTime(Time); Time.Write(_worldPacket);
_worldPacket.WriteUInt32(EarnerNativeRealm); _worldPacket.WriteUInt32(EarnerNativeRealm);
_worldPacket.WriteUInt32(EarnerVirtualRealm); _worldPacket.WriteUInt32(EarnerVirtualRealm);
_worldPacket.WriteBit(Initial); _worldPacket.WriteBit(Initial);
@@ -139,7 +139,7 @@ namespace Game.Networking.Packets
public uint EarnerNativeRealm; public uint EarnerNativeRealm;
public uint EarnerVirtualRealm; public uint EarnerVirtualRealm;
public uint AchievementID; public uint AchievementID;
public long Time; public WowTime Time;
public bool Initial; public bool Initial;
public ObjectGuid Sender; public ObjectGuid Sender;
} }
@@ -176,7 +176,7 @@ namespace Game.Networking.Packets
_worldPacket.WriteUInt32(progress.CriteriaID); _worldPacket.WriteUInt32(progress.CriteriaID);
_worldPacket.WriteInt64(progress.DateCreated); _worldPacket.WriteInt64(progress.DateCreated);
_worldPacket.WriteInt64(progress.DateStarted); _worldPacket.WriteInt64(progress.DateStarted);
_worldPacket.WritePackedTime(progress.DateUpdated); progress.DateUpdated.Write(_worldPacket);
_worldPacket.WriteUInt32(0); // this is a hack. this is a packed time written as int64 (progress.DateUpdated) _worldPacket.WriteUInt32(0); // this is a hack. this is a packed time written as int64 (progress.DateUpdated)
_worldPacket.WriteUInt64(progress.Quantity); _worldPacket.WriteUInt64(progress.Quantity);
_worldPacket.WritePackedGuid(progress.PlayerGUID); _worldPacket.WritePackedGuid(progress.PlayerGUID);
@@ -222,12 +222,12 @@ namespace Game.Networking.Packets
{ {
_worldPacket.WritePackedGuid(GuildGUID); _worldPacket.WritePackedGuid(GuildGUID);
_worldPacket.WriteUInt32(AchievementID); _worldPacket.WriteUInt32(AchievementID);
_worldPacket.WritePackedTime(TimeDeleted); TimeDeleted.Write(_worldPacket);
} }
public ObjectGuid GuildGUID; public ObjectGuid GuildGUID;
public uint AchievementID; public uint AchievementID;
public long TimeDeleted; public WowTime TimeDeleted;
} }
public class GuildAchievementEarned : ServerPacket public class GuildAchievementEarned : ServerPacket
@@ -238,12 +238,12 @@ namespace Game.Networking.Packets
{ {
_worldPacket.WritePackedGuid(GuildGUID); _worldPacket.WritePackedGuid(GuildGUID);
_worldPacket.WriteUInt32(AchievementID); _worldPacket.WriteUInt32(AchievementID);
_worldPacket.WritePackedTime(TimeEarned); TimeEarned.Write(_worldPacket);
} }
public uint AchievementID; public uint AchievementID;
public ObjectGuid GuildGUID; public ObjectGuid GuildGUID;
public long TimeEarned; public WowTime TimeEarned;
} }
public class AllGuildAchievements : ServerPacket public class AllGuildAchievements : ServerPacket
@@ -301,14 +301,14 @@ namespace Game.Networking.Packets
public void Write(WorldPacket data) public void Write(WorldPacket data)
{ {
data.WriteUInt32(Id); data.WriteUInt32(Id);
data.WritePackedTime(Date); Date.Write(data);
data.WritePackedGuid(Owner); data.WritePackedGuid(Owner);
data.WriteUInt32(VirtualRealmAddress); data.WriteUInt32(VirtualRealmAddress);
data.WriteUInt32(NativeRealmAddress); data.WriteUInt32(NativeRealmAddress);
} }
public uint Id; public uint Id;
public long Date; public WowTime Date;
public ObjectGuid Owner; public ObjectGuid Owner;
public uint VirtualRealmAddress; public uint VirtualRealmAddress;
public uint NativeRealmAddress; public uint NativeRealmAddress;
@@ -323,7 +323,7 @@ namespace Game.Networking.Packets
data.WritePackedGuid(Player); data.WritePackedGuid(Player);
data.WriteUInt32(Unused_10_1_5); data.WriteUInt32(Unused_10_1_5);
data.WriteUInt32(Flags); data.WriteUInt32(Flags);
data.WritePackedTime(Date); Date.Write(data);
data.WriteInt64(TimeFromStart); data.WriteInt64(TimeFromStart);
data.WriteInt64(TimeFromCreate); data.WriteInt64(TimeFromCreate);
data.WriteBit(RafAcceptanceID.HasValue); data.WriteBit(RafAcceptanceID.HasValue);
@@ -338,7 +338,7 @@ namespace Game.Networking.Packets
public ObjectGuid Player; public ObjectGuid Player;
public uint Unused_10_1_5; public uint Unused_10_1_5;
public uint Flags; public uint Flags;
public long Date; public WowTime Date;
public long TimeFromStart; public long TimeFromStart;
public long TimeFromCreate; public long TimeFromCreate;
public ulong? RafAcceptanceID; public ulong? RafAcceptanceID;
@@ -349,7 +349,7 @@ namespace Game.Networking.Packets
public uint CriteriaID; public uint CriteriaID;
public long DateCreated; public long DateCreated;
public long DateStarted; public long DateStarted;
public long DateUpdated; public WowTime DateUpdated;
public ulong Quantity; public ulong Quantity;
public ObjectGuid PlayerGUID; public ObjectGuid PlayerGUID;
public int Unused_10_1_5; public int Unused_10_1_5;
@@ -101,13 +101,14 @@ namespace Game.Networking.Packets
EventID = _worldPacket.ReadUInt64(); EventID = _worldPacket.ReadUInt64();
ModeratorID = _worldPacket.ReadUInt64(); ModeratorID = _worldPacket.ReadUInt64();
EventClubID = _worldPacket.ReadUInt64(); EventClubID = _worldPacket.ReadUInt64();
Date = _worldPacket.ReadPackedTime(); Date = new();
Date.Read(_worldPacket);
} }
public ulong ModeratorID; public ulong ModeratorID;
public ulong EventID; public ulong EventID;
public ulong EventClubID; public ulong EventClubID;
public long Date; public WowTime Date;
} }
class CalendarInviteAdded : ServerPacket class CalendarInviteAdded : ServerPacket
@@ -122,14 +123,14 @@ namespace Game.Networking.Packets
_worldPacket.WriteUInt8(Level); _worldPacket.WriteUInt8(Level);
_worldPacket.WriteUInt8((byte)Status); _worldPacket.WriteUInt8((byte)Status);
_worldPacket.WriteUInt8(Type); _worldPacket.WriteUInt8(Type);
_worldPacket.WritePackedTime(ResponseTime); ResponseTime.Write(_worldPacket);
_worldPacket.WriteBit(ClearPending); _worldPacket.WriteBit(ClearPending);
_worldPacket.FlushBits(); _worldPacket.FlushBits();
} }
public ulong InviteID; public ulong InviteID;
public long ResponseTime; public WowTime ResponseTime;
public byte Level = 100; public byte Level = 100;
public ObjectGuid InviteGuid; public ObjectGuid InviteGuid;
public ulong EventID; public ulong EventID;
@@ -144,7 +145,7 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WritePackedTime(ServerTime); ServerTime.Write(_worldPacket);
_worldPacket.WriteInt32(Invites.Count); _worldPacket.WriteInt32(Invites.Count);
_worldPacket.WriteInt32(Events.Count); _worldPacket.WriteInt32(Events.Count);
_worldPacket.WriteInt32(RaidLockouts.Count); _worldPacket.WriteInt32(RaidLockouts.Count);
@@ -159,7 +160,7 @@ namespace Game.Networking.Packets
Event.Write(_worldPacket); Event.Write(_worldPacket);
} }
public long ServerTime; public WowTime ServerTime;
public List<CalendarSendCalendarInviteInfo> Invites = new(); public List<CalendarSendCalendarInviteInfo> Invites = new();
public List<CalendarSendCalendarRaidLockoutInfo> RaidLockouts = new(); public List<CalendarSendCalendarRaidLockoutInfo> RaidLockouts = new();
public List<CalendarSendCalendarEventInfo> Events = new(); public List<CalendarSendCalendarEventInfo> Events = new();
@@ -177,9 +178,9 @@ namespace Game.Networking.Packets
_worldPacket.WriteUInt8((byte)GetEventType); _worldPacket.WriteUInt8((byte)GetEventType);
_worldPacket.WriteInt32(TextureID); _worldPacket.WriteInt32(TextureID);
_worldPacket.WriteUInt32((uint)Flags); _worldPacket.WriteUInt32((uint)Flags);
_worldPacket.WritePackedTime(Date); Date.Write(_worldPacket);
_worldPacket.WriteUInt32((uint)LockDate); LockDate.Write(_worldPacket);
_worldPacket.WritePackedGuid(EventGuildID); _worldPacket.WriteUInt64(EventGuildID);
_worldPacket.WriteInt32(Invites.Count); _worldPacket.WriteInt32(Invites.Count);
_worldPacket.WriteBits(EventName.GetByteCount(), 8); _worldPacket.WriteBits(EventName.GetByteCount(), 8);
@@ -194,10 +195,10 @@ namespace Game.Networking.Packets
} }
public ObjectGuid OwnerGuid; public ObjectGuid OwnerGuid;
public ObjectGuid EventGuildID; public ulong EventGuildID;
public ulong EventID; public ulong EventID;
public long Date; public WowTime Date;
public long LockDate; public WowTime LockDate;
public CalendarFlags Flags; public CalendarFlags Flags;
public int TextureID; public int TextureID;
public CalendarEventType GetEventType; public CalendarEventType GetEventType;
@@ -214,11 +215,11 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WriteUInt64(EventID); _worldPacket.WriteUInt64(EventID);
_worldPacket.WritePackedTime(Date); Date.Write(_worldPacket);
_worldPacket.WriteUInt32((uint)Flags); _worldPacket.WriteUInt32((uint)Flags);
_worldPacket.WriteUInt8((byte)EventType); _worldPacket.WriteUInt8((byte)EventType);
_worldPacket.WriteInt32(TextureID); _worldPacket.WriteInt32(TextureID);
_worldPacket.WritePackedGuid(EventGuildID); _worldPacket.WriteUInt64(EventClubID);
_worldPacket.WriteUInt64(InviteID); _worldPacket.WriteUInt64(InviteID);
_worldPacket.WriteUInt8((byte)Status); _worldPacket.WriteUInt8((byte)Status);
_worldPacket.WriteUInt8((byte)ModeratorStatus); _worldPacket.WriteUInt8((byte)ModeratorStatus);
@@ -233,12 +234,12 @@ namespace Game.Networking.Packets
} }
public ObjectGuid OwnerGuid; public ObjectGuid OwnerGuid;
public ObjectGuid EventGuildID; public ulong EventClubID;
public ObjectGuid InvitedByGuid; public ObjectGuid InvitedByGuid;
public ulong InviteID; public ulong InviteID;
public ulong EventID; public ulong EventID;
public CalendarFlags Flags; public CalendarFlags Flags;
public long Date; public WowTime Date;
public int TextureID; public int TextureID;
public CalendarInviteStatus Status; public CalendarInviteStatus Status;
public CalendarEventType EventType; public CalendarEventType EventType;
@@ -295,10 +296,10 @@ namespace Game.Networking.Packets
{ {
_worldPacket.WritePackedGuid(InviteGuid); _worldPacket.WritePackedGuid(InviteGuid);
_worldPacket.WriteUInt64(EventID); _worldPacket.WriteUInt64(EventID);
_worldPacket.WritePackedTime(Date); Date.Write(_worldPacket);
_worldPacket.WriteUInt32((uint)Flags); _worldPacket.WriteUInt32((uint)Flags);
_worldPacket.WriteUInt8((byte)Status); _worldPacket.WriteUInt8((byte)Status);
_worldPacket.WritePackedTime(ResponseTime); ResponseTime.Write(_worldPacket);
_worldPacket.WriteBit(ClearPending); _worldPacket.WriteBit(ClearPending);
_worldPacket.FlushBits(); _worldPacket.FlushBits();
@@ -308,8 +309,8 @@ namespace Game.Networking.Packets
public ulong EventID; public ulong EventID;
public CalendarInviteStatus Status; public CalendarInviteStatus Status;
public bool ClearPending; public bool ClearPending;
public long ResponseTime; public WowTime ResponseTime;
public long Date; public WowTime Date;
public ObjectGuid InviteGuid; public ObjectGuid InviteGuid;
} }
@@ -360,13 +361,13 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WriteUInt64(EventID); _worldPacket.WriteUInt64(EventID);
_worldPacket.WritePackedTime(Date); Date.Write(_worldPacket);
_worldPacket.WriteUInt32((uint)Flags); _worldPacket.WriteUInt32((uint)Flags);
_worldPacket.WriteUInt8((byte)Status); _worldPacket.WriteUInt8((byte)Status);
} }
public ulong EventID; public ulong EventID;
public long Date; public WowTime Date;
public CalendarFlags Flags; public CalendarFlags Flags;
public CalendarInviteStatus Status; public CalendarInviteStatus Status;
} }
@@ -386,9 +387,9 @@ namespace Game.Networking.Packets
{ {
_worldPacket.WriteUInt64(EventID); _worldPacket.WriteUInt64(EventID);
_worldPacket.WritePackedTime(OriginalDate); OriginalDate.Write(_worldPacket);
_worldPacket.WritePackedTime(Date); Date.Write(_worldPacket);
_worldPacket.WriteUInt32((uint)LockDate); LockDate.Write(_worldPacket);
_worldPacket.WriteUInt32((uint)Flags); _worldPacket.WriteUInt32((uint)Flags);
_worldPacket.WriteInt32(TextureID); _worldPacket.WriteInt32(TextureID);
_worldPacket.WriteUInt8((byte)EventType); _worldPacket.WriteUInt8((byte)EventType);
@@ -403,10 +404,10 @@ namespace Game.Networking.Packets
} }
public ulong EventID; public ulong EventID;
public long Date; public WowTime Date;
public CalendarFlags Flags; public CalendarFlags Flags;
public long LockDate; public WowTime LockDate;
public long OriginalDate; public WowTime OriginalDate;
public int TextureID; public int TextureID;
public CalendarEventType EventType; public CalendarEventType EventType;
public bool ClearPending; public bool ClearPending;
@@ -421,14 +422,14 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WriteUInt64(EventID); _worldPacket.WriteUInt64(EventID);
_worldPacket.WritePackedTime(Date); Date.Write(_worldPacket);
_worldPacket.WriteBit(ClearPending); _worldPacket.WriteBit(ClearPending);
_worldPacket.FlushBits(); _worldPacket.FlushBits();
} }
public ulong EventID; public ulong EventID;
public long Date; public WowTime Date;
public bool ClearPending; public bool ClearPending;
} }
@@ -576,7 +577,7 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WriteUInt64(InstanceID); _worldPacket.WriteUInt64(InstanceID);
_worldPacket.WriteUInt32(ServerTime); ServerTime.Write(_worldPacket);
_worldPacket.WriteInt32(MapID); _worldPacket.WriteInt32(MapID);
_worldPacket.WriteUInt32((uint)DifficultyID); _worldPacket.WriteUInt32((uint)DifficultyID);
_worldPacket.WriteInt32(TimeRemaining); _worldPacket.WriteInt32(TimeRemaining);
@@ -585,7 +586,7 @@ namespace Game.Networking.Packets
public ulong InstanceID; public ulong InstanceID;
public Difficulty DifficultyID; public Difficulty DifficultyID;
public int TimeRemaining; public int TimeRemaining;
public uint ServerTime; public WowTime ServerTime;
public int MapID; public int MapID;
} }
@@ -611,14 +612,14 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WritePackedTime(ServerTime); ServerTime.Write(_worldPacket);
_worldPacket.WriteInt32(MapID); _worldPacket.WriteInt32(MapID);
_worldPacket.WriteUInt32(DifficultyID); _worldPacket.WriteUInt32(DifficultyID);
_worldPacket.WriteInt32(OldTimeRemaining); _worldPacket.WriteInt32(OldTimeRemaining);
_worldPacket.WriteInt32(NewTimeRemaining); _worldPacket.WriteInt32(NewTimeRemaining);
} }
public long ServerTime; public WowTime ServerTime;
public int MapID; public int MapID;
public uint DifficultyID; public uint DifficultyID;
public int NewTimeRemaining; public int NewTimeRemaining;
@@ -754,7 +755,7 @@ namespace Game.Networking.Packets
ClubId = data.ReadUInt64(); ClubId = data.ReadUInt64();
EventType = data.ReadUInt8(); EventType = data.ReadUInt8();
TextureID = data.ReadInt32(); TextureID = data.ReadInt32();
Time = data.ReadPackedTime(); Time.Read(data);
Flags = data.ReadUInt32(); Flags = data.ReadUInt32();
var InviteCount = data.ReadUInt32(); var InviteCount = data.ReadUInt32();
@@ -777,7 +778,7 @@ namespace Game.Networking.Packets
public string Description; public string Description;
public byte EventType; public byte EventType;
public int TextureID; public int TextureID;
public long Time; public WowTime Time;
public uint Flags; public uint Flags;
public CalendarAddEventInviteInfo[] Invites = new CalendarAddEventInviteInfo[(int)SharedConst.CalendarMaxInvites]; public CalendarAddEventInviteInfo[] Invites = new CalendarAddEventInviteInfo[(int)SharedConst.CalendarMaxInvites];
} }
@@ -791,7 +792,8 @@ namespace Game.Networking.Packets
ModeratorID = data.ReadUInt64(); ModeratorID = data.ReadUInt64();
EventType = data.ReadUInt8(); EventType = data.ReadUInt8();
TextureID = data.ReadUInt32(); TextureID = data.ReadUInt32();
Time = data.ReadPackedTime(); Time = new();
Time.Read(data);
Flags = data.ReadUInt32(); Flags = data.ReadUInt32();
byte titleLen = data.ReadBits<byte>(8); byte titleLen = data.ReadBits<byte>(8);
@@ -808,7 +810,7 @@ namespace Game.Networking.Packets
public string Description; public string Description;
public byte EventType; public byte EventType;
public uint TextureID; public uint TextureID;
public long Time; public WowTime Time;
public uint Flags; public uint Flags;
} }
@@ -856,7 +858,7 @@ namespace Game.Networking.Packets
{ {
data.WriteUInt64(EventID); data.WriteUInt64(EventID);
data.WriteUInt8((byte)EventType); data.WriteUInt8((byte)EventType);
data.WritePackedTime(Date); Date.Write(data);
data.WriteUInt32((uint)Flags); data.WriteUInt32((uint)Flags);
data.WriteInt32(TextureID); data.WriteInt32(TextureID);
data.WriteUInt64(EventClubID); data.WriteUInt64(EventClubID);
@@ -870,7 +872,7 @@ namespace Game.Networking.Packets
public ulong EventID; public ulong EventID;
public string EventName; public string EventName;
public CalendarEventType EventType; public CalendarEventType EventType;
public long Date; public WowTime Date;
public CalendarFlags Flags; public CalendarFlags Flags;
public int TextureID; public int TextureID;
public ulong EventClubID; public ulong EventClubID;
@@ -112,7 +112,7 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WriteInt32(NumAccounts); _worldPacket.WriteInt32(NumAccounts);
_worldPacket.WritePackedTime(CreateDate); CreateDate.Write(_worldPacket);
_worldPacket.WriteInt32(GuildFlags); _worldPacket.WriteInt32(GuildFlags);
_worldPacket.WriteInt32(MemberData.Count); _worldPacket.WriteInt32(MemberData.Count);
_worldPacket.WriteBits(WelcomeText.GetByteCount(), 11); _worldPacket.WriteBits(WelcomeText.GetByteCount(), 11);
@@ -128,7 +128,7 @@ namespace Game.Networking.Packets
public List<GuildRosterMemberData> MemberData; public List<GuildRosterMemberData> MemberData;
public string WelcomeText; public string WelcomeText;
public string InfoText; public string InfoText;
public uint CreateDate; public WowTime CreateDate;
public int NumAccounts; public int NumAccounts;
public int GuildFlags; public int GuildFlags;
} }
@@ -1765,7 +1765,7 @@ namespace Game.Networking.Packets
public void Write(WorldPacket data) public void Write(WorldPacket data)
{ {
data.WriteInt32(Id); data.WriteInt32(Id);
data.WritePackedTime(CompletedDate); CompletedDate.Write(data);
data.WriteInt32(Type); data.WriteInt32(Type);
data.WriteInt32(Flags); data.WriteInt32(Flags);
@@ -1786,7 +1786,7 @@ namespace Game.Networking.Packets
} }
public int Id; public int Id;
public uint CompletedDate; public WowTime CompletedDate;
public int Type; public int Type;
public int Flags; public int Flags;
public int[] Data = new int[2]; public int[] Data = new int[2];
@@ -62,8 +62,8 @@ namespace Game.Networking.Packets
public override void Write() public override void Write()
{ {
_worldPacket.WritePackedTime(ServerTime); ServerTime.Write(_worldPacket);
_worldPacket.WritePackedTime(GameTime); GameTime.Write(_worldPacket);
_worldPacket.WriteFloat(NewSpeed); _worldPacket.WriteFloat(NewSpeed);
_worldPacket.WriteInt32(ServerTimeHolidayOffset); _worldPacket.WriteInt32(ServerTimeHolidayOffset);
_worldPacket.WriteInt32(GameTimeHolidayOffset); _worldPacket.WriteInt32(GameTimeHolidayOffset);
@@ -71,8 +71,8 @@ namespace Game.Networking.Packets
public float NewSpeed; public float NewSpeed;
public int ServerTimeHolidayOffset; public int ServerTimeHolidayOffset;
public uint GameTime; public WowTime GameTime;
public uint ServerTime; public WowTime ServerTime;
public int GameTimeHolidayOffset; public int GameTimeHolidayOffset;
} }
@@ -164,16 +164,17 @@ namespace Game
public override void SendAllData(Player receiver) public override void SendAllData(Player receiver)
{ {
foreach (var pair in _criteriaProgress) foreach (var (id, criteriaProgres) in _criteriaProgress)
{ {
CriteriaUpdate criteriaUpdate = new(); CriteriaUpdate criteriaUpdate = new();
criteriaUpdate.CriteriaID = pair.Key; criteriaUpdate.CriteriaID = id;
criteriaUpdate.Quantity = pair.Value.Counter; criteriaUpdate.Quantity = criteriaProgres.Counter;
criteriaUpdate.PlayerGUID = _owner.GetGUID(); criteriaUpdate.PlayerGUID = _owner.GetGUID();
criteriaUpdate.Flags = 0; criteriaUpdate.Flags = 0;
criteriaUpdate.CurrentTime = pair.Value.Date; criteriaUpdate.CurrentTime.SetUtcTimeFromUnixTime(criteriaProgres.Date);
criteriaUpdate.CurrentTime += _owner.GetSession().GetTimezoneOffset();
criteriaUpdate.CreationTime = 0; criteriaUpdate.CreationTime = 0;
SendPacket(criteriaUpdate); SendPacket(criteriaUpdate);
@@ -208,7 +209,8 @@ namespace Game
if (criteria.Entry.StartTimer != 0) if (criteria.Entry.StartTimer != 0)
criteriaUpdate.Flags = timedCompleted ? 1 : 0u; // 1 is for keeping the counter at 0 in client criteriaUpdate.Flags = timedCompleted ? 1 : 0u; // 1 is for keeping the counter at 0 in client
criteriaUpdate.CurrentTime = progress.Date; criteriaUpdate.CurrentTime.SetUtcTimeFromUnixTime(progress.Date);
criteriaUpdate.CurrentTime += _owner.GetSession().GetTimezoneOffset();
criteriaUpdate.ElapsedTime = (uint)timeElapsed.TotalSeconds; criteriaUpdate.ElapsedTime = (uint)timeElapsed.TotalSeconds;
criteriaUpdate.CreationTime = 0; criteriaUpdate.CreationTime = 0;
+39 -29
View File
@@ -107,9 +107,12 @@ namespace Game.Scenarios
} }
} }
ScenarioState scenarioState = new(); DoForAllPlayers(receiver =>
BuildScenarioState(scenarioState); {
SendPacket(scenarioState); ScenarioState scenarioState = new();
BuildScenarioStateFor(receiver, scenarioState);
receiver.SendPacket(scenarioState);
});
} }
public virtual void OnPlayerEnter(Player player) public virtual void OnPlayerEnter(Player player)
@@ -153,18 +156,22 @@ namespace Game.Scenarios
public override void SendCriteriaUpdate(Criteria criteria, CriteriaProgress progress, TimeSpan timeElapsed, bool timedCompleted) public override void SendCriteriaUpdate(Criteria criteria, CriteriaProgress progress, TimeSpan timeElapsed, bool timedCompleted)
{ {
ScenarioProgressUpdate progressUpdate = new(); DoForAllPlayers(receiver =>
progressUpdate.CriteriaProgress.Id = criteria.Id; {
progressUpdate.CriteriaProgress.Quantity = progress.Counter; ScenarioProgressUpdate progressUpdate = new();
progressUpdate.CriteriaProgress.Player = progress.PlayerGUID; progressUpdate.CriteriaProgress.Id = criteria.Id;
progressUpdate.CriteriaProgress.Date = progress.Date; progressUpdate.CriteriaProgress.Quantity = progress.Counter;
if (criteria.Entry.StartTimer != 0) progressUpdate.CriteriaProgress.Player = progress.PlayerGUID;
progressUpdate.CriteriaProgress.Flags = timedCompleted ? 1 : 0u; progressUpdate.CriteriaProgress.Date.SetUtcTimeFromUnixTime(progress.Date);
progressUpdate.CriteriaProgress.Date += receiver.GetSession().GetTimezoneOffset();
if (criteria.Entry.StartTimer != 0)
progressUpdate.CriteriaProgress.Flags = timedCompleted ? 1 : 0u;
progressUpdate.CriteriaProgress.TimeFromStart = (uint)timeElapsed.TotalSeconds; progressUpdate.CriteriaProgress.TimeFromStart = (uint)timeElapsed.TotalSeconds;
progressUpdate.CriteriaProgress.TimeFromCreate = 0; progressUpdate.CriteriaProgress.TimeFromCreate = 0;
SendPacket(progressUpdate); receiver.SendPacket(progressUpdate);
});
} }
public override bool CanUpdateCriteriaTree(Criteria criteria, CriteriaTree tree, Player referencePlayer) public override bool CanUpdateCriteriaTree(Criteria criteria, CriteriaTree tree, Player referencePlayer)
@@ -226,24 +233,29 @@ namespace Game.Scenarios
return IsCompletedCriteriaTree(tree); return IsCompletedCriteriaTree(tree);
} }
public override void SendPacket(ServerPacket data) public void DoForAllPlayers(Action<Player> worker)
{ {
foreach (ObjectGuid guid in _players) foreach (ObjectGuid guid in _players)
{ {
Player player = Global.ObjAccessor.GetPlayer(_map, guid); Player player = Global.ObjAccessor.GetPlayer(_map, guid);
if (player != null) if (player != null)
player.SendPacket(data); worker(player);
} }
} }
void BuildScenarioState(ScenarioState scenarioState) public override void SendPacket(ServerPacket data)
{
DoForAllPlayers(player => player.SendPacket(data));
}
void BuildScenarioStateFor(Player player, ScenarioState scenarioState)
{ {
scenarioState.ScenarioGUID = _guid; scenarioState.ScenarioGUID = _guid;
scenarioState.ScenarioID = (int)_data.Entry.Id; scenarioState.ScenarioID = (int)_data.Entry.Id;
ScenarioStepRecord step = GetStep(); ScenarioStepRecord step = GetStep();
if (step != null) if (step != null)
scenarioState.CurrentStep = (int)step.Id; scenarioState.CurrentStep = (int)step.Id;
scenarioState.CriteriaProgress = GetCriteriasProgress(); scenarioState.CriteriaProgress = GetCriteriasProgressFor(player);
scenarioState.BonusObjectives = GetBonusObjectivesData(); scenarioState.BonusObjectives = GetBonusObjectivesData();
// Don't know exactly what this is for, but seems to contain list of scenario steps that we're either on or that are completed // Don't know exactly what this is for, but seems to contain list of scenario steps that we're either on or that are completed
foreach (var state in _stepStates) foreach (var state in _stepStates)
@@ -301,7 +313,7 @@ namespace Game.Scenarios
public void SendScenarioState(Player player) public void SendScenarioState(Player player)
{ {
ScenarioState scenarioState = new(); ScenarioState scenarioState = new();
BuildScenarioState(scenarioState); BuildScenarioStateFor(player, scenarioState);
player.SendPacket(scenarioState); player.SendPacket(scenarioState);
} }
@@ -325,21 +337,19 @@ namespace Game.Scenarios
return bonusObjectivesData; return bonusObjectivesData;
} }
List<CriteriaProgressPkt> GetCriteriasProgress() List<CriteriaProgressPkt> GetCriteriasProgressFor(Player player)
{ {
List<CriteriaProgressPkt> criteriasProgress = new(); List<CriteriaProgressPkt> criteriasProgress = new();
if (!_criteriaProgress.Empty()) foreach (var (criteriaId, progress) in _criteriaProgress)
{ {
foreach (var pair in _criteriaProgress) CriteriaProgressPkt criteriaProgress = new();
{ criteriaProgress.Id = criteriaId;
CriteriaProgressPkt criteriaProgress = new(); criteriaProgress.Quantity = progress.Counter;
criteriaProgress.Id = pair.Key; criteriaProgress.Date.SetUtcTimeFromUnixTime(progress.Date);
criteriaProgress.Quantity = pair.Value.Counter; criteriaProgress.Date += player.GetSession().GetTimezoneOffset();
criteriaProgress.Date = pair.Value.Date; criteriaProgress.Player = progress.PlayerGUID;
criteriaProgress.Player = pair.Value.PlayerGUID; criteriasProgress.Add(criteriaProgress);
criteriasProgress.Add(criteriaProgress);
}
} }
return criteriasProgress; return criteriasProgress;
+21 -1
View File
@@ -1,4 +1,8 @@
using System; // Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Framework;
using System;
public class GameTime public class GameTime
{ {
@@ -12,6 +16,9 @@ public class GameTime
static DateTime _dateTime; static DateTime _dateTime;
static WowTime UtcWow;
static WowTime Wow;
public static long GetStartTime() public static long GetStartTime()
{ {
return StartTime; return StartTime;
@@ -47,6 +54,16 @@ public class GameTime
return _dateTime; return _dateTime;
} }
public static WowTime GetUtcWowTime()
{
return UtcWow;
}
public static WowTime GetWowTime()
{
return Wow;
}
public static void UpdateGameTimers() public static void UpdateGameTimers()
{ {
_gameTime = Time.UnixTime; _gameTime = Time.UnixTime;
@@ -55,5 +72,8 @@ public class GameTime
_gameTimeSteadyPoint = DateTime.Now; _gameTimeSteadyPoint = DateTime.Now;
_dateTime = Time.UnixTimeToDateTime(_gameTime); _dateTime = Time.UnixTimeToDateTime(_gameTime);
UtcWow.SetUtcTimeFromUnixTime(_gameTime);
Wow = UtcWow + Timezone.GetSystemZoneOffsetAt(_gameTimeSystemPoint);
} }
} }
+4 -1
View File
@@ -1,4 +1,7 @@
using System; // Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using System;
namespace Game namespace Game
{ {
+235
View File
@@ -0,0 +1,235 @@
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Game.Networking;
using System;
public struct WowTime : IComparable<WowTime>
{
int _year = -1;
int _month = -1;
int _monthDay = -1;
int _weekDay = -1;
int _hour = -1;
int _minute = -1;
int _flags = -1;
int _holidayOffset = 0;
public WowTime() { }
public uint GetPackedTime()
{
return (uint)(((_year % 100) & 0x1F) << 24
| (_month & 0xF) << 20
| (_monthDay & 0x3F) << 14
| (_weekDay & 0x7) << 11
| (_hour & 0x1F) << 6
| (_minute & 0x3F)
| (_flags & 0x3) << 29);
}
public void SetPackedTime(uint packedTime)
{
_year = (int)(packedTime >> 24) & 0x1F;
if (_year == 31)
_year = -1;
_month = (int)((packedTime >> 20) & 0xF);
if (_month == 15)
_month = -1;
_monthDay = (int)((packedTime >> 14) & 0x3F);
if (_monthDay == 63)
_monthDay = -1;
_weekDay = (int)((packedTime >> 11) & 0x7);
if (_weekDay == 7)
_weekDay = -1;
_hour = (int)((packedTime >> 6) & 0x1F);
if (_hour == 31)
_hour = -1;
_minute = (int)(packedTime & 0x3F);
if (_minute == 63)
_minute = -1;
_flags = (int)((packedTime >> 29) & 0x3);
if (_flags == 3)
_flags = -1;
}
public long GetUnixTimeFromUtcTime()
{
if (_year < 0 || _month < 0 || _monthDay < 0)
return 0;
return Time.DateTimeToUnixTime(new DateTime(_year + 100, _month, _monthDay + 1, _hour, _minute, 0, DateTimeKind.Utc));
}
public void SetUtcTimeFromUnixTime(long unixTime)
{
var dateTime = Time.UnixTimeToDateTime(unixTime);
_year = (dateTime.Year - 100) % 100;
_month = dateTime.Month;
_monthDay = dateTime.Day - 1;
_weekDay = (int)dateTime.DayOfWeek;
_hour = dateTime.Hour;
_minute = dateTime.Minute;
}
public bool IsInRange(WowTime from, WowTime to)
{
if (from.CompareTo(to) > 0)
return this >= from || this < to;
return this >= from && this < to;
}
public int GetYear() { return _year; }
public void SetYear(int year)
{
Cypher.Assert(year == -1 || (year >= 0 && year < 32));
_year = year;
}
public int GetMonth() { return _month; }
public void SetMonth(int month)
{
Cypher.Assert(month == -1 || (month >= 0 && month < 12));
_month = month;
}
public int GetMonthDay() { return _monthDay; }
public void SetMonthDay(int monthDay)
{
Cypher.Assert(monthDay == -1 || (monthDay >= 0 && monthDay < 32));
_monthDay = monthDay;
}
public int GetWeekDay() { return _weekDay; }
public void SetWeekDay(int weekDay)
{
Cypher.Assert(weekDay == -1 || (weekDay >= 0 && weekDay < 7));
_weekDay = weekDay;
}
public int GetHour() { return _hour; }
public void SetHour(int hour)
{
Cypher.Assert(hour == -1 || (hour >= 0 && hour < 24));
_hour = hour;
}
public int GetMinute() { return _minute; }
public void SetMinute(int minute)
{
Cypher.Assert(minute == -1 || (minute >= 0 && minute < 60));
_minute = minute;
}
public int GetFlags() { return _flags; }
public void SetFlags(int flags)
{
Cypher.Assert(flags == -1 || (flags >= 0 && flags < 3));
_flags = flags;
}
public int GetHolidayOffset() { return _holidayOffset; }
public void SetHolidayOffset(int holidayOffset) { _holidayOffset = holidayOffset; }
public static WowTime operator +(WowTime time, TimeSpan seconds)
{
long unixTime = time.GetUnixTimeFromUtcTime();
unixTime += (long)seconds.TotalSeconds;
time.SetUtcTimeFromUnixTime(unixTime);
return time;
}
public static WowTime operator -(WowTime time, TimeSpan seconds)
{
long unixTime = time.GetUnixTimeFromUtcTime();
unixTime -= (long)seconds.TotalSeconds;
time.SetUtcTimeFromUnixTime(unixTime);
return time;
}
public void Write(WorldPacket data)
{
data.WriteUInt32(GetPackedTime());
}
public void Read(WorldPacket data)
{
uint packedTime = data.ReadPackedTime();
SetPackedTime(packedTime);
}
public int CompareTo(WowTime other)
{
var compareFieldIfSet = int (int left1, int right1) =>
{
if (left1 < 0 || right1 < 0)
return 0;
return left1.CompareTo(right1);
};
var cmp = compareFieldIfSet(_year, other._year);
if (cmp == -1)
return cmp;
cmp = compareFieldIfSet(_month, other._month);
if (cmp == -1)
return cmp;
cmp = compareFieldIfSet(_monthDay, other._monthDay);
if (cmp == -1)
return cmp;
cmp = compareFieldIfSet(_weekDay, other._weekDay);
if (cmp == -1)
return cmp;
cmp = compareFieldIfSet(_hour, other._hour);
if (cmp == -1)
return cmp;
cmp = compareFieldIfSet(_minute, other._minute);
if (cmp == -1)
return cmp;
return 0;
}
public static bool operator >=(WowTime left, WowTime right)
{
return left.CompareTo(right) >= 0;
}
public static bool operator <=(WowTime left, WowTime right)
{
return left.CompareTo(right) <= 0;
}
public static bool operator >(WowTime left, WowTime right)
{
return left.CompareTo(right) > 0;
}
public static bool operator <(WowTime left, WowTime right)
{
return left.CompareTo(right) < 0;
}
public static bool operator ==(WowTime left, WowTime right)
{
return left.CompareTo(right) == 0;
}
public static bool operator !=(WowTime left, WowTime right)
{
return left.CompareTo(right) != 0;
}
}