Programming Beginner Bot Creator

Ok so I just started working on creating a bot, but my biggest obstacle has been using websocket to login. I made an account previously and now I'm trying to sign in. The response that I have gotten is:
|nametaken|USERNAME|Your assertion is stale. This usually means that the clock on the server computer is incorrect. If this is your server, please set the clock to the correct time.

I am assuming that it is treating it like a name change, so ya the name is taken, but it's taken by me?
 
Last edited:
Code:
var WebSocket = require("ws");
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

const USERNAME = "USERNAME";
const PASSWORD = "PASSWORD";
const ws = new WebSocket("ws://sim.smogon.com:8000/showdown/websocket");
var url = 'http://play.pokemonshowdown.com/~~showdown/action.php';


ws.addEventListener("open", () => {
    console.log("connected!");
});
ws.addEventListener("message", msg => {
    console.log(msg.data);
    console.log("");
    var msg_parts = msg.data.split('|');
    switch(msg_parts[1]){
        case "challstr":{
            console.log("received challstr");
            var id = msg_parts[2];
            var str = msg_parts[3];
            var assertion;
            var params;
            var http = new XMLHttpRequest();
            if(PASSWORD == null){
                params = "?act=getassertion&userid=" + USERNAME + "&challengekeyid=" + id + "&challenge=" + str;
                http.open('GET', url, true);
            }else{
                params = "act=login&name=" + USERNAME + "&pass=" + PASSWORD + "&challengekeyid=" + id + "&challenge=" + str;
                http.open('POST', url, true);
            }
            http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
            //http.setRequestHeader('Content-Length' , params.length);
            http.onreadystatechange = function(){
                if(http.readyState == 4){
                    //console.log("State: " + http.readyState + " Status: " + http.status + " Response: " + http.responseText);
                    var assID = http.responseText.search("assertion");
                    assertion = http.responseText.substring(assID + 12,http.responseText.length -2)
                }
            }
            http.send(params);
            console.log("sent login info");
            ws.send('|/trn ' + USERNAME +',0,' + assertion);
            //start_match();

            };
            break;
        case "player":
            if(msg_parts[3] == USERNAME)
                var playerNumber = msg_parts[2];
        case "request":{
            //console.log(battleParse(msg.data));
        }
        case "turn": {
            //makeMove();
        }          
}
});
My code is in javascript. Sorry if it's a little messy.
 
Last edited:

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top