コード例 #1
0
ファイル: AIController.cs プロジェクト: chemming/SRL_1
 public bool GetAction(ActionCode code)
 {
     if(code == ActionCode.fire1 || code == ActionCode.fire2)
     {
         if(shoot == true)
             return true;
     }
     return false;
 }
コード例 #2
0
ファイル: XActionNames.cs プロジェクト: liwq-net/SwfLib
        private static void Register(ActionCode actionCode, string nodeName)
        {
            ActionCode testCode;
            if (_nodeNameToCode.TryGetValue(nodeName, out testCode)) throw new InvalidOperationException("Node " + nodeName + " is already registered");

            string testNodeName;
            if (_codeToNodeName.TryGetValue(actionCode, out testNodeName)) throw new InvalidOperationException("Action " + actionCode + " is already registered");

            _codeToNodeName[actionCode] = nodeName;
            _nodeNameToCode[nodeName] = actionCode;
        }
コード例 #3
0
        public override bool GetActionUp(ActionCode ac)
        {
            if(!_actionMapping.ContainsKey(ac))
                return false;
            if(trackedObj.index == SteamVR_TrackedObject.EIndex.None)
                return false;

            var device = SteamVR_Controller.Input((int)trackedObj.index);

            return device.GetPressUp(_actionMapping[ac]);
        }
コード例 #4
0
        public override bool GetAction(ActionCode ac)
        {
            if(!_actionMapping.ContainsKey(ac))
                return false;

            // todo: make this a one time initialization process
            //       device isn't always initialized in the Start method
            //       so we currently retrieve it every time.
            //       check if this is inefficient and implement something better if needed.
            if(trackedObj.index == SteamVR_TrackedObject.EIndex.None)
                return false;

            var device = SteamVR_Controller.Input((int)trackedObj.index);

            return device.GetPress(_actionMapping[ac]);
        }
コード例 #5
0
 public void HandleRequest(RequestCode requestCode, ActionCode actionCode, string data, Client client)
 {
     if (actionCode == ActionCode.Chat)
     {
         string[] strs     = data.Split(',');
         string   username = strs[0];
         string   roomName = strs[1];
         string   Message  = strs[2];
         //收到消息之后告诉房间内的所有人
         Console.WriteLine("收到消息者" + username + "房间名:" + roomName + "消息" + Message);
         Console.WriteLine("当前房间人数" + RoomManager.Instance.roomList[roomName].Count);
         if (RoomManager.Instance.roomList.ContainsKey(roomName))
         {
             Console.WriteLine("发送数据");
             for (int i = 0; i < RoomManager.Instance.roomList[roomName].Count; i++)
             {
                 //Client clien = new Client();
                 Client clien = RoomManager.Instance.roomList[roomName][i];
                 server.SendResponse(clien, ActionCode.Chat, data);
             }
         }
     }
     else
     {
         BaseController controller;
         bool           isGet = controllerDict.TryGetValue(requestCode, out controller);
         if (isGet == false)
         {
             Console.WriteLine("无法得到[" + requestCode + "]所对应的Controller,无法处理请求"); return;
         }
         string     methodName = Enum.GetName(typeof(ActionCode), actionCode);
         MethodInfo mi         = controller.GetType().GetMethod(methodName);
         if (mi == null)
         {
             Console.WriteLine("[警告]在Controller[" + controller.GetType() + "]中没有对应的处理方法:[" + methodName + "]"); return;
         }
         object[] parameters = new object[] { data, client, server };
         object   o          = mi.Invoke(controller, parameters);
         if (o == null || string.IsNullOrEmpty(o as string))
         {
             return;
         }
         Console.Write("返回action" + actionCode);
         server.SendResponse(client, actionCode, o as string);
     }
 }
コード例 #6
0
        /// <summary>
        /// イベントリスナー追加
        /// </summary>
        /// <param name="code"></param>
        /// <param name="trigger"></param>
        /// <param name="action"></param>
        public void AddActionEventListener(ActionCode code, TriggerType trigger, UnityAction action)
        {
            var key = new ActionEventKey {
                code = code, trigger = trigger
            };
            ActionEvent inputEvent;

            if (!eventTable.TryGetValue(key, out inputEvent))
            {
                inputEvent = new ActionEvent();
                eventTable.Add(key, inputEvent);
            }

            Assert.IsNotNull(inputEvent, "inputEvent must be not null!");

            inputEvent.AddListener(action);
        }
コード例 #7
0
ファイル: History.cs プロジェクト: roman34rus/Print-Stat
        public History(ActionCode actionCode, Printer printer, Supply supply)
        {
            Date   = DateTime.Now;
            Action = (int)actionCode;

            PrinterId       = printer.Id;
            PrinterModel    = printer.PrinterModel.Name;
            PrinterName     = printer.Name;
            PrinterLocation = printer.Location;
            PrinterOwner    = printer.Owner;
            PrinterComment  = printer.Comment;

            SupplyId         = supply.Id;
            SupplyPartNumber = supply.SupplyModel.PartNumber;
            SupplyName       = supply.SupplyModel.Name;
            SupplyComment    = supply.Comment;
        }
コード例 #8
0
    private void OnActionStateUpdateEvent(string name, ActionCode newState, Vector3?lookDir)
    {
        if (gameObject.name != name)
        {
            return;
        }
        ActionState = newState;

        if (lookDir == null)
        {
            return;
        }

        float lockDuration = GetCastDuration(newState);

        m_RotationController.LookAt(lookDir.Value, lockDuration);
    }
