public void doWarp(ConnectedPlayer client, uint zoneId, string privateArea, byte spawnType, float x, float y, float z, float r)
        {
            WorldManager worldManager = Server.GetWorldManager();

            if (worldManager.GetZone(zoneId) == null)
            {
                if (client != null)
                {
                    client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "Zone does not exist or setting isn't valid."), true, false));
                }
                Log.error("Zone does not exist or setting isn't valid.");
            }

            if (client != null)
            {
                worldManager.DoZoneChange(client.getActor(), zoneId, privateArea, spawnType, x, y, z, r);
            }
            else
            {
                foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
                {
                    worldManager.DoZoneChange(entry.Value.getActor(), zoneId, privateArea, spawnType, x, y, z, r);
                }
            }
        }
 /// <summary>
 /// We only use the default options for SendMessagePacket.
 /// May as well make it less unwieldly to view
 /// </summary>
 /// <param name="client"></param>
 /// <param name="message"></param>
 private void sendMessage(ConnectedPlayer client, String message)
 {
     if (client != null)
     {
         client.getActor().queuePacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", message));
     }
 }
 private void removeKeyItem(ConnectedPlayer client, uint itemId)
 {
     if (client != null)
     {
         Player p = client.getActor();
         p.getInventory(Inventory.KEYITEMS).removeItem(itemId, 1);
     }
     else
     {
         foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
         {
             Player p = entry.Value.getActor();
             p.getInventory(Inventory.KEYITEMS).removeItem(itemId, 1);
         }
     }
 }
 // TODO:  make removeCurrency() remove all quantity of a currency if quantity_to_remove > quantity_in_inventory instead of silently failing
 private void removeCurrency(ConnectedPlayer client, uint itemId, int quantity)
 {
     if (client != null)
     {
         Player p = client.getActor();
         p.getInventory(Inventory.CURRENCY).removeItem(itemId, quantity);
     }
     else
     {
         foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
         {
             Player p = entry.Value.getActor();
             p.getInventory(Inventory.CURRENCY).removeItem(itemId, quantity);
         }
     }
 }
 private void giveItem(ConnectedPlayer client, uint itemId, int quantity)
 {
     if (client != null)
     {
         Player p = client.getActor();
         p.getInventory(Inventory.NORMAL).addItem(itemId, quantity);
     }
     else
     {
         foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
         {
             Player p = entry.Value.getActor();
             p.getInventory(Inventory.NORMAL).addItem(itemId, quantity);
         }
     }
 }
 public void printPos(ConnectedPlayer client)
 {
     if (client != null)
     {
         Player p = client.getActor();
         client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", String.Format("{0}\'s position: ZoneID: {1}, X: {2}, Y: {3}, Z: {4}, Rotation: {5}", p.customDisplayName, p.zoneId, p.positionX, p.positionY, p.positionZ, p.rotation)), true, false));
     }
     else
     {
         foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
         {
             Player p = entry.Value.getActor();
             Log.info(String.Format("{0}\'s position: ZoneID: {1}, X: {2}, Y: {3}, Z: {4}, Rotation: {5}", p.customDisplayName, p.zoneId, p.positionX, p.positionY, p.positionZ, p.rotation));
         }
     }
 }
 private void setGraphic(ConnectedPlayer client, uint slot, uint wId, uint eId, uint vId, uint cId)
 {
     if (client != null)
     {
         Player p = client.getActor();
         p.graphicChange(slot, wId, eId, vId, cId);
         p.sendAppearance();
     }
     else
     {
         foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
         {
             Player p = entry.Value.getActor();
             p.graphicChange(slot, wId, eId, vId, cId);
             p.sendAppearance();
         }
     }
 }
        /// <summary>
        /// Teleports player to a location on a predefined list
        /// </summary>
        /// <param name="client">The current player</param>
        /// <param name="id">Predefined list: &lt;ffxiv_database&gt;\server_zones_spawnlocations</param>
        public void doWarp(ConnectedPlayer client, uint id)
        {
            WorldManager worldManager = Server.GetWorldManager();

            FFXIVClassic_Map_Server.WorldManager.ZoneEntrance ze = worldManager.getZoneEntrance(id);

            if (ze == null)
            {
                return;
            }

            if (client != null)
            {
                worldManager.DoZoneChange(client.getActor(), ze.zoneId, ze.privateAreaName, ze.spawnType, ze.spawnX, ze.spawnY, ze.spawnZ, ze.spawnRotation);
            }
            else
            {
                foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
                {
                    worldManager.DoZoneChange(entry.Value.getActor(), ze.zoneId, ze.privateAreaName, ze.spawnType, ze.spawnX, ze.spawnY, ze.spawnZ, ze.spawnRotation);
                }
            }
        }
        private void removeItem(ConnectedPlayer client, uint itemId, int quantity, ushort type)
        {
            if (client != null)
            {
                Player p = client.getActor();

                if (p.getInventory(type) != null)
                {
                    p.getInventory(type).removeItem(itemId, quantity);
                }
            }
            else
            {
                foreach (KeyValuePair <uint, ConnectedPlayer> entry in mConnectedPlayerList)
                {
                    Player p = entry.Value.getActor();

                    if (p.getInventory(type) != null)
                    {
                        p.getInventory(type).removeItem(itemId, quantity);
                    }
                }
            }
        }
        internal bool doCommand(string input, ConnectedPlayer client)
        {
            input.Trim();
            if (input.StartsWith("!"))
            {
                input = input.Substring(1);
            }

            String[] split = input.Split(' ');
            split = split.Select(temp => temp.ToLower()).ToArray(); // Ignore case on commands
            split = split.Where(temp => temp != "").ToArray();      // strips extra whitespace from commands

            // Debug
            //sendMessage(client, string.Join(",", split));

            if (split.Length >= 1)
            {
                #region !help
                if (split[0].Equals("help"))
                {
                    if (split.Length == 1)
                    {
                        sendMessage(client, Resources.CPhelp);
                    }
                    if (split.Length == 2)
                    {
                        if (split[1].Equals("mypos"))
                        {
                            sendMessage(client, Resources.CPmypos);
                        }
                        else if (split[1].Equals("music"))
                        {
                            sendMessage(client, Resources.CPmusic);
                        }
                        else if (split[1].Equals("warp"))
                        {
                            sendMessage(client, Resources.CPwarp);
                        }
                        else if (split[1].Equals("givecurrency"))
                        {
                            sendMessage(client, Resources.CPgivecurrency);
                        }
                        else if (split[1].Equals("giveitem"))
                        {
                            sendMessage(client, Resources.CPgiveitem);
                        }
                        else if (split[1].Equals("givekeyitem"))
                        {
                            sendMessage(client, Resources.CPgivekeyitem);
                        }
                        else if (split[1].Equals("removecurrency"))
                        {
                            sendMessage(client, Resources.CPremovecurrency);
                        }
                        else if (split[1].Equals("removeitem"))
                        {
                            sendMessage(client, Resources.CPremoveitem);
                        }
                        else if (split[1].Equals("removekeyitem"))
                        {
                            sendMessage(client, Resources.CPremovekeyitem);
                        }
                        else if (split[1].Equals("reloaditems"))
                        {
                            sendMessage(client, Resources.CPreloaditems);
                        }
                        else if (split[1].Equals("reloadzones"))
                        {
                            sendMessage(client, Resources.CPreloadzones);
                        }

                        /*
                         * else if (split[1].Equals("property"))
                         *  sendMessage(client, Resources.CPproperty);
                         * else if (split[1].Equals("property2"))
                         *  sendMessage(client, Resources.CPproperty2);
                         * else if (split[1].Equals("sendpacket"))
                         *   sendMessage(client, Resources.CPsendpacket);
                         * else if (split[1].Equals("setgraphic"))
                         *     sendMessage(client, Resources.CPsetgraphic);
                         */
                    }
                    if (split.Length == 3)
                    {
                        if (split[1].Equals("test"))
                        {
                            if (split[2].Equals("weather"))
                            {
                                sendMessage(client, Resources.CPtestweather);
                            }
                        }
                    }

                    return(true);
                }
                #endregion

                #region !test
                else if (split[0].Equals("test"))
                {
                    if (split.Length == 1)
                    {
                        // catch invalid commands
                        sendMessage(client, Resources.CPhelp);
                    }
                    else if (split.Length >= 2)
                    {
                        #region !test weather
                        if (split[1].Equals("weather"))
                        {
                            try
                            {
                                doWeather(client, split[2], split[3]);
                                return(true);
                            }
                            catch (Exception e)
                            {
                                Log.error("Could not change weather: " + e);
                            }
                        }
                        #endregion
                    }
                }
                #endregion

                #region !mypos
                else if (split[0].Equals("mypos"))
                {
                    try
                    {
                        printPos(client);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not load packet: " + e);
                    }
                }
                #endregion

                #region !reloadzones
                else if (split[0].Equals("reloadzones"))
                {
                    if (client != null)
                    {
                        Log.info(String.Format("Got request to reset zone: {0}", client.getActor().zoneId));
                        client.getActor().zone.clear();
                        client.getActor().zone.addActorToZone(client.getActor());
                        client.getActor().sendInstanceUpdate();
                        client.queuePacket(BasePacket.createPacket(SendMessagePacket.buildPacket(client.actorID, client.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", String.Format("Reseting zone {0}...", client.getActor().zoneId)), true, false));
                    }
                    Server.GetWorldManager().reloadZone(client.getActor().zoneId);
                    return(true);
                }
                #endregion

                #region !reloaditems
                else if (split[0].Equals("reloaditems"))
                {
                    Log.info(String.Format("Got request to reload item gamedata"));
                    sendMessage(client, "Reloading Item Gamedata...");
                    gamedataItems.Clear();
                    gamedataItems = Database.getItemGamedata();
                    Log.info(String.Format("Loaded {0} items.", gamedataItems.Count));
                    sendMessage(client, String.Format("Loaded {0} items.", gamedataItems.Count));
                    return(true);
                }
                #endregion

                #region !sendpacket
                else if (split[0].Equals("sendpacket"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        sendPacket(client, "./packets/" + split[1]);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not load packet: " + e);
                    }
                }
                #endregion

                #region !graphic
                else if (split[0].Equals("graphic"))
                {
                    try
                    {
                        if (split.Length == 6)
                        {
                            setGraphic(client, UInt32.Parse(split[1]), UInt32.Parse(split[2]), UInt32.Parse(split[3]), UInt32.Parse(split[4]), UInt32.Parse(split[5]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give item.");
                    }
                }
                #endregion

                #region !giveitem
                else if (split[0].Equals("giveitem"))
                {
                    try
                    {
                        if (split.Length == 2)
                        {
                            giveItem(client, UInt32.Parse(split[1]), 1);
                        }
                        else if (split.Length == 3)
                        {
                            giveItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                        else if (split.Length == 4)
                        {
                            giveItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]), UInt16.Parse(split[3]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give item.");
                    }
                }
                #endregion

                #region !removeitem
                else if (split[0].Equals("removeitem"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        if (split.Length == 2)
                        {
                            removeItem(client, UInt32.Parse(split[1]), 1);
                        }
                        else if (split.Length == 3)
                        {
                            removeItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                        else if (split.Length == 4)
                        {
                            removeItem(client, UInt32.Parse(split[1]), Int32.Parse(split[2]), UInt16.Parse(split[3]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not remove item.");
                    }
                }
                #endregion

                #region !givekeyitem
                else if (split[0].Equals("givekeyitem"))
                {
                    try
                    {
                        if (split.Length == 2)
                        {
                            giveKeyItem(client, UInt32.Parse(split[1]));
                        }
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give keyitem.");
                    }
                }
                #endregion

                #region !removekeyitem
                else if (split[0].Equals("removekeyitem"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        if (split.Length == 2)
                        {
                            removeKeyItem(client, UInt32.Parse(split[1]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not remove keyitem.");
                    }
                }
                #endregion

                #region !givecurrency
                else if (split[0].Equals("givecurrency"))
                {
                    try
                    {
                        if (split.Length == 2)
                        {
                            giveCurrency(client, ITEM_GIL, Int32.Parse(split[1]));
                        }
                        else if (split.Length == 3)
                        {
                            giveCurrency(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not give currency.");
                    }
                }
                #endregion

                #region !removecurrency
                else if (split[0].Equals("removecurrency"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        if (split.Length == 2)
                        {
                            removeCurrency(client, ITEM_GIL, Int32.Parse(split[1]));
                        }
                        else if (split.Length == 3)
                        {
                            removeCurrency(client, UInt32.Parse(split[1]), Int32.Parse(split[2]));
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not remove currency.");
                    }
                }
                #endregion

                #region !music
                else if (split[0].Equals("music"))
                {
                    if (split.Length < 2)
                    {
                        return(false);
                    }

                    try
                    {
                        doMusic(client, split[1]);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log.error("Could not change music: " + e);
                    }
                }
                #endregion

                #region !warp
                else if (split[0].Equals("warp"))
                {
                    parseWarp(client, split);
                    return(true);
                }
                #endregion

                #region !property
                else if (split[0].Equals("property"))
                {
                    if (split.Length == 4)
                    {
                        changeProperty(Utils.MurmurHash2(split[1], 0), Convert.ToUInt32(split[2], 16), split[3]);
                    }
                    return(true);
                }
                #endregion

                #region !property2
                else if (split[0].Equals("property2"))
                {
                    if (split.Length == 4)
                    {
                        changeProperty(Convert.ToUInt32(split[1], 16), Convert.ToUInt32(split[2], 16), split[3]);
                    }
                    return(true);
                }
                #endregion
            }
            return(false);
        }
        private void parseWarp(ConnectedPlayer client, string[] split)
        {
            float  x = 0, y = 0, z = 0, r = 0.0f;
            uint   zoneId      = 0;
            string privatearea = null;

            if (split.Length == 2) // Predefined list
            {
                // TODO: Handle !warp Playername
                #region !warp (predefined list)
                try
                {
                    if (split[1].ToLower().StartsWith("0x"))
                    {
                        zoneId = Convert.ToUInt32(split[1], 16);
                    }
                    else
                    {
                        zoneId = Convert.ToUInt32(split[1]);
                    }
                }
                catch { return; }
                #endregion

                doWarp(client, zoneId);
            }
            else if (split.Length == 4)
            {
                #region !warp X Y Z
                if (split[1].StartsWith("@"))
                {
                    split[1] = split[1].Replace("@", string.Empty);

                    if (String.IsNullOrEmpty(split[1]))
                    {
                        split[1] = "0";
                    }

                    try { x = Single.Parse(split[1]) + client.getActor().positionX; }
                    catch { return; }

                    split[1] = x.ToString();
                }
                if (split[2].StartsWith("@"))
                {
                    split[2] = split[2].Replace("@", string.Empty);

                    if (String.IsNullOrEmpty(split[2]))
                    {
                        split[2] = "0";
                    }

                    try { y = Single.Parse(split[2]) + client.getActor().positionY; }
                    catch { return; }

                    split[2] = y.ToString();
                }
                if (split[3].StartsWith("@"))
                {
                    split[3] = split[3].Replace("@", string.Empty);

                    if (String.IsNullOrEmpty(split[3]))
                    {
                        split[3] = "0";
                    }

                    try { z = Single.Parse(split[3]) + client.getActor().positionZ; }
                    catch { return; }

                    split[3] = z.ToString();
                }

                try
                {
                    x = Single.Parse(split[1]);
                    y = Single.Parse(split[2]);
                    z = Single.Parse(split[3]);
                }
                catch { return; }

                zoneId = client.getActor().zoneId;
                r      = client.getActor().rotation;
                #endregion

                sendMessage(client, String.Format("Warping to: ZoneID: {0} X: {1}, Y: {2}, Z: {3}", zoneId, x, y, z));
                doWarp(client, zoneId, privatearea, 0x00, x, y, z, r);
            }
            else if (split.Length == 5)
            {
                #region !warp Zone X Y Z
                try
                {
                    x = Single.Parse(split[2]);
                    y = Single.Parse(split[3]);
                    z = Single.Parse(split[4]);
                }
                catch { return; }

                if (split[1].ToLower().StartsWith("0x"))
                {
                    try { zoneId = Convert.ToUInt32(split[1], 16); }
                    catch { return; }
                }
                else
                {
                    try { zoneId = Convert.ToUInt32(split[1]); }
                    catch { return; }
                }
                #endregion

                sendMessage(client, String.Format("Warping to: ZoneID: {0} X: {1}, Y: {2}, Z: {3}", zoneId, x, y, z));
                doWarp(client, zoneId, privatearea, 0x2, x, y, z, r);
            }
            else if (split.Length == 6)
            {
                #region !warp Zone Instance X Y Z
                try
                {
                    x = Single.Parse(split[3]);
                    y = Single.Parse(split[4]);
                    z = Single.Parse(split[5]);
                }
                catch { return; }

                if (split[1].ToLower().StartsWith("0x"))
                {
                    try { zoneId = Convert.ToUInt32(split[1], 16); }
                    catch { return; }
                }
                else
                {
                    try { zoneId = Convert.ToUInt32(split[1]); }
                    catch { return; }
                }

                privatearea = split[2];
                #endregion

                sendMessage(client, String.Format("Warping to: ZoneID: {0} X: {1}, Y: {2}, Z: {3}", zoneId, x, y, z));
                doWarp(client, zoneId, privatearea, 0x2, x, y, z, r);
            }
            else
            {
                return; // catch any invalid warps here
            }
        }
Ejemplo n.º 12
0
        public void processPacket(ClientConnection client, BasePacket packet)
        {
            if (packet.header.isCompressed == 0x01)
            {
                BasePacket.decryptPacket(client.blowfish, ref packet);
            }

            List <SubPacket> subPackets = packet.getSubpackets();

            foreach (SubPacket subpacket in subPackets)
            {
                if (subpacket.header.type == 0x01)
                {
                    packet.debugPrintPacket();
                    byte[] reply1Data =
                    {
                        0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x18, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFD, 0xFF, 0xFF,
                        0xE5, 0x6E, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x0
                    };

                    byte[] reply2Data =
                    {
                        0x01, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x38, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x2B, 0x5F, 0x26,
                        0x66, 0x00, 0x00, 0x00, 0xC8, 0xD6, 0xAF, 0x2B, 0x38, 0x2B, 0x5F, 0x26, 0xB8, 0x8D, 0xF0, 0x2B,
                        0xC8, 0xFD, 0x85, 0xFE, 0xA8, 0x7C, 0x5B, 0x09, 0x38, 0x2B, 0x5F, 0x26, 0xC8, 0xD6, 0xAF, 0x2B,
                        0xB8, 0x8D, 0xF0, 0x2B, 0x88, 0xAF, 0x5E, 0x26
                    };

                    BasePacket reply1 = new BasePacket(reply1Data);
                    BasePacket reply2 = new BasePacket(reply2Data);

                    //Write Timestamp into Reply1
                    using (MemoryStream mem = new MemoryStream(reply1.data))
                    {
                        using (BinaryWriter binReader = new BinaryWriter(mem))
                        {
                            binReader.BaseStream.Seek(0x14, SeekOrigin.Begin);
                            binReader.Write((UInt32)Utils.UnixTimeStampUTC());
                        }
                    }

                    //Read in Actor Id that owns this connection
                    uint actorID = 0;
                    using (MemoryStream mem = new MemoryStream(packet.data))
                    {
                        using (BinaryReader binReader = new BinaryReader(mem))
                        {
                            try
                            {
                                byte[] readIn = new byte[12];
                                binReader.BaseStream.Seek(0x14, SeekOrigin.Begin);
                                binReader.Read(readIn, 0, 12);
                                actorID = UInt32.Parse(Encoding.ASCII.GetString(readIn));
                            }
                            catch (Exception)
                            { }
                        }
                    }

                    //Should never happen.... unless actor id IS 0!
                    if (actorID == 0)
                    {
                        break;
                    }

                    client.owner = actorID;

                    //Write Actor ID into reply2
                    using (MemoryStream mem = new MemoryStream(reply2.data))
                    {
                        using (BinaryWriter binReader = new BinaryWriter(mem))
                        {
                            binReader.BaseStream.Seek(0x10, SeekOrigin.Begin);
                            binReader.Write(actorID);
                        }
                    }

                    ConnectedPlayer player = null;

                    if (packet.header.connectionType == BasePacket.TYPE_ZONE)
                    {
                        while (!mPlayers.ContainsKey(client.owner))
                        {
                        }
                        player = mPlayers[client.owner];
                    }

                    //Create connected player if not created
                    if (player == null)
                    {
                        player            = new ConnectedPlayer(actorID);
                        mPlayers[actorID] = player;
                    }

                    player.setConnection(packet.header.connectionType, client);

                    if (packet.header.connectionType == BasePacket.TYPE_ZONE)
                    {
                        Log.debug(String.Format("Got {0} connection for ActorID {1} @ {2}.", "zone", actorID, client.getAddress()));
                    }
                    else if (packet.header.connectionType == BasePacket.TYPE_CHAT)
                    {
                        Log.debug(String.Format("Got {0} connection for ActorID {1} @ {2}.", "chat", actorID, client.getAddress()));
                    }

                    //Create player actor
                    reply1.debugPrintPacket();
                    client.queuePacket(reply1);
                    client.queuePacket(reply2);
                    break;
                }
                else if (subpacket.header.type == 0x07)
                {
                    BasePacket init = Login0x7ResponsePacket.buildPacket(BitConverter.ToUInt32(packet.data, 0x10), Utils.UnixTimeStampUTC());
                    //client.queuePacket(init);
                }
                else if (subpacket.header.type == 0x08)
                {
                    //Response, client's current [actorID][time]
                    packet.debugPrintPacket();
                }
                else if (subpacket.header.type == 0x03)
                {
                    ConnectedPlayer player = null;

                    if (mPlayers.ContainsKey(client.owner))
                    {
                        player = mPlayers[client.owner];
                    }

                    if (player == null)
                    {
                        return;
                    }

                    //Normal Game Opcode
                    switch (subpacket.gameMessage.opcode)
                    {
                    //Ping
                    case 0x0001:
                        //subpacket.debugPrintSubPacket();
                        PingPacket pingPacket = new PingPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(PongPacket.buildPacket(player.actorID, pingPacket.time), true, false));
                        player.ping();
                        break;

                    //Unknown
                    case 0x0002:

                        subpacket.debugPrintSubPacket();
                        client.queuePacket(_0x2Packet.buildPacket(player.actorID), true, false);

                        Server.GetWorldManager().DoLogin(player.getActor());


                        break;

                    //Chat Received
                    case 0x0003:
                        ChatMessagePacket chatMessage = new ChatMessagePacket(subpacket.data);
                        Log.info(String.Format("Got type-{5} message: {0} @ {1}, {2}, {3}, Rot: {4}", chatMessage.message, chatMessage.posX, chatMessage.posY, chatMessage.posZ, chatMessage.posRot, chatMessage.logType));
                        subpacket.debugPrintSubPacket();

                        if (chatMessage.message.StartsWith("!"))
                        {
                            if (cp.doCommand(chatMessage.message, player))
                            {
                                continue;
                            }
                        }

                        player.getActor().broadcastPacket(SendMessagePacket.buildPacket(player.actorID, player.actorID, chatMessage.logType, player.getActor().customDisplayName, chatMessage.message), false);

                        break;

                    //Langauge Code
                    case 0x0006:
                        LangaugeCodePacket langCode = new LangaugeCodePacket(subpacket.data);
                        player.languageCode = langCode.languageCode;
                        break;

                    //Unknown - Happens a lot at login, then once every time player zones
                    case 0x0007:
                        //subpacket.debugPrintSubPacket();
                        _0x07Packet unknown07 = new _0x07Packet(subpacket.data);
                        break;

                    //Update Position
                    case 0x00CA:
                        //Update Position
                        //subpacket.debugPrintSubPacket();
                        UpdatePlayerPositionPacket posUpdate = new UpdatePlayerPositionPacket(subpacket.data);
                        player.updatePlayerActorPosition(posUpdate.x, posUpdate.y, posUpdate.z, posUpdate.rot, posUpdate.moveState);
                        player.getActor().sendInstanceUpdate();

                        if (player.getActor().isInZoneChange())
                        {
                            player.getActor().setZoneChanging(false);
                        }

                        break;

                    //Set Target
                    case 0x00CD:
                        //subpacket.debugPrintSubPacket();

                        SetTargetPacket setTarget       = new SetTargetPacket(subpacket.data);
                        player.getActor().currentTarget = setTarget.actorID;
                        player.getActor().broadcastPacket(SetActorTargetAnimatedPacket.buildPacket(player.actorID, player.actorID, setTarget.actorID), true);
                        break;

                    //Lock Target
                    case 0x00CC:
                        LockTargetPacket lockTarget           = new LockTargetPacket(subpacket.data);
                        player.getActor().currentLockedTarget = lockTarget.actorID;
                        break;

                    //Start Event
                    case 0x012D:
                        subpacket.debugPrintSubPacket();
                        EventStartPacket eventStart = new EventStartPacket(subpacket.data);

                        /*
                         * if (eventStart.error != null)
                         * {
                         *  player.errorMessage += eventStart.error;
                         *
                         *  if (eventStart.errorIndex == eventStart.errorNum - 1)
                         *      Log.error("\n"+player.errorMessage);
                         *
                         *
                         *  break;
                         * }
                         */

                        Actor ownerActor = Server.getStaticActors(eventStart.scriptOwnerActorID);
                        if (ownerActor != null && ownerActor is Command)
                        {
                            player.getActor().currentCommand     = eventStart.scriptOwnerActorID;
                            player.getActor().currentCommandName = eventStart.triggerName;
                        }
                        else
                        {
                            player.getActor().currentEventOwner = eventStart.scriptOwnerActorID;
                            player.getActor().currentEventName  = eventStart.triggerName;
                        }

                        if (ownerActor == null)
                        {
                            //Is it a instance actor?
                            ownerActor = Server.GetWorldManager().GetActorInWorld(player.getActor().currentEventOwner);
                            if (ownerActor == null)
                            {
                                //Is it a Director?
                                if (player.getActor().currentDirector != null && player.getActor().currentEventOwner == player.getActor().currentDirector.actorId)
                                {
                                    ownerActor = player.getActor().currentDirector;
                                }
                                else
                                {
                                    Log.debug(String.Format("\n===Event START===\nCould not find actor 0x{0:X} for event started by caller: 0x{1:X}\nEvent Starter: {2}\nParams: {3}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.triggerName, LuaUtils.dumpParams(eventStart.luaParams)));
                                    break;
                                }
                            }
                        }

                        LuaEngine.doActorOnEventStarted(player.getActor(), ownerActor, eventStart);

                        Log.debug(String.Format("\n===Event START===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nEvent Starter: {4}\nParams: {5}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.val1, eventStart.val2, eventStart.triggerName, LuaUtils.dumpParams(eventStart.luaParams)));
                        break;

                    //Unknown, happens at npc spawn and cutscene play????
                    case 0x00CE:
                        break;

                    //Event Result
                    case 0x012E:
                        subpacket.debugPrintSubPacket();
                        EventUpdatePacket eventUpdate = new EventUpdatePacket(subpacket.data);
                        Log.debug(String.Format("\n===Event UPDATE===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nStep: 0x{4:X}\nParams: {5}", eventUpdate.actorID, eventUpdate.scriptOwnerActorID, eventUpdate.val1, eventUpdate.val2, eventUpdate.step, LuaUtils.dumpParams(eventUpdate.luaParams)));

                        //Is it a static actor? If not look in the player's instance
                        Actor updateOwnerActor = Server.getStaticActors(player.getActor().currentEventOwner);
                        if (updateOwnerActor == null)
                        {
                            updateOwnerActor = Server.GetWorldManager().GetActorInWorld(player.getActor().currentEventOwner);

                            if (player.getActor().currentDirector != null && player.getActor().currentEventOwner == player.getActor().currentDirector.actorId)
                            {
                                updateOwnerActor = player.getActor().currentDirector;
                            }

                            if (updateOwnerActor == null)
                            {
                                break;
                            }
                        }

                        LuaEngine.doActorOnEventUpdated(player.getActor(), updateOwnerActor, eventUpdate);

                        break;

                    case 0x012F:
                        subpacket.debugPrintSubPacket();
                        ParameterDataRequestPacket paramRequest = new ParameterDataRequestPacket(subpacket.data);
                        if (paramRequest.paramName.Equals("charaWork/exp"))
                        {
                            player.getActor().sendCharaExpInfo();
                        }
                        break;

                    /* RECRUITMENT */
                    //Start Recruiting
                    case 0x01C3:
                        StartRecruitingRequestPacket recruitRequestPacket = new StartRecruitingRequestPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(StartRecruitingResponse.buildPacket(player.actorID, true), true, false));
                        break;

                    //End Recruiting
                    case 0x01C4:
                        client.queuePacket(BasePacket.createPacket(EndRecruitmentPacket.buildPacket(player.actorID), true, false));
                        break;

                    //Party Window Opened, Request State
                    case 0x01C5:
                        client.queuePacket(BasePacket.createPacket(RecruiterStatePacket.buildPacket(player.actorID, true, true, 1), true, false));
                        break;

                    //Search Recruiting
                    case 0x01C7:
                        RecruitmentSearchRequestPacket recruitSearchPacket = new RecruitmentSearchRequestPacket(subpacket.data);
                        break;

                    //Get Recruitment Details
                    case 0x01C8:
                        RecruitmentDetailsRequestPacket currentRecruitDetailsPacket = new RecruitmentDetailsRequestPacket(subpacket.data);
                        RecruitmentDetails details = new RecruitmentDetails();
                        details.recruiterName = "Localhost Character";
                        details.purposeId     = 2;
                        details.locationId    = 1;
                        details.subTaskId     = 1;
                        details.comment       = "This is a test details packet sent by the server. No implementation has been created yet...";
                        details.num[0]        = 1;
                        client.queuePacket(BasePacket.createPacket(CurrentRecruitmentDetailsPacket.buildPacket(player.actorID, details), true, false));
                        break;

                    //Accepted Recruiting
                    case 0x01C6:
                        subpacket.debugPrintSubPacket();
                        break;

                    /* SOCIAL STUFF */
                    case 0x01C9:
                        AddRemoveSocialPacket addBlackList = new AddRemoveSocialPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(BlacklistAddedPacket.buildPacket(player.actorID, true, addBlackList.name), true, false));
                        break;

                    case 0x01CA:
                        AddRemoveSocialPacket removeBlackList = new AddRemoveSocialPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(BlacklistRemovedPacket.buildPacket(player.actorID, true, removeBlackList.name), true, false));
                        break;

                    case 0x01CB:
                        int offset1 = 0;
                        client.queuePacket(BasePacket.createPacket(SendBlacklistPacket.buildPacket(player.actorID, new String[] { "Test" }, ref offset1), true, false));
                        break;

                    case 0x01CC:
                        AddRemoveSocialPacket addFriendList = new AddRemoveSocialPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(FriendlistAddedPacket.buildPacket(player.actorID, true, (uint)addFriendList.name.GetHashCode(), true, addFriendList.name), true, false));
                        break;

                    case 0x01CD:
                        AddRemoveSocialPacket removeFriendList = new AddRemoveSocialPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(FriendlistRemovedPacket.buildPacket(player.actorID, true, removeFriendList.name), true, false));
                        break;

                    case 0x01CE:
                        int offset2 = 0;
                        client.queuePacket(BasePacket.createPacket(SendFriendlistPacket.buildPacket(player.actorID, new Tuple <long, string>[] { new Tuple <long, string>(01, "Test2") }, ref offset2), true, false));
                        break;

                    case 0x01CF:
                        client.queuePacket(BasePacket.createPacket(FriendStatusPacket.buildPacket(player.actorID, null), true, false));
                        break;

                    /* SUPPORT DESK STUFF */
                    //Request for FAQ/Info List
                    case 0x01D0:
                        FaqListRequestPacket faqRequest = new FaqListRequestPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(FaqListResponsePacket.buildPacket(player.actorID, new string[] { "Testing FAQ1", "Coded style!" }), true, false));
                        break;

                    //Request for body of a faq/info selection
                    case 0x01D1:
                        FaqBodyRequestPacket faqBodyRequest = new FaqBodyRequestPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(FaqBodyResponsePacket.buildPacket(player.actorID, "HERE IS A GIANT BODY. Nothing else to say!"), true, false));
                        break;

                    //Request issue list
                    case 0x01D2:
                        GMTicketIssuesRequestPacket issuesRequest = new GMTicketIssuesRequestPacket(subpacket.data);
                        client.queuePacket(BasePacket.createPacket(IssueListResponsePacket.buildPacket(player.actorID, new string[] { "Test1", "Test2", "Test3", "Test4", "Test5" }), true, false));
                        break;

                    //Request if GM ticket exists
                    case 0x01D3:
                        client.queuePacket(BasePacket.createPacket(StartGMTicketPacket.buildPacket(player.actorID, false), true, false));
                        break;

                    //Request for GM response message
                    case 0x01D4:
                        client.queuePacket(BasePacket.createPacket(GMTicketPacket.buildPacket(player.actorID, "This is a GM Ticket Title", "This is a GM Ticket Body."), true, false));
                        break;

                    //GM Ticket Sent
                    case 0x01D5:
                        GMSupportTicketPacket gmTicket = new GMSupportTicketPacket(subpacket.data);
                        Log.info("Got GM Ticket: \n" + gmTicket.ticketTitle + "\n" + gmTicket.ticketBody);
                        client.queuePacket(BasePacket.createPacket(GMTicketSentResponsePacket.buildPacket(player.actorID, true), true, false));
                        break;

                    //Request to end ticket
                    case 0x01D6:
                        client.queuePacket(BasePacket.createPacket(EndGMTicketPacket.buildPacket(player.actorID), true, false));
                        break;

                    default:
                        Log.debug(String.Format("Unknown command 0x{0:X} received.", subpacket.gameMessage.opcode));
                        subpacket.debugPrintSubPacket();
                        break;
                    }
                }
                else
                {
                    packet.debugPrintPacket();
                }
            }
        }