mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-01-22 18:02:16 +00:00
console garbler virus
This commit is contained in:
parent
07b2e38881
commit
c6b5db16c0
3 changed files with 56 additions and 0 deletions
|
@ -476,6 +476,7 @@
|
|||
</Compile>
|
||||
<Compile Include="VirtualEnvironments.cs" />
|
||||
<Compile Include="Viruses\BeeperVirus.cs" />
|
||||
<Compile Include="Viruses\ConsoleGarble.cs" />
|
||||
<Compile Include="Viruses\CPLeach.cs" />
|
||||
<Compile Include="Viruses\WindowsEverywhere.cs" />
|
||||
<Compile Include="VirusTestCommands.cs" />
|
||||
|
|
50
ShiftOS.WinForms/Viruses/ConsoleGarble.cs
Normal file
50
ShiftOS.WinForms/Viruses/ConsoleGarble.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ShiftOS.Engine;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ShiftOS.WinForms.Viruses
|
||||
{
|
||||
[Virus("console_garble", "Console Garbler", "Sends random characters to stdout which can muck up your Terminal. The threatlevel determines the rate at which characters are sent.")]
|
||||
public class ConsoleGarble : IVirus
|
||||
{
|
||||
Timer timer = null;
|
||||
Random rnd = null;
|
||||
|
||||
public void Disinfect()
|
||||
{
|
||||
timer.Stop();
|
||||
timer = null;
|
||||
rnd = null;
|
||||
}
|
||||
|
||||
public void Infect(int threatlevel)
|
||||
{
|
||||
rnd = new Random();
|
||||
timer = new Timer();
|
||||
timer.Interval = 6000 / threatlevel;
|
||||
timer.Tick += (o, a) =>
|
||||
{
|
||||
var oldFG = ConsoleEx.ForegroundColor;
|
||||
var oldBG = ConsoleEx.BackgroundColor;
|
||||
var character = (char)rnd.Next(255);
|
||||
while (!char.IsLetterOrDigit(character))
|
||||
character = (char)rnd.Next(255);
|
||||
var ccolormax = Enum.GetValues(typeof(ConsoleColor)).Cast<int>().Max();
|
||||
|
||||
ConsoleEx.BackgroundColor = (ConsoleColor)rnd.Next(ccolormax);
|
||||
ConsoleEx.ForegroundColor = (ConsoleColor)rnd.Next(ccolormax);
|
||||
|
||||
Console.Write(character);
|
||||
ConsoleEx.OnFlush?.Invoke();
|
||||
|
||||
ConsoleEx.BackgroundColor = oldBG;
|
||||
ConsoleEx.ForegroundColor = oldFG;
|
||||
};
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,11 @@ namespace ShiftOS.Engine
|
|||
{
|
||||
infection.ThreatLevel = threatlevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
//no need to reinfect with a lower threatlevel
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue