Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2017-04-22 18:05:54, last edited by LukeM (2017-04-22 21:03:51)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Javascript PlayerIO is finally out

So, Javascript PlayerIO is out

This means a few things can now happen:

UnitEE can now be web-based as well, as I believe that the javascript library can be used with WebGL, which means there can still be a browser version of EE

We can now easily make web-based bots, without needing to use flash, all you need to do is have a <script> tag in a website for the library, and another for the actual bot
Code to connect with JavaScript:

global = {
	client: null,
	connection: null,
	players: {}
}

function Start() {
	var email = prompt("Email: ");
	var password = prompt("Password: ");
	var worldID = prompt("World ID: ");
	
	PlayerIO.authenticate("everybody-edits-su9rn58o40itdbnw69plyw", "simpleUsers", { email: email, password: password }, {}, function(client) {
		global.client = client;
		Log("Authenticated");
		global.client.bigDB.load("config", "config", function(config) {
			Log("Loaded config");
			global.client.multiplayer.createJoinRoom(worldID, "Everybodyedits" + config.version, true, null, null, function(connection) {
				global.connection = connection;
				Log("Connected");
				global.connection.addMessageCallback("*", OnMessage);
				global.connection.send("init");
			}, CallbackError);
		}, CallbackError);
	}, CallbackError);
}

function Log(text) {
	console.log(text);
}

function CallbackError(error) {
	Log("Error: " + error.code + ": " + error.message);
}

function OnMessage(message) {
	switch(message.type) {
		case "init":
			Log("init recieved");
			global.connection.send("init2");
			break;
		case "init2":
			Log("init2 recieved");
			break;
		case "add":
			global.players[message.getInt(0)] = message.getString(1);
			break;
		case "left":
			delete players[message.getInt(0)];
			break;
		case "say":
			Log(global.players[message.getInt(0)] + ": " + message.getString(1));
			break;
	}
}

Start();

Offline

#2 2017-04-22 18:07:55

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: Javascript PlayerIO is finally out

You connect using the good old playerIO.Authenticate method.

Offline

#3 2017-04-22 20:25:40, last edited by LukeM (2017-04-22 20:39:00)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

Ive managed to log in (with the code in the OP), but havent managed to join a world yet, as the default 'public' connectionID doesnt have permission

Does anyone know what connectionID we should use?

Edit: Ive done some googling, and it seems that QuickConnect doesnt even use a connectionID internally, so we might not be able to join at all?

Offline

#4 2017-04-22 20:38:48, last edited by hummerz5 (2017-04-22 20:46:13)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: Javascript PlayerIO is finally out

destroyer123 wrote:

Ive managed to log in (with the code in the OP), but havent managed to join a world yet, as the default 'public' connectionID doesnt have permission

Does anyone know what connectionID we should use?

it's been forever for me. "private" requires some sort of secret key doesn't it? Then idk

edit: what HG seems legit

also does this do anything, perhaps ? https://playerio.com/documentation/refe … ickConnect
I mean, it's only registration, but surely we could find a way that doesn't constantly register

edit2: could remove the "register: true" flag

Offline

#5 2017-04-22 20:41:39

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

hummerz5 wrote:

it's been forever for me. "private" requires some sort of secret key doesn't it? Then idk

just tested it, and it returns this:

Error: UnknownConnection: The connection requested is not known by the server

That is also what happened when I typed in something random, so im guessing that there isnt a way to connect with ID 'private'

Offline

#6 2017-04-22 20:43:29

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: Javascript PlayerIO is finally out

Try "simpleUsers"

Offline

#7 2017-04-22 20:46:39, last edited by LukeM (2017-04-22 21:02:54)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

HG wrote:

Try "simpleUsers"

That worked //forums.everybodyedits.com/img/smilies/big_smile
Thanks

I tried SimpleUser, but not simpleUsers //forums.everybodyedits.com/img/smilies/tongue

Edit: Well... it worked once, but now it doesnt seem to do anything...
It doesnt call the connected, or error functions...

Edit 2: Well... It now seems to only work once per world...

