2015-07-03 00:10:01 -04:00
using System ;
2015-03-08 17:20:10 -04:00
using System.Collections.Generic ;
2015-03-13 19:40:16 -04:00
using System.Collections ;
2015-03-08 17:20:10 -04:00
using System.Text ;
2015-07-03 00:10:01 -04:00
using System.Threading ;
2015-03-08 17:20:10 -04:00
using System.IO ;
2015-05-09 12:46:25 -04:00
using System.Runtime.InteropServices ;
2015-08-20 01:06:44 -04:00
using SharedLibrary ;
2015-03-08 17:20:10 -04:00
namespace IW4MAdmin
{
2015-08-20 01:06:44 -04:00
class IW4MServer : SharedLibrary . Server
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
public IW4MServer ( string address , int port , string password , int H , int PID ) : base ( address , port , password , H , PID )
2015-03-08 17:20:10 -04:00
{
2015-08-20 15:23:13 -04:00
commandQueue = new Queue < string > ( ) ;
2015-03-08 17:20:10 -04:00
}
2015-08-23 17:58:48 -04:00
2015-08-21 21:11:35 -04:00
private void getAliases ( List < Aliases > returnAliases , Aliases currentAlias )
{
foreach ( String IP in currentAlias . IPS )
{
List < Aliases > Matching = aliasDB . getPlayer ( IP ) ;
foreach ( Aliases I in Matching )
{
if ( ! returnAliases . Contains ( I ) & & returnAliases . Find ( x = > x . Number = = I . Number ) = = null )
{
returnAliases . Add ( I ) ;
getAliases ( returnAliases , I ) ;
}
}
}
}
public override List < Aliases > getAliases ( Player Origin )
{
List < Aliases > allAliases = new List < Aliases > ( ) ;
2015-04-10 00:02:12 -04:00
if ( Origin = = null )
2015-08-21 21:11:35 -04:00
return allAliases ;
Aliases currentIdentityAliases = aliasDB . getPlayer ( Origin . databaseID ) ;
if ( currentIdentityAliases = = null )
return allAliases ;
getAliases ( allAliases , currentIdentityAliases ) ;
2015-08-23 17:58:48 -04:00
return allAliases ;
2015-04-10 00:02:12 -04:00
}
2015-04-19 14:14:30 -04:00
2015-03-08 17:20:10 -04:00
//Add player object p to `players` list
2015-08-20 01:06:44 -04:00
override public bool addPlayer ( Player P )
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
if ( P . clientID < 0 | | P . clientID > ( players . Count - 1 ) ) // invalid index
2015-04-10 00:02:12 -04:00
return false ;
2015-08-20 01:06:44 -04:00
if ( players [ P . clientID ] ! = null & & players [ P . clientID ] . npID = = P . npID ) // if someone has left and a new person has taken their spot between polls
2015-04-10 00:02:12 -04:00
return true ;
2015-08-20 01:06:44 -04:00
Log . Write ( "Client slot #" + P . clientID + " now reserved" , Log . Level . Debug ) ;
2015-04-10 00:02:12 -04:00
2015-03-14 12:42:36 -04:00
#if DEBUG = = false
2015-03-08 17:20:10 -04:00
try
2015-03-14 12:42:36 -04:00
#endif
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
Player NewPlayer = clientDB . getPlayer ( P . npID , P . clientID ) ;
2015-04-10 00:02:12 -04:00
if ( NewPlayer = = null ) // first time connecting
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
Log . Write ( "Client slot #" + P . clientID + " first time connecting" , Log . Level . All ) ;
2015-03-13 19:40:16 -04:00
clientDB . addPlayer ( P ) ;
2015-08-20 01:06:44 -04:00
NewPlayer = clientDB . getPlayer ( P . npID , P . clientID ) ;
aliasDB . addPlayer ( new Aliases ( NewPlayer . databaseID , NewPlayer . Name , NewPlayer . IP ) ) ;
2015-03-08 17:20:10 -04:00
}
2015-08-20 01:06:44 -04:00
NewPlayer . updateName ( P . Name . Trim ( ) ) ;
NewPlayer . Alias = aliasDB . getPlayer ( NewPlayer . databaseID ) ;
2015-03-14 12:42:36 -04:00
2015-04-10 00:02:12 -04:00
if ( NewPlayer . Alias = = null )
2015-03-09 21:28:37 -04:00
{
2015-08-20 01:06:44 -04:00
aliasDB . addPlayer ( new Aliases ( NewPlayer . databaseID , NewPlayer . Name , NewPlayer . IP ) ) ;
NewPlayer . Alias = aliasDB . getPlayer ( NewPlayer . databaseID ) ;
2015-03-09 21:28:37 -04:00
}
2015-04-10 00:02:12 -04:00
if ( P . lastEvent = = null | | P . lastEvent . Owner = = null )
2015-03-14 12:42:36 -04:00
NewPlayer . lastEvent = new Event ( Event . GType . Say , null , NewPlayer , null , this ) ; // this is messy but its throwing an error when they've started it too late
else
NewPlayer . lastEvent = P . lastEvent ;
2015-04-10 00:02:12 -04:00
// lets check aliases
2015-08-21 21:11:35 -04:00
if ( ( NewPlayer . Alias . Names . Find ( m = > m . Equals ( P . Name ) ) ) = = null | | NewPlayer . Name = = null | | NewPlayer . Name = = String . Empty )
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
NewPlayer . updateName ( P . Name . Trim ( ) ) ;
2015-08-21 21:11:35 -04:00
NewPlayer . Alias . Names . Add ( NewPlayer . Name ) ;
2015-04-10 00:02:12 -04:00
}
// and ips
2015-08-21 21:11:35 -04:00
if ( NewPlayer . Alias . IPS . Find ( i = > i . Equals ( P . IP ) ) = = null | | P . IP = = null | | P . IP = = String . Empty )
2015-04-10 00:02:12 -04:00
{
2015-08-21 21:11:35 -04:00
NewPlayer . Alias . IPS . Add ( P . IP ) ;
2015-04-10 00:02:12 -04:00
}
2015-03-16 16:40:30 -04:00
2015-08-20 01:06:44 -04:00
NewPlayer . updateIP ( P . IP ) ;
2015-04-19 14:14:30 -04:00
2015-04-10 00:02:12 -04:00
aliasDB . updatePlayer ( NewPlayer . Alias ) ;
clientDB . updatePlayer ( NewPlayer ) ;
2015-03-16 16:40:30 -04:00
2015-08-20 15:23:13 -04:00
events . Enqueue ( new Event ( Event . GType . Connect , "" , NewPlayer , null , this ) ) ;
2015-07-15 18:10:07 -04:00
2015-08-20 01:06:44 -04:00
if ( NewPlayer . Level = = Player . Permission . Banned ) // their guid is already banned so no need to check aliases
2015-04-10 00:02:12 -04:00
{
2015-04-11 13:31:04 -04:00
String Message ;
2015-03-16 16:40:30 -04:00
2015-08-20 01:06:44 -04:00
Log . Write ( "Banned client " + P . Name + " trying to connect..." , Log . Level . Debug ) ;
2015-03-30 01:04:10 -04:00
2015-08-20 01:06:44 -04:00
if ( NewPlayer . lastOffense ! = null )
Message = "^7Player Kicked: Previously banned for ^5" + NewPlayer . lastOffense + " ^7(appeal at " + Website + ")" ;
2015-04-11 13:31:04 -04:00
else
Message = "Player Kicked: Previous Ban" ;
2015-03-16 16:40:30 -04:00
2015-04-11 13:31:04 -04:00
NewPlayer . Kick ( Message ) ;
2015-08-20 01:06:44 -04:00
if ( players [ NewPlayer . clientID ] ! = null )
2015-03-16 16:40:30 -04:00
{
2015-04-11 13:31:04 -04:00
lock ( players )
{
2015-08-20 01:06:44 -04:00
players [ NewPlayer . clientID ] = null ;
2015-04-11 13:31:04 -04:00
}
}
2015-03-23 23:01:05 -04:00
2015-04-11 13:31:04 -04:00
return true ;
}
2015-03-16 16:40:30 -04:00
2015-08-21 21:11:35 -04:00
List < Player > newPlayerAliases = getPlayerAliases ( NewPlayer ) ;
2015-03-23 23:01:05 -04:00
2015-04-11 13:31:04 -04:00
foreach ( Player aP in newPlayerAliases ) // lets check their aliases
{
if ( aP = = null )
continue ;
2015-04-10 00:02:12 -04:00
2015-08-20 01:06:44 -04:00
if ( aP . Level = = Player . Permission . Flagged )
2015-04-11 13:31:04 -04:00
NewPlayer . setLevel ( Player . Permission . Flagged ) ;
2015-04-10 00:02:12 -04:00
Ban B = isBanned ( aP ) ;
2015-04-11 13:31:04 -04:00
if ( B ! = null )
2015-04-10 00:02:12 -04:00
{
2015-08-20 01:06:44 -04:00
Log . Write ( String . Format ( "Banned client {0} is connecting with new alias {1}" , aP . Name , NewPlayer . Name ) , Log . Level . Debug ) ;
NewPlayer . lastOffense = String . Format ( "Evading ( {0} )" , aP . Name ) ;
2015-04-10 00:02:12 -04:00
2015-08-20 01:06:44 -04:00
if ( B . Reason ! = null )
NewPlayer . Ban ( "^7Previously Banned: ^5" + B . Reason + " ^7(appeal at " + Website + ")" , NewPlayer ) ;
2015-04-10 00:02:12 -04:00
else
NewPlayer . Ban ( "^7Previous Ban" , NewPlayer ) ;
2015-03-23 23:01:05 -04:00
2015-04-10 00:02:12 -04:00
lock ( players )
{
2015-08-20 01:06:44 -04:00
if ( players [ NewPlayer . clientID ] ! = null )
players [ NewPlayer . clientID ] = null ;
2015-04-10 00:02:12 -04:00
}
2015-03-23 23:01:05 -04:00
return true ;
2015-03-16 16:40:30 -04:00
}
2015-04-10 00:02:12 -04:00
}
2015-03-16 16:40:30 -04:00
2015-04-19 14:14:30 -04:00
//finally lets check their clean status :>
2015-07-15 17:11:29 -04:00
//checkClientStatus(NewPlayer);
2015-04-19 14:14:30 -04:00
2015-04-10 00:02:12 -04:00
lock ( players )
{
2015-08-20 01:06:44 -04:00
players [ NewPlayer . clientID ] = null ; // just in case we have shit in the way
players [ NewPlayer . clientID ] = NewPlayer ;
2015-04-10 00:02:12 -04:00
}
2015-03-23 23:01:05 -04:00
#if DEBUG = = FALSE
2015-08-20 13:52:30 -04:00
NewPlayer . Tell ( "Welcome ^5" + NewPlayer . Name + " ^7this is your ^5" + SharedLibrary . Utilities . timesConnected ( NewPlayer . Connections ) + " ^7time connecting!" ) ;
2015-03-23 23:01:05 -04:00
#endif
2015-08-20 01:06:44 -04:00
Log . Write ( "Client " + NewPlayer . Name + " connecting..." , Log . Level . Debug ) ; // they're clean
2015-03-23 23:01:05 -04:00
2015-04-24 15:37:56 -04:00
while ( chatHistory . Count > Math . Ceiling ( ( double ) clientnum / 2 ) )
2015-04-19 14:14:30 -04:00
chatHistory . RemoveAt ( 0 ) ;
chatHistory . Add ( new Chat ( NewPlayer , "<i>CONNECTED</i>" , DateTime . Now ) ) ;
2015-08-20 01:06:44 -04:00
if ( NewPlayer . Level = = Player . Permission . Flagged )
ToAdmins ( "^1NOTICE: ^7Flagged player ^5" + NewPlayer . Name + "^7 has joined!" ) ;
2015-04-10 00:02:12 -04:00
2015-08-20 01:06:44 -04:00
if ( NewPlayer . Level > Player . Permission . Moderator )
2015-04-10 00:02:12 -04:00
NewPlayer . Tell ( "There are ^5" + Reports . Count + " ^7recent reports!" ) ;
2015-03-08 17:20:10 -04:00
return true ;
}
2015-03-14 12:42:36 -04:00
#if DEBUG = = false
2015-03-08 17:20:10 -04:00
catch ( Exception E )
{
2015-08-20 01:06:44 -04:00
Log . Write ( "Unable to add player " + P . Name + " - " + E . Message , Log . Level . Debug ) ;
2015-03-08 17:20:10 -04:00
return false ;
}
2015-03-14 12:42:36 -04:00
#endif
2015-03-08 17:20:10 -04:00
}
//Remove player by CLIENT NUMBER
2015-08-20 01:06:44 -04:00
override public bool removePlayer ( int cNum )
2015-03-08 17:20:10 -04:00
{
2015-04-10 00:02:12 -04:00
if ( cNum > = 0 & & cNum < players . Count )
2015-03-16 16:40:30 -04:00
{
2015-04-13 00:25:34 -04:00
if ( players [ cNum ] = = null )
{
2015-05-09 12:46:25 -04:00
//Log.Write("Error - Disconnecting client slot is already empty!", Log.Level.Debug);
2015-04-13 00:25:34 -04:00
return false ;
}
2015-04-10 00:02:12 -04:00
Player Leaving = players [ cNum ] ;
Leaving . Connections + + ;
clientDB . updatePlayer ( Leaving ) ;
2015-03-16 16:40:30 -04:00
Log . Write ( "Client at " + cNum + " disconnecting..." , Log . Level . Debug ) ;
2015-08-20 15:23:13 -04:00
events . Enqueue ( new Event ( Event . GType . Disconnect , "" , Leaving , null , this ) ) ;
2015-04-10 00:02:12 -04:00
lock ( players )
{
players [ cNum ] = null ;
}
2015-03-16 16:40:30 -04:00
return true ;
}
else
{
2015-04-13 00:25:34 -04:00
Log . Write ( "Error - Client disconnecting has an invalid client index!" , Log . Level . Debug ) ;
2015-03-16 16:40:30 -04:00
return false ;
}
2015-03-08 17:20:10 -04:00
}
2015-03-16 16:40:30 -04:00
//Another version of client from line, written for the line created by a kill or death event
2015-08-20 01:06:44 -04:00
override public Player clientFromEventLine ( String [ ] L , int cIDPos )
2015-03-16 16:40:30 -04:00
{
2015-04-10 00:02:12 -04:00
if ( L . Length < cIDPos )
2015-03-16 16:40:30 -04:00
{
Log . Write ( "Line sent for client creation is not long enough!" , Log . Level . Debug ) ;
return null ;
}
2015-03-30 01:04:10 -04:00
int pID = - 2 ; // apparently falling = -1 cID so i can't use it now
2015-04-10 00:02:12 -04:00
int . TryParse ( L [ cIDPos ] . Trim ( ) , out pID ) ;
2015-03-16 16:40:30 -04:00
2015-03-30 01:04:10 -04:00
if ( pID = = - 1 ) // special case similar to mod_suicide
int . TryParse ( L [ 2 ] , out pID ) ;
2015-04-10 00:02:12 -04:00
if ( pID < 0 | | pID > 17 )
{
Log . Write ( "Error event player index " + pID + " is out of bounds!" , Log . Level . Debug ) ;
2015-03-30 01:04:10 -04:00
Log . Write ( "Offending line -- " + String . Join ( ";" , L ) , Log . Level . Debug ) ;
2015-04-10 00:02:12 -04:00
return null ;
2015-03-16 16:40:30 -04:00
}
else
{
2015-04-10 00:02:12 -04:00
Player P = null ;
try
{
P = players [ pID ] ;
return P ;
}
catch ( Exception )
{
Log . Write ( "Client index is invalid - " + pID , Log . Level . Debug ) ;
Log . Write ( L . ToString ( ) , Log . Level . Debug ) ;
return null ;
}
}
}
2015-03-16 16:40:30 -04:00
//Check ban list for every banned player and return ban if match is found
2015-08-20 01:06:44 -04:00
override public Ban isBanned ( Player C )
2015-03-08 17:20:10 -04:00
{
2015-04-11 13:31:04 -04:00
2015-08-20 01:06:44 -04:00
if ( C . Level = = Player . Permission . Banned )
return Bans . Find ( p = > p . npID . Equals ( C . npID ) ) ;
2015-04-11 13:31:04 -04:00
2015-03-08 17:20:10 -04:00
foreach ( Ban B in Bans )
{
2015-08-20 01:06:44 -04:00
if ( B . npID . Length < 5 | | B . IP . Length < 5 )
2015-03-23 23:01:05 -04:00
continue ;
2015-08-20 01:06:44 -04:00
if ( B . npID = = null | | C . npID = = null )
2015-03-23 23:01:05 -04:00
continue ;
2015-08-20 01:06:44 -04:00
if ( B . npID = = C . npID )
2015-03-08 17:20:10 -04:00
return B ;
2015-03-13 19:40:16 -04:00
2015-08-20 01:06:44 -04:00
if ( B . IP = = null | | C . IP = = null )
2015-03-13 19:40:16 -04:00
continue ;
2015-08-20 01:06:44 -04:00
if ( C . IP = = B . IP )
2015-03-13 19:40:16 -04:00
return B ;
2015-03-08 17:20:10 -04:00
}
return null ;
}
2015-08-28 00:39:36 -04:00
//Process requested command correlating to an event
2015-08-20 01:06:44 -04:00
override public Command processCommand ( Event E , Command C )
2015-03-08 17:20:10 -04:00
{
2015-08-20 13:52:30 -04:00
E . Data = SharedLibrary . Utilities . removeWords ( E . Data , 1 ) ;
String [ ] Args = E . Data . Trim ( ) . Split ( new char [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
if ( E . Origin . Level < C . Permission )
2015-03-08 17:20:10 -04:00
{
2015-08-20 13:52:30 -04:00
E . Origin . Tell ( "You do not have access to that command!" ) ;
2015-03-08 17:20:10 -04:00
return null ;
}
2015-08-20 13:52:30 -04:00
if ( Args . Length < ( C . requiredArgNum ) )
2015-03-08 17:20:10 -04:00
{
2015-08-20 13:52:30 -04:00
E . Origin . Tell ( "Not enough arguments supplied!" ) ;
2015-03-08 17:20:10 -04:00
return null ;
}
2015-08-20 01:06:44 -04:00
if ( C . needsTarget )
2015-03-08 17:20:10 -04:00
{
int cNum = - 1 ;
int . TryParse ( Args [ 0 ] , out cNum ) ;
2015-08-20 01:06:44 -04:00
if ( C . Name = = "stats" & & Args . Length = = 1 )
2015-03-23 23:01:05 -04:00
E . Target = E . Origin ;
2015-03-09 21:28:37 -04:00
if ( Args [ 0 ] = = String . Empty )
return C ;
2015-03-23 23:01:05 -04:00
2015-03-16 16:40:30 -04:00
if ( Args [ 0 ] [ 0 ] = = '@' ) // user specifying target by database ID
2015-03-08 17:20:10 -04:00
{
int dbID = - 1 ;
int . TryParse ( Args [ 0 ] . Substring ( 1 , Args [ 0 ] . Length - 1 ) , out dbID ) ;
2015-08-20 01:06:44 -04:00
IW4MServer castServer = ( IW4MServer ) ( E . Owner ) ;
Player found = castServer . clientDB . getPlayer ( dbID ) ;
2015-03-08 17:20:10 -04:00
if ( found ! = null )
2015-03-16 16:40:30 -04:00
{
2015-03-08 17:20:10 -04:00
E . Target = found ;
2015-03-16 16:40:30 -04:00
E . Target . lastEvent = E ;
E . Owner = this ;
}
2015-03-08 17:20:10 -04:00
}
2015-03-16 16:40:30 -04:00
else if ( Args [ 0 ] . Length < 3 & & cNum > - 1 & & cNum < 18 ) // user specifying target by client num
2015-03-08 17:20:10 -04:00
{
if ( players [ cNum ] ! = null )
E . Target = players [ cNum ] ;
}
else
2015-04-10 00:02:12 -04:00
E . Target = clientFromName ( Args [ 0 ] ) ;
2015-03-08 17:20:10 -04:00
if ( E . Target = = null )
{
E . Origin . Tell ( "Unable to find specified player." ) ;
return null ;
}
}
return C ;
}
2015-08-20 01:06:44 -04:00
override public void executeCommand ( String CMD )
2015-07-06 13:13:42 -04:00
{
2015-08-20 01:06:44 -04:00
commandQueue . Enqueue ( CMD ) ;
2015-07-06 13:13:42 -04:00
}
2015-08-20 01:06:44 -04:00
override public dvar getDvar ( String DvarName )
2015-07-06 13:13:42 -04:00
{
2015-08-17 16:38:42 -04:00
return Utilities . getDvar ( PID , DvarName , lastCommandPointer ) ;
2015-07-15 17:11:29 -04:00
}
2015-08-20 01:06:44 -04:00
override public void setDvar ( String Dvar , String Value )
2015-07-15 17:11:29 -04:00
{
2015-08-23 17:58:48 -04:00
lastDvarPointer = Utilities . executeCommand ( PID , Dvar + " " + "\"" + Value + "\"" , lastDvarPointer ) ;
2015-07-06 13:13:42 -04:00
}
2015-05-09 12:46:25 -04:00
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess ( int dwDesiredAccess , bool bInheritHandle , int dwProcessId ) ;
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory ( int hProcess , int lpBaseAddress , byte [ ] lpBuffer , int dwSize , ref int lpNumberOfBytesRead ) ;
2015-08-20 13:52:30 -04:00
private void manageEventQueue ( )
{
while ( isRunning )
{
if ( events . Count > 0 )
2015-08-20 15:23:13 -04:00
{
Event curEvent = events . Peek ( ) ;
2015-08-23 17:58:48 -04:00
if ( curEvent = = null )
2015-08-28 00:39:36 -04:00
{
events . Dequeue ( ) ;
2015-08-23 17:58:48 -04:00
continue ;
2015-08-28 00:39:36 -04:00
}
2015-08-23 17:58:48 -04:00
2015-08-20 15:23:13 -04:00
processEvent ( curEvent ) ;
2015-08-22 12:41:14 -04:00
foreach ( Plugin P in PluginImporter . potentialPlugins )
2015-08-22 02:04:30 -04:00
{
try
{
P . onEvent ( curEvent ) ;
}
catch ( Exception Except )
{
2015-08-28 00:39:36 -04:00
Log . Write ( String . Format ( "The plugin \"{0}\" generated an error. ( see log )" , P . Name ) , Log . Level . Production ) ;
2015-08-22 02:04:30 -04:00
Log . Write ( String . Format ( "Error Message: {0}" , Except . Message ) , Log . Level . Debug ) ;
Log . Write ( String . Format ( "Error Trace: {0}" , Except . StackTrace ) , Log . Level . Debug ) ;
continue ;
2015-08-28 00:39:36 -04:00
}
2015-08-22 02:04:30 -04:00
}
2015-08-20 15:23:13 -04:00
events . Dequeue ( ) ;
}
2015-08-20 13:52:30 -04:00
if ( commandQueue . Count > 0 )
lastCommandPointer = Utilities . executeCommand ( PID , commandQueue . Dequeue ( ) , lastCommandPointer ) ;
2015-08-20 15:23:13 -04:00
Thread . Sleep ( 300 ) ;
2015-08-20 13:52:30 -04:00
}
}
2015-03-08 17:20:10 -04:00
//Starts the monitoring process
2015-08-20 01:06:44 -04:00
override public void Monitor ( )
2015-03-08 17:20:10 -04:00
{
2015-03-14 12:42:36 -04:00
isRunning = true ;
2015-03-13 19:40:16 -04:00
2015-03-08 17:20:10 -04:00
if ( ! intializeBasics ( ) )
{
2015-07-17 18:53:51 -04:00
Log . Write ( "Stopping " + Port + " due to uncorrectable errors (check log)" , Log . Level . Production ) ;
2015-03-14 12:42:36 -04:00
isRunning = false ;
2015-03-09 16:11:09 -04:00
return ;
2015-03-08 17:20:10 -04:00
}
2015-07-06 13:13:42 -04:00
2015-08-20 13:52:30 -04:00
Thread eventQueueThread = new Thread ( new ThreadStart ( manageEventQueue ) ) ;
eventQueueThread . Name = "Event Queue Manager" ;
eventQueueThread . Start ( ) ;
2015-03-08 17:20:10 -04:00
long l_size = - 1 ;
String [ ] lines = new String [ 8 ] ;
String [ ] oldLines = new String [ 8 ] ;
DateTime start = DateTime . Now ;
2015-04-24 15:37:56 -04:00
DateTime playerCountStart = DateTime . Now ;
DateTime lastCount = DateTime . Now ;
2015-03-08 17:20:10 -04:00
2015-03-14 12:42:36 -04:00
#if DEBUG = = false
2015-03-10 17:56:01 -04:00
Broadcast ( "IW4M Admin is now ^2ONLINE" ) ;
2015-08-22 02:04:30 -04:00
int numExceptions = 0 ;
2015-03-14 12:42:36 -04:00
#endif
2015-03-08 17:20:10 -04:00
2015-03-23 23:01:05 -04:00
while ( isRunning )
2015-03-08 17:20:10 -04:00
{
2015-03-14 12:42:36 -04:00
#if DEBUG = = false
try
#endif
2015-03-08 17:20:10 -04:00
{
lastMessage = DateTime . Now - start ;
2015-04-24 15:37:56 -04:00
lastCount = DateTime . Now ;
if ( ( lastCount - playerCountStart ) . TotalMinutes > 4 )
{
2015-04-27 13:40:57 -04:00
while ( playerHistory . Count > 144 ) // 12 times a minute for 12 hours
2015-04-24 15:37:56 -04:00
playerHistory . Dequeue ( ) ;
2015-08-22 02:04:30 -04:00
playerHistory . Enqueue ( new PlayerHistory ( lastCount , clientnum ) ) ;
2015-04-24 15:37:56 -04:00
playerCountStart = DateTime . Now ;
}
2015-03-08 17:20:10 -04:00
if ( lastMessage . TotalSeconds > messageTime & & messages . Count > 0 )
{
2015-03-14 12:42:36 -04:00
initMacros ( ) ; // somethings dynamically change so we have to re-init the dictionary
2015-08-20 13:52:30 -04:00
Broadcast ( SharedLibrary . Utilities . processMacro ( Macros , messages [ nextMessage ] ) ) ;
2015-03-08 17:20:10 -04:00
if ( nextMessage = = ( messages . Count - 1 ) )
nextMessage = 0 ;
else
nextMessage + + ;
start = DateTime . Now ;
}
2015-08-20 01:06:44 -04:00
2015-08-22 02:04:30 -04:00
if ( ( DateTime . Now - lastPoll ) . Milliseconds > 300 )
2015-05-09 12:46:25 -04:00
{
int numberRead = 0 ;
2015-05-09 15:03:15 -04:00
int activeClients = 0 ;
2015-05-09 12:46:25 -04:00
for ( int i = 0 ; i < players . Count ; i + + )
{
Byte [ ] buff = new Byte [ 681872 ] ; // struct size ( 0.68MB :( )
ReadProcessMemory ( ( int ) Handle , 0x31D9390 + ( buff . Length ) * ( i ) , buff , buff . Length , ref numberRead ) ; // svs_clients start + current client
client_s eachClient = ( client_s ) Helpers . ReadStruct < client_s > ( buff ) ;
2015-07-17 18:53:51 -04:00
2015-07-03 00:10:01 -04:00
if ( eachClient . isBot = = 1 )
continue ;
2015-05-09 12:46:25 -04:00
if ( eachClient . state = = 0 )
removePlayer ( i ) ;
2015-07-17 18:53:51 -04:00
2015-08-20 01:06:44 -04:00
else if ( eachClient . state = = 5 )
2015-07-17 18:53:51 -04:00
{
2015-08-20 13:52:30 -04:00
addPlayer ( new Player ( SharedLibrary . Utilities . stripColors ( SharedLibrary . Utilities . cleanChars ( eachClient . name ) ) , eachClient . steamid . ToString ( "x16" ) , i , 0 , i , null , 0 , Helpers . NET_AdrToString ( eachClient . adr ) . Split ( ':' ) [ 0 ] ) ) ;
2015-05-09 15:03:15 -04:00
activeClients + + ;
2015-07-17 18:53:51 -04:00
}
2015-05-09 12:46:25 -04:00
}
lastPoll = DateTime . Now ;
2015-05-09 15:03:15 -04:00
clientnum = activeClients ;
2015-05-09 12:46:25 -04:00
}
2015-03-08 17:20:10 -04:00
if ( l_size ! = logFile . getSize ( ) )
{
lines = logFile . Tail ( 8 ) ;
if ( lines ! = oldLines )
{
l_size = logFile . getSize ( ) ;
int end ;
if ( lines . Length = = oldLines . Length )
end = lines . Length - 1 ;
else
end = Math . Abs ( ( lines . Length - oldLines . Length ) ) - 1 ;
for ( int count = 0 ; count < lines . Length ; count + + )
{
if ( lines . Length < 1 & & oldLines . Length < 1 )
continue ;
if ( lines [ count ] = = oldLines [ oldLines . Length - 1 ] )
continue ;
2015-04-10 00:02:12 -04:00
if ( lines [ count ] . Length < 10 ) // its not a needed line
2015-03-08 17:20:10 -04:00
continue ;
else
{
string [ ] game_event = lines [ count ] . Split ( ';' ) ;
2015-08-20 01:06:44 -04:00
Event event_ = Event . requestEvent ( game_event , ( Server ) this ) ;
2015-03-08 17:20:10 -04:00
if ( event_ ! = null )
{
if ( event_ . Origin = = null )
2015-04-11 13:31:04 -04:00
continue ;
2015-03-08 17:20:10 -04:00
event_ . Origin . lastEvent = event_ ;
event_ . Origin . lastEvent . Owner = this ;
2015-08-20 13:52:30 -04:00
events . Enqueue ( event_ ) ;
2015-03-08 17:20:10 -04:00
}
}
}
}
}
oldLines = lines ;
l_size = logFile . getSize ( ) ;
2015-08-20 15:23:13 -04:00
Thread . Sleep ( 300 ) ;
2015-03-08 17:20:10 -04:00
}
2015-03-14 12:42:36 -04:00
#if DEBUG = = false
2015-03-08 17:20:10 -04:00
catch ( Exception E )
{
2015-08-22 02:04:30 -04:00
numExceptions + + ;
Log . Write ( "Unexpected error on \"" + hostname + "\"" , Log . Level . Debug ) ;
Log . Write ( "Error Message: " + E . Message , Log . Level . Debug ) ;
Log . Write ( "Error Trace: " + E . StackTrace , Log . Level . Debug ) ;
if ( numExceptions < 30 )
continue ;
else
{
Log . Write ( "Maximum number of unhandled exceptions reached for \"" + hostname + "\"" , Log . Level . Production ) ;
events . Enqueue ( new Event ( Event . GType . Stop , "Monitoring stopping because of max exceptions reached" , null , null , this ) ) ;
isRunning = false ;
}
2015-03-08 17:20:10 -04:00
}
2015-03-14 12:42:36 -04:00
#endif
2015-03-08 17:20:10 -04:00
}
2015-08-21 21:11:35 -04:00
events . Enqueue ( new Event ( Event . GType . Stop , "Server monitoring stopped" , null , null , this ) ) ;
2015-03-14 12:42:36 -04:00
isRunning = false ;
2015-08-20 13:52:30 -04:00
eventQueueThread . Join ( ) ;
2015-03-08 17:20:10 -04:00
}
2015-04-19 14:14:30 -04:00
2015-08-20 01:06:44 -04:00
override public bool intializeBasics ( )
2015-03-08 17:20:10 -04:00
{
2015-10-10 19:31:24 -04:00
#if DEBUG = = false
2015-08-22 02:04:30 -04:00
try
2015-10-10 19:31:24 -04:00
#endif
2015-08-22 02:04:30 -04:00
{
2015-08-23 17:58:48 -04:00
// clear out any lingering instances
Utilities . shutdownInterface ( PID ) ;
2015-08-22 02:04:30 -04:00
// inject our dll
if ( ! Utilities . initalizeInterface ( PID ) )
{
Log . Write ( "Could not load IW4MAdmin interface!" , Log . Level . Debug ) ;
return false ;
}
2015-07-24 15:46:32 -04:00
2015-07-15 17:11:29 -04:00
// basic info dvars
2015-10-10 19:31:24 -04:00
do
{
hostname = SharedLibrary . Utilities . stripColors ( getDvar ( "sv_hostname" ) . current ) ;
mapname = getDvar ( "mapname" ) . current ;
} while ( hostname = = "0" | | mapname = = "0" ) ;
2015-08-26 01:49:47 -04:00
Map localizedMapName = maps . Find ( x = > x . Name . Equals ( mapname ) ) ;
if ( localizedMapName ! = null )
mapname = localizedMapName . Alias ;
2015-08-22 02:04:30 -04:00
IW_Ver = getDvar ( "shortversion" ) . current ;
maxClients = - 1 ;
2015-07-24 15:46:32 -04:00
Int32 . TryParse ( getDvar ( "party_maxplayers" ) . current , out maxClients ) ;
if ( maxClients = = - 1 )
{
2015-08-20 01:06:44 -04:00
Log . Write ( "Could not get max clients value" , Log . Level . Debug ) ;
2015-07-24 15:46:32 -04:00
return false ;
}
2015-08-22 02:04:30 -04:00
Gametype = getDvar ( "g_gametype" ) . current ;
2015-07-06 13:13:42 -04:00
2015-07-15 17:11:29 -04:00
// important log variables
2015-10-10 19:31:24 -04:00
do
{
Basepath = getDvar ( "fs_basepath" ) . current ;
Mod = getDvar ( "fs_game" ) . current ;
logPath = getDvar ( "g_log" ) . current ;
} while ( Basepath = = "0" | | Mod = = "0" | | logPath = = "0" ) ;
2015-08-22 02:04:30 -04:00
int oneLog = - 1 ;
2015-10-10 19:31:24 -04:00
logPath = logPath . Replace ( "/" , "\\" ) ;
Mod = Mod . Replace ( "/" , "\\" ) ;
2015-10-11 14:11:38 -04:00
Thread . Sleep ( 100 ) ;
Int32 . TryParse ( getDvar ( "iw4m_onelog" ) . current , out oneLog ) ;
2015-10-10 22:32:12 -04:00
2015-08-22 02:04:30 -04:00
if ( oneLog = = - 1 )
{
Log . Write ( "Could not get iw4m_onelog value" , Log . Level . Debug ) ;
return false ;
}
2015-07-15 17:11:29 -04:00
// our settings
2015-08-23 17:58:48 -04:00
setDvar ( "sv_kickbantime" , "3600" ) ; // 1 hour
2015-08-28 00:39:36 -04:00
Website = getDvar ( "_website" ) . current ;
if ( Website = = "0" | | Website = = null )
Website = "this server's website" ;
2015-10-10 19:31:24 -04:00
2015-08-23 17:58:48 -04:00
int logSync = - 1 ;
2015-10-10 22:32:12 -04:00
2015-10-11 14:11:38 -04:00
Thread . Sleep ( 100 ) ;
Int32 . TryParse ( getDvar ( "g_logSync" ) . current , out logSync ) ;
2015-08-23 17:58:48 -04:00
if ( logSync = = 0 )
{
Log . Write ( "g_logsync is not set to 1, restarting map..." ) ;
setDvar ( "g_logSync" , "1" ) ; // yas
executeCommand ( "map_restart" ) ;
SharedLibrary . Utilities . Wait ( 10 ) ;
}
2015-08-22 02:04:30 -04:00
if ( Mod = = String . Empty | | oneLog = = 1 )
logPath = Basepath + '\\' + "m2demo" + '\\' + logPath ;
else
logPath = Basepath + '\\' + Mod + '\\' + logPath ;
if ( ! File . Exists ( logPath ) )
{
Log . Write ( "Gamelog `" + logPath + "` does not exist!" , Log . Level . All ) ;
return false ;
}
logFile = new IFile ( logPath ) ;
Log . Write ( "Log file is " + logPath , Log . Level . Debug ) ;
Log . Write ( "Now monitoring " + getName ( ) , Log . Level . Production ) ;
events . Enqueue ( new Event ( Event . GType . Start , "Server started" , null , null , this ) ) ;
Bans = clientDB . getBans ( ) ;
return true ;
2015-03-08 17:20:10 -04:00
}
2015-10-10 19:31:24 -04:00
#if DEBUG = = false
2015-03-08 17:20:10 -04:00
catch ( Exception E )
{
2015-08-22 02:04:30 -04:00
Log . Write ( "Error during initialization - " + E . Message + "--" + E . StackTrace , Log . Level . All ) ;
2015-03-08 17:20:10 -04:00
return false ;
}
2015-10-10 19:31:24 -04:00
#endif
2015-03-08 17:20:10 -04:00
}
2015-07-06 13:13:42 -04:00
2015-03-08 17:20:10 -04:00
//Process any server event
2015-08-20 01:06:44 -04:00
override public bool processEvent ( Event E )
2015-03-08 17:20:10 -04:00
{
2015-04-11 13:31:04 -04:00
if ( E . Type = = Event . GType . Connect )
{
return true ;
}
2015-03-16 16:40:30 -04:00
if ( E . Type = = Event . GType . Disconnect )
2015-03-08 17:20:10 -04:00
{
2015-03-16 16:40:30 -04:00
if ( E . Origin = = null )
2015-03-09 21:28:37 -04:00
{
2015-03-16 16:40:30 -04:00
Log . Write ( "Disconnect event triggered, but no origin found." , Log . Level . Debug ) ;
return false ;
2015-03-09 21:28:37 -04:00
}
2015-03-16 16:40:30 -04:00
2015-04-24 15:37:56 -04:00
while ( chatHistory . Count > Math . Ceiling ( ( ( double ) clientnum - 1 ) / 2 ) )
2015-04-19 14:14:30 -04:00
chatHistory . RemoveAt ( 0 ) ;
chatHistory . Add ( new Chat ( E . Origin , "<i>DISCONNECTED</i>" , DateTime . Now ) ) ;
2015-08-20 01:06:44 -04:00
removePlayer ( E . Origin . clientID ) ;
2015-03-08 17:20:10 -04:00
return true ;
}
2015-03-09 21:28:37 -04:00
if ( E . Type = = Event . GType . Kill )
{
2015-03-16 16:40:30 -04:00
if ( E . Origin = = null )
{
Log . Write ( "Kill event triggered, but no origin found!" , Log . Level . Debug ) ;
return false ;
}
2015-03-23 23:01:05 -04:00
if ( E . Origin ! = E . Target )
{
2015-08-20 15:23:13 -04:00
events . Enqueue ( new Event ( Event . GType . Death , E . Data , E . Target , null , this ) ) ;
2015-03-23 23:01:05 -04:00
}
2015-03-16 16:40:30 -04:00
2015-04-11 13:31:04 -04:00
else // suicide/falling
2015-03-23 23:01:05 -04:00
{
2015-08-20 01:06:44 -04:00
Log . Write ( E . Origin . Name + " suicided..." , Log . Level . Debug ) ;
2015-08-20 17:54:38 -04:00
events . Enqueue ( new Event ( Event . GType . Death , "suicide" , E . Target , null , this ) ) ;
2015-03-23 23:01:05 -04:00
}
2015-03-09 21:28:37 -04:00
}
2015-03-16 16:40:30 -04:00
if ( E . Type = = Event . GType . Say )
2015-03-08 17:20:10 -04:00
{
2015-03-16 16:40:30 -04:00
if ( E . Data . Length < 2 ) // ITS A LIE!
return false ;
if ( E . Origin = = null )
{
Log . Write ( "Say event triggered, but no origin found! - " + E . Data , Log . Level . Debug ) ;
2015-03-09 21:28:37 -04:00
return false ;
2015-03-16 16:40:30 -04:00
}
2015-03-09 21:28:37 -04:00
2015-08-20 01:06:44 -04:00
Log . Write ( "Message from " + E . Origin . Name + ": " + E . Data , Log . Level . Debug ) ;
2015-03-08 17:20:10 -04:00
2015-03-16 16:40:30 -04:00
if ( E . Owner = = null )
{
Log . Write ( "Say event does not have an owner!" , Log . Level . Debug ) ;
return false ;
}
2015-08-22 02:04:30 -04:00
if ( E . Data . Substring ( 0 , 1 ) = = "!" | | E . Origin . Level = = Player . Permission . Console )
2015-04-19 14:14:30 -04:00
{
2015-08-22 02:04:30 -04:00
Command C = E . isValidCMD ( commands ) ;
2015-04-19 14:14:30 -04:00
2015-08-22 02:04:30 -04:00
if ( C ! = null )
{
C = processCommand ( E , C ) ;
if ( C ! = null )
{
if ( C . needsTarget & & E . Target = = null )
{
Log . Write ( "Requested event requiring target does not have a target!" , Log . Level . Debug ) ;
return false ;
}
2015-04-19 14:14:30 -04:00
2015-08-22 02:04:30 -04:00
try
{
C . Execute ( E ) ;
}
2015-03-08 17:20:10 -04:00
2015-08-22 02:04:30 -04:00
catch ( Exception Except )
{
Log . Write ( String . Format ( "A command request \"{0}\" generated an error." , C . Name , Log . Level . Debug ) ) ;
Log . Write ( String . Format ( "Error Message: {0}" , Except . Message ) , Log . Level . Debug ) ;
Log . Write ( String . Format ( "Error Trace: {0}" , Except . StackTrace ) , Log . Level . Debug ) ;
return false ;
}
return true ;
}
2015-03-16 16:40:30 -04:00
2015-08-22 02:04:30 -04:00
else
2015-03-16 16:40:30 -04:00
{
2015-08-22 02:04:30 -04:00
Log . Write ( "Player didn't properly enter command - " + E . Origin . Name , Log . Level . Debug ) ;
return true ;
2015-03-16 16:40:30 -04:00
}
2015-03-08 17:20:10 -04:00
}
2015-04-10 00:02:12 -04:00
2015-03-08 17:20:10 -04:00
else
2015-08-22 02:04:30 -04:00
E . Origin . Tell ( "You entered an invalid command!" ) ;
2015-03-08 17:20:10 -04:00
}
2015-08-22 02:04:30 -04:00
else // Not a command so who gives an F?
{
E . Data = SharedLibrary . Utilities . stripColors ( SharedLibrary . Utilities . cleanChars ( E . Data ) ) ;
if ( E . Data . Length > 50 )
E . Data = E . Data . Substring ( 0 , 50 ) + "..." ;
while ( chatHistory . Count > Math . Ceiling ( ( double ) clientnum / 2 ) )
chatHistory . RemoveAt ( 0 ) ;
chatHistory . Add ( new Chat ( E . Origin , E . Data , DateTime . Now ) ) ;
return true ;
}
2015-03-08 17:20:10 -04:00
return true ;
}
if ( E . Type = = Event . GType . MapChange )
{
2015-04-10 00:02:12 -04:00
Log . Write ( "New map loaded - " + clientnum + " active players" , Log . Level . Debug ) ;
2015-04-27 23:29:43 -04:00
2015-08-23 17:58:48 -04:00
String newMapName = "0" ;
String newGametype = "0" ;
String newHostName = "0" ;
while ( newMapName = = "0" | | newGametype = = "0" | | newHostName = = "0" ) // weird anomaly here.
{
newMapName = getDvar ( "mapname" ) . current ;
newGametype = getDvar ( "g_gametype" ) . current ;
newHostName = getDvar ( "sv_hostname" ) . current ;
}
2015-08-22 02:04:30 -04:00
Map newMap = maps . Find ( m = > m . Name . Equals ( newMapName ) ) ;
2015-04-27 23:29:43 -04:00
2015-08-22 02:04:30 -04:00
if ( newMap ! = null )
mapname = newMap . Alias ;
2015-04-27 23:29:43 -04:00
else
2015-08-22 02:04:30 -04:00
mapname = newMapName ;
2015-04-27 23:29:43 -04:00
2015-08-23 17:58:48 -04:00
Gametype = newGametype ;
hostname = SharedLibrary . Utilities . stripColors ( newHostName ) ;
2015-04-11 13:31:04 -04:00
return true ;
2015-03-08 17:20:10 -04:00
}
if ( E . Type = = Event . GType . MapEnd )
{
2015-03-10 16:45:20 -04:00
Log . Write ( "Game ending..." , Log . Level . Debug ) ;
2015-03-08 17:20:10 -04:00
return true ;
}
return false ;
}
2015-08-20 01:06:44 -04:00
override public void Ban ( String Message , Player Target , Player Origin )
2015-03-13 19:40:16 -04:00
{
2015-08-20 01:06:44 -04:00
if ( Target . clientID > - 1 )
executeCommand ( "tempbanclient " + Target . clientID + " \"" + Message + "^7\"" ) ;
2015-04-10 00:02:12 -04:00
2015-03-08 17:20:10 -04:00
if ( Origin ! = null )
{
Target . setLevel ( Player . Permission . Banned ) ;
2015-08-20 01:06:44 -04:00
Ban newBan = new Ban ( Target . lastOffense , Target . npID , Origin . npID , DateTime . Now , Target . IP ) ;
2015-07-17 18:53:51 -04:00
2015-03-13 19:40:16 -04:00
clientDB . addBan ( newBan ) ;
clientDB . updatePlayer ( Target ) ;
2015-07-17 18:53:51 -04:00
2015-08-20 17:54:38 -04:00
foreach ( SharedLibrary . Server S in Program . getServers ( ) ) // make sure bans show up on the webfront
S . Bans = S . clientDB . getBans ( ) ;
2015-07-17 18:53:51 -04:00
2015-04-10 00:02:12 -04:00
lock ( Reports ) // threading seems to do something weird here
{
List < Report > toRemove = new List < Report > ( ) ;
foreach ( Report R in Reports )
{
2015-08-20 01:06:44 -04:00
if ( R . Target . npID = = Target . npID )
2015-04-10 00:02:12 -04:00
toRemove . Add ( R ) ;
}
foreach ( Report R in toRemove )
{
Reports . Remove ( R ) ;
2015-08-20 01:06:44 -04:00
Log . Write ( "Removing report for banned GUID -- " + R . Origin . npID , Log . Level . Debug ) ;
2015-04-10 00:02:12 -04:00
}
}
2015-03-08 17:20:10 -04:00
}
}
2015-08-20 01:06:44 -04:00
override public bool Unban ( String GUID , Player Target )
2015-03-08 17:20:10 -04:00
{
foreach ( Ban B in Bans )
{
2015-08-20 01:06:44 -04:00
if ( B . npID = = Target . npID )
2015-03-08 17:20:10 -04:00
{
2015-08-20 01:06:44 -04:00
clientDB . removeBan ( Target . npID , Target . IP ) ;
2015-04-19 14:14:30 -04:00
2015-08-20 01:06:44 -04:00
Player P = clientDB . getPlayer ( Target . npID , - 1 ) ;
2015-03-08 17:20:10 -04:00
P . setLevel ( Player . Permission . User ) ;
2015-03-13 19:40:16 -04:00
clientDB . updatePlayer ( P ) ;
2015-07-06 13:13:42 -04:00
2015-08-20 17:54:38 -04:00
foreach ( SharedLibrary . Server S in Program . getServers ( ) ) // make sure bans show up on the webfront
S . Bans = S . clientDB . getBans ( ) ;
2015-03-08 17:20:10 -04:00
return true ;
}
}
return false ;
}
2015-08-20 17:54:38 -04:00
override public bool Reload ( )
{
try
{
messages = null ;
maps = null ;
rules = null ;
initMaps ( ) ;
initMessages ( ) ;
initRules ( ) ;
2015-08-22 12:41:14 -04:00
PluginImporter . Unload ( ) ;
2015-08-20 17:54:38 -04:00
PluginImporter . Load ( ) ;
return true ;
}
catch ( Exception E )
{
Log . Write ( "Unable to reload configs! - " + E . Message , Log . Level . Debug ) ;
messages = new List < String > ( ) ;
maps = new List < Map > ( ) ;
rules = new List < String > ( ) ;
return false ;
}
}
2015-03-08 17:20:10 -04:00
2015-08-20 01:06:44 -04:00
override public void initMacros ( )
2015-03-13 19:40:16 -04:00
{
Macros = new Dictionary < String , Object > ( ) ;
Macros . Add ( "TOTALPLAYERS" , clientDB . totalPlayers ( ) ) ;
2015-03-23 23:01:05 -04:00
Macros . Add ( "TOTALKILLS" , totalKills ) ;
2015-08-20 01:06:44 -04:00
Macros . Add ( "VERSION" , IW4MAdmin . Program . Version ) ;
2015-03-08 17:20:10 -04:00
}
2015-08-20 01:06:44 -04:00
override public void initCommands ( )
2015-03-08 17:20:10 -04:00
{
// Something like *COMMAND* | NAME | HELP MSG | ALIAS | NEEDED PERMISSION | # OF REQUIRED ARGS | HAS TARGET |
commands = new List < Command > ( ) ;
2015-08-23 17:58:48 -04:00
owner = clientDB . getOwner ( ) ;
2015-03-08 17:20:10 -04:00
if ( owner = = null )
commands . Add ( new Owner ( "owner" , "claim ownership of the server" , "owner" , Player . Permission . User , 0 , false ) ) ;
2015-08-26 01:49:47 -04:00
foreach ( Command C in PluginImporter . potentialCommands )
commands . Add ( C ) ;
2015-03-08 17:20:10 -04:00
commands . Add ( new Kick ( "kick" , "kick a player by name. syntax: !kick <player> <reason>." , "k" , Player . Permission . Moderator , 2 , true ) ) ;
commands . Add ( new Say ( "say" , "broadcast message to all players. syntax: !say <message>." , "s" , Player . Permission . Moderator , 1 , false ) ) ;
commands . Add ( new TempBan ( "tempban" , "temporarily ban a player for 1 hour. syntax: !tempban <player> <reason>." , "tb" , Player . Permission . Moderator , 2 , true ) ) ;
commands . Add ( new SBan ( "ban" , "permanently ban a player from the server. syntax: !ban <player> <reason>" , "b" , Player . Permission . SeniorAdmin , 2 , true ) ) ;
commands . Add ( new WhoAmI ( "whoami" , "give information about yourself. syntax: !whoami." , "who" , Player . Permission . User , 0 , false ) ) ;
commands . Add ( new List ( "list" , "list active clients syntax: !list." , "l" , Player . Permission . Moderator , 0 , false ) ) ;
2015-03-10 16:45:20 -04:00
commands . Add ( new Help ( "help" , "list all available commands. syntax: !help." , "h" , Player . Permission . User , 0 , false ) ) ;
2015-03-08 17:20:10 -04:00
commands . Add ( new FastRestart ( "fastrestart" , "fast restart current map. syntax: !fastrestart." , "fr" , Player . Permission . Moderator , 0 , false ) ) ;
commands . Add ( new MapRotate ( "maprotate" , "cycle to the next map in rotation. syntax: !maprotate." , "mr" , Player . Permission . Administrator , 0 , false ) ) ;
commands . Add ( new SetLevel ( "setlevel" , "set player to specified administration level. syntax: !setlevel <player> <level>." , "sl" , Player . Permission . Owner , 2 , true ) ) ;
2015-03-10 16:45:20 -04:00
commands . Add ( new Usage ( "usage" , "get current application memory usage. syntax: !usage." , "us" , Player . Permission . Moderator , 0 , false ) ) ;
2015-03-08 17:20:10 -04:00
commands . Add ( new Uptime ( "uptime" , "get current application running time. syntax: !uptime." , "up" , Player . Permission . Moderator , 0 , false ) ) ;
commands . Add ( new Warn ( "warn" , "warn player for infringing rules syntax: !warn <player> <reason>." , "w" , Player . Permission . Moderator , 2 , true ) ) ;
commands . Add ( new WarnClear ( "warnclear" , "remove all warning for a player syntax: !warnclear <player>." , "wc" , Player . Permission . Administrator , 1 , true ) ) ;
2015-04-13 00:25:34 -04:00
commands . Add ( new Unban ( "unban" , "unban player by database id. syntax: !unban @<id>." , "ub" , Player . Permission . SeniorAdmin , 1 , true ) ) ;
2015-03-08 17:20:10 -04:00
commands . Add ( new Admins ( "admins" , "list currently connected admins. syntax: !admins." , "a" , Player . Permission . User , 0 , false ) ) ;
commands . Add ( new MapCMD ( "map" , "change to specified map. syntax: !map" , "m" , Player . Permission . Administrator , 1 , false ) ) ;
2015-03-13 19:40:16 -04:00
commands . Add ( new Find ( "find" , "find player in database. syntax: !find <player>" , "f" , Player . Permission . SeniorAdmin , 1 , false ) ) ;
2015-03-08 17:20:10 -04:00
commands . Add ( new Rules ( "rules" , "list server rules. syntax: !rules" , "r" , Player . Permission . User , 0 , false ) ) ;
2015-03-09 16:11:09 -04:00
commands . Add ( new PrivateMessage ( "privatemessage" , "send message to other player. syntax: !pm <player> <message>" , "pm" , Player . Permission . User , 2 , true ) ) ;
2015-03-13 19:40:16 -04:00
commands . Add ( new Reload ( "reload" , "reload configurations. syntax: !reload" , "reload" , Player . Permission . Owner , 0 , false ) ) ;
2015-03-23 23:01:05 -04:00
commands . Add ( new Balance ( "balance" , "balance teams. syntax !balance" , "bal" , Player . Permission . Moderator , 0 , false ) ) ;
commands . Add ( new GoTo ( "goto" , "teleport to selected player. syntax !goto" , "go" , Player . Permission . SeniorAdmin , 1 , true ) ) ;
commands . Add ( new Flag ( "flag" , "flag a suspicious player and announce to admins on join . syntax !flag <player>:" , "flag" , Player . Permission . Moderator , 1 , true ) ) ;
commands . Add ( new _Report ( "report" , "report a player for suspicious behaivor. syntax !report <player> <reason>" , "rep" , Player . Permission . User , 2 , true ) ) ;
commands . Add ( new Reports ( "reports" , "get most recent reports. syntax !reports" , "reports" , Player . Permission . Moderator , 0 , false ) ) ;
2015-04-10 00:02:12 -04:00
commands . Add ( new _Tell ( "tell" , "send onscreen message to player. syntax !tell <player> <message>" , "t" , Player . Permission . Moderator , 2 , true ) ) ;
commands . Add ( new Mask ( "mask" , "hide your online presence from online admin list. syntax: !mask" , "mask" , Player . Permission . Administrator , 0 , false ) ) ;
commands . Add ( new BanInfo ( "baninfo" , "get information about a ban for a player. syntax: !baninfo <player>" , "bi" , Player . Permission . Moderator , 1 , true ) ) ;
commands . Add ( new Alias ( "alias" , "get past aliases and ips of a player. syntax: !alias <player>" , "known" , Player . Permission . Moderator , 1 , true ) ) ;
commands . Add ( new _RCON ( "rcon" , "send rcon command to server. syntax: !rcon <command>" , "rcon" , Player . Permission . Owner , 1 , false ) ) ;
2015-04-13 00:25:34 -04:00
commands . Add ( new FindAll ( "findall" , "find a player by their aliase(s). syntax: !findall <player>" , "fa" , Player . Permission . Moderator , 1 , false ) ) ;
2015-08-26 01:49:47 -04:00
commands . Add ( new Plugins ( "plugins" , "view all loaded plugins. syntax: !plugins" , "p" , Player . Permission . Administrator , 0 , false ) ) ;
2015-03-08 17:20:10 -04:00
}
//Objects
2015-08-20 01:06:44 -04:00
private Queue < String > commandQueue ;
2015-04-24 15:37:56 -04:00
2015-03-13 19:40:16 -04:00
//Will probably move this later
2015-08-17 16:38:42 -04:00
private IntPtr dllPointer ;
public IntPtr lastCommandPointer ;
public IntPtr lastDvarPointer ;
2015-03-08 17:20:10 -04:00
}
}