diff --git a/Build/TerrariaServer.XML b/Build/TerrariaServer.XML deleted file mode 100644 index 1b7deea8..00000000 --- a/Build/TerrariaServer.XML +++ /dev/null @@ -1,90 +0,0 @@ - - - - TerrariaServer - - - - - Hooks interface - - - - - List of players - - - - - See generic HandlerList - - - - - Works like an event. Allows for registering delegates with a higher or lower priority. - - - - - - Register a handler - - Delegate to be called - Priority of the delegate - Should the handler receive a call even if it has been handled - - - - Attempts to damage the player. - - int - how much damage to give - - - - Sends message to specified player - - string - text to send - Color - color for the text - - - - Meant to only be used by TServer. - - - - - The character name of the player. - - - - - Return a list of interfaces this plugin exposes. - - - - - - Called before initialize passing all the interfaces gathered from plugins - - - - - - Gets the T interface from the collection. Returns null if its not found. - - - - - - - - Called when the player first connects. They are not fully in the game yet, for that see Greet. - - - - - Called when the player is actually loaded into the game. - - - - diff --git a/CONTRIBUTING b/CONTRIBUTING deleted file mode 100644 index 095ad8ea..00000000 --- a/CONTRIBUTING +++ /dev/null @@ -1,36 +0,0 @@ -### Issue Guidelines -Please follow these simple requirements before posting an issue: - -1. TShock version number -2. Any stack traces that may have happened when the issue occurred -3. How to reproduce the issue - -### Pull Request Dev Guidelines - -These guidelines are for contributors. If you do not follow these guidelines your commits will be reverted. - -Required: -- Follow the code style. We generally use microsofts except for m_ infront of private variables. -- Do not push unfinished features to the master branch, instead create a remote branch and push to that. -- Do not push untested code to the master branch, instead push to the test branch. -- Document all compatibility issues in the COMPATIBILITY file. (IE file formats changing) -- DO NOT MASS COMMIT. Commit changes as you go (without pushing). That way when you push we don't get a thousand changes with a 1-3 line commit message. - -Optional: -- Build Version Increment (http://autobuildversion.codeplex.com/). - ----- - -### Dev Team Guidelines - -These guidelines are to be followed by all developers with commit level access to this repository: - -- Do not, for any reason, submit code to the master branch before it hits the development branch first. If the development branch is far ahead, and a new bug fix is going out, branch master, then merge with master and remove your branch. - - If you are found to do this, you will be the person merging and rebasing your code to fit general-devel. -- Prior to posting any version on the website, you must tick the version in AssemblyInfo.cs. This is the versioning formula: - - Major.Minor.Revision.BuildDate (tick Revision if you're fixing prior to an actual planned release) -- Do not release any development builds on the forums without consulting another developer first. -- __Document code prior to marking it done in JIRA__ -- Move any un-tested code to the "Needs Validation" section on JIRA prior to marking it as done. -- Do not push changes to any branch without a proper issue being assigned in JIRA. If a feature isn't planned for this release, __it shouldn't be in the repo about to be released__. -- Submit all pull requests to the general-devel branch prior to the master branch, or you will be ignored. \ No newline at end of file diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 7837af80..ec378ae0 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -910,28 +910,36 @@ namespace TShockAPI { var user = new User(); - try + if (args.Parameters.Count == 4) { - if (args.Parameters.Count == 4) + user.Name = args.Parameters[1]; + user.Password = args.Parameters[2]; + user.Group = args.Parameters[3]; + + try { - user.Name = args.Parameters[1]; - user.Password = args.Parameters[2]; - user.Group = args.Parameters[3]; - - args.Player.SendSuccessMessage("Account " + user.Name + " has been added to group " + user.Group + "!"); TShock.Users.AddUser(user); TShock.CharacterDB.SeedInitialData(TShock.Users.GetUser(user)); + args.Player.SendSuccessMessage("Account " + user.Name + " has been added to group " + user.Group + "!"); Log.ConsoleInfo(args.Player.Name + " added Account " + user.Name + " to group " + user.Group); } - else + catch (GroupNotExistsException e) { - args.Player.SendErrorMessage("Invalid syntax. Try /user help."); + args.Player.SendErrorMessage("Group " + user.Group + " does not exist!"); + } + catch (UserExistsException e) + { + args.Player.SendErrorMessage("User " + user.Name + " already exists!"); + } + catch (UserManagerException e) + { + args.Player.SendErrorMessage("User " + user.Name + " could not be added, check console for details."); + Log.ConsoleError(e.ToString()); } } - catch (UserManagerException ex) + else { - args.Player.SendErrorMessage(ex.Message); - Log.ConsoleError(ex.ToString()); + args.Player.SendErrorMessage("Invalid syntax. Try /user help."); } } // User deletion requires a username @@ -946,60 +954,77 @@ namespace TShockAPI args.Player.SendSuccessMessage("Account removed successfully."); Log.ConsoleInfo(args.Player.Name + " successfully deleted account: " + args.Parameters[1] + "."); } + catch (UserNotExistException e) + { + args.Player.SendErrorMessage("The user " + user.Name + " does not exist! Deleted nobody!"); + } 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 + + // 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) { - if (args.Parameters.Count == 3) + try { - args.Player.SendSuccessMessage("Password change succeeded for " + user.Name + "."); TShock.Users.SetUserPassword(user, args.Parameters[2]); Log.ConsoleInfo(args.Player.Name + " changed the password of account " + user.Name); + args.Player.SendSuccessMessage("Password change succeeded for " + user.Name + "."); } - else + catch (UserNotExistException e) { - args.Player.SendErrorMessage("Invalid user password syntax. Try /user help."); + args.Player.SendErrorMessage("User " + user.Name + " does not exist!"); + } + catch (UserManagerException e) + { + args.Player.SendErrorMessage("Password change for " + user.Name + " failed! Check console!"); + Log.ConsoleError(e.ToString()); } } - catch (UserManagerException ex) + else { - args.Player.SendErrorMessage(ex.Message); - Log.ConsoleError(ex.ToString()); + args.Player.SendErrorMessage("Invalid user password syntax. Try /user help."); } } - // Group changing requires a username or IP address, and a new group to set + // Group changing requires a username or IP address, and a new group to set else if (subcmd == "group") { - var user = new User(); - user.Name = args.Parameters[1]; + var user = new User(); + user.Name = args.Parameters[1]; - try + if (args.Parameters.Count == 3) { - if (args.Parameters.Count == 3) + try { - args.Player.SendSuccessMessage("Account " + user.Name + " has been changed to group " + args.Parameters[2] + "!"); TShock.Users.SetUserGroup(user, args.Parameters[2]); Log.ConsoleInfo(args.Player.Name + " changed account " + user.Name + " to group " + args.Parameters[2] + "."); + args.Player.SendSuccessMessage("Account " + user.Name + " has been changed to group " + args.Parameters[2] + "!"); } - else + catch (GroupNotExistsException e) { - args.Player.SendErrorMessage("Invalid user group syntax. Try /user help."); + args.Player.SendErrorMessage("That group does not exist!"); } + catch (UserNotExistException e) + { + args.Player.SendErrorMessage("User " + user.Name + " does not exist!"); + } + catch (UserManagerException e) + { + args.Player.SendErrorMessage("User " + user.Name + " could not be added. Check console for details."); + } + } - catch (UserManagerException ex) + else { - args.Player.SendMessage(ex.Message, Color.Green); - Log.ConsoleError(ex.ToString()); + args.Player.SendErrorMessage("Invalid user group syntax. Try /user help."); } } else if (subcmd == "help") diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index cd0f6d87..41c96534 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -47,34 +47,35 @@ namespace TShockAPI.DB db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : new MysqlQueryCreator()); - creator.EnsureExists(table); + if (creator.EnsureExists(table)) + { + // Add default groups if they don't exist + AddDefaultGroup("guest", "", + string.Join(",", Permissions.canbuild, Permissions.canregister, Permissions.canlogin, Permissions.canpartychat, + Permissions.cantalkinthird, Permissions.canchat)); + + AddDefaultGroup("default", "guest", + string.Join(",", Permissions.warp, Permissions.canchangepassword)); + + AddDefaultGroup("newadmin", "default", + string.Join(",", Permissions.kick, Permissions.editspawn, Permissions.reservedslot)); + + AddDefaultGroup("admin", "newadmin", + string.Join(",", Permissions.ban, Permissions.whitelist, "tshock.world.time.*", Permissions.spawnboss, + Permissions.spawnmob, Permissions.managewarp, Permissions.time, Permissions.tp, Permissions.slap, + Permissions.kill, Permissions.logs, + Permissions.immunetokick, Permissions.tpothers)); + + AddDefaultGroup("trustedadmin", "admin", + string.Join(",", Permissions.maintenance, "tshock.cfg.*", "tshock.world.*", Permissions.butcher, Permissions.item, + Permissions.heal, Permissions.immunetoban, Permissions.usebanneditem)); + + AddDefaultGroup("vip", "default", string.Join(",", Permissions.reservedslot)); + } // Load Permissions from the DB LoadPermisions(); - // Add default groups if they don't exist - AddDefaultGroup("guest", "", - string.Join(",", Permissions.canbuild, Permissions.canregister, Permissions.canlogin, Permissions.canpartychat, - Permissions.cantalkinthird, Permissions.canchat)); - - AddDefaultGroup("default", "guest", - string.Join(",", Permissions.warp, Permissions.canchangepassword)); - - AddDefaultGroup("newadmin", "default", - string.Join(",", Permissions.kick, Permissions.editspawn, Permissions.reservedslot)); - - AddDefaultGroup("admin", "newadmin", - string.Join(",", Permissions.ban, Permissions.whitelist, "tshock.world.time.*", Permissions.spawnboss, - Permissions.spawnmob, Permissions.managewarp, Permissions.time, Permissions.tp, Permissions.slap, - Permissions.kill, Permissions.logs, - Permissions.immunetokick, Permissions.tpothers)); - - AddDefaultGroup("trustedadmin", "admin", - string.Join(",", Permissions.maintenance, "tshock.cfg.*", "tshock.world.*", Permissions.butcher, Permissions.item, - Permissions.heal, Permissions.immunetoban, Permissions.usebanneditem)); - - AddDefaultGroup("vip", "default", string.Join(",", Permissions.reservedslot)); - Group.DefaultGroup = GetGroupByName(TShock.Config.DefaultGuestGroupName); } diff --git a/TShockAPI/DB/SqlTable.cs b/TShockAPI/DB/SqlTable.cs index 7fb62ed9..b7a77b91 100644 --- a/TShockAPI/DB/SqlTable.cs +++ b/TShockAPI/DB/SqlTable.cs @@ -52,7 +52,8 @@ namespace TShockAPI.DB creator = provider; } - public void EnsureExists(SqlTable table) + // Returns true if the table was created; false if it was not. + public bool EnsureExists(SqlTable table) { var columns = GetColumns(table); if (columns.Count > 0) @@ -66,7 +67,9 @@ namespace TShockAPI.DB else { database.Query(creator.CreateTable(table)); + return true; } + return false; } public List GetColumns(SqlTable table) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs old mode 100644 new mode 100755 index 07b94f63..d4555fee --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -76,6 +76,8 @@ namespace TShockAPI.DB if (1 > ret) throw new UserExistsException(user.Name); + + Hooks.AccountHooks.OnAccountCreate(user); } /// @@ -86,10 +88,13 @@ namespace TShockAPI.DB { try { + var tempuser = GetUser(user); int affected = database.Query("DELETE FROM Users WHERE Username=@0", user.Name); if (affected < 1) throw new UserNotExistException(user.Name); + + Hooks.AccountHooks.OnAccountDelete(tempuser); } catch (Exception ex) { diff --git a/TShockAPI/Hooks/AccountHooks.cs b/TShockAPI/Hooks/AccountHooks.cs new file mode 100755 index 00000000..e9bf76d2 --- /dev/null +++ b/TShockAPI/Hooks/AccountHooks.cs @@ -0,0 +1,66 @@ +/* +TShock, a server mod for Terraria +Copyright (C) 2011-2015 Nyx Studios (fka. The TShock Team) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +using TShockAPI.DB; +namespace TShockAPI.Hooks +{ + public class AccountDeleteEventArgs + { + public User User { get; set; } + + public AccountDeleteEventArgs(User user) + { + this.User = user; + } + } + + public class AccountCreateEventArgs + { + public User User { get; set; } + + public AccountCreateEventArgs(User user) + { + this.User = user; + } + } + + public class AccountHooks + { + public delegate void AccountCreateD(AccountCreateEventArgs e); + public static event AccountCreateD AccountCreate; + + public static void OnAccountCreate(User u) + { + if (AccountCreate == null) + return; + + AccountCreate(new AccountCreateEventArgs(u)); + } + + public delegate void AccountDeleteD(AccountDeleteEventArgs e); + public static event AccountDeleteD AccountDelete; + + public static void OnAccountDelete(User u) + { + if (AccountDelete == null) + return; + + AccountDelete(new AccountDeleteEventArgs(u)); + } + } +} diff --git a/TShockAPI/Rest/Rest.cs b/TShockAPI/Rest/Rest.cs index c23d0552..4fbf94e4 100644 --- a/TShockAPI/Rest/Rest.cs +++ b/TShockAPI/Rest/Rest.cs @@ -155,9 +155,9 @@ namespace Rests str = string.Format("{0}({1});", jsonp, str); } e.Response.Connection.Type = ConnectionType.Close; - e.Response.ContentType = new ContentTypeHeader("application/json"); + e.Response.ContentType = new ContentTypeHeader("application/json; charset=utf-8"); e.Response.Add(serverHeader); - e.Response.Body.Write(Encoding.ASCII.GetBytes(str), 0, str.Length); + e.Response.Body.Write(Encoding.UTF8.GetBytes(str), 0, str.Length); e.Response.Status = HttpStatusCode.OK; } diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 75ef9782..4072b8ed 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -75,6 +75,7 @@ + @@ -181,7 +182,7 @@ - +