Hi, this is my little peripherals mod. I made it for 1.5.1, when I was still quite new to modding. I added a port of Portable Peripherals not long after that, and the code got messy to maintain. Now I rewrote it for 1.6.2, however, the Portable Peripherals port is not here anymore.
The new version was made for 1.6.2, but it also works on 1.6.4 (for me, at least).
Without further ado,
Peripheral(s)
HTTP Server Module,
^ shown above is the first texture of v1. It's changed now.
Usage
Spoiler
Wrap the peripheral as usual.Call (where p is your wrap) p.start() to start the service, and p.stop() to stop it.
While the service is running, your computer can receive an event - "http_server_request".
To trigger this event, someone must open a web browser (or other Internet-accessing thing) to the webserver.
By default, the webserver runs on port 8080. This may require port forwarding if you host a server.
And the address should be whatever server you are playing on.
Single player possibilities:
localhost:8080
127.0.0.1:8080
0.0.0.0:8080
Server (using random names):
mcserver.eu => mcserver.eu:8080
playmc.com:26943 => playmc.com:8080
I hope this makes sense to you, I'm still at a loss of how to explain that. Anyway, pop the new address into your browser and you should see a page asking you to enter a Computer/Turtle's ID.
If my private server is currently running, you can see an example here: http://sl.teamredscript.com:8080/
Once you do so, and hit the button, it will change the URL to add that ID. It pretty much just adds the id to the URL, like http://sl.teamredscript.com:8080/5/
Okay, now back to the events.
If I access the URL http://sl.teamredscript.com:8080/5/ ,
computer 5 would receive an event:
Name: http_server_request
RequestID: 0
URL: /
Query Table (Lua Table): {}
Cookie Table (Lua Table): {}
This is when you should process the request. We will simply write back a page informing the user what URL they accessed, and set a cookie containing this information (for whatever reason)
p.setCookie(requestID, cookieName, cookieValue)
will set a cookie in the browser of name and value provided. Use the request ID you receive from the event.
p.respond(requestID, responseText, contentType*)
* optional
Use the request ID you receive from the event. ResponseText is what is wrote back to the browser.
Content type is the mime-type of your response. It defaults to "text/html" (HTML). If you want to show as text, you can use "text/plain".
If you need any clarification with this please ask ^^.
Config option configures whether or not the webserver runs, and which port, plus the block Id. The webserver only starts on the ServerStarting event, so not at the main menu, but only while in a world. The webserver does NOT exist on the client when connected to a MP server.
Oh, I nearly forgot (like the idiot I am ^^), Download:
Latest Version 2.0-3 for 1.6.x
All Versions, plus Links to each version's github (SOURCE CODE) tag
GitHub
version 1: Old Post
Spoiler
Attention: I will be porting this over the next few days to 1.6.2. It's about time, don't you think? :)/>At that time I will clean up the code a lot, and seperate PortablePeripherals again from my code. I suspect if/when PDAs are implemented in vanilla CC it won't be necessary, then I will port it again to the latest CCDesk if that's needed, but no promises.
~ TSL, 24 August 2013 at 13:20 GMT+1
Old Post
Spoiler
Hello everyone, this is my first PUBLIC ComputerCraft mod here. I plan to extend it, though I don't know what with.If you have good ideas, feel free to suggest them, I'll try and put some in. Anyways, on with the mod.
Have you ever messed with the HTTP api, maybe so that you can put a web interface on your world? I have, but I thought it would work out better if ComputerCraft was the webserver (and not a client constantly checking somewhere else for commands).
I made it.
This peripheral starts a webserver ( powered by Simple Framework, http://www.simpleframework.org/ ) that can interact with your computers.
Crafting:
If picture does not show:
[ REDSTONE ] [ REDSTONE TORCH ] [ REDSTONE ]
[ GOLD INGOT ] [ IRON BLOCK ] [ GOLD INGOT ]
[ GOLD INGOT ] [ IRON INGOT ] [ GOLD INGOT]
makes
1 HTTP Server Service Module
USAGE:
Spoiler
Okay, I lied. The peripheral doesn't really start a webserver, that'd be too many webservers. I was smarter than that. When your game starts, a webserver is started. Only one.When you start up the peripheral, the computer is given a subdirectory to reside in. It never sees outside. This is called a "service"
So, yes.
Wrap the "HTTP Server Service Module" (crafted above) like you would a normal peripheral.
Use the "start" method to start the service.
Use the "stop" method to stop the service.
Next: dealing with HTTP Requests
So, if you have computer ID 5, your URL will be at:
http://localhost/5/a_page
Please note that localhost should be the IP (or localhost if you play in SP), and if you change the port add : then the port number.
When an event is sent to your computers service, the computer receives an event called "http_server_request". Pay attention to the underscores.
The event also has 3 parameters.
Request Id - You will need to give this ID back when you respond to the request.
URL - This will be something like /a_url if http://localhost/5/a_url was visited.
Query - This is a table of the GET and POST variables. This means you can use forms.
It can be accessed like query.aValue for the aValue field, also like query["aValue"]… A Normal Lua Table.
Now you have to respond. To do this, use the "respond" method of the peripheral. You must use it like so:
http.respond(Request ID, HTML/Content to go Back)
If you want to use images you will have to link them from a website, I think.
If you notice at http://localhost/ there is a default message. Pretty simple.
If you are playing on a server with it installed, the IP address is most likely the same as the Minecraft Server.
Here is an example program that takes the peripheral on top of the computer, starts the service then waits for 1 request. When it gets this, it will show the request ID, the URL, and the Query vars in the computer console. It will also send back 'You are at URL: (url)' to the browser.
http = peripheral.wrap('top')
http.start()
id, req, url, query = os.pullEvent('http_server_request')
print('Request ID: ' .. req)
print('Accessing URL: ' .. url)
for k,v in pairs(query) do
print('Query Var ' .. k .. ' = ' .. v)
end
resp='You are at URL:
'
resp=resp..url
http.respond(req, resp)
http.stop()
Configuration (CONFIG):
Spoiler
You can edit the block ID of the peripheral.You can disable crafting of the HTTP Server Service Module.
You can enable Debug Mode. This is pretty much for me when I couldn't figure out why the peripherals weren't connecting.
You can enable/disable the HTTP Server.
You can also change the port of the HTTP Server. This could be useful if you already have a server on port 80.
Different style of documentation
Spoiler
Peripheral Name: http-serverMethods:
start() // starts SERVICE
stop() // stops SERVICE
respond(Request_ID, ContentBody) // headers are sorted for you, and untouchable. - until further notice
Events (only when SERVICE is started)
http_server_request:
Request Identifier (pass to respond)
URL (http://server-ip/computer-id/aUrl => /aUrl)
Query table (GET and POST variables, preprocessed courtesy of Simple Framework)
More about accessing your webserver:
Spoiler
I've been mentioning localhost all the way through. This is your server IP. On single player, you can use 127.0.0.1 or localhost as this is your server's IP. If you use a port other than 80 (in config file) you WILL NEED TO PUT A colon ( :)/> then the port number after the IP/address. Example: localhost:8080If your server is on a domain, that works too (play.serversite.com), and same port rules apply.
Hello everyone, here is my peripheral mod. Before you start reading the post, I'll shove credits at the top:
Credits
mentlerd - creating the original PortablePeripherals (the mod was discontinued so I ported it into my mod)
Simple Framework - http://www.simpleframework.org/ (this is the engine used for the HTTP Server)
Peripherals
HTTP Server Service Module
peripheral.getType( side ) = http-server
This allows you to host a "service" on HTTP.
By visiting http://SERVER ADDRESS:HTTP PORT/COMPUTER ID/ (i.e. http://play.a-mc-server.com:8080/5/),
you can see the service. By using the chat command /slp, you can see the status of the webserver. If it's enabled it'll tell you the port. The port number can be changed in the config.
Warning: Linux users (like me) will need to either use a port number above 2048 or run the game as root. As a word of advice, DO NOT run the game as root, EVER. So just use a port number like 8080. If you use a port which you don't have permission to open, typing /slp will yield:
Oh, and if you're playing singleplayer, the address will be 127.0.0.1.
And if you're trying to access the server from the computers ingame (i.e. the http api), it's also 127.0.0.1
http-server:
methods
isActive() - returns whether the HTTP Server is enabled in the config
start() - Starts servicing
stop() - Stops servicing
respond(request_id, response_text) - responds to REQUEST_ID with RESPONSE_TEXT as HTML
events
http_server_request:
Request Identifier (pass to respond)
URL (http://server-ip/computer-id/aUrl => /aUrl)
Query table (GET and POST variables, preprocessed courtesy of Simple Framework)
Cookie Table (as of 1.3)
example: e, request_id, url, query, cookie = os.pullEvent('http_server_request')
Please see Portable Peripheral's origin post until I add the information here.
http://www.computerc...le-transmitter/
But watch out, the recipe changed to require Nether Quartz:
Changelog:
v1.3 (changes since 1.2)
- Relocated textures
- Cleaned up source code
- Added a port of PortablePeripherals (discontinued) by mentlerd to the mod. The quartz are now crafted like:
G
Q
G
where: G=Glass, Q=Nether Quartz
- Fixed Wireless Transmitter (PP) not persisting.
- Added cookies table parameter to http_server_request event
- You can find the demo files in the computer's slperiph/ directory after you mounted one of my peripherals. Currently there is mentlerd's transmit program for the Wireless Transmitter (PP).
Spoiler
v1.3pre1- Relocated textures
- Cleaned up source code
- Added a port of PortablePeripherals (discontinued) by mentlerd to the mod. The quartz are now crafted like:
G
Q
G
where: G=Glass, Q=Nether Quartz
!!! Major Bug: In this prerelease, items placed in the Transmitter block will be lost when you exit the world or unload the chunk. Will be fixed tomorrow.
v1.2
- Port to Minecraft 1.5.1
- Now uses Searge (SRG) names and takes advantage of runtime deobfuscation, it should be version-independant now, so it'll work on 1.5 even though it's built for 1.5.1.
- The top and bottom textures are now the heat vents I've had in the textures for a while. Servers do get hot sometimes.
v1.0b
- Now starts on ServerStarting Events (when you load an SP world or start an SMP server)
- Now stops on ServerStopping Events (so when you exit your SP world it's not still running).
- Updated textures to those provided by TheModerGuy
v1.0
- Initial Release.
Cool things:
Spoiler
Turtle Remote Control by Android (screenshot: see post)Anyways, have fun and if you'd like to see something in this please leave a suggestion.
Also leave feedback, bug reports, and such.
Oh, and of course, the download:
ComputerCraft Edition
v1.3: http://bit.ly/Yk4P4c (bit.ly for stats)
All Versions (Old + Prereleases): https://www.dropbox....kj/2Iw-U9YdXU?m
Source on github: https://github.com/T...is-peripherals/
CCDesk (Emulator) Edition
Please check the complete/missing list below to see the peripherals which are missing.
v1.3-a / Port of 1.3 revision A: http://bit.ly/179aygR (bit.ly for stats)
All Versions (Old + Prereleases): https://www.dropbox....6mq0/ZotIYgiADI
Source on github: https://github.com/T...lperiph-deskcc/
Complete/Missing:
- PortablePeripherals: Everything is missing
- SLP HTTP Server Service: Complete (v1.3, in v1.3-a)
If you make something cool with it, share it, I'm interested to see what you can do with it. I might add your creation to the post (with credit of course) and maybe ship it with the mod (if I start shipping demo files, that is).