Beispiel #1
0
        private void btnBeginTesting_Click(object sender, EventArgs e)
        {
            if (remoteHost == null)
            {
                Color notice = Color.Yellow;
                lvRemoteHosts.BackColor = notice;
                SetTimeout.OnGui(() => lvRemoteHosts.BackColor = originalListviewBack, 166, this);
                SetTimeout.OnGui(() => lvRemoteHosts.BackColor = notice, 333, this);
                SetTimeout.OnGui(() => lvRemoteHosts.BackColor = originalListviewBack, 500, this);
                return;
            }

            SetControlState(true);

            if (bwSpeedTestController != null && bwSpeedTestController.IsBusy)
            {
                bwSpeedTestController.CancelAsync();
                Thread.Sleep(100);
            }
            NewBackgroundWorker();

            nsgCurrent.SetDuration((uint)Program.config.testDurationSeconds);
            nsgCurrent.SetDownloadData(new KeyValuePair <double, double> [0]);
            nsgCurrent.SetUploadData(new KeyValuePair <double, double> [0]);
            dlTotal = 0;
            ulTotal = 0;
            bwSpeedTestController.RunWorkerAsync(bwSpeedTestController);
        }
    public IEnumerator DownApk(string url)
    {
        WWW www = new WWW(url);

        do
        {
            yield return(null);

            LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在下载最新资源包...", www.progress);
        } while (!www.isDone);

        if (www.size > 0)
        {
            string filePath = Application.persistentDataPath + "/APK";
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            File.WriteAllBytes(filePath + "/version.apk", www.bytes);
            SDKManager.Instance.Install(filePath + "/version.apk");
        }
        else
        {
            SetTimeout.add(2f, () =>
            {
                LoadingNode.CloseLoadingNode();
            });
        }
    }
Beispiel #3
0
 public void WriteFile(DataFileTemplate template)
 {
     SetTimeout.OnBackground(() =>
     {
         try
         {
             Robust.Retry(() =>
             {
                 FileInfo fi = new FileInfo("SensorData/" + template.FileName);
                 if (!fi.Directory.Exists)
                 {
                     Directory.CreateDirectory(fi.Directory.FullName);
                 }
                 if (!fi.Exists || !fi.IsReadOnly)
                 {
                     File.WriteAllText(fi.FullName, ApplyTemplate(template.TemplateStr), Encoding.GetEncoding(1252));
                 }
             }, 1, 5, 10, 20, 50, 250, 500, 1000);
         }
         catch (Exception ex)
         {
             Logger.Debug(ex, "MqttDevice.WriteFile(\"" + template.ToString() + "\")");
         }
     }, 0, e => Logger.Debug(e));
 }
Beispiel #4
0
        private void playMusic()
        {
            _isAlarm = true;

            string path = MainModel.ins.cfgMd.timerMusicPath;

            if (File.Exists(path))
            {
                try {
                    musicPlayer.path   = path;
                    musicPlayer.volume = (float)MainModel.ins.cfgMd.timerVolume / 100;
                    musicPlayer.play();
                } catch (Exception ex) {
                    Debug.WriteLine(ex.ToString());
                }
            }

            //isPlay = true;
            try {
                int waitTime = MainModel.ins.cfgMd.alarmTimeSecond;
                if (waitTime <= 0 || waitTime > 3600)
                {
                    waitTime = 30;
                }

                waitAlarm = new SetTimeout(() => {
                    stop();
                }, waitTime * 1000);
            } catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
            }
        }
Beispiel #5
0
        public void stop()
        {
            try {
                if (timer != null)
                {
                    timer.Stop();
                    timer = null;
                }

                bool isPlay = musicPlayer.isPlay() || _isAlarm;
                try {
                    musicPlayer.stop();
                } catch (Exception) { }

                _isAlarm = false;

                if (isPlay)
                {
                    onPlayMusicFinished?.Invoke();
                }

                if (waitAlarm != null)
                {
                    waitAlarm.stop();
                    waitAlarm = null;
                }
            } catch (Exception) {
            }

            startTimer = null;
        }
Beispiel #6
0
 public static void On(HttpProcessor p)
 {
     UnmuteIfNeeded();
     currentMonitorStatus = "on";
     SetMonitorInState(-1);
     lock (myLock)
     {
         StopMonitorOffThread();
         StopWaitForWakeThread();
         if (p != null)
         {
             int offAfterSecs = p.GetIntParam("offAfterSecs", 0);
             if (offAfterSecs > 0)
             {
                 StartMonitorOffThread(offAfterSecs);
             }
         }
     }
     SetTimeout.OnBackground(() =>
     {
         //Cursor.Show();
         //IntPtr desktopHandle = NativeMethods.GetDesktopWindow();
         //if (desktopHandle != null && desktopHandle != IntPtr.Zero)
         //	NativeMethods.SetForegroundWindow(desktopHandle);
         int dx = Cursor.Position.X < 10 ? 1 : -1;
         int dy = Cursor.Position.Y < 10 ? 1 : -1;
         DragMouse(dx, dy, 1, 1);
         DragMouse(-dx, -dy, 1, 1);
     }, 0);
 }
Beispiel #7
0
 /// <summary>
 /// 换桌
 /// </summary>
 public void SendChangeDesk()
 {
     NetProcess.SendRequest <CommonSendProto>(null, MJProtoMap.CMD_SendChangeDesk, (msg) =>
     {
         StartGameBackData data = msg.Read <StartGameBackData>();
         if (data.code == 1)
         {
             if (mGameUI != null)
             {
                 mGameUI.ReSetUI(true);
                 MJGameModel.Inst.ResetData();
                 MJGameModel.Inst.mState = eMJRoomStatus.GAMEOVER;
                 MJGameModel.Inst.mStartGameData.roomInfo.roomState = eRoomState.GAMEOVER;//改变房间状态
                 SetTimeout.remove(ShowSmallSettle);
                 SetTimeout.remove(ChangHandsCardsShow);
             }
             HandleStartGameData(data.data);
         }
         else
         {
             GameUtils.ShowErrorTips(data.code);
             BackToClub();
         }
     });
 }
Beispiel #8
0
    /// <summary>
    /// 小结算
    /// </summary>
    /// <param name="msg"></param>
    private void OnSettlement(MessageData msg)
    {
        litSemResponse data = msg.Read <litSemResponse>();

        CardsInfoStruct[] playerCardsDatas = MJGameModel.Inst.allPlayersCardsInfoStruct;
        bool isNoWinner = true;//是否是流局

        for (int i = 0; i < playerCardsDatas.Length; i++)
        {
            if (playerCardsDatas[i] != null && playerCardsDatas[i].huList != null && playerCardsDatas[i].huList.Count > 0)
            {
                isNoWinner = false;
                break;
            }
        }
        if (isNoWinner) //流局
        {
            mGameUI.ServerNoWinner();
        }
        #region 小结算数据处理
        MJGameSettlementInfo mSettlData = new MJGameSettlementInfo();
        MJGameModel.Inst.mLitSem   = data;
        mSettlData.isEnd           = true;
        mSettlData.isHu            = !isNoWinner;
        mSettlData.settleContainer = new List <MJGameSettlementPlayerInfo>();
        for (int i = 0; i < data.litSemList.Count; i++)
        {
            MJGameSettlementPlayerInfo oneSettlementPlayerInfo = new MJGameSettlementPlayerInfo();
            int seatID = data.litSemList[i].seatId;
            PlayerInfoStruct onePData = MJGameModel.Inst.mRoomPlayers[seatID];              //玩家信息
            CardsInfoStruct  cdata    = MJGameModel.Inst.allPlayersCardsInfoStruct[seatID]; //牌信息
            oneSettlementPlayerInfo.seatId   = seatID;
            oneSettlementPlayerInfo.userId   = onePData.uId;
            oneSettlementPlayerInfo.nickName = onePData.nickName;
            oneSettlementPlayerInfo.score    = data.litSemList[i].currScore;
            oneSettlementPlayerInfo.headUrl  = onePData.headUrl;
            oneSettlementPlayerInfo.shoupai  = data.litSemList[i].handList;
            oneSettlementPlayerInfo.peng     = cdata.pengList;
            oneSettlementPlayerInfo.gang     = cdata.gangList;
            oneSettlementPlayerInfo.huPai    = cdata.huList;
            oneSettlementPlayerInfo.huOrder  = data.litSemList[i].huOrder;
            oneSettlementPlayerInfo.huDes    = data.litSemList[i].huIntro;
            mSettlData.settleContainer.Add(oneSettlementPlayerInfo);
        }
        #endregion

        MJGameModel.Inst.mSettlData = mSettlData;
        MJGameModel.Inst.mState     = eMJRoomStatus.GAMEOVER;
        MJGameModel.Inst.mStartGameData.roomInfo.roomState = eRoomState.GAMEOVER;//改变房间状态
        SetTimeout.add(1, ChangHandsCardsShow);

        SetTimeout.add(5, ShowSmallSettle);

        //清理离开游戏的玩家
        if (mGameUI != null)
        {
            mGameUI.SetAllPlayerOutLine();
        }
    }
 private void Execute()
 {
     if (this.fun != null)
     {
         this.fun();
     }
     SetTimeout.Clear(this.fun);
 }
Beispiel #10
0
    void Start()
    {
#if UNITY_ANDROID
        SendMsg(INIT_SQ_SDK, gameObject.name);//初始化SDK,设置回调物体
        //SendMsg("InitPay", "3015488239");//初始化支付
#elif UNITY_IPHONE
        SetTimeout.add(600, OnTimeToGetLocation, false, false);
#endif
    }
Beispiel #11
0
    //public void Create()
    //{
    //    for (int i = 0; i < 10; i++)
    //    {
    //        MaJangResultMj mj = Instantiate(mjPrefab, handParent);
    //        mj.gameObject.SetActive(true);
    //        //mj.Init(handList[i].mjNo.ToString());
    //        mj.transform.SetParent(handParent);
    //    }
    //    gameObject.SetActive(true);

    //    handParent.SetParent(horizontal);
    //    //SetTimeout.add(0.2f, () =>
    //    //{
    //    //    handParent.gameObject.SetActive(false);
    //    //    horizontal.gameObject.SetActive(false);
    //    //    handParent.gameObject.SetActive(true);
    //    //    horizontal.gameObject.SetActive(true);
    //    //});
    //}

    void OnEnable()
    {
        SetTimeout.add(0.1f, () =>
        {
            handParent.gameObject.SetActive(false);
            horizontal.gameObject.SetActive(false);
            handParent.gameObject.SetActive(true);
            horizontal.gameObject.SetActive(true);
        });
    }
Beispiel #12
0
        private void nudHttpsPort_ValueChanged(object sender, EventArgs e)
        {
            int old = Program.settings.https_port;

            Program.settings.https_port = (int)nudHttpsPort.Value;
            if (old != Program.settings.https_port)
            {
                Program.settings.Save();
                Program.service.Start();
                SetTimeout.OnGui(SetCurrentHttpPorts, 100, this);
            }
        }
Beispiel #13
0
        private void clear()
        {
            timeout.clear();
            timeout = null;

            var lst = MainMd.ins.configMd.lstHttpServer;

            for (int i = 0; i < lst.Count; ++i)
            {
                getPage().clear(lst[i]);
            }
        }
Beispiel #14
0
    /// <summary>
    /// 推送结算
    /// </summary>
    public static void G2C_Result(DdzJieSuanResp result)
    {
        LandlordsModel.Instance.IsInFight = false;
        DdzJieSuanInfo juesuanInfo = result.jieSuanInfo;

        //yield return new WaitForSecondsRealtime(0.1f);
        LandlordsModel.Instance.ResultModel.zd  = result.jieSuanInfo.zdbs;
        LandlordsModel.Instance.ResultModel.jdz = result.jieSuanInfo.dzbs;
        LandlordsModel.Instance.ResultModel.ct  = result.jieSuanInfo.ct ? 2 : 0;
        LandlordsModel.Instance.ResultModel.fct = result.jieSuanInfo.fc ? 2 : 0;
        for (int i = 0; i < juesuanInfo.playerInfo.Count; i++)
        {
            DdzJSPlayerInfo playerIcom = juesuanInfo.playerInfo[i];
            LandlordsModel.Instance.ResultModel.Add(playerIcom);
            if (playerIcom.income > 0)
            {
                LandlordsModel.Instance.CurWinerIds.Add(playerIcom.userId);
            }

            if (LandlordsModel.Instance.RoomModel.CurRoomInfo.IsMatch)
            {
                LandlordsModel.Instance.RoomPlayerHands.Find(p => p.playerInfo.uid == juesuanInfo.playerInfo[i].userId.ToString()).MatchScore += juesuanInfo.playerInfo[i].income;
            }
            else if (LandlordsModel.Instance.RoomModel.CurRoomInfo.RoomType == RoomType.RoomCard)
            {
                LandlordsModel.Instance.RoomPlayerHands.Find(p => p.playerInfo.uid == juesuanInfo.playerInfo[i].userId.ToString()).playerInfo.score += juesuanInfo.playerInfo[i].income;
            }
            else
            {
                LandlordsModel.Instance.RoomPlayerHands.Find(p => p.playerInfo.uid == juesuanInfo.playerInfo[i].userId.ToString()).playerInfo.money = juesuanInfo.playerInfo[i].coin;
            }
        }
        LandlordsModel.Instance.ResultModel.curJs = result.jieSuanInfo.currJs;
        LandlordsModel.Instance.ResultModel.allJs = result.jieSuanInfo.totalJs;

        float delay = 0;

        if (LandlordsModel.Instance.RoomModel.CurRoomInfo.RoomType != RoomType.Match)
        {
            delay = 1.5f;
        }
        else
        {
            delay = 0;
        }
        SetTimeout.add(delay, () =>
        {
            CheckIsChuntianOrReverse(juesuanInfo);
            //总显示
            LandlordsPage.Instance.GameOver();
        });
    }
    public static void Start(Action function, float delay, bool isIgnoreTimeScale = true)
    {
        SetTimeout.Clear(function);
        if (function == null)
        {
            return;
        }
        SetTimeout setTimeout = (new GameObject()).AddComponent <SetTimeout>();

        setTimeout.name = "[SetTimeout]";

        setTimeout.Add(function, delay, isIgnoreTimeScale);
        SetTimeout.functionDict.Add(function, setTimeout);
    }
 private static void HostConnect_StateChanged(object sender, StateChangedEventArgs e)
 {
     Logger.Info("HostConnect_StateChanged: " + e.state);
     if (e.state == HostConnectClientState.Disconnected && !isStopped)
     {
         int timeout = reconnectTimer.GetNextTimeout();
         Logger.Info("HostConnect disconnected. Automatic reconnection in " + (timeout / 1000) + " seconds.");
         SetTimeout.OnBackground(hostConnect.Connect, timeout);
     }
     else if (e.state == HostConnectClientState.Connected)
     {
         reconnectTimer.Reset();
     }
 }
