This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Exerro's profile picture

multiplayer online game using http

Started by Exerro, 26 December 2012 - 12:37 PM
Exerro #1
Posted 26 December 2012 - 01:37 PM
Hi, i was thinking about making a 2d minecraft game but it seems kind of pointless (play a crappy version of a game inside the game) so i thought i could make it multiplayer…but….idk if u can write to a website using http or communicate with other pcs in any way…? can someone explain how to (if possible) write to a website
BustedEarLobes #2
Posted 26 December 2012 - 03:19 PM
Hmm, I recommend using rednet instead of http. I assume you want to have it so you can play with multiplayer cross server. However, in order to use http you would have to have a server (Can range from 50 - 300$ per month for a decent one) and a domain. There are free server hosts you can look into but they may not have what you are looking for. On top of that you also have to know PHP and HTML. If you are up to it, you can pm me and I can help you with it (though it will take lots of time and reading on your own).
ChunLing #3
Posted 26 December 2012 - 05:57 PM
On the other hand, if you had the game run over http then people who weren't on your minecraft server (or using minecraft at all) could join your game. Of course, that raises the question of why anyone would play from inside of their minecraft game.
BustedEarLobes #4
Posted 26 December 2012 - 06:45 PM
On the other hand, if you had the game run over http then people who weren't on your minecraft server (or using minecraft at all) could join your game. Of course, that raises the question of why anyone would play from inside of their minecraft game.

Good point. Not only that, but anyone can hack the game by just sending data via http like

http.post("www.myserver.com/game/game.php?health=999999999999999999999999999999")

to the server.
Exerro #5
Posted 27 December 2012 - 12:36 AM
i know i would be able to it well i just want to know if it is possible…and i think fro what i've heard it is…anyway thanks for all the help
Could you do something like this with a webs website?
Sammich Lord #6
Posted 27 December 2012 - 01:37 AM
On the other hand, if you had the game run over http then people who weren't on your minecraft server (or using minecraft at all) could join your game. Of course, that raises the question of why anyone would play from inside of their minecraft game.

Good point. Not only that, but anyone can hack the game by just sending data via http like

http.post("www.myserver.com/game/game.php?health=999999999999999999999999999999")

to the server.
That is why you keep ALL player data server-side.

i know i would be able to it well i just want to know if it is possible…and i think fro what i've heard it is…anyway thanks for all the help
Could you do something like this with a webs website?
Webs does not have a feature to use PHP. You will have to learn PHP(Or any other server-side scripting language), write a script that responds to requests sent by the client. But there is one major problem… spamming HTTP will crash a server. I have personally encountered this on CCNET(A no longer running CC server) which crashed due to a script that checked for updates on startup, so whenever the computer started up it sent a HTTP request, there is nothing wrong with that if you have 5 computers doing that but if you have about 50-100 HTTP requests at once it can easily crash the server. There is also another problem, normal games such as Minecraft or any other game that uses networking constantly sends packets of data to the server or host(Host is for peer-peer networking games) at rapid rates, which you cannot accomplish with HTTP. You will have to come up with a in-genius way of having minimal packets sent but still keep a steady network connection. So this is very hard work.
Exerro #7
Posted 27 December 2012 - 02:21 AM
i would do it by sending an initial map doc when the game is loaded then when a player interacts with anything it just sends that data to the server and to other pcs so they would listen for "playermove" events or "blockplaced" events…
zekesonxx #8
Posted 27 December 2012 - 02:40 AM
For starters, a server is not $50-300 a month. If that's what your paying you either have a popular website or are getting ripped off horribly.

You would need to keep all data changing server-side, so instead of login.php?name=Zeke&health=20 it would be login.php?name=Zeke&pass=Password, and instead of attack.php?sethealth=1&name=Candy it would be attack.php?name=Candy&move=Super+Amazing+Fireball.

And there is no such thing as real-time. You need the Sockets peripheral to do anything along those lines.

