Java Reference
In-Depth Information
Example 16−5: MudPlace.java (continued)
/**
* This remote method sends a message to everyone in the room. Used to
* say things to everyone. Requires that the speaker be in this place.
**/
public void speak(RemoteMudPerson speaker, String msg)
throws RemoteException, NotThere
{
String name = verifyPresence(speaker);
tellEveryone(name + ":" + msg);
}
/**
* This remote method sends a message to everyone in the room. Used to
* do things that people can see. Requires that the actor be in this place.
**/
public void act(RemoteMudPerson actor, String msg)
throws RemoteException, NotThere
{
String name = verifyPresence(actor);
tellEveryone(name + " " + msg);
}
/**
* This remote method creates a new thing in this room.
* It requires that the creator be in this room.
**/
public void createThing(RemoteMudPerson creator,
String name, String description)
throws RemoteException, NotThere, AlreadyThere
{
// Make sure the creator is here
String creatorname = verifyPresence(creator);
synchronized(things) {
// Make sure there isn't already something with this name.
if (things.indexOf(name) != -1) throw new AlreadyThere();
// Add the thing name and descriptions to the appropriate lists
things.addElement(name);
descriptions.addElement(description);
}
// Tell everyone about the new thing and its creator
tellEveryone(creatorname + " has created a " + name);
}
/**
* Remove a thing from this room. Throws exceptions if the person
* who removes it isn't themselves in the room, or if there is no
* such thing here.
**/
public void destroyThing(RemoteMudPerson destroyer, String thing)
throws RemoteException, NotThere, NoSuchThing
{
// Verify that the destroyer is here
String name = verifyPresence(destroyer);
synchronized(things) {
// Verify that there is a thing by that name in this room
int i = things.indexOf(thing);
if (i == -1) throw new NoSuchThing();
// And remove its name and description from the lists
Search WWH ::




Custom Search