Esempio n. 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string nickname = string.Empty;
            string serverUrl = string.Empty;

            LoginForm loginForm = new LoginForm();

            while (string.IsNullOrEmpty(nickname) || string.IsNullOrEmpty(serverUrl))
            {
                if (loginForm.ShowDialog() != DialogResult.OK)
                    break;

                nickname = loginForm.Nickname;
                serverUrl = loginForm.ServerUrl;
            }

            if (string.IsNullOrEmpty(nickname))
                return;

            Credentials = new Hashtable();
            Credentials.Add("nickname", nickname);

            TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true);

            try
            {
                using (Connection = new ZyanConnection(serverUrl, protocol, Credentials, false, true))
                {
                    Connection.PollingInterval = new TimeSpan(0, 0, 30);
                    Connection.PollingEnabled = true;
                    Connection.Disconnected += new EventHandler<DisconnectedEventArgs>(Connection_Disconnected);
                    Connection.NewLogonNeeded += new EventHandler<NewLogonNeededEventArgs>(Connection_NewLogonNeeded);
                    Connection.Error += new EventHandler<ZyanErrorEventArgs>(Connection_Error);

                    Connection.CallInterceptors.For<IMiniChat>()
                        .Add<string, string>(
                            (chat, nickname2, text) => chat.SendMessage(nickname2, text),
                            (data, nickname2, text) =>
                            {
                                if (text.Contains("f**k") || text.Contains("sex"))
                                {
                                    MessageBox.Show("TEXT CONTAINS FORBIDDEN WORDS!");
                                    data.Intercepted = true;
                                }
                            });

                    Connection.CallInterceptionEnabled = true;

                    Application.Run(new ChatForm(nickname));
                }
            }
            catch (SecurityException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string nickname  = string.Empty;
            string serverUrl = string.Empty;

            LoginForm loginForm = new LoginForm();

            while (string.IsNullOrEmpty(nickname) || string.IsNullOrEmpty(serverUrl))
            {
                if (loginForm.ShowDialog() != DialogResult.OK)
                {
                    break;
                }

                nickname  = loginForm.Nickname;
                serverUrl = loginForm.ServerUrl;
            }

            if (string.IsNullOrEmpty(nickname))
            {
                return;
            }

            Credentials = new Hashtable();
            Credentials.Add("nickname", nickname);

            TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true);

            try
            {
                using (Connection = new ZyanConnection(serverUrl, protocol, Credentials, false, true))
                {
                    Connection.PollingInterval = new TimeSpan(0, 0, 30);
                    Connection.PollingEnabled  = true;
                    Connection.Disconnected   += new EventHandler <DisconnectedEventArgs>(Connection_Disconnected);
                    Connection.NewLogonNeeded += new EventHandler <NewLogonNeededEventArgs>(Connection_NewLogonNeeded);
                    Connection.Error          += new EventHandler <ZyanErrorEventArgs>(Connection_Error);

                    Connection.CallInterceptors.For <IMiniChat>()
                    .Add <string, string>(
                        (chat, nickname2, text) => chat.SendMessage(nickname2, text),
                        (data, nickname2, text) =>
                    {
                        if (text.Contains("f**k") || text.Contains("sex"))
                        {
                            MessageBox.Show("TEXT CONTAINS FORBIDDEN WORDS!");
                            data.Intercepted = true;
                        }
                    });

                    Connection.CallInterceptionEnabled = true;

                    Application.Run(new ChatForm(nickname));
                }
            }
            catch (SecurityException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }