PageRenderTime 647ms CodeModel.GetById 32ms RepoModel.GetById 9ms app.codeStats 0ms

/Scripts/Commands/Abstracted/Commands/Commands.cs

https://bitbucket.org/Kel/crepuscule
C# | 921 lines | 788 code | 133 blank | 0 comment | 112 complexity | a4c49f18e059bd9353c2a2238e7b86f7 MD5 | raw file
  1. using System;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using System.Collections;
  5. using Server;
  6. using Server.Items;
  7. using Server.Gumps;
  8. using Server.Spells;
  9. using Server.Mobiles;
  10. using Server.Network;
  11. using Server.Accounting;
  12. namespace Server.Scripts.Commands
  13. {
  14. public class TargetCommands
  15. {
  16. public static void Initialize()
  17. {
  18. Register( new KillCommand( true ) );
  19. Register( new KillCommand( false ) );
  20. Register( new HideCommand( true ) );
  21. Register( new HideCommand( false ) );
  22. Register( new KickCommand( true ) );
  23. Register( new KickCommand( false ) );
  24. Register( new FirewallCommand() );
  25. Register( new TeleCommand() );
  26. Register( new SetCommand() );
  27. Register( new AliasedSetCommand( AccessLevel.GameMaster, "Immortal", "blessed", "true", ObjectTypes.Mobiles ) );
  28. Register( new AliasedSetCommand( AccessLevel.GameMaster, "Invul", "blessed", "true", ObjectTypes.Mobiles ) );
  29. Register( new AliasedSetCommand( AccessLevel.GameMaster, "Mortal", "blessed", "false", ObjectTypes.Mobiles ) );
  30. Register( new AliasedSetCommand( AccessLevel.GameMaster, "NoInvul", "blessed", "false", ObjectTypes.Mobiles ) );
  31. Register( new AliasedSetCommand( AccessLevel.GameMaster, "Squelch", "squelched", "true", ObjectTypes.Mobiles ) );
  32. Register( new AliasedSetCommand( AccessLevel.GameMaster, "Unsquelch", "squelched", "false", ObjectTypes.Mobiles ) );
  33. Register( new GetCommand() );
  34. Register( new GetTypeCommand() );
  35. Register( new DeleteCommand() );
  36. Register( new RestockCommand() );
  37. Register( new DismountCommand() );
  38. Register( new AddCommand() );
  39. Register( new AddToPackCommand() );
  40. Register( new TellCommand() );
  41. Register( new PrivSoundCommand() );
  42. Register( new IncreaseCommand() );
  43. Register( new OpenBrowserCommand() );
  44. Register( new CountCommand() );
  45. Register( new InterfaceCommand() );
  46. }
  47. private static ArrayList m_AllCommands = new ArrayList();
  48. public static ArrayList AllCommands{ get{ return m_AllCommands; } }
  49. public static void Register( BaseCommand command )
  50. {
  51. m_AllCommands.Add( command );
  52. ArrayList impls = BaseCommandImplementor.Implementors;
  53. for ( int i = 0; i < impls.Count; ++i )
  54. {
  55. BaseCommandImplementor impl = (BaseCommandImplementor)impls[i];
  56. if ( (command.Supports & impl.SupportRequirement) != 0 )
  57. impl.Register( command );
  58. }
  59. }
  60. }
  61. public class CountCommand : BaseCommand
  62. {
  63. public CountCommand()
  64. {
  65. AccessLevel = AccessLevel.GameMaster;
  66. Supports = CommandSupport.Complex;
  67. Commands = new string[]{ "Count" };
  68. ObjectTypes = ObjectTypes.All;
  69. Usage = "Count";
  70. Description = "Counts the number of objects that a command modifier would use. Generally used with condition arguments.";
  71. ListOptimized = true;
  72. }
  73. public override void ExecuteList( CommandEventArgs e, ArrayList list )
  74. {
  75. if ( list.Count == 1 )
  76. AddResponse( "There is one matching object." );
  77. else
  78. AddResponse( String.Format( "There are {0} matching objects.", list.Count ) );
  79. }
  80. }
  81. public class OpenBrowserCommand : BaseCommand
  82. {
  83. public OpenBrowserCommand()
  84. {
  85. AccessLevel = AccessLevel.GameMaster;
  86. Supports = CommandSupport.AllMobiles;
  87. Commands = new string[]{ "OpenBrowser", "OB" };
  88. ObjectTypes = ObjectTypes.Mobiles;
  89. Usage = "OpenBrowser <url>";
  90. Description = "Opens the web browser of a targeted player to a specified url.";
  91. }
  92. public static void OpenBrowser_Callback( Mobile from, bool okay, object state )
  93. {
  94. object[] states = (object[])state;
  95. Mobile gm = (Mobile)states[0];
  96. string url = (string)states[1];
  97. if ( okay )
  98. {
  99. gm.SendMessage( "{0} : has opened their web browser to : {1}", from.Name, url );
  100. from.LaunchBrowser( url );
  101. }
  102. else
  103. {
  104. from.SendMessage( "You have chosen not to open your web browser." );
  105. gm.SendMessage( "{0} : has chosen not to open their web browser to : {1}", from.Name, url );
  106. }
  107. }
  108. public override void Execute( CommandEventArgs e, object obj )
  109. {
  110. if ( e.Length == 1 )
  111. {
  112. Mobile mob = (Mobile)obj;
  113. Mobile from = e.Mobile;
  114. if ( mob.Player )
  115. {
  116. NetState ns = mob.NetState;
  117. if ( ns == null )
  118. {
  119. LogFailure( "That player is not online." );
  120. }
  121. else
  122. {
  123. string url = e.GetString( 0 );
  124. CommandLogging.WriteLine( from, "{0} {1} requesting to open web browser of {2} to {3}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ), url );
  125. AddResponse( "Awaiting user confirmation..." );
  126. mob.SendGump( new WarningGump( 1060637, 30720, String.Format( "A game master is requesting to open your web browser to the following URL:<br>{0}", url ), 0xFFC000, 320, 240, new WarningGumpCallback( OpenBrowser_Callback ), new object[]{ from, url } ) );
  127. }
  128. }
  129. else
  130. {
  131. LogFailure( "That is not a player." );
  132. }
  133. }
  134. else
  135. {
  136. LogFailure( "Format: OpenBrowser <url>" );
  137. }
  138. }
  139. }
  140. public class IncreaseCommand : BaseCommand
  141. {
  142. public IncreaseCommand()
  143. {
  144. AccessLevel = AccessLevel.Counselor;
  145. Supports = CommandSupport.All;
  146. Commands = new string[]{ "Increase", "Inc" };
  147. ObjectTypes = ObjectTypes.Both;
  148. Usage = "Increase {<propertyName> <offset> ...}";
  149. Description = "Increases the value of a specified property by the specified offset.";
  150. }
  151. public override void Execute( CommandEventArgs e, object obj )
  152. {
  153. if ( obj is BaseMulti )
  154. {
  155. LogFailure( "This command does not work on multis." );
  156. }
  157. else if ( e.Length >= 2 )
  158. {
  159. string result = Properties.IncreaseValue( e.Mobile, obj, e.Arguments );
  160. if ( result == "The property has been increased." || result == "The properties have been increased." || result == "The property has been decreased." || result == "The properties have been decreased." || result == "The properties have been changed." )
  161. AddResponse( result );
  162. else
  163. LogFailure( result );
  164. }
  165. else
  166. {
  167. LogFailure( "Format: Increase {<propertyName> <offset> ...}" );
  168. }
  169. }
  170. }
  171. public class PrivSoundCommand : BaseCommand
  172. {
  173. public PrivSoundCommand()
  174. {
  175. AccessLevel = AccessLevel.GameMaster;
  176. Supports = CommandSupport.AllMobiles;
  177. Commands = new string[]{ "PrivSound" };
  178. ObjectTypes = ObjectTypes.Mobiles;
  179. Usage = "PrivSound <index>";
  180. Description = "Plays a sound to a given target.";
  181. }
  182. public override void Execute( CommandEventArgs e, object obj )
  183. {
  184. Mobile from = e.Mobile;
  185. if ( e.Length == 1 )
  186. {
  187. int index = e.GetInt32( 0 );
  188. Mobile mob = (Mobile)obj;
  189. CommandLogging.WriteLine( from, "{0} {1} playing sound {2} for {3}", from.AccessLevel, CommandLogging.Format( from ), index, CommandLogging.Format( mob ) );
  190. mob.Send( new PlaySound( index, mob.Location ) );
  191. }
  192. else
  193. {
  194. from.SendMessage( "Format: PrivSound <index>" );
  195. }
  196. }
  197. }
  198. public class TellCommand : BaseCommand
  199. {
  200. public TellCommand()
  201. {
  202. AccessLevel = AccessLevel.Counselor;
  203. Supports = CommandSupport.AllMobiles;
  204. Commands = new string[]{ "Tell" };
  205. ObjectTypes = ObjectTypes.Mobiles;
  206. Usage = "Tell \"text\"";
  207. Description = "Sends a system message to a targeted player.";
  208. }
  209. public override void Execute( CommandEventArgs e, object obj )
  210. {
  211. Mobile mob = (Mobile)obj;
  212. Mobile from = e.Mobile;
  213. CommandLogging.WriteLine( from, "{0} {1} telling {2} \"{3}\"", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ), e.ArgString );
  214. mob.SendMessage( e.ArgString );
  215. }
  216. }
  217. public class AddToPackCommand : BaseCommand
  218. {
  219. public AddToPackCommand()
  220. {
  221. AccessLevel = AccessLevel.GameMaster;
  222. Supports = CommandSupport.All;
  223. Commands = new string[]{ "AddToPack", "AddToCont" };
  224. ObjectTypes = ObjectTypes.Both;
  225. ListOptimized = true;
  226. Usage = "AddToPack <name> [params] [set {<propertyName> <value> ...}]";
  227. Description = "Adds an item by name to the backpack of a targeted player or npc, or a targeted container. Optional constructor parameters. Optional set property list.";
  228. }
  229. public override void ExecuteList( CommandEventArgs e, ArrayList list )
  230. {
  231. ArrayList packs = new ArrayList( list.Count );
  232. for ( int i = 0; i < list.Count; ++i )
  233. {
  234. object obj = list[i];
  235. Container cont = null;
  236. if ( obj is Mobile )
  237. cont = ((Mobile)obj).Backpack;
  238. else if ( obj is Container )
  239. cont = (Container)obj;
  240. if ( cont != null )
  241. packs.Add( cont );
  242. else
  243. LogFailure( "That is not a container." );
  244. }
  245. Add.Invoke( e.Mobile, e.Mobile.Location, e.Mobile.Location, e.Arguments, packs );
  246. }
  247. }
  248. public class AddCommand : BaseCommand
  249. {
  250. public AddCommand()
  251. {
  252. AccessLevel = AccessLevel.GameMaster;
  253. Supports = CommandSupport.Simple | CommandSupport.Self;
  254. Commands = new string[]{ "Add" };
  255. ObjectTypes = ObjectTypes.All;
  256. Usage = "Add [<name> [params] [set {<propertyName> <value> ...}]]";
  257. Description = "Adds an item or npc by name to a targeted location. Optional constructor parameters. Optional set property list. If no arguments are specified, this brings up a categorized add menu.";
  258. }
  259. public override bool ValidateArgs( BaseCommandImplementor impl, CommandEventArgs e )
  260. {
  261. if ( e.Length >= 1 )
  262. {
  263. Type t = ScriptCompiler.FindTypeByName( e.GetString( 0 ) );
  264. if ( t == null )
  265. {
  266. e.Mobile.SendMessage( "No type with that name was found." );
  267. string match = e.GetString( 0 ).Trim();
  268. if ( match.Length < 3 )
  269. {
  270. e.Mobile.SendMessage( "Invalid search string." );
  271. e.Mobile.SendGump(new Server.Gumps.CategorizedAddGump(e.Mobile, match, 0, Type.EmptyTypes, false));
  272. }
  273. else
  274. {
  275. e.Mobile.SendGump(new Server.Gumps.CategorizedAddGump(e.Mobile, match, 0, (Type[])CategorizedAddGump.Match(match).ToArray(typeof(Type)), true));
  276. }
  277. }
  278. else
  279. {
  280. return true;
  281. }
  282. }
  283. else
  284. {
  285. e.Mobile.SendGump( new Server.Gumps.CategorizedAddGump( e.Mobile ) );
  286. }
  287. return false;
  288. }
  289. public override void Execute( CommandEventArgs e, object obj )
  290. {
  291. IPoint3D p = obj as IPoint3D;
  292. if ( p == null )
  293. return;
  294. if ( p is Item )
  295. p = ((Item)p).GetWorldTop();
  296. else if ( p is Mobile )
  297. p = ((Mobile)p).Location;
  298. Add.Invoke( e.Mobile, new Point3D( p ), new Point3D( p ), e.Arguments );
  299. }
  300. }
  301. public class TeleCommand : BaseCommand
  302. {
  303. public TeleCommand()
  304. {
  305. AccessLevel = AccessLevel.Counselor;
  306. Supports = CommandSupport.Simple;
  307. Commands = new string[]{ "Teleport", "Tele" };
  308. ObjectTypes = ObjectTypes.All;
  309. Usage = "Teleport";
  310. Description = "Teleports your character to a targeted location.";
  311. }
  312. public override void Execute( CommandEventArgs e, object obj )
  313. {
  314. IPoint3D p = obj as IPoint3D;
  315. if ( p == null )
  316. return;
  317. Mobile from = e.Mobile;
  318. SpellHelper.GetSurfaceTop( ref p );
  319. CommandLogging.WriteLine( from, "{0} {1} teleporting to {2}", from.AccessLevel, CommandLogging.Format( from ), new Point3D( p ) );
  320. Point3D fromLoc = from.Location;
  321. Point3D toLoc = new Point3D( p );
  322. from.Location = toLoc;
  323. from.ProcessDelta();
  324. if ( !from.Hidden )
  325. {
  326. Effects.SendLocationParticles( EffectItem.Create( fromLoc, from.Map, EffectItem.DefaultDuration ), 0x3728, 10, 10, 2023 );
  327. Effects.SendLocationParticles( EffectItem.Create( toLoc, from.Map, EffectItem.DefaultDuration ), 0x3728, 10, 10, 5023 );
  328. from.PlaySound( 0x1FE );
  329. }
  330. }
  331. }
  332. public class DismountCommand : BaseCommand
  333. {
  334. public DismountCommand()
  335. {
  336. AccessLevel = AccessLevel.GameMaster;
  337. Supports = CommandSupport.AllMobiles;
  338. Commands = new string[]{ "Dismount" };
  339. ObjectTypes = ObjectTypes.Mobiles;
  340. Usage = "Dismount";
  341. Description = "Forcefully dismounts a given target.";
  342. }
  343. public override void Execute( CommandEventArgs e, object obj )
  344. {
  345. Mobile from = e.Mobile;
  346. Mobile mob = (Mobile)obj;
  347. CommandLogging.WriteLine( from, "{0} {1} dismounting {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ) );
  348. bool takenAction = false;
  349. for ( int i = 0; i < mob.Items.Count; ++i )
  350. {
  351. Item item = (Item)mob.Items[i];
  352. if ( item is IMountItem )
  353. {
  354. IMount mount = ((IMountItem)item).Mount;
  355. if ( mount != null )
  356. {
  357. mount.Rider = null;
  358. takenAction = true;
  359. }
  360. if ( mob.Items.IndexOf( item ) == -1 )
  361. --i;
  362. }
  363. }
  364. for ( int i = 0; i < mob.Items.Count; ++i )
  365. {
  366. Item item = (Item)mob.Items[i];
  367. if ( item.Layer == Layer.Mount )
  368. {
  369. takenAction = true;
  370. item.Delete();
  371. --i;
  372. }
  373. }
  374. if ( takenAction )
  375. AddResponse( "They have been dismounted." );
  376. else
  377. LogFailure( "They were not mounted." );
  378. }
  379. }
  380. public class RestockCommand : BaseCommand
  381. {
  382. public RestockCommand()
  383. {
  384. AccessLevel = AccessLevel.GameMaster;
  385. Supports = CommandSupport.AllNPCs;
  386. Commands = new string[]{ "Restock" };
  387. ObjectTypes = ObjectTypes.Mobiles;
  388. Usage = "Restock";
  389. Description = "Manually restocks a targeted vendor, refreshing the quantity of every item the vendor sells to the maximum. This also invokes the maximum quantity adjustment algorithms.";
  390. }
  391. public override void Execute( CommandEventArgs e, object obj )
  392. {
  393. if ( obj is BaseVendor )
  394. {
  395. CommandLogging.WriteLine( e.Mobile, "{0} {1} restocking {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( obj ) );
  396. ((BaseVendor)obj).Restock();
  397. AddResponse( "The vendor has been restocked." );
  398. }
  399. else
  400. {
  401. AddResponse( "That is not a vendor." );
  402. }
  403. }
  404. }
  405. public class GetTypeCommand : BaseCommand
  406. {
  407. public GetTypeCommand()
  408. {
  409. AccessLevel = AccessLevel.Counselor;
  410. Supports = CommandSupport.All;
  411. Commands = new string[]{ "GetType" };
  412. ObjectTypes = ObjectTypes.All;
  413. Usage = "GetType";
  414. Description = "Gets the type name of a targeted object.";
  415. }
  416. public override void Execute( CommandEventArgs e, object obj )
  417. {
  418. if ( obj == null )
  419. {
  420. AddResponse( "The object is null." );
  421. }
  422. else
  423. {
  424. Type type = obj.GetType();
  425. if ( type.DeclaringType == null )
  426. AddResponse( String.Format( "The type of that object is {0}.", type.Name ) );
  427. else
  428. AddResponse( String.Format( "The type of that object is {0}.", type.FullName ) );
  429. }
  430. }
  431. }
  432. public class GetCommand : BaseCommand
  433. {
  434. public GetCommand()
  435. {
  436. AccessLevel = AccessLevel.Counselor;
  437. Supports = CommandSupport.All;
  438. Commands = new string[]{ "Get" };
  439. ObjectTypes = ObjectTypes.All;
  440. Usage = "Get <propertyName>";
  441. Description = "Gets a property value by name of a targeted object.";
  442. }
  443. public override void Execute( CommandEventArgs e, object obj )
  444. {
  445. if ( e.Length == 1 )
  446. {
  447. string result = Properties.GetValue( e.Mobile, obj, e.GetString( 0 ) );
  448. if ( result == "Property not found." || result == "Property is write only." || result.StartsWith( "Getting this property" ) )
  449. LogFailure( result );
  450. else
  451. AddResponse( result );
  452. }
  453. else
  454. {
  455. LogFailure( "Format: Get <propertyName>" );
  456. }
  457. }
  458. }
  459. public class AliasedSetCommand : BaseCommand
  460. {
  461. private string m_Name;
  462. private string m_Value;
  463. public AliasedSetCommand( AccessLevel level, string command, string name, string value, ObjectTypes objects )
  464. {
  465. m_Name = name;
  466. m_Value = value;
  467. AccessLevel = level;
  468. if ( objects == ObjectTypes.Items )
  469. Supports = CommandSupport.AllItems;
  470. else if ( objects == ObjectTypes.Mobiles )
  471. Supports = CommandSupport.AllMobiles;
  472. else
  473. Supports = CommandSupport.All;
  474. Commands = new string[]{ command };
  475. ObjectTypes = objects;
  476. Usage = command;
  477. Description = String.Format( "Sets the {0} property to {1}.", name, value );
  478. }
  479. public override void Execute( CommandEventArgs e, object obj )
  480. {
  481. string result = Properties.SetValue( e.Mobile, obj, m_Name, m_Value );
  482. if ( result == "Property has been set." )
  483. AddResponse( result );
  484. else
  485. LogFailure( result );
  486. }
  487. }
  488. public class SetCommand : BaseCommand
  489. {
  490. public SetCommand()
  491. {
  492. AccessLevel = AccessLevel.Counselor;
  493. Supports = CommandSupport.All;
  494. Commands = new string[]{ "Set" };
  495. ObjectTypes = ObjectTypes.Both;
  496. Usage = "Set <propertyName> <value>";
  497. Description = "Sets a property value by name of a targeted object.";
  498. }
  499. public override void Execute( CommandEventArgs e, object obj )
  500. {
  501. if ( e.Length >= 2 )
  502. {
  503. string result = Properties.SetValue( e.Mobile, obj, e.GetString( 0 ), e.GetString( 1 ) );
  504. if ( result == "Property has been set." )
  505. AddResponse( result );
  506. else
  507. LogFailure( result );
  508. }
  509. else
  510. {
  511. LogFailure( "Format: Set <propertyName> <value>" );
  512. }
  513. }
  514. }
  515. public class DeleteCommand : BaseCommand
  516. {
  517. public DeleteCommand()
  518. {
  519. AccessLevel = AccessLevel.GameMaster;
  520. Supports = CommandSupport.AllNPCs | CommandSupport.AllItems;
  521. Commands = new string[]{ "Delete", "Remove" };
  522. ObjectTypes = ObjectTypes.Both;
  523. Usage = "Delete";
  524. Description = "Deletes a targeted item or mobile. Does not delete players.";
  525. }
  526. private void OnConfirmCallback( Mobile from, bool okay, object state )
  527. {
  528. object[] states = (object[])state;
  529. CommandEventArgs e = (CommandEventArgs)states[0];
  530. ArrayList list = (ArrayList)states[1];
  531. bool flushToLog = false;
  532. if ( okay )
  533. {
  534. AddResponse( "Delete command confirmed." );
  535. if ( list.Count > 20 )
  536. CommandLogging.Enabled = false;
  537. base.ExecuteList( e, list );
  538. if ( list.Count > 20 )
  539. {
  540. flushToLog = true;
  541. CommandLogging.Enabled = true;
  542. }
  543. }
  544. else
  545. {
  546. AddResponse( "Delete command aborted." );
  547. }
  548. Flush( from, flushToLog );
  549. }
  550. public override void ExecuteList( CommandEventArgs e, ArrayList list )
  551. {
  552. if ( list.Count > 1 )
  553. {
  554. e.Mobile.SendGump( new WarningGump( 1060637, 30720, String.Format( "You are about to delete {0} objects. This cannot be undone without a full server revert.<br><br>Continue?", list.Count ), 0xFFC000, 420, 280, new WarningGumpCallback( OnConfirmCallback ), new object[]{ e, list } ) );
  555. AddResponse( "Awaiting confirmation..." );
  556. }
  557. else
  558. {
  559. base.ExecuteList( e, list );
  560. }
  561. }
  562. public override void Execute( CommandEventArgs e, object obj )
  563. {
  564. if ( obj is Item )
  565. {
  566. CommandLogging.WriteLine( e.Mobile, "{0} {1} deleting {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( obj ) );
  567. ((Item)obj).Delete();
  568. AddResponse( "The item has been deleted." );
  569. }
  570. else if ( obj is Mobile && !((Mobile)obj).Player )
  571. {
  572. CommandLogging.WriteLine( e.Mobile, "{0} {1} deleting {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( obj ) );
  573. ((Mobile)obj).Delete();
  574. AddResponse( "The mobile has been deleted." );
  575. }
  576. else
  577. {
  578. LogFailure( "That cannot be deleted." );
  579. }
  580. }
  581. }
  582. public class KillCommand : BaseCommand
  583. {
  584. private bool m_Value;
  585. public KillCommand( bool value )
  586. {
  587. m_Value = value;
  588. AccessLevel = AccessLevel.GameMaster;
  589. Supports = CommandSupport.AllMobiles;
  590. Commands = value ? new string[]{ "Kill" } : new string[]{ "Resurrect", "Res" };
  591. ObjectTypes = ObjectTypes.Mobiles;
  592. if ( value )
  593. {
  594. Usage = "Kill";
  595. Description = "Kills a targeted player or npc.";
  596. }
  597. else
  598. {
  599. Usage = "Resurrect";
  600. Description = "Resurrects a targeted ghost.";
  601. }
  602. }
  603. public override void Execute( CommandEventArgs e, object obj )
  604. {
  605. Mobile mob = (Mobile)obj;
  606. Mobile from = e.Mobile;
  607. if ( m_Value )
  608. {
  609. if ( !mob.Alive )
  610. {
  611. LogFailure( "They are already dead." );
  612. }
  613. else if ( !mob.CanBeDamaged() )
  614. {
  615. LogFailure( "They cannot be harmed." );
  616. }
  617. else
  618. {
  619. CommandLogging.WriteLine( from, "{0} {1} killing {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ) );
  620. mob.Kill();
  621. AddResponse( "They have been killed." );
  622. }
  623. }
  624. else
  625. {
  626. if ( mob.IsDeadBondedPet )
  627. {
  628. BaseCreature bc = mob as BaseCreature;
  629. if ( bc != null )
  630. {
  631. CommandLogging.WriteLine( from, "{0} {1} resurrecting {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ) );
  632. bc.PlaySound( 0x214 );
  633. bc.FixedEffect( 0x376A, 10, 16 );
  634. bc.ResurrectPet();
  635. AddResponse( "It has been resurrected." );
  636. }
  637. }
  638. else if ( !mob.Alive )
  639. {
  640. CommandLogging.WriteLine( from, "{0} {1} resurrecting {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ) );
  641. mob.PlaySound( 0x214 );
  642. mob.FixedEffect( 0x376A, 10, 16 );
  643. mob.Resurrect();
  644. AddResponse( "They have been resurrected." );
  645. }
  646. else
  647. {
  648. LogFailure( "They are not dead." );
  649. }
  650. }
  651. }
  652. }
  653. public class HideCommand : BaseCommand
  654. {
  655. private bool m_Value;
  656. public HideCommand( bool value )
  657. {
  658. m_Value = value;
  659. AccessLevel = AccessLevel.Counselor;
  660. Supports = CommandSupport.AllMobiles;
  661. Commands = new string[]{ value ? "Hide" : "Unhide" };
  662. ObjectTypes = ObjectTypes.Mobiles;
  663. if ( value )
  664. {
  665. Usage = "Hide";
  666. Description = "Makes a targeted mobile disappear in a puff of smoke.";
  667. }
  668. else
  669. {
  670. Usage = "Unhide";
  671. Description = "Makes a targeted mobile appear in a puff of smoke.";
  672. }
  673. }
  674. public override void Execute( CommandEventArgs e, object obj )
  675. {
  676. Mobile m = (Mobile)obj;
  677. CommandLogging.WriteLine( e.Mobile, "{0} {1} {2} {3}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), m_Value ? "hiding" : "unhiding", CommandLogging.Format( m ) );
  678. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y, m.Z + 4 ), m.Map, 0x3728, 13 );
  679. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y, m.Z ), m.Map, 0x3728, 13 );
  680. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y, m.Z - 4 ), m.Map, 0x3728, 13 );
  681. Effects.SendLocationEffect( new Point3D( m.X, m.Y + 1, m.Z + 4 ), m.Map, 0x3728, 13 );
  682. Effects.SendLocationEffect( new Point3D( m.X, m.Y + 1, m.Z ), m.Map, 0x3728, 13 );
  683. Effects.SendLocationEffect( new Point3D( m.X, m.Y + 1, m.Z - 4 ), m.Map, 0x3728, 13 );
  684. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y + 1, m.Z + 11 ), m.Map, 0x3728, 13 );
  685. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y + 1, m.Z + 7 ), m.Map, 0x3728, 13 );
  686. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y + 1, m.Z + 3 ), m.Map, 0x3728, 13 );
  687. Effects.SendLocationEffect( new Point3D( m.X + 1, m.Y + 1, m.Z - 1 ), m.Map, 0x3728, 13 );
  688. m.PlaySound( 0x228 );
  689. m.Hidden = m_Value;
  690. if ( m_Value )
  691. AddResponse( "They have been hidden." );
  692. else
  693. AddResponse( "They have been revealed." );
  694. }
  695. }
  696. public class FirewallCommand : BaseCommand
  697. {
  698. public FirewallCommand()
  699. {
  700. AccessLevel = AccessLevel.Administrator;
  701. Supports = CommandSupport.AllMobiles;
  702. Commands = new string[]{ "Firewall" };
  703. ObjectTypes = ObjectTypes.Mobiles;
  704. Usage = "Firewall";
  705. Description = "Adds a targeted player to the firewall (list of blocked IP addresses). This command does not ban or kick.";
  706. }
  707. public override void Execute( CommandEventArgs e, object obj )
  708. {
  709. Mobile from = e.Mobile;
  710. Mobile targ = (Mobile)obj;
  711. NetState state = targ.NetState;
  712. if ( state != null )
  713. {
  714. CommandLogging.WriteLine( from, "{0} {1} firewalling {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targ ) );
  715. try
  716. {
  717. Firewall.Add( ((IPEndPoint)state.Socket.RemoteEndPoint).Address );
  718. AddResponse( "They have been firewalled." );
  719. }
  720. catch ( Exception ex )
  721. {
  722. LogFailure( ex.Message );
  723. }
  724. }
  725. else
  726. {
  727. LogFailure( "They are not online." );
  728. }
  729. }
  730. }
  731. public class KickCommand : BaseCommand
  732. {
  733. private bool m_Ban;
  734. public KickCommand( bool ban )
  735. {
  736. m_Ban = ban;
  737. AccessLevel = ( ban ? AccessLevel.Administrator : AccessLevel.GameMaster );
  738. Supports = CommandSupport.AllMobiles;
  739. Commands = new string[]{ ban ? "Ban" : "Kick" };
  740. ObjectTypes = ObjectTypes.Mobiles;
  741. if ( ban )
  742. {
  743. Usage = "Ban";
  744. Description = "Bans the account of a targeted player.";
  745. }
  746. else
  747. {
  748. Usage = "Kick";
  749. Description = "Disconnects a targeted player.";
  750. }
  751. }
  752. public override void Execute( CommandEventArgs e, object obj )
  753. {
  754. Mobile from = e.Mobile;
  755. Mobile targ = (Mobile)obj;
  756. if ( from.AccessLevel > targ.AccessLevel )
  757. {
  758. NetState fromState = from.NetState, targState = targ.NetState;
  759. if ( fromState != null && targState != null )
  760. {
  761. Account fromAccount = fromState.Account as Account;
  762. Account targAccount = targState.Account as Account;
  763. if ( fromAccount != null && targAccount != null )
  764. {
  765. CommandLogging.WriteLine( from, "{0} {1} {2} {3}", from.AccessLevel, CommandLogging.Format( from ), m_Ban ? "banning" : "kicking", CommandLogging.Format( targ ) );
  766. targ.Say( "I've been {0}!", m_Ban ? "banned" : "kicked" );
  767. AddResponse( String.Format( "They have been {0}.", m_Ban ? "banned" : "kicked" ) );
  768. targState.Dispose();
  769. if ( m_Ban )
  770. {
  771. targAccount.Banned = true;
  772. targAccount.SetUnspecifiedBan( from );
  773. from.SendGump( new BanDurationGump( targAccount ) );
  774. }
  775. }
  776. }
  777. else if ( targState == null )
  778. {
  779. LogFailure( "They are not online." );
  780. }
  781. }
  782. else
  783. {
  784. LogFailure( "You do not have the required access level to do this." );
  785. }
  786. }
  787. }
  788. }