Edit 3: Not sure why it stopped working, I closed and reloaded my browser and now it works again

Offline

#8 2017-04-22 22:26:05

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: Javascript PlayerIO is finally out

Hey guys, incase you run into the error where you're trying to detect blocks but javascript is picky about UInt vs Int so you have to do message.getUInt() instead of message.getInt() but then yo urealize uints are a mess -

var objects = message._internal_("get-objects", null);
// objects[3] is the id of the block in case "b"

works in both versions of the JS

Offline

#9 2017-04-22 22:42:55, last edited by drunkbnu (2017-04-22 22:49:24)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: Javascript PlayerIO is finally out

ninjasupeatsninja wrote:

Hey guys, incase you run into the error where you're trying to detect blocks but javascript is picky about UInt vs Int so you have to do message.getUInt() instead of message.getInt() but then yo urealize uints are a mess -

var objects = message._internal_("get-objects", null);
// objects[3] is the id of the block in case "b"

works in both versions of the JS

Or you can simply convert the uint to int with the << operator.

// MyInteger is the uint you want to convert to int
MyInteger <<< 0

Offline

Wooted by:

#10 2017-04-22 22:52:13, last edited by LukeM (2017-04-22 22:56:03)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

ninjasupeatsninja wrote:

Hey guys, incase you run into the error where you're trying to detect blocks but javascript is picky about UInt vs Int so you have to do message.getUInt() instead of message.getInt() but then yo urealize uints are a mess -

var objects = message._internal_("get-objects", null);
// objects[3] is the id of the block in case "b"

works in both versions of the JS

Yep, Ive done that too //forums.everybodyedits.com/img/smilies/big_smile

Are you having problems connecting sometimes? For some reason sometimes createJoinRoom doesnt seem to do anything...

HG wrote:

Or you can simply convert the uint to int with the << operator.

// MyInteger is the uint you want to convert to int
MyInteger <<< 0

The problem is that the playerIO library just refuses to return the value if you dont use the correct .getSomething method, its nothing to do with js... Im not sure why they've done that, I dont think any other versions do

Offline

#11 2017-04-22 22:59:41, last edited by SirJosh3917 (2017-04-22 23:00:56)

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: Javascript PlayerIO is finally out

destroyer123 wrote:

Are you having problems connecting sometimes? For some reason sometimes createJoinRoom doesnt seem to do anything...

yea it's really weird
im using latest firefox, i just open a new tab and paste in the same URL and it works again.

HG wrote:

Or you can simply convert the uint to int with the << operator.

// MyInteger is the uint you want to convert to int
MyInteger <<< 0

question : you say "with the << operator"
however in the code you have "MyInteger <<< 0"
which one?

also it should be MyUnsignedInteger for clarification between int and uint

but thanks for that!

Offline

#12 2017-04-22 23:02:15, last edited by drunkbnu (2017-04-22 23:05:01)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: Javascript PlayerIO is finally out

destroyer123 wrote:
ninjasupeatsninja wrote:

Hey guys, incase you run into the error where you're trying to detect blocks but javascript is picky about UInt vs Int so you have to do message.getUInt() instead of message.getInt() but then yo urealize uints are a mess -

var objects = message._internal_("get-objects", null);
// objects[3] is the id of the block in case "b"

works in both versions of the JS

Yep, Ive done that too //forums.everybodyedits.com/img/smilies/big_smile

Are you having problems connecting sometimes? For some reason sometimes createJoinRoom doesnt seem to do anything...

HG wrote:

Or you can simply convert the uint to int with the << operator.

// MyInteger is the uint you want to convert to int
MyInteger <<< 0

The problem is that the playerIO library just refuses to return the value if you dont use the correct .getSomething method, its nothing to do with js... Im not sure why they've done that, I dont think any other versions do

My suggestion was that you could get the uint from the message, then convert it to int to save it on your int blocks array.

ninjasupeatsninja wrote:

question : you say "with the << operator"
however in the code you have "MyInteger <<< 0"

<<< is an extended overload for <<, just like all other integer arithmetic operators have one (+ and +=, - and -=)

