NATION

PASSWORD

Login Scripts?

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Empire of Narnia
Negotiator
 
Posts: 5577
Founded: Oct 18, 2011
Ex-Nation

Login Scripts?

Postby Empire of Narnia » Sat Sep 08, 2012 9:53 pm

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.

User avatar
Improving Wordiness
Diplomat
 
Posts: 638
Founded: Dec 05, 2009
Ex-Nation

Postby Improving Wordiness » Sun Sep 09, 2012 12:22 am

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.
Klaus Devestatorie wrote:I'm a massive tool. ;)

User avatar
Ballotonia
Site Admin
 
Posts: 5416
Founded: Antiquity
Inoffensive Centrist Democracy

Postby Ballotonia » Sun Sep 09, 2012 12:55 am

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
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Sun Nov 11, 2012 5:39 pm

Would it be feasible to replicate this in PHP?
KEEP THE BLOOD CAVE FREE

User avatar
Unibot III
Negotiator
 
Posts: 5800
Founded: Mar 11, 2011
Inoffensive Centrist Democracy

Postby Unibot III » Sun Nov 11, 2012 6:14 pm

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.
[violet] wrote:I mean this in the best possible way,
but Unibot is not a typical NS player.
Milograd wrote:You're a caring, resolute lunatic
with the best of intentions.
Org. Join Date: 25/05/2008 | Former Delegate of The Rejected Realms | Gameplay Alignment: -18 / -13
Unibotian Factbook // An Analysis of NationStates Generations // The Gameplay Alignment Test // NS Weather // How do I join the UDL? // The Transpacific Trade
Paradise Found // The Unibotian Life Expectancy Index // Proudly Authored 9 GA Res., 14 SC Res. // Commended by SC#78 // The Polysemes of Nativeness;

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
✯ Duty is Eternal, Justice is Imminent: UDL

User avatar
Ballotonia
Site Admin
 
Posts: 5416
Founded: Antiquity
Inoffensive Centrist Democracy

Postby Ballotonia » Sun Nov 11, 2012 11:56 pm

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
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Unibot III
Negotiator
 
Posts: 5800
Founded: Mar 11, 2011
Inoffensive Centrist Democracy

Postby Unibot III » Mon Nov 12, 2012 1:00 am

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


Ah okay, upgrades. :)
[violet] wrote:I mean this in the best possible way,
but Unibot is not a typical NS player.
Milograd wrote:You're a caring, resolute lunatic
with the best of intentions.
Org. Join Date: 25/05/2008 | Former Delegate of The Rejected Realms | Gameplay Alignment: -18 / -13
Unibotian Factbook // An Analysis of NationStates Generations // The Gameplay Alignment Test // NS Weather // How do I join the UDL? // The Transpacific Trade
Paradise Found // The Unibotian Life Expectancy Index // Proudly Authored 9 GA Res., 14 SC Res. // Commended by SC#78 // The Polysemes of Nativeness;

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
✯ Duty is Eternal, Justice is Imminent: UDL

User avatar
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Mon Nov 12, 2012 5:08 am

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.
The problem with a UDP joke is that you have no idea if people got it.

User avatar
The Blaatschapen
Retired Moderator
 
Posts: 55239
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Mon Nov 12, 2012 12:09 pm

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.
Forumer mod, now a rocker mocker. Thank you Ringo
Heaven is other people
Behind the invisible hand of the market hides the iron fist of the state.
Whenever you find yourself on the side of the majority, it is time to pause and reflect - Mark Twain
Silent is an anagram of listen.
Male. Please address me as 'he'.
Blaat - all fluff, all action
This is the 8th line. If your sig is longer than mine, it is too long.

User avatar
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Mon Nov 12, 2012 3:36 pm

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 :(
The problem with a UDP joke is that you have no idea if people got it.

User avatar
The Blaatschapen
Retired Moderator
 
Posts: 55239
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Wed Feb 06, 2013 4:50 am

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 :)
Forumer mod, now a rocker mocker. Thank you Ringo
Heaven is other people
Behind the invisible hand of the market hides the iron fist of the state.
Whenever you find yourself on the side of the majority, it is time to pause and reflect - Mark Twain
Silent is an anagram of listen.
Male. Please address me as 'he'.
Blaat - all fluff, all action
This is the 8th line. If your sig is longer than mine, it is too long.

