Source code: org/mitre/cvw/CVWServerComm.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import org.mitre.cvw.search.FindFrame;
10
11 import java.net.*;
12 import java.io.*;
13 import java.util.Vector;
14
15
16 /**************************************************************
17 **************** CVW Server Comm Object *********************
18 **************************************************************/
19 /**
20 * This class processes all communication from and to the CVW server.
21 * @version 1.0
22 * @author Jay Carlson
23 * @author Deb Ercolini
24 */
25 public class CVWServerComm extends Object {
26 Socket cvwSock;
27 NetThread netThread;
28 CVWCoordinator applet;
29 boolean connValid = false;
30 int iport;
31 String host;
32 boolean idleState = true;
33 String serverName = null;
34
35 /**************************************************************
36 **************** static methods to help with ****************
37 **************** parsing to/from CVWServer ****************
38 **************************************************************/
39
40 /* 9/2/98 dage - moved from CVWCoordinator
41 */
42 /**
43 * Processes text to be sent to the CVW server so that given
44 * a character, all occurences of it will be escaped.
45 * @param end the first occurence of the character
46 * @param str the string to be searched
47 * @param c the character to be escaped
48 * @return the proccessed text
49 */
50 public static String escapeText(int end, String str, char c) {
51 StringBuffer tmp = new StringBuffer();
52 int start = 0;
53 do {
54 tmp.append(str.substring(start,end));
55 tmp.append("\\");
56 tmp.append(c);
57 start = end + 1;
58 } while ((end = str.indexOf(c, start)) != -1);
59 tmp.append(str.substring(start,str.length()));
60 //if(DEBUG) System.err.println(tmp);
61 return tmp.toString();
62 }
63
64 /* 11/20/96 dage - created.
65 * 9/2/98 dage - moved from CVWCoordinator
66 */
67 /**
68 * Changed >>!<< with "\n&quoyt;
69 * @param end the first index of the >>!<<
70 * @param str the string to be searched
71 * @return the resulting string
72 */
73 public static String replaceCRsForServer(int end, String str) {
74 //if(DEBUG) System.err.println("in replace crs for server");
75 StringBuffer tmp = new StringBuffer();
76 int start = 0;
77 do {
78 tmp.append(str.substring(start,end));
79 tmp.append(">>!<<");
80 start = end + 1;
81 } while ((end = str.indexOf("\n", start)) != -1);
82 tmp.append(str.substring(start,str.length()));
83 //if(DEBUG) System.err.println(tmp);
84 return tmp.toString();
85 }
86 /**
87 * Prepares the text being sent to the CVW serverby searching for special
88 * characters and escaping them and then wrapping the entire text in
89 * double quotes. Currently, the characters needing to be
90 * escaped are: \n, \r, \, ", :
91 * @param oldText the text to be prepped
92 * @return the text after it is processed
93 * @see escapeText
94 */
95 public static String prepTextForServer(String oldText) {
96 int end;
97 String text = oldText;
98 if ((end = text.indexOf('\n')) != -1)
99 text = replaceCRsForServer(end, text);
100 if ((end = text.indexOf('\r')) != -1)
101 text = text.replace('\r', ' ');
102 if ((end = text.indexOf('\\')) != -1)
103 text = escapeText(end, text, '\\');
104 if ((end = text.indexOf('"')) != -1)
105 text = escapeText(end, text, '"');
106 //if ((end = text.indexOf(':')) != -1)
107 //text = escapeText(end, text, ':');
108 text = "\"" + text + "\"";
109 //if(DEBUG) System.err.println("text: " + text);
110 return text;
111 }
112
113 /**
114 * Parses through a bar delimited string from the CVW server, checking for
115 * beginning and ending bars and adds space between consecutive bars.
116 * known .. if the first user has a blank fullname, it gets stripped
117 * from the mcp processor, and the string starts w/a |.
118 * known .. if the last user has a blank fullname, it gets stripped
119 * from the mcp processor, and the string ends w/a |.
120 *
121 * @param barDelim the string from the CVW server
122 * @return the processed string
123 */
124 public static String parseBarDelimitedStringFromServer(String barDelim) {
125 if (barDelim.length() == 0)
126 return barDelim;
127
128 String fNames = barDelim;
129 if (barDelim.charAt(0) == '|')
130 fNames = "| "+fNames;
131 if (fNames.charAt(fNames.length()-1) == '|')
132 fNames = fNames + " |";
133 int ind = fNames.indexOf("||");
134 if (ind < 0)
135 return fNames;
136 while (ind > 0) {
137 String beg = fNames.substring(0, ++ind);
138 String end = fNames.substring(ind++, fNames.length());
139 fNames = beg + " " + end;
140 ind = fNames.indexOf("||", ind);
141 }
142 return fNames;
143 }
144
145 private static CVWServerComm instance = null;
146
147 public static CVWServerComm getInstance() {
148 return instance;
149 }
150 /**
151 * Sends a MCP command to CVW server with no parameters.
152 * @param cmd the MCP command
153 */
154 public static void sendMCPCmdToServer(String cmd) {
155 sendMCPCmdToServer(cmd, "");
156 }
157
158 /**
159 * Sends a MCP command to CVW server with provided parameters,
160 * inserting the auth code.
161 * @param cmd the MCP command
162 * @param rest the parameter list
163 */
164 public static void sendMCPCmdToServer(String cmd, String rest) {
165 String authKey = Authenticator.getAuthKey();
166 if(CVWCoordinator.DEBUG) System.err.println(authKey + " CVWServerComm: " + cmd);
167 instance.sendCmdToServer(cmd + " " + authKey + " " + rest);
168 }
169
170 /**
171 * Sends a non-mcp command to the CVW server.
172 * @param cmd the string to send to the CVW server
173 */
174 public static void sendRawCmdToServer(String cmd) {
175 instance.sendCmdToServer(cmd);
176 }
177
178
179 /**
180 * Constructor
181 * @param hst the host name of server to connect to
182 * @param port the port number to connect to
183 */
184 CVWServerComm(String hst, String port) {
185 applet = CVWCoordinator.getInstance();
186
187 instance = this;
188
189 if (hst == null)
190 host = "nowhere.com";
191 else
192 host = hst;
193 if (port == null)
194 iport = 8888;
195 else
196 iport = (new Integer(port)).intValue();
197 openConnection();
198 }
199
200 /**
201 * Starts the communication thread.
202 * @see NetThread
203 */
204 public void startThread() {
205 if (connValid)
206 netThread.start();
207 }
208
209 /**
210 * Returns the current socket to the CVW server.
211 * @return the current socket to the CVW server
212 */
213 public Socket getSocket() {
214 return cvwSock;
215 }
216
217 /**
218 * Returns the name of the CVW server.
219 * @return the name of the CVW server
220 */
221 public String getServerName() {
222 return serverName;
223 }
224
225 /**
226 * Returns the host name of the CVW server.
227 * @return the host name of the CVW server
228 */
229 public String getServerHost() {
230 return host;
231 }
232
233 /**
234 * Returns the port of the CVW server.
235 * @return the port of the CVW server
236 */
237 public int getServerPort() {
238 return iport;
239 }
240
241 /**
242 * Returns whether the connection to the CVW server is valid.
243 * @return whether the connection to the CVW server is valid
244 */
245 public boolean connectionValid() {
246 return connValid;
247 }
248
249 /* 11/6/96 dage - moved this code from constructor so that
250 * a reconnect is possible with the same servercomm object.
251 */
252 /**
253 * Opens the connection to the CVW server.
254 * @see NetThread
255 */
256 public void openConnection() {
257 try {
258 cvwSock = new Socket(host, iport);
259 if (CVWCoordinator.DEBUG) System.err.println("got socket conn: " + cvwSock);
260 connValid = true;
261 } catch (Exception v) {
262 connValid = false;
263 if (v instanceof UnknownHostException) {
264 String host = v.getMessage();
265 displayError("You are trying to connect to CVW server with name: "
266 + host + ". Please check your configurtion file.",
267 "Unknown CVW Server");
268 } else if (v instanceof ConnectException) {
269 displayError("There is a problem connecting to CVW server: " +
270 host + ":" + iport + ".", v.getMessage());
271 } else
272 v.printStackTrace();
273 System.exit(1);
274 return;
275 }
276
277 netThread = new NetThread(cvwSock, this);
278 //if(CVWCoordinator.DEBUG) System.err.println(netThread + "new thread");
279 }
280
281 /**
282 * Closes the connection to the CVW server.
283 */
284 public void closeConnection() {
285 //should we stop the thread or will this do it?
286 if (!connValid) return;
287 connValid = false;
288 try { cvwSock.close();
289 } catch (Exception e) { }
290 }
291
292 /**
293 * Displays an error in a dialog box.
294 * @param errorString the message of the error
295 * @param title the title of the dialog box
296 * @see OkCancelDialog
297 */
298 public void displayError(String errorString, String title) {
299 OkCancelDialog ok = new OkCancelDialog(applet, errorString, true, title, OkCancelDialog.WARNING, OkCancelDialog.OK);
300 ok.pack();
301 ok.center();
302 ok.setVisible(true);
303 }
304
305 /**
306 * Sends the idle command to the CVW server and sets the idle state
307 * @param text the message of the idle (if any)
308 */
309 public void sendIdle(String text) {
310 sendCmdToServer("idle " + text);
311 idleState = true;
312 }
313
314 /**
315 * Sends a command to the CVW server if the connection is valid.
316 * @param cmd the command to be sent
317 */
318 public void sendCmdToServer(String cmd) {
319 if (!connValid) return;
320 if (idleState) {
321 idleState = false;
322 applet.setIdle(false);
323 }
324
325 ByteArrayOutputStream bs = new ByteArrayOutputStream();
326 PrintStream ps = new PrintStream(bs);
327
328 //System.err.print("<" + cmd.substring(0, Math.min(10, cmd.length())));
329 if (cmd.startsWith("#$#"))
330 if(CVWCoordinator.DEBUG) System.err.println("send: " + cmd);
331 //if(CVWCoordinator.DEBUG) System.err.println(Thread.currentThread() + "serverComm sending: " + cmd);
332
333 ps.println(cmd);
334 ps.flush();
335
336 try {
337 cvwSock.getOutputStream().write(bs.toByteArray());
338 cvwSock.getOutputStream().flush();
339 }
340 catch (Exception v) {
341 System.err.println("CVWServerComm: Error opening Stream: " + v);
342 }
343 }
344
345 /* 8/19/96 dage
346 * this object should not be parsing the lines from the server....
347 * there should be a cvw interpretter that then passes the lines to be
348 * displayed to the user and then does something else with the other lines
349 */
350 /**
351 * Receives communication from the CVW server one line at a time. This does some
352 * processing if the line does not start with #$#, otherwise it is processed by
353 * the processMCP method.
354 * @param theLine the line of communication from the CVW server
355 * @see NetThread#run
356 * @see #processMCP
357 */
358 public synchronized void receiveLine(String theLine) {
359 String frameName, urlString;
360 int startUrl;
361 URL url;
362
363 //if(CVWCoordinator.DEBUG) System.err.println("the line: " + theLine);
364 //if(CVWCoordinator.DEBUG) System.err.println(Thread.currentThread() + "serverComm line: " + theLine);
365 // if(CVWCoordinator.DEBUG) System.err.println("GAB - Server sends: " + theLine);
366 if (theLine.startsWith("@#@")) {
367 //if(CVWCoordinator.DEBUG) System.err.println("the line: " + theLine);
368 startUrl = theLine.indexOf(' ');
369 frameName = theLine.substring(3, startUrl);
370 urlString = theLine.substring(startUrl+1);
371 //if(CVWCoordinator.DEBUG) System.err.println("framename: ." + frameName + ".");
372 //if(CVWCoordinator.DEBUG) System.err.println("urlString: ." + urlString + ".");
373 try {
374 // do we really want this? wouldn't think so (especially since applet.getAppletContext = null!)
375 // applet.getAppletContext().showDocument(new URL(urlString), frameName);
376 System.err.println("line removed in CVWServerComm");
377 } catch (Exception e) {
378 e.printStackTrace();
379 }
380 return;
381 }
382 if (theLine.startsWith("#$#x-login-failed")) {
383 //if(CVWCoordinator.DEBUG) System.err.println(theLine);
384 applet.loginFailed("Login unsuccessful.");
385 return;
386 }
387
388 //if ((theLine.startsWith("*** Connected ***")) |
389 //(theLine.startsWith("*** Redirecting old connection to this port ***")))
390 if (theLine.startsWith("#$#mcp")) {
391 //if(CVWCoordinator.DEBUG) System.err.println(theLine);
392 //if(CVWCoordinator.DEBUG) System.err.println(applet.toString());
393 //if(CVWCoordinator.DEBUG) System.err.println("connected " + cvwSock);
394 applet.initMCP();
395 }
396
397 if (theLine.startsWith("*** Redirecting connection to new port")) {
398 if(CVWCoordinator.DEBUG) System.err.println("redirected port ");
399 //applet.quitCommand();
400 closeConnection();
401 }
402
403 if (theLine.startsWith("*** Timed-out waiting for ")) {
404 //if(CVWCoordinator.DEBUG) System.err.println("not connected " + cvwSock);
405 closeConnection();
406 return;
407 /* 12/6/96 dage - tried using these to see if the state of the socket
408 * can be detected by the input/output streams.
409 try {
410 if(CVWCoordinator.DEBUG) System.err.println(cvwSock.getOutputStream());
411 cvwSock.getOutputStream().flush();
412 if(CVWCoordinator.DEBUG) System.err.println(cvwSock.getInputStream());
413 cvwSock.getInputStream().available();
414 cvwSock.getInputStream().read();
415 }
416 catch (Exception v) { if(CVWCoordinator.DEBUG) System.err.println(v.toString()); }
417 */
418 }
419
420 if (theLine.startsWith("#$#")) {
421 processMCP(theLine);
422 return;
423 }
424
425 if (theLine.startsWith("Proxy in ") && (theLine.indexOf("hears:") > 0)) {
426 //ProxyWindow.getInstance().processProxyCommand(theLine);
427 applet.displayMudText("#" + theLine);
428 return;
429 }
430
431 if (CVWCoordinator.DEBUG)
432 System.err.println(theLine);
433 if (serverName == null) {
434 if (theLine.indexOf("<!--") == 0) {
435 try {
436 int end = theLine.indexOf("-->");
437 if (end == -1) end = theLine.length();
438 serverName = theLine.substring(4, end);
439 } catch (Exception e) {
440 serverName = "";
441 }
442 }
443 }
444
445 if (applet.DEBUG)
446 applet.displayMudText("#" + theLine);
447 else
448 applet.displayMudText(" " + theLine);
449
450 }
451
452 /**
453 * Processes the communication line which represents MCP from the CVW server
454 * converting it to a MCP command and then acting upon the MCP.
455 * @param theLine the communication string from the CVW server
456 * @see #parseMCP
457 */
458 public void processMCP(String theLine) {
459
460 if(CVWCoordinator.DEBUG) {
461 if (theLine.indexOf("cvw-system-list-users") < 0 &&
462 theLine.indexOf("cvw-system-allusers") < 0)
463 System.err.println("theline: " + theLine);
464 else
465 System.err.println("thelistline: " + theLine);
466 }
467 MCPCommand mcpCommand = parseMCP(theLine);
468
469 String cmd = mcpCommand.get("cmd");
470
471 /* 11/12/96 gab - should make this into a smart cache. */
472 if (cmd.equals("cvw-object-info")) {
473 //if(CVWCoordinator.DEBUG) System.err.println("GAB - MCP: " + mcpCommand);
474 applet.cache.cacheObject(mcpCommand);
475 return;
476 }
477
478 if(!CVWCoordinator.DEBUG) System.err.println("mcp: " + cmd);
479
480 /* 12/11/96 dage -- only do url if url tag is present otherwise
481 * maybe a note or document or folder or ... */
482 // GAB - URL launching
483 if (cmd.equals("cvw-object-window")) {
484 CVWObject object = applet.cache.get(mcpCommand.get("object"));
485 //if(CVWCoordinator.DEBUG) System.err.println(object.type + " " + object.typeValue);
486 // dage - should check to make sure object is not null
487 if (object instanceof CVWNote) {
488 CVWNote note = (CVWNote)object;
489 note.open(mcpCommand.get("text"), mcpCommand.get("perms"));
490 return;
491 } else if (object instanceof CVWURL) {
492 CVWURL url = (CVWURL)object;
493 url.open(mcpCommand.get("url"));
494 return;
495
496 } else if (object instanceof CVWWhiteboard) {
497 CVWWhiteboard wb = (CVWWhiteboard)object;
498
499 // RJT may need to consider "perms" here
500 wb.open(mcpCommand.get("server"), mcpCommand.get("path"), mcpCommand.get("docid"),
501 mcpCommand.get("perms"));
502 return;
503
504 } else if (object instanceof CVWGroup) {
505 CVWGroup grp = (CVWGroup)object;
506 grp.open(mcpCommand.get("perms"),
507 mcpCommand.get("fullpath"));
508
509 } else if (object.type.equals("Folder") ||
510 object.type.equals("SC to Folder")) {
511 if (object != GroupManager.getCVWGroupMgr())
512 ((CVWFolder)object).open(mcpCommand.get("fullpath"),
513 mcpCommand.get("perms"));
514
515 } else if (object instanceof CVWDocument) {
516 CVWDocument doc = (CVWDocument)object;
517 doc.open();
518 }
519 } //end cvw-object-window
520
521
522 if (cmd.equals("cvw-object-export-info")) {
523 //if(CVWCoordinator.DEBUG) System.err.println("GAB - MCP: " + mcpCommand);
524 CVWObject object = applet.cache.get(mcpCommand.get("object"));
525 if (object == null)
526 return;
527 if (object instanceof CVWNote)
528 ((CVWNote)object).export(mcpCommand.get("text"));
529 else if (object instanceof CVWDocument)
530 ((CVWDocument)object).export();
531 return;
532 }
533
534 if (cmd.equals("cvw-document-whiteboard")) {
535 CVWObject object = applet.cache.get(mcpCommand.get("object"));
536 if (object == null || !(object instanceof CVWDocument))
537 return;
538 if (mcpCommand.get("error").equals("none"))
539 ((CVWDocument)object).createWhiteboard();
540 else
541 ((CVWDocument)object).createWhiteboardError(mcpCommand.get("error"));
542 return;
543 }
544
545
546 if (cmd.equals("cvw-whiteboard-add-listener")) {
547
548 //System.out.println("CVWServerComm::processMCP() cvw-whiteboard-add-listener");
549
550 CVWObject object = applet.cache.get(mcpCommand.get("object"));
551 if (object instanceof CVWWhiteboard) {
552 CVWWhiteboard wb = (CVWWhiteboard)object;
553 wb.addListener(mcpCommand.get("user"), mcpCommand.get("user-name"));
554 return;
555 }
556 }
557
558 if (cmd.equals("cvw-whiteboard-add-item")) {
559
560 //System.out.println("CVWServerComm::processMCP() cvw-whiteboard-add-item");
561
562 CVWObject object = applet.cache.get(mcpCommand.get("object"));
563 if (object instanceof CVWWhiteboard) {
564 CVWWhiteboard wb = (CVWWhiteboard)object;
565
566 wb.add(mcpCommand.get("item_id"), mcpCommand.get("item_owner"),
567 mcpCommand.get("owner-name"), mcpCommand.get("item_perms"),
568 mcpCommand.get("item_type"), mcpCommand.get("item_color"),
569 mcpCommand.get("linelist"));
570
571 return;
572 }
573 }
574
575 if (cmd.equals("cvw-whiteboard-revert-item")) {
576
577 //System.out.println("CVWServerComm::processMCP() cvw-whiteboard-revert-item");
578
579 CVWObject object = applet.cache.get(mcpCommand.get("object"));
580 if (object instanceof CVWWhiteboard) {
581 CVWWhiteboard wb = (CVWWhiteboard)object;
582
583 wb.revert(mcpCommand.get("item_id"), mcpCommand.get("item_owner"),
584 mcpCommand.get("owner-name"), mcpCommand.get("item_perms"),
585 mcpCommand.get("old_item_id"), mcpCommand.get("item_type"),
586 mcpCommand.get("item_color"), mcpCommand.get("linelist"));
587 return;
588 }
589 }
590
591 if (cmd.equals("cvw-whiteboard-remove-item")) {
592
593 //System.out.println("CVWServerComm::processMCP() cvw-whiteboard-remove-item");
594
595 CVWObject object = applet.cache.get(mcpCommand.get("object"));
596 if (object instanceof CVWWhiteboard) {
597 CVWWhiteboard wb = (CVWWhiteboard)object;
598
599 wb.remove(mcpCommand.get("item_id"), "none");
600 return;
601 }
602 }
603
604 if (cmd.equals("cvw-whiteboard-remove-result")) {
605
606 //System.out.println("CVWServerComm::processMCP() cvw-whiteboard-remove-result");
607
608 CVWObject object = applet.cache.get(mcpCommand.get("object"));
609 if (object instanceof CVWWhiteboard) {
610 CVWWhiteboard wb = (CVWWhiteboard)object;
611
612 wb.remove(mcpCommand.get("item_id"), mcpCommand.get("error"));
613 return;
614 }
615 }
616
617 if (cmd.equals("cvw-whiteboard-remove-listener")) {
618
619 //System.out.println("CVWServerComm::processMCP() cvw-whiteboard-remove-listener");
620
621 CVWObject object = applet.cache.get(mcpCommand.get("object"));
622 if (object instanceof CVWWhiteboard) {
623 CVWWhiteboard wb = (CVWWhiteboard)object;
624
625 wb.rmListener(mcpCommand.get("user"), mcpCommand.get("user-name"));
626 return;
627 }
628 }
629
630 // GAB - 12/15/96 Open channel for launching audio
631 /* 7/17/97 dage - for some reason, if stopped/started one and then
632 * start/stop the other, the second would stop. So stopped both, then
633 * started both
634 * 8/20/97 dage - replace x-mcast-channel with cvw-av-audio, noticed
635 * that Gary was not using other parameters
636 mcpCommand.get("room");
637 mcpCommand.get("title");
638 mcpCommand.get("name");
639 * 2/16/98 dage - do all this in a method in applet rather than here.
640 * 8/27/98 dage - support 1.2 version
641 */
642 if (cmd.equals("cvw-av-audio")) {
643 //if(CVWCoordinator.DEBUG) System.err.println("GAB - mcast address is " + applet.mcastAddress);
644 AVController.getInstance().setAV(mcpCommand.get("primary"));
645 return;
646 }
647
648 if (cmd.equals("cvw-av-mcast-address")) {
649 AVController.getInstance().setAV(mcpCommand.get("location"), mcpCommand.get("audio_port"),
650 mcpCommand.get("video_port"),
651 mcpCommand.get("room"));
652 }
653
654 if (cmd.equals("cvw-av-audio-request")) {
655 String port = mcpCommand.get("port");
656 PhoneConversation.receivePhoneRequest(mcpCommand.get("from"),
657 mcpCommand.get("to"),
658 mcpCommand.get("location"),
659 mcpCommand.get("when"),
660 port);
661 return;
662 }
663
664 if (cmd.equals("cvw-av-audio-request-result")) {
665 String port = mcpCommand.get("port");
666 PhoneConversation.receivePhoneRequestResult(mcpCommand.get("from"),
667 mcpCommand.get("to"),
668 mcpCommand.get("location"),
669 mcpCommand.get("error"),
670 mcpCommand.get("receiver"),
671 mcpCommand.get("message"),
672 port);
673 return;
674 }
675
676 if (cmd.equals("cvw-av-audio-request-cancel")) {
677 PhoneConversation.receivePhoneRequestCancel(mcpCommand.get("from"),
678 mcpCommand.get("to"));
679 return;
680 }
681
682 if (cmd.equals("cvw-av-video-bandwidth")) {
683 AVController.getInstance().setVideoMaxBandwidth(mcpCommand.get("max"));
684 return;
685 }
686
687 if (cmd.equals("cvw-lookup-user-match")) {
688 if (mcpCommand.get("match").equals("1"))
689 applet.serverFindUserReturn(new CVWObjNum(mcpCommand.get("object")),
690 mcpCommand.get("name"));
691 else
692 applet.serverFindUserReturnFailed();
693 return;
694 }
695
696 /* 8/20/98 dage - added hooks for cvw-lookup-who-user
697 */
698 if (cmd.equals("cvw-lookup-who-user")) {
699 String name = mcpCommand.get("name");
700 String oNum = mcpCommand.get("object");
701 String iState = mcpCommand.get("idle_state");
702 if (iState == null) {
703 String dTime = mcpCommand.get("last_disconnect_time");
704 if (dTime == null)
705 dTime = mcpCommand.get("last_connect_time");
706 WhoUserProcessor.getInstance().whoUserInfoDisconnected(name, oNum, dTime);
707 } else
708 WhoUserProcessor.getInstance().whoUserInfo(name, oNum,mcpCommand.get("location"),
709 iState,
710 mcpCommand.get("idle_time"),
711 mcpCommand.get("idle_message"),
712 mcpCommand.get("busy_state"));
713 return;
714 }
715
716 if (cmd.equals("cvw-lookup-who-problem")) {
717 WhoUserProcessor.getInstance().whoUserInfoError( mcpCommand.get("user"),
718 mcpCommand.get("problem"));
719 return;
720 }
721
722 if (cmd.equals("cvw-lookup-who-end")) {
723 WhoUserProcessor.getInstance().whoUserInfoEnd();
724 return;
725 }
726
727 /* 5/4/99 dage - find protocol
728 */
729 if (cmd.startsWith("cvw-lookup")) {
730 FindFrame.receiveResults(mcpCommand);
731 return;
732 }
733
734 /* 9/23/96 dage -- added catch for cvw-object-detail
735 * 3/24/98 dage -- CVWDocument now implements getInfo
736 */
737 if (cmd.startsWith("cvw-object-detail")) {
738
739 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("object"));
740 CVWObject cvwObj = applet.cache.get(objNum);
741
742 if (cvwObj == null) { //shouldnt happen
743 System.err.println("Object not in the cache.");
744 return;
745 }
746 if (cvwObj instanceof CVWUser) {
747 //if(CVWCoordinator.DEBUG) System.err.println("GAB - Got a user object");
748 CVWUser user = (CVWUser)cvwObj;
749 if (mcpCommand.containsKey("info_only"))
750 user.setDetailInfo( mcpCommand.get("full_name"));
751 else {
752 user.setDetailInfo( mcpCommand.get("full_name"),
753 mcpCommand.get("badge"),
754 mcpCommand.get("office"),
755 mcpCommand.get("phone"),
756 mcpCommand.get("description"),
757 mcpCommand.get("email_address"),
758 mcpCommand.get("gender"));
759 user.getInfo();
760 }
761 } else if (cvwObj instanceof CVWNote) {
762 //((CVWNote)cvwObj).getInfo(mcpCommand.get("description"),
763 cvwObj.getInfo(mcpCommand.get("description"),
764 mcpCommand.get("perms"),
765 //mcpCommand.get("object-owner-name"));
766 mcpCommand.get("owners"));
767 } else if (cvwObj instanceof CVWURL) {
768 ((CVWURL)cvwObj).getInfo(mcpCommand.get("description"),
769 mcpCommand.get("perms"),
770 //mcpCommand.get("object-owner-name"),
771 mcpCommand.get("owners"),
772 mcpCommand.get("path"));
773 } else if (cvwObj instanceof CVWWhiteboard) {
774 ((CVWWhiteboard)cvwObj).getInfo(mcpCommand.get("description"),
775 mcpCommand.get("perms"),
776 //mcpCommand.get("object-owner-name"),
777 mcpCommand.get("owners"),
778 mcpCommand.get("path"));
779 } else if (cvwObj instanceof CVWGroup) {
780 //((CVWGroup)cvwObj).getInfo(mcpCommand.get("description"),
781 cvwObj.getInfo(mcpCommand.get("description"),
782 mcpCommand.get("perms"),
783 //mcpCommand.get("object-owner-name"),
784 mcpCommand.get("owners"));
785 } else if (cvwObj instanceof CVWRoom) {
786 cvwObj.getInfo(mcpCommand.get("description"),
787 mcpCommand.get("perms"),
788 mcpCommand.get("owners"));
789 } else if (cvwObj instanceof CVWDocument) {
790 //applet.openInfoDialog(new CVWObjNum(mcpCommand.get("object")),
791 ((CVWDocument)cvwObj).getInfo( mcpCommand.get("description"),
792 mcpCommand.get("perms"),
793 mcpCommand.get("owners"));
794 } else {
795 //just plain object
796 cvwObj.getInfo(mcpCommand.get("description"),
797 mcpCommand.get("perms"),
798 mcpCommand.get("owners"));
799 }
800 return;
801
802 }
803
804 /* 5/30/98 dage - added cvw-access-set-acl/owners-result
805 */
806 if (cmd.equals("cvw-access-admit-request")) {
807 CVWObject room = CVWCache.getInstance().get(mcpCommand.get("room"));
808 if (room != null && room instanceof CVWRoom)
809 ((CVWRoom)room).requestAdmitUserCommand(mcpCommand);
810 return;
811 }
812
813 if (cmd.equals("cvw-access-admit-request-result")) {
814 CVWObject room = CVWCache.getInstance().get(mcpCommand.get("room"));
815 if (room != null && room instanceof CVWRoom)
816 ((CVWRoom)room).requestAdmitUserResult(mcpCommand);
817 return;
818 }
819
820 if (cmd.equals("cvw-access-admit-key-revoked")) {
821 CVWObject room = CVWCache.getInstance().get(mcpCommand.get("room"));
822 if (room != null && room instanceof CVWRoom)
823 ((CVWRoom)room).revokeAdmitKey(mcpCommand.get("key"), mcpCommand.get("when"));
824 return;
825 }
826
827 if (cmd.equals("cvw-access-set-acl-result")) {
828 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("object"));
829 CVWObject cvwObj = applet.cache.get(objNum);
830 if (cvwObj == null) return; // should never happen
831 cvwObj.updateACLResult( mcpCommand.get("error"),
832 mcpCommand.get("acl"));
833 return;
834 }
835
836 if (cmd.equals("cvw-access-set-owners-result")) {
837 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("object"));
838 CVWObject cvwObj = applet.cache.get(objNum);
839 if (cvwObj == null) return; // should never happen
840 cvwObj.updateOwnersResult( mcpCommand.get("error"),
841 mcpCommand.get("owners"));
842 return;
843 }
844
845 /* 9/5/97 dage - added cvw-access-set-acl/owners-result
846 * 9/5/97 dage - added cvw-group-add/del-member-result
847 */
848 if (cmd.equals("cvw-group-add-member-result")) {
849 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("group"));
850 CVWGroup cvwObj = (CVWGroup)applet.cache.get(objNum);
851 if (cvwObj == null) return; // should never happen
852 cvwObj.updateMembersResult( mcpCommand.get("error"),
853 0, //"ADD"
854 mcpCommand.get("members"),
855 mcpCommand.get("invalid"),
856 mcpCommand.get("redundant"));
857 return;
858 }
859
860 if (cmd.equals("cvw-group-del-member-result")) {
861 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("group"));
862 CVWGroup cvwObj = (CVWGroup)applet.cache.get(objNum);
863 if (cvwObj == null) return; // should never happen
864 cvwObj.updateMembersResult( mcpCommand.get("error"),
865 1, //"DEL"
866 mcpCommand.get("members"),
867 mcpCommand.get("invalid"),
868 mcpCommand.get("missing"));
869 return;
870 }
871
872 /* 9/10/97 dage -- this should be caught with cvw-access-acl but
873 * assume that the only object sent is for the current room.
874 */
875 if (cmd.equals("cvw-access-acl")) {
876 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("object"));
877 CVWRoom cvwObj = (CVWRoom)applet.cache.get(objNum);
878 if (cvwObj == null) return; // should never happen
879 cvwObj.setContents(mcpCommand.get("acl"));
880
881 }
882
883 /* 11/20/96 dage -
884 * 9/7/97 dage - dont call objectIsNote, method objectCreateResult will
885 * do it.
886 */
887 if (cmd.equals("cvw-object-create-result")) {
888 if (mcpCommand.get("error").equals("1"))
889 CVWObject.objectCreateError(mcpCommand);
890 else {
891 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("object"));
892 CVWObject cvwObj = CVWCache.getInstance().get(objNum);
893 if (cvwObj == null) { // should never happen
894 cvwObj = new CVWObject();
895 cvwObj.setValues(objNum, "Item");
896 }
897 cvwObj.objectCreateResult(mcpCommand);
898 }
899 }
900
901 /* 11/20/96 dage -
902 */
903 if (cmd.equals("cvw-object-copy-result")) {
904 CVWObjNum objNum = new CVWObjNum(mcpCommand.get("object"));
905 CVWObject cvwObj = CVWCache.getInstance().get(objNum);
906 if (cvwObj == null) { // should never happen
907 cvwObj = new CVWObject();
908 cvwObj.setValues(objNum, "Item");
909 }
910 if(CVWCoordinator.DEBUG) System.err.println("GAB - we copied : " + mcpCommand);
911 cvwObj.objectCopyResult(mcpCommand);
912 return;
913 }
914
915 /* 1/5/98 dage - make applet do all this work
916 * 3/2/99 dage - make doc do all this work
917 * 11/4/99 dage - add hook for wb bkg doc copy
918 */
919 // GAB - mcp recieved if we are copying a document
920 if (cmd.equals("cvw-document-copy")) {
921 String objNum = mcpCommand.get("object");
922 CVWObject obj = CVWCache.getInstance().get(objNum);
923 CVWDocument doc;
924 if (obj instanceof CVWWhiteboard) {
925 ((CVWWhiteboard)obj).doDocBkgCopy(mcpCommand.get("new_object"));
926 return;
927 }
928 if (obj != null && obj instanceof CVWDocument)
929 doc = (CVWDocument)obj;
930 else {
931 doc = new CVWDocument(CVWObject.DOCUMENT, mcpCommand.get("docid"));
932 doc.objNum = new CVWObjNum(objNum);
933 }
934 doc.doDocCopy(mcpCommand.get("new_object"));
935 return;
936 }
937
938 /* 10/15/96 dage - x-icon-box no longer caught
939 if (cmd.equals("x-icon-box")) {
940 applet.roomDescription(mcpCommand.get("objnum"), mcpCommand.get("name"));
941 return;
942 }
943 */
944
945 if (cmd.startsWith("cvw-auth")) {
946 applet.processAuthorization(cmd, mcpCommand);
947 return;
948 }
949
950 // dage 8/28/96 need to trap other protocol stuff and store it
951 // maybe should do this and the following in processMCP
952 /* 10/16/96 dage - moved from recieveLine to here.
953 */
954 if (cmd.startsWith("protocol"))
955 { //if(CVWCoordinator.DEBUG) System.err.println(theLine);
956 applet.processProtocol(mcpCommand);
957 return;}
958
959 /* dage 10/7/96 -- removed casting to string, no longer needed, mcpCommand
960 * class returns strings always.
961 */
962 if (cmd.startsWith("cvw-map-info")) {
963 Integer total = new Integer(mcpCommand.get("totalfloors"));
964 String roomNames = mcpCommand.get("rooms");
965 String roomObjs = mcpCommand.get("roomobjs");
966 String floorNames = mcpCommand.get("floors");
967 String floorObjs = mcpCommand.get("floorobjs");
968 applet.updateMap(total.intValue(),floorNames,floorObjs,roomNames, roomObjs);
969 return;
970 }
971
972 /* dage 8/19/98 -- changed from cvw-system-allusers to cvw-system-onusers
973 * added busy tag
974 */
975 if (cmd.equals("cvw-system-onusers")) {
976 WindowMgr winMgr = WindowMgr.getWindowMgr();
977 OnlineUserList win = (OnlineUserList)winMgr.findToolWindow("OnlineUserList");
978 if (win != null)
979 win.updateOnlineUsers(mcpCommand.get("user"),mcpCommand.get("location"),
980 mcpCommand.get("idle"),mcpCommand.get("msgs"),
981 mcpCommand.get("busy"));
982
983 return;
984 }
985
986 if (cmd.equals("cvw-system-allusers")) {
987 WindowMgr winMgr = WindowMgr.getWindowMgr();
988 AllUserList win = (AllUserList)winMgr.findToolWindow("AllUserList");
989 if (win != null)
990 win.updateAllUsers(mcpCommand.get("objnums"), mcpCommand.get("unames"),
991 mcpCommand.get("locations"),
992 mcpCommand.get("emails"),
993 mcpCommand.get("idles"),
994 mcpCommand.get("fullnames"),
995 mcpCommand.get("busy"),
996 mcpCommand.get("server"));
997 return;
998 }
999
1000 if (cmd.equals("cvw-system-objects")) {
1001 String oNum = mcpCommand.get("group_manager");
1002 if (oNum != null)
1003 GroupManager.setCVWGroupMgr(oNum);
1004 return;
1005 }
1006
1007 if (cmd.equals("cvw-system-motd")) {
1008 //new CVWAnnouncementDialog(applet, mcpCommand.get("message"));
1009 applet.systemMOTD(mcpCommand.get("message"));
1010 return;
1011 }
1012
1013/* 8/19/97 dage - added cvw-system-list-users/groups
1014 */
1015 if (cmd.equals("cvw-system-list-users")) {
1016 String objNums = mcpCommand.get("users");
1017 String names = mcpCommand.get("names");
1018 String fullNames = mcpCommand.get("full_names");
1019//System.err.println("fullNames." + fullNames);
1020 //applet.updateSystemUsers(objNums,names,fullNames);
1021 GroupManager.getInstance().updateSystemUsers(objNums,names,fullNames);
1022 return;
1023 }
1024
1025 if (cmd.equals("cvw-system-list-groups")) {
1026 String objNums = mcpCommand.get("groups");
1027 String names = mcpCommand.get("names");
1028 String owners = mcpCommand.get("owners");
1029 //applet.updateSystemGroups(objNums,names,owners);
1030 GroupManager.getInstance().updateSystemGroups(objNums,names,owners);
1031 return;
1032 }
1033
1034/* 2/22/00 dage - added cvw-user-quota
1035 */
1036 if (cmd.equals("cvw-user-quota")) {
1037 applet.userQuota(mcpCommand.get("quota"));
1038 return;
1039 }
1040
1041/* 8/20/97 dage - added cvw-user-audit
1042 * 8/27/97 dage - should prolly just send the mcp command
1043 */
1044 if (cmd.startsWith("cvw-user-audit")) {
1045 applet.userAudit(mcpCommand.get("user"),
1046 mcpCommand.get("quota"),
1047 mcpCommand.get("objects"),
1048 mcpCommand.get("environments"),
1049 mcpCommand.get("fullpaths"),
1050 mcpCommand.get("shared_objects"),
1051 mcpCommand.get("shared_environments"),
1052 mcpCommand.get("shared_fullpaths"));
1053 return;
1054 }
1055
1056/* 8/22/97 dage - added cvw-user-password-set-result
1057 */
1058 if (cmd.equals("cvw-user-password-set-result")) {
1059 applet.passwordResult(mcpCommand.get("user"),
1060 mcpCommand.get("error"),
1061 mcpCommand.get("old"),
1062 mcpCommand.get("new"));
1063 return;
1064 }
1065
1066/* 2/28/98 dage - added cvw-user-move-notify
1067 */
1068 if (cmd.equals("cvw-user-move-notify")) {
1069 CVWObject room = applet.cache.get(mcpCommand.get("where"));
1070 TextProcessor tp = TextProcessor.getTextProcessor(room);
1071 if (tp != null)
1072 //applet.moveNotify
1073 tp.moveNotify(mcpCommand.get("user"),
1074 mcpCommand.get("where"),
1075 mcpCommand.get("type"));
1076 //else System.err.println("text proc is null " + mcpCommand);
1077 return;
1078 }
1079
1080
1081/* 2/28/98 dage - added cvw-user-connection-notify
1082 */
1083 if (cmd.equals("cvw-user-connection-notify")) {
1084 CVWObject room = applet.cache.get(mcpCommand.get("where"));
1085 TextProcessor tp = TextProcessor.getTextProcessor(room);
1086 if (tp != null)
1087 //applet.connectionNotify
1088 tp.connectionNotify(mcpCommand.get("user"),
1089 mcpCommand.get("where"),
1090 mcpCommand.get("when"),
1091 mcpCommand.get("type"));
1092 //else System.err.println("text proc is null " + mcpCommand);
1093 return;
1094 }
1095
1096
1097/* 2/28/98 dage - added cvw-user-idle-notify
1098 */
1099 if (cmd.equals("cvw-user-idle-notify")) {
1100 CVWObject room = applet.cache.get(mcpCommand.get("where"));
1101 TextProcessor tp = TextProcessor.getTextProcessor(room);
1102 if (tp != null)
1103 //applet.idleNotify
1104 tp.idleNotify(mcpCommand.get("user"),
1105 mcpCommand.get("where"),
1106 mcpCommand.get("when"),
1107 mcpCommand.get("message"));
1108 //else System.err.println("text proc is null " + mcpCommand);
1109 return;
1110 }
1111
1112/* 2/12/98 dage - added cvw-preferences-time-notify
1113 * 7/28/98 dage - notify all text processors of time stamp
1114 */
1115 if (cmd.equals("cvw-preferences-time-notify")) {
1116 TextProcessor tp;
1117 Vector v = TextProcessor.getTextProcessors();
1118 if (v == null) return;
1119 for (int i = 0; i < v.size(); i++) {
1120 tp = (TextProcessor)v.elementAt(i);
1121 if (tp != null)
1122 tp.timeNotify(mcpCommand.get("time"));
1123 //else System.err.println("text proc is null " + mcpCommand);
1124 }
1125 return;
1126 }
1127
1128/* 9/2/97 dage - added cvw-preferences
1129 * 5/22/98 dage - ver 1.1 split highlight_comm into highlight_private_comm and
1130 * hilight_public_comm
1131 */
1132 if (cmd.equals("cvw-preferences")) {
1133
1134 String pubComm = mcpCommand.get("highlight_public_comm");
1135 String prvComm = mcpCommand.get("highlight_private_comm");
1136 if (prvComm == null)
1137 prvComm = mcpCommand.get("highlight_comm");
1138 CVWPreferences cvwPrefs = applet.getPrefs();
1139 if (cvwPrefs != null) // shouldnt be
1140 cvwPrefs.update(mcpCommand.get("highlight_name"),
1141 prvComm,
1142 pubComm,
1143 mcpCommand.get("highlight_objects"),
1144 mcpCommand.get("highlight_objects_colors"),
1145 mcpCommand.get("time_stamp"),
1146 mcpCommand.get("idle_default_msg"));
1147 return;
1148 }
1149
1150/* 9/2/97 dage - added cvw-preferences-set-result ... someday may want to
1151 * pass the parameters which were send in case of error.
1152 */
1153 if (cmd.equals("cvw-preferences-set-result")) {
1154 applet.confirmPrefsFromServer(mcpCommand.get("error"),
1155 mcpCommand.get("error_msg"));
1156 return;
1157 }
1158
1159/* 10/15/96 dage - send the room name as well
1160 */
1161 if (cmd.startsWith("cvw-env-changed")) {
1162 Integer index = new Integer(mcpCommand.get("floornum"));
1163
1164 applet.roomChange(index.intValue(),
1165 mcpCommand.get("newroom"),
1166 mcpCommand.get("room_name"));
1167 return;
1168 }
1169
1170/* 2/25/97 dage - send the room name as well
1171 */
1172 if (cmd.startsWith("cvw-env-move-error")) {
1173 applet.moveError(mcpCommand);
1174 }
1175
1176// dage 8/28/96 grab user name and id... may need to store
1177// in a CVWUser object
1178 if (cmd.startsWith("cvw-init-id-user")) {
1179 applet.initUserID(mcpCommand.get("name"),
1180 new CVWObjNum(mcpCommand.get("object")),
1181 mcpCommand.get("priv"),
1182 mcpCommand.get("quota"));
1183 return;
1184 }
1185
1186/* 9/12/96 dage -- save the server name of the user --
1187 * thought needed for popup page but instead needs to be
1188 * in mcp protocol
1189 */
1190 if (cmd.startsWith("cvw-init-id-server")) {
1191 applet.initServerID(mcpCommand.get("name"), mcpCommand.get("id"));
1192 String docserver = mcpCommand.get("docserver");
1193 if (docserver != null) DocumentServerList.setLocalDocServerName(docserver);
1194 return;
1195 }
1196
1197/* 8/7/98 dage -- server knows the latest release of the client
1198 */
1199 if (cmd.startsWith("cvw-init-id-client-result")) {
1200 applet.initClientIDResult(mcpCommand.get("error"),
1201 mcpCommand.get("version"),
1202 mcpCommand.get("current-version"),
1203 mcpCommand.get("url"));
1204 return;
1205 }
1206
1207/* 11/18/96 dage -- result??? why not error?
1208 */
1209 //if (cmd.startsWith("cvw-text-error"))
1210 if (cmd.equals("cvw-text-result")) {
1211 //if(CVWCoordinator.DEBUG) System.err.println(mcpCommand);
1212 applet.textProc.textResult(mcpCommand);
1213 //applet.textResultNotification(mcpCommand);
1214 return;
1215 }
1216
1217 if (cmd.equals("cvw-text-result-end")) {
1218 //if(CVWCoordinator.DEBUG) System.err.println(mcpCommand);
1219 applet.textProc.textResultEnd(mcpCommand);
1220 //applet.textResultNotification(mcpCommand);
1221 return;
1222 }
1223
1224/* 11/18/96 dage -- this will be the answer from page or remote_emote
1225 * 11/21/96 dage - text-receipt is no longer used.
1226 //if (cmd.startsWith("cvw-text-receipt"))
1227 if (cmd.startsWith("cvw-text-display")) {
1228 //if(CVWCoordinator.DEBUG) System.err.println(mcpCommand);
1229 applet.textDisplayNotification(mcpCommand.get("text"),
1230 mcpCommand.get("title"));
1231 return;
1232 }
1233 */
1234
1235/* 8/05/97 dage --
1236 */
1237 if (cmd.equals("cvw-text-start")) {
1238 // if(CVWCoordinator.DEBUG) System.err.println(mcpCommand);
1239 applet.textStartDelayNotification(mcpCommand.get("type"));
1240 return;
1241 }
1242
1243/* 8/05/97 dage --
1244 */
1245 if (cmd.equals("cvw-text-stop")) {
1246 // if(CVWCoordinator.DEBUG) System.err.println(mcpCommand);
1247 applet.textStopDelayNotification();
1248 return;
1249 }
1250
1251/* 9/12/96 dage -- this is just temp until the new protocol is
1252 * designed for pages... also currently just displays generic message
1253 * 9/17/96 dage -- this currently uses CVWDialog class which in
1254 * future will be renamed to something more appropriate.
1255 * 9/19/96 dage -- renamed to PagePopupDialog include the sender
1256 * object number.... this will go away when we send the sender user
1257 * object in rather than just information.
1258 * 9/19/96 dage -- had to change to reflect the new mcp protocol
1259 */
1260 if (cmd.equals("cvw-text")) {
1261 // if(CVWCoordinator.DEBUG) System.err.println(mcpCommand);
1262 applet.textProc.textNotification(mcpCommand);
1263 //applet.textNotification(mcpCommand);
1264 return;
1265 }
1266
1267/* 2/16/98 dage -- notification from a user dismissing a popup
1268 */
1269 if (cmd.equals("cvw-text-receipt")) {
1270 applet.textProc.textPopupDismissNotification(mcpCommand.get("type"),
1271 mcpCommand.get("level"),
1272 mcpCommand.get("when"),
1273 mcpCommand.get("recipient"));
1274 }
1275
1276/* 2/13/97 dee changed, deb added comment from dee's cvs commit ....
1277 understand both forms (with and without
1278 message parameter) like xcvw. So now whois and anything else that
1279 tries to open a url will work.
1280 * 8/20/97 dage - replace display-url with cvw-text-url but still not
1281 * completely mcp-ifyed, client sends @url and from: #xxx is not sent
1282 * from client. Also moved to cvw-text area.
1283 * 2/27/98 dage - added from parameter. when and where are also
1284 * sent down the pipe but no currently used.
1285 */
1286 if (cmd.equals("cvw-text-url")) {
1287 if (mcpCommand.containsKey("message")) {
1288 applet.textProc.displayURL(mcpCommand.get("message"),
1289 mcpCommand.get("from"),
1290 mcpCommand.get("when"),
1291 mcpCommand.get("where"), // if sent to room
1292 mcpCommand.get("to"), // if sent to user
1293 mcpCommand.get("url"),
1294 mcpCommand.get("public"));
1295 } else
1296 applet.openURL(mcpCommand.get("url"));
1297 return;
1298 }
1299
1300 if (cmd.equals("cvw-text-url-result")) {
1301 if