Ejemplo n.º 1
0
        protected byte[] PrepareMessage(byte[] bytes, RemoteCommandType cmdType)
        {
            var buffer = new byte[bytes.Length + 1];

            Array.Copy(BitConverter.GetBytes((int)cmdType), buffer, 1);
            Array.Copy(bytes, 0, buffer, 1, buffer.Length - 1);

            return(buffer);
        }
        private string IncomingCommand(byte[] data, string path, string param)
        {
            using (MemoryStream str = new MemoryStream(data))
            {
                OSDMap map = (OSDMap)OSDParser.DeserializeJson(str);

                UUID sessionID = map["sessionId"].AsUUID();
                UUID userID    = map["userId"].AsUUID();
                UUID regionID  = map["regionId"].AsUUID();

                Scene scene = _scenes.FirstOrDefault((s) => s.RegionInfo.RegionID == regionID);
                if (scene == null)//No scene found...
                {
                    return(BuildCommandResponse(RemoteCommandResponse.NOTFOUND, null));
                }

                if (!scene.ConnectionManager.IsAuthorized(userID, sessionID))
                {
                    //They might not be in the scene, check if they have left recently
                    LeavingRegionInfo info = null;
                    if (!_avatarRegionCache.TryGetValue(userID, out info) || info.SessionID != sessionID)
                    {
                        return(BuildCommandResponse(RemoteCommandResponse.UNAUTHORIZED, null));//Wrong sessionID or was never here
                    }
                    //They moved out of this region
                    return(BuildMovedCommandResponse(userID));
                }

                ScenePresence presence = scene.GetScenePresence(userID);
                if (presence == null || presence.IsChildAgent)//Make sure that they are actually in the region
                {
                    return(BuildMovedCommandResponse(userID));
                }

                //Process the command
                RemoteCommandType commandID = (RemoteCommandType)map["id"].AsInteger();
                switch (commandID)
                {
                case RemoteCommandType.AvatarChatCommand:
                    return(ProcessAvatarChatCommand(presence, map));

                case RemoteCommandType.AvatarTeleportCommand:
                    return(ProcessAvatarTeleportCommand(presence, map));
                }
            }
            return(BuildCommandResponse(RemoteCommandResponse.INVALID, null));
        }
Ejemplo n.º 3
0
        public const int FOURCC_SELECT_TRACK  = 0x544c4553;        // "SELT" Client -> Server

        private static int RemoteCommandTypeToFourCC(RemoteCommandType t)
        {
            switch (t)
            {
            case RemoteCommandType.PlaylistData: return(FOURCC_PLAYLIST_DATA);

            case RemoteCommandType.Exit: return(FOURCC_EXIT);

            case RemoteCommandType.Pause: return(FOURCC_PAUSE);

            case RemoteCommandType.Stop: return(FOURCC_STOP);

            case RemoteCommandType.PlayPositionUpdate: return(FOURCC_PLAY_POSITION_UPDATE);

            default:
                System.Diagnostics.Debug.Assert(false);
                return(FOURCC_EXIT);
            }
        }
Ejemplo n.º 4
0
        private void SetIdAndVal(string id, string val)
        {
            string Decoded = WebServer.DecodeUrlChars(val);

            id = id.ToLower().Trim();
            switch (id)
            {
            case "com":
            {
                if (val == "msgbx")
                {
                    this.ComType = RemoteCommandType.MessageBox;
                }
                else if (val == "procstr" || val == "proc")
                {
                    this.ComType = RemoteCommandType.process;
                }
                else if (val == "closproc" || val == "closeprocess")
                {
                    this.ComType = RemoteCommandType.CloseProcess;
                }
                else if (val == "closallproc" || val == "closeallprocess")
                {
                    this.ComType = RemoteCommandType.CloseAllProcess;
                }


                break;
            }

            case "mbtitle": this.MessageBoxCap = Decoded; break;

            case "procnm": this.ProcessName = val; break;

            case "proctype": this.ViewImageProcess = val == "pic"; break;

            case "procpar": this.NoProcessPar = false; this.ProcessPar = Decoded; break;
            }
        }
