示例#1
0
        public TServer(Logger logger = null)
        {
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            // Get data from Settings
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            Object guid = localSettings.Values["Guid"];

            if (guid == null)
            {
                localSettings.Values["Guid"] = guid = Guid.NewGuid();
            }

            Object name = localSettings.Values["Name"];

            if (name == null)
            {
                localSettings.Values["Name"] = name = "SoundHub Server";
            }

            server = new HServer((Guid)guid, (string)name);
            server.ProfileRequest += server_ProfileRequest;
            server.ProfileRemove  += server_ProfileRemove;
            server.Logger          = logger;

            IsRecording = false;
        }
示例#2
0
        static public void Destroy()
        {
            if (s != null)
            {
                var serv    = WinAPI.FindWindow("_HIDDEN_HWND_SERVER", "_HIDDEN_HWND_SERVER");
                var x86help = WinAPI.FindWindow("_HIDDEN_X86_HELPER", "_HIDDEN_X86_HELPER");
                if (serv != IntPtr.Zero)
                {
                    WinAPI.PostMessage(serv, WinAPI.WM_QUIT, 0, 0);
                }
                if (x86help != IntPtr.Zero)
                {
                    WinAPI.PostMessage(x86help, WinAPI.WM_QUIT, 0, 0);
                }
                running = false;
                s.Dispose();
                s = null;
                // Multiple CreateWindowEx & WM_DESTROY causes NullReference exception in NATIVE CODE!!
                // So its disabled for now... Create window 1 time and not destroy it.
//				WinAPI.PostMessage(HWND, WinAPI.WM_DESTROY, 0, 0);
//		        HWND = IntPtr.Zero;
            }
        }
