Removed mousefontchars, valid chars are 0x20-0xA9(32-169)

Added checking to player names too.
This commit is contained in:
high 2011-07-09 10:00:00 -04:00
parent 1cd0f4c74b
commit b382125cc5
8 changed files with 33 additions and 31 deletions

View file

@ -134,8 +134,6 @@ namespace TShockAPI
{ {
byte playerid = args.Data.ReadInt8(); byte playerid = args.Data.ReadInt8();
byte hair = args.Data.ReadInt8(); byte hair = args.Data.ReadInt8();
//Various colours here
args.Data.Position += 21; args.Data.Position += 21;
bool hardcore = args.Data.ReadBoolean(); bool hardcore = args.Data.ReadBoolean();
string name = Encoding.ASCII.GetString(args.Data.ReadBytes((int)(args.Data.Length - args.Data.Position - 1))); string name = Encoding.ASCII.GetString(args.Data.ReadBytes((int)(args.Data.Length - args.Data.Position - 1)));
@ -145,6 +143,11 @@ namespace TShockAPI
Tools.ForceKick(args.Player, "Hair crash exploit."); Tools.ForceKick(args.Player, "Hair crash exploit.");
return true; return true;
} }
if (!Tools.ValidString(name))
{
Tools.ForceKick(args.Player, "Unprintable character in name");
return true;
}
if (name.Length > 32) if (name.Length > 32)
{ {
Tools.ForceKick(args.Player, "Name exceeded 32 characters."); Tools.ForceKick(args.Player, "Name exceeded 32 characters.");

View file

@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.4.0708")] [assembly: AssemblyVersion("2.3.4.0709")]
[assembly: AssemblyFileVersion("2.3.4.0708")] [assembly: AssemblyFileVersion("2.3.4.0709")]

View file

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.1 // Runtime Version:4.0.30319.235
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
@ -91,15 +91,6 @@ namespace TShockAPI {
} }
} }
/// <summary>
/// Looks up a localized string similar to !&quot;#$%&amp;&apos;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…///†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©.
/// </summary>
internal static string mousefontchars {
get {
return ResourceManager.GetString("mousefontchars", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to #format /// Looks up a localized string similar to #format
///#ip group ///#ip group

View file

@ -124,9 +124,6 @@
<data name="itembans" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="itembans" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>config\itembans.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> <value>config\itembans.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data> </data>
<data name="mousefontchars" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>config\mousefontchars.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="users" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="users" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>config\users.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value> <value>config\users.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data> </data>

View file

@ -26,6 +26,7 @@ using System.Reflection;
using System.Threading; using System.Threading;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Terraria; using Terraria;
using TerrariaAPI; using TerrariaAPI;
using TerrariaAPI.Hooks; using TerrariaAPI.Hooks;
@ -113,7 +114,7 @@ namespace TShockAPI
RegionManager.ReadAllSettings(); RegionManager.ReadAllSettings();
WarpsManager.ReadAllSettings(); WarpsManager.ReadAllSettings();
ItemManager.LoadBans(); ItemManager.LoadBans();
RconHandler.StartThread(); //RconHandler.StartThread();
Log.ConsoleInfo("AutoSave " + (TShock.Config.AutoSave ? "Enabled" : "Disabled")); Log.ConsoleInfo("AutoSave " + (TShock.Config.AutoSave ? "Enabled" : "Disabled"));
Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled")); Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));
@ -319,14 +320,11 @@ namespace TShockAPI
return; return;
} }
foreach (var character in text) if (!Tools.ValidString(text))
{ {
if (Resources.mousefontchars.IndexOf(character) == -1) Tools.Kick(tsplr, "Unprintable character in chat");
{ e.Handled = true;
Tools.HandleCheater(tsplr, "Attempted to crash clients"); return;
e.Handled = true;
return;
}
} }
if (msg.whoAmI != ply) if (msg.whoAmI != ply)

View file

@ -135,7 +135,6 @@
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="config\mousefontchars.txt" />
<Content Include="config\itembans.txt" /> <Content Include="config\itembans.txt" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@ -148,7 +147,7 @@
</PropertyGroup> </PropertyGroup>
<ProjectExtensions> <ProjectExtensions>
<VisualStudio> <VisualStudio>
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" /> <UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
</VisualStudio> </VisualStudio>
</ProjectExtensions> </ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View file

@ -659,5 +659,20 @@ namespace TShockAPI
return bytes.Aggregate("", (s, b) => s + b.ToString("X2")); return bytes.Aggregate("", (s, b) => s + b.ToString("X2"));
} }
} }
/// <summary>
/// Checks if the string contains any unprintable characters
/// </summary>
/// <param name="str">String to check</param>
/// <returns>True if the string only contains printable characters</returns>
public static bool ValidString(string str)
{
foreach (var c in str)
{
if (c < 0x20 || c > 0xA9)
return false;
}
return true;
}
} }
} }

View file

@ -1 +0,0 @@
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©