コード例 #9
0
    //处理响应
    private void OnProcessCallback(ActionCode actionCode, string data)
    {
        Facade.HandleResponse(actionCode, data);
        #region MyRegion
        //        ((RequestManger)GameFacade.Instance.GetManger(typeof(RequestManger))).HandleResponse(requestCode, data);//todo

        //        RequestManger requestManger = GameFacade.Instance.GetManger(typeof(RequestManger)) as RequestManger;
        //        if (requestManger != null)
        //        {
        //            requestManger.HandleResponse(requestCode,data);
        //        }
        //        else
        //        {
        //            Debug.Log("没有从GameFacade中得到RequestManger");
        //        }
        #endregion
    }
コード例 #10
0
    public static byte[] PackData(RequestCode requestData, ActionCode actionCode, string data)
    {
//        Debug.LogWarning("Message:"+requestData);
//        Debug.LogWarning("Message:"+actionCode);
//        Debug.LogWarning("Message:"+data);
//        byte[] requestCodeBytes = BitConverter.GetBytes((int)requestData);
//        Debug.LogWarning(BitConverter.ToString(requestCodeBytes));
//        Debug.LogWarning(Encoding.UTF8.GetBytes(BitConverter.ToString(requestCodeBytes)).Length);
//        byte[] actionCodeBytes = BitConverter.GetBytes((int)actionCode);
//        byte[] dataBytes = Encoding.UTF8.GetBytes(data);
//        int dataAmount = requestCodeBytes.Length + dataBytes.Length + actionCodeBytes.Length;
//        Debug.LogWarning("Length:"+dataAmount);
//        byte[] dataAmountBytes = BitConverter.GetBytes(dataAmount);
        //byte[] newBytes = dataAmountBytes.Concat(requestCodeBytes).ToArray<byte>();//Concat(dataBytes);
        //return newBytes.Concat(dataBytes).ToArray<byte>();
//        return dataAmountBytes.Concat(requestCodeBytes).ToArray<byte>()
//            .Concat(actionCodeBytes).ToArray<byte>()
//            .Concat(dataBytes).ToArray<byte>();
//        string test = "django,12345";
//        byte[] datas = Encoding.UTF8.GetBytes(test);
//
//        return datas;

        //  Debug.LogWarning("packData");
        // Debug.LogWarning("actionCode--------->"+(int)actionCode);
        JsonData jsonData = new JsonData();

        jsonData["requestCode"] = requestData.ToString();
        jsonData["actionCode"]  = actionCode.ToString();
        jsonData["data"]        = data;

        string datas = jsonData.ToJson();

        //  Debug.LogWarning("PackedData------>"+datas);

        byte[] Json = Encoding.UTF8.GetBytes(datas);
        return(Json);

//        byte[] test = dataAmountBytes.Concat(requestCodeBytes).ToArray<byte>()
//            .Concat(actionCodeBytes).ToArray<byte>();


//       Debug.LogWarning("---------"+Encoding.UTF8.GetBytes(BitConverter.ToString(test)).Length);
//        return Encoding.UTF8.GetBytes(BitConverter.ToString(test));
    }
コード例 #11
0
    /// <summary>
    /// 消息处理
    /// </summary>
    /// <param name="msg">消息</param>
    public void MessageHandler(ProtocalData msg)
    {
        if (msg == null)
        {
            return;
        }
        ActionCode  code = msg.GetName().ToEnum <ActionCode>();
        BaseHandler baseHandler;

        if (msgDict.TryGetValue(code, out baseHandler))
        {
            baseHandler.OnResponse(msg);
        }
        else
        {
            Debug.LogWarning("没有对应的处理类: " + msg.GetName());
        }
    }
コード例 #12
0
ファイル: AOEHintCreator.cs プロジェクト: namelesswc/MMOnkey
    private static float GetCastTime(ActionCode action)
    {
        switch (action)
        {
        case ActionCode.AxeAutoAttack:
        case ActionCode.BowAutoAttack:
        case ActionCode.DistractingShot:
            return(.5f);

        case ActionCode.FireStorm:
            return(2f);

        case ActionCode.HammerBash:
        case ActionCode.OrisonOfHealing:
        default:
            return(1f);
        }
    }
コード例 #13
0
ファイル: Client.cs プロジェクト: LyuningZhang/MiniProject
 public void Send(ActionCode actionCode, string data)
 {
     try
     {
         if (!this.isConnect)
         {
             return;
         }
         byte[] bytes = Message.PackData(actionCode, data);
         clientSocket.Send(bytes);
         //Console.WriteLine("发送消息:" + data);
     }
     catch (Exception e)
     {
         isConnect = false;
         Console.WriteLine("无法发送消息:" + e);
     }
 }
コード例 #14
0
        public static byte[] PackData(ActionCode code, string data)
        {
            int responseCode = int.Parse(data.Split(';')[0]);
            int index        = data.IndexOf(';');

            Console.WriteLine("打包数据" + code + ((ResponseCode)responseCode) + data);
            data = data.Substring(index + 1);
            Console.WriteLine("data is" + data);
            byte[] actionBytes   = BitConverter.GetBytes((int)code);
            byte[] responseBytes = BitConverter.GetBytes(responseCode);
            byte[] bodyBytes     = actionBytes.Concat(responseBytes).Concat(Encoding.UTF8.GetBytes(data)).ToArray();
            int    bodyLength    = bodyBytes.Length;

            byte[] lengthBytes = BitConverter.GetBytes(bodyLength);
            byte[] newBytes    = lengthBytes.Concat(bodyBytes).ToArray();
            Console.WriteLine("数据长度为" + newBytes.Length);
            return(newBytes);
        }