Beispiel #17
0
    public static void Clear(Action function)
    {
        if (function == null)
        {
            return;
        }

        if (functionDict.ContainsKey(function))
        {
            SetTimeout timeout = functionDict[function];
            functionDict.Remove(function);

            timeout.fun = null;
            DestroyImmediate(timeout);
        }
    }
 public static void Clear(Action function)
 {
     if (function == null)
     {
         return;
     }
     if (SetTimeout.functionDict.ContainsKey(function))
     {
         SetTimeout setTimeout = SetTimeout.functionDict[function];
         SetTimeout.functionDict.Remove(function);
         setTimeout.fun = null;
         if (!setTimeout.isDetroyed)
         {
             UnityEngine.Object.Destroy(setTimeout.gameObject);
         }
     }
 }
Beispiel #19
0
    public override void RoundEnter(bool isCanNoPlay)
    {
        base.RoundEnter(isCanNoPlay);
        switch (OrderController.Instance.CurInterationType)
        {
        case InterationType.CallLandlords:
            clock.Init(LandlordsPage.wait_CallLandlordsTime, 10, 5, null, true);
            break;

        case InterationType.QiangLandlords:
            clock.Init(LandlordsPage.wait_QiangTime, 10, 5, null, true);
            break;

        case InterationType.CallFen:
            clock.Init(LandlordsPage.wait_CallFenTime, 10, 5, () => AutoCallLandlord(), true);
            break;

        case InterationType.PopCard:
            if (LandlordsModel.Instance.IsTuoGuan)
            {
                //如果是托管状态
                return;
            }
            List <Card> cards = CardRules.DelayDiscardCard(UserInfoModel.userInfo.userId.ToString());
            if (CheckIsLastCanAutoPop())
            {
                SetTimeout.add(1.5f, () =>
                {
                    AutoPop();
                });
                return;
            }
            if (cards.Count == 0)
            {
                clock.Init(LandlordsPage.wait_canNotPopTime, 4, 5, () => AutoPop(), true);
            }
            else
            {
                clock.Init(LandlordsPage.wait_PopTime, 10, 5, () => AutoPop(), true);
            }
            break;

        default:
            break;
        }
    }
Beispiel #20
0
        private static void PartialWakeLogic(bool mute, int totalInputs = 1, PartialWakeNotifier pwn = null, int iterations = 0)
        {
            double    inputsRequired    = BPMath.Clamp(Program.settings.inputsRequiredToWake, 1, 50);
            const int maxIterations     = 100;
            const int iterationInterval = 100;

            if (totalInputs >= inputsRequired)
            {
                // Input requirements met.  Full Wake.
                if (pwn != null)
                {
                    pwn.Terminate();
                }
            }
            else if (iterations < maxIterations)
            {
                // Waiting for more inputs.
                if (pwn == null)
                {
                    pwn          = new PartialWakeNotifier();
                    pwn.Progress = (int)((totalInputs / inputsRequired) * 100);
                    SetTimeout.OnBackground(() => { Application.Run(pwn); }, 0);
                }
                pwn.SetSecondsRemaining((int)(((maxIterations - iterations) * iterationInterval) / 1000.0));
                SetTimeout.OnBackground(() =>
                {
                    if (LastInput.GetLastInputAgeMs() < maxIterations)
                    {
                        totalInputs++;
                        pwn.Progress = (int)((totalInputs / inputsRequired) * 100);
                    }
                    PartialWakeLogic(mute, totalInputs, pwn, iterations + 1);
                }, iterationInterval);
            }
            else
            {
                // Input requires not met.  Go back to sleep.
                if (pwn != null)
                {
                    pwn.Terminate();
                }
                Off(mute);
            }
        }
