Skip to content
Permalink
Browse files

Seperate bans to be both HTTP and UDP instead of a signular ban.

Also move the bans to just ignore the relavant  command type instead of freezing
  • Loading branch information...
Cazzar committed Feb 25, 2018
1 parent fe3d583 commit 11f2595ac98468ba007f32b5be1c1956e06e0e18
@@ -256,9 +256,10 @@ public CL_ServerStatus GetServerStatus()
contract.ImagesQueueStateId = (int) ShokoService.CmdProcessorImages.QueueState.queueState;
contract.ImagesQueueStateParams = ShokoService.CmdProcessorImages.QueueState.extraParams;

contract.IsBanned = ShokoService.AnidbProcessor.IsBanned;
contract.BanReason = ShokoService.AnidbProcessor.BanTime.ToString();
contract.BanOrigin = ShokoService.AnidbProcessor.BanOrigin;
var helper = ShokoService.AnidbProcessor;
contract.IsBanned = helper.IsHttpBanned || helper.IsUdpBanned;
contract.BanReason = (helper.IsHttpBanned ? helper.HttpBanTime : helper.UdpBanTime).ToString();
contract.BanOrigin = helper.BanOrigin;
}
catch (Exception ex)
{
@@ -54,8 +54,8 @@ public CL_ServerStatus GetServerStatus()
contract.ImagesQueueStateId = (int) ShokoService.CmdProcessorImages.QueueState.queueState;
contract.ImagesQueueStateParams = ShokoService.CmdProcessorImages.QueueState.extraParams;

contract.IsBanned = ShokoService.AnidbProcessor.IsBanned;
contract.BanReason = ShokoService.AnidbProcessor.BanTime.ToString();
contract.IsBanned = ShokoService.AnidbProcessor.IsHttpBanned || ShokoService.AnidbProcessor.IsUdpBanned;
contract.BanReason = (ShokoService.AnidbProcessor.IsHttpBanned ? ShokoService.AnidbProcessor.HttpBanTime : ShokoService.AnidbProcessor.UdpBanTime).ToString();
}
catch (Exception ex)
{
@@ -46,10 +46,41 @@ public class AniDBHelper

private Timer logoutTimer;

[Obsolete("Use HTTP/UDP ban time")]
public DateTime? BanTime { get; set; }


public DateTime? HttpBanTime { get; set; }
public DateTime? UdpBanTime { get; set; }

[Obsolete("Use HTTP/UDP ban status")]
private bool isBanned;

private bool _isHttpBanned;
private bool _isUdpBanned;

public bool IsHttpBanned
{
get => _isHttpBanned;
set
{
_isHttpBanned = value;
HttpBanTime = DateTime.Now;
}
}

public bool IsUdpBanned
{
get => _isUdpBanned;
set
{
_isUdpBanned = value;
UdpBanTime = DateTime.Now;
}
}


[Obsolete("Use HTTP/UDP ban status")]
public bool IsBanned
{
get => isBanned;
@@ -228,7 +259,7 @@ void LogoutTimer_Elapsed(object sender, ElapsedEventArgs e)
// if we haven't sent a command for 45 seconds, send a ping just to keep the connection alive
if (tsAniDBUDP.TotalSeconds >= Constants.PingFrequency &&
tsPing.TotalSeconds >= Constants.PingFrequency &&
!IsBanned && !ExtendPauseSecs.HasValue)
!IsUdpBanned && !ExtendPauseSecs.HasValue)
{
AniDBCommand_Ping ping = new AniDBCommand_Ping();
ping.Init();
@@ -15,8 +15,9 @@ public bool CheckForBan(string xmlresult)
int index = xmlresult.IndexOf(@">banned<", 0, StringComparison.InvariantCultureIgnoreCase);
if (index > -1)
{
ShokoService.AnidbProcessor.IsBanned = true;
ShokoService.AnidbProcessor.BanOrigin = "HTTP";
//ShokoService.AnidbProcessor.IsBanned = true;
//ShokoService.AnidbProcessor.BanOrigin = "HTTP";
ShokoService.AnidbProcessor.IsHttpBanned = true;
return true;
}

@@ -269,16 +269,7 @@ public Encoding Encoding

// if we get banned pause the command processor for a while
// so we don't make the ban worse
if (ResponseCode == 555)
{
ShokoService.AnidbProcessor.IsBanned = true;
ShokoService.AnidbProcessor.BanOrigin = "UDP";
}
else
{
ShokoService.AnidbProcessor.IsBanned = false;
ShokoService.AnidbProcessor.BanOrigin = string.Empty;
}
ShokoService.AnidbProcessor.IsUdpBanned = ResponseCode == 555;

// 598 UNKNOWN COMMAND usually means we had connections issue
// 506 INVALID SESSION
@@ -65,8 +65,9 @@ public bool Paused
extraParams = new string[0]
};
pauseTime = null;
ShokoService.AnidbProcessor.IsBanned = false;
ShokoService.AnidbProcessor.BanOrigin = string.Empty;
ShokoService.AnidbProcessor.IsUdpBanned = false;
ShokoService.AnidbProcessor.IsHttpBanned = false;

}
ServerInfo.Instance.GeneralQueuePaused = paused;
ServerInfo.Instance.GeneralQueueRunning = !paused;
@@ -27,7 +27,32 @@ public class CommandRequestRepository : BaseDirectRepository<CommandRequest, int
(int) CommandRequestType.ValidateAllImages
};

