Alias System - IP/SUBNET/UID

Started by Diego^, Dec 12, 2015, 10:19 PM

Previous topic - Next topic

Diego^

function onScriptLoad()
{
Alias <- [];
adb <- ConnectSQL( "Alias.db" );
QuerySQL( adb , "CREATE TABLE IF NOT EXISTS Alias ( Name TEXT, IP VARCHAR(20), UID TEXT )" );
LoadAlias();
}

function onScriptUnload()
{
DisconnectSQL( adb );
}

function LoadAlias()
{
local q = QuerySQL( adb, "SELECT * FROM Alias" ), i = 0;
while ( GetSQLColumnData( q, 0 ) != null )
{
Alias.push( { Nick = GetSQLColumnData( q, 0 ), IP = GetSQLColumnData( q, 1 ), UID = GetSQLColumnData( q, 2 ) } );
i ++;
GetSQLNextRow( q );
}
FreeSQLQuery( q );
print( "[Loaded] Alias - " + i );
}

function onPlayerJoin( player )
{
AddAlias( player );
}

function AddAlias( player )
{
local q = QuerySQL( adb,  "SELECT * FROM Alias WHERE Name='" + player.Name + "'" );
if ( !GetSQLColumnData( q, 0 ) )
{
QuerySQL( adb, "INSERT INTO Alias ( Name, IP, UID ) VALUES ( '" + player.Name + "', '" + player.IP + "', '" + player.UniqueID + "' )" );
Alias.push( { Nick = player.Name, IP = player.IP, UID = player.UniqueID } );
}
else
{
if ( GetSQLColumnData( q, 1 ) != player.IP )
{
QuerySQL( adb, "UPDATE Alias SET IP='" + player.IP + "' WHERE Name='" + player.Name + "'" );
UpdateAlias( player, "ip" );
}
if ( GetSQLColumnData( q, 2 ) != player.UniqueID )
{
QuerySQL( adb, "UPDATE Alias SET UID='" + player.UniqueID + "' WHERE Name='" + player.Name + "'" );
UpdateAlias( player, "uid" );
}
}
}

function UpdateAlias( player, option )
{
for ( local i = 0; i < Alias.len(); i++ )
{
if ( Alias[i].Nick == player.Name )
{
if ( option == "ip" ) Alias[i].IP = player.IP;
if ( option == "uid" ) Alias[i].UID = player.UniqueID;
}
}
}

function ShowAlias( player, plr, option )
{
if ( option == "ip" )
{
local i = 0, a = Alias.len(), b;
while( i < a )
{
if ( plr.IP == Alias[i].IP && plr.Name != Alias[i].Nick )
{
if ( b ) b = b + ", " + Alias[i].Nick;
else b = Alias[i].Nick;
}
i ++;
}
if ( !b ) MessagePlayer( plr.Name + " has no IP alias.", player );
else MessagePlayer( plr.Name + "'s IP alias: " + b + ".", player );
}
else if ( option == "subnet" )
{
local i = 0, a = Alias.len(), b;
local getsub_1 = split( player.IP, "." ),
sub_1 = getsub_1[0] + getsub_1[1];
while( i < a )
{
local getsub_2 = split( Alias[i].IP, "." ),
sub_2 = getsub_2[0] + getsub_2[1];
if ( sub_1 == sub_2 && plr.Name != Alias[i].Nick )
{
if ( b ) b = b + ", " + Alias[i].Nick;
else b = Alias[i].Nick;
}
i ++;
}
if ( !b ) MessagePlayer( plr.Name + " has no Subnet alias.", player );
else MessagePlayer( plr.Name + "'s Subnet alias: " + b + ".", player );
}
else if ( option == "uid" )
{
local i = 0, a = Alias.len(), b;
while( i < a )
{
if ( plr.UniqueID == Alias[i].UID && plr.Name != Alias[i].Nick )
{
if ( b ) b = b + ", " + Alias[i].Nick;
else b = Alias[i].Nick;
}
i ++;
}
if ( !b ) MessagePlayer( plr.Name + " has no UID alias.", player );
else MessagePlayer( plr.Name + "'s UID alias: " + b + ".", player );
}
}

function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return false;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return false;
}
}
else return false;
}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "ipalias" )
{
if ( !text ) MessagePlayer( "Syntax: /" + cmd + " <Nick/ID>", player );
else
{
local plr = GetPlayer( text );
if ( !plr ) MessagePlayer( "Unknown Player.", player );
else ShowAlias( player, plr, "ip" );
}
}