Ejemplo n.º 5
0
        private byte[] HandleMessage(ArraySegment <byte> bytes, RemoteCommandType cmdType)
        {
            byte[] response = null;

            switch (cmdType)
            {
            case RemoteCommandType.CurrencyRate:
            {
                var cmd      = MessagePackSerializer.Deserialize <CurrencyRateCommand>(bytes);
                var currency = DbRepository.GetCurrencyRate(cmd.Currency);
                response = MessagePackSerializer.Serialize <double>(currency);
                break;
            }

            case RemoteCommandType.DbExchangeInfo:
            {
                var cmd    = MessagePackSerializer.Deserialize <ExchangeInfoCommand>(bytes);
                var dbInfo = DbRepository.GetExchangeInfo(cmd.Exchange);
                response = MessagePackSerializer.Serialize <DbExchange>(dbInfo);
                break;
            }

            case RemoteCommandType.DbBalance:
            {
                var cmd = MessagePackSerializer.Deserialize <DbBalanceCommand>(bytes);
                response = MessagePackSerializer.Serialize <UserAccount>(DbRepository.GetLastBalances(cmd.Exchange));
                break;
            }

            case RemoteCommandType.DbServiceEventSession:
            {
                var cmd = MessagePackSerializer.Deserialize <ServiceEventCommand>(bytes);
                response = MessagePackSerializer.Serialize <int>(DbRepository.GetServiceEventSession());
                break;
            }

            case RemoteCommandType.DbWriteServiceEvent:
            {
                var cmd = MessagePackSerializer.Deserialize <ServiceEventCommand>(bytes);
                DbRepository.WriteServiceEvent(cmd.SessionId, cmd.EventType, cmd.ServiceName, cmd.Message, cmd.ExchangeId);
                break;
            }

            case RemoteCommandType.RunRestScheduler:
            {
                var cmd = MessagePackSerializer.Deserialize <RestSchedulerCommand>(bytes);
                if (cmd.Run)
                {
                    _restScheduler.Connect(cmd.Instrument);
                }
                else
                {
                    _restScheduler.Disconnect(cmd.Instrument);
                }
                break;
            }

            case RemoteCommandType.RestEnabledExchanges:
            {
                response = MessagePackSerializer.Serialize <Dictionary <string, bool> >(GetRestEnabledExchanges());
                break;
            }

            case RemoteCommandType.WsEnabledExchanges:
            {
                response = MessagePackSerializer.Serialize <Dictionary <string, bool> >(GetWebSocketEnabledExchanges());
                break;
            }

            case RemoteCommandType.ExchangeSettings:
            {
                response = MessagePackSerializer.Serialize <ExchangeSettingsData[]>(GetExchangeSettings());
                break;
            }

            case RemoteCommandType.ExchangePrices:
            {
                var cmd = MessagePackSerializer.Deserialize <ExchangePricesCommand>(bytes);
                lock (this) ExchangePrices(this, cmd.Prices);
                break;
            }

            case RemoteCommandType.Arbitrage:
            {
                var cmd = MessagePackSerializer.Deserialize <ArbitrageCommand>(bytes);
                switch (cmd.Type)
                {
                case ArbitrageCommand.CommandState.Start:
                    MatchingEngine.SingleInstrumentArbitrage();
                    response = MessagePackSerializer.Serialize <bool>(true);
                    break;

                case ArbitrageCommand.CommandState.Stop:
                    MatchingEngine.StopMatching();
                    response = MessagePackSerializer.Serialize <bool>(true);
                    break;

                case ArbitrageCommand.CommandState.Status:
                    response = MessagePackSerializer.Serialize <string>(MatchingEngine.GetState());
                    break;
                }
                break;
            }
            }
            return(response);
        }