–Bottom Line–
Rednet: Yes. HTTP: Kinda
Exerro #9
Posted 27 December 2012 - 03:03 AM
well….as its possible….anyone want to help?
Sammich Lord #10
Posted 27 December 2012 - 03:30 AM
well….as its possible….anyone want to help?
It is POSSIBLE but it will take a lot of skill and knowledge. You will have to still find the best way to send a low amount of packets to the server but still have fluent gameplay. If your idea is kinda like Terraria then it is highly unlikely. You would have to send raw packets to the server, get the movement aproved by the server, send another packet to the client saying you can move, then send a packet to all other clients within range to register the movement. it is still pretty much impossible without spamming HTTP. Like I have stated before, spamming HTTP is bad and Cloudy has talked about adding a timer to HTTP requests so you can't spam the constantly. Rednet would be completely possible. You can have global stats stored in a MySQL database on a webserver and do all the networking in rednet. What I am getting to is that rednet would be much easier and much more stable then HTTP. If you really want to pull this off you would have to use the socket peripheral.
Exerro #11
Posted 27 December 2012 - 05:51 AM
server has the blocks etc then when something happens it broadcasts that to all connected pcs…all the collision and stuff would be one by the pcs
Left4Cake #12
Posted 27 December 2012 - 12:53 PM
Hmm, I recommend using rednet instead of http. I assume you want to have it so you can play with multiplayer cross server. However, in order to use http you would have to have a server (Can range from 50 - 300$ per month for a decent one) and a domain. There are free server hosts you can look into but they may not have what you are looking for. On top of that you also have to know PHP and HTML. If you are up to it, you can pm me and I can help you with it (though it will take lots of time and reading on your own).

You don't have to have a domain (however, if you can afford a server you may as well get one), since one can always just type in the ip (url = "http://235.123.4.123" for example)

Also you can/may only want to make turn-base instance games, like online chess, or scrabble, and not something like this sadly. Unless maybe you could do a host + spectator system, where all other players are just ghost visiting someone else work. That way the server really only need to send map changes to the other clients, witch would just be uploading and downloading the save file, on second thought, may be not.
BustedEarLobes #13
Posted 27 December 2012 - 01:18 PM
For starters, a server is not $50-300 a month. If that's what your paying you either have a popular website or are getting ripped off horribly.

You would need to keep all data changing server-side, so instead of login.php?name=Zeke&health=20 it would be login.php?name=Zeke&pass=Password, and instead of attack.php?sethealth=1&name=Candy it would be attack.php?name=Candy&move=Super+Amazing+Fireball.

And there is no such thing as real-time. You need the Sockets peripheral to do anything along those lines.

–Bottom Line–
Rednet: Yes. HTTP: Kinda

Most servers are well over 50$, and for what he's trying to do, he would need a good one. PHP is fast, but having to force a web server to exchange data for a game like that would be slow and could crash or use up the bandwidth on the server. On top of that "attack.php?name=Candy&move=Super+Amazing+Fireball" would not work as anyone can STILL type that in and have the server calculate it.

Oh, and if you didn't think all this is hard enough, you would also pretty much have to look into mySQL for the player data base instead of making your own PHP one.

Basically, the http api is not really meant for games that exchange tons of data.
dissy #14
Posted 27 December 2012 - 01:35 PM
Most servers are well over 50$, and for what he's trying to do, he would need a good one.

You can get a VPS anywhere from $20 up. If you know Linux, I highly recomend linode.com for virtual private servers.
I have 6 machines with them across 4 countries and for all of them only pay $250/mo, and have been a customer of theirs for about 6 years now. Some of my machines are not the low end package either, and have extra IPs, all of which cost extra.
At the moment, those 6 linodes are half of my 11 server fleet. That's how impressed and happy I've been with their service.

Of course using a Linux VPS assumes you know how to administer a linux machine remotely.
A managed server (where someone else administers it for you) can easily cost $50-200/mo depending on what level of access you need.

To awsumbem13: For this particular project however, I'm not completely sure such a server would be needed.
You can always start out on a simple web host for $5/mo and do your development… Perhaps beta testing with 5-6 other people.
Get your backend code down, and then see how much bandwidth, storage, and memory are used up by those 5-6 people. Extrapolate out from there.
A basic web host might even be able to handle more users than that.
Is your end goal to only have 16 users? If your minecraft server only has 16 slots, that would be a good assumption, and you may be fine with a cheap web host plan.
Or is your goal hundreds of users? If so you likely will not have much choice than either running your own server, or having someone who knows how to so for you.
Left4Cake #15
Posted 29 December 2012 - 08:59 AM
On top of that "attack.php?name=Candy&move=Super+Amazing+Fireball" would not work as anyone can STILL type that in and have the server

The only problem is the name=Candy part. You could have their server create a Session ID, and then store it on the computer and server. It should be encrypted and should also expire if the server gose to long with out hearing anything from the client. Not the best screty but whould reqire more work then:
Exerro #16
Posted 29 December 2012 - 09:28 PM
Thanks for all the feedback :)/> all i need is a way to relay the information…i can adapt the ingame programs to make sense of it but i could do with some help….i will also add in a 'lan' mode that uses rednet