Example #1
0
		internal static void load(MainWindow win){
			main=win;
			string path=Path.Combine(System.Environment.CurrentDirectory,"plugin");
			if(!Directory.Exists(path)){
				win.write("没有发现插件目录");
				return;
			}
			string[] pluginsName= Directory.GetFiles(path,"*.dll");
			Type myType=typeof(iBilibilidanPlugin);
			foreach(string pluginPath in pluginsName){
				Assembly ass=Assembly.LoadFile(pluginPath);
				Type[] type;
				try{
					type=ass.GetExportedTypes();
				}
				catch (Exception)
				{
					win.write("无法兼容模块(已抛弃,请检查插件是否过旧)"+pluginPath);
					continue;
				}
				foreach(Type cla in type){
					if(myType.IsAssignableFrom(cla)&&!cla.IsAbstract){
						iBilibilidanPlugin p=(iBilibilidanPlugin)Activator.CreateInstance(cla);
						plugins.Add(p);
					}
				}
			}
			win.write("共载入"+pluginsName.Length+"个模块,识别出"+plugins.Count+"个插件");
		}
Example #2
0
        public bool link(int room)
        {
            if (socket != null)
            {
                unlink();                                                                         //断开之前的连接
            }
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //创建一个socket
            string r = room.ToString();

            try{
                window.write("连接到" + r + "中...");
                byte[] temp = Encoding.ASCII.GetBytes("{\"roomid\":" + r + ",\"uid\":201510566613409}"); //构造房间信息
                socket.Connect("livecmt-2.bilibili.com", 788);                                           //连接到弹幕服务器
                //构造消息头
                byte[] head = { 0x00, 0x00, 0x00, (byte)(0x31 + r.Length), 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01 };
                socket.Send(head); //发送消息头
                socket.Send(temp); //发送请求正文——房间信息
                socket.Send(re);   //这个本来应该是用来获取人数的,但是长期不发送服务器会断开连接,这里是为了防止这样的情况发生
                if (!flag)         //检查读弹幕线程是否在工作
                {
                    reader = new Thread(getdanmu);
                    reader.IsBackground = true;
                    reader.Start();
                }
                check_keeper();
                window.write("连接成功");
            }
            catch (InvalidCastException)
            {
                window.write("连接失败");
            }
            return(true);
        }
Example #3
0
 internal static void showPlugins()
 {
     if (main == null)
     {
         return;
     }
     main.write("正在展示已载入插件");
     foreach (iBilibilidanPlugin d in plugins)
     {
         main.write(d.name);
     }
     main.write("所有已载入插件已展示完毕");
 }
Example #4
0
        internal static void load(MainWindow win)
        {
            main = win;
            string path = Path.Combine(System.Environment.CurrentDirectory, "plugin");

            if (!Directory.Exists(path))
            {
                win.write("没有发现插件目录");
                return;
            }
            string[] pluginsName = Directory.GetFiles(path, "*.dll");
            Type     myType      = typeof(iBilibilidanPlugin);

            foreach (string pluginPath in pluginsName)
            {
                Assembly ass = Assembly.LoadFile(pluginPath);
                Type[]   type;
                try{
                    type = ass.GetExportedTypes();
                }
                catch (Exception)
                {
                    win.write("无法兼容模块(已抛弃,请检查插件是否过旧)" + pluginPath);
                    continue;
                }
                foreach (Type cla in type)
                {
                    if (myType.IsAssignableFrom(cla) && !cla.IsAbstract)
                    {
                        iBilibilidanPlugin p = (iBilibilidanPlugin)Activator.CreateInstance(cla);
                        plugins.Add(p);
                    }
                }
            }
            win.write("共载入" + pluginsName.Length + "个模块,识别出" + plugins.Count + "个插件");
        }