Java Reference
In-Depth Information
Example 16−5: MudPlace.java (continued)
}
catch (Exception e) { throw new NoSuchPlace(); }
synchronized(exits) {
// Check that the exit doesn't already exist.
if (exits.indexOf(exit) != -1) throw new ExitAlreadyExists();
// Add the exit, to the list of exit names
exits.addElement(exit);
// And add the destination to the list of destinations. Note that
// the destination is stored as a string rather than as a
// RemoteMudPlace. This is because if the remote server goes down
// then comes back up again, a RemoteMudPlace is not valid, but the
// string still is.
destinations.addElement(url + '@' + placename);
}
// Let everyone know about the new exit and where it leads
tellEveryone(name + " has linked " + exit + " to " +
"'" + placename + "' in MUD '" + mudname +
"' on host " + hostname);
}
/**
* Close an exit that leads out of this place.
* It does not close the return exit from there back to here.
* Note that this method does not destroy the place that the exit leads to.
* In the current implementation, there is no way to destroy a place.
**/
public void close(RemoteMudPerson who, String exit)
throws RemoteException, NotThere, NoSuchExit
{
// check that the person closing the exit is actually here
String name = verifyPresence(who);
synchronized(exits) {
// Check that the exit exists
int i = exits.indexOf(exit);
if (i == -1) throw new NoSuchExit();
// Remove it and its destination from the lists
exits.removeElementAt(i);
destinations.removeElementAt(i);
}
// Let everyone know that the exit doesn't exist anymore
tellEveryone(name + " has closed exit " + exit);
}
/**
* Remove a person from this place. If there is a message, send it to
* everyone who is left in this place. If the specified person is not here
* this method does nothing and does not throw an exception. This method
* is called by go(), and the client should call it when the user quits.
* The client should not allow the user to invoke it directly, however.
**/
public void exit(RemoteMudPerson who, String message)
throws RemoteException
{
String name;
synchronized(names) {
int i = people.indexOf(who);
if (i == -1) return;
Search WWH ::




Custom Search