Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Diego^ on Dec 12, 2015, 10:19 PM

Title: Alias System - IP/SUBNET/UID
Post by: Diego^ on Dec 12, 2015, 10:19 PM
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.
Title: Re: Alias System - IP/SUBNET/UID
Post by: . on Dec 12, 2015, 10:40 PM
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?
Title: Re: Alias System - IP/SUBNET/UID
Post by: Diego^ on Dec 12, 2015, 10:56 PM
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.
Title: Re: Alias System - IP/SUBNET/UID
Post by: DizzasTeR on Dec 13, 2015, 03:07 AM
I guess everyone know is Alias and if someone doesn't I don't know.

Nice work though.
Title: Re: Alias System - IP/SUBNET/UID
Post by: KAKAN on Dec 13, 2015, 05:11 AM
Awesome work mate!

Who doesn't know the meaning of "Alias"?
Title: Re: Alias System - IP/SUBNET/UID
Post by: Thijn on Dec 13, 2015, 01:07 PM
The fact most people know what it does doesn't mean people shouldn't describe their snippet when they decide to post it...
Title: Re: Alias System - IP/SUBNET/UID
Post by: wilber32 on Dec 13, 2015, 02:36 PM
Nice Diego
Title: Re: Alias System - IP/SUBNET/UID
Post by: wilber32 on Dec 13, 2015, 03:28 PM
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 );
   }
}
}

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi62.tinypic.com%2F24vp5p3.jpg&hash=ef6720cb9f766b1cb35664da52790c6c0e8f8858)
Title: Re: Alias System - IP/SUBNET/UID
Post by: KAKAN on Dec 13, 2015, 04:26 PM
Will you ever give credits? That is made by ADM devs.
He meant to get alias by IP UID or subnet.
Title: Re: Alias System - IP/SUBNET/UID
Post by: wilber32 on Dec 13, 2015, 05:29 PM
ah ok KAKAN