Esempio n. 1
0
        public async override Task ExecuteAsync(SlarkContext context)
        {
            var request = context.Message as PlayRequest;

            if (context.Server is PlayGameServer gameServer)
            {
                request.TryGet <string>("cid", "", out string cid);
                gameServer.Rooms.TryGet(r => r.Id == cid, out PlayRoom room);

                if (room != null)
                {
                    context.HasNotice = true;
                    var tuple = await room.NewPlayerJoinAsync(request, context.Sender);

                    context.Response = tuple.Item1.MetaText;
                    context.Notice   = tuple.Item2.MetaText;

                    context.Receivers = room.AvailableConnections;
                }
            }
            else if (context.Server is PlayLobbyServer lobby)
            {
                var responseBody = new Dictionary <string, object>()
                {
                    { "cmd", this.Command },
                    { "op", "added" },
                    { "i", request.CommandId },
                };

                var joinRequest = JsonConvert.DeserializeObject <RoomJoinRequest>(request.MetaText);

                var tuple = await lobby.MatchAsync(joinRequest);

                if (tuple.Item1 != null)
                {
                    var gs = tuple.Item1;
                    responseBody.Add("addr", gs.ClientConnectionUrl);
                    responseBody.Add("secureAddr", gs.ClientConnectionUrl);
                }

                if (tuple.Item2 != null)
                {
                    var room = tuple.Item2;
                    responseBody.Add("cid", room.Id);
                    responseBody.Add("open", room.IsOpen);
                    responseBody.Add("m", room.MemberIds);
                    responseBody.Add("memberIds", room.ActorIds);
                    responseBody.Add("visible", room.IsVisible);
                    responseBody.Add("maxMembers", room.MaxPlayerCount);
                }

                var response = new PlayResponse(responseBody);
                response.Timestamplize();
                response.SerializeBody();

                context.Response = response.MetaText;
            }
        }
Esempio n. 2
0
        public override Task ExecuteAsync(SlarkContext context)
        {
            var request      = context.Message as PlayRequest;
            var responseBody = new Dictionary <string, object>()
            {
                { "cmd", this.Command },
                { "op", "updated" },
                { "i", request.CommandId },
            };

            if (request.Body.ContainsKey("casAttr") || request.Body.ContainsKey("attr"))
            {
                context.HasNotice = true;
            }

            var response = new PlayResponse(responseBody);

            response.Timestamplize();
            response.SerializeBody();

            return(Task.FromResult(response.MetaText));
        }