Page 1 of 1

Login Scripts?

PostPosted: Sat Sep 08, 2012 9:53 pm
by Empire of Narnia
Would I be allowed rules-wise to make a script that would automatically log into my puppet nations to stop them from CTE'ing? If so does anybody have a script I could use or instructions to make one? It would just need to log into the nations within 28 days. I don't need it to answer issues or anything.

PostPosted: Sun Sep 09, 2012 12:22 am
by Improving Wordiness
You could contact Ballotonia as he used to use a log in script (not sure if he still does) Also UDL have a log in script I believe they use so you could make contact with Unibot to ask.
As far as I know it is not illegal to use a script to log in.

PostPosted: Sun Sep 09, 2012 12:55 am
by Ballotonia
Yes, that is legal.

Here's a legal login script, in Perl:
Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "LOGIN: $nation\n";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://www.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
}


Make sure to fill in the stuff at the top: main nation name (needed for the UserAgent, so Admin knows who is running which script.) and of course the names and passwords of your nations.

Note that this script uses a 6 second delay between calls, which is important for it to be legal (don't run more than one script at a time though).

Ballotonia

PostPosted: Sun Nov 11, 2012 5:39 pm
by Letoilenoir
Would it be feasible to replicate this in PHP?

PostPosted: Sun Nov 11, 2012 6:14 pm
by Unibot III
For Ballo's script use no capitals and use underscores for spaces in regards to nation-names.

Also, be warned, if you have handed out a nation to someone that's on that list and the script is run while your friend is borrowing your nation and using it as a WA Nation while you also have a WA Nation.. it appears as multing to the mods. Speaking from experiencing.

PostPosted: Sun Nov 11, 2012 11:56 pm
by Ballotonia
I do not speak php, so someone else will have to translate it into php.

Unibot III wrote:For Ballo's script use no capitals and use underscores for spaces in regards to nation-names.


The above script does not have that as a requirement. The name "Unibot III" should work.

Unibot III wrote:Also, be warned, if you have handed out a nation to someone that's on that list and the script is run while your friend is borrowing your nation and using it as a WA Nation while you also have a WA Nation.. it appears as multing to the mods. Speaking from experiencing.


It doesn't just appear as multying, it IS multying.

Ballotonia

PostPosted: Mon Nov 12, 2012 1:00 am
by Unibot III
Ballotonia wrote:The above script does not have that as a requirement. The name "Unibot III" should work.


Ah okay, upgrades. :)

PostPosted: Mon Nov 12, 2012 5:08 am
by Scoochi2
Letoilenoir wrote:Would it be feasible to replicate this in PHP?

my login script is in pure PHP.
However most servers have a fixed 30 second execution limit.
If you have control, change the value in php.ini to whatever you need (more nations = more time).

If you run PHP locally, you DO have control.

PostPosted: Mon Nov 12, 2012 12:09 pm
by The Blaatschapen
Scoochi2 wrote:
Letoilenoir wrote:Would it be feasible to replicate this in PHP?

my login script is in pure PHP.
However most servers have a fixed 30 second execution limit.
If you have control, change the value in php.ini to whatever you need (more nations = more time).

If you run PHP locally, you DO have control.


You can also use set_time_limit(). This has the benefit that you don't need to tweak php.ini by which other scripts might also be affected.

PostPosted: Mon Nov 12, 2012 3:36 pm
by Scoochi2
The Blaatschapen wrote:
Scoochi2 wrote:my login script is in pure PHP.
However most servers have a fixed 30 second execution limit.
If you have control, change the value in php.ini to whatever you need (more nations = more time).

If you run PHP locally, you DO have control.


You can also use set_time_limit(). This has the benefit that you don't need to tweak php.ini by which other scripts might also be affected.

likewise, you can add the following to .htaccess as follows (for a 60 second timeout):
php_value max_execution_time 60


However, some hosts do limit those methods as well unfortunately :(

PostPosted: Wed Feb 06, 2013 4:50 am
by The Blaatschapen
Ballotonia wrote:Yes, that is legal.

Here's a legal login script, in Perl:
Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "LOGIN: $nation\n";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://www.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
}


Make sure to fill in the stuff at the top: main nation name (needed for the UserAgent, so Admin knows who is running which script.) and of course the names and passwords of your nations.

