本文整理汇总了C#中db.Database.Verify方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Verify方法的具体用法?C# Database.Verify怎么用?C# Database.Verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.Verify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
List<ServerItem> filteredServers = null;
Account a = db.Verify(query["guid"], query["password"]);
if (a != null)
{
if (a.Banned)
{
filteredServers = YoureBanned();
}
else
{
filteredServers = GetServersForRank(a.Rank);
}
}
else
{
filteredServers = GetServersForRank(0);
}
var chrs = new Chars
{
Characters = new List<Char>(),
NextCharId = 2,
MaxNumChars = 1,
Account = db.Verify(query["guid"], query["password"]),
Servers = filteredServers
};
Account dvh = null;
if (chrs.Account != null)
{
db.GetCharData(chrs.Account, chrs);
db.LoadCharacters(chrs.Account, chrs);
chrs.News = db.GetNews(chrs.Account);
dvh = chrs.Account;
}
else
{
chrs.Account = Database.CreateGuestAccount(query["guid"]);
chrs.News = db.GetNews(null);
}
var ms = new MemoryStream();
var serializer = new XmlSerializer(chrs.GetType(),
new XmlRootAttribute(chrs.GetType().Name) {Namespace = ""});
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Encoding = Encoding.UTF8;
XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
serializer.Serialize(xtw, chrs, chrs.Namespaces);
db.Dispose();
}
}
示例2: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
else
{
try
{
status =
Encoding.UTF8.GetBytes(db.HttpGetGuildMembers(Convert.ToInt32(query["num"]),
Convert.ToInt32(query["offset"]), acc));
}
catch
{
status = Encoding.UTF8.GetBytes("<Error>Guild member error</Error>");
}
}
context.Response.OutputStream.Write(status, 0, status.Length);
context.Response.Close();
}
}
示例3: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (StreamReader rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
var acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
{
status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
}
else
{
var cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET password=SHA1(@password) WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@password", query["newPassword"]);
if (cmd.ExecuteNonQuery() > 0)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>");
}
context.Response.OutputStream.Write(status, 0, status.Length);
}
}
示例4: HandleRequest
protected override void HandleRequest()
{
using (Database db = new Database())
{
Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);
if (CheckAccount(acc, db))
{
if (acc.VerifiedEmail || !Program.Settings.GetValue<bool>("verifyEmail")) return;
string authKey = Database.GenerateRandomString(128);
var cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET [email protected], [email protected] WHERE [email protected];";
cmd.Parameters.AddWithValue("@newGuid", Query["newGuid"]);
cmd.Parameters.AddWithValue("@newAuthToken", authKey);
cmd.Parameters.AddWithValue("@oldGuid", Query["guid"]);
cmd.Parameters.AddWithValue("@password", Query["password"]);
cmd.ExecuteNonQuery();
MailMessage message = new MailMessage();
message.To.Add(Query["newGuid"]);
message.IsBodyHtml = true;
message.Subject = "Please verify your account.";
message.From = new MailAddress(Program.Settings.GetValue<string>("serverEmail", ""));
message.Body = "<center>Please verify your email via this <a href=\"" + Program.Settings.GetValue<string>("serverDomain", "localhost") + "/account/validateEmail?authToken=" + authKey + "\" target=\"_blank\">link</a>.</center>";
Program.SendEmail(message, true);
}
}
}
示例5: HandleRequest
protected override void HandleRequest()
{
using (var db = new Database())
{
var acc = db.Verify(Query["guid"], Query["password"]);
byte[] status;
if (acc == null)
{
status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
}
else
{
var cmd = db.CreateQuery();
object exescala;
cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE [email protected];";
cmd.Parameters.AddWithValue("@name", Query["name"]);
exescala = cmd.ExecuteScalar();
if (int.Parse(exescala.ToString()) > 0)
status = Encoding.UTF8.GetBytes("<Error>Duplicated name</Error>");
else
{
cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET [email protected], namechosen=TRUE WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@name", Query["name"]);
if (cmd.ExecuteNonQuery() != 0)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>");
}
}
Context.Response.OutputStream.Write(status, 0, status.Length);
}
}
示例6: HandleRequest
protected override void HandleRequest()
{
using (Database db = new Database())
{
try
{
Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);
string classType = Program.GameData.ObjectTypeToId[ushort.Parse(Query["classType"])];
if (CheckAccount(acc, db))
{
int price = Program.GameData.ObjectDescs[ushort.Parse(Query["classType"])].UnlockCost;
if (acc.Credits < price) return;
db.UpdateCredit(acc, -price);
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE unlockedclasses SET available='unrestricted' WHERE [email protected] AND [email protected];";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@class", classType);
cmd.ExecuteNonQuery();
}
}
catch (Exception e)
{
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
{
wtr.WriteLine("<Error>Invalid classType");
wtr.Flush();
wtr.WriteLine(e);
}
}
}
}
示例7: HandleRequest
public override void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database(Program.Settings.GetValue("conn")))
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
{
status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>");
}
else
{
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = "SELECT beginnerPackageTimeLeft FROM accounts WHERE [email protected]";
cmd.Parameters.AddWithValue("@uuid", query["guid"]);
object result = cmd.ExecuteScalar();
status = Encoding.UTF8.GetBytes("<BeginnerPackageTimeLeft>" + result + "</BeginnerPackageTimeLeft>");
}
context.Response.OutputStream.Write(status, 0, status.Length);
}
}
示例8: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (StreamReader rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database())
{
var acc = db.Verify(query["guid"], query["password"]);
if (acc == null)
{
var status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
context.Response.OutputStream.Write(status, 0, status.Length);
}
else
{
XmlSerializer serializer = new XmlSerializer(acc.GetType(), new XmlRootAttribute(acc.GetType().Name) { Namespace = "" });
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Encoding = Encoding.UTF8;
XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
serializer.Serialize(xtw, acc, acc.Namespaces);
}
}
}
示例9: HandleRequest
protected override void HandleRequest()
{
StreamWriter wtr = new StreamWriter(Context.Response.OutputStream);
if (Query.AllKeys.Length > 0)
{
using (Database db = new Database())
{
Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);
if (CheckAccount(acc, db, false))
{
foreach (ItemCostItem item in Prices)
{
if (item.Type == Query["skinType"] && item.Puchasable == 1)
{
if (!acc.OwnedSkins.Contains(int.Parse(Query["skinType"])))
{
acc.OwnedSkins.Add(int.Parse(Query["skinType"]));
db.UpdateCredit(acc, -item.Price);
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE accounts SET [email protected] WHERE [email protected] AND password=SHA1(@password)";
cmd.Parameters.AddWithValue("@ownedSkins",
Utils.GetCommaSepString(acc.OwnedSkins.ToArray()));
cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
cmd.Parameters.AddWithValue("@password", Query["password"]);
if (cmd.ExecuteNonQuery() == 0)
wtr.WriteLine("<Error>Unable to purchase</Error>");
}
}
}
}
}
}
}
示例10: HandleRequest
public override void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database(Program.Settings.GetValue("conn")))
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>");
else
{
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = @"DELETE FROM characters WHERE accId = @accId AND charId = @charId;";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@charId", query["charId"]);
if (cmd.ExecuteNonQuery() > 0)
status = Encoding.UTF8.GetBytes("<Success />");
else
status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>");
}
context.Response.OutputStream.Write(status, 0, status.Length);
}
}
示例11: HandleRequest
protected override void HandleRequest()
{
using (var db = new Database())
{
if (!IsUsername(Query["newGUID"])) WriteErrorLine("Invalid Username");
else
{
if (db.HasUuid(Query["guid"]) && db.Verify(Query["guid"], "") != null)
{
if (db.HasUuid(Query["newGUID"])) WriteErrorLine("Username is already taken");
else
{
var cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET [email protected], [email protected], password=SHA1(@password), guest=FALSE WHERE [email protected], [email protected];";
cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
cmd.Parameters.AddWithValue("@newUuid", Query["newGUID"]);
cmd.Parameters.AddWithValue("@password", Query["newPassword"]);
if (cmd.ExecuteNonQuery() > 0) Success();
else WriteErrorLine("Internal Error");
}
}
else
{
if (db.Register(Query["newGUID"], Query["newPassword"], false) != null) Success();
else WriteErrorLine("Internal Error");
}
}
}
}
示例12: GetChars
public Chars GetChars(string guid, string password, XmlData data)
{
using (var db = new Database())
{
Account a = db.Verify(guid, password, data);
if (a != null)
{
if (a.Banned)
return null;
}
Chars chrs = new Chars
{
Characters = new List<Char>(),
NextCharId = 2,
MaxNumChars = 1,
Account = a,
};
db.GetCharData(chrs.Account, chrs);
db.LoadCharacters(chrs.Account, chrs);
chrs.News = db.GetNews(Program.GameData, chrs.Account);
chrs.OwnedSkins = Utils.GetCommaSepString(chrs.Account.OwnedSkins.ToArray());
return chrs;
}
}
示例13: HandleRequest
public override void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database(Program.Settings.GetValue("conn")))
{
Account acc = db.Verify(query["guid"], query["password"]);
byte[] status;
if (acc == null)
status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>");
else
{
try
{
status = Encoding.UTF8.GetBytes(db.GetGuildBoard(acc));
}
catch (Exception e)
{
status = Encoding.UTF8.GetBytes("<Error>" + e.Message + "</Error>");
}
}
context.Response.OutputStream.Write(status, 0, status.Length);
}
}
示例14: HandleRequest
public void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (StreamReader rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db1 = new Database())
{
chrs = new Chars()
{
Characters = new List<Char>() { },
NextCharId = 2,
MaxNumChars = 1,
Account = db1.Verify(query["guid"], query["password"]),
Servers = new List<ServerItem>()
{
new ServerItem()
{
Name = "EUSouth",
Lat = 22.28,
Long = 114.16,
DNS = db.confreader.getservers(false).ToString(), //127.0.0.1, CHANGE THIS TO LET YOUR FRIENDS CONNECT
Usage = 0.2,
AdminOnly = false
}
//new ServerItem()
//{
// Name = "Admin Realm",
// Lat = 22.28,
// Long = 114.16,
// DNS = "127.0.0.1",
// Usage = 0.2,
// AdminOnly = true
//}
}
};
if (chrs.Account != null)
{
db1.GetCharData(chrs.Account, chrs);
db1.LoadCharacters(chrs.Account, chrs);
chrs.News = db1.GetNews(chrs.Account);
}
else
{
chrs.Account = Database.CreateGuestAccount(query["guid"]);
chrs.News = db1.GetNews(null);
}
MemoryStream ms = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(chrs.GetType(), new XmlRootAttribute(chrs.GetType().Name) { Namespace = "" });
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Encoding = Encoding.UTF8;
XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
serializer.Serialize(xtw, chrs, chrs.Namespaces);
}
}
示例15: HandleRequest
protected override void HandleRequest()
{
string result = "";
using (Database dbx = new Database())
{
Account acc = dbx.Verify(Query["guid"], Query["password"], Program.GameData);
if (String.IsNullOrEmpty(Query["guid"]) ||
String.IsNullOrEmpty(Query["password"]) ||
String.IsNullOrEmpty(Query["type"]) ||
acc == null)
{
Context.Response.StatusCode = 400;
result = "<Error>Invalid GUID/password combination</Error>";
}
else
{
string[][] ranks = dbx.GetArenaLeaderboards(Query["type"], acc);
result += "<ArenaRecords>";
foreach (string[] i in ranks)
{
MySqlCommand cmd = dbx.CreateQuery();
cmd.CommandText = "select skin, tex1, tex2, items, charType, petId from characters where charid = @charid";
cmd.Parameters.AddWithValue("@charid", i[2]);
string skin, tex1, tex2, inventory, cclass, petid;
skin = tex1 = tex2 = inventory = cclass = petid = null;
using (MySqlDataReader drdr = cmd.ExecuteReader())
{
while (drdr.Read())
{
skin = drdr.GetString("skin");
tex1 = drdr.GetString("tex1");
tex2 = drdr.GetString("tex2");
inventory = drdr.GetString("items");
cclass = drdr.GetString("charType");
petid = drdr.GetString("petId");
}
}
var _pet = dbx.GetPet(int.Parse(petid), acc);
result += $"<Record><WaveNumber>{i[0]}</WaveNumber><Time>{i[4]}</Time><PlayData><CharacterData>";
if (acc.Guild.Name != null) result += [email protected]"<GuildName>{acc.Guild.Name}</GuildName><GuildRank>{acc.Guild.Rank}</GuildRank>";
result += $"<Id>{i[2]}</Id><Texture>{skin}</Texture><Tex1>{tex1}</Tex1><Tex2>{tex2}</Tex2><Inventory>{inventory}</Inventory><Name>{acc.Name}</Name><Class>{cclass}</Class></CharacterData>";
result += "<Pet name=\"" + _pet.SkinName + "\" type=\"" + _pet.Type + "\" instanceId=\"" + _pet.InstanceId + "\" rarity=\"" + _pet.Rarity + "\" maxAbilityPower=\"" + _pet.MaxAbilityPower + "\" skin=\"" + _pet.Skin + "\" family=\"" + "Farm" + "\"><Abilities>";
for (int e = 0; e < 3; e++)
result += "<Ability type=\"" + _pet.Abilities[e].Type + "\" power=\"" + _pet.Abilities[e].Power + "\" points=\"" + _pet.Abilities[e].Points + "\"/>";
result += "</Abilities></Pet></PlayData></Record>";
}
result += "</ArenaRecords>";
}
}
byte[] buf = Encoding.UTF8.GetBytes(result);
Context.Response.ContentType = "text/*";
Context.Response.OutputStream.Write(buf, 0, buf.Length);
}