O.K. I read a bunch of posts about starting off and the long road to a MMOG. I have decided that I would take the advice of one article and attempt to program by own MUD. So I searched this forum and I googled the topic but I could not find a tutorial for making a MUD period, much less a java one. :’( I would really appriciate it if any of you, who know where there is a MUD tutorial, would direct me in that direction. Thanks
Subscribe to MUD-DEV.
Visit the mud-connector.
Read Imaginary Realities (online mag)
Step 1: Open a network socket on port 23.
Step 2: Output screens using a library such as JCurses or roll your own from the ANSI Escape Codes. (The “ESC” means character 27, or 0x1B in Hex. Yes, you actually print the ‘[’.)
Step 3: Read input from socket so your game can respond.
Step 4: Code something intereting around this.
There’s a ton of info you can find out from the terminal via the Telnet protocol (e.g. the width and height of the terminal), but that’s more complex than I’m willing to explain. The RFC is dry reading, but it explains it fairly well. Beware that most terminals are not truely RFC compliant. Thus you’re better off sticking with the escape codes.
Thanks for replying. I got on MUD-DEV, and mud-connector. I tried Imaginary Realities but couldnt get it to come up. From what I read I need a server next, right? Or really the server software. However I cant find one thats based in java. Does that matter, will I really need to code in the server software, or do I just need to make sure I get a java client? Sry Im such a noob.
jbanes I read ur reply and understood I need a network soket and a output screen library, but after that I got lost. :-/ Where did you start talking about a terminal and since its too complex to explain could you give me a site on where to read about that paragraph? I really have no clue on how to act on your post. Sry.
Thanks again for answering.
[quote]jbanes I read ur reply and understood I need a network soket and a output screen library, but after that I got lost. :-/ Where did you start talking about a terminal and since its too complex to explain could you give me a site on where to read about that paragraph? I really have no clue on how to act on your post. Sry.
[/quote]
Sorry, I thought I was being clear. Let me try to simplify it:
Telnet is a protocol designed for users to connect to remote terminals such as Unix or IBM Mainframes. When the Internet came around (actually it started with BBSes, but I won’t go there), gamers came up with an idea for a new sort of dungeon game. The concept was that instead of presenting telnet users with a command line interface, they’d provide them with a game screen. Thus MUDs were born.
Now if you look at the Telnet spec (you don’t actually have to do that, I’m speaking figuratively) it basically says that you can consider it nothing more than sending ASCII characters back and forth. i.e. The server can read text from the socket and write text back. There’s other features in the Telnet protocol, but those are largely ignored. It’s really just an open socket with text going back and forth.
This is extremely good news, because in Java it’s very simple to write ASCII strings to an output stream, and read them from an InputStream. i.e.:
Socket socket = new Socket("mymud.com", 23);
OutputStream out = socket.getOutputStream();
String message = new String("Hello World!\n");
for(int i=0; i<message.length; i++)
{
out.write(message.charAt(i);
}
That bit of code should send “Hello World!” plus a newline to the server. The server might respond like this:
ServerSocket server = new ServerSocket(23);
Socket socket = server.accept();
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
String message = "Hello to you too!\n";
int c;
while((c = in.read()) >= 0 && c != '\n') //Check for end of line
{
System.out.print((char)c); //Print out the message
}
for(int i=0; i<message.length; i++)
{
out.write(message.charAt(i);
}
So the above code would call the server, send “Hello World!” and get back the response “Hello to you too!”. Pretty cool, huh? The only problem is that the communication is going to be a bit dull. You see, if you were to use a telnet client to contact the server piece, the client would simply show the text scroll one line at a time. That’s no fun if we want to have text animations!
The solution is a set of codes called “ANSI Escape Characters”. These characters were originally IBM’s attempt at making their terminals smarter with better looking programs. I don’t think IBM ever realized how useful those codes would be for games! Here’s a tested and debugged class for sending the cursor to the home position (upper left), setting a color, and printing out “Hello World!”.
import java.io.*;
import java.net.*;
public class HelloServer
{
public static void main(String[] args) throws Exception
{
ServerSocket server = new ServerSocket(23);
Socket socket = server.accept();
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
String message = "Hello World!";
int color = 31;
int c;
while((c = in.read()) >= 0 && c != 'q')
{
//Send cursor location code
out.write(0x1B);
writeMessage(out, "[0;0H");
//Send a color
out.write(0x1B);
writeMessage(out, "["+color+"m");
//Send the Message
writeMessage(out, message);
//Make sure it gets sent
out.flush();
color++;
if(color > 49) color = 31;
}
socket.close();
}
private static void writeMessage(OutputStream out, String message) throws IOException
{
for(int i=0; i<message.length(); i++)
{
out.write(message.charAt(i));
}
}
}
Instructions:
- Compile the class above
- Run it by typing “java HelloServer” from the command line, or executing it in your IDE. It is now waiting for a connection.
- Open your favorite telnet or MUD client. Windows Telnet won’t work right, so if you don’t have a good client, go grab PuTTY
- Connect to “localhost” on port 23. (23 should be the default.)
- Hit enter to see new colors. Hit ‘q’ and then enter to quit.
Any questions?
Wow, I never knew one could do that, thats cool! Thanks for the info but I still have a few questions. So at the moment I can just tell it to read in text and out put the appropriate text cool. But when I want to publish it to a web page do I use a Japplet? When some one runs the game as an applet will it open the applet connect to my telnet, which I run all the time and then the game runs? Your post explained alot of things thanks.
Assuming you want to stick to the MUD original style then you don’t want an Applet at all… just rely on everyone having a telnet client (everyone does :))
Then use a URL like telnet://myhost.mydomain.com:12345
Kev
As KevGlass said, you’re fine with allowing MUD users to use their favorite telnet client. If you want to be a nice guy, though, you can always put an applet like this one on the server machine’s web server. That would allow players to play your MUD without downloading a client.
(Technically, they are downloading the Java Client, but the user will get the impression that they’re just using your web page. :-))
Ok thanks I think I got what you said, or at least good enough for now. I guess at the moment I should just start coding my game. Where can I find more examples like the HelloServer code? Im gonna google ANSI Escape Characters tutorial and see what I get. Thanks for all the help.
Ok I tried that and it didnt work. :-[ Where did you guys learn about this code???
You can learn about Diku Muds at http://www.dikumud.com/ This is the one that started Everquest. Download the dikumud code and read it, it’s acutally pretty short and you learn a lot quick! That’s what I did.
Good luck.
Thanks for the tip. I tried to download the source code but it brings all this stuf up that I have no clue what it is and I cant acctually find the code. Any suggestions?
Ok I think I found the source code but it does not look like Java to me, and wheather it is or not what kind of compilier do I need to compile it so I can then fool around with it and see what happens? Thanks again for the reply.
[quote]Ok thanks I think I got what you said, or at least good enough for now. I guess at the moment I should just start coding my game. Where can I find more examples like the HelloServer code? Im gonna google ANSI Escape Characters tutorial and see what I get. Thanks for all the help.
[/quote]
If you look at my original post, I linked to a page of ANSI Escape codes.
[quote]Ok I tried that and it didnt work. :-[ Where did you guys learn about this code???
[/quote]
What didn’t work? Were you not able to find info, or do you have code that doesn’t work? If it’s the later, post here and we’ll help figure it out.
[quote] Ok I think I found the source code but it does not look like Java to me
[/quote]
Ahh, what an excellent time to learn an additional programming language ie expand you horizons ;D .
I imagine diku mud is written in C. Have fun!
[quote]Ok thanks I think I got what you said, or at least good enough for now. I guess at the moment I should just start coding my game. Where can I find more examples like the HelloServer code? Im gonna google ANSI Escape Characters tutorial and see what I get. Thanks for all the help.
Ok I tried that and it didnt work. :-[ Where did you guys learn about this code???
[/quote]
Someone I know has just written a base ANSI MUD client that they’re going to open-source very soon. I’ll post here when I know when/where they’ve put it (don’t even know the name of the project at the moment!)
Most modern MUDs are written in ColdC, or the LambdaMOO stuff, or similar - i.e. traditional languages or environments adapted to make them more suitable for MUD dev.
You really should check out MUD-dev: lots of things aren’t documented anywhere else because they’re documented there. Unfortunately, their archives are off-line due to a server crash over xmas, but if you ask the admin there may be mirrors somewhere…
[quote]Ok I think I found the source code but it does not look like Java to me, and wheather it is or not what kind of compilier do I need to compile it so I can then fool around with it and see what happens? Thanks again for the reply.
[/quote]
Nonnus is correct. DikuMUD is written in a quaint little language called C, and I think the Posix (Unix) API. (Most of this API is supported in the standard C library on Windows, so no worries.)
It’s still good to learn basic C, imho–think external routines for Java.
You can get a C compiler for free at www.mingw.org. Grab MSYS too while you are there. If you must use a GUI environment, www.bloodshed.net uses the mingw compiler and adds a decent graphical front-end.
Let me know if you are going to persue C programming. I have these tools and it won’t be hard for me to give you some pointers on the DikuMUD code.
There’s actualy a small java based MUD on game.org
ftp://ftp.game.org/pub/mud/other/JavaMud.tar.gz
Greetz,
MC