Skip to content

Commit 2ee734d

Browse files
author
Matthew Bate
committed
Import Export of Ban IPs (Server Side)
1 parent b286672 commit 2ee734d

File tree

6 files changed

+695
-57
lines changed

6 files changed

+695
-57
lines changed

BHD-ServerManager/Classes/InstanceManagers/banInstanceManager.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public static OperationResult AddBlacklistNameRecord(
9898
DateTime? expireDate,
9999
banInstanceRecordType recordType,
100100
string notes,
101-
int associatedIPID = 0)
101+
int associatedIPID = 0,
102+
bool ignoreValidation = false)
102103
{
103104
try
104105
{
@@ -108,7 +109,7 @@ public static OperationResult AddBlacklistNameRecord(
108109

109110
if (recordType == banInstanceRecordType.Temporary && expireDate.HasValue)
110111
{
111-
if (expireDate.Value <= DateTime.Now)
112+
if (expireDate.Value <= DateTime.Now && !ignoreValidation)
112113
return new OperationResult(false, "Temporary ban end date must be in the future.");
113114
}
114115

@@ -153,7 +154,8 @@ public static OperationResult AddBlacklistIPRecord(
153154
DateTime? expireDate,
154155
banInstanceRecordType recordType,
155156
string notes,
156-
int associatedNameID = 0)
157+
int associatedNameID = 0,
158+
bool ignorevalidation = false)
157159
{
158160
try
159161
{
@@ -166,7 +168,7 @@ public static OperationResult AddBlacklistIPRecord(
166168

167169
if (recordType == banInstanceRecordType.Temporary && expireDate.HasValue)
168170
{
169-
if (expireDate.Value <= DateTime.Now)
171+
if (expireDate.Value <= DateTime.Now && !ignorevalidation)
170172
return new OperationResult(false, "Temporary ban end date must be in the future.");
171173
}
172174

@@ -218,17 +220,18 @@ public static DualRecordResult AddBlacklistBothRecords(
218220
DateTime banDate,
219221
DateTime? expireDate,
220222
banInstanceRecordType recordType,
221-
string notes)
223+
string notes,
224+
bool ignorevalidation = false)
222225
{
223226
try
224227
{
225228
// Add name record first
226-
var nameResult = AddBlacklistNameRecord(playerName, banDate, expireDate, recordType, notes);
229+
var nameResult = AddBlacklistNameRecord(playerName, banDate, expireDate, recordType, notes, 0, ignorevalidation);
227230
if (!nameResult.Success)
228231
return new DualRecordResult(false, nameResult.Message, 0, 0, nameResult.Exception);
229232

230233
// Add IP record with association
231-
var ipResult = AddBlacklistIPRecord(ipAddress, subnetMask, banDate, expireDate, recordType, notes, nameResult.RecordID);
234+
var ipResult = AddBlacklistIPRecord(ipAddress, subnetMask, banDate, expireDate, recordType, notes, nameResult.RecordID, ignorevalidation);
232235
if (!ipResult.Success)
233236
{
234237
// Rollback name record
@@ -510,7 +513,8 @@ public static OperationResult AddWhitelistNameRecord(
510513
DateTime? expireDate,
511514
banInstanceRecordType recordType,
512515
string notes,
513-
int associatedIPID = 0)
516+
int associatedIPID = 0,
517+
bool ignorevalidation = false)
514518
{
515519
try
516520
{
@@ -519,7 +523,7 @@ public static OperationResult AddWhitelistNameRecord(
519523

520524
if (recordType == banInstanceRecordType.Temporary && expireDate.HasValue)
521525
{
522-
if (expireDate.Value <= DateTime.Now)
526+
if (expireDate.Value <= DateTime.Now && !ignorevalidation)
523527
return new OperationResult(false, "Temporary whitelist end date must be in the future.");
524528
}
525529

@@ -560,7 +564,8 @@ public static OperationResult AddWhitelistIPRecord(
560564
DateTime? expireDate,
561565
banInstanceRecordType recordType,
562566
string notes,
563-
int associatedNameID = 0)
567+
int associatedNameID = 0,
568+
bool ignorevalidation = false)
564569
{
565570
try
566571
{
@@ -572,7 +577,7 @@ public static OperationResult AddWhitelistIPRecord(
572577

573578
if (recordType == banInstanceRecordType.Temporary && expireDate.HasValue)
574579
{
575-
if (expireDate.Value <= DateTime.Now)
580+
if (expireDate.Value <= DateTime.Now && !ignorevalidation)
576581
return new OperationResult(false, "Temporary whitelist end date must be in the future.");
577582
}
578583

@@ -614,15 +619,16 @@ public static DualRecordResult AddWhitelistBothRecords(
614619
DateTime exemptDate,
615620
DateTime? expireDate,
616621
banInstanceRecordType recordType,
617-
string notes)
622+
string notes,
623+
bool ignorevalidation = false)
618624
{
619625
try
620626
{
621-
var nameResult = AddWhitelistNameRecord(playerName, exemptDate, expireDate, recordType, notes);
627+
var nameResult = AddWhitelistNameRecord(playerName, exemptDate, expireDate, recordType, notes, 0, ignorevalidation);
622628
if (!nameResult.Success)
623629
return new DualRecordResult(false, nameResult.Message, 0, 0, nameResult.Exception);
624630

625-
var ipResult = AddWhitelistIPRecord(ipAddress, subnetMask, exemptDate, expireDate, recordType, notes, nameResult.RecordID);
631+
var ipResult = AddWhitelistIPRecord(ipAddress, subnetMask, exemptDate, expireDate, recordType, notes, nameResult.RecordID, ignorevalidation);
626632
if (!ipResult.Success)
627633
{
628634
DeleteWhitelistNameRecord(nameResult.RecordID);

BHD-ServerManager/Classes/SupportClasses/DatabaseManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using HawkSyncShared.Instances;
1+
using HawkSyncShared.DTOs;
2+
using HawkSyncShared.Instances;
23
using HawkSyncShared.ObjectClasses;
34
using HawkSyncShared.SupportClasses;
45
using Microsoft.Data.Sqlite;
56
using System;
67
using System.Diagnostics;
78
using System.Net;
89
using System.Text;
10+
using System.Text.Json;
911
using System.Threading;
1012
using System.Threading.Tasks;
1113

BHD-ServerManager/Forms/Panels/tabBans.Designer.cs

Lines changed: 85 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)