Author Topic: Randomize Character + Host Only  (Read 1221 times)

Current Code:
Code: [Select]
function getRandomString(%len)
{
   %chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
   for(%i=0;%i<%len;%i++)
   {
      %str = %str @ getSubStr(%chars,getRandom(0,strlen(%chars)-1),1);
   }
   return %str;
}
function servercmdrandomizepasswords(%client,%alen,%salen)
{
   //This is not for use on LAN servers,
   //how do I check that?
   if(what)
   {
       messageClient(%client,"\c6Sorry, but \c3/RandomizePasswords\c6 is only available on non-LAN servers only.");
    }
    else
   {
      if(%client.getName() $= "LocalClientConnection" || getNumKeyID() == %client.bl_id)
      {
         $Pref::Server::AdminPassword = getRandomString(%alen);
         $Pref::Server::SuperAdminPassword = getRandomString(%salen);
         for(%i=0;%i<ClientGroup.getCount();%i++)
         {
            %cl = ClientGroup.getObject(%i);
            if(%cl.isAdmin)
            {
               messageClient(%cl,'',"\c6The admin password is now \c2" @ $Pref::Server::AdminPassword @ "\c6.);
            if(%cl.isSuperAdmin)
               {
                  messageClient(%cl,'',"\c6The super admin password is now \c3" @ $Pref::Server::SuperAdminPassword @ "\6.);
               }
            }
         }
      }
   else
   {
        messageClient(%client,"\c6Sorry, but \c3/RandomizePasswords\c6 is host only.");
   }
}



The question is in the code.

Without wax,
Tickle.
« Last Edit: September 21, 2009, 02:43:24 AM by Tickle »

First off, you can't set variables in a package like that. Packages are only meant to contain functions. You have a load of syntax errors in there, that won't even execute.

Secondly, there's a "getRandomString(length);" function in RTB (probably RTBH_Support.cs) which you can look at.

Code: [Select]
$AdminPassword = ""@$char1a@""@$char2a@""@$char3a@""@$char4a@""@$char5a@""
Why are you concatenating empty strings?

Cause I'm making a security add-on that can randomize the server admin and super admin
Wouldn't this be a waste of time anyway. You can just not have a password and manually promote people.

Also, for your host-checking,

To use isHost, you're going to need to put this chunk of code somewhere (i.e. the bottom or top of your script):

Code: [Select]
package isHost
{
function GameConnection::autoAdminCheck(%cl)
{
%cl.isHost = (%cl.isLocalConnection() || %cl.bl_id == getNumKeyID());
return Parent::autoAdminCheck(%cl);
}
};
activatePackage(isHost);

The isHost variable isn't defined by default, so that will check if they own the server when they join, and if so, set their isHost variable to true.

Code: [Select]
$adminPassword = ""@$char1a@""@$char2a@""@$char3a@""@$char4a@""@$char5a@""to
Code: [Select]
$adminPassword = $char1a @ $char2a @ @$char3a @$char4a @ $char5a;
It's not like those variables have any value, either.


Also, for your host-checking,

%cl.bl_id == getNumKeyID() should be enough?



So I herd PHP highlighting looks okay on Torque aside from local vars being different and string comparisons and stuff like that (and probably some more advanced stuff that we'll probably never get into here).
Code: [Select]
<?php // START
function getRandomString(%len)
{
   %
chars "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
   for(%
i=0;%i<%len;%i++)
   {
      %
str = %str getSubStr(%chars,getRandom(0,strlen(%chars)-1),1);
   }
   return %
str;
}
function 
servercmdrandomizepasswords(%client)
{
   
// I suppose this would work? Check if they're local or their ID is the keyed ID.
   
if(%client.getName() $= "LocalClientConnection" || getNumKeyID() == %client.bl_id)
   {
      
// Set admin to 8 and super to 16 characters
      
$Pref::Server::AdminPassword getRandomString(8);
      
$Pref::Server::SuperAdminPassword getRandomString(16);
      
// Message admins/SAs their new passwords
      
for(%i=0;%i<ClientGroup.getCount();%i++)
      {
         %
cl ClientGroup.getObject(%i);
         if(%
cl.isAdmin)
         {
            
messageClient(%cl,'',"\c6The admin password is now \c2" $Pref::Server::AdminPassword);
            if(%
cl.isSuperAdmin)
            {
               
messageClient(%cl,'',"\c6The super admin password is now \c3" $Pref::Server::SuperAdminPassword);
            }
         }
      }
   }
}
// END ?>

Code: [Select]
   // I suppose this would work? Check if they're local or their ID is the keyed ID.
   if(%client.getName() $= "LocalClientConnection" || getNumKeyID() == %client.bl_id)

And if it's a dedicated LAN?

And if it's a dedicated LAN?

I believe mine works fine on dedi LANs as well; not sure why M didn't just use it.

I believe mine works fine on dedi LANs as well; not sure why M didn't just use it.
1. They don't have a BL_ID hooked on
2. They wouldn't be connecting locally

But wait, I thought the ID works no matter what?

Everyone's ID on a LAN server is "LAN" or "999999" or something. Don't forget, people without keys can join LAN servers too...

Everyone's ID on a LAN server is "LAN" or "999999" or something. Don't forget, people without keys can join LAN servers too...
It's 999999, the Player adjusts it to "LAN".
You may have noticed, but IGSO displays "999999"

Also you may have noticed on my ID list "999999 Kalphiter".

I know it's 999999 on Single Player but I wasn't sure about LAN servers.