Engine
Class AccessControl

source: C:\XIII\Engine\Classes\AccessControl.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Info
         |
         +--Engine.AccessControl
Direct Known Subclasses:XIIIAccessControl

class AccessControl
extends Engine.Info

//============================================================================= // AccessControl. // // AccessControl is a helper class for GameInfo. // The AccessControl class determines whether or not the player is allowed to // login in the PreLogin() function, and also controls whether or not a player // can enter as a spectator or a game administrator. // //=============================================================================
Variables
 class AdminClass
 string AdminPassword
           Password to receive bAdmin privileges.
 string GamePassword
           Password to enter game.
 string IPBanned
 string IPPolicies[50]
 string NeedPassword
 string WrongPassword


Function Summary
 bool AdminLogin(PlayerController P, string Password)
     
//_____________________________________________________________________________
 bool CheckIPPolicy(string Address)
     
//_____________________________________________________________________________
 void Kick(string S)
     
//_____________________________________________________________________________
 void KickBan(string S)
     
//_____________________________________________________________________________
 void SetAdminPassword(string P)
     
//_____________________________________________________________________________
 void SetGamePassword(string P)
     
//_____________________________________________________________________________



Source Code


00001	//=============================================================================
00002	// AccessControl.
00003	//
00004	// AccessControl is a helper class for GameInfo.
00005	// The AccessControl class determines whether or not the player is allowed to
00006	// login in the PreLogin() function, and also controls whether or not a player
00007	// can enter as a spectator or a game administrator.
00008	//
00009	//=============================================================================
00010	class AccessControl extends Info;
00011	
00012	var globalconfig string IPPolicies[50];
00013	var localized string IPBanned;
00014	var localized string WrongPassword;
00015	var localized string NeedPassword;
00016	var class<PlayerController> AdminClass;
00017	
00018	var private globalconfig string AdminPassword;       // Password to receive bAdmin privileges.
00019	var private globalconfig string GamePassword;        // Password to enter game.
00020	
00021	//_____________________________________________________________________________
00022	function SetAdminPassword(string P)
00023	{
00024	    Log("ACCESS SetAdminPassword '"$P$"'");
00025	    AdminPassword = P;
00026	}
00027	
00028	//_____________________________________________________________________________
00029	function SetGamePassword(string P)
00030	{
00031	    Log("ACCESS SetGamePassword '"$p$"'");
00032	    GamePassword = P;
00033	}
00034	
00035	//_____________________________________________________________________________
00036	function Kick( string S )
00037	{
00038	    local PlayerController P;
00039	
00040	    Log("ACCESS KICK '"$s$"'");
00041	
00042	    ForEach DynamicActors(class'PlayerController', P)
00043	      if ( P.PlayerReplicationInfo.PlayerName~=S
00044	        &&  (NetConnection(P.Player)!=None) )
00045	      {
00046	        P.Destroy();
00047	        return;
00048	      }
00049	}
00050	
00051	//_____________________________________________________________________________
00052	function KickBan( string S )
00053	{
00054	    local PlayerController P;
00055	    local string IP;
00056	    local int j;
00057	
00058	    Log("ACCESS KICKBAN '"$s$"'");
00059	    ForEach DynamicActors(class'PlayerController', P)
00060	      if ( P.PlayerReplicationInfo.PlayerName~=S
00061	        &&  (NetConnection(P.Player)!=None) )
00062	      {
00063	        IP = P.GetPlayerNetworkAddress();
00064	        if( CheckIPPolicy(IP) )
00065	        {
00066	          IP = Left(IP, InStr(IP, ":"));
00067	          Log("Adding IP Ban for: "$IP);
00068	          for(j=0;j<50;j++)
00069	            if( IPPolicies[j] == "" )
00070	              break;
00071	          if(j < 50)
00072	            IPPolicies[j] = "DENY,"$IP;
00073	          SaveConfig();
00074	        }
00075	        P.Destroy();
00076	        return;
00077	      }
00078	}
00079	
00080	//_____________________________________________________________________________
00081	function bool AdminLogin( PlayerController P, string Password )
00082	{
00083	    if ( AdminPassword == "" )
00084	      return false; // no clients allowed to be admins
00085	
00086	    if (Password == AdminPassword)
00087	    {
00088	      Log("Administrator logged in ("$class$"), give him class"@AdminClass);
00089	  //    Level.Game.Broadcast( P, P.PlayerReplicationInfo.PlayerName$"logged in as a server administrator." );
00090	      return true;
00091	    }
00092	    return false;
00093	}
00094	
00095	//_____________________________________________________________________________
00096	// Accept or reject a player on the server.
00097	// Fails login if you set the Error to a non-empty string.
00098	event PreLogin
00099	(
00100	    string Options,
00101	    string Address,
00102	    out string Error,
00103	    out string FailCode,
00104	    bool bSpectator
00105	  )
00106	
00107	  {
00108	    // Do any name or password or name validation here.
00109	    local string InPassword, SpectatorClass;
00110	
00111	    Log("ACCESS PRELOGIN :"$Options);
00112	
00113	    Error="";
00114	    InPassword = Level.Game.ParseOption( Options, "Password" );
00115	
00116	    if( (Level.NetMode != NM_Standalone) && Level.Game.AtCapacity(bSpectator) )
00117	    {
00118	        //Error=Level.Game.GameMessageClass.Default.MaxedOutMessage;
00119	        Error="POM:Engine:GameInfo:MaxedOutMessage";    // don't send the message in server language, but the reference of the localized message instead !
00120	    }
00121	    else if
00122	    (  GamePassword!=""
00123	    &&  caps(InPassword)!=caps(GamePassword)
00124	    &&  (AdminPassword=="" || caps(InPassword)!=caps(AdminPassword)) )
00125	    {
00126	      if( InPassword == "" )
00127	      {
00128	        //Error = NeedPassword;
00129	        Error = "POM:Engine:AccessControl:NeedPassword";     // don't send the message in server language, but the reference of the localized message instead !
00130	        FailCode = "NEEDPW";
00131	      }
00132	      else
00133	      {
00134	        //Error = WrongPassword;
00135	        Error = "POM:Engine:AccessControl:WrongPassword";    // don't send the message in server language, but the reference of the localized message instead !
00136	        FailCode = "WRONGPW";
00137	      }
00138	    }
00139	
00140	    if(!CheckIPPolicy(Address))
00141	    {
00142	      //Error = IPBanned;
00143	      Error = "POM:Engine:AccessControl:IPBanned";     // don't send the message in server language, but the reference of the localized message instead !
00144	    }
00145	}
00146	
00147	//_____________________________________________________________________________
00148	function bool CheckIPPolicy(string Address)
00149	{
00150	    local int i, j, LastMatchingPolicy;
00151	    local string Policy, Mask;
00152	    local bool bAcceptAddress, bAcceptPolicy;
00153	
00154	    // strip port number
00155	    j = InStr(Address, ":");
00156	    if(j != -1)
00157	      Address = Left(Address, j);
00158	
00159	    bAcceptAddress = True;
00160	    for(i=0; i<50 && IPPolicies[i] != ""; i++)
00161	    {
00162	      j = InStr(IPPolicies[i], ",");
00163	      if(j==-1)
00164	        continue;
00165	      Policy = Left(IPPolicies[i], j);
00166	      Mask = Mid(IPPolicies[i], j+1);
00167	      if(Policy ~= "ACCEPT")
00168	        bAcceptPolicy = True;
00169	      else
00170	      if(Policy ~= "DENY")
00171	        bAcceptPolicy = False;
00172	      else
00173	        continue;
00174	
00175	      j = InStr(Mask, "*");
00176	      if(j != -1)
00177	      {
00178	        if(Left(Mask, j) == Left(Address, j))
00179	        {
00180	          bAcceptAddress = bAcceptPolicy;
00181	          LastMatchingPolicy = i;
00182	        }
00183	      }
00184	      else
00185	      {
00186	        if(Mask == Address)
00187	        {
00188	          bAcceptAddress = bAcceptPolicy;
00189	          LastMatchingPolicy = i;
00190	        }
00191	      }
00192	    }
00193	
00194	    if(!bAcceptAddress)
00195	      Log("Denied connection for "$Address$" with IP policy "$IPPolicies[LastMatchingPolicy]);
00196	
00197	    return bAcceptAddress;
00198	}
00199	
00200	defaultproperties
00201	{
00202	     IPPolicies(0)="ACCEPT,*"
00203	     IPBanned="Your IP address has been banned on this server."
00204	     WrongPassword="The password you entered is incorrect."
00205	     NeedPassword="You need to enter a password to join this game."
00206	     AdminClass=Class'Engine.Admin'
00207	}

End Source Code