Ejemplo n.º 1
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();
     }
 }
Ejemplo n.º 2
0
 static void DisplayException(MLClientPlugin plugin, Exception ex)
 {
     if (plugin != null)
     {
         Console.WriteLine("{0}: {1}", plugin.ClientPluginID, ex.ToString());
     }
     else
     {
         Console.WriteLine(ex.ToString());
     }
 }
Ejemplo n.º 3
0
 static void networkClient_OnDisconnect(eSock.Client sender, System.Net.Sockets.SocketError ER)
 {
     foreach (var plugin in LoadedPlugins)
     {
         MLClientPlugin _plugin = plugin.Value;
         try
         {
             _plugin.ClientPlugin.OnDisconnect();
         }
         catch (Exception ex)
         {
             DisplayException(_plugin, ex);
         }
     }
     Console.WriteLine("Lost connection...");
     Thread.Sleep(5000);
     Connect();
 }
Ejemplo n.º 4
0
        static void LoadPlugin(string path)
        {
            MLClientPlugin _plugin = null;

            try
            {
                byte[] PluginBytes = null;

                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    using (Rijndael rij = new RijndaelManaged())
                    {
                        string key = Path.GetExtension(path);
                        key = key.Substring(1, key.Length - 1);
                        byte[] encryptionKey = eSock.Hashing.MD5Hash(key);
                        rij.Key = encryptionKey;
                        rij.IV  = encryptionKey;
                        ICryptoTransform crypto = rij.CreateDecryptor();
                        using (MemoryStream ms = new MemoryStream())
                        {
                            byte[] buffer    = new byte[1000];
                            int    bytesread = 0;
                            using (CryptoStream cs = new CryptoStream(fs, crypto, CryptoStreamMode.Read))
                            {
                                while ((bytesread = cs.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    ms.Write(buffer, 0, bytesread);
                                }
                                cs.Close();
                            }
                            PluginBytes = ms.ToArray();
                        }
                    }
                }

                /*
                 * using (Rijndael rij = new RijndaelManaged())
                 * {
                 *  byte[] encryptionKey = eSock.Hashing.MD5Hash(Path.GetExtension(path));
                 *  rij.Key = encryptionKey;
                 *  rij.IV = encryptionKey;
                 *  ICryptoTransform crypto = rij.CreateDecryptor();
                 *  byte[] encrypted = File.ReadAllBytes(path);
                 *
                 *  using (MemoryStream ms = new MemoryStream())
                 *  {
                 *      using (CryptoStream cs = new CryptoStream(ms, crypto, CryptoStreamMode.Write))
                 *      {
                 *          cs.Write(encrypted, 0, encrypted.Length);
                 *          cs.Flush();
                 *          cs.Close();
                 *      }
                 *      PluginBytes = ms.ToArray();
                 *  }
                 *
                 * }
                 */

                _plugin = new MLClientPlugin(PluginBytes);
                if (!_plugin.Load())
                {
                    throw new Exception("Failed to load plugin");
                }
                if (_plugin.ClientPluginID == Guid.Empty)
                {
                    throw new Exception("Invalid plugin ID");
                }
                if (LoadedPlugins.ContainsKey(_plugin.ClientPluginID))
                {
                    throw new Exception("Client plugin ID match");
                }
                _plugin.Path = path;
                LoadedPlugins.Add(_plugin.ClientPluginID, _plugin);
                Console.WriteLine("Loaded plugin: {0}", _plugin.ClientPluginID.ToString("n"));
                _plugin.ClientPlugin.OnPluginLoad(new MLConnection(_plugin.ClientPluginID, OnSend));
            }
            catch (Exception ex)
            {
                File.Delete(path);
                DisplayException(_plugin, ex);
            }
        }