Java Reference
In-Depth Information
Example 16−5: MudPlace.java (continued)
things.removeElementAt(i);
descriptions.removeElementAt(i);
}
// Let everyone know of the demise of this thing.
tellEveryone(name + " had destroyed the " + thing);
}
/**
* Create a new place in this MUD, with the specified name an description.
* The new place is accessible from this place through
* the specified exit, and this place is accessible from the new place
* through the specified entrance. The creator must be in this place
* in order to create a exit from this place.
**/
public void createPlace(RemoteMudPerson creator,
String exit, String entrance, String name,
String description)
throws RemoteException,NotThere,ExitAlreadyExists,PlaceAlreadyExists
{
// Verify that the creator is actually here in this place
String creatorname = verifyPresence(creator);
synchronized(exits) { // Only one client may change exits at a time
// Check that the exit doesn't already exist.
if (exits.indexOf(exit) != -1) throw new ExitAlreadyExists();
// Create the new place, registering its name with the server
MudPlace destination = new MudPlace(server, name, description);
// Link from there back to here
destination.exits.addElement(entrance);
destination.destinations.addElement(this);
// And link from here to there
exits.addElement(exit);
destinations.addElement(destination);
}
// Let everyone know about the new exit, and the new place beyond
tellEveryone(creatorname + " has created a new place: " + exit);
}
/**
* Create a new exit from this mud, linked to a named place in a named
* MUD on a named host (this can also be used to link to a named place in
* the current MUD, of course). Because of the possibilities of deadlock,
* this method only links from here to there; it does not create a return
* exit from there to here. That must be done with a separate call.
**/
public void linkTo(RemoteMudPerson linker, String exit,
String hostname, String mudname, String placename)
throws RemoteException, NotThere, ExitAlreadyExists, NoSuchPlace
{
// Verify that the linker is actually here
String name = verifyPresence(linker);
// Check that the link target actually exists. Throw NoSuchPlace if
// not. Note that NoSuchPlace may also mean "NoSuchMud" or
// "MudNotResponding".
String url = "rmi://" + hostname + '/' + Mud.mudPrefix + mudname;
try {
RemoteMudServer s = (RemoteMudServer) Naming.lookup(url);
RemoteMudPlace destination = s.getNamedPlace(placename);
Search WWH ::




Custom Search