Offline

#13 2017-04-22 23:05:18

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: Javascript PlayerIO is finally out

HG wrote:

<<< is an extended operator, just like all other integer arithmetic operators (+ and +=, - and -=)

so <<< and not <<, correct?

Offline

#14 2017-04-22 23:07:28, last edited by LukeM (2017-04-22 23:08:24)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

HG wrote:

My suggestion was that you could get the uint from the message, then convert it to int to save it on your int blocks array.

Javascript doesnt really care about types, I dont think there is even a difference between the ints and uints internally within playerIO
The original 'picky about UInt vs Int'ness is from PlayerIO requiring you to use the correct getThing method instead of just being able to use all the number ones interchangably (like you can do in the C# version):

		function get(index, type) {
			if (index > objects.length) {
				throw _pio.error("this message (" + self.type + ") only has " + objects.length + " entries");
			} else {
				if (types[index] == type) {
					return objects[index];
				} else {
					throw _pio.error("Value at index:" + index + " is a " + getTypeString(types[index]) + " and not a " + getTypeString(type) + " as requested. The value is: " + objects[index]);
				}
			}
		}

It doesnt matter what the actual type of the object is, if you call getLong then if the type isnt a long, it throws an error

Offline

#15 2017-04-22 23:10:53, last edited by drunkbnu (2017-04-22 23:13:12)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: Javascript PlayerIO is finally out

ninjasupeatsninja wrote:
HG wrote:

<<< is an extended operator, just like all other integer arithmetic operators (+ and +=, - and -=)

so <<< and not <<, correct?

It's the same, as in...

i <<< 4

...would equal to...

i = i << 4

<<< is not an operator, it's an overload. I mentioned the operator.

destroyer123 wrote:
HG wrote:

My suggestion was that you could get the uint from the message, then convert it to int to save it on your int blocks array.

Javascript doesnt really care about types, I dont think there is even a difference between the ints and uints internally within playerIO
The original 'picky about UInt vs Int'ness is from PlayerIO requiring you to use the correct getThing method instead of just being able to use all the number ones interchangably (like you can do in the C# version):

		function get(index, type) {
			if (index > objects.length) {
				throw _pio.error("this message (" + self.type + ") only has " + objects.length + " entries");
			} else {
				if (types[index] == type) {
					return objects[index];
				} else {
					throw _pio.error("Value at index:" + index + " is a " + getTypeString(types[index]) + " and not a " + getTypeString(type) + " as requested. The value is: " + objects[index]);
				}
			}
		}

It doesnt matter what the actual type of the object is, if you call getLong then if the type isnt a long, it throws an error

Then request to get the proper type and convert it locally. That's what the protocol is for.

The real mess is on the server, for messing with int/uint for blocks.

Offline

#16 2017-04-22 23:44:21

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: Javascript PlayerIO is finally out

It appears when i use ".joinRoom" method instead of "createJoinRoom", i'm able to refresh the page and join the world.
Here's some code that will determine between using joinRoom and createJoinRoom so that nobody ever runs into this problem again.

global = {
	client: null,
	connection: null,
	players: {}
}

function Start() {
	var email = prompt("Email: ");
	var password = prompt("Password: ");
	var worldID = prompt("World ID: ");
	
	PlayerIO.authenticate("everybody-edits-su9rn58o40itdbnw69plyw", "simpleUsers", { email: email, password: password }, {}, function(client) {
		global.client = client;
		Log("Authenticated");
		global.client.bigDB.load("config", "config", function(config) {
			Log("Loaded config");
			
			Log("Determining joinRoom or createJoinRoom");
			
			var rooms = global.client.multiplayer.listRooms("Everybodyedits" + config.version, null, 0, 0, function(roominfo) {
				
				var methodOfJoining = false; //createjoinroom
				for(var i = 0; i < roominfo.length; i++) {
					if(roominfo[i].id == worldID) {
						methodOfJoining = true; //joinroom
					}
				}
				
				if(methodOfJoining) {
					global.client.multiplayer.joinRoom(worldID, null, function(connection) {
						global.connection = connection;
						Log("Connected");
						global.connection.addMessageCallback("*", OnMessage);
						global.connection.send("init");
					}, CallbackError);
				} else {
					global.client.multiplayer.createJoinRoom(worldID, "Everybodyedits" + config.version, true, null, null, function(connection) {
						global.connection = connection;
						Log("Connected");
						global.connection.addMessageCallback("*", OnMessage);
						global.connection.send("init");
					}, CallbackError);
				}
			}, CallbackError);
		}, CallbackError);
	}, CallbackError);
}

function Log(text) {
	console.log(text);
}

function CallbackError(error) {
	Log("Error: " + error.code + ": " + error.message);
}

function OnMessage(message) {
	switch(message.type) {
		case "init":
			Log("init recieved");
			global.connection.send("init2");
			break;
		case "init2":
			Log("init2 recieved");
			break;
		case "b":
			var objects = message._internal_("get-objects", null);
			var id = objects[3];
			var x = objects[1];
			var y = objects[2];
			
			if(id == 14) {
				global.connection.send("b", 0, x, y, 9);
			}
			if(id == 9) {
				global.connection.send("b", 0, x, y, 0);
			}
		break;
		case "add":
			global.players[message.getInt(0)] = message.getString(1);
			break;
		case "left":
			delete players[message.getInt(0)];
			break;
		case "say":
			Log(global.players[message.getInt(0)] + ": " + message.getString(1));
			break;
	}
}

Start();

This should fix your having to close/open your browser/tab

Offline

#17 2017-04-23 00:19:55, last edited by LukeM (2017-04-23 00:20:08)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

^ Seems to work so far //forums.everybodyedits.com/img/smilies/big_smile

Ill continue testing, and if the 'cant join' thing doesnt happen again then ill change the OP

Offline

#18 2017-04-23 05:00:57

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: Javascript PlayerIO is finally out

hey guys, what does this change mean for EE? I mean, assuming botters choose to go this route. Do we even have botters?

A) What does this say about security of EE-related tools?
-- Web-available resources can be much more dynamic, but is there a risk in that? Should a read-only repository be considered, given that various users choose to do scans/decompilation to expose faulty security/phishing tools?

B) What does this say about capabilities of EE-related tools?
-- What advantages do we gain by being able to push things to a web instead of a downloadable? Not as windows-dependent, I imagine. Anything browser-oriented that's valuable?

