<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

/// <summary>
/// Server tells client that a spawn has just occurred and client should invoke the appropriate
/// hooks.
/// </summary>
public class SpawnMessage : ServerMessage
{
	public uint SpawnedObject;
	public uint ClonedFrom;

	public override void Process()
	{
		LoadMultipleObjects(new uint[] {SpawnedObject, ClonedFrom});

		if (NetworkObjects[0] == null)
		{
			Logger.LogWarning("Couldn't resolve SpawnedObject!", Category.NetMessage);
			return;
		}
		if (NetworkObjects[1] == null)
		{
			Logger.LogWarning("Couldn't resolve ClonedFrom!", Category.NetMessage);
			return;
		}

		//call all the hooks!
		var comps = NetworkObjects[0].GetComponents<IClientSpawn>();
		var spawnInfo = ClientSpawnInfo.Create(NetworkObjects[1]);
		if (comps != null)
		{
			foreach (var comp in comps)
			{
				comp.OnSpawnClient(spawnInfo);
			}
		}
	}

	/// <summary>
	/// Inform the client about this spawn event
	/// </summary>
	/// <param name="recipient">client to inform</param>
	/// <param name="result">results of the spawn that was already performed server side</param>
	/// <returns></returns>
	public static void Send(GameObject recipient, SpawnResult result)
	{
		foreach (var spawnedObject in result.GameObjects)
		{
			SpawnMessage msg = new SpawnMessage
			{
				SpawnedObject = spawnedObject.NetId(),
				ClonedFrom = result.SpawnInfo.SpawnType == SpawnType.Clone ? result.SpawnInfo.ClonedFrom.NetId() : NetId.Invalid
			};
			msg.SendTo(recipient);
		}
	}

	/// <summary>
	/// Inform all clients about this spawn event
	/// </summary>
	/// <param name="result">results of the spawn that was already performed server side</param>
	/// <returns></returns>
	public static void SendToAll(SpawnResult result)
	{
		foreach (var spawnedObject in result.GameObjects)
		{
			SpawnMessage msg = new SpawnMessage
			{
				SpawnedObject = spawnedObject.NetId(),
				ClonedFrom = result.SpawnInfo.SpawnType == SpawnType.Clone ? result.SpawnInfo.ClonedFrom.NetId() : NetId.Invalid
			};
			msg.SendToAll();
		}
	}
}<commit_msg>Fixed ClonnedFrom warning. Logs mentioned that it supposed to safe us from NRE. Can't reproduce any NREs.<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

/// <summary>
/// Server tells client that a spawn has just occurred and client should invoke the appropriate
/// hooks.
/// </summary>
public class SpawnMessage : ServerMessage
{
	public uint SpawnedObject;
	public uint ClonedFrom;

	public override void Process()
	{
		LoadMultipleObjects(new uint[] {SpawnedObject, ClonedFrom});

		if (NetworkObjects[0] == null)
		{
			Logger.LogWarning("Couldn't resolve SpawnedObject!", Category.NetMessage);
			return;
		}

		//call all the hooks!
		var comps = NetworkObjects[0].GetComponents<IClientSpawn>();
		var spawnInfo = ClientSpawnInfo.Create(NetworkObjects[1]);
		if (comps != null)
		{
			foreach (var comp in comps)
			{
				comp.OnSpawnClient(spawnInfo);
			}
		}
	}

	/// <summary>
	/// Inform the client about this spawn event
	/// </summary>
	/// <param name="recipient">client to inform</param>
	/// <param name="result">results of the spawn that was already performed server side</param>
	/// <returns></returns>
	public static void Send(GameObject recipient, SpawnResult result)
	{
		foreach (var spawnedObject in result.GameObjects)
		{
			SpawnMessage msg = new SpawnMessage
			{
				SpawnedObject = spawnedObject.NetId(),
				ClonedFrom = result.SpawnInfo.SpawnType == SpawnType.Clone ? result.SpawnInfo.ClonedFrom.NetId() : NetId.Invalid
			};
			msg.SendTo(recipient);
		}
	}

	/// <summary>
	/// Inform all clients about this spawn event
	/// </summary>
	/// <param name="result">results of the spawn that was already performed server side</param>
	/// <returns></returns>
	public static void SendToAll(SpawnResult result)
	{
		foreach (var spawnedObject in result.GameObjects)
		{
			SpawnMessage msg = new SpawnMessage
			{
				SpawnedObject = spawnedObject.NetId(),
				ClonedFrom = result.SpawnInfo.SpawnType == SpawnType.Clone ? result.SpawnInfo.ClonedFrom.NetId() : NetId.Invalid
			};
			msg.SendToAll();
		}
	}
}
{'fraction_non_alphanumeric': 0.12260807937632884, 'fraction_numerical': 0.001653673517599811, 'mean_word_length': 3.795016987542469, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '7485227', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1348, 'n_words': 350}