Esempio n. 1
0
        /// <summary>
        /// unix 格式 FTP
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        private RemoteEntity ParseFileStructFromUnixStyleRecord(string record)
        {
            ///Assuming record style as
            /// dr-xr-xr-x   1 owner    group               0 Feb 25  2011 bussys
            RemoteEntity f          = new RemoteEntity();
            string       processstr = record.Trim();

            string flags = processstr.Substring(0, 9);

            //f.Flags = processstr.Substring(0, 9);
            f.RType = (flags[0] == 'd') ? 1 : 0;

            processstr = (processstr.Substring(11)).Trim();

            CutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //skip one part

            string owner = CutSubstringFromStringWithTrim(ref processstr, ' ', 0);
            string group = CutSubstringFromStringWithTrim(ref processstr, ' ', 0);

            CutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //skip one part

            DateTime createTime = DateTime.Now;

            var dateString = CutSubstringFromStringWithTrim(ref processstr, ' ', 8);

            DateTime.TryParse(dateString, out createTime);

            f.CreateDate = createTime.ToString();
            f.Name       = processstr; //Rest of the part is name
            return(f);
        }
Esempio n. 2
0
        public static byte[] Whoami(CommandParameter parameter)
        {
            string playername = Encoding.UTF8.GetString(parameter.Data);
            var    player     = new Player();

            updateHub.Push(new EntityNotification()
            {
                Entity = player,
                Type   = EntityNotification.ActionType.Add
            }, DefaultChannels.Simulation);

            var remotePlayer = new RemoteEntity(player);

            remotePlayer.Components.AddComponent(new PositionComponent {
                Position = new Coordinate(0, new Index3(0, 0, 78), new Vector3(0, 0, 0))
            });
            remotePlayer.Components.AddComponent(new RenderComponent {
                Name = "Wauzi", ModelName = "dog", TextureName = "texdog", BaseZRotation = -90
            }, true);
            remotePlayer.Components.AddComponent(new BodyComponent()
            {
                Mass = 50f, Height = 2f, Radius = 1.5f
            });

            Console.WriteLine(playername);

            updateHub.Push(new EntityNotification()
            {
                Entity = remotePlayer,
                Type   = EntityNotification.ActionType.Add
            }, DefaultChannels.Network);


            return(Serializer.Serialize(player, Program.ServerHandler.SimulationManager.DefinitionManager));
        }