C) I'm out of questions. Do we have people anymore who would flock to this sort of thing?

D) Oh wait, how much more common would "plagiarism" be given that everything's out there?

Food for thought, debate any and all with me? lol

Offline

#19 2017-04-23 09:13:52, last edited by LukeM (2017-04-23 09:15:56)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

A) JavaScript is only supposed to run in browsers, this means that (as far as I know) there is no way to actually edit files on someone's computer without using external browser plugins. There is no guarantee though that the bot won't just send your email and password to some server somewhere, but there wasn't with downloadable bots either.

B) The main advantage is, as you say, that we can run bots on any OS, and that it's a bit easier for users who don't want to download a bot (being online also means you don't need to worry about updates). There is also the fact that JS is a scripting language, so it makes adding 'plugins' a lot easier (I have a few ideas for using this)

C) Personally, I've been looking at trying to make a browser based bot for a while now, and now that PlayerIO js is out, that is much easier. There is also HG and ninjasupeatsninja who also seem interested in making js bots
Edit: And it seems lrussel and Emalton are also making bots //forums.everybodyedits.com/img/smilies/big_smile

D) With JavaScript there is basically no way to protect your source code, apart from minification, which makes it harder to understand how it works (and makes the file size smaller), but this might not be a bad thing, it could be basically the same as forcing every bot to be open source

Offline

#20 2017-04-23 11:31:22, last edited by LukeM (2017-04-23 11:31:59)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

