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

ComputerCraft MUD?

Started by elfin8er, 17 December 2012 - 01:39 PM
elfin8er #1
Posted 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?
Henness #2
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
elfin8er #3
Posted 17 December 2012 - 02:46 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
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?
Sammich Lord #4
Posted 17 December 2012 - 02:51 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
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?
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.
Henness #5
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.
elfin8er #6
Posted 17 December 2012 - 02:56 PM
You would have to have access to a raw text file with the information that has been sent.
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 like


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?

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
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?
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.
That's how I can send data to the server, but how do I get data from the server?
Sammich Lord #7
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.
Henness #8
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
elfin8er #9
Posted 17 December 2012 - 03:20 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 think I get it (maybe). So each person would sorta have their own pastebin file with all their player information on it?

Sorry if I'm misunderstanding :P/>
ViperSRT3g #10
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.
elfin8er #11
Posted 17 December 2012 - 03:24 PM
This seems like an interesting project, I have a web server if you'd like to utilize it.
Got my own. Thanks though!
Sammich Lord #12
Posted 17 December 2012 - 03:26 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 think I get it (maybe). So each person would sorta have their own pastebin file with all their player information on it?

Sorry if I'm misunderstanding :P/>
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.
elfin8er #13
Posted 17 December 2012 - 03:29 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 think I get it (maybe). So each person would sorta have their own pastebin file with all their player information on it?

Sorry if I'm misunderstanding :P/>
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.
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?
ViperSRT3g #14
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.
elfin8er #15
Posted 17 December 2012 - 03:38 PM
So 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);

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.
How would the MySQL database send data to the computer then?
Henness #16
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.
ViperSRT3g #17
Posted 17 December 2012 - 03:42 PM
How would the MySQL database send data to the computer then?
Ah true. Seems like there's some simpler elegant approach to this.

Edit: By any chance is your MC server running on a PVS?
elfin8er #18
Posted 17 December 2012 - 03:57 PM

This is the way of doing it I was talking about, although like they said you wouldn't be able to use pastebin.
Why would all players send their info to the other players text files?

How would the MySQL database send data to the computer then?
Ah true. Seems like there's some simpler elegant approach to this.

Edit: By any chance is your MC server running on a PVS?
PVS?
Orwell #19
Posted 17 December 2012 - 04:01 PM
Why the files like that? You could do something like this in php:

<?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.."&amp;pass="..pass.."&amp;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.
Orwell #20
Posted 17 December 2012 - 04:04 PM
Edit: By any chance is your MC server running on a PVS?
PVS?

He probably meant a VPS: https://en.wikipedia.org/wiki/Virtual_private_server
Henness #21
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
elfin8er #22
Posted 17 December 2012 - 04:10 PM
Why the files like that? You could do something like this in php:

<?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.."&amp;pass="..pass.."&amp;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.
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.
elfin8er #23
Posted 18 December 2012 - 05:48 AM
Now with the above idea, how would I go about doing things like player inventory?
Orwell #24
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.

<?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.