first commit
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Filters;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.Filters
|
||||
{
|
||||
[TestClass]
|
||||
public class ClilocFilterTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillFilterLocalizedText()
|
||||
{
|
||||
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
|
||||
|
||||
if ( !Directory.Exists( localPath ) )
|
||||
{
|
||||
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
|
||||
return;
|
||||
}
|
||||
|
||||
Cliloc.Initialize( localPath );
|
||||
|
||||
byte[] packet =
|
||||
{
|
||||
0xC1, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x07,
|
||||
0xA1, 0x96, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
int length = packet.Length;
|
||||
|
||||
const int cliloc = 500118;
|
||||
const string replaceText = "The quick brown fox jumped over the lazy dog.";
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnReceivedEvent( byte[] data, int _ )
|
||||
{
|
||||
if ( data[0] != 0xAE )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
string text = Encoding.BigEndianUnicode.GetString( data, 48, data.Length - 48 );
|
||||
|
||||
if ( text != replaceText )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketReceivedEvent += OnReceivedEvent;
|
||||
|
||||
ClilocFilter.IsEnabled = true;
|
||||
ClilocFilter.Filters.Add( cliloc, replaceText );
|
||||
|
||||
IncomingPacketFilters.Initialize();
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketReceivedEvent -= OnReceivedEvent;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillFilterLocalizedTextAffix()
|
||||
{
|
||||
const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";
|
||||
|
||||
if ( !Directory.Exists( localPath ) )
|
||||
{
|
||||
Debug.WriteLine( "Not running test, requires Cliloc.enu" );
|
||||
return;
|
||||
}
|
||||
|
||||
Cliloc.Initialize( localPath );
|
||||
|
||||
byte[] packet =
|
||||
{
|
||||
0xCC, 0x00, 0x36, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x06, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x0F,
|
||||
0x62, 0x1E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x31, 0x34, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
int length = packet.Length;
|
||||
|
||||
const int cliloc = 1008158;
|
||||
const string replaceText = "The value is: ";
|
||||
|
||||
AutoResetEvent are = new AutoResetEvent( false );
|
||||
|
||||
void OnReceivedEvent( byte[] data, int _ )
|
||||
{
|
||||
if ( data[0] != 0xAE )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
string text = Encoding.BigEndianUnicode.GetString( data, 48, data.Length - 48 );
|
||||
|
||||
if ( !text.StartsWith( replaceText ) )
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
are.Set();
|
||||
}
|
||||
|
||||
Engine.InternalPacketReceivedEvent += OnReceivedEvent;
|
||||
|
||||
ClilocFilter.IsEnabled = true;
|
||||
ClilocFilter.Filters.Add( cliloc, replaceText );
|
||||
|
||||
IncomingPacketFilters.Initialize();
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
bool result = are.WaitOne( 5000 );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
|
||||
Engine.InternalPacketReceivedEvent -= OnReceivedEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
#region License
|
||||
|
||||
// Copyright (C) 2020 Reetus
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using ClassicAssist.Shared;
|
||||
using ClassicAssist.Data.Filters;
|
||||
using ClassicAssist.UO.Network;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.Filters
|
||||
{
|
||||
[TestClass]
|
||||
public class RepeatedMessageFilterTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillFilterOldAsciiSystemMessages()
|
||||
{
|
||||
AppDomain appDomain = AppDomain.CreateDomain( "WillFilterOldAsciiSystemMessages",
|
||||
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
|
||||
|
||||
appDomain.DoCallBack( () =>
|
||||
{
|
||||
byte[] packet =
|
||||
{
|
||||
0x1C, 0x00, 0x4B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x81, 0x00, 0x03, 0x53, 0x79,
|
||||
0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61, 0x72, 0x67,
|
||||
0x65, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x69, 0x6E, 0x20, 0x6C, 0x69, 0x6E,
|
||||
0x65, 0x20, 0x6F, 0x66, 0x20, 0x73, 0x69, 0x67, 0x68, 0x74, 0x00
|
||||
};
|
||||
|
||||
int length = packet.Length;
|
||||
|
||||
IncomingPacketFilters.Initialize();
|
||||
RepeatedMessagesFilter.IsEnabled = true;
|
||||
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
bool result = IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
} );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillSendToJournalFilteredMessages()
|
||||
{
|
||||
AppDomain appDomain = AppDomain.CreateDomain( "WillSendToJournalFilteredMessages",
|
||||
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
|
||||
|
||||
appDomain.DoCallBack( () =>
|
||||
{
|
||||
byte[] packet =
|
||||
{
|
||||
0x1C, 0x00, 0x4B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x81, 0x00, 0x03, 0x53, 0x79,
|
||||
0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61, 0x72, 0x67,
|
||||
0x65, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x69, 0x6E, 0x20, 0x6C, 0x69, 0x6E,
|
||||
0x65, 0x20, 0x6F, 0x66, 0x20, 0x73, 0x69, 0x67, 0x68, 0x74, 0x00
|
||||
};
|
||||
|
||||
int length = packet.Length;
|
||||
|
||||
IncomingPacketFilters.Initialize();
|
||||
RepeatedMessagesFilter.IsEnabled = true;
|
||||
RepeatedMessagesFilter.FilterOptions.SendToJournal = true;
|
||||
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
bool result = IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
Assert.IsTrue( Engine.Journal.Count > 0 );
|
||||
} );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WontSendToJournalFilteredMessagesDisabled()
|
||||
{
|
||||
AppDomain appDomain = AppDomain.CreateDomain( "WontSendToJournalFilteredMessagesDisabled",
|
||||
AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation );
|
||||
|
||||
appDomain.DoCallBack( () =>
|
||||
{
|
||||
byte[] packet =
|
||||
{
|
||||
0x1C, 0x00, 0x4B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x81, 0x00, 0x03, 0x53, 0x79,
|
||||
0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61, 0x72, 0x67,
|
||||
0x65, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x69, 0x6E, 0x20, 0x6C, 0x69, 0x6E,
|
||||
0x65, 0x20, 0x6F, 0x66, 0x20, 0x73, 0x69, 0x67, 0x68, 0x74, 0x00
|
||||
};
|
||||
|
||||
int length = packet.Length;
|
||||
|
||||
IncomingPacketFilters.Initialize();
|
||||
RepeatedMessagesFilter.IsEnabled = true;
|
||||
RepeatedMessagesFilter.FilterOptions.SendToJournal = false;
|
||||
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
bool result = IncomingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
Assert.IsTrue( result );
|
||||
Assert.AreEqual( 0, Engine.Journal.Count );
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using ClassicAssist.Data;
|
||||
using ClassicAssist.UO.Data;
|
||||
using ClassicAssist.UO.Network;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ClassicAssist.Tests.Filters
|
||||
{
|
||||
[TestClass]
|
||||
public class SavedPasswordsTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void WillSavePasswordIfEnabled()
|
||||
{
|
||||
AssistantOptions.SavedPasswords.Clear();
|
||||
|
||||
OutgoingPacketFilters.Initialize();
|
||||
|
||||
PacketWriter writer = new PacketWriter( 62 );
|
||||
writer.Write( (byte) 0x80 );
|
||||
writer.WriteAsciiFixed( "fakeusername", 30 );
|
||||
writer.WriteAsciiFixed( "fakepassword", 30 );
|
||||
writer.Write( (byte) 0 );
|
||||
|
||||
byte[] packet = writer.ToArray();
|
||||
int length = packet.Length;
|
||||
|
||||
OutgoingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
Assert.AreEqual( 0, AssistantOptions.SavedPasswords.Count );
|
||||
|
||||
AssistantOptions.SavePasswords = true;
|
||||
|
||||
OutgoingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
Assert.AreEqual( 1, AssistantOptions.SavedPasswords.Count );
|
||||
|
||||
AssistantOptions.SavedPasswords.Clear();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WillSavePasswordOnlyIfBlanl()
|
||||
{
|
||||
AssistantOptions.SavedPasswords.Clear();
|
||||
|
||||
OutgoingPacketFilters.Initialize();
|
||||
|
||||
AssistantOptions.SavePasswords = true;
|
||||
AssistantOptions.SavePasswordsOnlyBlank = true;
|
||||
|
||||
PacketWriter writer = new PacketWriter( 62 );
|
||||
writer.Write( (byte) 0x80 );
|
||||
writer.WriteAsciiFixed( "fakeusername", 30 );
|
||||
writer.WriteAsciiFixed( "fakepassword", 30 );
|
||||
writer.Write( (byte) 0 );
|
||||
|
||||
byte[] packet = writer.ToArray();
|
||||
int length = packet.Length;
|
||||
|
||||
OutgoingPacketFilters.CheckPacket( ref packet, ref length );
|
||||
|
||||
Assert.AreEqual( 1, AssistantOptions.SavedPasswords.Count );
|
||||
|
||||
PacketWriter writer2 = new PacketWriter( 62 );
|
||||
writer2.Write( (byte) 0x80 );
|
||||
writer2.WriteAsciiFixed( "fakeusername", 30 );
|
||||
writer2.WriteAsciiFixed( "", 30 );
|
||||
writer2.Write( (byte) 0 );
|
||||
|
||||
byte[] packet2 = writer2.ToArray();
|
||||
int length2 = packet2.Length;
|
||||
|
||||
OutgoingPacketFilters.CheckPacket( ref packet2, ref length2 );
|
||||
|
||||
byte[] tmp = new byte[30];
|
||||
Buffer.BlockCopy( packet2, 31, tmp, 0, 30 );
|
||||
|
||||
Assert.AreEqual( "fakepassword", Encoding.ASCII.GetString( tmp ).TrimEnd( '\0' ) );
|
||||
|
||||
PacketWriter writer3 = new PacketWriter( 62 );
|
||||
writer3.Write( (byte) 0x80 );
|
||||
writer3.WriteAsciiFixed( "fakeusername", 30 );
|
||||
writer3.WriteAsciiFixed( "butter", 30 );
|
||||
writer3.Write( (byte) 0 );
|
||||
|
||||
byte[] packet3 = writer3.ToArray();
|
||||
int length3 = packet3.Length;
|
||||
|
||||
OutgoingPacketFilters.CheckPacket( ref packet3, ref length3 );
|
||||
|
||||
byte[] tmp2 = new byte[30];
|
||||
Buffer.BlockCopy( packet3, 31, tmp2, 0, 30 );
|
||||
|
||||
Assert.AreEqual( "butter", Encoding.ASCII.GetString( tmp2 ).TrimEnd( '\0' ) );
|
||||
|
||||
AssistantOptions.SavedPasswords.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user