Beispiel #21
0
    public static void Start(Action function, float delay, bool isIgnoreTimeScale = true)
    {
        Clear(function);

        if (function == null)
        {
            return;
        }
        if (MainEntry.Instance == null)
        {
            return;
        }

        SetTimeout timeout = MainEntry.Instance.gameObject.AddComponent <SetTimeout>();

        timeout.Add(function, delay, isIgnoreTimeScale);

        functionDict.Add(function, timeout);
    }
Beispiel #22
0
    /// <summary>
    /// 显示网络提示
    /// </summary>
    public void ShowNetTips()
    {
        GameManager.Instance.CancelHeartBreath();
        NetProcess.ReleaseAllConnect();
        Global.Inst.GetController <NetLoadingController>().ShowLoading(true);
        SetTimeout.remove(ReConnet);
        if (Time.realtimeSinceStartup - mLastReconnetTime > 5)//重连间隔要大于5秒
        {
            SQDebug.Log("直接重连");

            ReConnet();
        }
        else
        {
            float time = 5 + mLastReconnetTime - Time.realtimeSinceStartup;
            SQDebug.Log("等" + time + "秒重连");
            SetTimeout.add(time, ReConnet);
        }
    }
    public void CheckVersion(CallBack onVersionUpdateFinish)
    {
        _onVersionUpdateFinish = onVersionUpdateFinish;
        LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在检测是否有新版本...", 0);
#if UNITY_EDITOR
        LoadingNode.OpenLoadingNode(LoadingType.Progress, "正在检测是否有新版本...", 1);
        SetTimeout.add(1, () =>
        {
            LoadingNode.CloseLoadingNode();
            if (_onVersionUpdateFinish != null)
            {
                _onVersionUpdateFinish();
                _onVersionUpdateFinish = null;
            }
        });
        //StartCoroutine(BigVersionUpdate(true));
#elif UNITY_ANDROID
        StartCoroutine(BigVersionUpdate(true));
#elif UNITY_IPHONE
        onVersionUpdateFinish();
        //StartCoroutine(BigVersionUpdate());
#endif
    }
