Exemplo n.º 1
0
        public void SendCompressedCommand(RemoteCommand command, object obj, AppSession session)
        {
            LogHelper.WriteLog(typeof(RemoteCommand), "发送消息:" + command.ToString());
            var type = ((int)command).ToString().PadLeft(2, '0');

            byte[] typeByte = Encoding.UTF8.GetBytes(type);

            var str      = JsonConvert.SerializeObject(obj);
            var comp_str = CompressHelper.Compress(str);

            byte[] byteBuffer = Encoding.UTF8.GetBytes(comp_str);

            int len = byteBuffer.Length;

            byte[] length = BitConverter.GetBytes(len);

            var data = typeByte.Concat(length).Concat(byteBuffer).ToArray();

            if (type.Length != 2)
            {
                return;
            }
            try
            {
                session.Send(data, 0, data.Length);
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 2
0
        public void SendCommand(RemoteServerInfo serverInfo, RemoteCommand remoteCommand)
        {
            string hostName;
            int    port;

            if (!tryGetServiceInfo(serverInfo.DacpId, out hostName, out port))
            {
                return;
            }

            string command = remoteCommand.ToString().ToLowerInvariant();

            Logger.Debug("Sending remote command to server: {0}", command);
            string url = string.Format("http://{0}:{1}/ctrl-int/1/{2}", hostName, port, command);

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Headers.Add("Active-Remote", serverInfo.ActiveRemote);
                request.BeginGetResponse(ar =>
                {
                    try
                    {
                        using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar))
                        {
                            if (response.StatusCode != HttpStatusCode.NoContent && response.StatusCode != HttpStatusCode.OK)
                            {
                                Logger.Warn("Client returned unexpected response to remote control request: {0} - {1}", response.StatusCode, response.StatusDescription);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(string.Format("Exception receiving remote control response from {0} -", url), ex);
                    }
                }, null);
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Exception sending remote control request to {0} -", url), ex);
            }
        }
Exemplo n.º 3
0
        public static void Send(RemoteCommand command)
        {
            string data = command.ToString() + "<EOF>";

            if (client?.Connected != true && !StartClient())
            {
                return;
            }
            try
            {
                // Convert the string data to byte data using ASCII encoding.
                byte[] byteData = Encoding.ASCII.GetBytes(data);
                // Begin sending the data to the remote device.
                client.BeginSend(byteData, 0, byteData.Length, 0,
                                 new AsyncCallback(SendCallback), client);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                client = null;
                Send(command);
            }
        }
Exemplo n.º 4
0
 protected virtual void AlertInvokeError(RemoteCommand command, Exception exception)
 {
     Debug.Log("Invoke " + command.ToString() + " is falied. " + exception.ToString());
 }
Exemplo n.º 5
0
 protected virtual void AlertIDConflict(RemoteCommand existingCommand, RemoteCommand conflictCommand)
 {
     Debug.Log("Conflict Command ID: " + existingCommand.ID + ", "
               + existingCommand.ToString() + ", " + conflictCommand.ToString());
 }
Exemplo n.º 6
0
        void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        {
            try
            {
                RemoteCommand type = (RemoteCommand)Enum.Parse(typeof(RemoteCommand), requestInfo.Key);
                LogHelper.WriteLog(typeof(RemoteCommand), "收到消息:" + type.ToString() + requestInfo.Key);
                switch (type)
                {
                case RemoteCommand.Login:
                    CheckLogin(requestInfo);
                    break;

                case RemoteCommand.SendFrontCurSession:
                    SendCurSessionToBack();
                    break;

                case RemoteCommand.ImportFrontLocalSessions:
                    SendCompressedCommand(RemoteCommand.ImportFrontLocalSessions, Game.Instance.LocalSessions, session);
                    break;

                case RemoteCommand.ImportBack:
                    OnImportBack(session, requestInfo);
                    break;

                case RemoteCommand.ImportBackNextSession:
                    OnImportBackNextSession(session, requestInfo);
                    break;

                case RemoteCommand.SendFrontBetRecordIdList:
                    SendBetRecordIdsToBack();
                    break;

                case RemoteCommand.SendFrontBetRecord:
                    SendBetRecordToBack(session, requestInfo);
                    break;

                case RemoteCommand.SendFrontAccount:
                    SendAccountToBack(session, requestInfo);
                    break;

                case RemoteCommand.ClearFrontAccount:
                    Game.Instance.Manager.ClearFrontAccountByBack();
                    break;

                case RemoteCommand.ClearFrontLocalSessions:
                    Game.Instance.Manager.ClearLocalSessions();
                    break;

                case RemoteCommand.SetWinner:
                    SetWinner(session, requestInfo);
                    break;

                case RemoteCommand.KillBig:
                    KillBig(session, requestInfo);
                    break;

                case RemoteCommand.ExtraWaybill:
                    ExtraWaybill();
                    break;

                case RemoteCommand.ShutdownFront:
                    ControlBoard.Instance.ShutdownComputer();
                    break;

                case RemoteCommand.BreakdownFront:
                    ControlBoard.Instance.BreakdownGame();
                    break;

                case RemoteCommand.LockFront:
                    Game.Instance.SetGameLock();
                    if (appSession.Connected && Login)
                    {
                        SendData(RemoteCommand.LockFrontOK, "", appSession);
                    }
                    break;

                case RemoteCommand.UnlockFront:
                    Game.Instance.SetGameUnlock();
                    if (appSession.Connected && Login)
                    {
                        SendData(RemoteCommand.UnlockFrontOK, "", appSession);
                    }
                    break;

                case RemoteCommand.ModifyFrontPassword:
                    ModifyFrontPassword(session, requestInfo);
                    break;

                case RemoteCommand.ModifyFrontSetting:
                    ModifyFrontSetting(session, requestInfo);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(Object), "UnobservedTaskException:" + ex.Message + ex.StackTrace);
                //throw;
            }
        }