Пример #1
0
        public async Task JoinChat(JoinOrCreateRoomMesg mesg)
        {
            //获取房间
            this.room = RoomManager.GetRoom(mesg.RoomName);

            if (room == null)
            {
                Console.WriteLine($"no Room {mesg.RoomName}");
                return;
            }

            await this.room.AddAsync(Context);

            var count = await room.GetMemberCountAsync();

            Console.WriteLine("Current Chat Player Count: " + count);

            //保存名字
            me = mesg.UserName;

            //广播消息:加入房间
            Broadcast(room).OnJoinChat(mesg);

            Console.WriteLine($"{mesg.UserName} Join {mesg.RoomName} Chat. {mesg.RoomName} Chat Player Count : {count}");
        }
Пример #2
0
        public async Task JoinOrCreateRoom(string roomName, string playerName)
        {
            #region 因为Context的不一样,导致广播调用不到函数,所以其他hub必须加入Context才行,所以先只是创建而已,等作者添加支持

            var result = RoomManager.GetRoom(roomName, out _room);

            if (result)
            {
                await RoomManager.JoinRoom(_room, Context);
            }
            else
            {
                _room = await Group.AddAsync(roomName);

                RoomManager.AddRoom(_room);
            }

            _playerName = playerName;

            #endregion

            Broadcast(_room).OnJoinRoom(playerName);

            Console.WriteLine($"{playerName} Join {roomName} Room.");
        }
Пример #3
0
        public async Task Init(PlayerControlInitMesg mesg)
        {
            var result = RoomManager.GetRoom(mesg.RoomName, out _room);

            if (result)
            {
                await _room.AddAsync(Context);
            }
        }
Пример #4
0
        public async UnaryResult <int> GetRoomPlayerCount(string roomName)
        {
            var room = RoomManager.GetRoom(roomName);

            if (room != null)
            {
                var count = await room.GetMemberCountAsync();

                return(count);
            }

            return(-1);
        }