示例#1
0
        public async override Task OnDisconnected(SlarkClientConnection slarkClientConnection)
        {
            if (slarkClientConnection.Client is PlayClient playClient)
            {
                var noticeBody = new Dictionary <string, object>()
                {
                    { "cmd", "conv" },
                    { "op", "members-offline" },
                };

                noticeBody["initBy"] = playClient.PeerId;

                var room = await FindRoomByClientAsync(playClient);

                if (room != null)
                {
                    noticeBody["cid"] = room.Id;
                    var player = await room.FindPlayerByClient(playClient);

                    if (player != null)
                    {
                        noticeBody["initByActor"] = player.ActorId;
                        noticeBody["master"]      = player.PeerId == room.MasterClientId;
                    }
                    var notice = new PlayNotice()
                    {
                        Body = noticeBody
                    };
                    notice.Timestamplize();
                    notice.SerializeBody();
                    await room.BroadcastAsync(notice);
                }
            }
            await base.OnDisconnected(slarkClientConnection);
        }
示例#2
0
        public override Task OnDisconnected(SlarkClientConnection slarkClientConnection)
        {
            if (slarkClientConnection.Client is TMClient client)
            {
                RoomContainer.ClientDisconnectLobby(client);
            }

            return(base.OnDisconnected(slarkClientConnection));
        }
示例#3
0
        public override SlarkContext CreateContext(SlarkClientConnection slarkClientConnection, string message)
        {
            var context = new TMContext()
            {
                Server  = this,
                Message = CreateMessage(message),
                Sender  = slarkClientConnection,
            };

            return(context);
        }
示例#4
0
        public virtual Task <PlayRoom> CreateWithConfigAsync(RoomConfig config, SlarkClientConnection connection)
        {
            var player = new StandardPlayer()
            {
                ClientConnection = connection,
                ActorId          = 1,
            };

            var room = new StandardPlayRoom(config)
            {
                MasterClientId = player.Client.PeerId,
                CreatorId      = player.Client.PeerId,
                Players        = new ConcurrentHashSet <Player>()
                {
                    { player }
                }
            };

            player.Client.RoomId = room.Id;

            Rooms.Add(room);

            return(Task.FromResult(room as PlayRoom));
        }
示例#5
0
 public override Task <SlarkClient> CreateClient(SlarkClientConnection slarkClientConnection)
 {
     return(Task.FromResult(new TMClient() as SlarkClient));
 }
示例#6
0
        public override SlarkContext CreateContext(SlarkClientConnection slarkClientConnection, string message)
        {
            var coreContext = base.CreateContext(slarkClientConnection, message);

            return(new PlayContext(coreContext));
        }
示例#7
0
 public override Task <SlarkClient> CreateClient(SlarkClientConnection slarkClientConnection)
 {
     return(Task.FromResult(new StandardPlayClient()
     {
     } as SlarkClient));
 }