本文整理汇总了C#中db.Database类的典型用法代码示例。如果您正苦于以下问题:C# Database类的具体用法?C# Database怎么用?C# Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Database类属于db命名空间,在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
开发者ID:rotmgkillroyx,项目名称:rotmg_svr_OLD,代码行数:28,代码来源:changePassword.cs
示例2: 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);
}
}
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:26,代码来源:getBoard.cs
示例3: 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>");
}
}
}
}
}
}
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:35,代码来源:purchaseSkin.cs
示例4: HandleRequest
protected override void HandleRequest()
{
using (var db = new Database())
{
if (Account == null) BadLogin();
else
{
var cmd = db.CreateQuery();
cmd.CommandText = "SELECT fame FROM stats WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", Account.AccountId);
if ((int)cmd.ExecuteScalar() < 5000) WriteErrorLine("Not enough fame");
else
{
cmd = db.CreateQuery();
cmd.CommandText = "UPDATE stats set fame = MIN(fame - 5000, 0) WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", Account.AccountId);
if (cmd.ExecuteNonQuery() > 0)
{
cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET maxCharSlot = maxCharSlot + 1 WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", Account.AccountId);
if (cmd.ExecuteNonQuery() > 0) Success();
else WriteErrorLine("Internal Error");
}
else WriteErrorLine("Internal Error");
}
}
}
}
开发者ID:BlackRayquaza,项目名称:PhoenixRealms,代码行数:29,代码来源:purchaseCharSlot.cs
示例5: 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);
}
}
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:26,代码来源:delete.cs
示例6: 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();
}
}
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:60,代码来源:list.cs
示例7: 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;
}
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:25,代码来源:list.cs
示例8: IsUserInLegends
public bool IsUserInLegends()
{
//Week
using (var db = new Database())
{
var cmd = db.CreateQuery();
cmd.CommandText = "SELECT * FROM death WHERE (time >= DATE_SUB(NOW(), INTERVAL 1 WEEK)) ORDER BY totalFame DESC LIMIT 10;";
using (var rdr = cmd.ExecuteReader())
while (rdr.Read())
if (rdr.GetString("accId") == AccountId) return true;
}
//Month
using (var db = new Database())
{
var cmd = db.CreateQuery();
cmd.CommandText = "SELECT * FROM death WHERE (time >= DATE_SUB(NOW(), INTERVAL 1 MONTH)) ORDER BY totalFame DESC LIMIT 10;";
using (var rdr = cmd.ExecuteReader())
while (rdr.Read())
if (rdr.GetString("accId") == AccountId) return true;
}
//All Time
using (var db = new Database())
{
var cmd = db.CreateQuery();
cmd.CommandText = "SELECT * FROM death WHERE TRUE ORDER BY totalFame DESC LIMIT 10;";
using (var rdr = cmd.ExecuteReader())
while (rdr.Read())
if (rdr.GetString("accId") == AccountId) return true;
}
return false;
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:33,代码来源:Player.List.cs
示例9: 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);
}
}
开发者ID:BlackRayquaza,项目名称:MMOE,代码行数:34,代码来源:setName.cs
示例10: CheckAccount
public bool CheckAccount(Account acc, Database db, bool checkAccInUse=true)
{
if (acc == null && !String.IsNullOrWhiteSpace(Query["password"]))
{
WriteErrorLine("Account credentials not valid");
return false;
}
else if (acc == null && String.IsNullOrWhiteSpace(Query["password"]))
return true;
if (acc.Banned)
{
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
wtr.WriteLine("<Error>Account under maintenance</Error>");
Context.Response.Close();
return false;
}
if (checkAccInUse)
{
int? timeout = 0;
if (db.CheckAccountInUse(acc, ref timeout))
{
if (timeout != null)
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
wtr.WriteLine("<Error>Account in use. (" + timeout + " seconds until timeout.)</Error>");
else
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
wtr.WriteLine("<Error>Account in use.</Error>");
Context.Response.Close();
return false;
}
}
return true;
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:35,代码来源:RequestHandlers.cs
示例11: GetGlobalNews
private List<globalNews_struct> GetGlobalNews(Database db)
{
List<globalNews_struct> ret = new List<globalNews_struct>();
var cmd = db.CreateQuery();
cmd.CommandText = "SELECT * FROM globalNews WHERE endTime >= now();";
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
ret.Add(new globalNews_struct
{
slot = rdr.GetInt32("slot"),
linkType = rdr.GetInt32("linkType"),
title = rdr.GetString("title"),
image = rdr.GetString("image"),
priority = rdr.GetInt32("priority"),
linkDetail = rdr.GetString("linkDetail"),
platform = rdr.GetString("platform"),
startTime = long.Parse(Database.DateTimeToUnixTimestamp(rdr.GetDateTime("startTime")).ToString() + "000"),
endTime = long.Parse(Database.DateTimeToUnixTimestamp(rdr.GetDateTime("endTime")).ToString() + "000")
});
}
}
return ret;
}
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:26,代码来源:globalNews.cs
示例12: HandleRequest
protected override void HandleRequest()
{
using (Database db = new Database())
{
Account acc = db.GetAccount(Query["accountId"], Program.GameData);
Char chr = db.LoadCharacter(acc, int.Parse(Query["charId"]));
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE [email protected] AND [email protected];";
cmd.Parameters.AddWithValue("@accId", Query["accountId"]);
cmd.Parameters.AddWithValue("@charId", Query["charId"]);
int time;
string killer;
bool firstBorn;
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
rdr.Read();
time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
killer = rdr.GetString("killer");
firstBorn = rdr.GetBoolean("firstBorn");
}
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
wtr.Write(chr.FameStats.Serialize(Program.GameData, acc, chr, time, killer, firstBorn));
}
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:26,代码来源:fame.cs
示例13: FreeDatabase
public void FreeDatabase(Database db)
{
lock (requestLock)
{
databases[db] = true;
}
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:7,代码来源:DatabaseTicker.cs
示例14: 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();
}
}
开发者ID:RiiggedMPGH,项目名称:Owl-Realms-Source,代码行数:29,代码来源:listMembers.cs
示例15: 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);
}
}
}
}
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:34,代码来源:purchaseClassUnlock.cs
示例16: Main
private static void Main(string[] args)
{
XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_server.config"));
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.Name = "Entry";
Database = new Database();
GameData = new XmlData();
InstanceId = Guid.NewGuid().ToString();
Console.CancelKeyPress += (sender, e) => e.Cancel = true;
if (RunPreCheck(port))
{
listener = new HttpListener();
listener.Prefixes.Add($"http://*:{port}/");
listener.Start();
listener.BeginGetContext(ListenerCallback, null);
Logger.Info($"Listening at port {port}...");
}
else
Logger.Error($"Port {port} is occupied");
while (Console.ReadKey(true).Key != ConsoleKey.Escape) ;
Logger.Info("Terminating...");
while (currentRequests.Count > 0) ;
listener?.Stop();
}
开发者ID:BlackRayquaza,项目名称:PhoenixRealms,代码行数:30,代码来源:Program.cs
示例17: Buy
public virtual void Buy(Player player)
{
if (ObjectType == 0x0505) //Vault chest
{
//if (new Database().ReadVault(player.Client.Account).Chests.Count < 64)
//{
if (TryDeduct(player))
{
var chest = new Database().CreateChest(player.Client.Account);
(Owner as Vault).AddChest(chest, this);
player.Client.SendPacket(new BuyResultPacket()
{
Result = 0,
Message = "Vault Chest Get!"
});
}
else
player.Client.SendPacket(new BuyResultPacket()
{
Result = BUY_NO_FAME,
Message = "Not enough fame!"
});
/*}
else
{
player.Client.SendPacket(new BuyResultPacket()
{
Result = 0,
Message = "You have a full vault!"
});
}*/
}
}
开发者ID:Club559,项目名称:Mining,代码行数:33,代码来源:SellableObject.cs
示例18: 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);
}
}
}
开发者ID:lcnvdl,项目名称:rotmg-server,代码行数:26,代码来源:verify.cs
示例19: 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);
}
}
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:26,代码来源:getBeginnerPackageTimeLeft.cs
示例20: HandleRequest
protected override void HandleRequest()
{
using (Database db = new Database())
{
string authKey = Database.GenerateRandomString(128);
var cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET [email protected] WHERE [email protected];";
cmd.Parameters.AddWithValue("@authToken", authKey);
cmd.Parameters.AddWithValue("@email", Query["guid"]);
if (cmd.ExecuteNonQuery() == 1)
{
MailMessage message = new MailMessage();
message.To.Add(Query["guid"]);
message.Subject = "Forgot Password";
message.From = new MailAddress(Program.Settings.GetValue<string>("serverEmail", ""), "Forgot Passowrd");
message.Body = emailBody.
Replace("{RPLINK}", String.Format("{0}/{1}{2}", Program.Settings.GetValue<string>("serverDomain", "localhost"), "account/resetPassword?authToken=", authKey)).
Replace("{SUPPORTLINK}", String.Format("{0}", Program.Settings.GetValue<string>("supportLink", "localhost"))).
Replace("{SERVERDOMAIN}", Program.Settings.GetValue<string>("serverDomain", "localhost"));
Program.SendEmail(message, true);
}
else
using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
wtr.Write("<Error>Error.accountNotFound</Error>");
}
}
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:27,代码来源:forgotPassword.cs
注:本文中的db.Database类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论