2018-04-02 01:25:06 -04:00
using SharedLibrary.Database ;
using SharedLibrary.Database.Models ;
using SharedLibrary.Exceptions ;
using SharedLibrary.Objects ;
using SharedLibrary.Services ;
using System ;
2015-03-08 17:20:10 -04:00
using System.Collections.Generic ;
2018-04-02 01:25:06 -04:00
using System.Data.Entity ;
2017-06-01 13:42:28 -04:00
using System.Linq ;
2018-04-02 01:25:06 -04:00
using System.Text ;
2017-11-25 20:29:58 -05:00
using System.Threading.Tasks ;
2017-05-26 18:49:27 -04:00
namespace SharedLibrary.Commands
2015-03-08 17:20:10 -04:00
{
2017-06-19 13:58:01 -04:00
public class CQuit : Command
2017-05-26 18:49:27 -04:00
{
2017-11-15 16:04:13 -05:00
public CQuit ( ) :
base ( "quit" , "quit IW4MAdmin" , "q" , Player . Permission . Owner , false )
{ }
2017-05-26 18:49:27 -04:00
2017-06-12 13:50:00 -04:00
public override Task ExecuteAsync ( Event E )
2017-05-26 18:49:27 -04:00
{
2017-06-12 13:50:00 -04:00
return Task . Run ( ( ) = > { E . Owner . Manager . Stop ( ) ; } ) ;
2017-05-26 18:49:27 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class COwner : Command
2017-08-17 19:28:08 -04:00
{
2017-11-15 16:04:13 -05:00
public COwner ( ) :
base ( "owner" , "claim ownership of the server" , "o" , Player . Permission . User , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2017-11-25 20:29:58 -05:00
if ( ( await ( E . Owner . Manager . GetClientService ( ) as Services . ClientService ) . GetOwners ( ) ) . Count = = 0 )
2015-03-08 17:20:10 -04:00
{
2017-11-25 20:29:58 -05:00
E . Origin . Level = Player . Permission . Owner ;
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "Congratulations, you have claimed ownership of this server!" ) ;
2017-11-25 20:29:58 -05:00
await E . Owner . Manager . GetClientService ( ) . Update ( E . Origin ) ;
2015-03-08 17:20:10 -04:00
}
else
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "This server already has an owner!" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 16:46:31 -04:00
public class CWarn : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CWarn ( ) :
base ( "warn" , "warn player for infringing rules" , "w" , Player . Permission . Trusted , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
Name = "reason" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
if ( E . Origin . Level < = E . Target . Level )
2017-06-19 13:58:01 -04:00
await E . Origin . Tell ( $"You do not have the required privileges to warn {E.Target.Name}" ) ;
2015-03-08 17:20:10 -04:00
else
2017-11-29 19:35:50 -05:00
await E . Target . Warn ( E . Data , E . Origin ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CWarnClear : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CWarnClear ( ) :
base ( "warnclear" , "remove all warning for a player" , "wc" , Player . Permission . Trusted , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
E . Target . Warnings = 0 ;
2015-08-20 01:06:44 -04:00
String Message = String . Format ( "All warning cleared for {0}" , E . Target . Name ) ;
2017-05-26 18:49:27 -04:00
await E . Owner . Broadcast ( Message ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CKick : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CKick ( ) :
base ( "kick" , "kick a player by name" , "k" , Player . Permission . Trusted , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
Name = "reason" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
if ( E . Origin . Level > E . Target . Level )
2017-06-19 13:58:01 -04:00
{
await E . Owner . ExecuteEvent ( new Event ( Event . GType . Kick , E . Data , E . Origin , E . Target , E . Owner ) ) ;
2017-11-29 19:35:50 -05:00
await E . Target . Kick ( E . Data , E . Origin ) ;
2017-11-18 01:59:37 -05:00
await E . Origin . Tell ( $"^5{E.Target} ^7has been kicked" ) ;
2017-06-19 13:58:01 -04:00
}
2015-03-08 17:20:10 -04:00
else
2017-08-17 19:28:08 -04:00
await E . Origin . Tell ( $"You do not have the required privileges to kick {E.Target.Name}" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CSay : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CSay ( ) :
base ( "say" , "broadcast message to all players" , "s" , Player . Permission . Moderator , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "message" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2017-06-12 13:50:00 -04:00
await E . Owner . Broadcast ( $"^:{E.Origin.Name} - ^6{E.Data}^7" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CTempBan : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CTempBan ( ) :
base ( "tempban" , "temporarily ban a player for specified time (defaults to 1 hour)" , "tb" , Player . Permission . Moderator , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
2017-11-16 18:09:19 -05:00
Name = "duration (m|h|d|w|y)" ,
2017-11-15 16:04:13 -05:00
Required = true ,
} ,
new CommandArgument ( )
{
Name = "reason" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2017-11-29 19:35:50 -05:00
String Message = Utilities . RemoveWords ( E . Data , 1 ) . Trim ( ) ;
2018-02-22 01:06:21 -05:00
var length = E . Data . Split ( ' ' ) [ 0 ] . ToLower ( ) . ParseTimespan ( ) ;
2018-03-06 02:22:19 -05:00
if ( length . TotalHours > = 1 & & length . TotalHours < 2 )
2018-03-27 20:27:01 -04:00
Message = E . Data . Replace ( "1h" , "" ) . Replace ( "1H" , "" ) ;
2017-08-23 18:29:48 -04:00
2015-08-20 01:06:44 -04:00
if ( E . Origin . Level > E . Target . Level )
2017-05-31 01:31:56 -04:00
{
2017-08-23 18:29:48 -04:00
await E . Target . TempBan ( Message , length , E . Origin ) ;
2017-11-18 01:59:37 -05:00
await E . Origin . Tell ( $"^5{E.Target} ^7has been temporarily banned for ^5{length.TimeSpanText()}" ) ;
2017-05-31 01:31:56 -04:00
}
2015-03-08 17:20:10 -04:00
else
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "You cannot temp ban " + E . Target . Name ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CBan : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CBan ( ) :
base ( "ban" , "permanently ban a player from the server" , "b" , Player . Permission . SeniorAdmin , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
2017-11-16 18:09:19 -05:00
Name = "reason" ,
Required = true
2017-11-15 16:04:13 -05:00
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
if ( E . Origin . Level > E . Target . Level )
2015-03-09 00:28:57 -04:00
{
2017-11-25 20:29:58 -05:00
await E . Target . Ban ( E . Data , E . Origin ) ;
2017-11-18 01:59:37 -05:00
await E . Origin . Tell ( $"^5{E.Target} ^7has been permanently banned" ) ;
2015-03-09 00:28:57 -04:00
}
2015-03-08 17:20:10 -04:00
else
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "You cannot ban " + E . Target . Name ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CUnban : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CUnban ( ) :
base ( "unban" , "unban player by database id" , "ub" , Player . Permission . SeniorAdmin , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "databaseID" ,
Required = true ,
2018-02-17 01:13:38 -05:00
} ,
new CommandArgument ( )
{
Name = "reason" ,
Required = true
2017-11-15 16:04:13 -05:00
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2018-02-17 01:13:38 -05:00
var penalties = await E . Owner . Manager . GetPenaltyService ( ) . GetActivePenaltiesAsync ( E . Target . AliasLinkId ) ;
if ( penalties . Where ( p = > p . Type = = Penalty . PenaltyType . Ban ) . FirstOrDefault ( ) ! = null )
{
await E . Owner . Unban ( E . Data , E . Target , E . Origin ) ;
await E . Origin . Tell ( $"Successfully unbanned {E.Target}" ) ;
}
else
{
await E . Origin . Tell ( $"{E.Target} is not banned" ) ;
}
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CWhoAmI : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CWhoAmI ( ) :
base ( "whoami" , "give information about yourself." , "who" , Player . Permission . User , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2018-02-17 15:06:37 -05:00
String You = String . Format ( "{0} [^3#{1}^7] {2} [^3@{3}^7] [{4}^7] IP: {5}" , E . Origin . Name , E . Origin . ClientNumber , E . Origin . NetworkId , E . Origin . ClientId , Utilities . ConvertLevelToColor ( E . Origin . Level ) , E . Origin . IPAddressString ) ;
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( You ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CList : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CList ( ) :
base ( "list" , "list active clients" , "l" , Player . Permission . Moderator , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2015-08-26 01:49:47 -04:00
StringBuilder playerList = new StringBuilder ( ) ;
2017-05-26 18:49:27 -04:00
int count = 0 ;
for ( int i = 0 ; i < E . Owner . Players . Count ; i + + )
2015-03-08 17:20:10 -04:00
{
2017-05-26 18:49:27 -04:00
var P = E . Owner . Players [ i ] ;
2015-03-11 00:47:34 -04:00
2017-05-26 18:49:27 -04:00
if ( P = = null )
continue ;
if ( P . Masked )
2017-11-25 20:29:58 -05:00
playerList . AppendFormat ( "[^3{0}^7]{3}[^3{1}^7] {2}" , Utilities . ConvertLevelToColor ( Player . Permission . User ) , P . ClientNumber , P . Name , Utilities . GetSpaces ( Player . Permission . SeniorAdmin . ToString ( ) . Length - Player . Permission . User . ToString ( ) . Length ) ) ;
2017-05-26 18:49:27 -04:00
else
2017-11-25 20:29:58 -05:00
playerList . AppendFormat ( "[^3{0}^7]{3}[^3{1}^7] {2}" , Utilities . ConvertLevelToColor ( P . Level ) , P . ClientNumber , P . Name , Utilities . GetSpaces ( Player . Permission . SeniorAdmin . ToString ( ) . Length - P . Level . ToString ( ) . Length ) ) ;
2015-08-26 01:49:47 -04:00
2017-06-07 20:59:59 -04:00
if ( count = = 2 | | E . Owner . GetPlayersAsList ( ) . Count = = 1 )
2017-05-26 18:49:27 -04:00
{
await E . Origin . Tell ( playerList . ToString ( ) ) ;
count = 0 ;
playerList = new StringBuilder ( ) ;
continue ;
2015-07-15 17:11:29 -04:00
}
2017-05-26 18:49:27 -04:00
count + + ;
2015-03-08 17:20:10 -04:00
}
}
}
2017-06-19 13:58:01 -04:00
public class CHelp : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CHelp ( ) :
base ( "help" , "list all available commands" , "h" , Player . Permission . User , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "command" ,
Required = false
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
String cmd = E . Data . Trim ( ) ;
if ( cmd . Length > 2 )
{
bool found = false ;
2017-05-26 18:49:27 -04:00
foreach ( Command C in E . Owner . Manager . GetCommands ( ) )
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
if ( C . Name = = cmd . ToLower ( ) )
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
await E . Origin . Tell ( "[^3" + C . Name + "^7] " + C . Description ) ;
await E . Origin . Tell ( C . Syntax ) ;
2015-03-08 17:20:10 -04:00
found = true ;
}
}
if ( ! found )
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "Could not find that command" ) ;
2015-03-08 17:20:10 -04:00
}
else
{
2015-03-11 00:47:34 -04:00
int count = 0 ;
2015-08-22 12:41:14 -04:00
StringBuilder helpResponse = new StringBuilder ( ) ;
2017-09-29 22:42:24 -04:00
var CommandList = E . Owner . Manager . GetCommands ( ) ;
2015-03-11 00:47:34 -04:00
2017-05-26 18:49:27 -04:00
foreach ( Command C in CommandList )
2017-08-17 19:28:08 -04:00
{
2015-08-20 01:06:44 -04:00
if ( E . Origin . Level > = C . Permission )
2015-03-08 17:20:10 -04:00
{
2015-08-22 12:41:14 -04:00
helpResponse . Append ( " [^3" + C . Name + "^7] " ) ;
2015-04-10 00:02:12 -04:00
if ( count > = 4 )
2015-03-11 00:47:34 -04:00
{
2017-05-31 01:31:56 -04:00
if ( E . Message [ 0 ] = = '@' )
await E . Owner . Broadcast ( helpResponse . ToString ( ) ) ;
else
await E . Origin . Tell ( helpResponse . ToString ( ) ) ;
2015-08-22 12:41:14 -04:00
helpResponse = new StringBuilder ( ) ;
2015-03-11 00:47:34 -04:00
count = 0 ;
}
count + + ;
2015-03-08 17:20:10 -04:00
}
}
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( helpResponse . ToString ( ) ) ;
2017-11-15 16:04:13 -05:00
await E . Origin . Tell ( "Type !help <cmd> to get command usage syntax" ) ;
2015-03-08 17:20:10 -04:00
}
}
}
2017-06-19 13:58:01 -04:00
public class CFastRestart : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CFastRestart ( ) :
base ( "fastrestart" , "fast restart current map" , "fr" , Player . Permission . Moderator , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2018-02-15 23:01:28 -05:00
await E . Owner . ExecuteCommandAsync ( "fast_restart" ) ;
2017-05-28 16:47:21 -04:00
if ( ! E . Origin . Masked )
2018-02-15 23:01:28 -05:00
await E . Owner . Broadcast ( $"^5{E.Origin.Name} ^7fast restarted the server" ) ;
2017-05-28 16:47:21 -04:00
else
2018-02-15 23:01:28 -05:00
await E . Owner . Broadcast ( $"The server has been fast restarted" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CMapRotate : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CMapRotate ( ) :
base ( "maprotate" , "cycle to the next map in rotation" , "mr" , Player . Permission . Administrator , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2017-05-28 16:47:21 -04:00
if ( ! E . Origin . Masked )
await E . Owner . Broadcast ( $"Map rotating in ^55 ^7seconds [^5{E.Origin.Name}^7]" ) ;
else
await E . Owner . Broadcast ( $"Map rotating in ^55 ^7seconds [^5Masked Admin^7]" ) ;
2018-02-07 00:19:06 -05:00
Task . Delay ( 5000 ) . Wait ( ) ;
2017-05-26 18:49:27 -04:00
await E . Owner . ExecuteCommandAsync ( "map_rotate" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CSetLevel : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CSetLevel ( ) :
2018-03-24 17:35:54 -04:00
base ( "setlevel" , "set player to specified administration level" , "sl" , Player . Permission . Moderator , true , new CommandArgument [ ]
2017-11-15 16:04:13 -05:00
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
Name = "level" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
if ( E . Target = = E . Origin )
{
2018-03-24 17:35:54 -04:00
await E . Origin . Tell ( "You cannot change your own level" ) ;
2015-03-08 17:20:10 -04:00
return ;
}
2017-11-29 19:35:50 -05:00
Player . Permission newPerm = Utilities . MatchPermission ( E . Data ) ;
2015-03-08 17:20:10 -04:00
2018-03-24 17:35:54 -04:00
if ( newPerm = = Player . Permission . Owner & &
! E . Owner . Manager . GetApplicationSettings ( ) . Configuration ( ) . EnableMultipleOwners )
2017-06-19 13:58:01 -04:00
{
2018-03-24 17:35:54 -04:00
await E . Origin . Tell ( "There can only be 1 owner. Modify your settings if multiple owners are required" ) ;
2017-06-19 13:58:01 -04:00
return ;
}
2018-03-24 17:35:54 -04:00
if ( E . Origin . Level < Player . Permission . Owner & &
! E . Owner . Manager . GetApplicationSettings ( ) . Configuration ( ) . EnableSteppedHierarchy )
{
await E . Origin . Tell ( $"This server does not allow you to promote ^5{E.Target.Name}" ) ;
return ;
}
if ( newPerm > = E . Origin . Level )
{
if ( E . Origin . Level < Player . Permission . Owner )
{
await E . Origin . Tell ( $"You can only promote ^5{E.Target.Name} ^7to ^5{(E.Origin.Level - 1)} ^7or lower privilege" ) ;
return ;
}
}
2015-03-08 17:20:10 -04:00
if ( newPerm > Player . Permission . Banned )
{
2018-03-06 02:22:19 -05:00
var ActiveClient = E . Owner . Manager . GetActiveClients ( )
. FirstOrDefault ( p = > p . NetworkId = = E . Target . NetworkId ) ;
2017-06-12 13:50:00 -04:00
2017-06-19 13:58:01 -04:00
if ( ActiveClient ! = null )
2018-02-24 00:56:03 -05:00
{
ActiveClient . Level = newPerm ;
2017-06-19 13:58:01 -04:00
await ActiveClient . Tell ( "Congratulations! You have been promoted to ^3" + newPerm ) ;
2018-02-24 00:56:03 -05:00
}
else
{
E . Target . Level = newPerm ;
await E . Owner . Manager . GetClientService ( ) . Update ( E . Target ) ;
}
2017-06-19 13:58:01 -04:00
2018-04-05 00:38:45 -04:00
try
{
E . Owner . Manager . GetPrivilegedClients ( ) . Add ( E . Target . ClientId , E . Target ) ;
}
catch ( Exception )
{
E . Owner . Manager . GetPrivilegedClients ( ) [ E . Target . ClientId ] = E . Target ;
}
2018-03-24 17:35:54 -04:00
await E . Origin . Tell ( $"{E.Target.Name} was successfully promoted" ) ;
2015-03-08 17:20:10 -04:00
}
else
2018-03-24 17:35:54 -04:00
await E . Origin . Tell ( "Invalid group specified" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CUsage : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CUsage ( ) :
base ( "usage" , "get current application memory usage" , "us" , Player . Permission . Moderator , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "IW4M Admin is using " + Math . Round ( ( ( System . Diagnostics . Process . GetCurrentProcess ( ) . PrivateMemorySize64 / 2048f ) / 1200f ) , 1 ) + "MB" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CUptime : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CUptime ( ) :
base ( "uptime" , "get current application running time" , "up" , Player . Permission . Moderator , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
TimeSpan uptime = DateTime . Now - System . Diagnostics . Process . GetCurrentProcess ( ) . StartTime ;
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( String . Format ( "IW4M Admin has been up for {0} days, {1} hours, and {2} minutes" , uptime . Days , uptime . Hours , uptime . Minutes ) ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CListAdmins : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CListAdmins ( ) :
base ( "admins" , "list currently connected admins" , "a" , Player . Permission . User , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2018-03-06 02:22:19 -05:00
int numOnline = 0 ;
2017-05-27 00:22:50 -04:00
for ( int i = 0 ; i < E . Owner . Players . Count ; i + + )
{
var P = E . Owner . Players [ i ] ;
2017-05-26 18:49:27 -04:00
if ( P ! = null & & P . Level > Player . Permission . Flagged & & ! P . Masked )
2017-05-31 01:31:56 -04:00
{
2018-03-06 02:22:19 -05:00
numOnline + + ;
2017-05-31 01:31:56 -04:00
if ( E . Message [ 0 ] = = '@' )
2017-06-12 17:47:31 -04:00
await E . Owner . Broadcast ( String . Format ( "[^3{0}^7] {1}" , Utilities . ConvertLevelToColor ( P . Level ) , P . Name ) ) ;
2017-05-31 01:31:56 -04:00
else
2017-06-12 17:47:31 -04:00
await E . Origin . Tell ( String . Format ( "[^3{0}^7] {1}" , Utilities . ConvertLevelToColor ( P . Level ) , P . Name ) ) ;
2017-05-31 01:31:56 -04:00
}
2017-05-27 00:22:50 -04:00
}
2018-03-06 02:22:19 -05:00
if ( numOnline = = 0 )
await E . Origin . Tell ( "No visible administrators online" ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CLoadMap : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CLoadMap ( ) :
base ( "map" , "change to specified map" , "m" , Player . Permission . Administrator , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "map" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
string newMap = E . Data . Trim ( ) . ToLower ( ) ;
2017-06-19 13:58:01 -04:00
foreach ( Map m in E . Owner . Maps )
2015-03-08 17:20:10 -04:00
{
if ( m . Name . ToLower ( ) = = newMap | | m . Alias . ToLower ( ) = = newMap )
{
2018-03-06 02:22:19 -05:00
await E . Owner . Broadcast ( $"Changing to map ^5{m.Alias}" ) ;
2018-02-07 00:19:06 -05:00
Task . Delay ( 5000 ) . Wait ( ) ;
2017-05-26 18:49:27 -04:00
await E . Owner . LoadMap ( m . Name ) ;
2015-03-08 17:20:10 -04:00
return ;
}
}
2018-03-06 02:22:19 -05:00
await E . Owner . Broadcast ( $"Attempting to change to unknown map ^5{newMap}" ) ;
2018-02-07 00:19:06 -05:00
Task . Delay ( 5000 ) . Wait ( ) ;
2017-05-26 18:49:27 -04:00
await E . Owner . LoadMap ( newMap ) ;
2015-03-08 17:20:10 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CFindPlayer : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CFindPlayer ( ) :
base ( "find" , "find player in database" , "f" , Player . Permission . Administrator , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
}
} )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2018-02-15 23:01:28 -05:00
var db_players = ( await ( E . Owner . Manager . GetClientService ( ) as ClientService )
. GetClientByName ( E . Data ) )
. OrderByDescending ( p = > p . LastConnection )
. ToList ( ) ;
2015-03-23 23:01:05 -04:00
2017-11-25 20:29:58 -05:00
if ( db_players . Count = = 0 )
2015-03-08 17:20:10 -04:00
{
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "No players found" ) ;
2015-03-08 17:20:10 -04:00
return ;
}
2018-02-11 20:17:20 -05:00
foreach ( var P in db_players )
2017-08-17 19:28:08 -04:00
{
2018-02-11 20:17:20 -05:00
// they're not going by another alias
string msg = P . Name . ToLower ( ) . Contains ( E . Data . ToLower ( ) ) ?
$"[^3{P.Name}^7] [^3@{P.ClientId}^7] - [{ Utilities.ConvertLevelToColor(P.Level)}^7] - {P.IPAddressString} | last seen {Utilities.GetTimePassed(P.LastConnection)}" :
$"({P.AliasLink.Children.First(a => a.Name.ToLower().Contains(E.Data.ToLower())).Name})->[^3{P.Name}^7] [^3@{P.ClientId}^7] - [{ Utilities.ConvertLevelToColor(P.Level)}^7] - {P.IPAddressString} | last seen {Utilities.GetTimePassed(P.LastConnection)}" ;
await E . Origin . Tell ( msg ) ;
2015-03-08 17:20:10 -04:00
}
}
}
2017-06-19 13:58:01 -04:00
public class CListRules : Command
2015-03-08 17:20:10 -04:00
{
2017-11-15 16:04:13 -05:00
public CListRules ( ) :
base ( "rules" , "list server rules" , "r" , Player . Permission . User , false )
{ }
2015-03-08 17:20:10 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-08 17:20:10 -04:00
{
2018-03-18 22:25:11 -04:00
if ( E . Owner . Manager . GetApplicationSettings ( ) . Configuration ( ) . GlobalRules ? . Count < 1 & &
E . Owner . ServerConfig . Rules ? . Count < 1 )
2017-05-31 01:31:56 -04:00
{
if ( E . Message . IsBroadcastCommand ( ) )
2017-11-19 01:44:11 -05:00
await E . Owner . Broadcast ( "The server owner has not set any rules" ) ;
2017-05-31 01:31:56 -04:00
else
2017-11-19 01:44:11 -05:00
await E . Origin . Tell ( "The server owner has not set any rules" ) ;
2017-05-31 01:31:56 -04:00
}
2015-03-08 17:20:10 -04:00
else
{
2018-03-18 22:25:11 -04:00
var rules = new List < string > ( ) ;
rules . AddRange ( E . Owner . Manager . GetApplicationSettings ( ) . Configuration ( ) . GlobalRules ) ;
if ( E . Owner . ServerConfig . Rules ! = null )
rules . AddRange ( E . Owner . ServerConfig . Rules ) ;
foreach ( string r in rules )
2017-05-31 01:31:56 -04:00
{
if ( E . Message . IsBroadcastCommand ( ) )
2018-02-15 23:01:28 -05:00
await E . Owner . Broadcast ( $"- {r}" ) ;
2017-05-31 01:31:56 -04:00
else
2018-02-15 23:01:28 -05:00
await E . Origin . Tell ( $"- {r}" ) ;
2017-05-31 01:31:56 -04:00
}
2015-03-08 17:20:10 -04:00
}
}
}
2015-03-09 16:11:09 -04:00
2017-06-19 13:58:01 -04:00
public class CPrivateMessage : Command
2015-03-09 16:11:09 -04:00
{
2017-11-15 16:04:13 -05:00
public CPrivateMessage ( ) :
base ( "privatemessage" , "send message to other player" , "pm" , Player . Permission . User , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
Name = "message" ,
Required = true
}
} )
{ }
2015-03-09 16:11:09 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-09 16:11:09 -04:00
{
2018-02-15 23:01:28 -05:00
await E . Target . Tell ( $"^1{E.Origin.Name} ^3[PM]^7 - {E.Data}" ) ;
await E . Origin . Tell ( $"To ^3{E.Target.Name} ^7-> {E.Data}" ) ;
2015-03-09 16:11:09 -04:00
}
}
2015-03-09 21:28:37 -04:00
2017-06-19 13:58:01 -04:00
public class CFlag : Command
2015-03-23 23:01:05 -04:00
{
2017-11-15 16:04:13 -05:00
public CFlag ( ) :
base ( "flag" , "flag a suspicious player and announce to admins on join" , "fp" , Player . Permission . Moderator , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
Name = "reason" ,
Required = true
}
} )
{ }
2015-03-23 23:01:05 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-23 23:01:05 -04:00
{
2018-02-11 20:17:20 -05:00
// todo: move unflag to seperate command
2015-08-20 01:06:44 -04:00
if ( E . Target . Level > = E . Origin . Level )
2015-03-23 23:01:05 -04:00
{
2018-02-11 20:17:20 -05:00
await E . Origin . Tell ( $"You cannot flag {E.Target.Name}" ) ;
2015-03-23 23:01:05 -04:00
return ;
}
2015-08-20 01:06:44 -04:00
if ( E . Target . Level = = Player . Permission . Flagged )
2015-03-23 23:01:05 -04:00
{
2017-11-25 20:29:58 -05:00
E . Target . Level = Player . Permission . User ;
2017-11-29 19:35:50 -05:00
await E . Owner . Manager . GetClientService ( ) . Update ( E . Target ) ;
2018-02-11 20:17:20 -05:00
await E . Origin . Tell ( $"You have ^5unflagged ^7{E.Target.Name}" ) ;
2015-03-23 23:01:05 -04:00
}
else
{
2017-11-25 20:29:58 -05:00
E . Target . Level = Player . Permission . Flagged ;
Penalty newPenalty = new Penalty ( )
{
Type = Penalty . PenaltyType . Flag ,
Expires = DateTime . UtcNow ,
Offender = E . Target ,
Offense = E . Data ,
Punisher = E . Origin ,
Active = true ,
2017-11-29 19:35:50 -05:00
When = DateTime . UtcNow ,
Link = E . Target . AliasLink
2017-11-25 20:29:58 -05:00
} ;
await E . Owner . Manager . GetPenaltyService ( ) . Create ( newPenalty ) ;
2017-06-19 13:58:01 -04:00
await E . Owner . ExecuteEvent ( new Event ( Event . GType . Flag , E . Data , E . Origin , E . Target , E . Owner ) ) ;
2018-02-15 23:01:28 -05:00
await E . Origin . Tell ( $"You have flagged ^5{E.Target.Name}" ) ;
2015-03-23 23:01:05 -04:00
}
}
}
2017-06-19 13:58:01 -04:00
public class CReport : Command
2015-03-23 23:01:05 -04:00
{
2017-11-15 16:04:13 -05:00
public CReport ( ) :
base ( "report" , "report a player for suspicious behavior" , "rep" , Player . Permission . User , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true
} ,
new CommandArgument ( )
{
Name = "reason" ,
Required = true
}
} )
{ }
2015-03-23 23:01:05 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-23 23:01:05 -04:00
{
2018-02-15 23:01:28 -05:00
if ( E . Data . ToLower ( ) . Contains ( "camp" ) )
{
await E . Origin . Tell ( "You cannot report a player for camping" ) ;
return ;
}
2017-11-25 20:29:58 -05:00
if ( E . Owner . Reports . Find ( x = > ( x . Origin = = E . Origin & & x . Target . NetworkId = = E . Target . NetworkId ) ) ! = null )
2016-01-16 17:58:24 -05:00
{
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "You have already reported this player" ) ;
2016-01-16 17:58:24 -05:00
return ;
}
2015-04-10 00:02:12 -04:00
if ( E . Target = = E . Origin )
{
2017-11-19 01:44:11 -05:00
await E . Origin . Tell ( "You cannot report yourself" ) ;
2015-04-10 00:02:12 -04:00
return ;
}
2015-08-20 01:06:44 -04:00
if ( E . Target . Level > E . Origin . Level )
2015-03-23 23:01:05 -04:00
{
2017-11-16 18:09:19 -05:00
await E . Origin . Tell ( $"You cannot report {E.Target.Name}" ) ;
2015-03-23 23:01:05 -04:00
return ;
}
E . Owner . Reports . Add ( new Report ( E . Target , E . Origin , E . Data ) ) ;
2016-01-16 17:58:24 -05:00
2018-02-09 02:21:25 -05:00
await E . Origin . Tell ( $"Thank you for your report, an administrator has been notified" ) ;
2017-05-26 18:49:27 -04:00
await E . Owner . ExecuteEvent ( new Event ( Event . GType . Report , E . Data , E . Origin , E . Target , E . Owner ) ) ;
await E . Owner . ToAdmins ( String . Format ( "^5{0}^7->^1{1}^7: {2}" , E . Origin . Name , E . Target . Name , E . Data ) ) ;
2015-03-23 23:01:05 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CListReports : Command
2015-03-23 23:01:05 -04:00
{
2017-11-15 16:04:13 -05:00
public CListReports ( ) :
base ( "reports" , "get or clear recent reports" , "reps" , Player . Permission . Moderator , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "clear" ,
Required = false
}
} )
{ }
2015-03-23 23:01:05 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-03-23 23:01:05 -04:00
{
2015-08-26 01:49:47 -04:00
if ( E . Data ! = null & & E . Data . ToLower ( ) . Contains ( "clear" ) )
{
E . Owner . Reports = new List < Report > ( ) ;
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "Reports successfully cleared!" ) ;
2015-08-26 01:49:47 -04:00
return ;
}
2015-03-23 23:01:05 -04:00
if ( E . Owner . Reports . Count < 1 )
{
2017-11-19 01:44:11 -05:00
await E . Origin . Tell ( "No players reported yet" ) ;
2015-03-23 23:01:05 -04:00
return ;
}
2017-05-26 18:49:27 -04:00
foreach ( Report R in E . Owner . Reports )
await E . Origin . Tell ( String . Format ( "^5{0}^7->^1{1}^7: {2}" , R . Origin . Name , R . Target . Name , R . Reason ) ) ;
2015-03-23 23:01:05 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CMask : Command
2015-04-10 00:02:12 -04:00
{
2017-11-15 16:04:13 -05:00
public CMask ( ) :
2017-11-29 19:35:50 -05:00
base ( "mask" , "hide your presence as an administrator" , "hide" , Player . Permission . Moderator , false )
2017-11-15 16:04:13 -05:00
{ }
2015-04-10 00:02:12 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-04-10 00:02:12 -04:00
{
if ( E . Origin . Masked )
{
E . Origin . Masked = false ;
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "You are now unmasked" ) ;
2015-04-10 00:02:12 -04:00
}
else
{
E . Origin . Masked = true ;
2017-05-26 18:49:27 -04:00
await E . Origin . Tell ( "You are now masked" ) ;
2015-04-10 00:02:12 -04:00
}
2017-06-19 13:58:01 -04:00
2017-11-25 20:29:58 -05:00
await E . Owner . Manager . GetClientService ( ) . Update ( E . Origin ) ;
2015-04-10 00:02:12 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CListBanInfo : Command
2015-04-10 00:02:12 -04:00
{
2017-11-15 16:04:13 -05:00
public CListBanInfo ( ) :
base ( "baninfo" , "get information about a ban for a player" , "bi" , Player . Permission . Moderator , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
2017-11-16 18:09:19 -05:00
Name = "player" ,
Required = true
2017-11-15 16:04:13 -05:00
}
} )
{ }
2015-04-10 00:02:12 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-04-10 00:02:12 -04:00
{
2017-11-25 20:29:58 -05:00
var B = await E . Owner . Manager . GetPenaltyService ( ) . GetClientPenaltiesAsync ( E . Target . ClientId ) ;
2017-05-27 18:08:04 -04:00
2017-11-25 20:29:58 -05:00
var penalty = B . FirstOrDefault ( b = > b . Type > Penalty . PenaltyType . Kick & & b . Expires > DateTime . UtcNow ) ;
if ( penalty = = null )
2015-04-10 00:02:12 -04:00
{
2017-11-19 01:44:11 -05:00
await E . Origin . Tell ( "No active ban was found for that player" ) ;
2015-04-10 00:02:12 -04:00
return ;
}
2017-11-29 19:35:50 -05:00
await E . Origin . Tell ( String . Format ( "^1{0} ^7was banned by ^5{1} ^7for: {2} {3}" , E . Target . Name , penalty . Punisher . Name , penalty . Offense , penalty . Type = = Penalty . PenaltyType . TempBan ? $"({(penalty.Expires - DateTime.UtcNow).TimeSpanText()} remaining)" : "" ) ) ;
2015-04-10 00:02:12 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CListAlias : Command
2015-04-10 00:02:12 -04:00
{
2017-11-15 16:04:13 -05:00
public CListAlias ( ) :
base ( "alias" , "get past aliases and ips of a player" , "known" , Player . Permission . Moderator , true , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "player" ,
Required = true ,
}
} )
{ }
2015-04-10 00:02:12 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-04-10 00:02:12 -04:00
{
StringBuilder message = new StringBuilder ( ) ;
2017-11-25 20:29:58 -05:00
var names = new List < string > ( E . Target . AliasLink . Children . Select ( a = > a . Name ) ) ;
2018-02-10 23:33:42 -05:00
var IPs = new List < string > ( E . Target . AliasLink . Children . Select ( a = > a . IPAddress . ConvertIPtoString ( ) ) . Distinct ( ) ) ;
2015-04-10 00:02:12 -04:00
2017-11-25 20:29:58 -05:00
await E . Target . Tell ( $"[^3{E.Target}^7]" ) ;
2017-08-17 19:28:08 -04:00
2015-07-17 18:53:51 -04:00
message . Append ( "Aliases: " ) ;
2017-11-25 20:29:58 -05:00
message . Append ( String . Join ( " | " , names ) ) ;
2017-06-01 13:42:28 -04:00
await E . Origin . Tell ( message . ToString ( ) ) ;
2015-04-11 13:31:04 -04:00
2017-06-01 13:42:28 -04:00
message . Clear ( ) ;
message . Append ( "IPs: " ) ;
2017-11-25 20:29:58 -05:00
message . Append ( String . Join ( " | " , IPs ) ) ;
2017-06-01 13:42:28 -04:00
await E . Origin . Tell ( message . ToString ( ) ) ;
2015-04-10 00:02:12 -04:00
}
}
2017-06-19 13:58:01 -04:00
public class CExecuteRCON : Command
2015-04-10 00:02:12 -04:00
{
2017-11-15 16:04:13 -05:00
public CExecuteRCON ( ) :
base ( "rcon" , "send rcon command to server" , "rcon" , Player . Permission . Owner , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "command" ,
Required = true
}
} )
{ }
2015-04-10 00:02:12 -04:00
2017-05-26 18:49:27 -04:00
public override async Task ExecuteAsync ( Event E )
2015-04-10 00:02:12 -04:00
{
2017-06-07 17:08:29 -04:00
var Response = await E . Owner . ExecuteCommandAsync ( E . Data . Trim ( ) ) ;
foreach ( string S in Response )
await E . Origin . Tell ( S . StripColors ( ) ) ;
if ( Response . Length = = 0 )
await E . Origin . Tell ( "Successfully sent RCON command!" ) ;
2015-04-10 00:02:12 -04:00
}
}
2017-06-12 17:47:31 -04:00
2017-06-19 13:58:01 -04:00
public class CPlugins : Command
2017-06-12 17:47:31 -04:00
{
2017-11-15 16:04:13 -05:00
public CPlugins ( ) :
base ( "plugins" , "view all loaded plugins" , "p" , Player . Permission . Administrator , false )
{ }
2017-06-12 17:47:31 -04:00
public override async Task ExecuteAsync ( Event E )
{
await E . Origin . Tell ( "^5Loaded Plugins:" ) ;
foreach ( var P in Plugins . PluginImporter . ActivePlugins )
{
await E . Origin . Tell ( String . Format ( "^3{0} ^7[v^3{1}^7] by ^5{2}^7" , P . Name , P . Version , P . Author ) ) ;
}
}
}
2017-08-17 19:28:08 -04:00
public class CIP : Command
{
2017-11-15 16:04:13 -05:00
public CIP ( ) :
base ( "getexternalip" , "view your external IP address" , "ip" , Player . Permission . User , false )
{ }
2017-08-17 19:28:08 -04:00
public override async Task ExecuteAsync ( Event E )
{
2018-02-17 15:06:37 -05:00
await E . Origin . Tell ( $"Your external IP is ^5{E.Origin.IPAddressString}" ) ;
2017-08-17 19:28:08 -04:00
}
}
2018-02-10 01:26:38 -05:00
public class CPruneAdmins : Command
{
public CPruneAdmins ( ) : base ( "prune" , "demote any admins that have not connected recently (defaults to 30 days)" , "p" , Player . Permission . Owner , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "inactive days" ,
Required = false
}
} )
{ }
2018-03-06 02:22:19 -05:00
2018-02-10 01:26:38 -05:00
public override async Task ExecuteAsync ( Event E )
{
int inactiveDays = 30 ;
try
{
if ( E . Data . Length > 0 )
{
inactiveDays = Int32 . Parse ( E . Data ) ;
if ( inactiveDays < 1 )
throw new FormatException ( ) ;
}
}
catch ( FormatException )
{
await E . Origin . Tell ( "Invalid number of inactive days" ) ;
return ;
}
List < EFClient > inactiveUsers = null ;
// update user roles
using ( var context = new DatabaseContext ( ) )
{
var lastActive = DateTime . UtcNow . AddDays ( - inactiveDays ) ;
inactiveUsers = await context . Clients
. Where ( c = > c . Level > Player . Permission . Flagged & & c . Level < = Player . Permission . Moderator )
. Where ( c = > c . LastConnection < lastActive )
. ToListAsync ( ) ;
inactiveUsers . ForEach ( c = > c . Level = Player . Permission . User ) ;
await context . SaveChangesAsync ( ) ;
}
2018-03-06 02:22:19 -05:00
await E . Origin . Tell ( $"Pruned {inactiveUsers.Count} inactive privileged users" ) ;
}
}
2018-04-04 15:38:34 -04:00
public class CSetPassword : Command
{
public CSetPassword ( ) : base ( "setpassword" , "set your authentication password" , "sp" , Player . Permission . Moderator , false , new CommandArgument [ ]
{
new CommandArgument ( )
{
Name = "password" ,
Required = true
}
} )
{ }
public override async Task ExecuteAsync ( Event E )
{
2018-04-05 00:38:45 -04:00
if ( E . Data . Length < 5 )
{
await E . Origin . Tell ( "Your password must be atleast 5 characters long" ) ;
return ;
}
2018-04-04 15:38:34 -04:00
string [ ] hashedPassword = Helpers . Hashing . Hash ( E . Data ) ;
E . Origin . Password = hashedPassword [ 0 ] ;
E . Origin . PasswordSalt = hashedPassword [ 1 ] ;
2018-04-05 00:38:45 -04:00
// update the password for the client in privileged
E . Owner . Manager . GetPrivilegedClients ( ) [ E . Origin . ClientId ] = E . Origin ;
2018-04-04 15:38:34 -04:00
await E . Owner . Manager . GetClientService ( ) . Update ( E . Origin ) ;
2018-04-05 00:38:45 -04:00
await E . Origin . Tell ( "Your password has been set successfully" ) ;
2018-04-04 15:38:34 -04:00
}
}
2018-04-02 01:25:06 -04:00
public class CKillServer : Command
2018-03-06 02:22:19 -05:00
{
2018-04-02 01:25:06 -04:00
public CKillServer ( ) : base ( "killserver" , "kill the game server" , "kill" , Player . Permission . Administrator , false )
2018-03-06 02:22:19 -05:00
{
}
public override async Task ExecuteAsync ( Event E )
{
var gameserverProcesses = System . Diagnostics . Process . GetProcessesByName ( "iw4x" ) ;
2018-04-02 01:25:06 -04:00
var currentProcess = gameserverProcesses . FirstOrDefault ( g = > g . MainWindowTitle . Contains ( E . Owner . Hostname ) ) ;
2018-03-06 02:22:19 -05:00
if ( currentProcess = = null )
{
await E . Origin . Tell ( "Could not find running/stalled instance of IW4x" ) ;
}
else
{
// attempt to kill it natively
try
{
if ( ! E . Owner . Throttled )
{
2018-03-24 17:35:54 -04:00
#if ! DEBUG
await E . Owner . ExecuteCommandAsync ( "quit" ) ;
#endif
2018-03-06 02:22:19 -05:00
}
}
catch ( NetworkException )
{
await E . Origin . Tell ( "Unable to cleanly shutdown server, forcing" ) ;
}
if ( ! currentProcess . HasExited )
{
try
{
currentProcess . Kill ( ) ;
2018-04-02 01:25:06 -04:00
await E . Origin . Tell ( "Successfully killed server process" ) ;
2018-03-06 02:22:19 -05:00
}
catch ( Exception e )
{
2018-04-02 01:25:06 -04:00
await E . Origin . Tell ( "Could not kill server process" ) ;
2018-03-06 02:22:19 -05:00
E . Owner . Logger . WriteDebug ( "Unable to kill process" ) ;
E . Owner . Logger . WriteDebug ( $"Exception: {e.Message}" ) ;
return ;
}
}
}
2018-02-10 01:26:38 -05:00
}
}
2015-03-08 17:20:10 -04:00
}