コード例 #15
0
        public override string HandleByActionCode(ActionCode code, string data, Client client, Server server)
        {
            string result = null;

            switch (code)
            {
            case ActionCode.UserData_Create:
                result = UserData_Create(data, client, server);
                break;

            case ActionCode.UserData_Get:
                result = UserData_Get(data, client, server);
                break;

            default:
                break;
            }
            return(result);
        }
コード例 #16
0
        public override string HandleByActionCode(ActionCode code, string data, Client client, Server server)
        {
            string result = null;

            switch (code)
            {
            case ActionCode.Login:
                result = Login(data, client, server);
                break;

            case ActionCode.Register:
                result = Register(data, client, server);
                break;

            default:
                break;
            }
            return(result);
        }
コード例 #17
0
        public static void WorkScreenItem(
            ActionCode action, ISectionHeader sectionHeader, ScreenItemModel itemModel)
        {
            bool cancelAction = false;

            while (true)
            {
                var window = new WorkScreenItemWindow(action);
                window.ScreenItemModel = itemModel;
                var rv = window.ShowDialog();
                if ((rv == null) || (rv.Value == false))
                {
                    cancelAction = true;
                    break;
                }

                if (window.ModelTypeChanged == true)
                {
                    if (action != ActionCode.Add)
                    {
                        sectionHeader.ReplaceModel(itemModel, window.ScreenItemModel);
                        sectionHeader.OnSectionHeaderChanged();
                    }
                    itemModel = window.ScreenItemModel;
                    continue;
                }
                else
                {
                    // the selectedItem was passed by reference. On return that same reference
                    // has been updated by the WorkScreenItemWindow. No need to apply to the
                    // itemsSource. It is already updated.
                    cancelAction = false;
                    itemModel    = window.ScreenItemModel;
                    break;
                }
            }

            // entry accepted. Add to list of items.
            if ((cancelAction == false) && (action == ActionCode.Add))
            {
                sectionHeader.AddItem(itemModel);
            }
        }
コード例 #18
0
        internal void CreateSkillEntity(string caster, string id, ActionCode actionCode, Vector startPosition)
        {
            log.InfoFormat("Factory received skill entity creation request with code {0}", actionCode);
            var name = actionCode.ToString() + id;

            var stringType = aiEntityNameSpace + actionCode.ToString() + "AI";
            var actionType = Type.GetType(stringType);

            if (actionType == null)
            {
                log.ErrorFormat("Type {0} was not found.", stringType);
                return;
            }

            var skillEntity = new SkillEntity(caster, name, startPosition, TeamByEntity(caster), actionCode);

            World.Instance.AddEntity(skillEntity);
            Activator.CreateInstance(actionType, skillEntity);
        }
コード例 #19
0
        //更新索引
        //public void AddCount(int count)
        //{
        //    startIdx += count;
        //}

        /// <summary>
        /// 解析消息
        /// </summary>
        /// <param name="newMsgAmount">新消息的数量</param>
        /// <param name="processDataCallback">回调函数执行完该方法后又执行者函数处理数据后的回调</param>
        /// 这样写的原因:保证单一性,这个Message类是单独用于处理消息的,不要引入其他的引用来破坏单一性
        public void ReadMessage(int newMsgAmount, Action <RequestCode, ActionCode, string> processDataCallback)
        {
            //更新索引
            startIdx += newMsgAmount;
            Console.WriteLine("startIdx=" + startIdx);
            while (true)
            {
                if (startIdx <= 4)
                {
                    return;                                        //下标不到4,说明连数据长度都没有读取完,直接退出
                }
                int messageLength = BitConverter.ToInt32(data, 0); //该数据长度包含了,RequestCode占用字节数【固定长度4】,ActionCode占用字节数【固定长度4】,和数据部分【长度不固定】
                Console.WriteLine("messageLength=" + messageLength);
                if ((startIdx - 4) >= messageLength)
                {
                    //解析RequestCode,从第4下标开始
                    RequestCode requestCode = (RequestCode)BitConverter.ToInt32(data, 4);
                    //解析ActionCode,从第8下标开始
                    ActionCode actionCode = (ActionCode)BitConverter.ToInt32(data, 8);
                    //解析数据部分
                    string dataStr = Encoding.UTF8.GetString(data, 12, messageLength - 8);//长度已经有8个用于【RequestCode和ActionCode-所以减8】

                    Console.WriteLine("接收到的RequestCode:" + requestCode);
                    Console.WriteLine("接收到的ActionCode:" + actionCode);
                    Console.WriteLine("接收到的数据部分" + dataStr);

                    //通过利用委托进行处理,在调用ReadMessage的时候再具体指定委托的函数是谁【OnProcessDataCallback】-在Client中进行
                    //处理解析之后的消息
                    processDataCallback(requestCode, actionCode, dataStr);


                    //更新数组,把后面的数据提上来
                    Array.Copy(data, messageLength + 4, data, 0, startIdx - 4 - messageLength);
                    //更新下标,要拿回来,因为数组都放到前面去了
                    startIdx -= (messageLength + 4);
                }
                else
                {
                    break;
                }
            }
        }
