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


C# RequestContext.SendValue方法代码示例

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


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

示例1: onGetListGames

 private Task onGetListGames(RequestContext<IScenePeerClient> ctx)
 {
     m_log.Debug("Lobby", "Client (id : " + ctx.RemotePeer.Id + ") with player name : \"" + m_players[ctx.RemotePeer].Name + "\" fetch games infos");
     try
     {
         ctx.SendValue(m_games);
     }
     catch (Exception)
     {
         ctx.SendValue(null);
     }
     return Task.FromResult(true);
 }
开发者ID:songotony,项目名称:RTypeStormancer,代码行数:13,代码来源:RTypeMainLobby.cs

示例2: OnGetShipKillCount

        private Task OnGetShipKillCount(RequestContext<IScenePeerClient> request)
        {
            request.SendValue(s =>
            {
                s.Write(BitConverter.GetBytes(this._deathCount), 0, 8);
                s.Write(BitConverter.GetBytes(this._scene.GetComponent<IEnvironment>().Clock), 0, 8);
            });

            return Task.FromResult(true);
        }
开发者ID:LaurentQUERSIN,项目名称:boids-demo,代码行数:10,代码来源:GameScene.cs

示例3: 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

示例4: onTest

 private Task onTest(RequestContext<IScenePeerClient> ctx)
 {
     ctx.SendValue("");
     return Task.FromResult(true);
 }
开发者ID:LaurentQUERSIN,项目名称:test_latence_RPC-server,代码行数:5,代码来源:testserver.cs

示例5: OnGetUsersInfos

    Task OnGetUsersInfos(RequestContext<IScenePeerClient> ctx)
    {
        var users = new List<ChatUserInfo>();

        foreach(ChatUserInfo user in _UsersInfos.Values)
        {
            users.Add(user);
        }

        ctx.SendValue<List<ChatUserInfo>>(users);

        return Task.FromResult(true);
    }
开发者ID:LaurentQUERSIN,项目名称:The-Interpolator---server,代码行数:13,代码来源:ChatServer.cs

示例6: 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

示例7: OnRpcPing

 private Task OnRpcPing(RequestContext<IScenePeerClient> reqCtx)
 {
     reqCtx.SendValue((ulong)_scene.GetComponent<IEnvironment>().Clock);
     return Task.FromResult(true);
 }
开发者ID:antlafarge,项目名称:stormancer-tester,代码行数:5,代码来源:TesterBehavior.cs

示例8: OnRpc

        // process the RPC server, send back the data, and start a RPC client
        private async Task OnRpc(RequestContext<IScenePeerClient> reqCtx)
        {
            _scene.GetComponent<ILogger>().Info("rpc", "RPC request received");

            // copy the RPC data
            var copyStream = new MemoryStream();
            reqCtx.InputStream.CopyTo(copyStream);
            
            // cancellation
            reqCtx.CancellationToken.Register(() =>
            {
                _scene.GetComponent<ILogger>().Info("rpcservercancelled", "RPC on server request cancelled");
                reqCtx.RemotePeer.Send("rpcservercancelled", s =>
                {
                    copyStream.Seek(0, SeekOrigin.Begin);
                    copyStream.CopyTo(s);
                }, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE_ORDERED);
            });

            await Task.Delay(1000);

            // if not cancelled, send back the data
            reqCtx.SendValue(s =>
            {
                copyStream.Seek(0, SeekOrigin.Begin);
                copyStream.CopyTo(s);
            });

            // create an async task for the RPC client
            _queue.Enqueue(Task.Run(async () =>
            {
                await Task.Delay(1000);
                var observable = reqCtx.RemotePeer.Rpc("rpc", s =>
                {
                    copyStream.Seek(0, SeekOrigin.Begin);
                    copyStream.CopyTo(s);
                }).Subscribe((p) =>
                {
                    _scene.GetComponent<ILogger>().Warn("rpc", "RPC on client should be cancelled, but a response has been received");
                });

                if (reqCtx.CancellationToken.IsCancellationRequested)
                {
                    observable.Dispose();
                }
            }));
        }
开发者ID:antlafarge,项目名称:stormancer-tester,代码行数:48,代码来源:TesterBehavior.cs

示例9: UseSkill

 private async Task UseSkill(RequestContext<IScenePeerClient> args)
 {
     string errorMsg = null;
     if (!await UseSkillImpl(args))
     {
         args.SendValue(new UseSkillResponse { error = true, errorMsg = errorMsg });
     }
 }
开发者ID:LaurentQUERSIN,项目名称:boids-demo,代码行数:8,代码来源:GameScene.cs

示例10: 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

示例11: 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

示例12: 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

