Exemple #1
0
 private static Task ServerBroadCastAsync(string serverUsername, CancellationToken ct)
 {
     return(Task.Factory.StartNew(async() => {
         string firstChar;
         while (true)
         {
             if (ManageInput(serverUsername, out firstChar, server: true))
             {
                 var inputUser = firstChar + C.Read().Trim();
                 if (inputUser.ToLower().Contains("file"))
                 {
                     try{
                         await SocketFileHandler.Start(null);
                     }catch (Exception) {}
                 }
                 var message = serverUsername + inputUser;
                 C.Cursor(message.Length, Console.CursorTop - 1); //don't show Enter pressed
                 await SocketMessageHandler.ServerSide(new TcpClient(), message, true);
                 if (Users.Where(u => u.Client.Connected).Count() > 0)
                 {
                     Display.Receipt();
                 }
             }
         }
     }, ct));
 }
Exemple #2
0
            private async static Task ClientReceiveSendAsync(TcpClient sender)
            {
                while (true)
                {
                    byte[] bytes = new byte[!StealthMode ? sender.SendBufferSize : 3500];
                    await sender.GetStream().ReadAsync(bytes, 0, bytes.Length);

                    var message = Encoding.UTF8.GetString(bytes);
                    if (!StealthMode)
                    {
                        await SocketMessageHandler.ServerSide(sender, message.Trim('\0'));
                    }
                    else
                    {
                        await SocketMessageHandler.ServerSide(sender, message);
                    }
                }
            }
Exemple #3
0
 private static Task ReceiveAsync(TcpClient client, CancellationToken ct)
 {
     return(Task.Factory.StartNew(async() =>
     {
         while (true)
         {
             byte[] bytes = new byte[!StealthMode ? client.SendBufferSize : 3500];
             await client.GetStream().ReadAsync(bytes, 0, bytes.Length);
             var message = Encoding.UTF8.GetString(bytes);
             if (!StealthMode)
             {
                 SocketMessageHandler.ClientSide(message.Trim('\0'));
             }
             else
             {
                 SocketMessageHandler.ClientSide(message);
             }
         }
     }, ct));
 }
Exemple #4
0
 public static bool ManageInput(string username, out string s, bool server = false)
 {
     if (Console.KeyAvailable)
     {
         ConsoleKeyInfo key;
         if (U.OSX)
         {
             key = Console.ReadKey(true);
         }
         else
         {
             key = C.Key(); C.WL("");
         }
         if (key.Key == ConsoleKey.Enter)
         {
             C.Write(username);
         }
         var k = C.Key();
         if (k.Key == ConsoleKey.Enter)
         {
             s = ""; return(false);
         }
         if (k.Key == ConsoleKey.Tab)
         {
             C.Cursor(username.Length, Console.CursorTop);//hide tab pressed
             s = SocketMessageHandler.AutoCompleteUsers(C.Key().Key, server);
             C.Write(s);
         }                //AutoComplete
         else
         {
             s = k.KeyChar.ToString();
         }
         return(true);
     }
     else
     {
         Thread.Sleep(100);
     }
     s = "";
     return(false);
 }