Note that this script uses a 6 second delay between calls, which is important for it to be legal (don't run more than one script at a time though).

Ballotonia


Sorry for the revival of this thread, but Ballotonia, can I post an edit on this login script that I made, that will notify the user which puppet has a new telegram?

I just tested it with the new TG system :)

PostPosted: Wed Feb 06, 2013 4:55 am
by Svobodny
What do you use to execute these scripts? Does it require third party software to be downloaded? If so, from where? I've been looking into doing this for sometime but don't know where to start - never thought to post here!

PostPosted: Wed Feb 06, 2013 8:13 am
by Ballotonia
The Blaatschapen wrote:Sorry for the revival of this thread, but Ballotonia, can I post an edit on this login script that I made, that will notify the user which puppet has a new telegram?

I just tested it with the new TG system :)


It's ok to post any legal script for others to use as well.

Ballotonia

PostPosted: Wed Feb 06, 2013 8:19 am
by Jamie Anumia
Svobodny wrote:What do you use to execute these scripts? Does it require third party software to be downloaded? If so, from where? I've been looking into doing this for sometime but don't know where to start - never thought to post here!

To run Ballotonia's script you need Perl. Though other users have made login scripts using alternative programs such as PHP too.

PostPosted: Wed Feb 06, 2013 8:21 am
by The Blaatschapen
Ballotonia wrote:
The Blaatschapen wrote:Sorry for the revival of this thread, but Ballotonia, can I post an edit on this login script that I made, that will notify the user which puppet has a new telegram?

I just tested it with the new TG system :)


It's ok to post any legal script for others to use as well.

Ballotonia

Good. Though it was more a question on what permissions I have to modify and redistribute your script.

Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "\nLOGIN: $nation";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://century.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
if (-1 != rindex ($pageContent, "You have <a href=\"page=telegrams\">"))
  {
    print " has telegrams";
  }
}


I added 1 new if clause in the whole thing and rearranged where it does a linebreak. I hope this helps people.

PostPosted: Mon Dec 30, 2019 8:41 pm
by QuietDad of TNP
I've been running this script once a month for years without issue. Recently, after running it, I was warned by the admins that it violates the rules by direct HTML calls and not using the API. Looking at it (I'm a programmer for decades),it uses PERL's POST funtion and logs you on thru the web site and not the API. I see that this does violate terms of service,I just have run it monthly for years (scheduled chron job) without an issue supporting my 650+ puppets.
While I fully see the issues and will use one of the other solutions that do a direct API call, I'm just warning everyone while I ran it forever without issue, it doesn't make it right

PostPosted: Tue Dec 31, 2019 3:02 am
by All Wild Things
QuietDad of TNP wrote:I've been running this script once a month for years without issue. Recently, after running it, I was warned by the admins that it violates the rules by direct HTML calls and not using the API. Looking at it (I'm a programmer for decades),it uses PERL's POST funtion and logs you on thru the web site and not the API. I see that this does violate terms of service,I just have run it monthly for years (scheduled chron job) without an issue supporting my 650+ puppets.
While I fully see the issues and will use one of the other solutions that do a direct API call, I'm just warning everyone while I ran it forever without issue, it doesn't make it right

There's more updated ones included here:
https://www.nationstates.net/page=dispa ... 34239#tech

If you come across others, please let me know!

PostPosted: Tue Dec 31, 2019 5:24 am
by The JELLEAIN Republic
How would use such a script? Where do you, ... put it ?

PostPosted: Tue Dec 31, 2019 3:03 pm
by Cekoviu
The JELLEAIN Republic wrote:How would use such a script? Where do you, ... put it ?

https://www.nationstates.net/pages/api.html#examples
If you write a Perl script, you can put it anywhere and call it using the perl command with the filename as an argument. PHP scripts can be run by installing XAMPP and either opening the script in a browser or (better option for this) directly accessing PHP from the shell. Then to periodically run the script, use cron (on Unix-like systems; no idea how to do it in Windows). You can just Google this - there are simple tutorials for executing scripts in all kinds of languages and for scheduling commands.

