public bool AddUser(TjUser user) { if (TShock.DB.Query($"INSERT INTO TJUsers(uuid, disabled, pads) VALUES ('{user.Uuid}', {user.SelfDisabled.ToInt()}, '{JsonConvert.SerializeObject(user.DisabledPads)}')") != 1) { TShock.Log.Error("SQL Error while adding user!"); return(false); } UserList.Add(user); return(true); }
public bool ModifyUser(TjUser user) { if (TShock.DB.Query($"UPDATE TJUsers SET disabled={user.SelfDisabled.ToInt()}, pads='{JsonConvert.SerializeObject(user.DisabledPads)}' WHERE uuid='{user.Uuid}'") != 1) { TShock.Log.Error("SQL Error while updating user!"); return(false); } UserList.RemoveAll(u => u.Uuid == user.Uuid); UserList.Add(user); return(true); }
public static DisabledManager Start() { bool tju = false, tjp = false; try { TShock.DB.Query("CREATE TABLE TJUsers(uuid TEXT, disabled INT2, pads TEXT)"); } catch (Exception exe) { if (exe.HResult != -2147467259) { throw new Exception("SQL ERROR: " + exe.HResult); } tju = true; } try { TShock.DB.Query("CREATE TABLE TJPads(x INT, y INT)"); } catch (Exception exe) { if (exe.HResult != -2147467259) { throw new Exception("SQL ERROR: " + exe.HResult); } tjp = true; } var dm = new DisabledManager { UserList = new List <TjUser>(), DisabledPads = new List <PadPoint>(), PadDisables = new List <PadDisable>() }; if (tju) { var query = TShock.DB.QueryReader("SELECT * FROM TJUsers"); while (query.Read()) { var user = new TjUser() { Uuid = query.Get <string>("uuid"), SelfDisabled = query.Get <int>("disabled") == 1, DisabledPads = JsonConvert.DeserializeObject <List <PadPoint> >(query.Get <string>("pads")) }; if (user.DisabledPads == null) { user.DisabledPads = new List <PadPoint>(); } dm.UserList.Add(user); } } if (tjp) { var query = TShock.DB.QueryReader("SELECT * FROM TJPads"); while (query.Read()) { dm.DisabledPads.Add(new PadPoint() { X = query.Get <int>("x"), Y = query.Get <int>("y") }); } } dm.TryConvert(); return(dm); }