While testing my bot, the couldnt connect thing happened again (while using ninja's code, so I think its probably a playerIO problem), but this time Im getting this error:

The connection to ws://108.178.28.114/ was interrupted while the page was loading.

Just wondering if anyone else has also had this problem, and if anyone has managed to fix it

Also I tried using OnDisconnect, and it doesnt seem to be working, (im placing a lot of blocks, and sometimes it randomly disconnects, sometimes throwing an error (but not calling OnDisconnect), and sometimes just continuing as if its still connected)
Has anyone had this problem too?

Offline

#21 2017-04-23 12:59:06

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Javascript PlayerIO is finally out

Well, now that Javascript is out, imagine you'd have a little server running.
You could potentially use a website to let players turn your BAL on, on demand.

Aside from that you can also do something else funny: make stuff like Keep Talking and Nobody Explodes. Where one person (group) has one portion of the information, and the other the rest and they'd have to communicate to get through.
Obviously you can just do that through 2 EE rooms, but in a website you have way more control over what and how you display stuff, and make it generally more user-friendly.
The big problem with this idea, however, would be cheating. How are you going to make sure the player can ONLY be in one of the two: the EE room or the website? You can check for the IP on the website, but not on EE. Username is obviously a bad method too, since somebody can just make an alt account.

Offline

Wooted by:

#22 2017-04-23 14:26:10

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: Javascript PlayerIO is finally out

den3107 wrote:

You could potentially use a website to let players turn your BAL on, on demand.

javascript runs on someone's stuff, if there's an advantage, we'd assume it wasn't on my stuff because I already could run my stuff

so my question, they would have to run the BAL themselves.. is there a way to authenticate without giving them the username/password?

Offline

#23 2017-04-23 15:08:17, last edited by Processor (2017-04-23 15:09:30)

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: Javascript PlayerIO is finally out

hummerz5 wrote:
den3107 wrote:

You could potentially use a website to let players turn your BAL on, on demand.

javascript runs on someone's stuff, if there's an advantage, we'd assume it wasn't on my stuff because I already could run my stuff

so my question, they would have to run the BAL themselves.. is there a way to authenticate without giving them the username/password?

Yes there is, but nothing stops them from using the connection to break the rules and get your account banned, sadly.

Also, guys, Socket.IO has always existed if you wanted to do anything multiplayer in the browser.


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

Wooted by:

#24 2017-04-26 02:37:10, last edited by Cyral (2017-04-26 02:44:16)

Cyral
Member
From: United States
Joined: 2015-02-15
Posts: 2,269

Re: Javascript PlayerIO is finally out

I think what Processor is getting at, and what makes the most sense, is to run the bot on your own server (programmed in any language that has the Player.IO SDK), and control it from a webpage.

You've never needed the Player.IO JavaScript SDK to do this, and it would be beneficial to not use it if you are interested in protecting your source code or credentials. Essentially you could write the bot in whatever you want, and use Socket.IO (or any Websockets library) to communicate with that bot. For example, you could have a button on a webpage send a message to your bot, hosted on a server, to run a certain function. The bot would execute that, and your logic would all be private, just exposing a communication method so it could be controlled from the web.

When you are using the JS SDK, you are creating an instance of the bot's connection whenever you use the webpage, rather than having a persistent bot running behind the scenes. (Which is why I am confused at the "24/7" aspect of this, when it is really just for the duration of the webpage unless you do what I described)

Note that this advice applies to traditional BALs and not bots that are meant to be distributed and ran by anyone.


Player Since 2011. I used to make bots and stuff.

Offline

Wooted by: (3)

#25 2017-04-26 08:23:54

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: Javascript PlayerIO is finally out

I agree ^

I'm not personally going to convert any BALs to JavaScript as there isn't much of an advantage, as you've said
The thing that JavaScript excels at is having bots like NinjaBot or EEditor, which people could use by connecting to a website, instead of needing to download it, and if you're not on Windows, also setting up some third party .net thing
I personally have quite a few ideas, and I'm in the process of setting a few of them up right now (not giving any spoilers)

Offline

SmittyW1493931057658521

Board footer

Powered by FluxBB

[ Started around 1732394291.7776 - Generated in 0.182 seconds, 12 queries executed - Memory usage: 1.79 MiB (Peak: 2.07 MiB) ]