Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Text.RegularExpressions;
- using Microsoft.SqlServer.Server;
- namespace EquFunctions
- {
- public partial class InvHandler
- {
- // ParseInventory Procedure
- // Returns the row data for an inventory entry (invdata).
- [SqlProcedure]
- public static void ParseInventory(string data)
- {
- SqlMetaData cObjectID = new SqlMetaData("ObjectID", SqlDbType.BigInt);
- SqlMetaData cFlags = new SqlMetaData("Flags", SqlDbType.Int);
- SqlMetaData cItemFlags = new SqlMetaData("ItemFlags", SqlDbType.VarChar, 16);
- SqlMetaData cName = new SqlMetaData("Name", SqlDbType.NVarChar, 1024);
- SqlMetaData cDisplay = new SqlMetaData("Display", SqlDbType.NVarChar, 1024);
- SqlMetaData cLevel = new SqlMetaData("Level", SqlDbType.TinyInt);
- SqlMetaData cType = new SqlMetaData("Type", SqlDbType.TinyInt);
- SqlMetaData cWear = new SqlMetaData("Wear", SqlDbType.SmallInt);
- SqlMetaData cTimer = new SqlMetaData("Timer", SqlDbType.Int);
- SqlMetaData cContainerID = new SqlMetaData("ContainerID", SqlDbType.BigInt);
- Dictionary<char, int> fd = new Dictionary<char, int>() { {'K', (int) invflags.keep },
- {'M', (int) invflags.magic},
- {'H', (int) invflags.hum },
- {'I', (int) invflags.invis},
- {'G', (int) invflags.glow },
- {'T', (int) invflags.temp } };
- string ESC = @"";
- string STX = @"";
- Hashtable ct = new Hashtable() { {"R", ESC + @"[1;31m"},
- {"r", ESC + @"[0;31m"},
- {"G", ESC + @"[1;32m"},
- {"g", ESC + @"[0;32m"},
- {"Y", ESC + @"[1;33m"},
- {"y", ESC + @"[0;33m"},
- {"B", ESC + @"[1;34m"},
- {"b", ESC + @"[0;34m"},
- {"M", ESC + @"[1;35m"},
- {"m", ESC + @"[0;35m"},
- {"C", ESC + @"[1;36m"},
- {"c", ESC + @"[0;36m"},
- {"W", ESC + @"[1;37m"},
- {"w", ESC + @"[0;37m"},
- {"D", ESC + @"[1;30m"}};
- SqlDataRecord r;
- Regex pattern = new Regex(@"(?<id>\d+),(?<iflgs>\w+)?,(?<disp>.+?),(?<lvl>\d+),(?<type>\d+),(?<unq>\d+),(?<wear>-?\d+),(?<tmr>-?\d+),(?<cid>\d+)");
- Regex dpatt1 = new Regex(@"^([^@]+)");
- Regex dpatt2 = new Regex(@"@(\w)([^@|$]+)");
- r = new SqlDataRecord(cObjectID, cFlags, cItemFlags, cDisplay, cName, cLevel, cType, cWear, cTimer, cContainerID);
- int flags = 0;
- Byte t08;
- Int16 t16;
- Int32 t32;
- Int64 t64;
- string items;
- Match m = pattern.Match(data);
- if (m.Success)
- {
- Int64.TryParse(m.Groups["id"].Value, out t64);
- r.SetInt64(0, t64);
- items = m.Groups["iflgs"].Value;
- r.SetString(2, items);
- string tname = "", dname = "";
- StringBuilder sb = new StringBuilder(m.Groups["disp"].Value);
- sb.Replace(@"""", "");
- sb.Replace("@-", "~");
- sb.Replace("@@", STX);
- string name = sb.ToString();
- Match match1 = dpatt1.Match(name);
- int len = match1.Groups[1].Length;
- if (len > 0)
- {
- tname = ct["w"] + match1.Groups[1].Value;
- dname = match1.Groups[1].Value;
- name = name.Substring(len);
- }
- if (name.Length > 0)
- {
- foreach (Match m2 in dpatt2.Matches(name))
- {
- tname += ct[m2.Groups[1].Value] + m2.Groups[2].Value;
- dname += m2.Groups[2].Value;
- }
- }
- tname = tname.Replace(STX, "@");
- if (dname == "") dname = tname;
- else dname = dname.Replace(STX, "@");
- if (tname == dname) tname = ct["w"] + tname;
- if (!name.EndsWith(ESC + @"[0;37m")) name += ESC + @"[0;37m";
- r.SetString(3, tname);
- r.SetString(4, dname);
- Byte.TryParse(m.Groups["lvl"].Value, out t08);
- r.SetByte(5, t08);
- Byte.TryParse(m.Groups["type"].Value, out t08);
- r.SetByte(6, t08);
- Byte.TryParse(m.Groups["unq"].Value, out t08);
- flags = (t08 != 0) ? (int)invflags.unique : 0;
- Int16.TryParse(m.Groups["wear"].Value, out t16);
- r.SetInt16(7, t16);
- Int32.TryParse(m.Groups["tmr"].Value, out t32);
- r.SetInt32(8, t32);
- Int64.TryParse(m.Groups["cid"].Value, out t64);
- r.SetInt64(9, t64);
- if (items != null) for (int i = 0; i < items.Length; i++) flags |= fd[items[i]];
- r.SetInt32(1, flags);
- SqlContext.Pipe.Send(r);
- }
- }
- // ParseItem Procedure
- // Returns the row data for an inventory entry (invitem).
- public static void ParseItem(string data)
- {
- SqlMetaData cObjectID = new SqlMetaData("ObjectID", SqlDbType.BigInt);
- SqlMetaData cFlags = new SqlMetaData("Flags", SqlDbType.Int);
- SqlMetaData cItemFlags = new SqlMetaData("ItemFlags", SqlDbType.VarChar, 16);
- SqlMetaData cName = new SqlMetaData("Name", SqlDbType.NVarChar, 1024);
- SqlMetaData cDisplay = new SqlMetaData("Display", SqlDbType.NVarChar, 1024);
- SqlMetaData cLevel = new SqlMetaData("Level", SqlDbType.TinyInt);
- SqlMetaData cType = new SqlMetaData("Type", SqlDbType.TinyInt);
- SqlMetaData cWear = new SqlMetaData("Wear", SqlDbType.SmallInt);
- SqlMetaData cTimer = new SqlMetaData("Timer", SqlDbType.Int);
- SqlMetaData cContainerID = new SqlMetaData("ContainerID", SqlDbType.BigInt);
- Dictionary<char, int> fd = new Dictionary<char, int>() { {'K', (int) invflags.keep },
- {'M', (int) invflags.magic},
- {'H', (int) invflags.hum },
- {'I', (int) invflags.invis},
- {'G', (int) invflags.glow },
- {'T', (int) invflags.temp } };
- string ESC = @"";
- SqlDataRecord r;
- Regex pattern = new Regex(@"(?<id>\d+),(?<iflgs>\w+)?,(?<disp>[^,]+),(?<lvl>\d+),(?<type>\d+),(?<unq>\d+),(?<wear>-?\d+),(?<tmr>-?\d+)");
- Regex dpatt = new Regex(@"\[(?:[0-1];)?\d+m([^|$]+)");
- r = new SqlDataRecord(cObjectID, cFlags, cItemFlags, cDisplay, cName, cLevel, cType, cWear, cTimer, cContainerID);
- int flags = 0;
- Byte t08;
- Int16 t16;
- Int32 t32;
- Int64 t64;
- string items;
- string tname = "";
- Match m = pattern.Match(data);
- if (m.Success)
- {
- Int64.TryParse(m.Groups["id"].Value, out t64);
- r.SetInt64(0, t64);
- items = m.Groups["iflgs"].Value;
- r.SetString(2, items);
- string name = m.Groups["disp"].Value;
- Match mf = dpatt.Match(name);
- if (mf.Success)
- {
- if (mf.Index > 0) name = ESC + @"[0;37m" + name;
- }
- foreach (Match m3 in dpatt.Matches(name)) tname += m3.Groups[1].Value;
- if (tname == "")
- {
- tname = name;
- name = ESC + @"[0;37m" + name;
- }
- if (!name.EndsWith(ESC + @"[0;37m")) name += ESC + @"[0;37m";
- r.SetString(3, name);
- r.SetString(4, tname);
- Byte.TryParse(m.Groups["lvl"].Value, out t08);
- r.SetByte(5, t08);
- Byte.TryParse(m.Groups["type"].Value, out t08);
- r.SetByte(6, t08);
- Byte.TryParse(m.Groups["unq"].Value, out t08);
- flags = (t08 != 0) ? (int)invflags.unique : 0;
- Int16.TryParse(m.Groups["wear"].Value, out t16);
- r.SetInt16(7, t16);
- Int32.TryParse(m.Groups["tmr"].Value, out t32);
- r.SetInt32(8, t32);
- Int64.TryParse(m.Groups["cid"].Value, out t64);
- r.SetInt64(9, 0);
- if (items != null) for (int i = 0; i < items.Length; i++) flags |= fd[items[i]];
- r.SetInt32(1, flags);
- SqlContext.Pipe.Send(r);
- }
- }
- // GetInvEntry Procedure
- // Returns the row data for an inventory entry.
- [SqlProcedure]
- public static void ParseEquipment(string data)
- {
- SqlMetaData cObjectID = new SqlMetaData("ObjectID", SqlDbType.BigInt);
- SqlMetaData cFlags = new SqlMetaData("Flags", SqlDbType.Int);
- SqlMetaData cName = new SqlMetaData("Name", SqlDbType.VarChar, 128);
- SqlMetaData cLevel = new SqlMetaData("Level", SqlDbType.TinyInt);
- SqlMetaData cType = new SqlMetaData("Type", SqlDbType.TinyInt);
- SqlMetaData cWear = new SqlMetaData("Wear", SqlDbType.SmallInt);
- SqlMetaData cContainerID = new SqlMetaData("ContainerID", SqlDbType.BigInt);
- Dictionary<char, int> fd = new Dictionary<char, int>() { {'K', (int) invflags.keep },
- {'M', (int) invflags.magic},
- {'H', (int) invflags.hum },
- {'I', (int) invflags.invis},
- {'G', (int) invflags.glow },
- {'T', (int) invflags.temp } };
- SqlDataRecord r;
- Regex pattern = new Regex(@"(?<id>\d+),(?<iflgs>\w+),(?<name>\w+),(?<lvl>\d+),(?<type>\d+),(?<wear>-?\d+),(?<cid>\d+)");
- r = new SqlDataRecord(cObjectID, cFlags, cName, cLevel, cType, cWear, cContainerID);
- int flags = 0;
- Byte t08;
- Int16 t16;
- Int64 t64;
- Match m = pattern.Match(data);
- if (m.Success)
- {
- Int64.TryParse(m.Groups["id"].Value, out t64);
- r.SetInt64(0, t64);
- string items = m.Groups["iflgs"].Value;
- for (int i = 0; i < items.Length; i++) flags |= fd[items[i]];
- r.SetInt32(1, flags);
- r.SetString(2, m.Groups["name"].Value);
- Byte.TryParse(m.Groups["lvl"].Value, out t08);
- r.SetByte(3, t08);
- Byte.TryParse(m.Groups["type"].Value, out t08);
- r.SetByte(4, t08);
- Int16.TryParse(m.Groups["wear"].Value, out t16);
- r.SetInt16(5, t16);
- Int64.TryParse(m.Groups["cid"].Value, out t64);
- r.SetInt64(6, t64);
- SqlContext.Pipe.Send(r);
- }
- }
- }
- //This enum describes the items flags.
- [FlagsAttribute]
- enum invflags
- {
- None = 0, //no flags are set.
- keep = 1, //the item is kept.
- invis = 2, //the item is invisible.
- magic = 4, //the item is magic.
- glow = 8, //the item glows.
- hum = 16, //the item hums.
- temp = 32, //the item has a temporary timer.
- unique = 128, //the item has been marked as unique.
- ALL = keep | invis | magic | glow | hum | temp | unique
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement