예제 #1
0
        public Task <int> Join(TableUser_Data user)
        {
            var iret = 1;

            if (!CanJoin())
            {
                iret = -2;//人数已满
                return(Task.FromResult(iret));
            }
            if (HasPlayer(user.Id))
            {
                iret = 2; //已加入
                return(Task.FromResult(iret));
            }

            if (m_TableRoomInfo.RoomOwnerId == string.Empty)
            {
                m_TableRoomInfo.RoomOwnerId = user.Id;
            }
            user.RoomId = m_TableRoomInfo.Id;
            m_TableRoomInfo.Ls_User.Add(user);

            Log.Debug($"{user.Id}加入房间:{m_TableRoomInfo.Id}");
            return(Task.FromResult(iret));
        }
예제 #2
0
        public async Task <int> Join(TableUser_Data user_data)
        {
            var        iret = 1;
            ITableRoom tr   = null;

            var roomid = GetUserRoomId(user_data.Id);

            if (roomid != null)
            {
                user_data.RoomId = roomid;
                //iret = -2;//已经在别的房间
                //return iret;
            }

            /*
             * var tu_data = GetTableUser_Data(user_data.Id);  //this.GetITableUser(user_data.Id);
             * if(tu_data == null)
             * {
             *  AddTableUser_Data(user_data);
             * }*/

            if (user_data.RoomId == string.Empty)
            {
                tr = await CreateTableRoom();
            }
            else
            {
                tr = GetTableRoom(user_data.RoomId);
                if (tr != null)
                {
                    iret = 2;//已经在房间中
                    return(iret);
                }
                else
                {
                    tr = await CreateTableRoom();
                }
            }

            iret = await tr.Join(user_data);

            if (iret > 0)
            {
                var trinfo = await tr.GetTableRoomInfo();

                SetUserRoomId(user_data.Id, trinfo.Id);
            }

            return(iret);
        }