<commit_before><?php

/**
 * PHPInSimMod - Packet Module
 * @package PRISM
 * @subpackage Packet
 */

/* Start of PRISM PACKET HEADER */
abstract class struct
{
	public function __construct($rawPacket = NULL)
	{
		if ($rawPacket !== NULL)
			$this->unpack($rawPacket);
	}
	public function __invoke()
	{
		$argv = func_get_args();
		$argi = 0;
		$argc = count($argv);
		foreach ($this as $property => $value)
		{
			$RP = new ReflectionProperty(get_class($this), $property);
			if ($RP->isPublic())
				$object->$property = $argv[$argi++];
			if ($argc == $argi)
				continue;
		}
	}
	public function __toString()
	{
		return $this->printPacketDetails();
	}
	// Magic Methods (Object Overloading)
	public function &__get($name)
	{
		if (!property_exists(get_class($this), $name))
			return FALSE;
		else
			return $this->$name;
	}
	public function &__call($name, $arguments)
	{
		if (property_exists(get_class($this), $name))
			$this->$name = array_shift($arguments);
		return $this;
	}
	public function __isset($name)
	{
		return isset($this->$name);
	}
	public function __unset($name)
	{
		if (isset($this->$name))
			$this->$name = NULL;
	}
	// Normal Methods
	public function send($hostId = NULL)
	{
		global $PRISM;
		$PRISM->hosts->sendPacket($this, $hostId);
	}
	public function printPacketDetails($pre = '')
	{
		global $TYPEs;
		$packFormat = $this->parsePackFormat();
		$propertyNumber = -1;
		$str = $pre . get_class($this) . ' {' . PHP_EOL;
		foreach ($this as $property => $value)
		{
			$pkFnkFormat = $packFormat[++$propertyNumber];
			if (gettype($this->$property) == 'array')
			{
				$str .= "{$pre}\tArray\t{$property}\t= {" . PHP_EOL;
				foreach ($this->$property as $k => $v)
				{
					if ($v instanceof struct)
					{
						$str .= $pre . $v->printPacketDetails($pre . "\t\t\t") . PHP_EOL;
					}
					else
					{
						$str .= "{$pre}\t\t\t{$k}\t{$v}" . PHP_EOL;
					}
				}
				$str .= "{$pre}\t}" . PHP_EOL;
				break;
			}
			elseif ($property == 'Type')
			{
				$str .= "{$pre}\t{$pkFnkFormat}\t{$property}\t= {$TYPEs[$this->Type]} ({$this->$property})" . PHP_EOL;
			}
			else
			{
				$str .= "{$pre}\t{$pkFnkFormat}\t{$property}\t= {$this->$property}" . PHP_EOL;
			}
		}
		return "{$str}{$pre}}" . PHP_EOL;
	}
	public function unpack($rawPacket)
	{
		foreach (unpack($this::UNPACK, $rawPacket) as $property => $value)
		{
			$this->$property = $value;
		}

		return $this;
	}
	public function pack()
	{
		# Message Packets
		if (($this instanceof IS_MST || $this instanceof IS_MTC) && ($strLen = strLen($this->Msg)) >= 64)
		{
			for ($Msg = $this->Msg, $start = 0; $start < $strLen; $start += 63)
				$this->Msg(subStr($Msg, $start, 63))->Send();
		}
		if ($this instanceof IS_MSX && strLen($this->Msg) >= 96)
			$this->Msg = subStr($this->Msg, 0, 92) . '...';
		if ($this instanceof IS_MSL && strLen($this->Msg) >= 128)
			$this->Msg = subStr($this->Msg, 0, 124) . '...';
		# Button Packets
		if ($this instanceof IS_BTN && strLen($this->Text) >= 240)
			$this->Text = subStr($this->Msg, 0, 236) . '...';

		$return = '';
		$packFormat = $this->parsePackFormat();
		$propertyNumber = -1;<commit_msg>Smartly splits words over muliple messages packets as needed, to ensure that the whole message get's across.<commit_after><?php

/**
 * PHPInSimMod - Packet Module
 * @package PRISM
 * @subpackage Packet
 */

/* Start of PRISM PACKET HEADER */
abstract class struct
{
	public function __construct($rawPacket = NULL)
	{
		if ($rawPacket !== NULL)
			$this->unpack($rawPacket);
	}
	public function __invoke()
	{
		$argv = func_get_args();
		$argi = 0;
		$argc = count($argv);
		foreach ($this as $property => $value)
		{
			$RP = new ReflectionProperty(get_class($this), $property);
			if ($RP->isPublic())
				$object->$property = $argv[$argi++];
			if ($argc == $argi)
				continue;
		}
	}
	public function __toString()
	{
		return $this->printPacketDetails();
	}
	// Magic Methods (Object Overloading)
	public function &__get($name)
	{
		if (!property_exists(get_class($this), $name))
			return FALSE;
		else
			return $this->$name;
	}
	public function &__call($name, $arguments)
	{
		if (property_exists(get_class($this), $name))
			$this->$name = array_shift($arguments);
		return $this;
	}
	public function __isset($name)
	{
		return isset($this->$name);
	}
	public function __unset($name)
	{
		if (isset($this->$name))
			$this->$name = NULL;
	}
	// Normal Methods
	public function send($hostId = NULL)
	{
		global $PRISM;
		$PRISM->hosts->sendPacket($this, $hostId);
	}
	public function printPacketDetails($pre = '')
	{
		global $TYPEs;
		$packFormat = $this->parsePackFormat();
		$propertyNumber = -1;
		$str = $pre . get_class($this) . ' {' . PHP_EOL;
		foreach ($this as $property => $value)
		{
			$pkFnkFormat = $packFormat[++$propertyNumber];
			if (gettype($this->$property) == 'array')
			{
				$str .= "{$pre}\tArray\t{$property}\t= {" . PHP_EOL;
				foreach ($this->$property as $k => $v)
				{
					if ($v instanceof struct)
					{
						$str .= $pre . $v->printPacketDetails($pre . "\t\t\t") . PHP_EOL;
					}
					else
					{
						$str .= "{$pre}\t\t\t{$k}\t{$v}" . PHP_EOL;
					}
				}
				$str .= "{$pre}\t}" . PHP_EOL;
				break;
			}
			elseif ($property == 'Type')
			{
				$str .= "{$pre}\t{$pkFnkFormat}\t{$property}\t= {$TYPEs[$this->Type]} ({$this->$property})" . PHP_EOL;
			}
			else
			{
				$str .= "{$pre}\t{$pkFnkFormat}\t{$property}\t= {$this->$property}" . PHP_EOL;
			}
		}
		return "{$str}{$pre}}" . PHP_EOL;
	}
	public function unpack($rawPacket)
	{
		foreach (unpack($this::UNPACK, $rawPacket) as $property => $value)
		{
			$this->$property = $value;
		}

		return $this;
	}
	public function pack()
	{
		# Message Packets
		if (($this instanceof IS_MST || $this instanceof IS_MTC) && strLen($this->Msg) >= 64)
		{
			foreach(explode("\n", wordwrap($this->Msg, 63, "\n", TRUE)) as $Msg)
				$this->Msg($Msg)->Send();
			return;
		}
		if ($this instanceof IS_MSX && strLen($this->Msg) >= 96)
		{
			foreach(explode("\n", wordwrap($this->Msg, 95, "\n", TRUE)) as $Msg)
				$this->Msg($Msg)->Send();
			return;
		}
		if ($this instanceof IS_MSL && strLen($this->Msg) >= 128)
		{
			foreach(explode("\n", wordwrap($this->Msg, 127, "\n", TRUE)) as $Msg)
				$this->Msg($Msg)->Send();
			return;
		}
		# Button Packets
		if ($this instanceof IS_BTN && strLen($this->Text) >= 240)
			$this->Text = subStr($this->Msg, 0, 236) . '...';

		$return = '';
		$packFormat = $this->parsePackFormat();
		$propertyNumber = -1;
{'fraction_non_alphanumeric': 0.2070294435023894, 'fraction_numerical': 0.008170186526899954, 'mean_word_length': 3.291005291005291, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 87, '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': '6168733', 'n_tokens_mistral': 2809, 'n_tokens_neox': 2421, 'n_words': 509}