Her er hele sourcen på den fil jeg har min klasse i, bare som et eksempel :
using System;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using RagingFury.EQ.SupportClasses;
[assembly:AssemblyKeyFile(@"C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Technologies\Interop\Applications\LoanApps\COMtoNET\loanlib\sample.snk")]
[assembly:AssemblyVersion("1.4.0.0")]
namespace EQComponent
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("EQ.Items")]
public class Items
{
private RFWS.ItemsWebservice ourRef = new RFWS.ItemsWebservice();
public string GetItemInfo(int ItemID)
{
string result = "";
string cookie = "";
string stats = "";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("
http://www.magelo.com/components/eq_item_info.jsp");
myRequest.AllowAutoRedirect = true;
myRequest.Referer = "
http://www.magelo.com/eq_item_info.html?num="+ItemID.ToString();
myRequest.CookieContainer = new CookieContainer(10);
HttpWebResponse ourResponse = (HttpWebResponse)myRequest.GetResponse();
Stream receiveStream = ourResponse.GetResponseStream();
StreamReader readStream = new StreamReader( receiveStream);//, encode );
foreach (Cookie thisCookie in myRequest.CookieContainer.GetCookies(new Uri("
http://www.magelo.com")))
if (thisCookie.Name == "JSESSIONID")
cookie = "Cookie: JSESSIONID="+thisCookie.Value;
Char[] read = new Char[256];
int count = readStream.Read( read, 0, 256 );
while (count > 0)
{
string str = new string(read, 0, count);
result += str;
count = readStream.Read(read, 0, 256);
}
ourResponse.Close();
Regex myReg;
Match myMatch;
myReg = new Regex(@"new item_struct\(\d+,\'(?<1>.*?)\',", RegexOptions.IgnoreCase|RegexOptions.Multiline);
string itemName = "";
for (myMatch = myReg.Match(result); myMatch.Success; myMatch = myMatch.NextMatch())
{
itemName = myMatch.Groups[1].Value;
if (itemName.Substring(itemName.Length-1, 1) == @"\")
itemName = "";
}
itemName = itemName.Replace(@"\'", "'");
// NAME AND COOKIE FOUND
myRequest = (HttpWebRequest)WebRequest.Create("
http://www.magelo.com/components/eq_item_shot.jsp?num="+ItemID.ToString());
myRequest.AllowAutoRedirect = true;
myRequest.Referer = "
http://www.magelo.com/eq_item_info.html?num="+ItemID.ToString();
myRequest.Headers.Add(cookie);
ourResponse = (HttpWebResponse)myRequest.GetResponse();
receiveStream = ourResponse.GetResponseStream();
readStream = new StreamReader( receiveStream);//, encode );
read = new Char[256];
count = readStream.Read( read, 0, 256 );
while (count > 0)
{
string str = new string(read, 0, count);
result += str;
count = readStream.Read(read, 0, 256);
}
ourResponse.Close();
result = result.Replace(" ", " ");
result = result.Replace("<br>", " ");
result = result.Replace(" ", " ");
result = result.Replace(" ", " ");
result = result.Replace("SV DISEASE", "SVD");
result = result.Replace("SV POISON", "SVP");
result = result.Replace("SV COLD", "SVC");
result = result.Replace("SV FIRE", "SVF");
result = result.Replace("SV MAGIC", "SVM");
myReg = new Regex(@"Slot: (?<1>.*)", RegexOptions.IgnoreCase|RegexOptions.Multiline);
myMatch = myReg.Match(result);
if (myMatch.Success)
stats = myMatch.Groups[1].Value;
myReg = new Regex(@"(?<1>Effect: <script type=""text/javascript"">if\(typeof\(spell_url\)!=""undefined""\) document\.write\(""<a href='""\+spell_url\+""\?num=\d+' target='_parent'>.*?</a>""\); else document.write\("")(?<2>.*?)(?<3>""\);</script>)", RegexOptions.IgnoreCase);
myMatch = myReg.Match(stats);
string effect = "";
string effectname = "";
if (myMatch.Success)
{
effect = myMatch.Groups[0].Value;
effectname = myMatch.Groups[2].Value;
stats = stats.Replace(effect, "Effect: "+effectname);
}
if (stats == "")
itemName = ((string)(itemName + " - not wearable.")).Trim().Replace(@"\'", "'");
else
itemName = ((string)(itemName + " - " + stats)).Trim().Replace(@"\'", "'");
return itemName;
}
public string GetSingleItem(string pattern)
{
RFWS.itemInfo[] itemID;
itemID = ourRef.GetItems(pattern);
if (itemID.Length == 0)
return "No item matching the given pattern was found";
return GetItemInfo(itemID[0].ItemID);
}
public string GetSingleItemWithCost(string pattern)
{
RFWS.itemInfo[] itemID;
itemID = ourRef.GetItems(pattern);
if (itemID.Length == 0)
return "No item matching the given pattern was found";
return GetItemInfo(itemID[0].ItemID)+" - Cost : " + itemID[0].ItemCost.ToString();
}
public string FindItems(string pattern)
{
RFWS.itemInfo[] itemID;
string result = "";
itemID = ourRef.GetItems(pattern);
if (itemID.Length == 0)
return "No item matching the given pattern was found";
for (int i = 0; i <= itemID.GetUpperBound(0); i++)
result += itemID[i].ItemID.ToString()+ " - " + itemID[i].ItemName + " (Cost : " + itemID[i].ItemCost.ToString() + ")<CR>";
return result;
}
public bool IsOfficer(string name)
{
return ourRef.IsOfficer(name);
}
public bool IsMember(string name)
{
return ourRef.IsMember(name);
}
public RFWS.dkpInfo DKPPoints(string name)
{
return ourRef.DKPPoints(name);
}
public string DKP(string names)
{
AdvancedSortedList ourList = new AdvancedSortedList();
ourList.KeyName = "Points";
string resultText = "";
string currentName = "";
int result;
int current = 0;
result = names.IndexOf(",", current, names.Length);
while (result >= 0)
{
currentName = names.Substring(0, result);
names = names.Substring(result+1, names.Length-result-1);
points = ourRef.DKPPoints(currentName.Trim());
ourList.Add(new dkpPerson(currentName.Trim(), 0, 0));
result = names.IndexOf(",", current, names.Length);
}
points = ourRef.DKPPoints(names.Trim());
ourList.Add(new dkpPerson(names.Trim(), 0,0));
foreach (dkpPerson ourPerson in ourList.GetEnumeratorWithSort("Points", true))
resultText += ourPerson.Name + ": " + ourPerson.Points.ToString() + "<CR>";
return resultText;
}
private class dkpPerson
{
private string name;
private int points;
private int totalPoints;
public dkpPerson(string name, int points, int totalPoints)
{
this.name = name;
this.points = points;
this.totalPoints = totalPoints;
}
public string Name
{
get
{
return name;
}
}
public int Points
{
get
{
return points;
}
}
public int TotalPoints
{
get
{
return totalPoints;
}
}
}
}
}
Skod kode men det virker til spillet :P