示例#1
0
        private static void SendBuffer(ClientHandle h)
        {
            h.DoSendTitle(_title);
            h.DoSendStatus(_status);

            foreach (string output in _outputs.Skip(_outputs.Count - 200))
            {
                h.DoSendOutput(output);
            }
        }
示例#2
0
        private static void OnConnection(ClientHandle h)
        {
            bool authenticated = false;
            if (String.IsNullOrEmpty(_settings.Pin))
            {
                authenticated = true;
                SendBuffer(h);
            }

            Output += s =>
            {
                if (!authenticated) return;

                h.DoSendOutput(s);
            };

            Title += s =>
            {
                if (!authenticated) return;

                h.DoSendTitle(s);
            };

            Status += s =>
            {
                if (!authenticated) return;

                h.DoSendStatus(s);
            };

            h.ReceiveAuthentication += authentication =>
            {
                if (_settings.Pin == authentication.Pin || authenticated)
                {
                    authenticated = true;
                    SendBuffer(h);
                }
                else
                {
                    h.DoSendWrongAuth();
                    h.DoSendClose();
                }
            };

            h.ReceiveInput += input =>
            {
                if (!authenticated) return;

                _clientEx.Input(input.Text);
            };

            h.ReceiveSetData += data =>
            {
                if (!authenticated) return;

                if (data.Settings != null)
                    _settings = XmlSerialize.Deserialize<CupCakeServerSettings>(data.Settings);

                if (_settings.Email == null)
                    _settings.Email = data.Email;
                if (_settings.Password == null)
                    _settings.Password = data.Password;
                if (_settings.World == null)
                    _settings.World = data.World;
                if (_settings.ConnectionString == null)
                    _settings.DatabaseType = data.DatabaseType;
                if (_settings.ConnectionString == null)
                    _settings.ConnectionString = data.ConnectionString;

                if (data.Directories != null)
                    _settings.Dirs.InsertRange(0, data.Directories);

                Start();
            };
        }