0
|
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC.
|
|
2 // All rights reserved.
|
|
3 //
|
|
4 //-------------------------------------------------------------------------
|
|
5 // This file is part of the TightVNC software. Please visit our Web site:
|
|
6 //
|
|
7 // http://www.tightvnc.com/
|
|
8 //
|
|
9 // This program is free software; you can redistribute it and/or modify
|
|
10 // it under the terms of the GNU General Public License as published by
|
|
11 // the Free Software Foundation; either version 2 of the License, or
|
|
12 // (at your option) any later version.
|
|
13 //
|
|
14 // This program is distributed in the hope that it will be useful,
|
|
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 // GNU General Public License for more details.
|
|
18 //
|
|
19 // You should have received a copy of the GNU General Public License along
|
|
20 // with this program; if not, write to the Free Software Foundation, Inc.,
|
|
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
22 //-------------------------------------------------------------------------
|
|
23 //
|
|
24
|
|
25 package com.glavsoft.rfb.protocol.state;
|
|
26
|
1
|
27 import alice.datasegment.DataSegment;
|
18
|
28 import alice.datasegment.ReceiveData;
|
1
|
29
|
0
|
30 import com.glavsoft.exceptions.AuthenticationFailedException;
|
|
31 import com.glavsoft.exceptions.FatalException;
|
|
32 import com.glavsoft.exceptions.TransportException;
|
|
33 import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
|
|
34 import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
|
|
35 import com.glavsoft.rfb.encoding.ServerInitMessage;
|
|
36 import com.glavsoft.rfb.protocol.ProtocolContext;
|
|
37 import com.glavsoft.rfb.protocol.ProtocolSettings;
|
|
38
|
|
39 import java.util.logging.Logger;
|
|
40
|
|
41 /**
|
|
42 * ClientInit
|
|
43 *
|
|
44 * Once the client and server are sure that they're happy to talk to one
|
|
45 * another, the client sends an initialisation message. At present this
|
|
46 * message onl@!,@!,y consists of a boolean indicating whether the server should try
|
|
47 * to share the desktop by leaving other clients connected, or give exclusive
|
|
48 * access to this client by disconnecting all other clients.
|
|
49 *
|
|
50 * 1 - U8 - shared-flag
|
|
51 *
|
|
52 * Shared-flag is non-zero (true) if the server should try to share the desktop by leaving
|
|
53 * other clients connected, zero (false) if it should give exclusive access to this client by
|
|
54 * disconnecting all other clients.
|
|
55 *
|
|
56 * ServerInit
|
|
57 *
|
|
58 * After receiving the ClientInit message, the server sends a ServerInit message. This
|
|
59 * tells the client the width and height of the server’s framebuffer, its pixel format and the
|
|
60 * name associated with the desktop.
|
|
61 */
|
|
62 public class InitState extends ProtocolState {
|
|
63
|
|
64 public InitState(ProtocolContext context) {
|
|
65 super(context);
|
|
66 }
|
|
67
|
|
68 @Override
|
|
69 public boolean next() throws UnsupportedProtocolVersionException, TransportException,
|
|
70 UnsupportedSecurityTypeException, AuthenticationFailedException, FatalException {
|
|
71 clientAndServerInit();
|
|
72 return false;
|
|
73 }
|
|
74
|
|
75 protected void clientAndServerInit() throws TransportException {
|
|
76 ServerInitMessage serverInitMessage = getServerInitMessage();
|
|
77 ProtocolSettings settings = context.getSettings();
|
|
78 settings.enableAllEncodingCaps();
|
|
79 completeContextData(serverInitMessage);
|
|
80 }
|
|
81
|
|
82 protected void completeContextData(ServerInitMessage serverInitMessage) {
|
18
|
83 ReceiveData rData = new ReceiveData(serverInitMessage, false, false);
|
|
84 DataSegment.getLocal().put("ServerInitMessage", rData, null);
|
0
|
85 context.setPixelFormat(serverInitMessage.getPixelFormat());
|
|
86 context.setFbWidth(serverInitMessage.getFrameBufferWidth());
|
|
87 context.setFbHeight(serverInitMessage.getFrameBufferHeight());
|
|
88 context.setRemoteDesktopName(serverInitMessage.getName());
|
|
89 Logger.getLogger(getClass().getName()).fine(serverInitMessage.toString());
|
|
90 }
|
|
91
|
|
92 protected ServerInitMessage getServerInitMessage() throws TransportException {
|
|
93 writer.write(context.getSettings().getSharedFlag());
|
|
94 return new ServerInitMessage(reader);
|
|
95 }
|
|
96
|
|
97
|
|
98 }
|