Overwrite

Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
Unstable Kitsune
2023-11-28 23:20:26 -05:00
parent 3cd54811de
commit b918192e4e
11608 changed files with 2644205 additions and 47 deletions

View File

@@ -0,0 +1,258 @@
using System;
using System.Collections;
using System.IO;
using Server;
using Server.Commands;
using Server.Commands.Generic;
namespace Knives.Utils
{
public class Commands
{
public static void Initialize()
{
CommandSystem.Register( "Commands", AccessLevel.Administrator, new CommandEventHandler( OnCommands ) );
EventSink.Login += new LoginEventHandler( OnLogin );
}
private static void OnCommands( CommandEventArgs e )
{
CommandsGump.SendTo( e.Mobile );
}
private static Hashtable s_Defaults = new Hashtable();
private static ArrayList s_InitInfo = new ArrayList();
private static bool s_Inited;
public static bool HasMod( string command )
{
return s_Defaults[command] != null && new ArrayList(CommandSystem.Entries.Keys).Contains(command);
}
public static void RestoreCommand( string command )
{try{
if ( !HasMod( command ) )
{
s_Defaults.Remove( command );
CommandSystem.Entries.Remove( command );
return;
}
DefaultInfo info = (DefaultInfo)s_Defaults[command];
CommandEntry entry = new CommandEntry(info.OldCommand, ((CommandEntry)CommandSystem.Entries[command]).Handler, info.OldAccess);
CommandSystem.Entries.Remove(command);
if ( HasMod( info.OldCommand ) )
RestoreCommand( info.OldCommand );
CommandSystem.Entries[info.OldCommand] = entry;
s_Defaults.Remove( command );
foreach( BaseCommandImplementor imp in BaseCommandImplementor.Implementors )
foreach( string str in new ArrayList( imp.Commands.Keys ) )
if ( str == command )
{
imp.Commands[info.OldCommand] = imp.Commands[str];
((BaseCommand)imp.Commands[str]).AccessLevel = info.OldAccess;
if ( str != info.OldCommand )
imp.Commands.Remove( str );
}
}
catch{ Errors.Report("Commands-> RestoreDefault"); }
}
public static void ApplyCommand( string old, string txt )
{try{
if (CommandSystem.Entries[txt] != null
|| CommandSystem.Entries[old] == null)
return;
if ( HasMod( old ) )
{
((DefaultInfo)s_Defaults[old]).NewCommand = txt;
s_Defaults[txt] = s_Defaults[old];
s_Defaults.Remove( old );
}
else
{
DefaultInfo info = new DefaultInfo();
info.OldCommand = old;
info.NewCommand = txt;
info.NewAccess = ((CommandEntry)CommandSystem.Entries[old]).AccessLevel;
info.OldAccess = info.NewAccess;
s_Defaults[txt] = info;
}
CommandSystem.Entries[txt] = CommandSystem.Entries[old];
CommandSystem.Entries.Remove(old);
foreach( BaseCommandImplementor imp in BaseCommandImplementor.Implementors )
foreach( string str in new ArrayList( imp.Commands.Keys ) )
if ( str == old )
{
imp.Commands[txt] = imp.Commands[str];
imp.Commands.Remove( str );
}
}catch{ Errors.Report( "Commands-> ApplyCommand" ); } }
public static void Access( string command, int num )
{try{
if (CommandSystem.Entries[command] == null)
return;
DefaultInfo info = new DefaultInfo();
if ( !HasMod( command ) )
{
info = new DefaultInfo();
info.OldCommand = command;
info.NewCommand = command;
info.NewAccess = ((CommandEntry)CommandSystem.Entries[command]).AccessLevel + num;
info.OldAccess = ((CommandEntry)CommandSystem.Entries[command]).AccessLevel;
s_Defaults[command] = info;
}
else
{
info = (DefaultInfo)s_Defaults[command];
info.NewAccess = info.NewAccess+num;
}
CommandEntry entry = new CommandEntry(command, ((CommandEntry)CommandSystem.Entries[command]).Handler, info.NewAccess);
CommandSystem.Entries[command] = entry;
foreach( BaseCommandImplementor imp in BaseCommandImplementor.Implementors )
foreach( string str in new ArrayList( imp.Commands.Keys ) )
if ( str == command )
((BaseCommand)imp.Commands[str]).AccessLevel = info.NewAccess;
}catch{ Errors.Report( "Commands-> Access-> Int" ); } }
public static void Access( string command, AccessLevel level )
{try{
if (CommandSystem.Entries[command] == null)
return;
DefaultInfo info = new DefaultInfo();
if ( !HasMod( command ) )
{
info = new DefaultInfo();
info.OldCommand = command;
info.NewCommand = command;
info.NewAccess = level;
info.OldAccess = ((CommandEntry)CommandSystem.Entries[command]).AccessLevel;
s_Defaults[command] = info;
}
else
{
info = (DefaultInfo)s_Defaults[command];
info.NewAccess = level;
}
CommandEntry entry = new CommandEntry(command, ((CommandEntry)CommandSystem.Entries[command]).Handler, info.NewAccess);
CommandSystem.Entries[command] = entry;
foreach( BaseCommandImplementor imp in BaseCommandImplementor.Implementors )
foreach( string str in new ArrayList( imp.Commands.Keys ) )
if ( str == command )
((BaseCommand)imp.Commands[str]).AccessLevel = info.NewAccess;
}catch{ Errors.Report( "Commands-> Access-> AccessLevel" ); } }
public static void Configure()
{
EventSink.WorldLoad += new WorldLoadEventHandler( OnLoad );
EventSink.WorldSave += new WorldSaveEventHandler( OnSave );
}
private static void OnSave( WorldSaveEventArgs e )
{try{
if ( !Directory.Exists( "Saves/Commands/" ) )
Directory.CreateDirectory( "Saves/Commands/" );
GenericWriter writer = new BinaryFileWriter( Path.Combine( "Saves/Commands/", "Commands.bin" ), true );
writer.Write( 0 ); // version
ArrayList list = new ArrayList( s_Defaults.Values );
writer.Write( list.Count );
foreach( DefaultInfo info in list )
{
writer.Write( info.NewCommand );
writer.Write( info.OldCommand );
writer.Write( (int)info.NewAccess );
}
writer.Close();
}catch{ Errors.Report( "Commands-> OnSave" ); } }
private static void OnLoad()
{try{
if ( !File.Exists( Path.Combine( "Saves/Commands/", "Commands.bin" ) ) )
return;
using ( FileStream bin = new FileStream( Path.Combine( "Saves/Commands/", "Commands.bin" ), FileMode.Open, FileAccess.Read, FileShare.Read ) )
{
GenericReader reader = new BinaryFileReader( new BinaryReader( bin ) );
int version = reader.ReadInt();
int count = reader.ReadInt();
object[] obj;
for( int i = 0; i < count; ++i )
{
obj = new object[3];
obj[0] = reader.ReadString();
obj[1] = reader.ReadString();
obj[2] = reader.ReadInt();
s_InitInfo.Add( obj );
}
}
}catch{ Errors.Report( "Commands-> OnLoad" ); } }
private static void OnLogin( LoginEventArgs e )
{
if ( s_Inited )
return;
s_Inited = true;
foreach( object[] obj in s_InitInfo )
{
ApplyCommand( obj[1].ToString(), obj[0].ToString() );
Access( obj[0].ToString(), (AccessLevel)obj[2] );
}
}
private class DefaultInfo
{
private string c_NewCommand;
private string c_OldCommand;
private AccessLevel c_NewAccess;
private AccessLevel c_OldAccess;
public string NewCommand{ get{ return c_NewCommand; } set{ c_NewCommand = value; } }
public string OldCommand{ get{ return c_OldCommand; } set{ c_OldCommand = value; } }
public AccessLevel NewAccess{ get{ return c_NewAccess; } set{ c_NewAccess = value; } }
public AccessLevel OldAccess{ get{ return c_OldAccess; } set{ c_OldAccess = value; } }
public DefaultInfo()
{
}
}
}
}

