public static async Task <bool> DeleteBanAsync(int id, IPAddress ip, BanType type) { try { using (var connection = await GetConnectionAsync()) { using (var command = connection.CreateCommand()) { if (ip != null) { command.CommandText = $"DELETE FROM {tb_13} WHERE (ban_user = {id} OR ban_ip = {ip.ToInt64()}) AND ban_type = {(byte)type}"; } else { command.CommandText = $"DELETE FROM {tb_13} WHERE ban_user = {id} AND ban_type = {(byte)type}"; } return(await command.ExecuteNonQueryAsyncEx() > 0); } } } catch (Exception exp) { ServerLogger.LogException(exp); return(false); } }
private Ban CreateBan(Login user, BanType banType) { TimeSpan?duration = Ban.CalculateDuration(user.Identity, banType); DateTime expirationDate; if (duration == TimeSpan.MaxValue) { expirationDate = SqlDateTime.MaxValue.Value; } else { expirationDate = DateTime.Now.Add(duration.Value); } return(new Ban() { BannedByLoginId = user.Id, BanType = banType, BanTypeId = banType.Id, DateCreated = DateTime.Now, DateExpires = expirationDate, InEffect = true, Login = user }); }
/// <summary> /// Ban a Single User. /// Only Moderator that can ban other user. /// </summary> /// <param name="userId">Ban user's user ID</param> /// <param name="banType">The type of Ban</param> /// <param name="reason">The reason of Banning</param> /// <param name="endDate">The date when the ban is lifted</param> /// <param name="comment">The detail or comment about the banning</param> /// <param name="notifyUser">Notify user via email or not</param> /// <param name="callback">Returns a result via callback when completed</param> public void BanUser(string userId, BanType banType, BanReason reason, DateTime endDate, string comment, bool notifyUser, ResultCallback <UserBanResponseV3> callback) { Report.GetFunctionLog(this.GetType().Name); if (!this.loginSession.IsValid()) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } var banRequest = new BanCreateRequest { ban = banType.ToString(), comment = comment, endDate = endDate.ToString("o"), reason = reason.ToString(), skipNotif = !notifyUser }; this.coroutineRunner.Run( this.userAccount.BanUser( AccelBytePlugin.Config.Namespace, this.loginSession.AuthorizationToken, userId, banRequest, callback)); }
public void unban(int index) { string[] keys = new string[bannedNames.Count]; bannedNames.Keys.CopyTo(keys, 0); BanType type = (BanType)this.bannedNames[keys[index]]; List <object> banHashKeys = new List <object>(FengGameManagerMKII.banHash.Keys); foreach (object key in banHashKeys) { string stripped = ModMain.stripColorCodes((string)FengGameManagerMKII.banHash[key]); if (type == BanType.CONTAINS_PART) { if (stripped.Contains(keys[index])) { FengGameManagerMKII.banHash.Remove(key); } } else if (type == BanType.FULL_NAME) { if (stripped.Equals(keys[index])) { FengGameManagerMKII.banHash.Remove(key); } } } lock (bannedLock){ bannedNames.Remove(keys[index]); } }
public BanEventArgs(string nickName, int druation, BanType type = BanType.BanOrTimeout) { NickName = nickName; Duration = druation; Type = type; DeletedMessage = null; MessageID = null; }
public BanEventArgs(string nickName, string deletedMessage, string MsgID, BanType type = BanType.MsgDelete) { NickName = nickName; Duration = 0; Type = type; DeletedMessage = deletedMessage; MessageID = MsgID; }
private BanType Initialize() { DataAccess.BanType banType; using (var db = new CSSDataContext()) { banType = db.BanTypes.FirstOrDefault(p => p.RocNumber == 1); if (_initialized) { return(banType); } if (db.Logins.FirstOrDefault(p => p.Username == "Admin") == null) { //Create new user CreateUser("Admin", "Test", "NA", 10); var admin = Login.FindLoginByUsernameOrCallsign(db, "Admin"); admin.Login_Roles.Add(new Login_Role() { RoleId = (int)RoleType.Administrator }); admin.Login_Roles.Add(new Login_Role() { RoleId = (int)RoleType.SuperAdministrator }); } db.Bans.DeleteAllOnSubmit(db.Bans); var banClass = new BanClass() { Id = 1, Name = "Minor" }; db.BanClasses.DeleteAllOnSubmit(db.BanClasses); db.BanClasses.InsertOnSubmit(banClass); banType = new BanType() { BanClassId = 1, BaseTimeInMinutes = 30, Description = "Harassment / Threats", IsIncremental = true, RocNumber = 1 }; db.BanTypes.DeleteAllOnSubmit(db.BanTypes); db.BanTypes.InsertOnSubmit(banType); db.SubmitChanges(); } _initialized = true; return(banType); }
/* public BanUserOperation(string opername,BanType opertype,DateTime opertime,string cause,Dictionary<int,DateTime> foruminfos,int targetid,string targetname) * { * OperatorName = opername; * OperationType = opertype; * OperationTime = opertime; * Cause = cause; * ForumInfos = foruminfos; * UserID = targetid; * UserName = targetname; * } */ public BanUserOperation(string opername, BanType opertype, DateTime opertime, string cause, int targetid, string targetname) { OperatorName = opername; OperationType = opertype; OperationTime = opertime; Cause = cause; UserID = targetid; UserName = targetname; }
public BanEvent(string ip, string id, string name, string reason, string adminname) { _type = BanType.IDandIP; _reason = reason; _ip = ip; _id = id; _name = name; _banner = adminname; }
public override Task Generate() { BanType previousBan = BanType.None; if (_settings.ContainsKey(SettingID.BanType)) { previousBan = _settings[SettingID.BanType].GetValue <BanType>(); } DateTime previousBanEnd = DateTime.Now; if (_settings.ContainsKey(SettingID.BanEnd)) { previousBanEnd = _settings[SettingID.BanEnd].GetValue <DateTime>(); } WheelExtension.WheelDifficultyPreference difficulty = WheelExtension.WheelDifficultyPreference.Default; if (_settings.ContainsKey(SettingID.WheelDifficulty)) { difficulty = _settings[SettingID.WheelDifficulty].GetValue <WheelExtension.WheelDifficultyPreference>(); } List <BanType> possibleBans = new List <BanType>() { BanType.NoHentai, BanType.OnlyHentai, BanType.NoRegularPorn, BanType.NoRegularPorn }; if (_settings.TryGetValue(SettingID.TrapLevel, out UserSetting sissySetting)) { if (sissySetting.GetValue <SissyLevel>() >= SissyLevel.Normal) { possibleBans.Add(BanType.OnlyTrapPorn); } } var index = Helpers.RandomGenerator.RandomInt(0, possibleBans.Count); var chosenBan = possibleBans[index]; int days = (int)difficulty + 1; var builder = new DiscordEmbedBuilder() { Title = "Ban!", Description = $"You are allowed to watch {chosenBan.ToFormattedText().ToLower()} for the next {days} days." }; if (previousBan != BanType.None && previousBanEnd > DateTime.Now) { builder.Description += $" Your previous ban of {previousBan.ToFormattedText().ToLower()} has been lifted."; } Embed = builder.Build(); return(Task.CompletedTask); }
public DB_Ban(int id, int by, string reason, long ip, int user, DateTime start, DateTime end, byte type) { Id = id; BanBy = by; Reason = reason; Ip = ip == -1 ? null : new IPAddress(ip); User = user; Start = start; End = end; Type = (BanType)type; }
public void TestPermanentBanCalculations() { Initialize(); DataAccess.BanClass banClass = new BanClass() { Id = (int)BanClassType.Major, Name = "Major" }; DataAccess.BanType banType = new BanType() { BanClass = banClass, BanClassId = banClass.Id, BaseTimeInMinutes = 30, Description = "Permanent ban after one infraction.", IsIncremental = true, InfractionsBeforePermanentBan = 1, SrNumber = 13 }; DataAccess.Login testUser = CreateUser(Guid.NewGuid().ToString().Substring(0, 20), "Test", "NA", 10); DataAccess.Identity identity = testUser.Identity; // Test 1x Ban - 30 minutes TimeSpan?duration = Ban.CalculateDuration(identity, banType); Assert.AreEqual(30, duration.Value.TotalMinutes); // Test 2x Ban - Permanent. testUser.Bans.Add(CreateBan(testUser, banType)); duration = Ban.CalculateDuration(identity, banType); Assert.AreEqual(TimeSpan.MaxValue, duration.Value); // Test permanent ban on first infraction banType = new BanType() { BanClass = banClass, BanClassId = banClass.Id, BaseTimeInMinutes = 30, Description = "Permanent ban on first infraction.", IsIncremental = true, InfractionsBeforePermanentBan = 0, SrNumber = 9 }; testUser = CreateUser(Guid.NewGuid().ToString().Substring(0, 20), "Test", "NA", 10); identity = testUser.Identity; // Test 1x Ban - Permanent. testUser.Bans.Add(CreateBan(testUser, banType)); duration = Ban.CalculateDuration(identity, banType); Assert.AreEqual(TimeSpan.MaxValue, duration.Value); }
public BanEvent(Fougerite.Player player, string Banner, string reason, Fougerite.Player Sender) { _type = BanType.Player; _player = player; _reason = reason; _ip = player.IP; _id = player.SteamID; _name = player.Name; _sender = Sender; _banner = Banner; }
public string BTypeToRSubtype(BanType type) { if (type == BanType.@public) { return(Keys.BanPublicKey); } else { return("?"); } }
public Ban(int id, BanType banType, string value, string reason, double expires, uint addedById, double addedOn, bool active) { this.ID = id; this.BanType = banType; this.Value = value; this.Reason = reason; this.Expires = expires; this.AddedByID = addedById; this.AddedOn = addedOn; this.Active = active; }
/// <summary> /// Deserializes the data present in the packet contents into data fields in the class. /// </summary> public override void Deserialize() { sender = ReadNullString(); alias = ReadNullString(); banType = (BanType)_contentReader.ReadByte(); time = _contentReader.ReadInt32(); reason = ReadNullString(); UID1 = _contentReader.ReadUInt32(); UID2 = _contentReader.ReadUInt32(); UID3 = _contentReader.ReadUInt32(); }
/// <summary> /// Банит раздел /// </summary> /// <param name="sectionId">раздел, который нужно забанить</param> /// <param name="banType">тип бана</param> public void SetBanSection(SectionId sectionId, BanType banType) { BanDate = DateTime.Now; if (!BannedSections.ContainsKey(sectionId)) { BannedSections.Add(sectionId, banType); } else { BannedSections[sectionId] = banType; } }
public PlayerBan(string playerName, string playerKeyhash, string playerIPAddress, string adminName, string reason, BanType type, long playerDatabaseId, long adminDatabaseId) { PlayerName = playerName; PlayerKeyhash = playerKeyhash; PlayerIPAddress = playerIPAddress; PlayerDatabaseId = playerDatabaseId; AdminName = adminName; AdminDatabaseId = adminDatabaseId; Duration = DURATION_PERMANENT; Type = type; Reason = reason; }
public PlayerBan(string playerName, string playerKeyhash, string playerIPAddress, string adminName, string reason, TimeSpan duration, BanType type, long playerDatabaseId, long adminDatabaseId) { PlayerName = playerName; PlayerKeyhash = playerKeyhash; PlayerIPAddress = playerIPAddress; PlayerDatabaseId = playerDatabaseId; AdminName = adminName; AdminDatabaseId = adminDatabaseId; Duration = (long)duration.TotalSeconds; Type = type; Reason = reason; }
/// <summary> /// Банит раздел /// </summary> /// <param name="sectionId">раздел, который нужно забанить</param> /// <param name="banType">тип бана</param> public void SetBanSection(SectionId sectionId, BanType banType) { BanDate = DateTime.Now; string key = sectionId.ToString(); if (!BannedSections.ContainsKey(key)) { BannedSections.Add(key, banType); } else { BannedSections[key] = banType; } }
public static void InvokePlayerBanned(BanDetails banDetails, BanType banType) { if (PlayerBannedEvent == null) { return; } PlayerBannedEvent ev = new PlayerBannedEvent() { Details = banDetails, Type = banType }; PlayerBannedEvent.Invoke(ev); }
public void InsertBan(Player p, Player a, string reason, bool ip, int duration = -1) { PlayerBan b = null; BanType t = (ip ? BanType.IPAddress : BanType.Keyhash); if (duration < 0) { b = new PlayerBan(p.Name, p.KeyHash, p.RemoteAddressStr, a.Name, reason, t, p.DatabaseId, a.DatabaseId); } else { b = new PlayerBan(p.Name, p.KeyHash, p.RemoteAddressStr, a.Name, reason, new TimeSpan(0, 0, 0, duration), t, p.DatabaseId, a.DatabaseId); } core.Database.InsertBan(b); }
public PlayerBan(long databaseId, string playerName, string playerKeyhash, string playerIPAddress, string adminName, string reason, DateTime date, long duration, BanType type, long playerDatabaseId, long adminDatabaseId) { DatabaseId = databaseId; PlayerName = playerName; PlayerKeyhash = playerKeyhash; PlayerIPAddress = playerIPAddress; PlayerDatabaseId = playerDatabaseId; AdminName = adminName; AdminDatabaseId = adminDatabaseId; Date = date; Duration = duration; Type = type; Reason = reason; }
/// <summary> /// Adds the user to the database. /// </summary> /// <param name="user">The user.</param> /// <param name="bannedBy">The admin who added the ban.</param> /// <param name="banAddDate">The date and time that the ban was added.</param> /// <param name="banExpirationDate">The date and time that the user's ban will expire.</param> /// <param name="banType">The type of ban.</param> /// <returns></returns> public UserDbResult AddUserToDb(string user, string bannedBy, DateTime banAddDate, DateTime banExpirationDate, BanType banType) { var result = UserDbResult.Unspecified; if (VerifyDb()) { if (DoesUserExistInDb(user.ToLowerInvariant())) { return(UserDbResult.UserAlreadyExists); } try { using (var sqlcon = new SQLiteConnection(_sqlConString)) { sqlcon.Open(); using (var cmd = new SQLiteCommand(sqlcon)) { cmd.CommandText = "INSERT INTO bannedusers(user, bannedBy, banAddDate, banExpirationDate, banType)" + " VALUES(@user, @bannedBy, @banAddDate, @banExpirationDate, @banType)"; cmd.Parameters.AddWithValue("@user", user.ToLowerInvariant()); cmd.Parameters.AddWithValue("@bannedBy", bannedBy); cmd.Parameters.AddWithValue("@banAddDate", banAddDate); cmd.Parameters.AddWithValue("@banExpirationDate", banExpirationDate); cmd.Parameters.AddWithValue("@banType", (long)banType); cmd.ExecuteNonQuery(); Log.Write(string.Format( "{0} successfully added to ban database by: {1} on: {2}. Time-ban expires on: {3}.", user, bannedBy, banAddDate.ToString("G", DateTimeFormatInfo.InvariantInfo), banExpirationDate.ToString("G", DateTimeFormatInfo.InvariantInfo)), _logClassType, _logPrefix); result = UserDbResult.Success; } } } catch (Exception ex) { Log.WriteCritical(string.Format("Problem adding player {0} to ban database: {1}", user, ex.Message), _logClassType, _logPrefix); result = UserDbResult.InternalError; } } return(result); }
public static void InvokePlayerBanned(BanDetails details, BanType type) { PlayerBanned playerBanned = PlayerBannedEvent; if (playerBanned == null) { return; } PlayerBannedEvent ev = new PlayerBannedEvent() { Details = details, Type = type }; PlayerBannedEvent?.Invoke(ev); }
/// <summary> /// Bans the identifier /// </summary> /// <param name="identifier">The starbound identifier of the player to ban</param> /// <param name="reason">The reason for the ban</param> /// <param name="type">The type of the ban</param> /// <param name="duration">The duration of the ban</param> /// <returns>Rcon Response of hte ban</returns> public async Task <RconResponse> Ban(int connection, string reason, BanType type, int duration) { if (type == BanType.Invalid) { return(new RconResponse() { Message = "Invalid ban type", Success = false }); } string mode = type == BanType.Complete ? "both" : (type == BanType.IP ? "ip" : "uuid"); var response = await ExecuteAsync($"ban ${connection} \"{reason}\" {mode} {duration}"); OnBan?.Invoke(this, response); return(response); }
public static bool IsBanned(BanType BanType, int ID, out bool Locally) { switch (BanType) { case BanType.Item: return(IsBannedItem(ID, out Locally)); case BanType.Projectile: return(IsBannedProjectile(ID, out Locally)); case BanType.Tile: return(IsBannedTile(ID, out Locally)); default: throw new NotImplementedException($"Unknown {nameof(Overrides.BanType)}."); } }
public BanEvent(string iporid, string name, string reason, string adminname, bool IsID) { if (IsID) { _type = BanType.OnlyID; _reason = reason; _id = iporid; _name = name; _banner = adminname; } else { _type = BanType.OnlyIP; _reason = reason; _ip = iporid; _name = name; _banner = adminname; } }
public void LoadBans(DatabaseClient dbClient) { Logging.Write("Loading bans... "); Dictionary <int, Ban> newBans = new Dictionary <int, Ban>(); DataTable bans = dbClient.ReadDataTable("SELECT * FROM bans;"); if (bans != null && bans.Rows.Count > 0) { foreach (DataRow dataRow in bans.Rows) { int id = (int)dataRow["id"]; BanType banType = (string)dataRow["type"] == "user" ? BanType.User : (string)dataRow["type"] == "ip" ? BanType.IP : BanType.Machine; newBans.Add(id, new Ban(id, banType, (string)dataRow["value"], (string)dataRow["reason"], (double)dataRow["expire"], (uint)dataRow["added_by_id"], (double)dataRow["added_on"], TextUtilies.StringToBool((string)dataRow["active"]))); } } this.Bans = newBans; Logging.WriteLine("completed!", ConsoleColor.Green); }
public SteamUser GetUser(long steamId) { TimeSpan timePlayed = IsCsgoInstalled(steamId); if (timePlayed > TimeSpan.Zero) { string name = GetName(steamId); BanType banType = GetBanType(steamId); var steamUser2 = new SteamUser(steamId) { TimePlayed = timePlayed, BanType = banType, Name = name }; return(steamUser2); } return(null); }
public override void BanUser(string operatorname, BanType bantype, DateTime operationtime, string cause, Dictionary<int, DateTime> foruminfos, int userid, string targetname, string userip) { using (SqlQuery query = new SqlQuery()) { StringBuffer sqlBuffer = new StringBuffer(); sqlBuffer += "DELETE FROM bx_BannedUsers WHERE UserID = @UserID;"; sqlBuffer += "INSERT INTO bx_BanUserLogs(OperationType,OperationTime,OperatorName,Cause,UserID,Username,UserIP,AllBanEndDate) Values(@OperationType,@OperationTime,@OperatorName,@Cause,@UserID,@Username,@UserIP,@AllBanEndDate);DECLARE @logid int;SELECT @logid=@@IDENTITY;"; foreach (KeyValuePair<int, DateTime> forumBanInfo in foruminfos) { sqlBuffer += string.Format("INSERT INTO bx_BannedUsers( UserID, ForumID, EndDate, Cause ) VALUES(@UserID , @ForumID{0},@EndDate{0}, @Cause);", forumBanInfo.Key); sqlBuffer += string.Format("INSERT INTO bx_BanUserLogForumInfos(LogID,ForumID,ForumName,EndDate) Select @logid,@ForumID{0},ForumName,@EndDate{0} FROM [bx_Forums] WHERE ForumID=@ForumID{0};", forumBanInfo.Key); query.CreateParameter<int>(string.Format("@ForumID{0}", forumBanInfo.Key), forumBanInfo.Key, SqlDbType.Int); query.CreateParameter<DateTime>(string.Format("@EndDate{0}", forumBanInfo.Key), forumBanInfo.Value, SqlDbType.DateTime); } query.CreateParameter<int>("@OperationType", (int)bantype, SqlDbType.Int); query.CreateParameter<DateTime>("@OperationTime", operationtime, SqlDbType.DateTime); query.CreateParameter<string>("@OperatorName", operatorname, SqlDbType.NVarChar, 50); query.CreateParameter<string>("@Cause", cause, SqlDbType.NVarChar, 1000); query.CreateParameter<int>("@UserID", userid, SqlDbType.Int); query.CreateParameter<string>("@Username", targetname, SqlDbType.NVarChar, 50); query.CreateParameter<string>("@UserIP", userip, SqlDbType.NVarChar, 50); DateTime allBanEndDate; if (foruminfos.TryGetValue(0, out allBanEndDate)) { query.CreateParameter<DateTime>("@AllBanEndDate", allBanEndDate, SqlDbType.DateTime); } else { query.CreateParameter<DateTime>("@AllBanEndDate", DateTime.MaxValue, SqlDbType.DateTime); } query.CommandText = sqlBuffer.ToString(); query.ExecuteNonQuery(); } }