User avatar
Svobodny
Lobbyist
 
Posts: 25
Founded: Aug 08, 2011
Ex-Nation

Postby Svobodny » Wed Feb 06, 2013 4:55 am

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!
Svobodný Republika

User avatar
Ballotonia
Site Admin
 
Posts: 5416
Founded: Antiquity
Inoffensive Centrist Democracy

Postby Ballotonia » Wed Feb 06, 2013 8:13 am

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
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Jamie Anumia
Senator
 
Posts: 3797
Founded: Feb 15, 2012
Liberal Democratic Socialists

Postby Jamie Anumia » Wed Feb 06, 2013 8:19 am

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.
Last edited by Jamie Anumia on Wed Feb 06, 2013 8:20 am, edited 1 time in total.

User avatar
The Blaatschapen
Retired Moderator
 
Posts: 55239
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Wed Feb 06, 2013 8:21 am

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.
Last edited by The Blaatschapen on Thu Feb 26, 2015 1:19 pm, edited 1 time in total.
Reason: Changed 'www' into 'century' to keep it working with the new theme
Forumer mod, now a rocker mocker. Thank you Ringo
Heaven is other people
Behind the invisible hand of the market hides the iron fist of the state.
Whenever you find yourself on the side of the majority, it is time to pause and reflect - Mark Twain
Silent is an anagram of listen.
Male. Please address me as 'he'.
Blaat - all fluff, all action
This is the 8th line. If your sig is longer than mine, it is too long.

User avatar
QuietDad of TNP
Political Columnist
 
Posts: 3
Founded: Feb 14, 2015
Inoffensive Centrist Democracy

Postby QuietDad of TNP » Mon Dec 30, 2019 8:41 pm

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

User avatar
All Wild Things
Spokesperson
 
Posts: 190
Founded: Apr 24, 2017
Civil Rights Lovefest

Postby All Wild Things » Tue Dec 31, 2019 3:02 am

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!

User avatar
The JELLEAIN Republic
Ambassador
 
Posts: 1518
Founded: Jul 15, 2019
Ex-Nation

Postby The JELLEAIN Republic » Tue Dec 31, 2019 5:24 am

How would use such a script? Where do you, ... put it ?
May the autocorrect be with you...
Cannot think of a name wrote:It's a narrative, and narratives don't require masterminds or persian cats.
Male. Lives in USA. Quotes
The Greater Ohio Valley wrote:Same here. I wash my hands religiously to keep the medical debt away.

User avatar
Cekoviu
Post Marshal
 
Posts: 16035
Founded: Oct 18, 2017
Civil Rights Lovefest

Postby Cekoviu » Tue Dec 31, 2019 3:03 pm

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.
RWDT - REST IN POWER
Market socialist, David Hume fangirl, and massive Tuvaboo. Moderate SWERF & traditionalist SJW. Non-denominational Christian, influenced by Orthodoxy and certain Protestant currents.
/tʃɛ'koʊ.vi:.ju:/ (check-OH-vee-you)

User avatar
[violet]
Site Admin
 
Posts: 14540
Founded: Antiquity

Postby [violet] » Tue Dec 31, 2019 5:31 pm

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.

User avatar
QuietDad of TNP
Political Columnist
 
Posts: 3
Founded: Feb 14, 2015
Inoffensive Centrist Democracy

Postby QuietDad of TNP » Tue Dec 31, 2019 11:05 pm

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

User avatar
Canyamel
Bureaucrat
 
Posts: 60
Founded: Oct 31, 2017
Democratic Socialists

Postby Canyamel » Wed Jan 01, 2020 8:23 am

One question about the scripts, are these two legal?
viewtopic.php?f=15&t=401352
viewtopic.php?f=12&t=423382&start=58

User avatar
[violet]
Site Admin
 
Posts: 14540
Founded: Antiquity

Postby [violet] » Wed Jan 01, 2020 5:33 pm

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.


Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Sebero Sree

Advertisement

Remove ads