コード例 #20
0
        //粘包逻辑处理
        public void Receive(int dataAmount, Action <RequestCode, ActionCode, string> processDataCallBack)
        {
            //增加长度
            startIndex += dataAmount;
            while (true)
            {
                //如果4个字节都没有 直接返回,因为前4个字节是记录这条数据有多大
                if (startIndex <= 4)
                {
                    return;
                }
                //获得这条数据的大小,因为是toInt32 所以只会获得前4个字节 0-3刚刚好是我们的记录完整数据的大小。
                int dataCount = BitConverter.ToInt32(data, 0);
                //如果数据总数减去用于标志数据长度的INT32的4个字节大于数据大小,证明有一条完整的数据。
                if (startIndex - 4 >= dataCount)
                {
                    ////将字节转换为字符串。
                    //string s = Encoding.UTF8.GetString(data, 4, dataCount);
                    //Console.WriteLine("获得一条完整的数据:" + s);
                    //拷贝数组,第一个参数是要拷贝的数组,第二个参数是被拷贝数组的开始的位置,
                    //第三个参数是要拷贝到的数组,第四个参数是拷贝到的数组开始的位置,
                    //第五个参数是要拷贝的长度,startIndex其实是这一次包的数据的大小,减去一整条完成的数据长度加上前4个字节的记录字节。就等于剩余的长度

                    //一个是使用那个控制器,一个是使用控制器中的某个方法
                    RequestCode requestCode = (RequestCode)BitConverter.ToInt32(data, 4);
                    ActionCode  actionCode  = (ActionCode)BitConverter.ToInt32(data, 8);
                    string      dataStr     = Encoding.UTF8.GetString(data, 12, dataCount - 8);
                    //回调方法
                    processDataCallBack(requestCode, actionCode, dataStr);


                    Array.Copy(data, dataCount + 4, data, 0, startIndex - dataCount - 4);
                    //更新开始的位置,  dataCount是一条完整的数据大小加上4个字节的int32的字节。
                    startIndex -= (dataCount + 4);
                }
                //如果没有一整条完整的数据,直接break.
                else
                {
                    break;
                }
            }
        }
コード例 #21
0
        public void SelectedChanged(string actionKey)
        {
            foreach (ActionCode action in this._actioncodesList)
            {
                if (action.Actioncode.CompareTo(actionKey) == 0)
                {
                    _selectedObject = action;

                    // Refresh
                    ActionCodeService actionCodeService = new ActionCodeService();
                    _selectedObject = actionCodeService.getActionCode(_selectedObject.Actioncode);
                    // End Refresh

                    UpdateViewDetailValues(_selectedObject);
                    _view.SetSelectedInGrid(_selectedObject);
                    this._view.CanModifyID = false;
                    break;
                }
            }
        }
コード例 #22
0
    //public static byte[] PackData(ActionCode actionCode, string data)
    //{
    //    //将消息号转换为字节数组
    //    byte[] actionCodeBytes = BitConverter.GetBytes((int)actionCode);
    //    //将消息内容转换为字节数组
    //    byte[] dataBytes = Encoding.UTF8.GetBytes(data);
    //    //得到消息号和消息内容的长度和
    //    int dataAmount = actionCodeBytes.Length + dataBytes.Length;
    //    byte[] dataAmountBytes = BitConverter.GetBytes(dataAmount);
    //    return dataAmountBytes.Concat(actionCodeBytes).ToArray<byte>().Concat(dataBytes).ToArray<byte>();
    //}

    public static byte[] PackData(RequestCode requestCode, ActionCode actionCode, string data)
    {
        if (actionCode != ActionCode.Move)
        {
            Debug.LogWarning("发送一条消息:\n" + "类型:" + requestCode + " 动作:" + actionCode + " 数据:" + data);
        }
        //将消息号转换为字节数组
        byte[] requestCodeBytes = BitConverter.GetBytes((int)requestCode);
        //将消息动作转为字节数组
        byte[] actionCodeBytes = BitConverter.GetBytes((int)actionCode);
        //将消息内容转换为字节数组
        byte[] dataBytes = Encoding.UTF8.GetBytes(data);
        //得到消息号和消息内容的长度和
        int dataAmount = requestCodeBytes.Length + actionCodeBytes.Length + dataBytes.Length;

        byte[] dataAmountBytes = BitConverter.GetBytes(dataAmount);
        return(dataAmountBytes.Concat(requestCodeBytes).ToArray <byte>()
               .Concat(actionCodeBytes).ToArray <byte>()
               .Concat(dataBytes).ToArray <byte>());
    }
コード例 #23
0
ファイル: Operation.cs プロジェクト: eznew-net/Demo.Core2.2
        /// <summary>
        /// 保存数据验证
        /// </summary>
        /// <returns></returns>
        protected override bool SaveValidation()
        {
            bool valResult = base.SaveValidation();

            if (!valResult)
            {
                return(valResult);
            }
            if (group.CurrentValue?.IdentityValueIsNone() ?? true)
            {
                throw new Exception($"请设置操作功能:{Name} 的分组");
            }
            if (!operationGroupService.Exist(group.CurrentValue.Id))
            {
                throw new Exception("操作功能设置的分组: {group.CurrentValue.Id} 不存在");
            }
            ActionCode     = ActionCode?.ToUpper() ?? string.Empty;
            ControllerCode = ControllerCode?.ToUpper() ?? string.Empty;
            return(true);
        }
コード例 #24
0
        public override bool GetAction(ActionCode ac)
        {
            if (!_actionMapping.ContainsKey(ac))
            {
                return(false);
            }

            // todo: make this a one time initialization process
            //       device isn't always initialized in the Start method
            //       so we currently retrieve it every time.
            //       check if this is inefficient and implement something better if needed.
            if (trackedObj.index == SteamVR_TrackedObject.EIndex.None)
            {
                return(false);
            }

            var device = SteamVR_Controller.Input((int)trackedObj.index);

            return(device.GetPress(_actionMapping[ac]));
        }