Ejemplo n.º 6
0
        // 受信したとき用ctor
        public RemoteCommand(int header, int bytes, byte[] payload)
        {
            cmd = FourCCToRemoteCommandType(header);

            switch (header)
            {
            case FOURCC_PLAYLIST_WANT:
            case FOURCC_EXIT:
            case FOURCC_PAUSE:
                // no payload
                if (payload.Length != 0)
                {
                    Console.WriteLine("D: RemoteCommand {0} and payload length is not 0! {1}.", cmd, payload.Length);
                    break;
                }
                break;

            case FOURCC_PLAY:
            case FOURCC_SELECT_TRACK:
                /* trackIdx (4 bytes)
                 */
                if (payload.Length != 4)
                {
                    Console.WriteLine("D: RemoteCommand {0} and payload length is not 4! {1}.", cmd, payload.Length);
                    break;
                }
                trackIdx = BitConverter.ToInt32(payload, 0);
                if (trackIdx < 0)
                {
                    Console.WriteLine("D: RemoteCommand {0} and trackIdx is negative value {1}.", cmd, payload.Length);
                    trackIdx = 0;
                    break;
                }
                break;

            case FOURCC_SEEK:
                /* positionMillisec (4bytes)
                 * trackMillisec (4bytes)
                 */
                if (payload.Length != 8)
                {
                    Console.WriteLine("D: RemoteCommand Seek and payload length is not 8 {0}.", payload.Length);
                    break;
                }
                positionMillisec = BitConverter.ToInt32(payload, 0);
                if (positionMillisec < 0)
                {
                    Console.WriteLine("D: RemoteCommand Play and positionMillisec is negative value {0}.", positionMillisec);
                    positionMillisec = 0;
                    break;
                }
                trackMillisec = BitConverter.ToInt32(payload, 4);
                if (trackMillisec <= 0)
                {
                    Console.WriteLine("D: RemoteCommand Play and positionMillisec is zero or negative value {0}.", trackMillisec);
                    trackMillisec = 1;
                    break;
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }
        }
Ejemplo n.º 7
0
 public RemoteCommand(RemoteCommandType t, int aTrackIdx = 0, int aPositionMs = 0)
 {
     cmd              = t;
     trackIdx         = aTrackIdx;
     positionMillisec = aPositionMs;
 }
Ejemplo n.º 8
0
        private byte[] HandleMessage(ArraySegment <byte> bytes, RemoteCommandType cmdType)
        {
            byte[] response = null;

            switch (cmdType)
            {
            case RemoteCommandType.CurrencyRate:
            {
                var cmd      = MessagePackSerializer.Deserialize <CurrencyRateCommand>(bytes);
                var currency = _dbRepo.GetCurrencyRate(cmd.Currency);
                response = MessagePackSerializer.Serialize <double>(currency);
                break;
            }

            case RemoteCommandType.DbExchangeInfo:
            {
                var cmd    = MessagePackSerializer.Deserialize <ExchangeInfoCommand>(bytes);
                var dbInfo = _dbRepo.GetExchangeInfo(cmd.Exchange);
                response = MessagePackSerializer.Serialize <DbExchange>(dbInfo);
                break;
            }

            case RemoteCommandType.DbBalance:
            {
                var cmd = MessagePackSerializer.Deserialize <DbBalanceCommand>(bytes);
                var db  = _dbRepo.GetLastBalances(cmd.Exchange);
                response = MessagePackSerializer.Serialize <DbAccount>(db);
                break;
            }

            case RemoteCommandType.DbSyncBalance:
            {
                var cmd = MessagePackSerializer.Deserialize <DbSyncBalancesCommand>(bytes);
                cmd      = _dbRepo.SyncBalances(cmd);
                response = MessagePackSerializer.Serialize <DbSyncBalancesCommand>(cmd);
                break;
            }

            case RemoteCommandType.DbServiceEventSession:
            {
                var cmd = MessagePackSerializer.Deserialize <ServiceEventCommand>(bytes);
                int id  = 0;
                lock (_obj) id = _dbRepo.GetServiceEventSession();
                response = MessagePackSerializer.Serialize <int>(id);
                break;
            }

            case RemoteCommandType.DbWriteServiceEvent:
            {
                var cmd = MessagePackSerializer.Deserialize <ServiceEventCommand>(bytes);
                _dbRepo.WriteServiceEvent(new ServiceEventData
                    {
                        ServiceName = cmd.ServiceName,
                        SessionId   = cmd.SessionId,
                        EventType   = cmd.EventType,
                        Message     = cmd.Message,
                        ExchangeId  = cmd.ExchangeId
                    });
                break;
            }

            case RemoteCommandType.MatchingData:
            {
                var cmd = MessagePackSerializer.Deserialize <MatchingDataCommand>(bytes);
                _dbRepo.SaveTransaction(cmd.Data, ex => _log.WriteError(ex.Message));
                break;
            }

            case RemoteCommandType.RunRestScheduler:
            {
                var cmd = MessagePackSerializer.Deserialize <RestSchedulerCommand>(bytes);
                if (cmd.Run)
                {
                    _restScheduler.Connect(cmd.Instrument);
                }
                else
                {
                    _restScheduler.Disconnect(cmd.Instrument);
                }
                break;
            }

            case RemoteCommandType.RestEnabledExchanges:
            {
                var config           = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");
                var enabledExchanges = config.GetRestEnabledExchanges();
                response = MessagePackSerializer.Serialize <Dictionary <string, bool> >(enabledExchanges);
                break;
            }

            case RemoteCommandType.WsEnabledExchanges:
            {
                var config           = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");
                var enabledExchanges = config.GetWebSocketEnabledExchanges();
                response = MessagePackSerializer.Serialize <Dictionary <string, bool> >(enabledExchanges);
                break;
            }

            case RemoteCommandType.ExchangeSettings:
            {
                var config   = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");
                var settings = new List <ExchangeSettingsData>();
                foreach (ExchangeElement setting in config.ExchangeSettings)
                {
                    settings.Add(new ExchangeSettingsData
                        {
                            Exchange     = (ExchangeName)Enum.Parse(typeof(ExchangeName), setting.Name),
                            Currency     = setting.Currency,
                            RestUrl      = setting.RestUrl,
                            WebsocketUrl = setting.WsUrl,
                            PublicKey    = setting.PublicKey,
                            PrivateKey   = setting.PrivateKey,
                            UserId       = setting.UserId
                        });
                }
                response = MessagePackSerializer.Serialize <ExchangeSettingsData[]>(settings.ToArray());
                break;
            }

            case RemoteCommandType.ExchangePrices:
            {
                if (_logMatchingData)
                {
                    var cmd = MessagePackSerializer.Deserialize <ExchangePricesCommand>(bytes);
                    _dbRepo.SaveOrderBook(cmd.Prices);
                }
                break;
            }

            case RemoteCommandType.CanResetBalances:
            {
                var cmd    = MessagePackSerializer.Deserialize <CanResetBalancesCommand>(bytes);
                var result = _dbRepo.CanResetBalances(cmd.Exchanges);
                response = MessagePackSerializer.Serialize <Tuple <bool, DbAccount[]> >(result);
                break;
            }
            }
            return(response);
        }
Ejemplo n.º 9
0
        private void SetIdAndVal(string id, string val)
        {
            string Decoded = WebServer.DecodeUrlChars(val);

            id = id.ToLower().Trim();
            int val_int = 10;

            val_int = AppHelper.StringToint(val, 10);
            switch (id)
            {
            case "com":
            {
                if (val == "msgbx")
                {
                    this.ComType = RemoteCommandType.MessageBox;
                }
                else if (val == "procstr" || val == "proc")
                {
                    this.ComType = RemoteCommandType.process;
                }
                else if (val == "closproc" || val == "closeprocess")
                {
                    this.ComType = RemoteCommandType.CloseProcess;
                }
                else if (val == "closallproc" || val == "closeallprocess")
                {
                    this.ComType = RemoteCommandType.CloseAllProcess;
                }
                else if (val == "mvcrs" || val == "movecursor")
                {
                    this.ComType = RemoteCommandType.MoveMouse;
                }
                else if (val == "msclk" || val == "mouseclick")
                {
                    this.ComType = RemoteCommandType.MouseClick;
                }
                else if (val == "mute" || val == "mutesys")
                {
                    this.ComType = RemoteCommandType.MuteSystemSound;
                }
                else if (val == "msrclk" || val == "mouseright")
                {
                    this.ComType = RemoteCommandType.MouseRightClick;
                }
                else if (val == "prntscr" || val == "printscreen")
                {
                    this.ComType = RemoteCommandType.PrintScreenShot;
                }
                else if (val == "ls" || val == "list")
                {
                    this.ComType = RemoteCommandType.LS;
                }
                else if (val == "hdcl" || val == "hidecl")
                {
                    this.ComType = RemoteCommandType.HideClient;
                }

                else if (val == "shcl" || val == "showcl")
                {
                    this.ComType = RemoteCommandType.ShowClient;
                }

                break;
            }

            case "mbtitle": this.MessageBoxCap = Decoded; break;

            case "frm": this.formvisible = AppHelper.BoolTruefalsefromString(Decoded); break;

            case "dirpath":
            case "directorypath":
            case "drpth": this.DirPath = Decoded; break;

            case "crsx":    { this.X = val_int;; break; }

            case "close": { this.closeMessage = AppHelper.BoolTruefalsefromString(Decoded); break; }

            case "crsy":    { this.Y = val_int;; break; }

            case "procnm": this.ProcessName = val; break;

            case "proctype": this.ViewImageProcess = (val == "pic"); break;

            case "procpar": this.NoProcessPar = false; this.ProcessPar = Decoded; break;

            case "shftdir": this.CursorGoingBack = (val.Contains("back")); break;
            }
        }
Ejemplo n.º 10
0
        private void SetIdAndVal(string id, string val)
        {
            string Decoded = WebServer.DecodeUrlChars(val);
            id = id.ToLower().Trim();
            int val_int = 10;
            val_int = AppHelper.StringToint(val, 10);
            switch (id)
            {
                case "com":
                    {
                        if(val=="msgbx")
                            this.ComType = RemoteCommandType.MessageBox;
                        else  if (val == "procstr" || val =="proc")
                                this.ComType = RemoteCommandType.process;
                        else if (val == "closproc" || val == "closeprocess")
                            this.ComType = RemoteCommandType.CloseProcess;
                        else if (val == "closallproc" || val == "closeallprocess")
                            this.ComType = RemoteCommandType.CloseAllProcess;
                        else if (val == "mvcrs" || val == "movecursor")
                            this.ComType = RemoteCommandType.MoveMouse;
                        else if (val == "msclk" || val == "mouseclick")
                            this.ComType = RemoteCommandType.MouseClick;
                        else if (val == "mute" || val == "mutesys")
                            this.ComType = RemoteCommandType.MuteSystemSound;
                        else if (val == "msrclk" || val == "mouseright")
                            this.ComType = RemoteCommandType.MouseRightClick;
                        else if (val == "prntscr" || val == "printscreen")
                            this.ComType = RemoteCommandType.PrintScreenShot;
                        else if (val == "ls" || val == "list")
                            this.ComType = RemoteCommandType.LS;
                        else if (val == "hdcl" || val == "hidecl")
                            this.ComType = RemoteCommandType.HideClient;

                        else if (val == "shcl" || val == "showcl")
                            this.ComType = RemoteCommandType.ShowClient;

                        break;
                    }
                case "mbtitle": this.MessageBoxCap = Decoded; break;
                case "frm": this.formvisible = AppHelper.BoolTruefalsefromString(Decoded); break;
                case "dirpath":
                case "directorypath":
                case "drpth": this.DirPath = Decoded; break;
                case "crsx"     :    { this.X = val_int; ; break; }
                case "close": { this.closeMessage = AppHelper.BoolTruefalsefromString(Decoded) ; break; }
                case "crsy"    :    { this.Y = val_int; ; break; }
                case "procnm": this.ProcessName = val; break;
                case "proctype": this.ViewImageProcess =( val == "pic"); break;
                case "procpar": this.NoProcessPar = false; this.ProcessPar = Decoded; break;
                case "shftdir": this.CursorGoingBack = (val.Contains("back")); break;
            }
        }