View File

@@ -0,0 +1,187 @@
using System;
using System.Collections;
using Server;
using Server.Commands;
namespace Knives.Utils
{
public class CommandsGump : GumpPlus
{
public static void SendTo( Mobile m )
{
new CommandsGump( m );
}
private static string s_Help = " With this interface, you can modify every command and the Access Level required to use it! Should I warn you about changing some of these? Sure, why not. "
+ "Remember to only allow staff levels you can trust access to certain commands! This system won't let you run two commands from a single input, nor can you input a blank command or one with spaces. "
+ "If you get lost, simple hit the red button just to the left of the command to reset it. Enjoy!";
private const int Width = 250;
private const int Height = 350;
public ArrayList c_List = new ArrayList();
public int c_Page = 0;
public CommandsGump( Mobile m ) : base( m, 100, 100 )
{
NewGump();
}
protected override void BuildGump()
{
AddBackground( 0, 0, Width, Height, 0x13BE );
AddButton( Width-20, Height-20, 0x5689, 0x5689, "Help", new TimerCallback( Help ) );
BuildList();
DisplayList();
}
private void BuildList()
{
c_List.Clear();
foreach( string str in CommandSystem.Entries.Keys )
if ( ((CommandEntry)CommandSystem.Entries[str]).AccessLevel <= Owner.AccessLevel )
c_List.Add( str );
c_List.Sort( new InternalSorter() );
}
private void DisplayList()
{
int toList = 10;
int beginAt = toList*c_Page;
while( c_Page > 0 )
{
if ( beginAt > c_List.Count )
beginAt = toList * --c_Page;
else
break;
}
if ( c_Page != 0 )
AddButton( Width/2-7, 30, 0x15E0, 0x15E4, "Next Page", new TimerCallback( PageDown ) );
if ( c_Page < (c_List.Count-1)/toList )
AddButton( Width/2-7, Height-25, 0x15E2, 0x15E6, "Previous Page", new TimerCallback( PageUp ) );
int y = 30;
int x = 20;
AddHtml( 20, 10, Width-40, 21, "<CENTER>Command Mod Menu", false, false );
for( int i = beginAt; i < c_List.Count && i < beginAt+toList; ++i )
{
AddImageTiled( x, y+=25, 100, 21, 0xBBA );
AddTextField( x, y, 100, 21, 0x480, i, c_List[i].ToString() );
AddButton( x+105, y+3, 0x93A, 0x93A, "Submit Command Name", new TimerStateCallback( ApplyCommand ), i );
if( Commands.HasMod( c_List[i].ToString() ) )
AddButton( 5, y+3, 0x29F6, 0x29F6, "Restore Default", new TimerStateCallback( RestoreDefault ), i );
AddHtml( x+130, y, 100, 21, ((CommandEntry)CommandSystem.Entries[c_List[i].ToString()]).AccessLevel.ToString(), false, false );
if ( ((CommandEntry)CommandSystem.Entries[c_List[i].ToString()]).AccessLevel < AccessLevel.Administrator )
AddButton( x+210, y, 0x983, 0x983, "Access Up", new TimerStateCallback( AccessUp ), i );
if ( ((CommandEntry)CommandSystem.Entries[c_List[i].ToString()]).AccessLevel > AccessLevel.Player )
AddButton( x+210, y+10, 0x985, 0x985, "Access Down", new TimerStateCallback( AccessDown ), i );
}
}
private void Help()
{
NewGump();
InfoGump.SendTo( Owner, 300, 300, s_Help, true );
}
private void PageUp()
{
c_Page++;
NewGump();
}
private void PageDown()
{
c_Page--;
NewGump();
}
private void RestoreDefault( object obj )
{
if ( !(obj is int) )
return;
if ( Commands.HasMod( c_List[(int)obj].ToString() ) )
Commands.RestoreCommand( c_List[(int)obj].ToString() );
NewGump();
}
private void ApplyCommand( object obj )
{
if ( !(obj is int) )
return;
if ( GetTextField( (int)obj ) == "" || GetTextField( (int)obj ).IndexOf( " " ) != -1 )
{
NewGump();
return;
}
if ( CommandSystem.Entries[GetTextField( (int)obj )] != null )
Owner.SendMessage( "That command already exists." );
else
Commands.ApplyCommand( c_List[(int)obj].ToString(), GetTextField( (int)obj ) );
NewGump();
}
private void AccessUp( object obj )
{
if ( !(obj is int) )
return;
Commands.Access( c_List[(int)obj].ToString(), 1 );
NewGump();
}
private void AccessDown( object obj )
{
if ( !(obj is int) )
return;
Commands.Access( c_List[(int)obj].ToString(), -1 );
NewGump();
}
private class InternalSorter : IComparer
{
public InternalSorter()
{
}
public int Compare( object x, object y )
{
if ( x == null && y == null )
return 0;
else if ( x == null )
return -1;
else if ( y == null )
return 1;
string a = x as string;
string b = y as string;
if ( a == null || b == null )
return 0;
return Insensitive.Compare( a, b );
}
}
}
}