<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Logging;
using Guardians;
using UnityEngine;

namespace Booma.Proxy
{
	//TODO: This is kinda copy-paste of LobbyEnteredAreaWarpedEventListener, can we do anything better here?? 
	//This is basically the same as LobbyEnteredAreaWarpedEventListener
	//Lobby handles this simply and specificly compared to the Game
	//In Lobby it should only really mean that they're now fully init
	//and ready for physical world object initialization.
	[SceneTypeCreate(GameSceneType.Pioneer2)]
	[SceneTypeCreate(GameSceneType.LobbyDefault)]
	public sealed class LobbyRemotePlayerWarpAckedSpawnEventListener : BaseSingleEventListenerInitializable<IRemoteClientAcknowledgedWarpEventSubscribable, RemotePlayerWarpAcknowledgementEventArgs>
	{
		private IZoneSettings ZoneSettings { get; }

		private ILog Logger { get; }

		private IFactoryCreatable<GameObject, RemotePlayerWorldRepresentationCreationContext> RemotePlayerFactory { get; }

		private IReadonlyEntityGuidMappable<PlayerZoneData> ZoneDataMappable { get; }

		/// <inheritdoc />
		public LobbyRemotePlayerWarpAckedSpawnEventListener(
			IRemoteClientAcknowledgedWarpEventSubscribable subscriptionService, 
			[NotNull] IZoneSettings zoneSettings, 
			[NotNull] ILog logger, 
			[NotNull] IFactoryCreatable<GameObject, RemotePlayerWorldRepresentationCreationContext> remotePlayerFactory, 
			IReadonlyEntityGuidMappable<PlayerZoneData> zoneDataMappable) 
			: base(subscriptionService)
		{
			ZoneSettings = zoneSettings ?? throw new ArgumentNullException(nameof(zoneSettings));
			Logger = logger ?? throw new ArgumentNullException(nameof(logger));
			RemotePlayerFactory = remotePlayerFactory ?? throw new ArgumentNullException(nameof(remotePlayerFactory));
			ZoneDataMappable = zoneDataMappable;
		}

		/// <inheritdoc />
		protected override void OnEventFired(object source, RemotePlayerWarpAcknowledgementEventArgs args)
		{
			//We should never call this event unless we have zone data. It would make no sense.
			if(ZoneSettings.ZoneId != ZoneDataMappable[args.EntityGuid].ZoneId)
				if(Logger.IsWarnEnabled)
					Logger.Warn($"Encountered warped player in Lobby not in the same zone. Current: {ZoneSettings.ZoneId} Remote: {ZoneDataMappable[args.EntityGuid].ZoneId}. This should only happen if they are cheating.");

			//If the zone id is the same as the current local zone
			//then we should create a world representation for the player.
			RemotePlayerFactory.Create(new RemotePlayerWorldRepresentationCreationContext(args.EntityGuid));<commit_msg>Made LobbyRemotePlayerWarpAckedSpawn work in Games<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Logging;
using Guardians;
using UnityEngine;

namespace Booma.Proxy
{
	//TODO: This is kinda copy-paste of LobbyEnteredAreaWarpedEventListener, can we do anything better here?? 
	//This is basically the same as LobbyEnteredAreaWarpedEventListener
	//Lobby handles this simply and specificly compared to the Game
	//In Lobby it should only really mean that they're now fully init
	//and ready for physical world object initialization.
	[SceneTypeCreate(GameSceneType.Pioneer2)]
	[SceneTypeCreate(GameSceneType.LobbyDefault)]
	public sealed class LobbyRemotePlayerWarpAckedSpawnEventListener : BaseSingleEventListenerInitializable<IRemoteClientAcknowledgedWarpEventSubscribable, RemotePlayerWarpAcknowledgementEventArgs>
	{
		private IZoneSettings ZoneSettings { get; }

		private ILog Logger { get; }

		private IFactoryCreatable<GameObject, RemotePlayerWorldRepresentationCreationContext> RemotePlayerFactory { get; }

		private IReadonlyEntityGuidMappable<PlayerZoneData> ZoneDataMappable { get; }

		/// <inheritdoc />
		public LobbyRemotePlayerWarpAckedSpawnEventListener(
			IRemoteClientAcknowledgedWarpEventSubscribable subscriptionService, 
			[NotNull] IZoneSettings zoneSettings, 
			[NotNull] ILog logger, 
			[NotNull] IFactoryCreatable<GameObject, RemotePlayerWorldRepresentationCreationContext> remotePlayerFactory, 
			IReadonlyEntityGuidMappable<PlayerZoneData> zoneDataMappable) 
			: base(subscriptionService)
		{
			ZoneSettings = zoneSettings ?? throw new ArgumentNullException(nameof(zoneSettings));
			Logger = logger ?? throw new ArgumentNullException(nameof(logger));
			RemotePlayerFactory = remotePlayerFactory ?? throw new ArgumentNullException(nameof(remotePlayerFactory));
			ZoneDataMappable = zoneDataMappable;
		}

		/// <inheritdoc />
		protected override void OnEventFired(object source, RemotePlayerWarpAcknowledgementEventArgs args)
		{
			//We should never call this event unless we have zone data. It would make no sense.
			//Also, this case is very possible in games. They can Ack that they saw our warp. That they are now Forest or
			//something and we're in Caves or Pioneer. We should NOT create a visible/world representation of a
			//remote player that acked on a different zone.
			if(ZoneSettings.ZoneId != ZoneDataMappable[args.EntityGuid].ZoneId)
			{
				if(Logger.IsInfoEnabled)
					Logger.Info($"Encountered warped player {args.EntityGuid} not in the same zone. Current: {ZoneSettings.ZoneId} Remote: {ZoneDataMappable[args.EntityGuid].ZoneId}.");

				return;
			}

			//If the zone id is the same as the current local zone
			//then we should create a world representation for the player.
			RemotePlayerFactory.Create(new RemotePlayerWorldRepresentationCreationContext(args.EntityGuid));
{'fraction_non_alphanumeric': 0.06874328678839957, 'fraction_numerical': 0.00035803795202291446, 'mean_word_length': 5.747584541062802, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945906', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1506, 'n_words': 441}