示例#1
0
 /// <summary>
 /// Loads the actions.
 /// </summary>
 /// <param name="node">The node.</param>
 public void LoadActions(XmlNode node, string path)
 {
     foreach (XmlNode actionNode in node.SelectNodes("actions/action"))
     {
         NodeAttributes attributes = new NodeAttributes(actionNode);
         TemplateAction action = new TemplateAction(this, attributes.AsString("type"), path + "\\" + attributes.AsString("source"), attributes.AsString("target"));
         this.Actions.Add(action);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void Listen(HttpRequest request, HttpResponse response)
        {
            try
            {
                // Ali je pot v registriranem listenerju in kliči listener ter return ;
                if (IsRegisteredExtension(request.RequestPath.ToLower()))
                {
                    string[] _tmp = request.RequestPath.ToLower().Split(new char[] { '.' });
                    if (_tmp.Length > 0)
                    {
                        ProcessExtensionListener(request, response, _tmp[_tmp.Length - 1]);
                        return;
                    }
                    else
                    {
                        throw new InvalidDataException("Cannot determine extension from " + request.RequestPath);
                    }
                }

                if (request.RequestPath.EndsWith("/"))
                {
                    // Preverimo, ali je v folderju index file.
                    foreach (string file in _serverRootFile)
                    {
                        if (Containes(_serverRootFolder + request.RequestPath + file))
                        {
                            response.Write(ReadToByte(_serverRootFolder + request.RequestPath + file), _server.GetMimeType.GetMimeFromFile(request.RequestPath + file));
                            return;
                        }
                    }
                    // Ni index fajla,  izpišemo folder.

                    /*
                     * 1) Skopiramo vse poti v začasno datoteko
                     * 2) vse poti, ki ustrezajo ustrezni mapi, skopiramo in pripravimo za izpis
                     * 3) če ne najdemo, je treba izpisat 404.
                     */
                    List <string> _ustreznePoti = new List <string>();

                    foreach (string _pot in GetNames())
                    {
                        if (_pot.ToLower().Contains((_serverRootFolder + request.RequestPath).ToLower().Replace('/', '.')))
                        {
                            // Dodamo samo pravilne url-je za trenutno mapo, brez polne poti in v pravilni obliki.
                            int    cut      = _pot.ToLower().Split(new string[] { _serverRootFolder.ToLower() + request.RequestPath.ToLower().Replace('/', '.') }, StringSplitOptions.None)[1].Length;
                            string _tmpPath = _pot.Replace('.', '/');
                            int    Place    = _tmpPath.LastIndexOf("/");
                            _tmpPath = _tmpPath.Remove(Place, 1).Insert(Place, ".");
                            if (!_tmpPath.Substring(_tmpPath.Length - cut).Contains("/"))
                            {
                                _ustreznePoti.Add(_tmpPath.Substring(_tmpPath.Length - cut));
                            }
                        }
                    }
                    if (_ustreznePoti.Count > 0)
                    {
                        SimpleTemplate _template = new SimpleTemplate();
                        _template.LoadString(ReadToByte("SystemHtml/templateFolderListing.html"));
                        _template.SafeMode = false;

                        StringBuilder rezultat = new StringBuilder();
                        foreach (string _pot in _ustreznePoti)
                        {
                            rezultat.Append("<a href=\"" + _pot + "\">" + _pot + "</a><br>\n");
                        }

                        _template["path"] = new TemplateAction()
                        {
                            Pattern = "PATH", Data = request.RequestPath
                        };
                        _template["content"] = new TemplateAction()
                        {
                            Pattern = "CONTENT", Data = rezultat.ToString()
                        };
                        _template.ProcessAction();
                        response.Write(_template.GetByte(), "text/html");
                        return;
                    }
                    else
                    {
                        ReturnErrorMessage(request, response, "404");
                        return;
                    }
                }
                else
                {
                    /*
                     * Ni folder, izpišemo zahtevano datoteko.
                     */
                    if (Containes(_serverRootFolder + request.RequestPath))
                    {
                        response.Write(ReadToByte(_serverRootFolder + request.RequestPath), _server.GetMimeType.GetMimeFromFile(request.RequestPath));
                        return;
                    }
                    else
                    {
                        ReturnErrorMessage(request, response, "404");
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                response.Write(e);
            }
        }
示例#3
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="packet">
        /// The packet.
        /// </param>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="dynel">
        /// The dynel.
        /// </param>
        public static void Read(byte[] packet, Client client, Dynel dynel)
        {
            sender = client;
            PacketReader packetReader = new PacketReader(packet);

            packetReader.PopHeader();
            packetReader.PopByte();
            temp1  = packetReader.PopInt();
            count  = packetReader.PopInt(); // Count of commands sent
            action = packetReader.PopInt();
            temp4  = packetReader.PopInt();
            user   = packetReader.PopIdentity();
            target = packetReader.PopIdentity();
            packetReader.Finish();
            bool feedback = true;

            switch (action)
            {
            case 1:

                // Get
                break;

            case 2:

                // Drop
                break;

            case 3:

                // Use
                OnUse();
                AOCoord newcoord = client.Character.Coordinates;
                feedback = false;

                if (Statels.StatelppfonUse.ContainsKey(client.Character.PlayField))
                {
                    foreach (Statels.Statel s in Statels.StatelppfonUse[client.Character.PlayField])
                    {
                        if (s.onUse(client, target))
                        {
                            return;
                        }
                    }
                }

                bool teleport  = false;
                int  playfield = 152;
                switch (target.Instance)
                {
                // Need to add feedback to the character
                // Are the Newer Grid points in this list???
                // No newer Grid points in list, will be replaced by a check against a list of statels read from rdb anyway
                // - Algorithman
                case -1073605919:         // Teleport Tower(noobisland)(right)
                    if (client.Character.Stats.Side.Value != 2)
                    {
                        client.SendChatText("You need to be omni to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 202;
                        newcoord.z = 878;
                        newcoord.y = 16;
                        playfield  = 687;
                    }

                    break;

                case -1073736991:         // Teleport Tower(noobisland)(left)
                    if (client.Character.Stats.Side.Value != 1)
                    {
                        client.SendChatText("You need to be clan to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 390;
                        newcoord.z = 340;
                        newcoord.y = 0;
                        playfield  = 545;
                    }

                    break;

                case -1073671455:         // Teleport Tower(noobisland)(middle)
                    if (client.Character.Stats.Side.Value != 0)
                    {
                        client.SendChatText("You need to be neutral to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 685;
                        newcoord.z = 480;
                        newcoord.y = 73;
                        playfield  = 800;
                    }

                    break;

                case -1073741189:         // 2ho -> Stret west
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 1143;
                        newcoord.z = 541;
                        newcoord.y = 8;
                        playfield  = 790;
                    }

                    break;

                case -1073478890:         // Stret West -> 2ho
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 760;
                        newcoord.z = 1982;
                        newcoord.y = 7;
                        playfield  = 635;
                    }

                    break;

                case -1073216841:         // Harry's -> Plesant Meadows
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 370;
                        newcoord.z = 1564;
                        newcoord.y = 7;
                        playfield  = 630;
                    }

                    break;

                case -1073216906:         // Plesant Meadows -> Harry's
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 3196;
                        newcoord.z = 3172;
                        newcoord.y = 7;
                        playfield  = 695;
                    }

                    break;

                case -1073282442:         // Pleasant Meadows -> Omni-Tek outpost in Lush Fields
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 3389;
                        newcoord.z = 800;
                        newcoord.y = 8;
                        playfield  = 695;
                    }

                    break;

                case -1073413449:         // Omni-Tek outpost in Lush Fields -> Pleasant Meadows
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 370;
                        newcoord.z = 1562;
                        newcoord.y = 7;
                        playfield  = 630;
                    }

                    break;

                case -1073347913:         // Harry's trading outpost -> Omni-1 Trade (free)
                    newcoord.x = 3569;
                    newcoord.z = 912;
                    newcoord.y = 9;
                    playfield  = 695;
                    break;

                case -1073282377:         // Omni-1 Trade -> Harry's trading outpost (free)
                    newcoord.x = 3290;
                    newcoord.z = 2922;
                    newcoord.y = 7;
                    playfield  = 695;
                    break;

                default:
                    feedback = true;
                    teleport = false;
                    break;
                }

                if (teleport)
                {
                    client.Teleport(newcoord, client.Character.Heading, playfield);
                }

                // Use item in inventory
                if (target.Type == 104)
                {
                    InventoryEntries ie = client.Character.GetInventoryAt(target.Instance);
                    AOItem           mi = ItemHandler.GetItemTemplate(ie.Item.LowID);

                    // TODO mi.applyon(client.Character, ItemHandler.eventtype_onuse, true, false, ie.Placement);
                    TemplateAction.Send(client.Character, ie);
                    if (mi.isConsumable())
                    {
                        ie.Item.MultipleCount--;
                        if (ie.Item.MultipleCount <= 0)
                        {
                            client.Character.Inventory.Remove(ie);
                            DeleteItem.Send(client.Character, ie.Container, ie.Placement);

                            // Packets.Stat.Set(client, 0, client.Character.Stats.GetStat(0),false);
                        }
                    }

                    foreach (AOEvents aoe in mi.Events)
                    {
                        if (aoe.EventType == Constants.EventtypeOnUse)
                        {
                            sender.Character.ExecuteEvent(
                                sender.Character, sender.Character, aoe, true, false, 0, CheckReqs.doCheckReqs);
                            SkillUpdate.SendStat(client, 0x209, client.Character.Stats.SocialStatus.Value, false);

                            // Social Status
                            return;
                        }
                    }

                    int    le    = packet[7] + packet[6] * 256;
                    byte[] reply = new byte[le];
                    Array.Copy(packet, reply, le);
                    reply[0]    = 0xdf;
                    reply[1]    = 0xdf;
                    reply[8]    = 0x00;
                    reply[9]    = 0x00;
                    reply[10]   = 0x0C;
                    reply[11]   = 0x0E;
                    reply[12]   = (byte)(client.Character.Id >> 24);
                    reply[13]   = (byte)(client.Character.Id >> 16);
                    reply[14]   = (byte)(client.Character.Id >> 8);
                    reply[15]   = (byte)client.Character.Id;
                    reply[0x1c] = 0;
                    reply[32]   = 1;
                    reply[36]   = 3;

                    PacketWriter pw = new PacketWriter();
                    pw.PushBytes(reply);
                    byte[] rep = pw.Finish();
                    client.SendCompressed(rep);
                    SkillUpdate.SendStat(client, 0x209, client.Character.Stats.SocialStatus.Value, false);

                    // Social Status
                    return;
                }
                else if (target.Type == 51035)
                {
                    // Shops
                    VendingMachine vm = VendorHandler.GetVendorById(target.Instance);
                    ShopInventory.Send(client, vm);
                    Trade.Send(client, client.Character, vm);
                    Trade.Send(client, vm, client.Character);
                    Trade.Send(client, vm, client.Character);
                    int    le    = packet[7] + packet[6] * 256;
                    byte[] reply = new byte[le];
                    Array.Copy(packet, reply, le);
                    reply[0]    = 0xdf;
                    reply[1]    = 0xdf;
                    reply[8]    = 0x00;
                    reply[9]    = 0x00;
                    reply[10]   = 0x0C;
                    reply[11]   = 0x0E;
                    reply[12]   = (byte)(client.Character.Id >> 24);
                    reply[13]   = (byte)(client.Character.Id >> 16);
                    reply[14]   = (byte)(client.Character.Id >> 8);
                    reply[15]   = (byte)client.Character.Id;
                    reply[0x1c] = 0;
                    reply[0x20] = 1;

                    client.Character.LastTrade = target;

                    PacketWriter pw = new PacketWriter();
                    pw.PushBytes(reply);
                    byte[] rep = pw.Finish();
                    client.SendCompressed(rep);
                }
                else if (target.Type == 51050)
                {
                    // Open corpse
                }

                break;

            case 4:

                // Repair
                break;

            case 5:

                // UseItemOnItem
#if DEBUG
                Console.WriteLine("Use Item on Item not defined yet");
                Console.WriteLine("Packet data:");
                string line   = string.Empty;
                int    count2 = 0;
                foreach (byte packbyte in packet)
                {
                    if ((count2 % 16) == 0)
                    {
                        Console.WriteLine(line);
                        line = string.Empty;
                    }

                    line = line + packbyte.ToString("X2") + " ";
                    count2++;
                }

                if (line != string.Empty)
                {
                    Console.WriteLine();
                }

                Console.WriteLine(line);
#endif
                break;

            default:
                break;
            }

            if (feedback)
            {
#if DEBUG
                string Feedback1 = string.Format("T1 {0}, Count {1}, Action {2}, T4 {3}", temp1, count, action, temp4);
                string Feedback2 = string.Format(
                    "User {0}:{1}, Target {2}:{3} ({4}:{5})",
                    user.Type,
                    user.Instance,
                    target.Type,
                    (uint)target.Instance,
                    target.Type.ToString("X4"),
                    ((uint)target.Instance).ToString("X8"));
                Statels.Statel b = null;
                if (Statels.Statelppf.ContainsKey(client.Character.PlayField))
                {
                    foreach (Statels.Statel z in Statels.Statelppf[client.Character.PlayField])
                    {
                        if ((z.Type == target.Type) && ((Int32)z.Instance == target.Instance))
                        {
                            b = z;
                            break;
                        }
                    }
                }

                if (b != null)
                {
                    foreach (Statels.StatelEvent e in b.Events)
                    {
                        Console.WriteLine("DebugOutput: \r\n" + e);
                    }

                    Console.WriteLine(b.Coordinates.ToString());
                }
                else
                {
                    Console.WriteLine(
                        "No Statel defined in database for #" + target.Type + ":" + (UInt32)target.Instance + " ("
                        + target.Type.ToString("X4") + ":" + target.Instance.ToString("X8") + ")");
                }

                client.SendChatText(Feedback1);
                client.SendChatText(Feedback2);
#endif
            }
        }
示例#4
0
        /// <summary>
        /// </summary>
        /// <param name="message">
        /// </param>
        /// <param name="client">
        /// </param>
        /// <exception cref="NullReferenceException">
        /// </exception>
        public static void Read(GenericCmdMessage message, ZoneClient client)
        {
            switch (message.Action)
            {
            case GenericCmdAction.Get:
                break;

            case GenericCmdAction.Drop:
                break;

            case GenericCmdAction.Use:
                if (message.Target.Type == IdentityType.Inventory)
                {
                    Item item = null;
                    try
                    {
                        item = client.Character.BaseInventory.GetItemInContainer(
                            (int)message.Target.Type,
                            message.Target.Instance);
                    }
                    catch (Exception)
                    {
                    }

                    if (item == null)
                    {
                        throw new NullReferenceException(
                                  "No item found at " + message.Target.Type + "/" + message.Target.Instance);
                    }

                    TemplateAction.Send(client, item, (int)message.Target.Type, message.Target.Instance);

                    if (ItemLoader.ItemList[item.HighID].IsConsumable())
                    {
                        item.MultipleCount--;
                        if (item.MultipleCount == 0)
                        {
                            client.Character.BaseInventory.RemoveItem(
                                (int)message.Target.Type,
                                message.Target.Instance);

                            DeleteItem.Send(client, (int)message.Target.Type, message.Target.Instance);
                        }
                    }

                    item.PerformAction(client.Character, EventType.OnUse, message.Target.Instance);
                    Reply(message, client);
                }
                else
                {
                    string s = "Generic Command received:\r\nAction: " + message.Action.ToString() + "("
                               + ((int)message.Action).ToString() + ")\r\nTarget: " + message.Target.Type + " "
                               + ((int)message.Target.Type).ToString("X8") + ":"
                               + message.Target.Instance.ToString("X8");
                    if (PlayfieldLoader.PFData.ContainsKey(client.Character.Playfield.Identity.Instance))
                    {
                        StatelData sd =
                            PlayfieldLoader.PFData[client.Playfield.Identity.Instance].Statels.FirstOrDefault(
                                x =>
                                (x.StatelIdentity.Type == message.Target.Type) &&
                                (x.StatelIdentity.Instance == message.Target.Instance));

                        if (sd != null)
                        {
                            s = s + "\r\nFound Statel with " + sd.Events.Count + " events";
                            Events onUse = sd.Events.FirstOrDefault(x => x.EventType == (int)EventType.OnUse);
                            if (onUse != null)
                            {
                                onUse.Perform(client.Character, client.Character);
                            }
                        }
                    }

                    client.Character.Send(new ChatTextMessage()
                    {
                        Identity = client.Character.Identity, Text = s
                    });
                }

                break;
            }
        }
 public abstract void Handle(TemplateAction action);
 public abstract void Handle(TemplateAction action);