/// <summary> /// Handles the specified <see cref="Message"/>. /// </summary> /// <param name="Device">The device.</param> /// <param name="Message">The message.</param> /// <param name="Cancellation">The cancellation.</param> public static async Task Handle(Device Device, Message Message, CancellationToken Cancellation) { var AskForTvContentMessage = (AskForTvContentMessage)Message; if (AskForTvContentMessage == null) { throw new LogicException(typeof(AskForTvContentHandler), nameof(AskForTvContentMessage) + " == null at Handle(Device, Message, CancellationToken)."); } int ChannelId = RoyalTvManager.GetChannelArenaData(AskForTvContentMessage.ArenaData); if (ChannelId == -1) { throw new LogicException(typeof(AskForTvContentHandler), "ChannelId == -1 at Handle(Device, Message, CancellationToken)."); } var Channel = RoyalTvManager.Channels[ChannelId]; if (Channel == null) { throw new LogicException(typeof(AskForTvContentHandler), "Channel == null at Handle(Device, Message, CancellationToken)."); } var RoyalTv = Channel.ToArray(); Device.NetworkManager.SendMessage(new RoyalTvContentMessage(RoyalTv, AskForTvContentMessage.ArenaData)); }
/// <summary> /// Adds the specified replay to royal tv. /// </summary> public static void AddReplayToRoyalTv(BattleLog BattleLog) { int ChannelIdx = RoyalTvManager.GetChannelArenaData(BattleLog.ArenaData); if (ChannelIdx != -1) { RoyalTvManager.AddEntry(ChannelIdx, new RoyalTvEntry(BattleLog)); } }
/// <summary> /// Handles the specified <see cref="Message"/>. /// </summary> /// <param name="Device">The device.</param> /// <param name="Message">The message.</param> /// <param name="Cancellation">The cancellation.</param> public static async Task Handle(Device Device, Message Message, CancellationToken Cancellation) { var HomeBattleReplayMessage = (HomeBattleReplayMessage)Message; if (HomeBattleReplayMessage == null) { throw new LogicException(typeof(HomeBattleReplayHandler), nameof(HomeBattleReplayMessage) + " == null at Handle(Device, Message, CancellationToken)."); } if (!HomeBattleReplayMessage.ReplayId.IsZero) { BattleLog BattleLog = await Battles.Get(HomeBattleReplayMessage.ReplayId.HigherInt, HomeBattleReplayMessage.ReplayId.LowerInt); if (BattleLog != null) { int ChannelIdx = RoyalTvManager.GetChannelArenaData(HomeBattleReplayMessage.ArenaData); if (ChannelIdx != -1) { RoyalTvEntry TvEntry = RoyalTvManager.GetEntryByIdx(ChannelIdx, HomeBattleReplayMessage.ReplayShardId); if (TvEntry != null) { Interlocked.Increment(ref TvEntry.ViewCount); } } byte[] Decompressed = Encoding.UTF8.GetBytes(BattleLog.ReplayJson); byte[] Compressed = ZLibHelper.CompressCompressableByteArray(Decompressed); Device.NetworkManager.SendMessage(new HomeBattleReplayDataMessage(Compressed)); } else { Logging.Info(typeof(HomeBattleReplayHandler), "BattleLog == null at Handle(Device, Message, CancellationToken)."); } } else { Logging.Info(typeof(HomeBattleReplayHandler), "ReplayId.IsZero == true at Handle(Device, Message, CancellationToken)."); } }
/// <summary> /// Defines the entry point of the application. /// </summary> internal static void Main() { Base.Initialize(); GameDb.Initialize(); Devices.Initialize(); Players.Initialize(); Clans.Initialize(); Battles.Initialize(); Leaderboards.Initialize(); InboxManager.Initialize(); EventManager.Initialize(); BattleManager.Initialize(); RoyalTvManager.Initialize(); HandlerFactory.Initialize(); NetworkTcp.Initialize(); Program.Initialized = true; Console.CancelKeyPress += ConsoleOnCancelKeyPress; CommandLine.Initialize(); }