summaryrefslogtreecommitdiff
path: root/NET/worlds/network/textCmd.java
blob: f5ba287622368c896d0b87b1894ea8e0b3188238 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package NET.worlds.network;

import NET.worlds.console.BBChatCommand;
import NET.worlds.console.BlackBox;
import NET.worlds.console.Console;
import NET.worlds.console.GammaTextArea;
import NET.worlds.console.MuteListPart;
import NET.worlds.core.IniFile;
import NET.worlds.scape.Drone;
import NET.worlds.scape.Pilot;
import NET.worlds.scape.PosableDrone;
import java.io.IOException;

public class textCmd extends receivedNetPacket {
   public static final byte TEXTCMD = 14;
   protected ObjID _senderID;
   protected String _text;

   public textCmd() {
      this._commandType = 14;
   }

   public textCmd(String text) {
      super(null, 14);
      this._senderID = new ObjID("");
      this._text = text;
   }

   @Override
   void parseNetData(ServerInputStream data) throws IOException {
      this._senderID = new ObjID();
      this._senderID.parseNetData(data);
      this._text = data.readUTF();
   }

   @Override
   int packetSize() {
      return ServerOutputStream.utfLength(this._text) + 1 + this._senderID.packetSize() + super.packetSize();
   }

   @Override
   void send(ServerOutputStream o) throws IOException {
      super.send(o);
      this._senderID.send(o);
      o.writeUTF(this._text);
   }

   @Override
   void process(WorldServer _serv) throws Exception {
      String name;
      if (this._senderID.longID() == null) {
         name = "[Unknown Name (#" + String.valueOf(this._senderID.shortID()) + ")]";
      } else {
         name = this._senderID.longID();
         if (MuteListPart.isMuted(_serv, name)) {
            return;
         }
      }

      handleActionText(_serv, this._text, name, this._senderID);
      if (!this._text.startsWith("&|+")) {
         this.displayText(name, this._text);
      }
   }

   protected void displayText(String name, String text) {
      String filteredName = FilthFilter.get().filterName(name);
      String line = "";
      if (IniFile.gamma().getIniInt("classicChatBox", 1) == 1) {
         line = filteredName + "> ";
         line = line + FilthFilter.get().filter(text);
         BlackBox.getInstance().submitEvent(new BBChatCommand(line));
         Console.println(line);
      } else {
         boolean colored = false;
         if (Drone.isEmployeeAccount(name)) {
            line = GammaTextArea.colorStartBlueTag + " ";
            colored = true;
         } else if (name.toLowerCase().startsWith(Console.message("host"))) {
            line = GammaTextArea.colorStartRedTag + " ";
            colored = true;
         } else if (name.toLowerCase().startsWith(Console.message("guest-"))) {
            line = GammaTextArea.colorStartMagentaTag + " ";
            colored = true;
         }

         line = line + "<b> " + filteredName + "> </b>  ";
         if (colored) {
            line = line + " " + GammaTextArea.colorEndTag + " ";
         }

         line = line + FilthFilter.get().filter(text);
         BlackBox.getInstance().submitEvent(new BBChatCommand(line));
         Console.println(line);
      }
   }

   public static void handleActionText(WorldServer _serv, String msg, String name, ObjID senderID) {
      if (msg.startsWith("&|+action>")) {
         NetworkObject o = _serv.getObject(senderID);
         if (o == null) {
            return;
         }

         String act = msg.substring(10);
         if (!(o instanceof PosableDrone)) {
            return;
         }

         ((PosableDrone)o).animate(act);
      }

      if (msg.startsWith("&|+action2>")) {
         int idx = msg.indexOf("|sender|");
         String senderAction = null;
         String receiverAction = null;
         if (idx != -1) {
            senderAction = msg.substring(idx);
            receiverAction = msg.substring(11, idx);
            NetworkObject ox = _serv.getObject(senderID);
            if (ox != null && ox instanceof PosableDrone) {
               ((PosableDrone)ox).animate(senderAction);
               Pilot.sendText("&|+action>" + senderAction);
            }
         } else {
            receiverAction = msg.substring(11);
         }

         try {
            Console.getActive().getPilot().animate(receiverAction);
         } catch (Exception var8) {
            System.out.println("Error animating pilot " + var8.toString());
         }
      }
   }

   @Override
   public String toString(WorldServer serv) {
      return "TEXT     " + this._senderID.toString(serv) + ": " + this._text;
   }
}