This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
ComputerCraft MUD?
Started by elfin8er, 17 December 2012 - 01:39 PMPosted 17 December 2012 - 02:39 PM
Just wondering if anyone put any serious thought into making a computercraft MUD. May try and do it, but I'm not sure how to go about doing it. Should I use MYSQL, or rednet? Any tips or suggestions?
Posted 17 December 2012 - 02:44 PM
Just wondering if anyone put any serious thought into making a computercraft MUD. May try and do it, but I'm not sure how to go about doing it. Should I use MYSQL, or rednet? Any tips or suggestions?
I have seen some ASCII art based RPG's but none have been multiplayer. Are you thinking multiplayer within a server or multiplayer using the http api? Because if you used the http api that would be amazing
Posted 17 December 2012 - 02:46 PM
I wanted to use the HTTP API. I've been playing around with it a lot, but the hardest part would be allowing the server to send info to a computer. I can do it the other way around and have computercraft send to the server, but any ideas on how to have the server send info to the computer?Just wondering if anyone put any serious thought into making a computercraft MUD. May try and do it, but I'm not sure how to go about doing it. Should I use MYSQL, or rednet? Any tips or suggestions?
I have seen some ASCII art based RPG's but none have been multiplayer. Are you thinking multiplayer within a server or multiplayer using the http api? Because if you used the http api that would be amazing
Posted 17 December 2012 - 02:51 PM
Use http.post, it allows you to post data then get the output from the server. Just have a PHP script tell the client what to display.I wanted to use the HTTP API. I've been playing around with it a lot, but the hardest part would be allowing the server to send info to a computer. I can do it the other way around and have computercraft send to the server, but any ideas on how to have the server send info to the computer?Just wondering if anyone put any serious thought into making a computercraft MUD. May try and do it, but I'm not sure how to go about doing it. Should I use MYSQL, or rednet? Any tips or suggestions?
I have seen some ASCII art based RPG's but none have been multiplayer. Are you thinking multiplayer within a server or multiplayer using the http api? Because if you used the http api that would be amazing
Posted 17 December 2012 - 02:52 PM
You would have to have access to a raw text file with the information that has been sent. or what he said ^
You would probably need to make some sort of web based server.
You would probably need to make some sort of web based server.
Posted 17 December 2012 - 02:56 PM
But then wouldn't everything get mixed up? That's what I have for single player stuff. What if I saved everything to a text file. The text file could be likeYou would have to have access to a raw text file with the information that has been sent.
username: elfin8er
hp: 100
maxhp: 200
mp: 100
maxmp: 150
username: re8nifle
hp: 150
maxhp: 200
mp: 150
maxmp: 150
then have computercraft read it?
That's how I can send data to the server, but how do I get data from the server?Use http.post, it allows you to post data then get the output from the server. Just have a PHP script tell the client what to display.I wanted to use the HTTP API. I've been playing around with it a lot, but the hardest part would be allowing the server to send info to a computer. I can do it the other way around and have computercraft send to the server, but any ideas on how to have the server send info to the computer?Just wondering if anyone put any serious thought into making a computercraft MUD. May try and do it, but I'm not sure how to go about doing it. Should I use MYSQL, or rednet? Any tips or suggestions?
I have seen some ASCII art based RPG's but none have been multiplayer. Are you thinking multiplayer within a server or multiplayer using the http api? Because if you used the http api that would be amazing
Posted 17 December 2012 - 03:08 PM
Just request something. Like http.get("http://somewebserver.web/server.php?hi=111&hello=1111")
Then have the PHP script just output the data needed.
Then have the PHP script just output the data needed.
Posted 17 December 2012 - 03:10 PM
http.get()
I would be quite the challenge,
You could make a computer on a server that's up all the time, then make it so every time someone connects to the MUD server make it download the player connection file edit it to add that player. Then have the server get that file and add the player to the server, then have the mud server upload a user file to pastebin and add the link saved to the connected players file. Then have the cleint download the connected players file and get the address to the clients own player file.
Then base everything of that system
I would be quite the challenge,
You could make a computer on a server that's up all the time, then make it so every time someone connects to the MUD server make it download the player connection file edit it to add that player. Then have the server get that file and add the player to the server, then have the mud server upload a user file to pastebin and add the link saved to the connected players file. Then have the cleint download the connected players file and get the address to the clients own player file.
Then base everything of that system
Posted 17 December 2012 - 03:20 PM
I think I get it (maybe). So each person would sorta have their own pastebin file with all their player information on it?http.get()
I would be quite the challenge,
You could make a computer on a server that's up all the time, then make it so every time someone connects to the MUD server make it download the player connection file edit it to add that player. Then have the server get that file and add the player to the server, then have the mud server upload a user file to pastebin and add the link saved to the connected players file. Then have the cleint download the connected players file and get the address to the clients own player file.
Then base everything of that system
Sorry if I'm misunderstanding :P/>
Posted 17 December 2012 - 03:23 PM
This seems like an interesting project, I have a web server if you'd like to utilize it.
Posted 17 December 2012 - 03:24 PM
Got my own. Thanks though!This seems like an interesting project, I have a web server if you'd like to utilize it.
Posted 17 December 2012 - 03:26 PM
Pastebin bans you if you use it a ton. I suggest using a server-side MySQL database for player data so people don't hack their stats.I think I get it (maybe). So each person would sorta have their own pastebin file with all their player information on it?http.get()
I would be quite the challenge,
You could make a computer on a server that's up all the time, then make it so every time someone connects to the MUD server make it download the player connection file edit it to add that player. Then have the server get that file and add the player to the server, then have the mud server upload a user file to pastebin and add the link saved to the connected players file. Then have the cleint download the connected players file and get the address to the clients own player file.
Then base everything of that system
Sorry if I'm misunderstanding :P/>
Posted 17 December 2012 - 03:29 PM
What if I used a php script, that would get each users info, and save it to a file on my web server? Each user would have their own user file with all of their info stored on it. Would I even need a MySQL database then?Pastebin bans you if you use it a ton. I suggest using a server-side MySQL database for player data so people don't hack their stats.I think I get it (maybe). So each person would sorta have their own pastebin file with all their player information on it?http.get()
I would be quite the challenge,
You could make a computer on a server that's up all the time, then make it so every time someone connects to the MUD server make it download the player connection file edit it to add that player. Then have the server get that file and add the player to the server, then have the mud server upload a user file to pastebin and add the link saved to the connected players file. Then have the cleint download the connected players file and get the address to the clients own player file.
Then base everything of that system
Sorry if I'm misunderstanding :P/>
Posted 17 December 2012 - 03:32 PM
Wouldn't it be simpler to just stick with MySQL? That way you just need to do queries and that would be it. No files to have to periodically update.
Posted 17 December 2012 - 03:38 PM
So something like
Computercraft Code
Then something like
Computercraft Code
http.get("http://example.com/server.php?username=elfin8er&maxhp=150&hp=100")
Then something like
$username = $_GET['username'];
$hp = $_GET['hp']
$maxhp = $_GET['maxhp']
$fh = fopen(username, 'w') or die("can't open file");
$stringData= "$hp /n $maxhp";
fwrite($fh, $stringData);
fclose($fh);
How would the MySQL database send data to the computer then?Wouldn't it be simpler to just stick with MySQL? That way you just need to do queries and that would be it. No files to have to periodically update.
Posted 17 December 2012 - 03:40 PM
This is the way of doing it I was talking about, although like they said you wouldn't be able to use pastebin.
Posted 17 December 2012 - 03:42 PM
Ah true. Seems like there's some simpler elegant approach to this.How would the MySQL database send data to the computer then?
Edit: By any chance is your MC server running on a PVS?
Posted 17 December 2012 - 03:57 PM
Why would all players send their info to the other players text files?
This is the way of doing it I was talking about, although like they said you wouldn't be able to use pastebin.
PVS?Ah true. Seems like there's some simpler elegant approach to this.How would the MySQL database send data to the computer then?
Edit: By any chance is your MC server running on a PVS?
Posted 17 December 2012 - 04:01 PM
Why the files like that? You could do something like this in php:
Edit: and of course you'd want some type of flow control mechanism to not flood http packets.
Edit2: I'd also look into the advantages of POST over GET, depending on your needs.
<?php
$user = $_GET['user'];
$pass = $_GET['pass'];
$other_params = $_GET['other_relevant_data'];
// get data from the MySQL database using user and pass and let's say that you parse everything into raw data (like your text file) and put it into the var $content
// also use other parameters to update the database (i.e. use client data as input to update the server model)
echo $content; // print the content to the webpage
?>
Let's say you put this php script in a file 'script.php' on 'http://www.example.com' and fill in some mysql stuff for creating a large string (for example the same format as the text files you had earlier). Then if you'd visit 'http://www.example.com/script.php?user=elfin8er&pass=Computercraft&other_relevant_data=derp', you'd only get the echoed string $content as the body of the webpage. So in Lua, you could do something like this:
local bRunning = true
local user = "elfin8er"
local pass = "Computercraft"
local health = 20
local url = "http://www.example.com/script.php"
while bRunning do
local content = http.get(url, "user="..user.."&pass="..pass.."&other_relevant_data="..health)
-- this gets data from the server based on user, pass and health and at the same time notifies the server of stuff like changing health, user login, etc.
local str = content.readAll()
-- do something with the received data
-- let's say we want to drain health continuously for this example:
health = health - 1 -- the server will get notified of this on the next iteration
end
You'd probably want to use events for the http requests to handle input and stuff properly.Edit: and of course you'd want some type of flow control mechanism to not flood http packets.
Edit2: I'd also look into the advantages of POST over GET, depending on your needs.
Posted 17 December 2012 - 04:04 PM
PVS?Edit: By any chance is your MC server running on a PVS?
He probably meant a VPS: https://en.wikipedia.org/wiki/Virtual_private_server
Posted 17 December 2012 - 04:04 PM
Why would all players send their info to the other players text files?
Thats not what its doing, each player's cleint only edits its own file, all the rest of them get read and NOT edited
Posted 17 December 2012 - 04:10 PM
Perfect. That should do the trick. Btw, thanks for all of your guys' help, but I am by no means a Computercraft expert. I can and will figure out a way to do all of this, but it may not be in the best way.Why the files like that? You could do something like this in php:Let's say you put this php script in a file 'script.php' on 'http://www.example.com' and fill in some mysql stuff for creating a large string (for example the same format as the text files you had earlier). Then if you'd visit 'http://www.example.com/script.php?user=elfin8er&pass=Computercraft&other_relevant_data=derp', you'd only get the echoed string $content as the body of the webpage. So in Lua, you could do something like this:<?php $user = $_GET['user']; $pass = $_GET['pass']; $other_params = $_GET['other_relevant_data']; // get data from the MySQL database using user and pass and let's say that you parse everything into raw data (like your text file) and put it into the var $content // also use other parameters to update the database (i.e. use client data as input to update the server model) echo $content; // print the content to the webpage ?>
You'd probably want to use events for the http requests to handle input and stuff properly.local bRunning = true local user = "elfin8er" local pass = "Computercraft" local health = 20 local url = "http://www.example.com/script.php" while bRunning do local content = http.get(url, "user="..user.."&pass="..pass.."&other_relevant_data="..health) -- this gets data from the server based on user, pass and health and at the same time notifies the server of stuff like changing health, user login, etc. local str = content.readAll() -- do something with the received data -- let's say we want to drain health continuously for this example: health = health - 1 -- the server will get notified of this on the next iteration end
Edit: and of course you'd want some type of flow control mechanism to not flood http packets.
Edit2: I'd also look into the advantages of POST over GET, depending on your needs.
Posted 18 December 2012 - 05:48 AM
Now with the above idea, how would I go about doing things like player inventory?
Posted 18 December 2012 - 05:57 AM
Well, my code example clearly show both input and output to the server, so I'd should be quite straight forward. But I'll write something up real quick.
Just try and identify the way of handling input and the way of handling output, you can build anything from there.
<?php
$user = $_GET['user'];
$pass = $_GET['pass'];
$event = $_GET['event'];
$p1 = $_GET['p1'];
$p2 = $_GET['p2'];
if ( strcmp($event, 'getInventory') ) {
// get the inventory from SQL and put it's representation in $inventory, use $user and $pass to determine which inventory
echo $inventory; // OUTPUT TO CLIENT
} elseif ( strcmp($event, 'updateInventory') ) {
// use user, pass and p1 and p2 to update the inventory accordingly
// INPUT FROM CLIENT
};
?>
Just try and identify the way of handling input and the way of handling output, you can build anything from there.