📄 mudserver.java
字号:
package mud;import java.rmi.*;import java.rmi.server.*;import java.rmi.registry.*;import java.io.*;import java.util.Hashtable;import java.util.zip.*;import mud.Mud.*;import java.rmi.server.UnicastRemoteObject;public class MudServer extends UnicastRemoteObjectimplements RemoteMudServer,Serializable{ MudPlace entrance; String password; String mudname; Hashtable places; public MudServer(String mudname,String password, String placename,String description) throws RemoteException { this.mudname = mudname; this.password = password; this.places = new Hashtable(); try{ this.entrance = new MudPlace(this,placename,description); } catch(PlaceAlreadyExists e){ } } public MudServer() throws RemoteException{ } public String getMudName() throws RemoteException{ return mudname; } public RemoteMudPlace getEntrance() throws RemoteException{ return entrance; } public RemoteMudPlace getNamedPlace(String name) throws RemoteException,NoSuchPlace{ RemoteMudPlace p = (RemoteMudPlace)this.places.get(name); if(p == null) throw new NoSuchPlace(); return p; } public void setPlaceName(RemoteMudPlace place,String name) throws PlaceAlreadyExists{ if(places.containsKey(name)) throw new PlaceAlreadyExists(); places.put(name,place); } public void dump(String password,String filename) throws RemoteException,BadPassword,IOException{ if((this.password !=null)&& (!this.password.equals(password))){ throw new BadPassword(); } ObjectOutputStream out= new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(filename))); out.writeObject(this); out.close(); } public static void main(String[] args){ try{ MudServer server; if(args.length == 1){ FileInputStream f= new FileInputStream(args[0]); ObjectInputStream in =new ObjectInputStream(new GZIPInputStream(f)); server = (MudServer) in.readObject(); } else{ System.out.println("System Starting"); server = new MudServer(args[0],args[1],args[2],args[3]); } Naming.rebind(Mud.mudPrefix + server.mudname,server); } catch(Exception e){ System.out.println(e); System.out.println("Usage: java Mudserver <savefile> \n"+ "or: java MudServer <mudname> <password> <placename> <description>"); System.exit(1); } } static final long serialVerionUID = 7453281245880199453L;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -