summaryrefslogtreecommitdiff
path: root/NET/worlds/network/netProperty.java
blob: c2f8e4b04de500d2355efa9fde9d9b7529dac413 (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
package NET.worlds.network;

import java.io.IOException;

public class netProperty {
   protected int _propID;
   protected String _value;

   public netProperty() {
      this._propID = 0;
   }

   public netProperty(int p) {
      this._propID = p;
   }

   public netProperty(int p, String val) {
      assert val != null;

      this._propID = p;
      this._value = val;
   }

   public int property() {
      return this._propID;
   }

   public String value() {
      return this._value;
   }

   int packetSize() {
      return this._value != null ? 2 + ServerOutputStream.utfLength(this._value) : 0;
   }

   void parseNetData(ServerInputStream data) throws IOException {
      this._propID = data.readUnsignedByte();
      this._value = data.readUTF();
   }

   void send(ServerOutputStream o) throws IOException {
      o.writeByte(this._propID);
      o.writeUTF(this._value);
   }

   @Override
   public String toString() {
      return netCmds.getPropName(this._propID) + "=" + this._value;
   }
}