嗯断断续续弄了有两个月吧。先给个最简版本(做多用户多房间聊天室还是很好用的)。
如果未安装java虚拟机,需先到:http://www.java.com/zh_CN/download/manual.jsp下载。
选择:Windows(脱机安装),16兆的那个。这儿有个直接下载地址:http://jdl.sun.com/webapps/download/AutoDL?BundleId=10343
装好这个之后,分别下载:
http://www.foryears.com/mudserver.rar mud服务器端
http://www.foryears.com/mudclient.rar mud客户端
里面配有简要的说明。
附程序用到的dom4j解析xml:
import java.util.*;
import java.io.File;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.Node;
import org.dom4j.DocumentHelper;
import org.dom4j.Attribute;
public class Dom4jParseXml {
//通过xml文件名得到DOM
public Document getDocument(String xmlFileName) throws DocumentException {
SAXReader reader = new SAXReader();
Document d = reader.read(new File(xmlFileName));
return d;
}
//重载,通过xml文件内容得到DOM
public Document getDocument(String xmlContent, boolean b) throws
DocumentException {
Document d = DocumentHelper.parseText(xmlContent);
return d;
}
//输出字符串
public String transformDOM(Document d) {
String xmlContent = "";
xmlContent = d.asXML();
return xmlContent;
}
//得到节点
public Element getNode(Document d, String elePath, String eleValue) {
Element ele = null;
List l = d.selectNodes(elePath);
Iterator iter = l.iterator();
while (iter.hasNext()) {
Element tmp = (Element) iter.next();
if (tmp.getText().equals(eleValue)) {
ele = tmp;
}
}
return ele;
}
//重载,得到节点
public Element getNode(Document d, String eleName) {
Element ele = (Element) d.selectSingleNode(eleName);
return ele;
}
//增加节点
public void addNode(Element parentEle, String eleName, String eleValue) {
Element newEle = parentEle.addElement(eleName);
newEle.setText(eleValue);
}
//增加属性节点
public void addAttribute(Element ele, String attributeName,
String attributeValue) {
ele.addAttribute(attributeName, attributeValue);
}
//删除节点
public void removeNode(Element parentEle, String eleName, String eleValue) {
Iterator iter = parentEle.elementIterator();
Element delEle = null;
while (iter.hasNext()) {
Element tmp = (Element) iter.next();
if (tmp.getName().equals(eleName) && tmp.getText().equals(eleValue)) {
delEle = tmp;
}
}
if (delEle != null) {
parentEle.remove(delEle);
}
}
//删除属性
public void removeAttr(Element ele, String attributeName) {
Attribute att = ele.attribute(attributeName);
ele.remove(att);
}
//修改节点值
public void setNodeText(Element ele, String newValue) {
ele.setText(newValue);
}
//修改属性值
public void setAttribute(Element ele, String attributeName,
String attributeValue) {
Attribute att = ele.attribute(attributeName);
att.setText(attributeValue);
}
}