Beispiel #24
0
 /// <summary>
 /// Scans for new keyboards attached to the system, and begins listening to any keyboards that are not currently being listened to.
 /// </summary>
 public void ScanForNewKeyboards()
 {
     try
     {
         string[] keyboardNames = LinuxInputHelper.GetKeyboardInputNames();
         if (keyboardNames == null)
         {
             return;
         }
         foreach (string keyboardName in keyboardNames)
         {
             string devicePath = "/dev/input/" + keyboardName;
             lock (activeListeners)
             {
                 if (!activeListeners.TryGetValue(devicePath, out LinuxInputListener listener) || !listener.IsAlive)
                 {
                     Logger.Info("Created Keyboard Listener for " + devicePath);
                     activeListeners[devicePath]  = listener = new LinuxInputListener(devicePath);
                     listener.KeyDownEvent       += Listener_KeyDownEvent;
                     listener.KeyUpEvent         += Listener_KeyUpEvent;
                     listener.KeyAutoRepeatEvent += Listener_KeyAutoRepeatEvent;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Debug(ex);
     }
     finally
     {
         SetTimeout.OnBackground(() =>
         {
             ScanForNewKeyboards();
         }, msBetweenKeyboardScans);
     }
 }
Beispiel #25
0
        public void stop()
        {
            try {
                bool isPlay = musicPlayer.isPlay() || _isAlarm;
                try {
                    musicPlayer.stop();
                } catch (Exception) { }

                _isAlarm = false;

                if (isPlay)
                {
                    lastStopTime = DateTime.Now.ToFileTimeUtc();
                    onPlayMusicFinished?.Invoke();
                }

                if (waitAlarm != null)
                {
                    waitAlarm.stop();
                    waitAlarm = null;
                }
            } catch (Exception) {
            }
        }
    public IEnumerator BigVersionUpdate(bool isTip)
    {
        WWW www = new WWW(ConstantUtils.urlVersionConfigPath);

        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            JsonData jds    = JsonMapper.ToObject(www.text.Trim());
            string   apkUrl = "";

#if UNITY_ANDROID
            serverVersion = jds["android_severVersion"].ToString();
            apkUrl        = jds["android_apkUrl"].ToString();
            UserInfoModel.userInfo.downUrl = jds["android_webDownApkUrl"].ToString();
#elif UNITY_IPHONE
            serverVersion = jds["ios_curVersion"].ToString();
            apkUrl        = jds["ios_apkUrl"].ToString();
            UserInfoModel.userInfo.downUrl = jds["ios_webDownApkUrl"].ToString();
#elif UNITY_EDITOR
            serverVersion = jds["android_curVersion"].ToString();
            apkUrl        = jds["android_apkUrl"].ToString();
            UserInfoModel.userInfo.downUrl = jds["android_webDownApkUrl"].ToString();
#endif
            if (VersionManager.Instance.MastUpdate())
            {
                CallBack call = () =>
                {
#if UNITY_ANDROID
                    StartCoroutine(DownloadAPK(apkUrl));
#elif UNITY_IPHONE
                    Application.OpenURL(apkUrl);
                    //IOSCall.Instance.OpenUrl (url);
#endif
                };
                if (isTip)
                {
                    TipManager.Instance.OpenTip(TipType.AlertTip, "检测到版本有更新,请更新!", 0, () =>
                    {
                        call();
                    });
                }
                else
                {
                    call();
                }
            }
            else
            {//如果不需要更新
                if (File.Exists(Application.persistentDataPath + "/APK" + "/version.apk"))
                {
                    File.Delete(Application.persistentDataPath + "/APK" + "/version.apk");
                }

                SetTimeout.add(2f, () =>
                {
                    LoadingNode.CloseLoadingNode();
                });
            }
        }
    }
Beispiel #27
0
        public override void handleGETRequest(HttpProcessor p)
        {
            if (!Program.settings.IpIsWhitelisted(p.RemoteIPAddressStr))
            {
                p.writeFailure("403 Forbidden");
                return;
            }
            string successMessage = "<div>" + p.requestedPage + " command successful</div>";
            List <KeyValuePair <string, string> > additionalHeaders = new List <KeyValuePair <string, string> >();

            additionalHeaders.Add(new KeyValuePair <string, string>("Access-Control-Allow-Origin", "*"));
            if (p.requestedPage == "on")
            {
                On(p);
            }
            else if (p.requestedPage == "off")
            {
                int    idleTimeMs = p.GetIntParam("ifidle", 0);
                int    delayMs    = p.GetIntParam("delay", 0);
                Action setOff     = () =>
                {
                    if (idleTimeMs <= 0 || LastInput.GetLastInputAgeMs() >= idleTimeMs)
                    {
                        Off(p.GetBoolParam("mute"));
                    }
                };
                if (delayMs > 0)
                {
                    SetTimeout.OnBackground(setOff, delayMs);
                }
                else
                {
                    setOff();
                }
            }
            else if (p.requestedPage == "off_if_idle")
            {
                OffIfIdle(Program.settings.idleTimeMs, p.GetBoolParam("mute"));
            }
            else if (p.requestedPage == "standby")
            {
                currentMonitorStatus = "off";
                SetMonitorInState(1);
            }
            else if (p.requestedPage == "status")
            {
                p.writeSuccess("text/plain", additionalHeaders: additionalHeaders);
                p.outputStream.Write(currentMonitorStatus);
                return;
            }
            else if (p.requestedPage == "idle")
            {
                p.writeSuccess("text/plain", additionalHeaders: additionalHeaders);
                p.outputStream.Write(LastInput.GetLastInputAgeMs());
                return;
            }
            else if (p.requestedPage == "smarttoggle")
            {
                if (currentMonitorStatus == "on")
                {
                    OffIfIdle(Program.settings.idleTimeMs, p.GetBoolParam("mute"));
                }
                else
                {
                    On(p);
                }
            }
            else if (p.requestedPage == "cancel")
            {
                StopMonitorOffThread();
            }
            else if (p.requestedPage == "getvolume")
            {
                int level = 0;
                try
                {
                    level = (int)Math.Round(AudioManager.GetMasterVolume());
                    //level = Audio.GetVolume();
                }
                catch (Exception ex)
                {
                    p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error");
                    p.outputStream.Write(ex.ToString());
                    return;
                }
                p.writeSuccess("text/plain");
                p.outputStream.Write(level);
            }
            else if (p.requestedPage == "setvolume")
            {
                int level = p.GetIntParam("level");
                level = level.Clamp(0, 100);
                try
                {
                    AudioManager.SetMasterVolume(level);
                    //Audio.SetVolume(level);
                }
                catch (Exception ex)
                {
                    p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error");
                    p.outputStream.Write(ex.ToString());
                    return;
                }
                p.writeSuccess("text/plain");
                p.outputStream.Write(level);
            }
            else if (p.requestedPage == "mute")
            {
                try
                {
                    AudioManager.SetMasterVolumeMute(true);
                    //Audio.SetMute(true);
                }
                catch (Exception ex)
                {
                    p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error");
                    p.outputStream.Write(ex.ToString());
                    return;
                }
                p.writeSuccess("text/plain");
                p.outputStream.Write("muted");
            }
            else if (p.requestedPage == "unmute")
            {
                try
                {
                    AudioManager.SetMasterVolumeMute(false);
                    //Audio.SetMute(false);
                }
                catch (Exception ex)
                {
                    p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error");
                    p.outputStream.Write(ex.ToString());
                    return;
                }
                p.writeSuccess("text/plain");
                p.outputStream.Write("unmuted");
            }
            else if (p.requestedPage == "getmute")
            {
                bool muted = false;
                try
                {
                    muted = AudioManager.GetMasterVolumeMute();
                    //muted = Audio.GetMute();
                }
                catch (Exception ex)
                {
                    p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error");
                    p.outputStream.Write(ex.ToString());
                    return;
                }
                p.writeSuccess("text/plain");
                p.outputStream.Write(muted ? "muted" : "unmuted");
            }
            else if (p.requestedPage == "mousemove")
            {
                int dx    = p.GetIntParam("dx");                           // x change
                int dy    = p.GetIntParam("dy");                           // y change
                int delay = p.GetIntParam("delay").Clamp(1, 200);          // Approximate milliseconds between movements.
                int times = p.GetIntParam("times").Clamp(1, 5000 / delay); // Number of times to perform the change.  Limited to about 5 seconds of movement.
                try
                {
                    DragMouse(dx, dy, delay, times);
                }
                catch (Exception ex)
                {
                    p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error");
                    p.outputStream.Write(ex.ToString());
                    return;
                }
                p.writeSuccess("text/plain; charset=utf-8");
                p.outputStream.Write("move complete. moved " + dx + "," + dy + " " + times + " times with " + delay + " ms delay");
            }
            else if (p.requestedPage == "AllowLocalOverride")
            {
                Program.settings.syncAllowLocalOverride = true;
                Program.settings.Save();
                p.writeSuccess("text/plain; charset=utf-8");
                p.outputStream.Write("✅ Allow local input to override synced state");
            }
            else if (p.requestedPage == "DisallowLocalOverride")
            {
                Program.settings.syncAllowLocalOverride = false;
                Program.settings.Save();
                p.writeSuccess("text/plain; charset=utf-8");
                p.outputStream.Write("❌ Allow local input to override synced state");
            }
            else
            {
                successMessage = "";
            }

            if (p.responseWritten)
            {
                return;
            }

            p.writeSuccess(additionalHeaders: additionalHeaders);
            p.outputStream.Write("<html><head><title>Monitor Control Service</title></head>"
                                 + "<style type=\"text/css\">"
                                 + " table { border-collapse: collapse; }"
                                 + " th, td { border: 1px solid black; padding: 3px 5px; }"
                                 + "</style>"
                                 + "<body>"
                                 + "<p class=\"result\">" + successMessage + "</p>"
                                 + "<p class=\"syncStatus\">(Remote server \"" + Program.settings.syncAddress + "\") " + HttpUtility.HtmlEncode(MonitorControlService.syncedServerStatus) + "</p>"
                                 + "<table>"
                                 //+ "<thead>"
                                 //+ "<tr><th></th><th></th></tr>"
                                 //+ "</thead>"
                                 + "<tbody>"
                                 + BuildRow("on", "turn displays on")
                                 + BuildRow("on?offAfterSecs=15", "turn displays on, then after 15 seconds, off")
                                 + BuildRow("cancel", "cancel a scheduled monitor off command (see above)")
                                 + BuildRow("off", "turn displays off")
                                 + BuildRow("off?ifidle=3000", "turn displays off if idle for 3000ms")
                                 + BuildRow("off?delay=3000&ifidle=2900", "wait 3000ms, then turn displays off if idle for 2900ms")
                                 + BuildRow("off?delay=3000&ifidle=2900&mute=1", "wait 3000ms, then turn displays off if idle for 2900ms, and also mute until the computer is no longer idle")
                                 + BuildRow("off_if_idle", "turn displays off if idle for the configured idle time (" + Program.settings.idleTimeMs + " ms)")
                                 + BuildRow("off_if_idle?mute=1", "turn displays off if idle for the configured idle time (" + Program.settings.idleTimeMs + " ms). Also mute until the computer is no longer idle.")
                                 + BuildRow("standby", "change displays to standby state -- probably does nothing")
                                 + BuildRow("status", "return the current status (\"on\" or \"off\")")
                                 + BuildRow("idle", "return the time in milliseconds since the last user input")
                                 + BuildRow("smarttoggle", "if status is \"on\" then <b>off_if_idle</b>, else <b>on</b>. Also supports the <b>mute</b> boolean argument.")
                                 + BuildRow("getvolume", "returns default audio device volume from 0 to 100")
                                 + BuildRow("setvolume?level=10", "sets default audio device volume from 0 to 100")
                                 + BuildRow("mute", "mutes default audio device")
                                 + BuildRow("unmute", "unmutes default audio device")
                                 + BuildRow("getmute", "returns \"muted\" or \"unmuted\"")
                                 + BuildRow("mousemove?dx=2&dy=-2&delay=4&times=5", "moves the mouse cursor up 2px and to the right 2px, 5 times, waiting 4ms between each movement. Max delay 200ms. Max 5 seconds movement per command.")
                                 + BuildRow("AllowLocalOverride", "Enables the setting \"Allow local input to override synced state\"")
                                 + BuildRow("DisallowLocalOverride", "Disables the setting \"Allow local input to override synced state\"")
                                 + "</tbody>"
                                 + "</table>"
                                 + "</body>"
                                 + "</html>");
        }
Beispiel #28
0
 public void Init(MaJangPlayer player)
 {
     mPlayer = player;
     if (itemName)
     {
         itemName.text = player.nickName.text;
     }
     if (score)
     {
         score.text = player.win.ToString();
     }
     #region 吃 碰 杠
     List <MaJangModel[]> altList = player.lightMjList;
     if (altList.Count > 0)
     {
         for (int i = 0; i < altList.Count; i++)
         {
             MaJangModel[] mjModel = altList[i];
             GameObject    mjAlt   = Instantiate(altPrefab, horizontal);
             mjAlt.SetActive(true);
             for (int j = 0; j < mjAlt.transform.childCount; j++)
             {
                 if (mjModel.Length > j)
                 {
                     mjAlt.transform.GetChild(j).GetComponent <MaJangResultMj>().Init(mjModel[j].mjNo.ToString());
                 }
                 else
                 {
                     mjAlt.transform.GetChild(j).gameObject.SetActive(false);
                 }
             }
             mjAlt.transform.SetParent(horizontal);
         }
     }
     #endregion
     #region 手牌
     List <MaJangModel> handList = player.handMjList;
     int handCount = player.win > 0 ? handList.Count - 1 : handList.Count;
     for (int i = 0; i < handCount; i++)
     {
         MaJangResultMj mj = Instantiate(mjPrefab, handParent);
         mj.gameObject.SetActive(true);
         mj.Init(handList[i].mjNo.ToString());
         mj.transform.SetParent(handParent);
     }
     handParent.gameObject.SetActive(false);
     handParent.GetComponent <HorizontalLayoutGroup>().enabled = false;
     handParent.GetComponent <HorizontalLayoutGroup>().enabled = true;
     handParent.SetParent(horizontal);
     if (player.win > 0)
     {
         MaJangModel last = player.handMjList[handList.Count - 1];
         mjPrefab.Init(last.mjNo.ToString());
         mjPrefab.transform.SetParent(horizontal);
     }
     else
     {
         mjPrefab.gameObject.SetActive(false);
     }
     #endregion
     gameObject.SetActive(true);
     horizontal.GetComponent <HorizontalLayoutGroup>().enabled = false;
     horizontal.GetComponent <HorizontalLayoutGroup>().enabled = true;
     SetTimeout.add(0.1f, () =>
     {
         handParent.gameObject.SetActive(false);
         horizontal.gameObject.SetActive(false);
         handParent.gameObject.SetActive(true);
         horizontal.gameObject.SetActive(true);
     });
 }
 private void PartialWakeNotifier_Load(object sender, EventArgs e)
 {
     SetWindowOnTop();
     resetTopTimeout  = SetTimeout.OnGui(SetWindowOnTop, 1000, this);
     resetTop2Timeout = SetTimeout.OnGui(SetWindowOnTop, 2000, this);
 }
Beispiel #30
0
 private void Start()
 {
     inst = this;
 }