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
|
|
27 import com.glavsoft.exceptions.AuthenticationFailedException;
|
|
28 import com.glavsoft.exceptions.FatalException;
|
|
29 import com.glavsoft.exceptions.TransportException;
|
|
30 import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
|
|
31 import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
|
|
32 import com.glavsoft.rfb.encoding.ServerInitMessage;
|
|
33 import com.glavsoft.rfb.protocol.ProtocolContext;
|
|
34 import com.glavsoft.rfb.protocol.ProtocolSettings;
|
|
35
|
|
36 import java.util.logging.Logger;
|
|
37
|
|
38 /**
|
|
39 * ClientInit
|
|
40 *
|
|
41 * Once the client and server are sure that they're happy to talk to one
|
|
42 * another, the client sends an initialisation message. At present this
|
|
43 * message onl@!,@!,y consists of a boolean indicating whether the server should try
|
|
44 * to share the desktop by leaving other clients connected, or give exclusive
|
|
45 * access to this client by disconnecting all other clients.
|
|
46 *
|
|
47 * 1 - U8 - shared-flag
|
|
48 *
|
|
49 * Shared-flag is non-zero (true) if the server should try to share the desktop by leaving
|
|
50 * other clients connected, zero (false) if it should give exclusive access to this client by
|
|
51 * disconnecting all other clients.
|
|
52 *
|
|
53 * ServerInit
|
|
54 *
|
|
55 * After receiving the ClientInit message, the server sends a ServerInit message. This
|
|
56 * tells the client the width and height of the server’s framebuffer, its pixel format and the
|
|
57 * name associated with the desktop.
|
|
58 */
|
|
59 public class InitState extends ProtocolState {
|
|
60
|
|
61 public InitState(ProtocolContext context) {
|
|
62 super(context);
|
|
63 }
|
|
64
|
|
65 @Override
|
|
66 public boolean next() throws UnsupportedProtocolVersionException, TransportException,
|
|
67 UnsupportedSecurityTypeException, AuthenticationFailedException, FatalException {
|
|
68 clientAndServerInit();
|
|
69 return false;
|
|
70 }
|
|
71
|
|
72 protected void clientAndServerInit() throws TransportException {
|
|
73 ServerInitMessage serverInitMessage = getServerInitMessage();
|
|
74 ProtocolSettings settings = context.getSettings();
|
|
75 settings.enableAllEncodingCaps();
|
|
76 completeContextData(serverInitMessage);
|
|
77 }
|
|
78
|
|
79 protected void completeContextData(ServerInitMessage serverInitMessage) {
|
|
80 context.setPixelFormat(serverInitMessage.getPixelFormat());
|
|
81 context.setFbWidth(serverInitMessage.getFrameBufferWidth());
|
|
82 context.setFbHeight(serverInitMessage.getFrameBufferHeight());
|
|
83 context.setRemoteDesktopName(serverInitMessage.getName());
|
|
84 Logger.getLogger(getClass().getName()).fine(serverInitMessage.toString());
|
|
85 }
|
|
86
|
|
87 protected ServerInitMessage getServerInitMessage() throws TransportException {
|
|
88 writer.write(context.getSettings().getSharedFlag());
|
|
89 return new ServerInitMessage(reader);
|
|
90 }
|
|
91
|
|
92
|
|
93 }
|