home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 4.2 KB | 94 lines |
- // Thread that gets updates on entities as needed
-
- // Written by Bernie Roehl, December 1996
-
- package multi;
-
- import java.io.*;
- import java.util.*;
-
- class RegistryUpdater extends Thread {
-
- World world;
-
- public RegistryUpdater(World wrld) {
- world = wrld;
- setPriority(NORM_PRIORITY-1);
- start();
- }
-
- public void run() {
- while (true) {
- try { sleep(1); }
- catch (InterruptedException ex) { }
- for (int i = 0; i < world.entities.size(); ++i) {
- Entity e = (Entity) world.entities.elementAt(i);
- if (e != null) {
- if (e.needsInfo()) {
- synchronized(world.registry_socket) {
- String response;
- StringTokenizer tokens;
- world.registry_output.println("GETENTITY " + e.getId());
- try { response = world.registry_input.readLine(); }
- catch (IOException ex) {
- System.out.println("could not read response to GETENTITY: " + ex);
- return;
- }
- e.markRegistryChanged();
- tokens = new StringTokenizer(response);
- e.setName(tokens.nextToken());
- String newURL = tokens.nextToken();
- if (e.getURL() == null
- || !newURL.equals(e.getURL())) {
- e.setURL(newURL);
- e.markNewURL();
- }
- e.setOwner(tokens.nextToken());
- e.setAvatar(tokens.nextToken().equals("true"));
- e.setPersistent(tokens.nextToken().equals("true"));
- e.setCreationTime(Long.parseLong(tokens.nextToken()));
- try { response = world.registry_input.readLine(); }
- catch (IOException ex) {
- System.out.println("could not read response to GETENTITY: " + ex);
- return;
- }
- e.setNickName(response);
- try { response = world.registry_input.readLine(); }
- catch (IOException ex) {
- System.out.println("could not read response to GETENTITY: " + ex);
- return;
- }
- tokens = new StringTokenizer(response);
- e.setTextSSRC(Integer.parseInt(tokens.nextToken()));
- do {
- try { response = world.registry_input.readLine(); }
- catch (IOException ex) {
- System.out.println("could not read response to GETENTITY: " + ex);
- return;
- }
- } while (!response.equals("."));
- world.registry_output.println("GETINFO " + e.getId());
- String[] info = new String[20];
- int ind = 0;
- while (true) {
- try { response = world.registry_input.readLine(); }
- catch (IOException ex) {
- System.out.println("could not read response to GETINFO: " + e);
- break;
- }
- if (response.startsWith("."))
- break;
- if (ind < info.length)
- info[ind++] = new String(response);
- }
- e.setInfo(info);
- e.gotAllInfo();
- }
- }
- }
- }
- }
- }
- }
-
-