Advertisement
by Wolfram and Hart » Tue Nov 14, 2017 3:25 pm
by Wolfram and Hart » Tue Nov 14, 2017 3:26 pm
by Attorney Urquhart » Wed Nov 15, 2017 3:00 pm
Wolfram and Hart wrote:I spotted this thread, and as I'd been thinking of starting a Constitution Clinic, it seemed an ideal candidate for hijacking.
Link to The Keenland Powers constitution
The purpose is to look for contradictions, and any clauses that are unclear or redundant. Comments should address these issues only. Comments should not try to change the spirit of the original document.
I'll let the rest of the Wolfram and Hart legal team know, and we'll add commentary as we find the time.
by Wolfram and Hart » Wed Nov 15, 2017 3:07 pm
by Chricoma » Wed Nov 22, 2017 5:33 pm
by Attorney Urquhart » Fri Nov 24, 2017 11:12 am
Chricoma wrote:https://www.nationstates.net/page=dispatch/id=906163
The Constitution of the OEU, to be reviewed
We already approved it and it is law now but some insight would be nice
by Attorney Urquhart » Fri Nov 24, 2017 11:12 pm
Chricoma wrote:https://www.nationstates.net/page=dispatch/id=906163
The Constitution of the OEU, to be reviewed
We already approved it and it is law now but some insight would be nice
by Pergamon » Sat Nov 25, 2017 6:25 am
by Chricoma » Sat Nov 25, 2017 1:23 pm
Attorney Urquhart wrote:Chricoma wrote:https://www.nationstates.net/page=dispatch/id=906163
The Constitution of the OEU, to be reviewed
We already approved it and it is law now but some insight would be nice
The Constitution of the United Nations
of the Official European Union
Table of Articles
1. Bill of rights
2. OEU Regional Government
3. OEU Political Parties
4. OEU Parliament
5. OEU Government Officials
6. OEU criminal procedures
1. Bill of Rights
1. All nations are entitled to immediate citizenship*
2. All nations are entitled to rp freely within reason
3. All nations are free to run there nation as they please
4. All nations may join political partys and run in elections
5. All nations have a right to free speech within reason
6. All nations have a right to a fair trial
7. All nations have a right to sue other nations
8. All nations have the right to give their ideas on how the government should be run. If a nation has an idea for a new law, they can bring their request to their delegate who will bring it up at the next Parliamentary meeting.
*If previously banned from the OEU you must register for citizenship with the Minister of Defense
ANALYSIS OF BILL OF RIGHTS:
The * put by 1. about being previously banned needs clarification. If someone is banned how could they be allowed back into a Region? Keep in mind when you banject someone they are also listed on the Admin page and can't reenter a Region. This will need to be addressed I think. Also please check look at the inconsistencies this may have with your Penal/Legal/Sentencing codes.
On point 4 and all other point when you say "all nation's" do nation's require Citizenship to do something like for example run for an election? This needs stated I think.
Point 8 is a little confusing and is somewhat contrary to the rest of the document. I don't know that simply proposing legislation through a Delegate should be put into a Bill of Rights.
2. OEU Regional Government
-Consists of many different political parties
-Consists of a Parliament. The OEU Parliament consists of two houses. The house of Delegates and the Senate
-Consists of five Regional officers, four of which are voted for
-Consists of a Supreme Court ran by a Head Justice
3. OEU Political Parties
-All Nations may join a political party if they meet the parties requirements
-All Nations may form their own party
-Parties are eligible to be represented in Parliament if they have at least two members
-By joining a party, you are eligible to run in elections or attend the OEU parliament.
-The leader of a party with the most members becomes the Prime Minister
-Parties may be ran at the leaders own discretion
-It is the Parties job to choose their Delegates and Senators
4. OEU Parliament
-The Parliament is made up of the House of Delegates and the Senate
The House of Delegates
The House of Delegates will be made up of delegates from each party. For every three people in a party there will be one appointed delegate in the house for that party. The delegates in the parliament will make the bills that the nations of the OEU bring up. The Chancellor of the OEU will act as the head of the House of Delegates and is responsible for holding meetings where the law making process will take place. At one such meeting, if a bill is successfully aggreed upon by majority rule ,then the bill must be passed by the Senate.
The Senate
The Senate will consist of two members from each party. The Senates job is to anylize any bill passed by the House of Delegates. Once the house passes a bill to the Senate, the Senate has the ability to officially make the bill a law with a majority vote. If the bill is approved by the Senate, then the Prime Minister can make it an official law. The Prime Minister will act as head of the Senate and is responsible for holding frequent meetings.
ANALYSIS OF OEU PARLIAMENT:
I can't really find anything wrong with this section. You did misspell "analyize" under to the Senate section.
5. OEU Regional Officers
-The OEU Regional Officers are made up of 5 different officials each having there own responsibility.
-Any and all of these officers can be impeached if there is failure in preforming there duties. Impeachment may be brought up by any nation to the Founder or Chancellor who will bring the accusations to the Senate. The Senate will be responsible for holding a vote where if 2/3 vote impeachment, the officer will be relieved of his or her duties.
Founder
-Founder of the OEU
-Has executive Authority
-The ONLY nation who may hold two officer positions. (Both being Founder and a different officer position)
-May NOT abuse the Executive power
Prime Minister
-The leader of the Senate and is responsible for holding frequent meetings
-Has authority to appoint Chancellor
-The Prime Minister is appointed by the party with the most members
-The Prime Minister has power to appoint temporary Officers
-The Prime Minister has veto power
-The Prime Minister has the power to quickly and effectively eject nations that are known threats to the region or other nations
-The Prime Minister has the power to declare war
-The Prime Minister is allowed to create quick and effective legislation within reason in times of national emergency
-The Prime Minister has the power to declare a National Emergency.
-Controls Border control, communications, polls, appearance, and embassies.
ANALYSIS OF PRIME MINISTER:
When you say that the Prime Minister may appointment Temporary Officers, what is a Temporary Officer? Are they simply meant to fill a vacancy or meant for a temporary agency?
Also on the point of "quick and effective legislation" do you mean he can create law entirely with out the legislative branch?
That's something a court would have trouble with I think.
Chancellor
-Appointed by the Prime Minister
-Leader of the House of Delegates and is responsible for holding frequent meetings.
-Is next in command and has the authority to carry out the Prime Ministers jobs if the Prime Minister is unable to do so
-Can carry out quick and efficient ejections of nations that are known threats to the region or other nations
-Has the power to give awards and honorary ceremonies to nations that have preformed a good deed to the region.
-Controls Border control, communications, polls, appearance and embassies
Minister of Defense
-The Minister of Defense is responsible to moniter potential threats to the region
-The Minister of Defense has the power to eject a nation known to be a threat quickly and efficiently.
-Elected every month*
-Can declare war if the circumstances call for quick and immediate action
-Controls Border Control, Communications, embassies
ANALYSIS OF DEFENSE:
Misspelled "monitor". Also what is meant by monitor? Is there an intelligence agency involved or just monitoring in general?
WA Delegate
-The WA delegate is responsible for representing the OEU in the world assembly
-The WA delegate is responsible for administering foreign embassies.
-The WA delegate is the ambassador to the OEU and therefore must be active in International affairs
-Controls WA power and embassies
-Elected through endorsements
ANALYSIS OF WA Delegate:
Under 1. You say "representing" but a lot of Regions have a voting law or some other requirement for the Delegate. Perhaps this should be given more detail and procedure.
Head Justice
-In charge of the Supreme court
-May call forth new amendments to the Constitution
-May rule any laws unconstitutional and therefore making the law non-existant. (Parliament may overturn the unconstitutional ruling with 2/3 vote from each house
-The Head judge when dealing with criminal cases and lawsuits
-Voted into position every month and a half
ANALYSIS OF HEAD JUSTICE:
In my opinion you should leave amendments to the legislative branch. It's better to keep a judge out of direct politics for a more impartial judicial system.
The OEU Government
-Executive: Carrys out laws, can veto laws. Prime Minister
-Parliament: Makes the laws. Senate and House of Delegates
-Supreme court: Interprets the laws. Head Justice
6. Criminal procedures
-Unless somone is found an immediate threat they CANNOT be ejected or banned without a fair trial
-If they do not oblige to the trial within 24 hours then they may be ejected without trial
-The trial will be judged by the head Justice
-In a trial, the prosecutor (which may be a government officer) must state his claim. Your are INNOCENT untill proven guilty
-If found innocent you will be freed without question
-If found guilty, the Head Justice will apply punishment which may result in expulsion
ANALYSIS OF CRIMINAL PROCEDURE:
The second point about not obliging needs fixed. If you mean not obliging in the sense that the Defendant won't enter a Guilty or Not Guilty plea then there is a procedure called Standing Mute. The Court enters this plea on behalf of the Defendant if they refuse to plea. It has the effect of a Not Guilty plea and the case automatically goes to trial.
Also I noticed there is no stated burden of proof for the prosecutor. It should be beyond a reasonable doubt.
Finally, under the point on applying punishment I think there should be some sort of sentencing code or guide line giving the judge a minimum and maximum sentencing range. Otherwise the judge has to much push and pull which may violate impartiality.
------------------------------------------------------------------------------
Please note that this is only my independent analysis of your query and does not represent all of the possible differing legal opinions of the law firm.
-James Urquhart, Esquire
by Wolfram and Hart » Mon Nov 27, 2017 12:02 am
by Chricoma » Mon Nov 27, 2017 5:28 pm
Wolfram and Hart wrote:The Constitution of the OEU
[center]The Constitution of the United Nations
of the Official European Union[/center]Table of Articles
1. Bill of rights
2. OEU Regional Government
3. OEU Political Parties
4. OEU Parliament
5. OEU Government Officials
6. OEU criminal procedures
1. Bill of Rights
1. All nations are entitled to immediate citizenship*
2. All nations are entitled to rp freely within reason
WH: How will “within reason” be defined / judged?
3. All nations are free to run there nation as they please
4. All nations may join political partys and run in elections
5. All nations have a right to free speech within reason
WH: How will “within reason” be defined / judged?
6. All nations have a right to a fair trial
7. All nations have a right to sue other nations
8. All nations have the right to give their ideas on how the government should be run. If a nation has an idea for a new law, they can bring their request to their delegate who will bring it up at the next Parliamentary meeting.
*If previously banned from the OEU you must register for citizenship with the Minister of Defense
2. OEU Regional Government
-Consists of many different political parties
WH: I don't think it's necessary to mention political parties in this section.
-Consists of a Parliament. The OEU Parliament consists of two houses. The house of Delegates and the Senate
-Consists of five Regional officers, four of which are voted for
WH: I'm not convinced. The Founder is permanent. The Prime Minister isn’t really elected - they're an appointment of the largest party. The Chancellor isn't elected, they're chosen by the Prime Minister. The WA delegate is elected via endorsements, meaning that a raider can easily take this position.
-Consists of a Supreme Court ran by a Head Justice
WH: I think I would have found this constitution easier to understand if it was in a different order. To me, section 5 belongs before 4,belongs before 3.
3. OEU Political Parties
-All Nations may join a political party if they meet the parties requirements
WH: party’s.
-All Nations may form their own party
-Parties are eligible to be represented in Parliament if they have at least two members
-By joining a party, you are eligible to run in elections or attend the OEU parliament.
WH: ... provided there are at least two members?
-The leader of a party with the most members becomes the Prime Minister
WH: And if there is a tie?
-Parties may be ran at the leaders own discretion
-It is the Parties job to choose their Delegates and Senators
4. OEU Parliament
-The Parliament is made up of the House of Delegates and the Senate
The House of Delegates
The House of Delegates will be made up of delegates from each party. For every three people in a party there will be one appointed delegate in the house for that party.
WH: So with only two party members, you don't get a delgate?
The delegates in the parliament will make the bills that the nations of the OEU bring up. The Chancellor of the OEU will act as the head of the House of Delegates and is responsible for holding meetings where the law making process will take place. At one such meeting, if a bill is successfully aggreed upon by majority rule ,then the bill must be passed by the Senate.
WH: "must be passed”. So if there's a majority in the Delegates, then it doesn't need to be approved by the Senate.
The Senate
The Senate will consist of two members from each party.
WH: So with only two party members, you don't get a delgate, as both will be senators.
The Senates job is to anylize any bill passed by the House of Delegates. Once the house passes a bill to the Senate, the Senate has the ability to officially make the bill a law with a majority vote.
WH: ...unless it already got a majority vote by the delegates.
If the bill is approved by the Senate, then the Prime Minister can make it an official law. The Prime Minister will act as head of the Senate and is responsible for holding frequent meetings.
WH: How frequent?
5. OEU Regional Officers
-The OEU Regional Officers are made up of 5 different officials each having there own responsibility.
-Any and all of these officers can be impeached if there is failure in preforming there duties. Impeachment may be brought up by any nation to the Founder or Chancellor who will bring the accusations to the Senate. The Senate will be responsible for holding a vote where if 2/3 vote impeachment, the officer will be relieved of his or her duties.
WH: their duties
Founder
-Founder of the OEU
-Has executive Authority
-The ONLY nation who may hold two officer positions. (Both being Founder and a different officer position)
-May NOT abuse the Executive power
Prime Minister
-The leader of the Senate and is responsible for holding frequent meetings
-Has authority to appoint Chancellor
-The Prime Minister is appointed by the party with the most members
-The Prime Minister has power to appoint temporary Officers
WH: How will that work in practice?
-The Prime Minister has veto power
-The Prime Minister has the power to quickly and effectively eject nations that are known threats to the region or other nations
-The Prime Minister has the power to declare war
-The Prime Minister is allowed to create quick and effective legislation within reason in times of national emergency
-The Prime Minister has the power to declare a National Emergency.
-Controls Border control, communications, polls, appearance, and embassies.
WH: I think it would be helpful to put this list of powers close to the top of the job description
Chancellor
-Appointed by the Prime Minister
-Leader of the House of Delegates and is responsible for holding frequent meetings.
-Is next in command and has the authority to carry out the Prime Ministers jobs if the Prime Minister is unable to do so
-Can carry out quick and efficient ejections of nations that are known threats to the region or other nations
-Has the power to give awards and honorary ceremonies to nations that have preformed a good deed to the region.
-Controls Border control, communications, polls, appearance and embassies
Minister of Defense
-The Minister of Defense is responsible to moniter potential threats to the region
-The Minister of Defense has the power to eject a nation known to be a threat quickly and efficiently.
-Elected every month*
WH: What is the process for elections?
-Can declare war if the circumstances call for quick and immediate action
-Controls Border Control, Communications, embassies
WA Delegate
-The WA delegate is responsible for representing the OEU in the world assembly
-The WA delegate is responsible for administering foreign embassies.
-The WA delegate is the ambassador to the OEU and therefore must be active in International affairs
WH: for the OEU
-Controls WA power and embassies
WH: Careful how this is enacted. In theory, raiders could close embassies
-Elected through endorsements
Head Justice
-In charge of the Supreme court
-May call forth new amendments to the Constitution
WH: Do these amendments need approval by anyone?
-May rule any laws unconstitutional and therefore making the law non-existant. (Parliament may overturn the unconstitutional ruling with 2/3 vote from each house
WH: Are they required to say why they believe a law is unconstitutional?
-The Head judge when dealing with criminal cases and lawsuits
-Voted into position every month and a half
WH: What is the process for elections?
The OEU Government
-Executive: Carrys out laws, can veto laws. Prime Minister
-Parliament: Makes the laws. Senate and House of Delegates
-Supreme court: Interprets the laws. Head Justice
6. Criminal procedures
-Unless somone is found an immediate threat they CANNOT be ejected or banned without a fair trial
-If they do not oblige to the trial within 24 hours then they may be ejected without trial
-The trial will be judged by the head Justice
-In a trial, the prosecutor (which may be a government officer) must state his claim. Your are INNOCENT untill proven guilty
WH: “may be” or “must be”?
-If found innocent you will be freed without question
WH: Maybe use “not guilty”. The previous clause assumes innocence
-If found guilty, the Head Justice will apply punishment which may result in expulsion
by Wolfram and Hart » Tue Nov 28, 2017 2:03 pm
Pergamon wrote:Really, this is an amazing idea. However, I doubt we will be interacting at all.
by Wolfram and Hart » Tue Dec 05, 2017 1:47 pm
<!DOCTYPE html>
<!-- Wolfram & Hart Puppet Login Script v1.0
Version | Date | Name | Comment
1.0 | 04 Dec 2017 | Wolfram & Hart | Created
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
Don't use this code to log in more than 25 puppets in 30 seconds.
(That would break NationStates API rules, as at the time of writing).
-->
<head>
<!-- Set the title, visible in the browser tab -->
<title>W&H Puppet Login</title>
<!-- Set the colour scheme and format for the page -->
<style>
body {background-color: black;}
div {
text-align:center;
color: white;
font-family: times;
}
</style>
</head>
<body>
<div>
<!-- Display headers. Use <span> tags to format the "W", "&", and "H" in "Wolfram & Hart". -->
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Puppet Login</h3>
<!-- Add a blank line -->
<br>
<!-- Add a button. When clicked, this will run the JavaScript code -->
<button type="button" onclick="fLoginAll()">Login</button>
<!-- Add an empty paragraph, ready to display results -->
<p id="result"></p>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com"
/* ************************************************************************************* */
/* Tell NS the format of the password. This code uses the unencrypted text password.
(The one you type into the NationStates website). NS allows you to use an encrypted
password instead. See this page for more details:
https://www.nationstates.net/pages/api.html#nationapi-privateshards
*/
var strPasswordType = "X-Password"
/* Set a variable to record the nations processed. This will update the html paragraph */
var strMessage = "";
/* ************CHANGE THIS TO INCLUDE UP TO 25 OF YOUR NATIONS AND PASSWORDS*********** */
/* This function calls the fLogin function (below) for each nation / password pair.
You can have up to 25 nations here without breaking NS API rules */
function fLoginAll() {
fLogin("Nation 1", "Password1")
fLogin("Nation 2", "Password2")
fLogin("Nation 3", "Password3")
fLogin("Nation 4", "Password4")
}
/* ************************************************************************************* */
/* This function uses AJAX to 'ping' (login) each nation, and records if the ping worked. */
function fLogin(strNation, strPassword) {
/* Create an object to send the login details to NS */
var xhttp = new XMLHttpRequest();
/* Set the object to update the html paragraph when it gets a response from NS */
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
strMessage = strMessage+"<br>" + strNation + ": " + xhttp.status;
if (xhttp.status == 200) {
strMessage = strMessage + ": OK";
} else if (xhttp.status == 403) {
strMessage = strMessage + ": Forbidden (incorrect password?)";
} else if (xhttp.status == 404) {
strMessage = strMessage + ": Not Found (nation doesn't exist?)";
} else if (xhttp.status == 429) {
strMessage = strMessage + ": Exceeding Rate Limit (max 25 nations every 30 seconds)";
}
document.getElementById("result").innerHTML = strMessage;
}
};
/* Tell the object which nation URL to log in to.
Replace any space characters in the nation name (" ") with underlines ("_")
Tell it the password.
Tell it your contact details.
Send the request to NS.
*/
xhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation="+strNation.replace(" ", "_")+"&q=ping", true);
xhttp.setRequestHeader(strPasswordType, strPassword)
xhttp.setRequestHeader("User-Agent", strUserAgent)
xhttp.send();
}
</script>
</body>
</html>
<!DOCTYPE html>
<!-- Wolfram & Hart Puppet Login Script v1.2
Version | Date | Name | Comment
1.0 | 04 Dec 2017 | Wolfram & Hart | Created
1.2 | 16 Dec 2017 | Wolfram & Hart | Changes following Roavin's advice:
| | | Put nation / password pairs into an array.
| | | Included 'setTimeout()' in fLogin function
| | | to leave suitable gap between logins.
| | | Other minor changes.
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
-->
<head>
<!-- Set the title, visible in the browser tab -->
<title>W&H Puppet Login</title>
<!-- Set the colour scheme and format for the page -->
<style>
body {background-color: black;}
div {
text-align:center;
color: white;
font-family: times;
}
</style>
</head>
<body>
<div>
<!-- Display headers. Use <span> tags to format the "W", "&", and "H" in "Wolfram & Hart". -->
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Puppet Login</h3>
<!-- Add a blank line -->
<br>
<!-- Add a button. When clicked, this will run the JavaScript function, "fMain" -->
<button type="button" onclick="fMain()">Login</button>
<!-- Add an empty paragraph, ready to display results -->
<p id="result"></p>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com";
/* ************************************************************************************* */
/* ***************CHANGE THIS ARRAY TO INCLUDE YOUR NATIONS AND PASSWORDS*************** */
var aobjNations = [
{nation:"Nation 1", password:"Password1"},
{nation:"Nation 2", password:"Password2"},
{nation:"Nation 3", password:"Password3"},
{nation:"Last Nation", password:"LastPassword"}
];
/* ************************************************************************************* */
/* Tell NS the format of the password. This code uses the unencrypted text password.
(The one you type into the NationStates website). NS allows you to use an encrypted
password instead. See this page for more details:
https://www.nationstates.net/pages/api.html#nationapi-privateshards
*/
var strPasswordType = "X-Password";
/* Set a variable to record the nations processed. This will update the html paragraph. */
var strMessage = "";
/* The fMain function resets the 'results' paragraph to being blank.
It then tells the code to login the first nation in the list (position 0)
*/
function fMain() {
strMessage = "";
document.getElementById("result").innerHTML = "";
fLogin(0);
}
/* The fLogin function uses AJAX to 'ping' (login) each nation, and records if the ping worked.
intNation is a number indicating which nation in the array is being processed.
A value of 0 indicates the first nation in the array.
*/
function fLogin(intNation) {
/* If there are still nations to be processed, then process them */
if (intNation < aobjNations.length) {
/* get the nation name & password from the list */
var strNation = aobjNations[intNation].nation;
var strPassword = aobjNations[intNation].password;
/* Create an object to send the login details to NS */
var objXhttp = new XMLHttpRequest();
/* Set the object to update the html paragraph when it gets a response from NS
When a response is received, update the paragraph. Then wait 1200ms (1.2 seconds)
before logging in the next nation. That allows up to 25 nations to be logged in
in 30 seconds.
*/
objXhttp.onreadystatechange = function() {
if (objXhttp.readyState == 4) {
if (objXhttp.status == 200) {
strMessage = strMessage + "<br>" + strNation + ": OK";
setTimeout(function(){ fLogin(intNation + 1) }, 1200);
} else if (objXhttp.status == 403) {
strMessage = strNation + ": Forbidden (incorrect password?)<br>" + strMessage;
setTimeout(function(){ fLogin(intNation + 1) }, 1200);
} else if (objXhttp.status == 404) {
strMessage = strNation + ": Not Found (nation CTEd / misspelled / doesn't exist?)<br>" + strMessage;
setTimeout(function(){ fLogin(intNation + 1) }, 1200);
} else if (objXhttp.status == 429) {
strMessage = strNation + ": Too Many Requests. Processing stopped<br>" + strMessage;
} else {
strMessage = strNation + ": Error " + objXhttp.status + "<br>" + strMessage;
setTimeout(function(){ fLogin(intNation + 1) }, 1200);
}
document.getElementById("result").innerHTML = strMessage;
}
};
/* Tell the object which nation URL to log in to.
Replace any space characters in the nation name (" ") with underlines ("_")
Tell it the password.
Tell it your contact details.
Send the request to NS.
*/
objXhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation="+strNation.replace(" ", "_")+"&q=ping", true);
objXhttp.setRequestHeader(strPasswordType, strPassword)
objXhttp.setRequestHeader("User-Agent", strUserAgent)
objXhttp.send();
} else {
strMessage = "Processing Complete<br>" + strMessage;
document.getElementById("result").innerHTML = strMessage;
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<!-- Wolfram & Hart PuppetMaster v1.4
Version | Date | Name | Comment
1.0 | 04 Dec 2017 | Wolfram & Hart | Created
1.2 | 16 Dec 2017 | Wolfram & Hart | Changes following Roavin's advice:
| | | Put nation / password pairs into an array.
| | | Included 'setTimeout()' in fGetXml function
| | | to leave suitable gap between logins.
| | | Other minor changes.
1.4 | 12 Feb 2018 | Wolfram & Hart | NS query now returns the WA status, region, and number of unread issues, TGs etc
| | | Output is now to a table instead of paragraph.
| | | WA nation is listed first, followed by nations in the Rejected Realms
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
-->
<head>
<title>W&H PuppetMaster</title>
<style>
body {background-color: black;}
div {
text-align: center;
color: white;
font-family: times;
}
table,th,td {
border : 1px solid white;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<div>
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>PuppetMaster</h3>
<br>
<button type="button" onclick="fMain()">View Puppets</button>
<p id="err"></p>
<table id="msg" align=center></table>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com";
/* ************************************************************************************* */
/* ***************CHANGE THIS ARRAY TO INCLUDE YOUR NATIONS AND PASSWORDS*************** */
var aobjNtns = [
{nation:"Nation 1", password:"Password1"},
{nation:"Nation 2", password:"Password2"},
{nation:"Nation 3", password:"Password3"},
{nation:"Last Nation", password:"LastPassword"}
];
/* ************************************************************************************* */
/* Tell NS the format of the password. This code uses the unencrypted text password.
(The one you type into the NationStates website). NS allows you to use an encrypted
password instead. See this page for more details:
https://www.nationstates.net/pages/api.html#nationapi-privateshards
*/
var strPasswordType = "X-Password";
/* Set variables to record the nations processed. This will update the html. */
var strErr;
var strWA;
var strTRR;
var strMsg;
var strHdr = "<tr><th>Nation</th><th>Region</th><th>Notices</th><th>Telegrams</th><th>RMB</th><th>Issues</th></tr>";
var intNtn = 0;
/* The fMain function resets the 'msg' table to being blank.
It then tells the code to login the first nation in the list.
*/
function fMain() {
strErr = "";
strWA = "";
strTRR = "";
strMsg = "";
document.getElementById("err").innerHTML = strErr;
document.getElementById("msg").innerHTML = strMsg;
fGetXml();
}
/* fGetXml checks if there is another nation to be processed, then requests the XML from NS */
function fGetXml() {
if (intNtn < aobjNtns.length) {
var strNtn = aobjNtns[intNtn].nation.replace(" ", "_"); // get the nation name & password from the list
var strPassword = aobjNtns[intNtn].password;
intNtn = intNtn + 1;
var objXhttp = new XMLHttpRequest(); // Create an object to send the details to NS
objXhttp.onreadystatechange = function() {
if (objXhttp.readyState == 2) {
setTimeout(function(){ fGetXml() }, 1200); // readyState == 2 means the request was received. Set the timer to send the next request.
} else if (objXhttp.readyState == 4) {
if (objXhttp.status == 200) {
fProcessXml(this);
} else {
if (objXhttp.status == 403) {
strErr = strNtn + ": Forbidden (incorrect password?)<br>" + strErr;
} else if (objXhttp.status == 404) {
strErr = strNtn + ": Not Found (nation CTEd / misspelled / doesn't exist?)<br>" + strErr;
} else if (objXhttp.status == 429) {
strErr = strNtn + ": Too Many Requests. Processing stopped<br>" + strErr;
} else {
strErr = strNtn + ": Error " + objXhttp.status + "<br>" + strErr;
};
document.getElementById("err").innerHTML = strErr;
};
};
};
objXhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation=" + strNtn + "&q=wa+name+region+unread", true);
objXhttp.setRequestHeader(strPasswordType, strPassword);
objXhttp.setRequestHeader("User-Agent", strUserAgent);
objXhttp.send();
};
}
/* fProcess reads in the XML data. It puts any WA nation to the top of the output,
followed by any nations in the Rejected Realms, followed by all other nations.
*/
function fProcessXml(objXhttp) {
var objXML = objXhttp.responseXML;
var strNtn = objXML.getElementsByTagName("NAME")[0].childNodes[0].nodeValue;
var strRgn = objXML.getElementsByTagName("REGION")[0].childNodes[0].nodeValue;
var strNtc = objXML.getElementsByTagName("NOTICES")[0].childNodes[0].nodeValue;
if (strNtc == "0") { strNtc = ""; };
var strTGs = objXML.getElementsByTagName("TELEGRAMS")[0].childNodes[0].nodeValue;
if (strTGs == "0") { strTGs = ""; };
var strRMB = objXML.getElementsByTagName("RMB")[0].childNodes[0].nodeValue;
if (strRMB == "0") { strRMB = ""; };
var strIss = objXML.getElementsByTagName("ISSUES")[0].childNodes[0].nodeValue;
if (strIss == "0") { strIss = ""; };
var strTmp = strRgn + "</th><th>" + strNtc +
"</th><th>" + strTGs + "</th><th>" + strRMB + "</th><th>" + strIss + "</th></tr>"
if (objXML.getElementsByTagName("UNSTATUS")[0].childNodes[0].nodeValue != "Non-member") {
strWA = strWA + "<tr style='color:red;'><th>WA Member: " + strNtn + "</th><th>" + strTmp;
} else if (strRgn == "the Rejected Realms") {
strTRR = strTRR + "<tr><th>" + strNtn + "</th><th style='color:red;'>" + strTmp;
} else {
strMsg = strMsg + "<tr><th>" + strNtn + "</th><th>" + strTmp;
};
document.getElementById("msg").innerHTML = strHdr + strWA + strTRR + strMsg;
}
</script>
</body>
</html>
<!DOCTYPE html>
<!-- Wolfram & Hart PuppetMaster v1.6
Version | Date | Name | Comment
1.0 | 04 Dec 2017 | Wolfram & Hart | Created
1.2 | 16 Dec 2017 | Wolfram & Hart | Changes following Roavin's advice:
| | | Put nation / password pairs into an array.
| | | Included 'setTimeout()' in fGetXml function to leave suitable gap between logins.
| | | Other minor changes.
1.4 | 12 Feb 2018 | Wolfram & Hart | NS query now returns the WA status, region, and number of unread issues, TGs etc
| | | Output is now to a table instead of paragraph.
| | | WA nation is listed first, followed by nations in the Rejected Realms
1.6 | 20 Aug 2018 | Wolfram & Hart | Added 'fSetNextRequest()' to improve efficiency of request times
| | |
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
Feedback: If you use this script, please drop [nation]Wolfram & Hart[/nation] a telegram.
It would be interesting to know how widely this was used (if at all!)
Any suggestions for improvements and enhancements are welcome.
-->
<head>
<title>W&H PuppetMaster</title>
<style>
body {background-color: black;}
div {
text-align: center;
color: white;
font-family: times;
}
table,th,td {
border : 1px solid white;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<div>
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>PuppetMaster</h3>
<br>
<button type="button" onclick="fMain()">View Puppets</button>
<p id="err"></p>
<table id="msg" align=center></table>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com";
/* ************************************************************************************* */
/* ***************CHANGE THIS ARRAY TO INCLUDE YOUR NATIONS AND PASSWORDS*************** */
var aobjNtns = [
{nation:"Nation 1", password:"Password1"},
{nation:"Nation 2", password:"Password2"},
{nation:"Nation 3", password:"Password3"},
{nation:"Last Nation", password:"LastPassword"}
];
/* ************************************************************************************* */
/* Tell NS the format of the password. This code uses the unencrypted text password.
(The one you type into the NationStates website). NS allows you to use an encrypted
password instead. See this page for more details:
https://www.nationstates.net/pages/api.html#nationapi-privateshards
*/
var strPasswordType = "X-Password";
/* Set variables to record the nations processed. This will update the html. */
var strErr;
var strWA;
var strTRR;
var strMsg;
var strHdr = "<tr><th>Nation</th><th>Region</th><th>Notices</th><th>Telegrams</th><th>RMB</th><th>Issues</th></tr>";
var intNtn = 0;
/* NS can receive 25 requests in 30 seconds. Recording the times that NS receives the requests
enables us to send the latest request exactly 30 seconds after NS received the 25th-ago request.
*/
var adteTime = [];
/* The fMain function:
Initialises the adteTime array with values from 'now' to 24 seconds in the future.
Resets the 'msg' table to being blank.
Tells the code to login the first nation in the list.
*/
function fMain() {
var dteNow = new Date().getTime();
var i;
for (i = 0; i < 24; i++) {
adteTime[i] = dteNow + (i + 1) * 1200;
}
strErr = "";
strWA = "";
strTRR = "";
strMsg = "";
document.getElementById("err").innerHTML = strErr;
document.getElementById("msg").innerHTML = strMsg;
fGetXml();
}
/* fGetXml checks if there is another nation to be processed, then requests the XML from NS */
function fGetXml() {
if (intNtn < aobjNtns.length) {
var strNtn = aobjNtns[intNtn].nation.replace(" ", "_"); // get the nation name & password from the list
var strPassword = aobjNtns[intNtn].password;
intNtn = intNtn + 1;
var objXhttp = new XMLHttpRequest(); // Create an object to send the details to NS
objXhttp.onreadystatechange = function() {
if (objXhttp.readyState == 2) {
fSetNextRequest();
} else if (objXhttp.readyState == 4) {
if (objXhttp.status == 200) {
fProcessXml(this);
} else {
if (objXhttp.status == 403) {
strErr = strNtn + ": Forbidden (incorrect password?)<br>" + strErr;
} else if (objXhttp.status == 404) {
strErr = strNtn + ": Not Found (nation CTEd / misspelled / doesn't exist?)<br>" + strErr;
} else if (objXhttp.status == 429) {
strErr = strNtn + ": Too Many Requests. Processing stopped<br>" + strErr;
} else {
strErr = strNtn + ": Error " + objXhttp.status + "<br>" + strErr;
};
document.getElementById("err").innerHTML = strErr;
};
};
};
objXhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation=" + strNtn + "&q=wa+name+region+unread", true);
objXhttp.setRequestHeader(strPasswordType, strPassword);
objXhttp.setRequestHeader("User-Agent", strUserAgent);
objXhttp.send();
};
}
/* fSetNextRequest adds an entry to the end of adteTime, set for 30 seconds from now.
It then looks at the entry recorded for the 25th-ago request, to set up when the next request should go.
*/
function fSetNextRequest() {
var intDly;
var dteNow = new Date().getTime();
adteTime.push(dteNow + 30000);
intDly = adteTime.shift() - dteNow;
if (intDly < 0) { intDly = 1; };
setTimeout(function(){ fGetXml() }, intDly);
}
/* fProcess reads in the XML data. It puts any WA nation to the top of the output,
followed by any nations in the Rejected Realms, followed by all other nations.
*/
function fProcessXml(objXhttp) {
var objXML = objXhttp.responseXML;
var strNtn = objXML.getElementsByTagName("NAME")[0].childNodes[0].nodeValue;
var strRgn = objXML.getElementsByTagName("REGION")[0].childNodes[0].nodeValue;
var strNtc = objXML.getElementsByTagName("NOTICES")[0].childNodes[0].nodeValue;
if (strNtc == "0") { strNtc = ""; };
var strTGs = objXML.getElementsByTagName("TELEGRAMS")[0].childNodes[0].nodeValue;
if (strTGs == "0") { strTGs = ""; };
var strRMB = objXML.getElementsByTagName("RMB")[0].childNodes[0].nodeValue;
if (strRMB == "0") { strRMB = ""; };
var strIss = objXML.getElementsByTagName("ISSUES")[0].childNodes[0].nodeValue;
if (strIss == "0") { strIss = ""; };
var strTmp = strRgn + "</th><th>" + strNtc +
"</th><th>" + strTGs + "</th><th>" + strRMB + "</th><th>" + strIss + "</th></tr>"
if (objXML.getElementsByTagName("UNSTATUS")[0].childNodes[0].nodeValue != "Non-member") {
strWA = strWA + "<tr style='color:red;'><th>WA Member: " + strNtn + "</th><th>" + strTmp;
} else if (strRgn == "the Rejected Realms") {
strTRR = strTRR + "<tr><th>" + strNtn + "</th><th style='color:red;'>" + strTmp;
} else {
strMsg = strMsg + "<tr><th>" + strNtn + "</th><th>" + strTmp;
};
document.getElementById("msg").innerHTML = strHdr + strWA + strTRR + strMsg;
}
</script>
</body>
</html>
by Queen Yuno » Tue Dec 05, 2017 7:24 pm
Wolfram and Hart wrote:Puppet Login Script
Edit: Seems my code is dodgy, and each nation counts as two hits to NS. We're allowed 50 hits per 30 seconds, or else we get blocked for 15 mins. Until I can figure out how to make a nation count as only one hit, this code should be used for a max of 25 nations.
What
Use this code to log in to a list of your puppets with the push of one button. Handy to stop them CTEing!
How
On your PC or laptop, open a text editor, like Notepad. Copy the code (below) into the editor.
Put your own email address in the code (place indicated by all the asterisks).
Put your own Nation names and passwords in the code (place indicated by all the asterisks).
REMEMBER: If you share your computer, then potentially someone else will have access to these passwords.
Save the file as “PuppetLogin.html”
Check the filename. If it saved as “PuppetLogin.html.txt” or similar, rename it to “PuppetLogin.html”.
When you open the file again, it should get opened in your browser by default. You should see a black page with “Wolfram & Hart” written across the top.
When you click the button, the code should send login requests to NS. NS then sends a response back. The code associated with the response gets displayed on your webpage.
Why
Yes, I know there's already code out there that you can download. But I don't like downloading things, and I like to know how things work. So I wrote code that needs no downloading, and is filled with explanatory comments.
HTML can be written in a simple text editor, and JavaScript can be embedded directly in HTML. Both will be recognised by your browser without the need for any other software or downloads. So they're what I used.
This is the first time I've properly tried to code HTML and JavaScript, so I've added comments at practically every line of code, explaining what it does. That also means users know exactly what they are getting.
- Code: Select all
<!DOCTYPE html>
<!-- Wolfram & Hart Puppet Login Script v1.0
Version | Date | Name | Comment
1.0 | 04 Dec 2017 | Wolfram & Hart | Created
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
Don't use this code to log in more than 25 puppets in 30 seconds.
(That would break NationStates API rules, as at the time of writing).
-->
<head>
<!-- Set the title, visible in the browser tab -->
<title>W&H Puppet Login</title>
<!-- Set the colour scheme and format for the page -->
<style>
body {background-color: black;}
div {
text-align:center;
color: white;
font-family: times;
}
</style>
</head>
<body>
<div>
<!-- Display headers. Use <span> tags to format the "W", "&", and "H" in "Wolfram & Hart". -->
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Puppet Login</h3>
<!-- Add a blank line -->
<br>
<!-- Add a button. When clicked, this will run the JavaScript code -->
<button type="button" onclick="fLoginAll()">Login</button>
<!-- Add an empty paragraph, ready to display results -->
<p id="result"></p>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com"
/* ************************************************************************************* */
/* Tell NS the format of the password. This code uses the unencrypted text password.
(The one you type into the NationStates website). NS allows you to use an encrypted
password instead. See this page for more details:
https://www.nationstates.net/pages/api.html#nationapi-privateshards
*/
var strPasswordType = "X-Password"
/* Set a variable to record the nations processed. This will update the html paragraph */
var strMessage = "";
/* ************CHANGE THIS TO INCLUDE UP TO 25 OF YOUR NATIONS AND PASSWORDS*********** */
/* This function calls the fLogin function (below) for each nation / password pair.
You can have up to 25 nations here without breaking NS API rules */
function fLoginAll() {
fLogin("Nation 1", "Password1")
fLogin("Nation 2", "Password2")
fLogin("Nation 3", "Password3")
fLogin("Nation 4", "Password4")
}
/* ************************************************************************************* */
/* This function uses AJAX to 'ping' (login) each nation, and records if the ping worked. */
function fLogin(strNation, strPassword) {
/* Create an object to send the login details to NS */
var xhttp = new XMLHttpRequest();
/* Set the object to update the html paragraph when it gets a response from NS */
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
strMessage = strMessage+"<br>" + strNation + ": " + xhttp.status;
if (xhttp.status == 200) {
strMessage = strMessage + ": OK";
} else if (xhttp.status == 403) {
strMessage = strMessage + ": Forbidden (incorrect password?)";
} else if (xhttp.status == 404) {
strMessage = strMessage + ": Not Found (nation doesn't exist?)";
} else if (xhttp.status == 429) {
strMessage = strMessage + ": Exceeding Rate Limit (max 25 nations every 30 seconds)";
}
document.getElementById("result").innerHTML = strMessage;
}
};
/* Tell the object which nation URL to log in to.
Replace any space characters in the nation name (" ") with underlines ("_")
Tell it the password.
Tell it your contact details.
Send the request to NS.
*/
xhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation="+strNation.replace(" ", "_")+"&q=ping", true);
xhttp.setRequestHeader(strPasswordType, strPassword)
xhttp.setRequestHeader("User-Agent", strUserAgent)
xhttp.send();
}
</script>
</body>
</html>
by Wolfram and Hart » Wed Dec 06, 2017 5:50 am
by Roavin » Wed Dec 06, 2017 6:21 am
Wolfram and Hart wrote:We're allowed 50 'hits' on the server every 30 seconds. Each nation counts as two hits in my code (don't know why yet), so that's a max of 25 nations in 30 seconds.
Wolfram and Hart wrote:It would be good to add a timer. The code could split the list into chunks of 25 nations, then send them out every 30 seconds. That would comply with site rules.
I'll work on that at some point. Though anyone else is welcome to post how they would do that!
by Honeydewistania » Tue Dec 12, 2017 8:34 am
Alger wrote:if you have egoquotes in your signature, touch grass
by The Noble Thatcherites » Tue Dec 12, 2017 9:01 am
I didn’t realize that we where working together. That’s awesome. I look forward to working together more often.Honeydewistania wrote:Wolfram and Hart have been working on some Special Operations defending the defenceless and the occasional tag.
Regions Defended:
Sikh Empire with help from South Asians
Pacific Islands
Eurasian Socialist Union helping The Union of Democratic States
Giveran Empire
Regions Tagged:
Sontami
Special Operatives Present:
Port Honeydew
Wolfram and Hart
Attorneys Office
Excited? Are you thrilled just by looking at this posts? Do you want to be like us, super cool? Contact Wolfram and Hart.
Kanglia wrote:Thatcher. Wants. As. Little. To. Do. With. You. All. As. Possible.
Résumé
The Union of Democratic States
Citizen and Founder
Prime Minister (x1)
Motion(s) Passed (x15)
Ambassador (x21)
Publisher for The Union Post (x5)
Constitutional Framer (x4)
The Free Nations Region
Citizen and Legislator
Justice (x1)
Motion(s) Passed (1x)
The Allied States
Citizen
Senator (x1)
FORGE
Representative (x4)
Chancellor (x1)
ITDA
Founder
Representative (x1)
Secretary General (x1)
Charter Author (x2)
Court of International Law and Justice
Foreign Affairs Justice (x1)
Europeia
Citizen and Assemblyman (x1)
The South Pacific
Citizen
SPSF Recruit (x1)
by Wolfram and Hart » Sun Dec 17, 2017 2:47 pm
by Wolfram and Hart » Sat Dec 30, 2017 6:11 pm
<!DOCTYPE html>
<!-- Wolfram & Hart Telegraph Machine\ Script v1.0
Version | Date | Name | Comment
1.0 | 23 Dec 2017 | Wolfram & Hart | Created
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
Feedback: If you use this script, please drop [nation]Wolfram & Hart[/nation] a telegram.
It would be interesting to know how widely this was used (if at all!)
Any suggestions for improvements and enhancements are welcome.
-->
<head>
<!-- Set the title, visible in the browser tab -->
<title>W&H Telegraph Machine</title>
<!-- Set the colour scheme and format for the page -->
<style>
body {background-color: black;}
div {
text-align:center;
color: white;
font-family: times;
}
</style>
</head>
<body>
<div>
<!-- Display headers. Use <span> tags to format the "W", "&", and "H" in "Wolfram & Hart". -->
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Telegraph Machine</h3>
<!-- Add a blank line -->
<br>
<!-- Add a button. When clicked, this will run the JavaScript function, "fMain" -->
<button type="button" onclick="fMain()">Telegram New Nations</button>
<!-- Add an empty paragraph, ready to display results -->
<p id="result"></p>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* ***********INSERT YOUR OWN CLIENT KEY, TG ID, AND SECRET KEY IN THIS SECTION******** */
/* Need client key, telegram ID, and the secret key.
See https://www.nationstates.net/pages/api.html#telegrams for more info.
*/
var strClientKey = "abcd1234"
var strTgId = "12345678"
var strSecretKey = "12345678abcd"
/* ************************************************************************************* */
/* Set TG speed (recruitment = 180s, non recruitment = 30s) */
var intSpeed = 180000
/* Set an array variable to store the list of nations */
var astrNations = [];
/* Set a variable to record the nations processed. This will update the html paragraph. */
var strMessage = "";
/* The fMain function resets the 'result' paragraph to being blank.
It then gets a list of new nations from NS (should be 50 most recently created)
It waits until after the list of nations is received before trying to send a TG
*/
function fMain() {
strMessage = "";
document.getElementById("result").innerHTML = "";
fGetNewNations();
}
/* The fGetNewNations function requests the list of new nations from NS
When the list is in, it calls the fTelegram function, to send the first TG.
*/
function fGetNewNations() {
/* Create an object to send the details to NS */
var objXhttp = new XMLHttpRequest();
objXhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
astrNations = this.responseText.split(",");
fTelegram(0);
}
};
objXhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?q=newnations", true);
objXhttp.send();
}
/* the fTelegram function sends out the TG, logs a response, then sets a timer to send the next one */
function fTelegram(intNation) {
/* If there are still nations to be processed, then process them */
if (intNation < astrNations.length) {
/* get the nation name from the list */
var strNation = astrNations[intNation];
/* Create an object to send the details to NS */
var objXhttp = new XMLHttpRequest();
/* Set the object to update the html paragraph when it gets a response from NS
When a response is received, update the paragraph. Then wait before telegramming the next nation.
*/
objXhttp.onreadystatechange = function() {
if (objXhttp.readyState == 4) {
if (objXhttp.status == 200) {
strMessage = strMessage + "<br>" + strNation + ": OK";
setTimeout(function(){ fTelegram(intNation + 1) }, intSpeed);
} else {
strMessage = strNation + ": Error " + objXhttp.status + ": " + objXhttp.responseText + "<br>" + strMessage;
setTimeout(function(){ fTelegram(intNation + 1) }, intSpeed);
}
document.getElementById("result").innerHTML = strMessage;
}
};
objXhttp.open("GET",
"https://www.nationstates.net/cgi-bin/api.cgi?a=sendTG&client=" + strClientKey
+ "&tgid=" + strTgId + "&key=" + strSecretKey + "&to=" + strNation.replace(" ", "_"), true);
objXhttp.send();
} else {
strMessage = "Processing Complete<br>" + strMessage;
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<!-- Wolfram & Hart Telegraph Machine Script v1.2
Version | Date | Name | Comment
1.0 | 23 Dec 2017 | Wolfram & Hart | Created
1.2 | 03 Feb 2018 | Wolfram & Hart | Restructured to use Callback function with AJAX request.
| | | Loop added to keep looking for new nations.
| | | Bug fix for 1st and last nation name processing.
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
-->
<head>
<title>W&H Telegraph Machine</title>
<style>
body {background-color: black;}
div {
text-align:center;
color: white;
font-family: times;
}
</style>
</head>
<body>
<div>
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Telegraph Machine</h3>
<br>
<button type="button" onclick="fMain()">Telegram New Nations</button>
<p id="err"></p>
<p id="msg"></p>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* Get a list of the 50 most recently created nations.
For each nation:
If the nation accepts recruitment TGs, send one.
Move on to the next nation.
When all 50 nations are done, start again.
*/
/* *******INSERT YOUR OWN CLIENT KEY, TG ID, SECRET KEY AND REGION IN THIS SECTION****** */
var strClientKey = "abcd1234";
var strTgId = "12345678";
var strSecretKey = "123456abcdef";
var strRegion = "MyRegion";
/* ************************************************************************************* */
var intSpdTG = 180000; // Recruitment TGs can be sent every 180 seconds (note non-recruitment TGs can be sent every 30 seconds)
var intSpdAPI = 1200; // Regular API calls to NS can be sent every 1.2 seconds (actually 50 "hits" in 30 seconds, but this seems to work)
var astrNtns = []; // An array variable to store the list of new nations
var intNtn = 0; // Keep a note of which nation is being processed
var strErr = ""; // Keep a record of any HTTP errors
var strMsg = ""; // Keep a record of nations successfully processed
/* The fMain function is called when the button is pressed.
Reset displayed paragraphs to be blank, then request a list of new NS nations
*/
function fMain() {
strRegion = strRegion.replace(" ", "_");
strErr = "";
strMsg = "";
document.getElementById("err").innerHTML = strErr;
document.getElementById("msg").innerHTML = strMsg;
fGetNewNations();
}
/* The fGetNewNations function requests the list of new nations from NS */
function fGetNewNations() {
fGetXml("https://www.nationstates.net/cgi-bin/api.cgi?q=newnations", fProcessNewNations);
}
/* The fProcessNewNations function parses the list of new nations into an array
It then tries to recruit the first nation (0) on the list
*/
function fProcessNewNations(objXml) {
if (objXml.status == 200) {
astrNtns = objXml.responseXML.getElementsByTagName("NEWNATIONS")[0].childNodes[0].nodeValue.split(",");
intNtn = 0;
setTimeout(function(){ fGetCanRecruit() }, intSpdAPI);
} else {
strErr = "fGetNewNations Error " + objXml.status + ": " + objXml.responseText + "<br>" + strErr;
document.getElementById("err").innerHTML = strErr;
}
}
/* The fGetCanRecruit function checks if the nation accepts recruitment TGs
Sending the optional "from=(region_name)" parameter checks that you didn't send them a TG too recently.
*/
function fGetCanRecruit() {
/* First check that there are still nations to process */
if (intNtn >= astrNtns.length) {
fGetNewNations();
} else {
/* get the nation name from the list */
var strNtn = astrNtns[intNtn].replace(" ", "_");
var strUrl = "https://www.nationstates.net/cgi-bin/api.cgi?nation=" + strNtn + "&q=tgcanrecruit&from=" + strRegion
fGetXml(strUrl, fProcessCanRecruit);
}
}
/* The fProcessCanRecruit function:
If the response is "1", (Nation accepts recruitment TGs), send a TG
Else, try the next nation
*/
function fProcessCanRecruit(objXml) {
if (objXml.status == 200) {
var strMrkr = objXml.responseXML.getElementsByTagName("TGCANRECRUIT")[0].childNodes[0].nodeValue;
if (strMrkr == "1") {
setTimeout(function(){ fTelegram() }, intSpdAPI);
} else {
strMsg = intNtn + ": " + astrNtns[intNtn] + ": TG Blocked" + "<br>" + strMsg;
document.getElementById("msg").innerHTML = strMsg;
intNtn = intNtn + 1;
setTimeout(function(){ fGetCanRecruit() }, intSpdAPI);
}
} else {
strErr = "fGetCanRecruit Error " + objXml.status + ": " + objXml.responseText + "<br>" + strErr;
document.getElementById("err").innerHTML = strErr;
intNtn = intNtn + 1;
setTimeout(function(){ fGetCanRecruit() }, intSpdAPI);
}
}
/* The fTelegram function sends out the TG */
function fTelegram() {
var strNtn = astrNtns[intNtn].replace(" ", "_");
var strUrl = "https://www.nationstates.net/cgi-bin/api.cgi?a=sendTG&client="
+ strClientKey + "&tgid=" + strTgId + "&key=" + strSecretKey + "&to=" + strNtn;
fGetXml(strUrl, fProcessTelegram);
}
/* Log the response, then check the next nation */
function fProcessTelegram(objXml) {
if (objXml.status == 200) {
strMsg = intNtn + ": " + astrNtns[intNtn] + ": TG Sent" + "<br>" + strMsg;
document.getElementById("msg").innerHTML = strMsg;
} else {
strErr = "fTelegram Error " + objXml.status + ": " + objXml.responseText + "<br>" + strErr;
document.getElementById("err").innerHTML = strErr;
}
intNtn = intNtn + 1;
setTimeout(function(){ fGetCanRecruit() }, intSpdTG - intSpdAPI);
}
/* fGetXml needs to know the URL to get data from, and the function to run when the data is retrieved. */
function fGetXml(strUrl, objFn) {
var objXhttp = new XMLHttpRequest(); // Create an object to send the details to NS
objXhttp.onreadystatechange = function() {
if (this.readyState == 4) {
objFn(this);
}
};
objXhttp.open("GET", strUrl, true);
objXhttp.send();
}
</script>
</body>
</html>
by Wolfram and Hart » Tue Feb 13, 2018 3:12 pm
by Wolfram and Hart » Thu Oct 25, 2018 2:53 pm
<!DOCTYPE html>
<!-- Wolfram & Hart Sleeping Beauty v1.0
Version | Date | Name | Comment
1.0 | 25 Oct 2018 | Wolfram & Hart | Created
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
Feedback: If you use this script, please drop [nation]Wolfram & Hart[/nation] a telegram.
It would be interesting to know how widely this was used (if at all!)
Any suggestions for improvements and enhancements are welcome.
-->
<head>
<title>W&H Sleeping Beauty</title>
<style>
body {background-color: black;}
div {
text-align: center;
color: white;
font-family: times;
}
table,th,td {
border : 1px solid white;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<div>
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Sleeping Beauty</h3>
<br>
<button type="button" onclick="fMain()">Process Puppets</button>
<p><i>(Click table header to sort data)</i></p>
<p id="log"></p>
<p id="err"></p>
<table id="msg" align=center><tr>
<th onclick="fSortNtns('ntn')">Nation</th>
<th onclick="fSortNtns('rgn')">Region</th>
<th onclick="fSortNtns('ntc')">Notices</th>
<th onclick="fSortNtns('tgs')">Telegrams</th>
<th onclick="fSortNtns('rmb')">RMB</th>
<th onclick="fSortNtns('iss')">Issues</th>
</tr></table>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com";
/* ************************************************************************************* */
/* ***********CHANGE THIS ARRAY TO INCLUDE YOUR NATIONS, PASSWORDS, AND STYLES********** */
var aobjNtns = [
{nation:"Nation 1", password:"Password1", style:"1st"},
{nation:"Nation 2", password:"Password2", style:"2nd"},
{nation:"Nation 3", password:"Password3", style:"2nd last"},
{nation:"Nation 4", password:"Password4", style:"last"},
{nation:"Last Nation", password:"LastPassword", style:"random"}
];
/*
var aobjNtns = [
];
*/
/* ************************************************************************************* */
/* *****************SET THE TIME (IN MINUTES) TO TRY AND FINISH BY********************** */
var intEnd = 60;
/* ************************************************************************************* */
var strPasswordType = "X-Password"; // Tell NS the format of the above passwords. This info is needed by NS
var dteNow; // Used at various points to record the current time
var strNtnLast = ""; // Record the last nation processed to determine whether Pin or Password is used for next login.
var strErr; // Set variables to record the nations processed. These are used to update the html.
var strMsg;
var strHdr = document.getElementById("msg").innerHTML;
var strSort = "";
/* The fMain function:
Convert the target end time, intEnd, to millisecconds, and subtract estimated required processing times.
After this convertion, intEnd represents the latest time that the code should start handling a nation.
Reset the 'msg' table to being blank.
Put the list of nations into a random order, then adds them to the request queue.
Tell the code to login the first nation in the queue.
*/
function fMain() {
dteNow = new Date().getTime(); // Note the time. Used when adding nations to the request queue
intEnd = (intEnd * 60000) - (aobjNtns.length * 1200) - 400000; // Convert target end time to ms and adjust
if (intEnd < 0) { intEnd = 1000; }; // Make sure the new end time is at least one second long!
strErr = ""; // Reset the message strings and blank out the html
strMsg = strHdr;
document.getElementById("err").innerHTML = strErr;
document.getElementById("msg").innerHTML = strMsg;
aobjNtns = aobjNtns.map(fRemapNtns); // Add some extra detail to the nation records
aobjRqst = aobjNtns.map(fAddNtnsToRqstQueue); // Add the nations to the request queue
aobjRqst.sort(fSortWhen); // Sort requests into the order in which they'll be made
fGetXml(); // Request the first item in the request queue
}
/* fRemapNtns expands each Nation object to hold the data that will be returned from NS */
function fRemapNtns(value, index, array) {
return {
name: value.nation,
ntn: value.nation.toLowerCase().replace(/ /g, "_"),
styl: value.style.toLowerCase(),
pwrdtyp: strPasswordType,
pwrd: value.password,
pin: "",
wa: "",
rgn: "?",
ntc: -1,
tgs: -1,
rmb: -1,
iss: -1
};
}
/* fAddNtnsToRqstQueue takes the list of nations and passwords, and adds them to a queue of requests to be sent to NS
Set a random time, based on intEnd, to start handling the nation.
*/
function fAddNtnsToRqstQueue(value, index, array) {
return {
ntn: value.ntn,
rqst: "&q=wa+name+region+unread+issues",
pwrdtyp: value.pwrdtyp,
pwrd: value.pwrd,
when: dteNow + intEnd * Math.random()
};
}
/* function to sort array by scheduled request time */
function fSortWhen(a,b) {
return a.when - b.when;
}
/* fGetXml takes the first request to be processed, then requests the XML from NS
When the result is back, call fProcessXml.
*/
function fGetXml() {
if (aobjRqst.length > 0) {
var objRqst = aobjRqst.shift(); // Take the first item in the queue
var objXhttp = new XMLHttpRequest(); // Create an object to send the details to NS
objXhttp.onreadystatechange = function() {
if (objXhttp.readyState == 4) {
if (objXhttp.status == 200) {
fProcessXml(this); // When a response is received from NS, process it
} else {
if (objXhttp.status == 403) {
strErr = objRqst.ntn + ": Forbidden (incorrect password?)<br>" + strErr;
} else if (objXhttp.status == 404) {
strErr = objRqst.ntn + ": Not Found (nation CTEd / misspelled / doesn't exist?)<br>" + strErr;
} else if (objXhttp.status == 429) {
strErr = objRqst.ntn + ": Too Many Requests. Processing stopped<br>" + strErr;
} else {
strErr = objRqst.ntn + ": Error " + objXhttp.status + "<br>" + strErr;
};
document.getElementById("err").innerHTML = strErr;
};
};
};
// Set the details of the request:
objXhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation=" + objRqst.ntn + objRqst.rqst, true);
if (objRqst.ntn == strNtnLast) {
var i = 0;
while (aobjNtns[i].ntn != strNtnLast) { i++; }; // Find the matching nation in aobjNtns
objXhttp.setRequestHeader("X-Pin", aobjNtns[i].pin); // If this request is for the same nation as the last,
objXhttp.setRequestHeader(objRqst.pwrdtyp, objRqst.pwrd); // use the Pin. Send password as well, just in case
} else {
objXhttp.setRequestHeader(objRqst.pwrdtyp, objRqst.pwrd); // Else set to use the password, and
strNtnLast = objRqst.ntn; // record that this nation is now the latest nation
};
objXhttp.setRequestHeader("User-Agent", strUserAgent); // Set to send the User-Agent too
objXhttp.send(); // Send the request to NS
};
}
/* fProcess:
Reads in the XML data.
Updates the nation with the new Pin
Works out when to call the routine that sends the next request
*/
function fProcessXml(objXhttp) {
dteNow = new Date().getTime();
var objXML = objXhttp.responseXML; // Read in the body of the returned data
var strNtn = objXML.getElementsByTagName("NATION")[0].getAttribute("id"); // Read the nation ID
var i = 0;
while (aobjNtns[i].ntn != strNtn) { i++; }; // Find the matching nation in aobjNtns
var strPin = objXhttp.getResponseHeader("X-Pin"); // Read in the pin from returned data header
if (strPin != null) { aobjNtns[i].pin = strPin; }; // Assign the pin to the nation
if (objXML.getElementsByTagName("UNREAD").length > 0) {
fProcessFirst(objXhttp, strNtn, i); // If this was the first request for the nation, process accordingly
} else {
fProcessIssue(objXML, i); // If this was the result of answering an issue, process accordingly
};
if (aobjRqst.length > 0) {
var intWhen = aobjRqst[0].when - dteNow; // If there are more requests in the queue, work out when to send the next
if (intWhen < 1200) { intWhen = 1200; };
setTimeout(function(){ fGetXml() }, intWhen);
} else {
window.alert("Done"); // Else notify the user that the job is complete
};
}
/* fProcess reads in the XML data.
*/
function fProcessFirst(objXhttp, strNtn, i) {
var dteWhen = dteNow;
var strTmp
var objXML = objXhttp.responseXML; // Read in the body of the returned data
aobjNtns[i].pwrdtyp = "X-Autologin";
var strPwrd = objXhttp.getResponseHeader("X-Autologin"); // Read in the password from returned data header
aobjNtns[i].pwrd = strPwrd; // Update the nation with the returned data
aobjNtns[i].wa = objXML.getElementsByTagName("UNSTATUS")[0].childNodes[0].nodeValue;
aobjNtns[i].rgn = objXML.getElementsByTagName("REGION")[0].childNodes[0].nodeValue;
aobjNtns[i].ntc = objXML.getElementsByTagName("NOTICES")[0].childNodes[0].nodeValue;
aobjNtns[i].tgs = objXML.getElementsByTagName("TELEGRAMS")[0].childNodes[0].nodeValue;
aobjNtns[i].rmb = objXML.getElementsByTagName("RMB")[0].childNodes[0].nodeValue;
aobjNtns[i].iss = objXML.getElementsByTagName("ISSUES")[0].childNodes[0].nodeValue;
var aobjIss = objXML.getElementsByTagName("ISSUE"); // Create an array of the issues data
var strOpt = "ignore";
for (var j = 0; j < aobjIss.length; j++) {
var aobjOpts = aobjIss[j].getElementsByTagName('OPTION'); // For each issue, find the options & choose response
switch (aobjNtns[i].styl) {
case "random":
strOpt = aobjOpts[Math.floor(Math.random() * aobjOpts.length)].getAttribute('id'); // Choose a random answer
break;
case "1st":
strOpt = aobjOpts[0].getAttribute('id'); // Choose the first available answer
break;
case "2nd":
strOpt = aobjOpts[1].getAttribute('id'); // Choose the second available answer
break;
case "2nd last":
strOpt = aobjOpts[aobjOpts.length - 2].getAttribute('id'); // Choose the second last answer
break;
case "last":
strOpt = aobjOpts[aobjOpts.length - 1].getAttribute('id'); // Choose the last answer
break;
}; // Else the default treatment is to ignore issues
if (strOpt != "ignore") {
dteWhen = dteWhen + 20000 + 60000 * Math.random(); // Set the gap between issue answers to 20 to 80 seconds
var objRqst = {
ntn: strNtn,
rqst: "&c=issue&issue=" + aobjIss[j].getAttribute("id") + "&option=" + strOpt,
pwrdtyp: "X-Autologin",
pwrd: strPwrd,
when: dteWhen
};
aobjRqst.push(objRqst); // Add the nation, issue, and answer to the request queue
};
};
aobjRqst.sort(fSortWhen); // Make sure the request queue is in the right order
fSortNtns(strSort); // Update the visible HTML table
}
/* fProcessIssue:
Reduces the nation's issue count by one, if an issue was successfully answered
*/
function fProcessIssue(objXML, i) {
if (objXML.getElementsByTagName("OK").length > 0) {
aobjNtns[i].iss = aobjNtns[i].iss - 1; // If the issue was successfully answered, reduce the number of outstanding issues
fSortNtns(strSort); // Update the visible HTML table
};
}
function fSortNtns(strBy) {
strSort = strBy;
switch (strBy) {
case "ntn":
aobjNtns.sort(fSortNtn);
break;
case "rgn":
aobjNtns.sort(fSortRgn);
break;
case "ntc":
aobjNtns.sort(fSortNtc);
break;
case "tgs":
aobjNtns.sort(fSortTgs);
break;
case "rmb":
aobjNtns.sort(fSortRmb);
break;
case "iss":
aobjNtns.sort(fSortIss);
break;
};
fUpdateTable();
}
/* function to sort array by nation */
function fSortNtn(a,b) {
var x = a.ntn.toLowerCase();
var y = b.ntn.toLowerCase();
if (x < y) { return -1; };
if (x > y) { return 1; };
return 0;
}
/* function to sort array by region */
function fSortRgn(a,b) {
var x = a.rgn.toLowerCase();
var y = b.rgn.toLowerCase();
if (x < y) { return -1; };
if (x > y) { return 1; };
return 0;
}
/* function to sort array by nation sort order */
function fSortNtc(a,b) {
return b.ntc - a.ntc;
}
/* function to sort array by nation sort order */
function fSortTgs(a,b) {
return b.tgs - a.tgs;
}
/* function to sort array by nation sort order */
function fSortRmb(a,b) {
return b.rmb - a.rmb;
}
/* function to sort array by nation sort order */
function fSortIss(a,b) {
return b.iss - a.iss;
}
/*
*/
function fUpdateTable() {
var i;
var strMsg = strHdr; // Set the table header
var strNtc;
var strTgs;
var strRmb;
var strIss;
for (i = 0; i < aobjNtns.length; i++) {
if (aobjNtns[i].wa == "WA Member") {
strMsg = strMsg + "<tr style='color:red;'>"; // Set to display any WA nation in red
} else {
strMsg = strMsg + "<tr>";
};
strNtc = aobjNtns[i].ntc; // If 'unread' counts are unknown, display them as "?"
if (strNtc < 0) { strNtc = "?" };
strTgs= aobjNtns[i].tgs;
if (strTgs < 0) { strTgs = "?" };
strRmb = aobjNtns[i].rmb;
if (strRmb < 0) { strRmb = "?" };
strIss = aobjNtns[i].iss;
if (strIss < 0) { strIss = "?" };
strMsg = strMsg + "<td>"
+ aobjNtns[i].name + "</td><td>" + aobjNtns[i].rgn + "</td><td>"
+ strNtc + "</td><td>" + strTgs + "</td><td>"
+ strRmb + "</td><td>" + strIss + "</td></tr>"; // Add details of each nation
};
document.getElementById("msg").innerHTML = strMsg; // Output the complete data to the HTML table
}
</script>
</body>
</html>
<!DOCTYPE html>
<!-- Wolfram & Hart Sleeping Beauty v1.2
Version | Date | Name | Comment
1.0 | 25 Oct 2018 | Wolfram & Hart | Created
1.2 | 19 Nov 2018 | Wolfram & Hart | Included SPDR. Continues processing if nation or password invalid.
This code is not warranted in any way. Use at your own risk.
Use and modify this code as suits.
Make sure you comply with the NationStates API rules.
See: https://www.nationstates.net/pages/api.html
-->
<head>
<title>W&H Sleeping Beauty</title>
<style>
body {background-color: black;}
div {
text-align: center;
color: white;
font-family: times;
}
table,th,td {
border : 1px solid white;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<div>
<h1><span style="font-size:120%;">W</span>OLFRAM <span style="color:red; font-size:120%;">&</span> <span style="font-size:120%;">H</span>ART</h1>
<h3>Sleeping Beauty</h3>
<br>
<button type="button" onclick="fMain()">Process Puppets</button>
<p><i>(Click table header to sort data)</i></p>
<p id="log"></p>
<p id="err"></p>
<table id="msg" align=center><tr>
<th onclick="fSortNtns('ntn')">Nation</th>
<th onclick="fSortNtns('rgn')">Region</th>
<th onclick="fSortNtns('ntc')">Notices</th>
<th onclick="fSortNtns('tgs')">Telegrams</th>
<th onclick="fSortNtns('rmb')">RMB</th>
<th onclick="fSortNtns('iss')">Issues</th>
<th onclick="fSortNtns('spdr')">Influence</th>
</tr></table>
</div>
<!-- This is the JavaScript that will be run when the button is pressed -->
<script>
/* **********************CHANGE THIS TO USE YOUR OWN EMAIL ADDRESS********************** */
/* NationStates require a 'UserAgent', so you can be contacted if something goes wrong */
var strUserAgent = "myname@email.com";
/* ************************************************************************************* */
/* ***********CHANGE THIS ARRAY TO INCLUDE YOUR NATIONS, PASSWORDS, AND STYLES********** */
var aobjNtns = [
{nation:"Nation 1", password:"Password1", style:"1st"},
{nation:"Nation 2", password:"Password2", style:"2nd"},
{nation:"Nation 3", password:"Password3", style:"2nd last"},
{nation:"Nation 4", password:"Password4", style:"last"},
{nation:"Last Nation", password:"LastPassword", style:"random"}
];
/* ************************************************************************************* */
/* *****************SET THE TIME (IN MINUTES) TO TRY AND FINISH BY********************** */
var intEnd = 60;
/* ************************************************************************************* */
var strPasswordType = "X-Password"; // Tell NS the format of the above passwords. This info is needed by NS
var dteNow; // Used at various points to record the current time
var strNtnLast = ""; // Record the last nation processed to determine whether Pin or Password is used for next login.
var strErr; // Set variables to record the nations processed. These are used to update the html.
var strMsg;
var strHdr = document.getElementById("msg").innerHTML;
var strSort = "";
/* The fMain function:
Convert the target end time, intEnd, to millisecconds, and subtract estimated required processing times.
After this convertion, intEnd represents the latest time that the code should start handling a nation.
Reset the 'msg' table to being blank.
Put the list of nations into a random order, then adds them to the request queue.
Tell the code to login the first nation in the queue.
*/
function fMain() {
dteNow = new Date().getTime(); // Note the time. Used when adding nations to the request queue
intEnd = (intEnd * 60000) - (aobjNtns.length * 1200) - 400000; // Convert target end time to ms and adjust
if (intEnd < 0) { intEnd = 1000; }; // Make sure the new end time is at least one second long!
strErr = ""; // Reset the message strings and blank out the html
strMsg = strHdr;
document.getElementById("err").innerHTML = strErr;
document.getElementById("msg").innerHTML = strMsg;
aobjNtns = aobjNtns.map(fRemapNtns); // Add some extra detail to the nation records
aobjRqst = aobjNtns.map(fAddNtnsToRqstQueue); // Add the nations to the request queue
aobjRqst.sort(fSortWhen); // Sort requests into the order in which they'll be made
fGetXml(); // Request the first item in the request queue
}
/* fRemapNtns expands each Nation object to hold the data that will be returned from NS */
function fRemapNtns(value, index, array) {
return {
name: value.nation,
ntn: value.nation.toLowerCase().replace(/ /g, "_"),
styl: value.style.toLowerCase(),
pwrdtyp: strPasswordType,
pwrd: value.password,
pin: "",
wa: "",
rgn: "?",
ntc: -1,
tgs: -1,
rmb: -1,
iss: -1,
spdr: -1
};
}
/* fAddNtnsToRqstQueue takes the list of nations and passwords, and adds them to a queue of requests to be sent to NS
Set a random time, based on intEnd, to start handling the nation.
*/
function fAddNtnsToRqstQueue(value, index, array) {
return {
ntn: value.ntn,
rqst: "&q=wa+name+region+unread+issues+census;scale=65;mode=score",
pwrdtyp: value.pwrdtyp,
pwrd: value.pwrd,
when: dteNow + intEnd * Math.random()
};
}
/* function to sort array by scheduled request time */
function fSortWhen(a,b) {
return a.when - b.when;
}
/* fGetXml takes the first request to be processed, then requests the XML from NS
When the result is back, call fProcessXml.
*/
function fGetXml() {
if (aobjRqst.length > 0) {
var objRqst = aobjRqst.shift(); // Take the first item in the queue
var objXhttp = new XMLHttpRequest(); // Create an object to send the details to NS
objXhttp.onreadystatechange = function() {
if (objXhttp.readyState == 4) {
if (objXhttp.status == 200) {
fProcessXml(this); // When a response is received from NS, process it
} else {
if (objXhttp.status == 403) {
strErr = objRqst.ntn + ": Forbidden (incorrect password?)<br>" + strErr;
fGetNext();
} else if (objXhttp.status == 404) {
strErr = objRqst.ntn + ": Not Found (nation CTEd / misspelled / doesn't exist?)<br>" + strErr;
fGetNext();
} else if (objXhttp.status == 429) {
strErr = objRqst.ntn + ": Too Many Requests. Processing stopped<br>" + strErr;
} else {
strErr = objRqst.ntn + ": Error " + objXhttp.status + "<br>" + strErr;
};
document.getElementById("err").innerHTML = strErr;
};
};
};
// Set the details of the request:
objXhttp.open("GET", "https://www.nationstates.net/cgi-bin/api.cgi?nation=" + objRqst.ntn + objRqst.rqst, true);
if (objRqst.ntn == strNtnLast) {
var i = 0;
while (aobjNtns[i].ntn != strNtnLast) { i++; }; // Find the matching nation in aobjNtns
objXhttp.setRequestHeader("X-Pin", aobjNtns[i].pin); // If this request is for the same nation as the last,
objXhttp.setRequestHeader(objRqst.pwrdtyp, objRqst.pwrd); // use the Pin. Send password as well, just in case
} else {
objXhttp.setRequestHeader(objRqst.pwrdtyp, objRqst.pwrd); // Else set to use the password, and
strNtnLast = objRqst.ntn; // record that this nation is now the latest nation
};
objXhttp.setRequestHeader("User-Agent", strUserAgent); // Set to send the User-Agent too
objXhttp.send(); // Send the request to NS
};
}
/* fGetNext sets up when to call fGetXML again */
function fGetNext() {
dteNow = new Date().getTime();
if (aobjRqst.length > 0) {
var intWhen = aobjRqst[0].when - dteNow; // If there are more requests in the queue, work out when to send the next
if (intWhen < 1200) { intWhen = 1200; };
setTimeout(function(){ fGetXml() }, intWhen);
} else {
window.alert("Done"); // Else notify the user that the job is complete
};
}
/* fProcess:
Reads in the XML data.
Updates the nation with the new Pin
Works out when to call the routine that sends the next request
*/
function fProcessXml(objXhttp) {
// dteNow = new Date().getTime();
var objXML = objXhttp.responseXML; // Read in the body of the returned data
var strNtn = objXML.getElementsByTagName("NATION")[0].getAttribute("id"); // Read the nation ID
var i = 0;
while (aobjNtns[i].ntn != strNtn) { i++; }; // Find the matching nation in aobjNtns
var strPin = objXhttp.getResponseHeader("X-Pin"); // Read in the pin from returned data header
if (strPin != null) { aobjNtns[i].pin = strPin; }; // Assign the pin to the nation
if (objXML.getElementsByTagName("UNREAD").length > 0) {
fProcessFirst(objXhttp, strNtn, i); // If this was the first request for the nation, process accordingly
} else {
fProcessIssue(objXML, i); // If this was the result of answering an issue, process accordingly
};
fGetNext();
}
/* fProcess reads in the XML data.
*/
function fProcessFirst(objXhttp, strNtn, i) {
var dteWhen = dteNow;
var strTmp
var objXML = objXhttp.responseXML; // Read in the body of the returned data
aobjNtns[i].pwrdtyp = "X-Autologin";
var strPwrd = objXhttp.getResponseHeader("X-Autologin"); // Read in the password from returned data header
aobjNtns[i].pwrd = strPwrd; // Update the nation with the returned data
aobjNtns[i].wa = objXML.getElementsByTagName("UNSTATUS")[0].childNodes[0].nodeValue;
aobjNtns[i].rgn = objXML.getElementsByTagName("REGION")[0].childNodes[0].nodeValue;
aobjNtns[i].ntc = objXML.getElementsByTagName("NOTICES")[0].childNodes[0].nodeValue;
aobjNtns[i].tgs = objXML.getElementsByTagName("TELEGRAMS")[0].childNodes[0].nodeValue;
aobjNtns[i].rmb = objXML.getElementsByTagName("RMB")[0].childNodes[0].nodeValue;
aobjNtns[i].iss = objXML.getElementsByTagName("ISSUES")[0].childNodes[0].nodeValue;
aobjNtns[i].spdr = Number(objXML.getElementsByTagName("SCORE")[0].childNodes[0].nodeValue);
var aobjIss = objXML.getElementsByTagName("ISSUE"); // Create an array of the issues data
var strOpt = "ignore";
for (var j = 0; j < aobjIss.length; j++) {
var aobjOpts = aobjIss[j].getElementsByTagName('OPTION'); // For each issue, find the options & choose response
switch (aobjNtns[i].styl) {
case "random":
strOpt = aobjOpts[Math.floor(Math.random() * aobjOpts.length)].getAttribute('id'); // Choose a random answer
break;
case "1st":
strOpt = aobjOpts[0].getAttribute('id'); // Choose the first available answer
break;
case "2nd":
strOpt = aobjOpts[1].getAttribute('id'); // Choose the second available answer
break;
case "2nd last":
strOpt = aobjOpts[aobjOpts.length - 2].getAttribute('id'); // Choose the second last answer
break;
case "last":
strOpt = aobjOpts[aobjOpts.length - 1].getAttribute('id'); // Choose the last answer
break;
}; // Else the default treatment is to ignore issues
if (strOpt != "ignore") {
dteWhen = dteWhen + 20000 + 60000 * Math.random(); // Set the gap between issue answers to 20 to 80 seconds
var objRqst = {
ntn: strNtn,
rqst: "&c=issue&issue=" + aobjIss[j].getAttribute("id") + "&option=" + strOpt,
pwrdtyp: "X-Autologin",
pwrd: strPwrd,
when: dteWhen
};
aobjRqst.push(objRqst); // Add the nation, issue, and answer to the request queue
};
};
aobjRqst.sort(fSortWhen); // Make sure the request queue is in the right order
fSortNtns(strSort); // Update the visible HTML table
}
/* fProcessIssue:
Reduces the nation's issue count by one, if an issue was successfully answered
*/
function fProcessIssue(objXML, i) {
if (objXML.getElementsByTagName("OK").length > 0) {
aobjNtns[i].iss = aobjNtns[i].iss - 1; // If the issue was successfully answered, reduce the number of outstanding issues
fSortNtns(strSort); // Update the visible HTML table
};
}
function fSortNtns(strBy) {
strSort = strBy;
switch (strBy) {
case "ntn":
aobjNtns.sort(fSortNtn);
break;
case "rgn":
aobjNtns.sort(fSortRgn);
break;
case "ntc":
aobjNtns.sort(fSortNtc);
break;
case "tgs":
aobjNtns.sort(fSortTgs);
break;
case "rmb":
aobjNtns.sort(fSortRmb);
break;
case "iss":
aobjNtns.sort(fSortIss);
break;
case "spdr":
aobjNtns.sort(fSortSpdr);
break;
};
fUpdateTable();
}
/* function to sort array by nation */
function fSortNtn(a,b) {
var x = a.ntn.toLowerCase();
var y = b.ntn.toLowerCase();
if (x < y) { return -1; };
if (x > y) { return 1; };
return 0;
}
/* function to sort array by region */
function fSortRgn(a,b) {
var x = a.rgn.toLowerCase();
var y = b.rgn.toLowerCase();
if (x < y) { return -1; };
if (x > y) { return 1; };
return 0;
}
/* function to sort array by notices */
function fSortNtc(a,b) {
return b.ntc - a.ntc;
}
/* function to sort array by telegrams */
function fSortTgs(a,b) {
return b.tgs - a.tgs;
}
/* function to sort array by RMB posts */
function fSortRmb(a,b) {
return b.rmb - a.rmb;
}
/* function to sort array by Issues */
function fSortIss(a,b) {
return b.iss - a.iss;
}
/* function to sort array by SPDR */
function fSortSpdr(a,b) {
return b.spdr - a.spdr;
}
/*
*/
function fUpdateTable() {
var i;
var strMsg = strHdr; // Set the table header
var strNtc;
var strTgs;
var strRmb;
var strIss;
var strSpdr;
for (i = 0; i < aobjNtns.length; i++) {
if (aobjNtns[i].wa == "WA Member") {
strMsg = strMsg + "<tr style='color:red;'>"; // Set to display any WA nation in red
} else {
strMsg = strMsg + "<tr>";
};
strNtc = aobjNtns[i].ntc; // If 'unread' counts are unknown, display them as "?"
if (strNtc < 0) { strNtc = "?" };
strTgs= aobjNtns[i].tgs;
if (strTgs < 0) { strTgs = "?" };
strRmb = aobjNtns[i].rmb;
if (strRmb < 0) { strRmb = "?" };
strIss = aobjNtns[i].iss;
if (strIss < 0) { strIss = "?" };
strSpdr = aobjNtns[i].spdr;
if (strSpdr < 0) { strSpdr = "?" };
strMsg = strMsg + "<td>"
+ aobjNtns[i].name + "</td><td>" + aobjNtns[i].rgn + "</td><td>"
+ strNtc + "</td><td>" + strTgs + "</td><td>"
+ strRmb + "</td><td>" + strIss + "</td><td>"
+ strSpdr + "</td></tr>"; // Add details of each nation
};
document.getElementById("msg").innerHTML = strMsg; // Output the complete data to the HTML table
}
</script>
</body>
</html>
by Wolfram and Hart » Mon Nov 19, 2018 2:50 pm
Advertisement
Users browsing this forum: Ancapia, Klaus Devestatorie
Advertisement