Beispiel #1
0
        static void Main(string[] args)
        {
            _client.OnDataRetrieved += _client_OnDataRetrieved;
            _client.OnDisconnect    += _client_OnDisconnect;
            if (!_client.Connect("127.0.0.1", 1337))
            {
                Console.WriteLine("Failed to connect");
                Console.ReadLine();
                return;
            }
            Connected = true;

            while (Connected)
            {
                try
                {
                    Console.Write("File to send: ");
                    string path = Console.ReadLine();
                    _stream = new FileStream(path, FileMode.Open);
                    _client.Send((byte)PacketHeader.StartFileTransfer, Path.GetFileName(path));
                    Console.WriteLine("Waiting for responce..");
                    while (FileHandle == 0)
                    {
                        Thread.Sleep(100);
                    }
                    Console.WriteLine("Handle: {0}", FileHandle);
                    byte[] buffer    = new byte[1000];
                    int    bytesRead = 0;
                    while ((bytesRead = _stream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        byte[] block = new byte[bytesRead];
                        Buffer.BlockCopy(buffer, 0, block, 0, block.Length);
                        _client.Send((byte)PacketHeader.FileTransferBlock, FileHandle, block, _stream.Position == _stream.Length);
                        Console.WriteLine("Sent block ({0} bytes) || LastBlock: {1}", bytesRead, _stream.Position == _stream.Length);
                    }
                    FileHandle = 0;
                    _stream.Dispose();
                    _stream = null;
                    Console.WriteLine("File Complete");
                }
                catch
                {
                    Console.WriteLine("Error");
                }
            }
            Console.WriteLine("Not connected");
            Console.ReadLine();
        }
Beispiel #2
0
        public static bool Connect(string ip, int port)
        {
            _client = new eSock.Client();
            if (!_client.Connect(ip, port))
            {
                return(false);
            }

            try
            {
                object[] data = _client.Send((byte)NetworkHeaders.Handshake);
                if ((NetworkHeaders)data[0] != NetworkHeaders.AcceptHandshake)
                {
                    return(false);
                }
                string encryptionKey = (string)data[1];

                _client.Encryption.EncryptionKey = encryptionKey;
                _client.Encryption.Enabled       = true;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
        public static object CreateRemoteCall(string function, object[] args)
        {
            if (_client == null)
            {
                Console.WriteLine("[NetCore] Attempted RemoteCall with null client");
                return(null);
            }

            if (!_client.Connected)
            {
                Console.WriteLine("[NetCore] Attempted RemoteCall without connection");
                return(null);
            }

            try
            {
                object[] derp = _client.Send((byte)NetworkHeaders.RemoteCall, function, args);
                return(derp[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(null);
        }
Beispiel #4
0
        public static bool ConnectWithProxy(string proxyIP, int proxyPort, string targetIp, int targetPort, string username = "", string password = "")
        {
            _client = new eSock.Client();
            if (!_client.ConnectProxy(proxyIP, proxyPort, targetIp, targetPort, username, password))
            {
                return(false);
            }
            try
            {
                object[] data = _client.Send((byte)NetworkHeaders.Handshake);
                if ((NetworkHeaders)data[0] != NetworkHeaders.AcceptHandshake)
                {
                    return(false);
                }
                string encryptionKey = (string)data[1];

                _client.Encryption.EncryptionKey = encryptionKey;
                _client.Encryption.Enabled       = true;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #5
0
 private static void NetworkClient_OnConnect(eSock.Client sender, bool success)
 {
     if (success)
     {
         Console.WriteLine("Connected!");
         foreach (var plugin in LoadedPlugins)
         {
             MLClientPlugin _plugin = plugin.Value;
             try
             {
                 _plugin.ClientPlugin.OnConnect();
             }
             catch (Exception ex)
             {
                 DisplayException(_plugin, ex);
             }
         }
         networkClient.Send(Guid.Empty, (byte)NetworkPacket.Handshake);
         Console.WriteLine("handshake sent");
     }
     else
     {
         Console.WriteLine("Failed to connect.");
         Thread.Sleep(5000);
         Connect();
     }
 }