示例13: OnRequestObjects

        public Task OnRequestObjects(RequestContext<IScenePeer> ctx)
        {
           List<ReplicatorDTO> dtos = new List<ReplicatorDTO>();

            foreach(StormancerNetworkIdentity ni in LocalObjectToSync)
            {
                ReplicatorDTO dto = new ReplicatorDTO();

                dto.Id = ni.Id;
                dto.PrefabId = ni.PrefabId;
                dto.ClientId = ClientProvider.GetClientId(); ;

                dtos.Add(dto);
            }
            ctx.SendValue<List<ReplicatorDTO>>(dtos);
            Debug.Log("receiving objects for new player. Sent " + dtos.Count + " objects.");
            return TaskHelper.FromResult(true);
        }
开发者ID:LaurentQUERSIN,项目名称:The-interpolator---client,代码行数:18,代码来源:ReplicatorBehaviour.cs

示例14: OnUpdateLeaderBoard

        // onUpdateLeaderBoard is a rpc resqponse procedure handling the "update_leaderboard" rpc request sent by a client
        // We receive nothing (null) and send a leaderboard data transfert object containing the leaderboard informations to be displayed by the client.
        //
        private Task OnUpdateLeaderBoard(RequestContext<IScenePeerClient> ctx)
        {
            List<Player> playerList = _players.Values.ToList();
            LeaderBoardDtO board = new LeaderBoardDtO();

            playerList.OrderByDescending(x => x.record);

            int i = 0;
            while (i < playerList.Count && i < 5)
            {
                board.names[i] = playerList[i].name;
                board.scores[i] = playerList[i].record.ToString();
                i++;
            }
            while (i < 5)
            {
                board.names[i] = "";
                board.scores[i] = "";
                i++;
            }
            if (_players.ContainsKey(ctx.RemotePeer.Id))
            {
                board.localNbr = _players[ctx.RemotePeer.Id].score.ToString();
            }
            ctx.SendValue(board);
            return Task.FromResult(true);
        }
开发者ID:LaurentQUERSIN,项目名称:Pop-The-Balls,代码行数:30,代码来源:ServerLogic.cs

示例15: OnClick

        // OnClick is a reponse procedure handling the "click" rpc request sent by a client
        // We receive a Stream containing click information sent by a client and send back a stream telling the player whether he touched a ball or not and his life.
        // If a ball have been hit, the server telle very client to destory it.
        //
        private Task OnClick(RequestContext<IScenePeerClient> ctx)
        {
            Player player;
            if (_players.TryGetValue(ctx.RemotePeer.Id, out player))
            {
                //bool hitGoodBall = false;
               // bool touched = false;
                var reader = new BinaryReader(ctx.InputStream);
                float x = reader.ReadSingle();
                float y = reader.ReadSingle();
                long timestamp = reader.ReadInt32();

                Ball temp;
                Ball hitBall = null;

                bool hitGoodBall = TryFindHitBall(x,y,timestamp, out hitBall);
                
                if (hitBall != null)
                {
                    if (hitGoodBall)
                    {
                        player.score++;
                        player.streak++;
                        if (player.score > player.record)
                            player.record = player.score;
                        if (player.streak >= 5)
                        {
                            player.streak = 0;
                            player.Life++;
                            if (player.Life > 3)
                                player.Life = 3;
                            ctx.SendValue(s => 
                            {
                                var writer = new BinaryWriter(s, Encoding.UTF8, false);
                                writer.Write(3);
                                writer.Write(player.Life);
                            });
                        }
                        else
                            ctx.SendValue(s => { var writer = new BinaryWriter(s, Encoding.UTF8, false); writer.Write(1); });
                        _scene.Broadcast("destroy_ball", s =>
                        {
                            var writer = new BinaryWriter(s, Encoding.UTF8, false);
                            writer.Write(hitBall.id);
                        }, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE_SEQUENCED);
                        _balls.TryRemove(hitBall.id, out temp);
                    }
                    else
                    {
                        player.streak = 0;
                        player.Life--;
                        ctx.SendValue(s => 
                        {
                            var writer = new BinaryWriter(s, Encoding.UTF8, false);
                            writer.Write(2);
                            writer.Write(_players[ctx.RemotePeer.Id].Life);
                        });
                        _scene.Broadcast("destroy_ball", s =>
                        {
                            var writer = new BinaryWriter(s, Encoding.UTF8, false);
                            writer.Write(hitBall.id);
                        }, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE_SEQUENCED);
                        _balls.TryRemove(hitBall.id, out temp);
                        if (_players[ctx.RemotePeer.Id].Life <= 0)
                        {
                            _players[ctx.RemotePeer.Id].Life = 3;
                            _players[ctx.RemotePeer.Id].score = 0;
                        }
                    }
                }
                if (hitBall == null)
                    ctx.SendValue(s => { var writer = new BinaryWriter(s, Encoding.UTF8, false); writer.Write(0); });
            }
            return Task.FromResult(true);
        }
开发者ID:LaurentQUERSIN,项目名称:Pop-The-Balls,代码行数:79,代码来源:ServerLogic.cs


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