示例#1
0
        public void OnKeyDownHandler(object sender, KeyEventArgs e)
        {
            var DecEncHelper = new utils.DecodingEncodingHelper();

            if (connected)
            {
                if (e.Key == Key.Enter)
                {
                    string msg = ClientInput.Text;
                    if (msg.StartsWith("/"))
                    {
                        inputHandler.handleInput(msg.Remove(0, 1), connectedClient, ClientOutput);
                    }
                    else
                    {
                        ClientOutput.AppendText("Du: " + msg + Environment.NewLine);
                        client.SocketObject.Send(DecEncHelper.StringToBytes($"001{msg}"));
                    }
                    ClientInput.Text = "";
                }
            }
        }
示例#2
0
        public void TryConnect(object s)
        {
            string username = s.ToString();
            int    trys     = 0;

            byte[] buffer = new byte[1024];

            var DecEncHelper = new utils.DecodingEncodingHelper();

            ConnectionStatus.Dispatcher.Invoke(() => {
                ConnectionStatus.Text = "Connecting...";
            });
            while (!connected)
            {
                Socket     socketObject = new Socket(config.Ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                var        Client       = new objects.Client(username, socketObject, config.Ip, config.Port, "first_channel_is_managed_by_server");
                IPEndPoint serverIp     = new IPEndPoint(Client.Ip, Client.Port);

                IAsyncResult result = Client.SocketObject.BeginConnect(Client.Ip, Client.Port, null, null);

                bool success = result.AsyncWaitHandle.WaitOne(5000, true);

                if (Client.SocketObject.Connected)
                {
                    ConnectionStatus.Dispatcher.Invoke(() => {
                        ConnectionStatus.Text = "Connected";
                    });
                    ClientOutput.Dispatcher.Invoke(() => {
                        ClientOutput.Text = "" + Environment.NewLine;
                    });
                    client = new objects.Client(username, socketObject, config.Ip, config.Port, "first_channel_is_managed_by_server");
                    Client.SocketObject.EndConnect(result);
                    connectedClient = Client;
                    client.SocketObject.Send(DecEncHelper.StringToBytes($"011{client.Username}"));
                    Thread.Sleep(10);
                    client.SocketObject.Send(DecEncHelper.StringToBytes($"611Welcome_Channel"));
                    Status.Dispatcher.Invoke(() => {
                        Status.Header     = $"_Online as : {client.Username}";
                        Status.Background = Brushes.Green;
                    });
                    connected = true;
                    Disconnect.Dispatcher.Invoke(() => {
                        Disconnect.IsEnabled = true;
                    });
                    utils.ServerHandler _serverHandler = new utils.ServerHandler(client, ClientOutput, ChannelTreeView);
                    Thread t = new Thread(new ThreadStart(_serverHandler.startPR));
                    t.Start();
                    _serverHandler.getChannel();
                }
                else
                {
                    Client.SocketObject.Close();
                    ConnectionStatus.Dispatcher.Invoke(() => {
                        ConnectionStatus.Text = $"Trying to connect ip: {Client.Ip} Attempts: {trys}";
                    });
                    Debug.Print($"[Client/Info] Attempting to connect to server with ip: {Client.Ip} Attempts: {trys}");
                }
                trys++;
                Thread.Sleep(2000);
            }
        }
示例#3
0
 public void getChannel()
 {
     var DecEncHelper = new utils.DecodingEncodingHelper();
 }