当前位置: 首页>>代码示例>>C#>>正文


C# RequestContext.ReadObject方法代码示例

本文整理汇总了C#中RequestContext.ReadObject方法的典型用法代码示例。如果您正苦于以下问题:C# RequestContext.ReadObject方法的具体用法?C# RequestContext.ReadObject怎么用?C# RequestContext.ReadObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RequestContext的用法示例。


在下文中一共展示了RequestContext.ReadObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnGetShipInfos

        private Task OnGetShipInfos(RequestContext<IScenePeerClient> arg)
        {

            var shipIds = arg.ReadObject<ushort[]>();

            var ships = new List<ShipCreatedDto>(shipIds.Length);
            foreach (var id in shipIds)
            {
                Ship ship;
                if (_ships.TryGetValue(id, out ship))
                {
                    ships.Add(new ShipCreatedDto { timestamp = _scene.GetComponent<IEnvironment>().Clock, id = ship.id, team = ship.team, x = ship.x, y = ship.y, rot = ship.rot, weapons = ship.weapons, status = ship.Status });
                }
            }

            arg.SendValue(ships);
            return Task.FromResult(true);

        }
开发者ID:LaurentQUERSIN,项目名称:boids-demo,代码行数:19,代码来源:GameScene.cs

示例2: onJoinGame

        private Task onJoinGame(RequestContext<IScenePeerClient> packet)
        {
            GameInfos game = packet.ReadObject<GameInfos>();

            game = m_games.Find(npc => { return (npc.IDOwner == game.IDOwner); });
            if (game.Playing || game.IDPlayers.Count == game.MaxPlayer)
            {
                packet.SendValue(null);
                return Task.FromResult(true);
            }
            game.IDPlayers[packet.RemotePeer.Id] = m_players[packet.RemotePeer];
            foreach (IScenePeerClient client in m_scene.RemotePeers)
                foreach (long key in game.IDPlayers.Keys)
                    if (client.Id == key && key != packet.RemotePeer.Id)
                        client.Send("UpdateGame", game);
            packet.SendValue(game);
            return Task.FromResult(true);
        }
开发者ID:songotony,项目名称:RTypeStormancer,代码行数:18,代码来源:RTypeMainLobby.cs

示例3: OnRegisterObject

        public Task OnRegisterObject(RequestContext<IScenePeerClient> ctx)
        {
            _log.Debug("replicator", "registering object");
            var dto = ctx.ReadObject<ReplicatorDTO>();
            var obj = new ReplicatorObject();

            obj.Client = ctx.RemotePeer;
            obj.PrefabId = dto.PrefabId;
            obj.Id = Ids++;

            dto.Id = obj.Id;

            ctx.SendValue<ReplicatorDTO>(dto);

            foreach(IScenePeerClient client in _scene.RemotePeers)
            {
                if (client.Id != ctx.RemotePeer.Id)
                {
                    client.Send<ReplicatorDTO>("CreateObject", dto);
                }
            }
            return Task.FromResult(true);
        }
开发者ID:LaurentQUERSIN,项目名称:The-Interpolator---server,代码行数:23,代码来源:ReplicatorBehaviour.cs

示例4: UseSkillImpl

        private async Task<bool> UseSkillImpl(RequestContext<IScenePeerClient> arg)
        {

            var env = _scene.GetComponent<IEnvironment>();
            var p = arg.ReadObject<UserSkillRequest>();
            var ship = _ships[_players[arg.RemotePeer.Id].ShipId];

            if (ship.Status != ShipStatus.InGame || ship.currentPv <= 0)
            {
                return false;
                //throw new ClientException("You can only use skills during games.");
            }

            var timestamp = _scene.GetComponent<IEnvironment>().Clock;
            var weapon = ship.weapons.FirstOrDefault(w => w.id == p.skillId);
            if (weapon == null)
            {
                return false;
                //throw new ClientException(string.Format("Skill '{0}' not available.", p.skillId));
            }

            if (weapon.fireTimestamp + weapon.coolDown > timestamp)
            {
                return false;
                //throw new ClientException("Skill in cooldown.");
            }
            if (!_ships.ContainsKey(p.target))
            {
                return false;
            }

            var target = _ships[p.target];
            if (target.Status != ShipStatus.InGame)
            {
                return false;
                //throw new ClientException("Can only use skills on ships that are in game.");
            }
            var dx = ship.x - target.x;
            var dy = ship.y - target.y;
            if (weapon.range * weapon.range < dx * dx + dy * dy)
            {
                return false;
                //throw new ClientException("Target out of range.");
            }

            weapon.fireTimestamp = timestamp;
            var success = _rand.Next(100) < weapon.precision * 100;
            if (success)
            {
                if (target.currentPv > 0)
                {
                    target.ChangePv(-weapon.damage);
                }
            }

            this.RegisterSkill(ship.id, target.id, success, weapon.id, timestamp);

            arg.SendValue(new UseSkillResponse { error = false, errorMsg = null, skillUpTimestamp = weapon.fireTimestamp + weapon.coolDown, success = success });
            return true;
        }
