home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 3.1 KB | 132 lines |
- // Simple Multiuser Server
- // (c) Copyright Justin Couch justin@vlc.com.au
- // The Virtual Light Company 1996
- //
- // From Chapter 20: Late Night VRML 2.0 and java
- //
- // This is the Chat message handler class. The real work of parsing an
- // individual message is done here and sending out messages to the other
- // users based on whatever filtering parameters are needed.
-
- package filter;
-
- import java.net.*;
- import java.io.*;
-
- class FilterMessage extends Thread
- {
- // these define the flags in bytes 2 & 3
- private static final int SUSPEND = 0x0001;
- private static final int REQUEST_REFRESH = 0x0002;
- private static final int GONE = 0x0004;
-
- private static int msg_number = 0;
-
- private UserServer server;
- private DatagramPacket _packet;
- private int sequence_num;
- private int text_id;
- private int flags = 0;
- private int port = 0;
- private float[] view_pos = new float[3];
- private float acuity = 0;
- private int horizon = 0;
- private int region_count = 0;
- private int port_count = 0;
- private int[] region_list;
- private int[] port_list;
-
-
- // all that gets done here is to copy over the packet into the internal
- // reference. We leave all the real work to the run method because that
- // allows java's thread handling system to share the workload much better.
- // If we didn't then the whole chat Server thread would block until we have
- // dealt with the response here.
- public FilterMessage(DatagramPacket packet, ThreadGroup tg, UserServer userver)
- {
- super(tg, "Filter Message " + msg_number++);
-
- setPriority(5);
-
- _packet = packet;
- server = userver;
- }
-
- // analyse the packet and send out the text to the other users.
- public void run()
- {
- int i;
- ByteArrayInputStream buffer =
- new ByteArrayInputStream(_packet.getData());
- DataInputStream data = new DataInputStream(buffer);
- String hostname = _packet.getAddress().getHostName();
-
- try
- {
- // get the response port number
- port = data.readUnsignedShort();
-
- // get flags
- flags = data.readUnsignedShort();
-
- // get view point position
- view_pos[0] = data.readFloat();
- view_pos[1] = data.readFloat();
- view_pos[2] = data.readFloat();
-
- // acuity
- acuity = data.readFloat();
-
- // horizon count
- horizon = data.readInt();
-
- // list of regions
- region_count = data.readUnsignedShort();
-
- region_list = new int[region_count];
-
- for(i = 0; i < region_count; i++)
- {
- region_list[i] = data.readUnsignedShort();
- }
-
- // deal with the ports
- port_count = data.readUnsignedShort();
-
- port_list = new int[port_count];
-
- for(i = 0; i < port_count; i++)
- {
- port_list[i] = data.readUnsignedShort();
- }
-
- switch(flags)
- {
- case SUSPEND:
- server.suspend(hostname);
- break;
- case REQUEST_REFRESH:
- server.refresh(hostname);
- break;
- case GONE:
- server.remove(hostname);
- break;
- default:
- // now tell the users server to add the filter message
- server.set_filter(hostname,
- port,
- acuity,
- horizon,
- region_list,
- port_list);
- }
- }
- catch(IOException e)
- {
- System.err.println("Filter server error " + e.getMessage());
- }
-
- // all done, go and process it now.
- }
- }
-