本文整理匯總了C#中TShockAPI.DB.User類的典型用法代碼示例。如果您正苦於以下問題:C# User類的具體用法?C# User怎麽用?C# User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
User類屬於TShockAPI.DB命名空間,在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SendEmail
public static void SendEmail(TSPlayer player, string email, User user)
{
MailMessage mail = new MailMessage(AccountRecovery.Config.EmailFrom, email);
SmtpClient client = new SmtpClient();
client.Timeout = 15000;
client.Host = AccountRecovery.Config.HostSMTPServer;
client.Port = AccountRecovery.Config.HostPort;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(AccountRecovery.Config.ServerEmailAddress, AccountRecovery.Config.ServerEmailPassword);
client.EnableSsl = true;
//client.ServicePoint.MaxIdleTime = 1;
mail.Subject = AccountRecovery.Config.EmailSubjectLine;
mail.Body = AccountRecovery.Config.EmailBodyLine;
mail.IsBodyHtml = AccountRecovery.Config.UseHTML;
string passwordGenerated = GeneratePassword(AccountRecovery.Config.GeneratedPasswordLength);
TShock.Users.SetUserPassword(user, passwordGenerated);
TShock.Log.ConsoleInfo("{0} has requested a new password succesfully.", user.Name);
mail.Body = string.Format(mail.Body.Replace("$NEW_PASSWORD", passwordGenerated));
mail.Body = string.Format(mail.Body.Replace("$USERNAME", user.Name));
client.Send(mail);
client.Dispose();
player.SendSuccessMessage("A new password has been generated and sent to {0} for {1}.", email, user.Name);
TShock.Log.ConsoleInfo("A new password has been generated and sent to {0} for {1}.", email, user.Name);
}
示例2: AddAsync
public async Task<bool> AddAsync(User user, DateTime expiration)
{
return await Task.Run(() =>
{
syncLock.EnterWriteLock();
try
{
return db.Query("INSERT INTO Mutes VALUES (@0, @1, @2, @3, @4, @5)",
null,
user.Name,
user.UUID,
JsonConvert.DeserializeObject<List<string>>(user.KnownIps)[0],
DateTime.UtcNow.ToString("s"),
expiration.ToString("s")) > 0;
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
return false;
}
finally
{
syncLock.ExitWriteLock();
}
});
}
示例3: OnAccountDelete
public static void OnAccountDelete(User u)
{
if (AccountDelete == null)
return;
AccountDelete(new AccountDeleteEventArgs(u));
}
示例4: ChangeGroup
public bool ChangeGroup(object Player, object Group)
{
TShockAPI.TSPlayer p = null;
TShockAPI.DB.User u = new TShockAPI.DB.User();
string g = "";
if ((p = GetPlayer(Player)) == null) {
return false;
}
if (Group is string) {
g = Group as string;
} else if (Group is TShockAPI.Group) {
g = (Group as TShockAPI.Group).Name;
}
if (string.IsNullOrEmpty(g) == true) {
return false;
}
try {
u.Name = p.User.Name;
TShockAPI.TShock.Users.SetUserGroup(u, g);
} catch (Exception ex) {
ScriptLog.ErrorFormat("tshock_change_group", "Group change failed: {0}", ex.Message);
return false;
}
return true;
}
示例5: RemoteClient_PacketReceived
private void RemoteClient_PacketReceived(Client sender, Client.PacketReceivedEventArgs e)
{
PacketType packetType = (PacketType)e.Reader.ReadInt16();
//Disconnect the user if he attempts to do anything else before authenticating.
if (packetType != PacketType.Authenticate && !Authenticated)
{
Disconnect("Your attempt at sending packets before authenticating has been ignored!");
return;
}
switch (packetType)
{
case PacketType.Authenticate:
InterfaceType = (InterfaceType)e.Reader.ReadByte();
int major = e.Reader.ReadInt32();
int minor = e.Reader.ReadInt32();
if (Rtc.buildVersion.Major != major || Rtc.buildVersion.Minor != minor)
{
Disconnect($"Your version ({major}.{minor}) is incompatible with the server's version ({Rtc.buildVersion.Major}.{Rtc.buildVersion.Minor}).");
return;
}
string Username = e.Reader.ReadString();
string Password = e.Reader.ReadString();
TSUser = TShock.Users.GetUserByName(Username);
if (TSUser == null || !TSUser.VerifyPassword(Password))
{
Disconnect("Invalid username/password or insufficient privileges.");
return;
}
Group g = TShock.Groups.GetGroupByName(TSUser.Group);
if (!g.HasPermission("*"))
{
Disconnect("Invalid username/password or insufficient privileges.");
return;
}
Authenticated = true;
Packet pck = new Packet((short)PacketType.MessageBuffer, (short)Rtc.MessagesBuffer.Length);
for (int i = 0; i < Rtc.MessagesBuffer.Length; i++)
{
if (!string.IsNullOrEmpty(Rtc.MessagesBuffer[i]))
pck.Write(Rtc.ColorBuffer[i], Rtc.MessagesBuffer[i]);
}
sender.Send(pck);
break;
case PacketType.Input:
string text = e.Reader.ReadString();
Rtc.ConsoleInput.SendText(text);
break;
}
}
示例6: InsertTradeLog
public static bool InsertTradeLog(User trader, User tradee, string traderItems, string tradeeItems, DateTime tradeDate)
{
try
{
return TShock.CharacterDB.database.Query("INSERT INTO TradeRequestLogs (Trader, Tradee, TraderItems, TradeeItems, TradeDate) VALUES (@0, @1, @2, @3, @4);", trader.Name, tradee.Name, traderItems, tradeeItems, tradeDate.ToString("s")) != 0;
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
}
return false;
}
示例7: GetUserTradeLogs
public static IList<string> GetUserTradeLogs(User user, bool recent)
{
try
{
if(recent)
{
using (var reader = TShock.DB.QueryReader("SELECT * FROM TradeRequestLogs ORDER BY TradeRequestLogs.TradeDate DESC LIMIT 20"))
{
IList<string> results = new List<string>();
while (reader.Read())
{
string trader = reader.Get<String>("Trader");
string tradee = reader.Get<String>("Tradee");
string traderItems = reader.Get<String>("TraderItems");
string tradeeItems = reader.Get<String>("TradeeItems");
string tradeDate = reader.Get<String>("TradeDate");
results.Add(string.Format("{0} - {1} {2} <-> {3} {4}", DateTime.Parse(tradeDate), trader, traderItems, tradeeItems, tradee));
}
return results;
}
}
else
{
// using (var reader = TShock.DB.QueryReader("SELECT * FROM TradeRequestLogs WHERE Trader LIKE '%@0%' OR Tradee LIKE '%@1%'", user.Name, user.Name))
using (var reader = TShock.DB.QueryReader("SELECT * FROM TradeRequestLogs WHERE [email protected] OR [email protected]", user.Name, user.Name))
{
IList<string> results = new List<string>();
while (reader.Read())
{
string trader = reader.Get<String>("Trader");
string tradee = reader.Get<String>("Tradee");
string traderItems = reader.Get<String>("TraderItems");
string tradeeItems = reader.Get<String>("TradeeItems");
string tradeDate = reader.Get<String>("TradeDate");
results.Add(string.Format("{0} - {1} {2} <-> {3} {4}", DateTime.Parse(tradeDate), trader, traderItems, tradeeItems, tradee));
}
return results;
}
}
}
catch (Exception ex)
{
TShock.Log.ConsoleError("FetchHashedPasswordAndGroup SQL returned an error: " + ex);
}
return null;
}
示例8: AddUser
/// <summary>
/// Adds a given username to the database
/// </summary>
/// <param name="user">User user</param>
public void AddUser(User user)
{
if (!TShock.Groups.GroupExists(user.Group))
throw new GroupNotExistsException(user.Group);
int ret;
try
{
ret = _database.Query("INSERT INTO Users (Username, Password, UUID, UserGroup, Registered) VALUES (@0, @1, @2, @3, @4);", user.Name,
user.Password, user.UUID, user.Group, DateTime.UtcNow.ToString("s"));
}
catch (Exception ex)
{
// Detect duplicate user using a regexp as Sqlite doesn't have well structured exceptions
if (Regex.IsMatch(ex.Message, "Username.*not unique"))
throw new UserExistsException(user.Name);
throw new UserManagerException("AddUser SQL returned an error (" + ex.Message + ")", ex);
}
if (1 > ret)
throw new UserExistsException(user.Name);
Hooks.AccountHooks.OnAccountCreate(user);
}
示例9: AddUser
/// <summary>
/// Adds a given username to the database
/// </summary>
/// <param name="user">User user</param>
public void AddUser(User user)
{
if (!TShock.Groups.GroupExists(user.Group))
throw new GroupNotExistsException(user.Group);
int ret;
try
{
ret = database.Query("INSERT INTO Users (Username, Password, UserGroup) VALUES (@0, @1, @2);", user.Name,
TShock.Utils.HashPassword(user.Password), user.Group);
}
catch (Exception ex)
{
// Detect duplicate user using a regexp as Sqlite doesn't have well structured exceptions
if (Regex.IsMatch(ex.Message, "Username.*not unique"))
throw new UserExistsException(user.Name);
throw new UserManagerException("AddUser SQL returned an error (" + ex.Message + ")", ex);
}
if (1 > ret)
throw new UserExistsException(user.Name);
}
示例10: SeedInitialData
public bool SeedInitialData(User user)
{
var inventory = new StringBuilder();
var items = new List<NetItem>(TShock.ServerSideCharacterConfig.StartingInventory);
if (items.Count < NetItem.MaxInventory)
items.AddRange(new NetItem[NetItem.MaxInventory - items.Count]);
string initialItems = String.Join("~", items.Take(NetItem.MaxInventory));
try
{
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8);",
user.ID,
TShock.ServerSideCharacterConfig.StartingHealth,
TShock.ServerSideCharacterConfig.StartingHealth,
TShock.ServerSideCharacterConfig.StartingMana,
TShock.ServerSideCharacterConfig.StartingMana,
initialItems,
-1,
-1,
0);
return true;
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
}
return false;
}
示例11: AccountCreateEventArgs
public AccountCreateEventArgs(User user)
{
this.User = user;
}
示例12: ManageUsers
//Todo: Add separate help text for '/user add' and '/user del'. Also add '/user addip' and '/user delip'
private static void ManageUsers(CommandArgs args)
{
// This guy needs to go away for the help later on to take effect.
//if (args.Parameters.Count < 2)
//{
// args.Player.SendMessage("Syntax: /user <add/del> <ip/user:pass> [group]");
// args.Player.SendMessage("Note: Passwords are stored with SHA512 hashing. To reset a user's password, remove and re-add them.");
// return;
//}
// This guy needs to be here so that people don't get exceptions when they type /user
if (args.Parameters.Count < 1)
{
args.Player.SendMessage("Invalid user syntax. Try /user help.", Color.Red);
return;
}
string subcmd = args.Parameters[0];
// Add requires a username:password pair/ip address and a group specified.
if (subcmd == "add")
{
var namepass = args.Parameters[1].Split(':');
var user = new User();
try
{
if (args.Parameters.Count > 2)
{
if (namepass.Length == 2)
{
user.Name = namepass[0];
user.Password = namepass[1];
user.Group = args.Parameters[2];
}
else if (namepass.Length == 1)
{
user.Address = namepass[0];
user.Group = args.Parameters[2];
user.Name = user.Address;
}
if (!string.IsNullOrEmpty(user.Address))
{
args.Player.SendMessage("IP address admin added. If they're logged in, tell them to rejoin.", Color.Green);
args.Player.SendMessage("WARNING: This is insecure! It would be better to use a user account instead.", Color.Red);
TShock.Users.AddUser(user);
Log.ConsoleInfo(args.Player.Name + " added IP " + user.Address + " to group " + user.Group);
}
else
{
args.Player.SendMessage("Account " + user.Name + " has been added to group " + user.Group + "!", Color.Green);
TShock.Users.AddUser(user);
Log.ConsoleInfo(args.Player.Name + " added Account " + user.Name + " to group " + user.Group);
}
}
else
{
args.Player.SendMessage("Invalid syntax. Try /user help.", Color.Red);
}
}
catch (UserManagerException ex)
{
args.Player.SendMessage(ex.Message, Color.Green);
Log.ConsoleError(ex.ToString());
}
}
// User deletion requires a username
else if (subcmd == "del" && args.Parameters.Count == 2)
{
var user = new User();
if (args.Parameters[1].Contains("."))
user.Address = args.Parameters[1];
else
user.Name = args.Parameters[1];
try
{
TShock.Users.RemoveUser(user);
args.Player.SendMessage("Account removed successfully.", Color.Green);
Log.ConsoleInfo(args.Player.Name + " successfully deleted account: " + args.Parameters[1]);
}
catch (UserManagerException ex)
{
args.Player.SendMessage(ex.Message, Color.Red);
Log.ConsoleError(ex.ToString());
}
}
// Password changing requires a username, and a new password to set
else if (subcmd == "password")
{
var user = new User();
user.Name = args.Parameters[1];
try
{
if (args.Parameters.Count == 3)
{
//.........這裏部分代碼省略.........
示例13: SetUserGroup
/// <summary>
/// Sets the group for a given username
/// </summary>
/// <param name="user">User user</param>
/// <param name="group">string group</param>
public void SetUserGroup(User user, string group)
{
try
{
Group grp = TShock.Groups.GetGroupByName(group);
if (null == grp)
throw new GroupNotExistsException(group);
if (database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0)
throw new UserNotExistException(user.Name);
// Update player group reference for any logged in player
foreach (var player in TShock.Players.Where(p => null != p && p.UserAccountName == user.Name))
{
player.Group = grp;
}
}
catch (Exception ex)
{
throw new UserManagerException("SetUserGroup SQL returned an error", ex);
}
}
示例14: DeleteAsync
public async Task<bool> DeleteAsync(User user)
{
return await Task.Run(() =>
{
syncLock.EnterWriteLock();
string query = db.GetSqlType() == SqlType.Mysql ?
"DELETE FROM Mutes WHERE UUID = @0 OR IP = @1 ORDER BY ID DESC LIMIT 1" :
"DELETE FROM Mutes WHERE ID IN (SELECT ID FROM Mutes WHERE UUID = @0 OR IP = @1 ORDER BY ID DESC LIMIT 1)";
try
{
return db.Query(query, user.UUID, JsonConvert.DeserializeObject<List<string>>(user.KnownIps)[0]) > 0;
}
catch (Exception ex)
{
TShock.Log.Error(ex.ToString());
return false;
}
finally
{
syncLock.ExitWriteLock();
}
});
}
示例15: SetUserGroup
/// <summary>
/// Sets the group for a given username
/// </summary>
/// <param name="user">User user</param>
/// <param name="group">string group</param>
public void SetUserGroup(User user, string group)
{
try
{
if (!TShock.Groups.GroupExists(group))
throw new GroupNotExistsException(group);
if (database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0)
throw new UserNotExistException(user.Name);
}
catch (Exception ex)
{
throw new UserManagerException("SetUserGroup SQL returned an error", ex);
}
}