Esempio n. 3
0
 public void Construct(
     GameLoop loop,
     [InjectOptional] ScoreManager score,
     Settings settings,
     RemoteEntity.Settings entitySettings
     )
 {
     _loop     = loop;
     _score    = score;
     _settings = settings;
     _entity   = new RemoteEntity(transform, entitySettings);
 }
 private void AddRemoteEntites(LocalEntity entity, EntityAdded added)
 {
     if (Role == InstanceRole.OWNER)
     {
         foreach (var client in _clientSims)
         {
             var remote = new RemoteEntity(entity.Id, GetRoleForSim(client.Id, added), client);
             entity.NetworkEntityAdded(remote);
         }
     }
     else
     {
         var remote = new RemoteEntity(entity.Id, GetRoleForSim(_ownerSim.Id, added), _ownerSim);
         entity.NetworkEntityAdded(remote);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Compute result of conflict between both entity
        /// </summary>
        /// <param name="localDataStore"></param>
        /// <param name="local">Value of entity in local datastore</param>
        /// <param name="remote">Value of entity in remote datastore</param>
        /// <returns>Value of entity to put in remote and local datastore</returns>
        public RemoteMergeResolution Merge(IDataStore localDataStore, object local, object remote)
        {
            LocalEntity    = (T)local;
            RemoteEntity   = (T)remote;
            LocalDataStore = localDataStore;

            var remoteMergeResolution = new RemoteMergeResolution();

            if (LocalEntity == null && RemoteEntity == null)
            {
                return(remoteMergeResolution);
            }

            if (RemoteEntity == null)
            {
                remoteMergeResolution.Insert(LocalDataStore, LocalEntity);
                return(remoteMergeResolution);
            }

            RemoteEntity.LastSyncAt = SyncSessionInfo.HighBoundaryAnchor;

            if (LocalEntity != null && LocalEntity.IsSameEntity(RemoteEntity))
            {
                LocalEntity.LastSyncAt = SyncSessionInfo.HighBoundaryAnchor;
                remoteMergeResolution.Merge(LocalDataStore, LocalEntity, RemoteEntity);
                return(remoteMergeResolution);
            }

            var duplicate = RemoteEntity.FindDuplicateEntity(LocalDataStore);

            if (duplicate != null)
            {
                duplicate.LastSyncAt = SyncSessionInfo.HighBoundaryAnchor;
                remoteMergeResolution.MergeAndKeepLocalIdentity(LocalDataStore, duplicate, RemoteEntity);
                return(remoteMergeResolution);
            }

            if (LocalEntity == null)
            {
                RemoteMergeResolution.InsertInLocal(LocalDataStore, SyncSessionInfo, RemoteEntity);
                return(remoteMergeResolution);
            }

            LocalEntity.LastSyncAt = SyncSessionInfo.HighBoundaryAnchor;
            remoteMergeResolution.MergeDistinctEntity(LocalDataStore, LocalEntity, RemoteEntity);
            return(remoteMergeResolution);
        }
Esempio n. 6
0
        /// <summary>
        /// Checks entity to see if it has timedout.
        /// </summary>
        /// <param name="re"></param>
        /// <returns></returns>
        private IEnumerator TimeoutRemoteEntity(RemoteEntity re)
        {
            while (Application.isPlaying)
            {
                float elapsedTime = Time.timeSinceLevelLoad - re.LastUpdate;
                if (elapsedTime > heartBeat)
                {
                    break;
                }
                else
                {
                    yield return(new WaitForSeconds(elapsedTime));
                }
            }

            // Entity has expired, remove it
            Debug.Log("Entity Timeout. Removing: " + re.State.Marking.ASCII);

            // Fire events
            RemoveEntity(re, true);
        }
Esempio n. 7
0
        public static byte[] Whoami(CommandParameter parameter)
        {
            var    updateHub              = TypeContainer.Get <IUpdateHub>();
            string playername             = Encoding.UTF8.GetString(parameter.Data);
            var    player                 = new Player();
            var    entityNotificationPool = TypeContainer.Get <IPool <EntityNotification> >();
            var    entityNotification     = entityNotificationPool.Get();

            entityNotification.Entity = player;
            entityNotification.Type   = EntityNotification.ActionType.Add;

            updateHub.Push(entityNotification, DefaultChannels.Simulation);
            entityNotification.Release();


            var remotePlayer = new RemoteEntity(player);

            remotePlayer.Components.AddComponent(new PositionComponent()
            {
                Position = new Coordinate(0, new Index3(0, 0, 78), new Vector3(0, 0, 0))
            });
            remotePlayer.Components.AddComponent(new RenderComponent()
            {
                Name = "Wauzi", ModelName = "dog", TextureName = "texdog", BaseZRotation = -90
            }, true);
            remotePlayer.Components.AddComponent(new BodyComponent()
            {
                Mass = 50f, Height = 2f, Radius = 1.5f
            });

            Console.WriteLine(playername);
            entityNotification        = entityNotificationPool.Get();
            entityNotification.Entity = remotePlayer;
            entityNotification.Type   = EntityNotification.ActionType.Add;

            updateHub.Push(entityNotification, DefaultChannels.Network);
            entityNotification.Release();
            return(Serializer.Serialize(player));
        }
Esempio n. 8
0
        /// <summary>
        /// Windows 格式 FTP
        /// </summary>
        /// <param name="Record"></param>
        /// <returns></returns>
        private RemoteEntity ParseFileStructFromWindowsStyleRecord(string Record)
        {
            RemoteEntity f          = new RemoteEntity();
            string       processstr = Record.Trim();
            string       dateStr    = processstr.Substring(0, 8);

            processstr = (processstr.Substring(8, processstr.Length - 8)).Trim();
            string timeStr = processstr.Substring(0, 7);

            processstr   = (processstr.Substring(7, processstr.Length - 7)).Trim();
            f.CreateDate = DateTime.Parse(dateStr + " " + timeStr, _myCultureInfo).ToString();
            if (processstr.Substring(0, 5) == "<DIR>")
            {
                f.RType    = 1;
                processstr = (processstr.Substring(5, processstr.Length - 5)).Trim();
            }
            else
            {
                processstr = processstr.Substring(processstr.IndexOf(' ')).TrimStart(' ');
            }
            f.Name = processstr;
            return(f);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new remote entity from an entity state pdu
        /// </summary>
        /// <param name="from">GameObject to use, from entity map.</param>
        /// <param name="es">The entity state pdu.</param>
        /// <returns></returns>
        private RemoteEntity CreateEntity(GameObject from, EntityState es)
        {
            GameObject   entityGO = Instantiate(from) as GameObject;
            RemoteEntity re       = entityGO.GetComponent <RemoteEntity>() ?? entityGO.AddComponent <RemoteEntity>();

            RemoteEntities.Add(es.EntityID.HashCode, re);   // Add new entity
            re.Init(es);

            // Fire events
            newEntity.Invoke(re);
            newRemoteEntity.Invoke(re);

            // Start periodic checks, if the entity is not updated within the HeartBeat duration then it will be removed from the sim.
            re.LastUpdate = Time.timeSinceLevelLoad;
            StartCoroutine(TimeoutRemoteEntity(re));

            if (remoteEntityParent != null)
            {
                entityGO.transform.parent = remoteEntityParent.transform;
            }

            return(re);
        }
Esempio n. 10
0
        /// <summary>
        /// 查看目录详情
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public List <RemoteEntity> DirectoryListDetailed(string directory)
        {
            List <RemoteEntity> listResult = new List <RemoteEntity>();

            try
            {
                _ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory);

                _ftpRequest.UseBinary  = true;
                _ftpRequest.UsePassive = true;
                _ftpRequest.KeepAlive  = true;

                _ftpRequest.Credentials = new NetworkCredential(userName, password);
                _ftpRequest.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;
                _ftpResponse            = (FtpWebResponse)_ftpRequest.GetResponse();

                _ftpStream = _ftpResponse.GetResponseStream();
                StreamReader ftpReader = new StreamReader(_ftpStream);

                string line = string.Empty;

                int fileStyle = -1;

                while (!string.IsNullOrEmpty(line = ftpReader.ReadLine()))
                {
                    if (fileStyle == -1)
                    {
                        fileStyle = GetFileListStyle(line);
                    }

                    if (fileStyle == -1)//未知格式FTP
                    {
                        continue;
                    }

                    RemoteEntity entity = null;

                    if (fileStyle == 1)
                    {
                        entity = ParseFileStructFromWindowsStyleRecord(line);
                    }
                    else
                    {
                        entity = ParseFileStructFromUnixStyleRecord(line);
                    }

                    entity.RelativePath = directory + "/" + entity.Name;
                    entity.Url          = host + "/" + directory + "/" + entity.Name;


                    listResult.Add(entity);
                }

                ftpReader.Close();
                _ftpStream.Close();
                _ftpResponse.Close();
                _ftpRequest = null;
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex.ToString());
#endif
            }
            return(listResult);
        }
Esempio n. 11
0
 public RemotePermissionScheme AddPermissionTo(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3)
 {
     return(_client.addPermissionTo(in0, in1, in2, in3));
 }
Esempio n. 12
0
 /// <remarks/>
 public void deletePermissionFromAsync(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3, object userState) {
     if ((this.deletePermissionFromOperationCompleted == null)) {
         this.deletePermissionFromOperationCompleted = new System.Threading.SendOrPostCallback(this.OndeletePermissionFromOperationCompleted);
     }
     this.InvokeAsync("deletePermissionFrom", new object[] {
                 in0,
                 in1,
                 in2,
                 in3}, this.deletePermissionFromOperationCompleted, userState);
 }
Esempio n. 13
0
 public RemotePermissionScheme deletePermissionFrom(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3) {
     object[] results = this.Invoke("deletePermissionFrom", new object[] {
                 in0,
                 in1,
                 in2,
                 in3});
     return ((RemotePermissionScheme)(results[0]));
 }
 public void Construct(RemoteEntity.Settings entitySettings)
 {
     _entity = new RemoteEntity(transform, entitySettings);
 }
Esempio n. 15
0
 public RemotePermissionScheme DeletePermissionFrom(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3)
 {
     return(_client.deletePermissionFrom(in0, in1, in2, in3));
 }
Esempio n. 16
0
 /// <remarks/>
 public void addPermissionToAsync(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3) {
     this.addPermissionToAsync(in0, in1, in2, in3, null);
 }
Esempio n. 17
0
 public RemotePermissionScheme DeletePermissionFrom(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3)
 {
     throw new NotImplementedException();
 }
Esempio n. 18
0
 /// <remarks/>
 public void deletePermissionFromAsync(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3) {
     this.deletePermissionFromAsync(in0, in1, in2, in3, null);
 }
Esempio n. 19
0
    /// <summary>
    /// 可以优化代码结构。
    /// </summary>
    /// <param name="battlePropDic"></param>
    public void Init(Dictionary <int, BattleProp> battlePropDic)
    {
        resSvc   = ResSvc.Instance;
        timerSvc = TimerSvc.Instance;

        //初始化各管理器
        stateMgr = gameObject.AddComponent <StateMgr>();
        stateMgr.Init();

        bulletParent    = GameObject.Find("Temp/Bullets").transform;
        effectParent    = GameObject.Find("Temp/Effects").transform;
        bulletPool      = gameObject.AddComponent <ObjectPool>();
        laserBulletPool = gameObject.AddComponent <ObjectPool>();
        hitEffectPool   = gameObject.AddComponent <ObjectPool>();
        fireEffectPool  = gameObject.AddComponent <ObjectPool>();
        shellEffectPool = gameObject.AddComponent <ObjectPool>();

        //找到自己的战场参数
        foreach (var item in battlePropDic)
        {
            RoleType       roleType       = (RoleType)item.Key;
            ControllerBase controllerBase = null;
            GameObject     playerGO       = null;
            if (roleType == BattleSys.Instance.GetCurrentRoleType())
            {
                playerGO = resSvc.LoadPrefab(PathDefine.PlayerPath);
                #region 设置摄像机以及添加玩家控制器
                switch (roleType)
                {
                case RoleType.Red:
                    Camera.main.transform.position         = new Vector3(0, 1f, -30f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 0, 0);
                    break;

                case RoleType.Blue:
                    Camera.main.transform.position         = new Vector3(0, 1f, 30f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 180, 0);
                    break;

                case RoleType.Yellow:
                    Camera.main.transform.position         = new Vector3(-30, 1, 30f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 180, 0);
                    break;

                case RoleType.Green:
                    Camera.main.transform.position         = new Vector3(30, 1, 30f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 180, 0);
                    break;

                case RoleType.Purple:
                    Camera.main.transform.position         = new Vector3(-30, 1, -30f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 0, 0);
                    break;

                case RoleType.Black:
                    Camera.main.transform.position         = new Vector3(30, 1, -30f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 0, 0);
                    break;

                case RoleType.Orange:
                    Camera.main.transform.position         = new Vector3(22, 1, -5f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 0, 0);
                    break;

                case RoleType.White:
                    Camera.main.transform.position         = new Vector3(-25, 1, -5f);
                    Camera.main.transform.localEulerAngles = new Vector3(0, 0, 0);
                    break;
                }
                playerController = playerGO.AddComponent <PlayerController>();
                #endregion
                playerController.SetRoleType(roleType);
                controllerDic.Add(roleType, playerController);


                #region 设置实体数据
                playerEntity = new PlayerEntity(this, stateMgr);

                playerEntity.SetCtrl(playerController);
                playerEntity.SetBattleProps(battlePropDic.TryGet(item.Key));
                //考虑了扩展游戏到AI
                playerEntity.SetRoleType(roleType);
                playerEntity.Born();
                #endregion

                controllerBase = playerController;
            }
            else
            {
                //设置远程角色
                playerGO = resSvc.LoadPrefab(PathDefine.PlayerPath);
                if (playerGO.GetComponent <CharacterController>() != null)
                {
                    Destroy(playerGO.GetComponent <CharacterController>());
                }
                RemoteController remoteController = playerGO.AddComponent <RemoteController>();
                remoteController.SetRoleType(roleType);
                controllerDic.Add(roleType, remoteController);


                #region 设置实体数据
                RemoteEntity remoteEntity = new RemoteEntity(this, stateMgr);

                remoteEntity.SetCtrl(remoteController);
                remoteEntity.SetBattleProps(battlePropDic.TryGet(item.Key));
                //考虑了扩展游戏到AI
                //remoteEntity.SetRoleType(roleType);
                remoteEntity.Born();
                #endregion

                controllerBase = remoteController;
            }

            switch (roleType)
            {
            case RoleType.Red:
                playerGO.transform.position         = new Vector3(0, 0f, -30f);;
                playerGO.transform.localEulerAngles = new Vector3(0, 0, 0);
                playerGO.name = "Red";
                break;

            case RoleType.Blue:
                playerGO.transform.position         = new Vector3(0, 0, 30f);
                playerGO.transform.localEulerAngles = new Vector3(0, 180, 0);
                playerGO.name = "Blue";
                break;

            case RoleType.Yellow:
                playerGO.transform.position         = new Vector3(-30, 0, 30f);
                playerGO.transform.localEulerAngles = new Vector3(0, 180, 0);
                playerGO.name = "Yellow";
                break;

            case RoleType.Green:
                playerGO.transform.position         = new Vector3(30, 0, 30f);
                playerGO.transform.localEulerAngles = new Vector3(0, 180, 0);
                playerGO.name = "Green";
                break;

            case RoleType.Purple:
                playerGO.transform.position         = new Vector3(-30, 0, -30f);
                playerGO.transform.localEulerAngles = new Vector3(0, 0, 0);
                playerGO.name = "Purple";
                break;

            case RoleType.Black:
                playerGO.transform.position         = new Vector3(30, 0, -30f);
                playerGO.transform.localEulerAngles = new Vector3(0, 0, 0);
                playerGO.name = "Black";
                break;

            case RoleType.Orange:
                playerGO.transform.position         = new Vector3(22, 0, -5f);
                playerGO.transform.localEulerAngles = new Vector3(0, 0, 0);
                playerGO.name = "Orange";
                break;

            case RoleType.White:
                playerGO.transform.position         = new Vector3(-25, 0, -5f);
                playerGO.transform.localEulerAngles = new Vector3(0, 0, 0);
                playerGO.name = "White";
                break;
            }

            #region 添加枪支
            Transform  gunTrans = controllerBase.transform.Find(PathDefine.gunTransName).GetComponent <Transform>();
            GameObject go       = null;
            switch (battlePropDic.TryGet(item.Key).weapenType)
            {
            case WeapenType.Rifle:
                go      = resSvc.LoadPrefab(PathDefine.RiflePrefab);
                go.name = "Rifle";
                go.transform.SetParent(gunTrans);
                go.transform.localPosition    = new Vector3(0, 0, -0.1f);
                go.transform.localEulerAngles = Vector3.zero;
                go.transform.localScale       = Vector3.one;
                break;

            case WeapenType.Sniper:
                go      = resSvc.LoadPrefab(PathDefine.SniperPrefab);
                go.name = "Sniper";
                LineRenderer line = go.AddComponent <LineRenderer>();
                line.material   = Resources.Load <Material>("ResMaterials/Gun/Lin");
                line.startWidth = 0.3f;
                line.endWidth   = 0.3f;
                line.enabled    = false;
                lineRendererDic.Add(roleType, line);
                go.transform.SetParent(gunTrans);
                go.transform.localPosition = new Vector3(0, 0, -0.1f);
                go.transform.localRotation = Quaternion.Euler(Vector3.zero);
                go.transform.localScale    = new Vector3(0.7f, 0.7f, 0.7f);
                break;
            }
            #endregion
        }

        //设置我的武器
        playerEntity.SetPlayerWeapen();

        PECommon.Log("Init BattleMgr Done.");
    }
Esempio n. 20
0
 public static IObservable <StateChange <RemoteEntity, EntityState <RemoteAttributes> > > StateAllChangesWithCurrent(this RemoteEntity entity)
 {
     return(entity.StateAllChangesWithCurrent <RemoteEntity, EntityState <RemoteAttributes>, RemoteAttributes>());
 }
Esempio n. 21
0
 /// <remarks/>
 public System.IAsyncResult BegindeletePermissionFrom(string in0, RemotePermissionScheme in1, RemotePermission in2, RemoteEntity in3, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("deletePermissionFrom", new object[] {
             in0,
             in1,
             in2,
             in3}, callback, asyncState);
 }