示例#3
0
        public static void Init(Func <string, UIElement, bool, UIElement> updateMainPage)
        {
            _updateMain = updateMainPage;

            #region DataBase

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AppData\\hjudgeData.db"))
            {
                SQLiteConnection.CreateFile(AppDomain.CurrentDomain.BaseDirectory + "\\AppData\\hjudgeData.db");
            }
            //var DbSQLiteConnection = new SQLiteConnection("Data Source=" +
            //                                  $"{AppDomain.CurrentDomain.BaseDirectory + "\\AppData\\hjudgeData.db"};Initial Catalog=sqlite;Integrated Security=True;");
            if (DbSQLiteConnection.State == ConnectionState.Closed)
            {
                DbSQLiteConnection.Open();
            }

            if (!CreateJudgeTable(DbSQLiteConnection))
            {
                if (MessageBox.Show("版本升级需要清空所有评测记录,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
                    MessageBoxResult.Yes)
                {
                    DropTable(DbSQLiteConnection, "Judge");
                    CreateJudgeTable(DbSQLiteConnection);
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            if (!CreateUserTable(DbSQLiteConnection))
            {
                if (MessageBox.Show("版本升级需要清空所有用户信息,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
                    MessageBoxResult.Yes)
                {
                    DropTable(DbSQLiteConnection, "User");
                    CreateUserTable(DbSQLiteConnection);
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            if (!CreateProblemTable(DbSQLiteConnection))
            {
                if (MessageBox.Show("版本升级需要清空所有题目信息,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
                    MessageBoxResult.Yes)
                {
                    DropTable(DbSQLiteConnection, "Problem");
                    CreateProblemTable(DbSQLiteConnection);
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            if (!CreateMessageTable(DbSQLiteConnection))
            {
                if (MessageBox.Show("版本升级需要清空所有消息记录,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
                    MessageBoxResult.Yes)
                {
                    DropTable(DbSQLiteConnection, "Message");
                    CreateMessageTable(DbSQLiteConnection);
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            if (!CreateCompetitionTable(DbSQLiteConnection))
            {
                if (MessageBox.Show("版本升级需要清空所有比赛信息,是否继续?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
                    MessageBoxResult.Yes)
                {
                    DropTable(DbSQLiteConnection, "Competition");
                    CreateCompetitionTable(DbSQLiteConnection);
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            DbSQLiteConnection.Close();
            #endregion

            #region Network

            HServer.OnAccept += (id, client) =>
            {
                var    ip   = string.Empty;
                ushort port = 0;
                if (!HServer.GetRemoteAddress(id, ref ip, ref port))
                {
                    return(HandleResult.Ignore);
                }
                var clientInfo = new ClientInfo
                {
                    UserId    = 0,
                    ConnId    = id,
                    IpAddress = ip,
                    Port      = port,
                    PkgInfo   = new PkgInfo
                    {
                        IsHeader = true,
                        Length   = PkgHeaderSize
                    }
                };
                HServer.SetExtra(id, clientInfo);
                Recv.Add(new ClientData {
                    Info = clientInfo
                });
                SendData("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(), id, null);
                return(HandleResult.Ok);
            };
            HServer.OnClose += (id, operation, code) =>
            {
                HServer.RemoveExtra(id);
                var t = (from c in Recv where c.Info.ConnId == id select c).FirstOrDefault();
                if (t != null)
                {
                    lock (RemoveClientLock)
                    {
                        var x = new List <ClientData>();
                        while (Recv.TryTake(out var tmp))
                        {
                            if (!tmp.Equals(t))
                            {
                                x.Add(tmp);
                            }
                            else
                            {
                                if (tmp.Info.UserId != 0)
                                {
                                    UpdateMainPageState(
                                        $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 用户 {tmp.Info.UserName} 注销了");
                                }
                                break;
                            }
                        }
                        foreach (var i in x)
                        {
                            Recv.Add(i);
                        }
                    }
                }
                return(HandleResult.Ok);
            };
            HServer.OnReceive += HServerOnOnReceive;

            HServer.IpAddress = Configuration.Configurations.IpAddress;
            HServer.Port      = 23333;
            if (!HServer.Start())
            {
                MessageBox.Show("服务端网络初始化失败,请检查系统设置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            new Thread(DealingBytes)
            {
                Priority = ThreadPriority.Highest
            }.Start();
            for (var i = 0; i < Environment.ProcessorCount; i++)
            {
                new Thread(DealingOperations)
                {
                    Priority = ThreadPriority.Highest
                }
            }
示例#4
0
        public static void Init()
        {
            if (!MahouUI.ENABLED)
            {
                return;
            }
            if (running)
            {
                bool exist = true;
                if (Environment.Is64BitOperatingSystem)
                {
                    if (Process.GetProcessesByName("jkl").Length > 0)
                    {
                        Logging.Log("[JKL] > JKL already running.");
                    }
                    else
                    {
                        exist = false;
                    }
                }
                else
                {
                    if (Process.GetProcessesByName("jklx86").Length > 0)
                    {
                        Logging.Log("[JKL] > JKLx86 already running.");
                    }
                    else
                    {
                        exist = false;
                    }
                }
                if (!exist)
                {
                    Logging.Log("[JKL] > JKL seems closed, restarting...");
                    running = false;
                }
            }
            if (s == null)
            {
                Logging.Log("[JKL] > Initializing JKL HWND server...");
                s = new HServer();
                Logging.Log("[JKL] > SERVER HWND: " + s.Handle + " WinTitle: " + s.Text);
            }
            if (!running)
            {
                if (jklExist())
                {
                    if (Environment.Is64BitOperatingSystem)
                    {
                        Logging.Log("[JKL] > Starting jkl.exe...");
                        var jkl = new ProcessStartInfo();
                        jkl.UseShellExecute  = true;
                        jkl.FileName         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe");
                        jkl.WorkingDirectory = Path.Combine(Path.GetTempPath());
                        Process.Start(jkl);
                    }
                    else
                    {
                        Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"...");
                        var jkl = new ProcessStartInfo();
                        jkl.UseShellExecute  = true;
                        jkl.FileName         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe");
                        jkl.Arguments        = "-msg";
                        jkl.WorkingDirectory = Path.Combine(Path.GetTempPath());
                        Process.Start(jkl);
                    }
                    var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id");
                    var tries  = 0;
                    while (!File.Exists(umsgID))
                    {
                        Thread.Sleep(350);
                        tries++;
                        if (tries > 20)
                        {
                            Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1);
                            Destroy();
                            break;
                        }
                    }
                    if (tries <= 20)
                    {
                        Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout.");
                        Logging.Log("[JKL] > Retrieving umsg.id...");
                        jkluMSG = Int32.Parse(File.ReadAllText(umsgID));
                        File.Delete(umsgID);
//						KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350);
                        KMHook.DoLater(() => { MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetCurrentLocale(); }, 200);
                        running = true;
                    }
                }
                else
                {
                    Logging.Log("[JKL] > " + jklInfoStr, 1);
                }
                if (jkluMSG == -1)
                {
                    KMHook.JKLERR = true;
                }
                else
                {
                    KMHook.JKLERR = false;
                }
                Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + s.Handle + "].");
            }
        }