开发者ID:LaurentQUERSIN,项目名称:boids-demo,代码行数:60,代码来源:GameScene.cs

示例5: CreateAccount

        private async Task CreateAccount(RequestContext<IScenePeerClient> p, ISceneHost scene)
        {
            try
            {
                var userService = scene.GetComponent<IUserService>();
                var rq = p.ReadObject<CreateAccountRequest>();

                scene.GetComponent<ILogger>().Log(LogLevel.Trace, "user.provider.loginpassword", "Creating user " + rq.Login + ".", rq.Login);
                ValidateLoginPassword(rq.Login, rq.Password);

                var user = await userService.GetUserByClaim(PROVIDER_NAME, "login", rq.Login);

                if (user != null)
                {
                    scene.GetComponent<ILogger>().Log(LogLevel.Trace, "user.provider.loginpassword", "User with login " + rq.Login + " already exists.", rq.Login);

                    throw new ClientException("An user with this login already exist.");
                }

                user = await userService.GetUser(p.RemotePeer);
                if (user == null)
                {
                    try
                    {
                        var uid = PROVIDER_NAME + "-" + rq.Login;
                        user = await userService.CreateUser(uid, JObject.Parse(rq.UserData));
                    }
                    catch (Exception ex)
                    {
                        scene.GetComponent<ILogger>().Log(LogLevel.Trace, "user.provider.loginpassword", "Couldn't create user " + rq.Login + ".", ex);

                        throw new ClientException("Couldn't create account : " + ex.Message);
                    }
                }

                var salt = GenerateSaltValue();

                try
                {
                    await userService.AddAuthentication(user, PROVIDER_NAME, JObject.FromObject(new
                    {
                        login = rq.Login,
                        email = rq.Email,
                        salt = salt,
                        password = HashPassword(rq.Password, salt),
                        validated = false,
                    }));
                }
                catch (Exception ex)
                {
                    scene.GetComponent<ILogger>().Log(LogLevel.Trace, "user.provider.loginpassword", "Couldn't link account " + rq.Login + ".", ex);

                    throw new ClientException("Couldn't link account : " + ex.Message);
                }

                scene.GetComponent<ILogger>().Log(LogLevel.Trace, "user.provider.loginpassword", "Creating user " + rq.Login + ".", rq.Login);
                p.SendValue(new LoginResult
                {
                    Success = true
                });


            }
            catch (Exception ex)
            {
                p.SendValue(new LoginResult { ErrorMsg = ex.Message, Success = false });
            }
        }
开发者ID:Falanwe,项目名称:Stormancer-AuthenticationPlugin,代码行数:68,代码来源:LoginPasswordAuthenticationProvider.cs

示例6: OnPlay

        // OnPlay is a response procedure handling the "play" rpc request sent by a client
        // An Rpc response procedure is created by server when an rpc request is received. These are totaly asynchronous so it can handle multiple rpc at the same time.
        // Here, we receive a Connection Data Transfert Object and send back an int to tell the client whether he can play or not.
        //
        private Task OnPlay(RequestContext<IScenePeerClient> ctx)
        {
            // we use RequestContext.ReadObject<Type>() to deserialize to data received from the Client.
            string name = ctx.ReadObject<ConnectionDtO>().name.ToLower();
            bool nameAlreadyTaken = false;

            foreach (var p in _players.Values)
            {
                string temp = p.name.ToLower();
                if (temp == name)
                {
                    nameAlreadyTaken = true;
                    break;
                }
            }
            if (nameAlreadyTaken == false)
            {
                var player = new Player(name);
                _log.Debug("main", "client joined with name : " + player.name);
                _players.TryAdd(ctx.RemotePeer.Id, player);
                ctx.SendValue(0);
            }
            else
            {
                ctx.SendValue(1);
            }
            return Task.FromResult(true);
        }
开发者ID:LaurentQUERSIN,项目名称:Pop-The-Balls,代码行数:32,代码来源:ServerLogic.cs


注:本文中的RequestContext.ReadObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。