PostPosted: Tue Dec 31, 2019 5:31 pm
by [violet]
QuietDad of TNP wrote:I've been running this script once a month for years without issue. Recently, after running it, I was warned by the admins that it violates the rules by direct HTML calls and not using the API.

Actually you were warned for violating the rate limit, because you were making ~30 requests per minute, which is three times more than the rules permit.

I see this script has a delay built-in, but it seems like each request triggers a couple of redirects, which means you're making 3x more requests than you think.

Nowadays it's strongly recommended that people use the API instead, which is faster, more reliable, and avoids all of these kinds of problems, but we don't insist on it.

PostPosted: Tue Dec 31, 2019 11:05 pm
by QuietDad of TNP
Again,rules are rules and I am not "defending" anything. I've just run it since it came out and have never had an issue with it. I am editing the script and incereasing the built in delay from 6 to 60 and we'll see if that helps. The issue have is that due to gameplay I have over 650 puppet nations and some of the other "solutions" require loging on to every puppet at least once and I just dont have the patience

PostPosted: Wed Jan 01, 2020 8:23 am
by Canyamel
One question about the scripts, are these two legal?
viewtopic.php?f=15&t=401352
viewtopic.php?f=12&t=423382&start=58

PostPosted: Wed Jan 01, 2020 5:33 pm
by [violet]
Unfortunately admin doesn't usually have the capacity to read other people's source code and try to figure out what it does. So we can't certify third-party scripts.

As a general rule, you're fine with any script that uses the NationStates API. There's really only one thing you can screw up there: Failing to set an identifying UserAgent. So long as you do that, the worst that can happen is that the API might lock your script out for a brief period if it detects you've gone over the rate limit. You can't accidentally make any illegal requests or break site rules.

A script that interacts with the HTML site instead, however, has to make sure it sticks to the rules all by itself. There's no automatic enforcement of this; instead, there's just an admin like me checking site logs every now and again. And I see a script breaking the rules, your IP address can get banned, which locks you (not just your script) out of the whole site.

Some older scripts (like the one in this thread) were written before the API existed as it does today. There are newer alternatives available that do the same thing only better, because they use the API. The older HTML scripts are still legal, but potentially dangerous, for the reasons mentioned above.

How do i execute this?

PostPosted: Tue Sep 19, 2023 1:18 pm
by Random Card Farmer 6
Ballotonia wrote:Yes, that is legal.

Here's a legal login script, in Perl:
Code: Select all
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

# Enter your MAIN Nation name here:
my $username = "YOURMAINNATIONNAME";

# Enter names and passwords of your nations here:
my @nations = (
  ["nation1", "password1"],
  ["nation2", "password2"],
  ["nation3", "password3"],
);

# ---------------------------------------------------------------------------------------------
# --- Nothing to edit beyond this point ---
my $delayTime = 6; # pause between fetches
my $mech = WWW::Mechanize->new ();
$mech->agent ("Nation:$username ");

foreach my $loginItem (@nations)
{
  my $nation = lc($loginItem->[0]);
  $nation =~ s/ /_/g;
  my $password = $loginItem->[1];
  print "LOGIN: $nation\n";
  my %envelop = ( nation => $nation, password => $password, logging_in => 1);
  while (!defined eval {$mech->post ("http://www.nationstates.net", \%envelop)})
  {
    print "Trying again...\n";
    sleep ($delayTime);
  }
  sleep ($delayTime);
  my $pageContent = $mech->content ();
  utf8::decode ($pageContent);
  if (-1 == rindex ($pageContent, "a href=\"nation=$nation\" class=\"STANDOUT\""))
  {
    print "LOGIN FAILED! Halting run...\n";
    last; # jump out of foreach loop
  }
}


Make sure to fill in the stuff at the top: main nation name (needed for the UserAgent, so Admin knows who is running which script.) and of course the names and passwords of your nations.

Note that this script uses a 6 second delay between calls, which is important for it to be legal (don't run more than one script at a time though).

Ballotonia

PostPosted: Tue Sep 19, 2023 2:14 pm
by Roavin
You shouldn't run that anymore; it's old, slow, based on an outdated method, and likely won't even work anymore.

There are a variety of API-using tools these days that you could use. They are faster, safer, and easier to use. I personally use Auralia's NSLogin (there's a web version here), but there are a number of other tools around as well.