NATION

PASSWORD

How to keep following the simultaneity rule

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

How to keep following the simultaneity rule

Postby Eluvatar » Wed Mar 04, 2020 9:52 pm

Testlandia wrote:A tool may not execute restricted actions simultaneously, but must instead wait for the completion of each command--that is, a complete response from the NationStates server--before issuing the next one. A tool should not spawn background processes to enable multiple simultaneous server connections that each perform a restricted action.


In imperative programming, this aspect of things is relatively straightforward: do not have multiple threads of execution simultaneously making HTTP requests that perform restricted actions of nationstates.net, even in response to multiple user inputs. For example, in a GUI program like an android app, it's can be easier to follow this rule than not to.

In HTML/javascript, however, this can be tricky.

It is illegal to generate and use a page with multiple forms pointed at nationstates.net if you can submit the forms in parallel: that is to say, if you can click the next form without waiting for the last form's submission to be completed. It is also illegal to create a button which causes something to happen when clicked and can be clicked again before the result of the previous click is complete. It is also illegal to create a keybinding which causes something to happen when pressed (other than clicking an existing NS form or link) and does not prevent you from using it (or another one) before it finishes.

Legal solutions will involve submitting restricted actions using AJAX and not allowing a subsequent action until the AJAX callback is called. This might look somewhat like the following:

Code: Select all
$('form#my_restricted_action_button_form').submit(function(event) {
    disallow_next_click();
    $.post("http://embed.nationstates.net/cgi-bin/restricted-action.cgi", data, function(){
        allow_next_click();
    });
    event.preventDefault();
});

function disallow_next_click() {
    $('form input[type="submit"], form button').attr("disabled", true).addClass("disabledForSimultaneity");
}

function allow_next_click() {
    $('.disabledForSimultaneity').removeAttr("disabled").removeClass("disabledForSimultaneity");
}


This approach has the advantage of not re-enabling things that were meant to be disabled.

The only situation in which you don't have to proactively lock things down is when you turn user input into a "restricted action" is if you are submitting a form or clicking a link which is part of the HTML your browser received from nationstates.net.
Last edited by Eluvatar on Thu Mar 05, 2020 7:29 am, edited 1 time in total.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Wed Mar 04, 2020 9:55 pm

Last edited by Eluvatar on Wed Mar 04, 2020 10:07 pm, edited 1 time in total.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Roavin
Admin
 
Posts: 1777
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Thu Mar 05, 2020 5:29 am

For use with jQuery, you can do something similar to this line to disable buttons before performing a request:

Code: Select all
$('form input[type="submit"], form button').attr("disabled", true).addClass("disabledForSimultaneity");


Then, when a request completes (for example, in your jqXHR.always() callback), do the following:
Code: Select all
$('.disabledForSimultaneity').removeAttr("disabled").removeClass("disabledForSimultaneity");


This approach has the advantage of not re-enabling things that were meant to be disabled.
Last edited by Roavin on Thu Mar 05, 2020 5:30 am, edited 1 time in total.
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.

User avatar
The Northern Light
Spokesperson
 
Posts: 156
Founded: Oct 10, 2014
Iron Fist Consumerists

Postby The Northern Light » Thu Mar 05, 2020 5:36 am

Can I suggest linking this thread in the OSRS, in the scripting section? Otherwise, it is very hard to track down --- indeed, in my experience, a lot of coders are not even aware of all these intricate simultaneity rules.
Last edited by The Northern Light on Thu Mar 05, 2020 5:45 am, edited 1 time in total.
Home of the WADP, Planet Eras, and the Constibillocode!
Join The North Pacific!
Where the democracy is strong, the debate robust, and the rum plentiful!

Forum | Discord Chat | Citizenship | Executive Staff | North Pacific Army | World Assembly Ministry | Roleplay | Trading Cards | Handbook

User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Thu Mar 05, 2020 7:23 am

The Northern Light wrote:Can I suggest linking this thread in the OSRS, in the scripting section? Otherwise, it is very hard to track down --- indeed, in my experience, a lot of coders are not even aware of all these intricate simultaneity rules.

I have done that.
Roavin wrote:For use with jQuery, you can do something similar to this line to disable buttons before performing a request:

Code: Select all
$('form input[type="submit"], form button').attr("disabled", true).addClass("disabledForSimultaneity");


Then, when a request completes (for example, in your jqXHR.always() callback), do the following:
Code: Select all
$('.disabledForSimultaneity').removeAttr("disabled").removeClass("disabledForSimultaneity");


This approach has the advantage of not re-enabling things that were meant to be disabled.

Shamelessly stolen.
Last edited by Eluvatar on Thu Mar 05, 2020 7:30 am, edited 1 time in total.
To Serve and Protect: UDL

Eluvatar - Taijitu member


Return to Technical

Who is online

Users browsing this forum: Afria Thebel, Autumn Meadows, Beaufort, Bormiar, Disruptia, Kractero, Reyo, The Southern Dependencies, Three Galaxies, Tungstan, Verwis

Advertisement

Remove ads