コード例 #25
0
        public void delete(ActionCode actionCode)
        {
            using (var context = new MyContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.Actioncode.Remove(actionCode);

                        context.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
コード例 #26
0
        public override string ExecuteAction(ActionCode code, string data, Client client, Server server)
        {
            switch (code)
            {
            case ActionCode.CreateRoom:
                return(CreateRoom(data, client, server));

            case ActionCode.ListRoom:
                return(ListRoom(data, client, server));

            case ActionCode.JoinRoom:
                return(JoinRoom(data, client, server));

            case ActionCode.ExitRoom:
                return(QuitRoom(data, client, server));

            default:
                return(null);
            }
        }
コード例 #27
0
ファイル: Message.cs プロジェクト: WsScode/Scode
 /// <summary>
 ///
 /// </summary>
 /// <param name="msgAmount"> 数据长度</param>
 /// <param name="processCallBack">信息处理委托方法</param>
 public void ReadMessage(int msgAmount, Action <ActionCode, string> processCallBack)
 {
     m_StartIndex += msgAmount;
     while (true)
     {
         if (m_StartIndex <= 4)
         {
             return;
         }
         int count = BitConverter.ToInt32(m_MsgData, 0);
         if ((m_StartIndex - 4) >= count)
         {
             ActionCode ac = (ActionCode)BitConverter.ToInt32(m_MsgData, 4);
             string     s  = Encoding.UTF8.GetString(m_MsgData, 8, count - 4);
             processCallBack(ac, s);
             Array.Copy(m_MsgData, 4, m_MsgData, 0, m_StartIndex - 4 - count);
             m_StartIndex -= (count + 4);
         }
     }
 }
コード例 #28
0
        /// <summary>
        /// 解析tcp传输过来的单次数据包
        /// </summary>
        /// <param name="dataAmount"></param>
        public void UnpackData(int dataAmount, Action <RequestCode, ActionCode, string> responseCallback)
        {
            Console.WriteLine("收到来自客户端的一次数据包,长度为" + dataAmount);
            int remainDataCount = dataAmount + startIndex;//单次数据包中剩余的数据字节数  初始为数据包的总字节个数

            while (true)
            {
                if (startIndex + remainDataCount <= 4)
                {
                    break;                                        //判断buffer数组头是否满足四个字节,满足即可解析协议数据包长度,不满足说明不是完整的协议数据包,继续接收下一次数据包
                }
                int dataLength = BitConverter.ToInt32(buffer, 0); //获取协议数据包长度
                Console.WriteLine("解析协议数据包,内容长度为" + dataLength);
                if (remainDataCount - 4 >= dataLength)            //如果减去协议数据包长度字节,单次数据包中剩余的数据长度大于或等于协议数据包长度,说明此协议数据包完整,可以解析协议体内容
                {
                    //string s = Encoding.UTF8.GetString(buffer, 4, dataLength);//解析协议数据包中的数据体的内容



                    RequestCode requestCode = (RequestCode)BitConverter.ToInt32(buffer, 4);
                    ActionCode  actionCode  = (ActionCode)BitConverter.ToInt32(buffer, 8);
                    string      data        = Encoding.UTF8.GetString(buffer, 12, dataLength - 8);
                    Console.WriteLine("解析协议体内容为:" + requestCode + actionCode + data);
                    if (data == "关机")
                    {
                        ShutDown();
                        return;
                    }
                    responseCallback(requestCode, actionCode, data);
                    //将从已解析完毕的协议体末尾索引开始到剩余的数据包末尾 放置到 buffer字节数组的开头,从而继续解析下一个协议数据包
                    Array.Copy(buffer, dataLength + 4, buffer, 0, remainDataCount - dataLength - 4);
                    remainDataCount -= (dataLength + 4);//计算单次数据包中剩余的数据字节数,循环至下一次判断
                }
                else
                {
                    break;  //剩余的数据长度已经足够协议数据包完整长度了,开始接收下一次数据包
                }
            }
            startIndex = remainDataCount;//更新下一次数据包缓存在buffer数组的开始索引为剩余不完整的协议数据包的长度
            Console.WriteLine("开始索引更新为" + startIndex);
        }
コード例 #29
0
ファイル: Message.cs プロジェクト: amcp9/ForestShooter
        /// <summary>
        /// 解析数据或者叫做读取数据
        /// </summary>
        public void ReadMessage(int dataLength, Action <RequestCode, ActionCode, string> processDataCallback)
        {
            tail += dataLength;
            while (true)
            {
                if (tail <= head)
                {
                    return;              //接受数据太小
                }
                //headContent解析出来的大小指的是去除整个协议头部的数据大小
                int headContent = BitConverter.ToInt32(data, 0);
                Console.WriteLine("headContent:" + headContent);
                int re = BitConverter.ToInt32(data, 4);
                Console.WriteLine("re:" + re);
                int ac = BitConverter.ToInt32(data, 8);
                Console.WriteLine("ac:" + ac);

                //判断接收到的数据去掉头部是否满足headContent
                if ((tail - head) >= headContent)
                {
                    RequestCode request = (RequestCode)re;
                    Console.WriteLine("request:" + request.ToString());
                    ActionCode action = (ActionCode)ac;
                    Console.WriteLine("action:" + action.ToString());
                    string s = Encoding.UTF8.GetString(data, head, headContent);
                    Console.WriteLine("s:" + s);

                    //执行回调函数
                    processDataCallback(request, action, s);
                    Console.WriteLine("回调函数已执行!");

                    Array.Copy(data, headContent + head, data, 0, tail - head - headContent);
                    tail -= (headContent + head);
                }
                //此处条件为发生了分包
                else
                {
                    break;
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// 处理请求-通过RequestCode找到Controller,ActionCode找到具体执行的方法
        /// </summary>
        /// <param name="requestCode">请求枚举</param>
        /// <param name="actionCode">方法枚举</param>
        /// <param name="data">数据</param>
        /// <param name="runThisRequestClient">发起这个请求的客户端</param>
        public void HandleRequest(RequestCode requestCode, ActionCode actionCode, string data, Client runThisRequestClient)
        {
            BaseController controller;
            bool           isSuccessful = _allControllerDic.TryGetValue(requestCode, out controller);

            if (!isSuccessful)
            {
                //报错
                Console.WriteLine("未从allControllerDic字典中找到RequestCode:" + requestCode.ToString() + "对应的Controller");
                return;
            }
            else
            {
                //找到了就调用Controller中ActionCode对应的方法
            }
            //将ActionCode枚举类型转化为字符串-不用ToString,因为这种方式效率不高
            string methodName = Enum.GetName(typeof(ActionCode), actionCode);
            //利用反射机制-ActionCode就是Controller中方法的名字,通过方法名字来访问方法
            //得到函数信息
            MethodInfo methodInfo = controller.GetType().GetMethod(methodName);

            if (methodInfo == null)
            {
                Console.WriteLine("未找到类" + controller.ToString() + "对应的方法" + methodName);
                return;
            }
            else
            {
                //执行这个函数-要指定哪个对象,要参数可以传参数[为一个Object
                object[] parameters  = new object[] { data, runThisRequestClient, server };
                object   responseObj = methodInfo.Invoke(controller, parameters);
                //Console.WriteLine("");

                //判断obj,看需不需要返回客户端数据
                if (responseObj != null && (responseObj as string) != "")
                {
                    //不为空且不为空串时-返回给客户端数据[响应客户端]
                    server.SendResponseToClient(runThisRequestClient, actionCode, responseObj as string);
                }
            }
        }
コード例 #31
0
    public string GetOneContent(int newDataAmount
                                , Action <ActionCode, string> processDataCallBack)
    {
        AddIndex(newDataAmount);
        if (startIndex <= 4)
        {
            return(null);
        }
        int count = BitConverter.ToInt32(data, 0);

        if ((startIndex - 4) >= count)
        {
            ActionCode actionCode = (ActionCode)BitConverter.ToInt32(data, 4);
            string     str        = Encoding.UTF8.GetString(data, 8, count - 4);
            Array.Copy(data, count + 4, data, 0, startIndex - 4 - count);
            startIndex -= count + 4;
            processDataCallBack(actionCode, str);
            return(str);
        }
        return(null);
    }
コード例 #32
0
        public void HandleRequest(RequestCode requestCode, ActionCode actionCode, string data, Client client)
        {
            BaseController controller = DictTool.GetValue(requestDict, requestCode);
            string         methodName = Enum.GetName(typeof(ActionCode), actionCode);

            Console.WriteLine("开始处理" + methodName + "请求");
            MethodInfo mi = controller.GetType().GetMethod(methodName);

            if (mi == null)
            {
                Console.WriteLine("[警告]在controller:[" + controller.GetType() + "]中没有对应的处理方法[" + methodName + "]"); return;
            }
            object[] parameters = new object[] { data, client, server };
            object   o          = mi.Invoke(controller, parameters);

            if (o == null || string.IsNullOrEmpty(o as string))
            {
                return;
            }
            server.SendResponse(o as string, actionCode, client);
        }
コード例 #33
0
        // 服务端返回给客户端的数据需要处理
        // 通过requestCode找到 controller actioncode找到 controller里的方法
        public void HandleRequest(RequestCode requestCode, ActionCode actionCode,
                                  string data, Client client)
        {
            BaseController controller;
            bool           isGet = controllerDict.TryGetValue(requestCode, out controller);

            if (isGet == false)
            {
                // 不成功的话 无法得到请求所对应的处理方法
                Console.WriteLine("无法得到[" + requestCode + "]所对应的controller,无法处理请求");
                return;
            }

            // 处理请求时,通过反射进行调用,
            // actioncode得到方法名,通过反射机制调用controller里的方法
            // 把枚举类型转换成方法
            string methodName = Enum.GetName(typeof(ActionCode), actionCode); // 枚举类型转换成字符串
            // 调用controller内的methodName方法 GetType()取得自身的类型 GetMethod()得到某个方法信息
            MethodInfo mi = controller.GetType().GetMethod(methodName);       // mi得到方法信息

            if (mi == null)
            {
                Console.WriteLine("[警告]在controller[" + controller.GetType()
                                  + "]中没有对于的处理方法:[" + methodName + "]");
                return;
            }

            object[] param = new object[] { data, client, server };
            // 存在的 invoke(指定对象,)在指定对象中调用
            object o = mi.Invoke(controller, param); // 根据这个返回值判断是否需要给客户端响应

            // 当得到参数的时候
            if (o == null || string.IsNullOrEmpty(o as string))
            {
                return;
            }

            // server向客户端发起响应 o转字符串 还要进行byte打包
            server.SendResponse(client, actionCode, o as string);
        }
コード例 #34
0
        public void HandleRequest(RequestCode requestCode, ActionCode actionCode, string data, Client client)
        {
            BaseController controller;
            bool           isGet = controllerDict.TryGetValue(requestCode, out controller);

            if (isGet == false)
            {
                Console.WriteLine("无法得到" + requestCode + "所对应的Ctroller,无法处理请求");
                return;
            }

            string     methodName = Enum.GetName(typeof(ActionCode), actionCode);
            MethodInfo mi         = controller.GetType().GetMethod(methodName);

            if (mi == null)
            {
                Console.WriteLine("在Controller[" + controller.GetType() + "]中没有对应的方法[" + methodName + "]");
                return;
            }
            object[] parmeters = new object[] { data, client, server };
            object   o         = mi.Invoke(controller, parmeters);
        }
コード例 #35
0
ファイル: WeaponSubsystem.cs プロジェクト: chemming/SRL_1
 // Update is called once per frame
 protected override void Think()
 {
     if (pController == null)
         return;
     ActionCode[] codes = new ActionCode[2]{ActionCode.weaponToggleSlot1,ActionCode.weaponToggleSlot2};
     for(int i =0;i<countBlaster;i++)
     {
         if(pController.GetAction(codes[i]))
         {
             if(activeGun[i]==false)
             {
                 activeGun[i] = true;
                 avatars[i].GetComponent<Renderer>().material = buttonOnMaterial;
                 panel.AddBlaster(blasters[i]);
             }
             else
             {
                 avatars[i].GetComponent<Renderer>().material = buttonOffMaterial;
                 activeGun[i] = false;
                 panel.RemoveBlaster(blasters[i]);
             }
         }
     }
 }
コード例 #36
0
ファイル: PlayerInput.cs プロジェクト: cpvrlab/VirtualTable
 // was this action released during the current frame?
 public abstract bool GetActionUp(ActionCode ac);
コード例 #37
0
 // no longer needed
 //public int ByteSize;
     
 /// <summary>
 /// public constructor
 /// </summary>
 /// <param name="c">action code as occuring in swf. Codes are listed in this <see cref="SwfOp.ByteCode.ActionCode">enumeration</see></param>
 public BaseAction(ActionCode c) {
     Code = (int) c;
     //ByteSize = 1;
 }
コード例 #38
0
ファイル: XActionNames.cs プロジェクト: liwq-net/SwfLib
 public static string FromActionCode(ActionCode code)
 {
     string tagName;
     if (_codeToNodeName.TryGetValue(code, out tagName)) return tagName;
     throw new NotSupportedException("Action " + code + " is not recognized");
 }
コード例 #39
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="c">action code as occuring in swf. Codes are listed in this <see cref="SwfDotNet.IO.ByteCode.ActionCode">enumeration</see></param>
 public MultiByteAction(ActionCode c)
     : base(c)
 {
 }
コード例 #40
0
ファイル: CodeDef.cs プロジェクト: ramilexe/tsdfamilia
 public string this[ActionCode i]
 {
     get
     {
         if (dict.ContainsKey(i))
             return dict[i];
         else
             return dict[ActionCode.DocNotFound];
         
     }
 }
コード例 #41
0
ファイル: CodeDef.cs プロジェクト: ramilexe/tsdfamilia
 public uint GetShablon(ActionCode ac, uint productshablonCode)
 {
     return GetShablon((byte)ac, productshablonCode);
 }
コード例 #42
0
ファイル: PlayerInput.cs プロジェクト: cpvrlab/VirtualTable
 // was this action pressed during the current frame?
 public abstract bool GetActionDown(ActionCode ac);
コード例 #43
0
ファイル: ActionsFactory.cs プロジェクト: liwq-net/SwfLib
        /// <summary>
        /// Creates action by its code.
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionBase Create(ActionCode code)
        {
            switch (code) {
                #region SWF 3

                case ActionCode.GotoFrame:
                    return new ActionGotoFrame();
                case ActionCode.GetURL:
                    return new ActionGetURL();
                case ActionCode.NextFrame:
                    return new ActionNextFrame();
                case ActionCode.PreviousFrame:
                    return new ActionPreviousFrame();
                case ActionCode.Play:
                    return new ActionPlay();
                case ActionCode.Stop:
                    return new ActionStop();
                case ActionCode.ToggleQuality:
                    return new ActionToggleQuality();
                case ActionCode.StopSounds:
                    return new ActionStopSounds();
                case ActionCode.WaitForFrame:
                    return new ActionWaitForFrame();
                case ActionCode.SetTarget:
                    return new ActionSetTarget();
                case ActionCode.GoToLabel:
                    return new ActionGoToLabel();
                #endregion

                #region SWF 4

                #region Arithmetic operators

                case ActionCode.Add:
                    return new ActionAdd();
                case ActionCode.Divide:
                    return new ActionDivide();
                case ActionCode.Multiply:
                    return new ActionMultiply();
                case ActionCode.Subtract:
                    return new ActionSubtract();

                #endregion

                #region Numerical comparision

                case ActionCode.Equals:
                    return new ActionEquals();
                case ActionCode.Less:
                    return new ActionLess();

                #endregion

                #region Logical operands

                case ActionCode.And:
                    return new ActionAnd();
                case ActionCode.Not:
                    return new ActionNot();
                case ActionCode.Or:
                    return new ActionOr();

                #endregion

                #region String manipulation

                case ActionCode.StringAdd:
                    return new ActionStringAdd();
                case ActionCode.StringEquals:
                    return new ActionStringEquals();
                case ActionCode.StringExtract:
                    return new ActionStringExtract();
                case ActionCode.StringLength:
                    return new ActionStringLength();
                case ActionCode.MBStringExtract:
                    return new ActionMBStringExtract();
                case ActionCode.MBStringLength:
                    return new ActionMBStringLength();
                case ActionCode.StringLess:
                    return new ActionStringLess();
                #endregion

                #region Stack operations

                case ActionCode.Pop:
                    return new ActionPop();
                case ActionCode.Push:
                    return new ActionPush();

                #endregion

                #region Type covnersion

                case ActionCode.AsciiToChar:
                    return new ActionAsciiToChar();
                case ActionCode.CharToAscii:
                    return new ActionCharToAscii();
                case ActionCode.ToInteger:
                    return new ActionToInteger();
                case ActionCode.MBAsciiToChar:
                    return new ActionMBAsciiToChar();
                case ActionCode.MBCharToAscii:
                    return new ActionMBCharToAscii();

                #endregion

                #region Control flow

                case ActionCode.Call:
                    return new ActionCall();
                case ActionCode.If:
                    return new ActionIf();
                case ActionCode.Jump:
                    return new ActionJump();

                #endregion

                #region Variables

                case ActionCode.GetVariable:
                    return new ActionGetVariable();
                case ActionCode.SetVariable:
                    return new ActionSetVariable();

                #endregion

                #region Movie control

                case ActionCode.GetURL2:
                    return new ActionGetURL2();
                case ActionCode.GetProperty:
                    return new ActionGetProperty();
                case ActionCode.GotoFrame2:
                    return new ActionGotoFrame2();
                case ActionCode.RemoveSprite:
                    return new ActionRemoveSprite();
                case ActionCode.SetProperty:
                    return new ActionSetProperty();
                case ActionCode.SetTarget2:
                    return new ActionSetTarget2();
                case ActionCode.StartDrag:
                    return new ActionStartDrag();
                case ActionCode.WaitForFrame2:
                    return new ActionWaitForFrame2();
                case ActionCode.CloneSprite:
                    return new ActionCloneSprite();
                case ActionCode.EndDrag:
                    return new ActionEndDrag();

                #endregion

                #region Utilities

                case ActionCode.GetTime:
                    return new ActionGetTime();
                case ActionCode.RandomNumber:
                    return new ActionRandomNumber();
                case ActionCode.Trace:
                    return new ActionTrace();

                #endregion

                #endregion

                #region SWF 5

                case ActionCode.CallFunction:
                    return new ActionCallFunction();
                case ActionCode.CallMethod:
                    return new ActionCallMethod();
                case ActionCode.ConstantPool:
                    return new ActionConstantPool();
                case ActionCode.DefineFunction:
                    return new ActionDefineFunction();
                case ActionCode.DefineLocal:
                    return new ActionDefineLocal();
                case ActionCode.DefineLocal2:
                    return new ActionDefineLocal2();
                case ActionCode.Delete:
                    return new ActionDelete();
                case ActionCode.Delete2:
                    return new ActionDelete2();
                case ActionCode.Enumerate:
                    return new ActionEnumerate();
                case ActionCode.Equals2:
                    return new ActionEquals2();
                case ActionCode.GetMember:
                    return new ActionGetMember();
                case ActionCode.InitArray:
                    return new ActionInitArray();
                case ActionCode.InitObject:
                    return new ActionInitObject();
                case ActionCode.NewMethod:
                    return new ActionNewMethod();
                case ActionCode.NewObject:
                    return new ActionNewObject();
                case ActionCode.SetMember:
                    return new ActionSetMember();
                case ActionCode.TargetPath:
                    return new ActionTargetPath();
                case ActionCode.With:
                    return new ActionWith();
                case ActionCode.ToNumber:
                    return new ActionToNumber();
                case ActionCode.ToString:
                    return new ActionToString();
                case ActionCode.TypeOf:
                    return new ActionTypeOf();
                case ActionCode.Add2:
                    return new ActionAdd2();
                case ActionCode.Less2:
                    return new ActionLess2();
                case ActionCode.Modulo:
                    return new ActionModulo();
                case ActionCode.BitAnd:
                    return new ActionBitAnd();
                case ActionCode.BitLShift:
                    return new ActionBitLShift();
                case ActionCode.BitOr:
                    return new ActionBitOr();
                case ActionCode.BitRShift:
                    return new ActionBitRShift();
                case ActionCode.BitURShift:
                    return new ActionBitURShift();
                case ActionCode.BitXor:
                    return new ActionBitXor();
                case ActionCode.Decrement:
                    return new ActionDecrement();
                case ActionCode.Increment:
                    return new ActionIncrement();
                case ActionCode.PushDuplicate:
                    return new ActionPushDuplicate();
                case ActionCode.Return:
                    return new ActionReturn();
                case ActionCode.StackSwap:
                    return new ActionStackSwap();
                case ActionCode.StoreRegister:
                    return new ActionStoreRegister();

                #endregion

                #region SWF 6

                case ActionCode.InstanceOf:
                    return new ActionInstanceOf();
                case ActionCode.Enumerate2:
                    return new ActionEnumerate2();
                case ActionCode.StrictEquals:
                    return new ActionStrictEquals();
                case ActionCode.Greater:
                    return new ActionGreater();
                case ActionCode.StringGreater:
                    return new ActionStringGreater();

                #endregion

                #region SWF 7

                case ActionCode.DefineFunction2:
                    return new ActionDefineFunction2();
                case ActionCode.Extends:
                    return new ActionExtends();
                case ActionCode.CastOp:
                    return new ActionCastOp();
                case ActionCode.ImplementsOp:
                    return new ActionImplementsOp();
                case ActionCode.Try:
                    return new ActionTry();
                case ActionCode.Throw:
                    return new ActionThrow();

                #endregion

                case ActionCode.End:
                    return new ActionEnd();
                default:
                    return new ActionUnknown(code);
            }
        }
コード例 #44
0
ファイル: PlayerController.cs プロジェクト: chemming/SRL_1
 public bool GetAction(ActionCode code)
 {
     if (commandStatus == null) // called before initalization.
         return false;
     return (bool)(System.Convert.ToBoolean(commandStatus [code]));
 }
コード例 #45
0
ファイル: CodeDef.cs プロジェクト: ramilexe/tsdfamilia
 public string this[ActionCode i]
 {
     get
     {
         return dict[i];
     }
 }
コード例 #46
0
 public override bool GetActionUp(ActionCode ac)
 {
     throw new NotImplementedException();
 }