else if ( cmd == "subnetalias" )
{
if ( !text ) MessagePlayer( "Syntax: /" + cmd + " <Nick/ID>", player );
else
{
local plr = GetPlayer( text );
if ( !plr ) MessagePlayer( "Unknown Player.", player );
else ShowAlias( player, plr, "subnet" );
}
}

else if ( cmd == "uidalias" )
{
if ( !text ) MessagePlayer( "Syntax: /"+ cmd + " <Nick/ID>", player );
else
{
local plr = GetPlayer( text );
if ( !plr ) MessagePlayer( "Unknown Player.", player );
else ShowAlias( player, plr, "uid" );
}
}
}

Commands: (/)ipalias, subnetalias, uidalias.
BRL's Developer.

.

A bit more information if possible? FFS where have you seen anyone simply posting a piece of code without any kind of information. No wonder people can't find sh!t on this forum. You ran out of imagination describing it? Or you have no idea what you coded?
.

Diego^

#2
Quote from: S.L.C on Dec 12, 2015, 10:40 PMA bit more information if possible? FFS where have you seen anyone simply posting a piece of code without any kind of information. No wonder people can't find sh!t on this forum. You ran out of imagination describing it? Or you have no idea what you coded?

The commands are intended for server administrators to check players using other nicks with the intention of benefiting in some way. If I did not let description is because my English is bad. And also I think that a good portion of people who attending this forum, know what this script does.
BRL's Developer.

DizzasTeR

I guess everyone know is Alias and if someone doesn't I don't know.

Nice work though.

KAKAN

Awesome work mate!

Who doesn't know the meaning of "Alias"?
oh no

Thijn

The fact most people know what it does doesn't mean people shouldn't describe their snippet when they decide to post it...

wilber32


wilber32

#7
I have one simpler


Function Tables ();
{
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Alias ( IP TEXT, Nicks TEXT )" );
}

function onPlayerJoin( player )
{
AddAlias( player );
}

function AddAlias( player )
{
   local a, subnet, q, data, newdata, found = false, i = 1;
   a=split(player.IP,".");
   subnet=a[0]+"."+a[1];
   q = QuerySQL( db, "SELECT Nicks FROM Alias WHERE IP='" + subnet + "'" );
   data = GetSQLColumnData( q, 0 );
   if ( !data ) QuerySQL( db, "INSERT INTO Alias VALUES('" + subnet + "', '" + player.Name + "')" );
   else{
          while ( GetTok( data, " - ", i ) )
          {
            if ( GetTok( data, " - ", i ) == player.Name ) found = true; break;
            i++;
          }
      newdata = data +" - "+ player.Name;
          if ( !found ) QuerySQL( db, "UPDATE Alias SET Nicks='" + newdata + "' WHERE IP='" + subnet + "'" );
    }
FreeSQLQuery( q );
}

function GetAlias( IP )
{
    local a, subnet, q, data;
    a=split(IP,".");
    subnet=a[0]+"."+a[1];
q = QuerySQL( db, "SELECT Nicks FROM Alias WHERE IP='" + subnet + "'" );
    data = GetSQLColumnData( q, 0 );
if ( data ) return data;
else return "None";
}

function onPlayerCommand( player, cmd, text )
{
else if ( cmd == "alias" )
{
   if ( stats[ player.ID ].Level < 3 ) MessagePlayer( "Error - You don't have access to it.", player);
   else if ( !text ) MessagePlayer( "Syntax: /alias <player>", player);
   else
   {
     local plr = GetPlayer( GetTok( text, " ", 1 ) );
     if ( !plr ) MessagePlayer( "Error - Unknown player.", player);
     else MessagePlayer( "" + plr.Name + "(" + plr.IP + ")'s aliases: " + GetAlias( plr.IP ) + ".", player );
   }
}

else if ( cmd == "salias" )
{
   if ( stats[ player.ID ].Level < 3 ) MessagePlayer( "Error - You don't have access to it.", player);
   else if ( !text ) MessagePlayer( "Syntax: /salias <subnet>", player);
   else
   {
     local ip = split(text, "."), length = NumTok(text, ".").tointeger();
if (  length < 2 ) PrivMessage( player, "Invalid IP" );
     else if (!IsNum( ip[0] )) MessagePlayer( "Error - Unknown IP.", player);
else if (!IsNum( ip[1] )) MessagePlayer( "Error - Unknown IP.", player);
     else MessagePlayer( "Subnet(" + text + ")'s aliases: " + GetAlias( text ) + ".", player );
   }
}
}


KAKAN

Will you ever give credits? That is made by ADM devs.
He meant to get alias by IP UID or subnet.
oh no

wilber32