<commit_before>﻿using PolarisServer.Database;
using PolarisServer.Models;
using PolarisServer.Object;
using PolarisServer.Packets.PSOPackets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PolarisServer.Packets.Handlers
{
    [PacketHandlerAttr(0x4, 0x14)]
    class ObjectInteract : PacketHandler
    {
        public override void HandlePacket(Client context, byte[] data, uint position, uint size)
        {
            PacketReader reader = new PacketReader(data);
            reader.ReadBytes(12); // Padding MAYBE???????????
            EntityHeader srcObject = reader.ReadStruct<EntityHeader>();
            byte[] someBytes = reader.ReadBytes(4); // Dunno what this is yet.
            EntityHeader dstObject = reader.ReadStruct<EntityHeader>(); // Could be wrong
            reader.ReadBytes(16); // Not sure what this is yet
            string command = reader.ReadAscii(0xD711, 0xCA);
            PSOObject srcObj;
            if(srcObject.EntityType == EntityType.Object)
            {
                srcObj = ObjectManager.Instance.getObjectByID(context.CurrentZone, srcObject.ID);
            }
            else if(srcObject.EntityType == EntityType.Player)
            {
                srcObj = new PSOObject();
                srcObj.Header = srcObject;
                srcObj.Name = "Player";
            }
            else
            {
                srcObj = null;
            }

            Logger.WriteInternal("[OBJ] {0} (ID {1}) <{2}> --> Ent {3} (ID {4})", srcObj.Name, srcObj.Header.ID, command, (EntityType)dstObject.EntityType, dstObject.ID);

            // TODO: Delete this code and do this COMPLETELY correctly!!!
            if (command == "Transfer" && context.CurrentZone == "lobby")
            {
                // Try and get the teleport definition for the object...
                using (var db = new PolarisEf())
                {
                    db.Configuration.AutoDetectChangesEnabled = true;
                    var teleporterEndpoint = db.Teleports.Find("lobby", (int)srcObject.ID);

                    if (teleporterEndpoint == null)
                    {
                        Logger.WriteError("[OBJ] Teleporter for {0} in {1} does not contain a destination!", srcObj.Header.ID, "lobby");
                        // Teleport Player to default point
                        context.SendPacket(new TeleportTransferPacket(srcObj, new PSOLocation(0f, 1f, 0f, -0.000031f, -0.417969f, 0.000031f, 134.375f)));
                        // Unhide player
                        context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new EntityHeader(), new EntityHeader(), "Forwarded"));
                    }
                    else
                    {
                        PSOLocation endpointLocation = new PSOLocation()
                        {
                            RotX = teleporterEndpoint.RotX,
                            RotY = teleporterEndpoint.RotY,
                            RotZ = teleporterEndpoint.RotZ,
                            RotW = teleporterEndpoint.RotW,
                            PosX = teleporterEndpoint.PosX,
                            PosY = teleporterEndpoint.PosY,
                            PosZ = teleporterEndpoint.PosZ,
                        };
                        // Teleport Player
                        context.SendPacket(new TeleportTransferPacket(srcObj, endpointLocation));
                        // Unhide player
                        context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new EntityHeader(), new EntityHeader(), "Forwarded")); 
                    }
                }
            }
        }
    }

}<commit_msg>Respond to the NPC ready request. As usual, this isn't the 100% right way to do this.<commit_after>﻿using PolarisServer.Database;
using PolarisServer.Models;
using PolarisServer.Object;
using PolarisServer.Packets.PSOPackets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PolarisServer.Packets.Handlers
{
    [PacketHandlerAttr(0x4, 0x14)]
    class ObjectInteract : PacketHandler
    {
        public override void HandlePacket(Client context, byte[] data, uint position, uint size)
        {
            PacketReader reader = new PacketReader(data);
            reader.ReadBytes(12); // Padding MAYBE???????????
            EntityHeader srcObject = reader.ReadStruct<EntityHeader>();
            byte[] someBytes = reader.ReadBytes(4); // Dunno what this is yet.
            EntityHeader dstObject = reader.ReadStruct<EntityHeader>(); // Could be wrong
            reader.ReadBytes(16); // Not sure what this is yet
            string command = reader.ReadAscii(0xD711, 0xCA);
            PSOObject srcObj;
            if(srcObject.EntityType == EntityType.Object)
            {
                srcObj = ObjectManager.Instance.getObjectByID(context.CurrentZone, srcObject.ID);
            }
            else if(srcObject.EntityType == EntityType.Player)
            {
                srcObj = new PSOObject();
                srcObj.Header = srcObject;
                srcObj.Name = "Player";
            }
            else
            {
                srcObj = null;
            }

            Logger.WriteInternal("[OBJ] {0} (ID {1}) <{2}> --> Ent {3} (ID {4})", srcObj.Name, srcObj.Header.ID, command, (EntityType)dstObject.EntityType, dstObject.ID);

            // TODO: Delete this code and do this COMPLETELY correctly!!!
            if (command == "Transfer" && context.CurrentZone == "lobby")
            {
                // Try and get the teleport definition for the object...
                using (var db = new PolarisEf())
                {
                    db.Configuration.AutoDetectChangesEnabled = true;
                    var teleporterEndpoint = db.Teleports.Find("lobby", (int)srcObject.ID);

                    if (teleporterEndpoint == null)
                    {
                        Logger.WriteError("[OBJ] Teleporter for {0} in {1} does not contain a destination!", srcObj.Header.ID, "lobby");
                        // Teleport Player to default point
                        context.SendPacket(new TeleportTransferPacket(srcObj, new PSOLocation(0f, 1f, 0f, -0.000031f, -0.417969f, 0.000031f, 134.375f)));
                        // Unhide player
                        context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new EntityHeader(), new EntityHeader(), "Forwarded"));
                    }
                    else
                    {
                        PSOLocation endpointLocation = new PSOLocation()
                        {
                            RotX = teleporterEndpoint.RotX,
                            RotY = teleporterEndpoint.RotY,
                            RotZ = teleporterEndpoint.RotZ,
                            RotW = teleporterEndpoint.RotW,
                            PosX = teleporterEndpoint.PosX,
                            PosY = teleporterEndpoint.PosY,
                            PosZ = teleporterEndpoint.PosZ,
                        };
                        // Teleport Player
                        context.SendPacket(new TeleportTransferPacket(srcObj, endpointLocation));
                        // Unhide player
                        context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new EntityHeader(), new EntityHeader(), "Forwarded")); 
                    }
                }
            }

            if (command == "READY" && context.CurrentZone == "lobby")
            {
                context.SendPacket(new ObjectActionPacket(new EntityHeader((ulong)context.User.PlayerId, EntityType.Player), srcObj.Header, srcObj.Header,
                    new EntityHeader(), "FavsNeutral"));
                context.SendPacket(new ObjectActionPacket(new EntityHeader((ulong)context.User.PlayerId, EntityType.Player), srcObj.Header, srcObj.Header,
                    new EntityHeader(), "AP")); // Short for Appear, Thanks Zapero!
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.09643034209221617, 'fraction_numerical': 0.013262270699058007, 'mean_word_length': 1.6138645934564302, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1684003', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1948, 'n_words': 468}