summaryrefslogtreecommitdiff
path: root/NET/worlds/console/StatNetRefNode.java
blob: 9ce6fe27674d03998025cbc0cdb36418b11e9dc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package NET.worlds.console;

import NET.worlds.core.Std;
import NET.worlds.network.NetworkRoom;
import NET.worlds.network.WorldServer;
import NET.worlds.scape.Pilot;
import NET.worlds.scape.Room;
import java.awt.List;
import java.util.Vector;

public class StatNetRefNode extends StatMan implements MainCallback {
   private static StatNetRefNode _singleInstance = new StatNetRefNode();
   private int _totBytesSent;
   private int _totBytesRcvd;
   private int _totPacketsSent;
   private int _totPacketsRcvd;
   private int _lastTime;
   private static final int TITLE = 0;
   private static final int BLANK = 1;
   private int _listCount = 0;

   public static StatNetRefNode getNode() {
      return _singleInstance;
   }

   private StatNetRefNode() {
      StatNetNode.getNode().addChild(this);
   }

   @Override
   public String toString() {
      return "Drone Referrers to Current Server";
   }

   public void addBytesSent(int bytesSent) {
      this._totBytesSent += bytesSent;
   }

   public void addBytesRcvd(int bytesRcvd) {
      this._totBytesRcvd += bytesRcvd;
   }

   public void addPacketsSent(int pktSent) {
      this._totPacketsSent += pktSent;
   }

   public void addPacketsRcvd(int pktRcvd) {
      this._totPacketsRcvd += pktRcvd;
   }

   @Override
   void grabList(List list) {
      super.grabList(list);
      Main.register(this);
   }

   @Override
   void releaseList(boolean terminalCallback) {
      if (!terminalCallback) {
         Main.unregister(this);
      }

      super.releaseList(terminalCallback);
   }

   @Override
   public void mainCallback() {
      int thisTime = Std.getFastTime();
      if (thisTime - this._lastTime > 1000) {
         this.updateList();
         this._lastTime = thisTime;
      }
   }

   @Override
   void createList() {
      this._grabbedList.add("Drones Referring to Current Server:", 0);
      this._grabbedList.add("", 1);
      Pilot p = Pilot.getActive();
      Room r = p.getRoom();
      NetworkRoom netRoom = null;
      if (r != null) {
         netRoom = r.getNetworkRoom();
      }

      WorldServer ws = null;
      if (netRoom != null) {
         ws = netRoom.getServer();
      }

      if (ws != null) {
         Vector<String> list = ws.printDroneReferrers();

         for (int i = list.size() - 1; i >= 0; i--) {
            String name = list.elementAt(i);
            this._grabbedList.add(name);
         }
      }
   }

   @Override
   void updateList() {
      this._grabbedList.removeAll();
      this.createList();
   }
}