private static readonly HashSet<int> CommandTypesGeneral = Enum.GetValues(typeof(CommandRequestType))
private static readonly HashSet<int> AniDbUdpCommands = new HashSet<int>
{
(int) CommandRequestType.AniDB_AddFileUDP,
(int) CommandRequestType.AniDB_DeleteFileUDP,
(int) CommandRequestType.AniDB_GetCalendar,
(int) CommandRequestType.AniDB_GetEpisodeUDP,
(int) CommandRequestType.AniDB_GetFileUDP,
(int) CommandRequestType.AniDB_GetMyListFile,
(int) CommandRequestType.AniDB_GetReleaseGroup,
(int) CommandRequestType.AniDB_GetReleaseGroupStatus,
(int) CommandRequestType.AniDB_GetReviews, // this isn't used.
(int) CommandRequestType.AniDB_GetUpdated,
(int) CommandRequestType.AniDB_UpdateWatchedUDP,
(int) CommandRequestType.AniDB_UpdateMylistStats,
(int) CommandRequestType.AniDB_VoteAnime

};

private static readonly HashSet<int> AniDbHttpCommands = new HashSet<int>
{
(int) CommandRequestType.AniDB_GetAnimeHTTP,
(int) CommandRequestType.AniDB_SyncMyList,
(int) CommandRequestType.AniDB_SyncVotes,
};

private static readonly HashSet<int> CommandTypesGeneral = Enum.GetValues(typeof(CommandRequestType))
.OfType<CommandRequestType>().Select(a => (int) a).Except(CommandTypesHasher).Except(CommandTypesImages)
.ToHashSet();

@@ -94,7 +119,15 @@ public CommandRequest GetNextDBCommandRequestGeneral()
.ThenBy(cr => cr.DateTimeUpdated).Asc
.Take(1)
.List<CommandRequest>();
if (crs.Count > 0) return crs[0];
if (crs.Count > 0)
{
if (ShokoService.AnidbProcessor.IsHttpBanned)
crs = crs.Where(s => !AniDbHttpCommands.Contains(s.CommandType)).ToList();
if (ShokoService.AnidbProcessor.IsUdpBanned)
crs = crs.Where(s => !AniDbUdpCommands.Contains(s.CommandType)).ToList();

return crs[0];
}

return null;
}

0 comments on commit 11f2595

Please sign in to comment.
You can’t perform that action at this time.