예제 #1
0
파일: GameTable.cs 프로젝트: zhukaixy/Scut
 private GameTable()
 {
     _cardRole     = new CardRole();
     _pokerConfig  = new ShareCacheStruct <PokerInfo>();
     _userCacheSet = new GameDataCacheSet <GameUser>();
     _roomStruct   = new MemoryCacheStruct <RoomData>();
 }
예제 #2
0
 private GameTable()
 {
     _cardRole = new CardRole();
     _pokerConfig = new ShareCacheStruct<PokerInfo>();
     _userCacheSet = new GameDataCacheSet<GameUser>();
     _roomStruct = new MemoryCacheStruct<RoomData>();
 }
예제 #3
0
        protected override void TakeRemote()
        {
            var session = paramGetter.GetSession();

            if (session == null)
            {
                ErrorCode = 10000;
                ErrorInfo = "Sessin is null.";
                return;
            }

            switch (_type)
            {
            case NoticeMode.AllService:
            {
                var sessionlist = GameSession.GetAll();
                foreach (var on in sessionlist)
                {
                    if (on.Connected && !on.IsRemote)
                    {
                        MsgData data = new MsgData();
                        data.Type   = MsgType.Notice;
                        data.UserId = on.UserId;

                        var parameters = new Parameters();
                        parameters["Type"]     = NoticeMode.AllService;
                        parameters["ServerID"] = _serverID;
                        parameters["Content"]  = _content;
                        data.Param             = parameters;
                        MsgDispatcher.Push(data);
                    }
                }
            }
            break;

            case NoticeMode.World:
            {
                var cache = new MemoryCacheStruct <ChatUser>();
                var list  = cache.FindAll(t => t.ServerID == _serverID);
                foreach (var v in list)
                {
                    var sess = GameSession.Get(v.UserId);
                    if (sess != null && sess.Connected && !sess.IsRemote)
                    {
                        MsgData data = new MsgData();
                        data.Type   = MsgType.Notice;
                        data.UserId = sess.UserId;

                        var parameters = new Parameters();
                        parameters["Type"]     = NoticeMode.World;
                        parameters["ServerID"] = _serverID;
                        parameters["Content"]  = _content;
                        data.Param             = parameters;
                        MsgDispatcher.Push(data);
                    }
                }
            }
            break;
            }
        }
예제 #4
0
 private string GetUserName(int userId)
 {
     var cache = new MemoryCacheStruct<ChatUser>();
     ChatUser user;
     if (cache.TryGet(userId.ToString(), out user))
     {
         return user.UserName;
     }
     return string.Empty;
 }
예제 #5
0
 private ChatUser GetUser(int userId)
 {
     var cache = new MemoryCacheStruct<ChatUser>();
     ChatUser chatUser;
     if (cache.TryGet(userId.ToString(), out chatUser))
     {
         return chatUser;
     }
     return null;
 }
예제 #6
0
        private ChatUser GetUser(int userId)
        {
            var      cache = new MemoryCacheStruct <ChatUser>();
            ChatUser chatUser;

            if (cache.TryGet(userId.ToString(), out chatUser))
            {
                return(chatUser);
            }
            return(null);
        }
예제 #7
0
        private string GetUserName(int userId)
        {
            var      cache = new MemoryCacheStruct <ChatUser>();
            ChatUser user;

            if (cache.TryGet(userId.ToString(), out user))
            {
                return(user.UserName);
            }
            return(string.Empty);
        }
예제 #8
0
파일: GameRoom.cs 프로젝트: kehaoran74/Scut
 static GameRoom()
 {
     _instance = new GameRoom();
     var roomStruct = new MemoryCacheStruct<RoomData>();
     var roomList = new ShareCacheStruct<RoomInfo>().FindAll(false);
     foreach (var roomInfo in roomList)
     {
         var roomData = new RoomData() { RoomId = roomInfo.Id };
         string key = roomData.RoomId.ToString();
         roomStruct.TryAdd(key, roomData);
     }
 }
예제 #9
0
        protected override bool DoSuccess(int userId, out IUser user)
        {
            user = null;
            var      cache    = new MemoryCacheStruct <ChatUser>();
            ChatUser chatUser = cache.Find(t => t.UserName == _userName);

            if (chatUser != null)
            {
                user = chatUser;
                return(true);
            }
            return(false);
        }
예제 #10
0
        protected override void OnDisconnected(GameSession session)
        {
            var user = session.User as SessionUser;

            if (user != null)
            {
                var      cache    = new MemoryCacheStruct <ChatUser>();
                ChatUser chatUser = cache.Find(t => t.UserId == user.UserId);
                if (chatUser != null && session.SessionId == chatUser.SessionId)
                {
                    cache.TryRemove(user.UserId.ToString());
                }
            }

            base.OnDisconnected(session);
        }
예제 #11
0
        static GameRoom()
        {
            _instance = new GameRoom();
            var roomStruct = new MemoryCacheStruct <RoomData>();
            var roomList   = new ShareCacheStruct <RoomInfo>().FindAll(false);

            foreach (var roomInfo in roomList)
            {
                var roomData = new RoomData()
                {
                    RoomId = roomInfo.Id
                };
                string key = roomData.RoomId.ToString();
                roomStruct.TryAdd(key, roomData);
            }
        }
예제 #12
0
 public bool CheckLogin()
 {
     var cache = new MemoryCacheStruct<ChatUser>();
     ChatUser chatUser = cache.Find(t => t.UserName == PassportID);
     if (chatUser != null)
     {
         UserID = chatUser.UserId.ToString();
         return true;
     }
     //not user create it.
     chatUser = new ChatUser()
     {
         UserId = (int)RedisConnectionPool.GetNextNo(typeof(ChatUser).FullName),
         UserName = PassportID,
         AccessTime = DateTime.Now
     };
     if (cache.TryAdd(chatUser.UserId.ToString(), chatUser))
     {
         UserID = chatUser.UserId.ToString();
         return true;
     }
     return false;
 }
예제 #13
0
        public override bool TakeAction()
        {
            SessionUser user = null;

            try
            {
                var      cache    = new MemoryCacheStruct <ChatUser>();
                ChatUser chatUser = cache.Find(t => t.UserId == _userId);

                if (chatUser == null)
                {
                    chatUser = new ChatUser()
                    {
                        UserId    = _userId,
                        SessionId = Current.SessionId,
                        GuildID   = string.Empty
                    };
                    cache.TryAdd(_userId.ToString(), chatUser);
                }

                user = new SessionUser()
                {
                    PassportId = _userId.ToString(), UserId = _userId
                };
                Current.Bind(user);

                return(true);
            }
            catch (Exception ex)
            {
                SaveLog(ex);
                ErrorCode = Language.Instance.ErrorCode;
                ErrorInfo = Language.Instance.ValidateError;
                return(false);
            }
        }
예제 #14
0
        protected override void TakeRemote()
        {
            var session = paramGetter.GetSession();

            if (session == null)
            {
                ErrorCode = 10000;
                ErrorInfo = "Sessin is null.";
                return;
            }

            var      cache    = new MemoryCacheStruct <ChatUser>();
            ChatUser chatUser = cache.Find(t => t.UserId == _userId);

            if (chatUser != null)
            {
                chatUser.UserName   = _userName;
                chatUser.VipLv      = _vipLv;
                chatUser.Profession = _profession;
                chatUser.AvatarUrl  = _avatarUrl;
                chatUser.ServerID   = _serverID;
                chatUser.GuildID    = _guildID;
            }
        }
예제 #15
0
        public bool CheckLogin()
        {
            var      cache    = new MemoryCacheStruct <ChatUser>();
            ChatUser chatUser = cache.Find(t => t.UserName == PassportID);

            if (chatUser != null)
            {
                UserID = chatUser.UserId.ToString();
                return(true);
            }
            //not user create it.
            chatUser = new ChatUser()
            {
                UserId     = (int)RedisConnectionPool.GetNextNo(typeof(ChatUser).FullName),
                UserName   = PassportID,
                AccessTime = DateTime.Now
            };
            if (cache.TryAdd(chatUser.UserId.ToString(), chatUser))
            {
                UserID = chatUser.UserId.ToString();
                return(true);
            }
            return(false);
        }
예제 #16
0
 /// <summary>
 /// 房间
 /// </summary>
 private GameRoom()
 {
     _roomStruct = new MemoryCacheStruct <RoomData>();
     _roomConfig = new ShareCacheStruct <RoomInfo>();
 }
예제 #17
0
파일: Action100.cs 프로젝트: ioying/Scut
 public Action100(HttpGet httpGet)
     : base(ActionIDDefine.Cst_Action100, httpGet)
 {
     _roomStruct = new MemoryCacheStruct <UserConnection>();
 }
예제 #18
0
        public static void InitData()
        {
            VitInit                   = ConfigEnvSet.GetInt("User.VitInit");
            VitMax                    = ConfigEnvSet.GetInt("User.VitMax");
            VitRestore                = ConfigEnvSet.GetInt("User.VitRestore");
            CombatLogCountMax         = ConfigEnvSet.GetInt("User.CombatLogCountMax");
            FriendCountMax            = ConfigEnvSet.GetInt("User.FriendCountMax");
            FriendApplyCountMax       = ConfigEnvSet.GetInt("User.FriendApplyCountMax");
            FriendGiveAwayCountMax    = ConfigEnvSet.GetInt("User.FriendGiveAwayCountMax");
            FriendGiveAwayVitValue    = ConfigEnvSet.GetInt("User.FriendGiveAwayVitValue");
            RepairSignNeedDiamond     = ConfigEnvSet.GetInt("User.RepairSignNeedDiamond");
            MaxMailNum                = ConfigEnvSet.GetInt("User.MaxMailNum");
            OpenTaskSystemUserLevel   = ConfigEnvSet.GetInt("System.OpenTaskSystemUserLevel");
            OpenRankSystemUserLevel   = ConfigEnvSet.GetInt("System.OpenRankSystemLevel");
            InviteFightAwardGold      = ConfigEnvSet.GetInt("User.InviteFightAwardGold");
            InviteFightDiamondWeekMax = ConfigEnvSet.GetInt("User.InviteFightDiamondWeekMax");



            var guildlist = new ShareCacheStruct <GuildsCache>().FindAll();

            foreach (var v in guildlist)
            {
                v.Lv = v.ConvertLevel();
            }
            var gameCache = new ShareCacheStruct <GameCache>();

            GameCache openServiceCache = gameCache.FindKey(OpenServiceDataCacheKey);

            if (openServiceCache == null)
            {
                openServiceCache       = new GameCache();
                openServiceCache.Key   = OpenServiceDataCacheKey;
                openServiceCache.Value = DateTime.Now.ToString();
                gameCache.Add(openServiceCache);
                gameCache.Update();

                IsFirstOpenService = true;
            }
            OpenServiceDate = openServiceCache.Value.ToDateTime();
            OpenServiceDate = new DateTime(OpenServiceDate.Year, 8 /*OpenServiceDate.Month*/, 1, 9, 0, 0);

            //GameCache signStartIDCache = gameCache.FindKey(SignStartIDCacheKey);
            //if (signStartIDCache == null)
            //{
            //    signStartIDCache = new GameCache();
            //    signStartIDCache.Key = SignStartIDCacheKey;
            //    signStartIDCache.Value = "1";
            //    gameCache.Add(signStartIDCache);
            //    gameCache.Update();
            //}
            //SignStartID = signStartIDCache.Value.ToInt();
            SignStartID = GetSignStartID();


            // 加载老用户记录
            var cacheSet = new MemoryCacheStruct <OldUserCache>();

            var    dbProvider = DbConnectionProvider.CreateDbProvider(DbConfig.Log);
            string sql        = "SELECT OpenID,NickName,AvatarUrl,CreateDate FROM OldUserLog";

            using (IDataReader reader = dbProvider.ExecuteReader(CommandType.Text, sql))
            {
                while (reader.Read())
                {
                    OldUserCache olduser = new OldUserCache();
                    olduser.OpenID     = reader["OpenID"].ToString();
                    olduser.NickName   = reader["NickName"].ToString();
                    olduser.AvatarUrl  = reader["AvatarUrl"].ToString();
                    olduser.CreateDate = reader["CreateDate"].ToDateTime();
                    cacheSet.TryAdd(olduser.OpenID, olduser);
                }
            }


            // 排行榜奖励数据
            GameCache levelCache = gameCache.FindKey(LevelRankingAwardCacheKey);

            if (levelCache == null)
            {
                levelCache       = new GameCache();
                levelCache.Key   = LevelRankingAwardCacheKey;
                levelCache.Value = MathUtils.ToJson(LevelRankingAwardCacheList);
                gameCache.Add(levelCache);
                gameCache.Update();
            }
            LevelRankingAwardCacheList = MathUtils.ParseJson <CacheList <UserRankAward> >(levelCache.Value);

            GameCache fightValueCache = gameCache.FindKey(FightValueRankingAwardCacheKey);

            if (fightValueCache == null)
            {
                fightValueCache       = new GameCache();
                fightValueCache.Key   = FightValueRankingAwardCacheKey;
                fightValueCache.Value = MathUtils.ToJson(FightValueRankingAwardCacheList);
                gameCache.Add(fightValueCache);
                gameCache.Update();
            }
            FightValueRankingAwardCacheList = MathUtils.ParseJson <CacheList <UserRankAward> >(fightValueCache.Value);

            GameCache comboCache = gameCache.FindKey(ComboRankingAwardCacheKey);

            if (comboCache == null)
            {
                comboCache       = new GameCache();
                comboCache.Key   = ComboRankingAwardCacheKey;
                comboCache.Value = MathUtils.ToJson(ComboRankingAwardCacheList);
                gameCache.Add(comboCache);
                gameCache.Update();
            }
            ComboRankingAwardCacheList = MathUtils.ParseJson <CacheList <UserRankAward> >(comboCache.Value);
        }
예제 #19
0
        protected override void TakeRemote()
        {
            var remoteSession = paramGetter.GetSession();

            if (remoteSession == null)
            {
                ErrorCode = 10000;
                ErrorInfo = "RemoteSession is null.";
                return;
            }



            switch (_chatType)
            {
            case ChatType.AllService:
            {
                var cache  = new MemoryCacheStruct <ChatUser>();
                var Sender = cache.Find(t => (t.UserId == _sender));
                if (Sender != null)
                {
                    var sessionlist = GameSession.GetAll();
                    foreach (var on in sessionlist)
                    {
                        if (on.Connected && !on.IsRemote)
                        {
                            MsgData data = new MsgData();
                            data.Type   = MsgType.Chat;
                            data.UserId = on.UserId;

                            var parameters = new Parameters();
                            parameters["Type"]             = ChatType.AllService;
                            parameters["Sender"]           = _sender;
                            parameters["SenderName"]       = Sender.UserName;
                            parameters["SenderVipLv"]      = Sender.VipLv;
                            parameters["SenderProfession"] = Sender.Profession;
                            parameters["SenderAvatarUrl"]  = Sender.AvatarUrl;
                            parameters["ServerID"]         = _serverID;
                            parameters["SendDate"]         = _sendDate;
                            parameters["Content"]          = _content;
                            data.Param = parameters;
                            MsgDispatcher.Push(data);
                        }
                    }
                }
            }
            break;

            case ChatType.World:
            {
                var cache  = new MemoryCacheStruct <ChatUser>();
                var Sender = cache.Find(t => (t.UserId == _sender));
                if (Sender != null)
                {
                    var list = cache.FindAll(t => t.ServerID == Sender.ServerID);
                    foreach (var v in list)
                    {
                        var session = GameSession.Get(v.UserId);
                        if (session != null && session.Connected && !session.IsRemote)
                        {
                            MsgData data = new MsgData();
                            data.Type   = MsgType.Chat;
                            data.UserId = v.UserId;

                            var parameters = new Parameters();
                            parameters["Type"]             = ChatType.World;
                            parameters["Sender"]           = _sender;
                            parameters["SenderName"]       = Sender.UserName;
                            parameters["SenderVipLv"]      = Sender.VipLv;
                            parameters["SenderProfession"] = Sender.Profession;
                            parameters["SenderAvatarUrl"]  = Sender.AvatarUrl;
                            parameters["ServerID"]         = _serverID;
                            parameters["SendDate"]         = _sendDate;
                            parameters["Content"]          = _content;
                            data.Param = parameters;
                            MsgDispatcher.Push(data);
                        }
                    }
                }
            }
            break;

            case ChatType.Whisper:
            {
                var cache    = new MemoryCacheStruct <ChatUser>();
                var Sender   = cache.Find(t => (t.UserId == _sender));
                var Receiver = cache.Find(t => (t.UserId == _reveiver));
                if (Sender != null && Receiver != null)
                {
                    var session = GameSession.Get(_reveiver);
                    if (session != null && session.Connected && !session.IsRemote)
                    {
                        MsgData data = new MsgData();
                        data.Type   = MsgType.Chat;
                        data.UserId = _reveiver;

                        var parameters = new Parameters();
                        parameters["Type"]             = ChatType.Whisper;
                        parameters["Sender"]           = _sender;
                        parameters["SenderName"]       = Sender.UserName;
                        parameters["SenderVipLv"]      = Sender.VipLv;
                        parameters["SenderProfession"] = Sender.Profession;
                        parameters["SenderAvatarUrl"]  = Sender.AvatarUrl;
                        parameters["ServerID"]         = _serverID;
                        parameters["SendDate"]         = _sendDate;
                        parameters["Content"]          = _content;
                        data.Param = parameters;
                        MsgDispatcher.Push(data);
                    }
                }
            }
            break;

            case ChatType.Guild:
            {
                var cache  = new MemoryCacheStruct <ChatUser>();
                var Sender = cache.Find(t => (t.UserId == _sender));
                if (Sender != null)
                {
                    if (Sender.GuildID.IsEmpty())
                    {
                        return;
                    }
                    var list = cache.FindAll(t => t.GuildID == Sender.GuildID);
                    foreach (var v in list)
                    {
                        var session = GameSession.Get(v.UserId);
                        if (session != null && session.Connected && !session.IsRemote)
                        {
                            MsgData data = new MsgData();
                            data.Type   = MsgType.Chat;
                            data.UserId = v.UserId;

                            var parameters = new Parameters();
                            parameters["Type"]             = ChatType.Guild;
                            parameters["Sender"]           = _sender;
                            parameters["SenderName"]       = Sender.UserName;
                            parameters["SenderVipLv"]      = Sender.VipLv;
                            parameters["SenderProfession"] = Sender.Profession;
                            parameters["SenderAvatarUrl"]  = Sender.AvatarUrl;
                            parameters["ServerID"]         = _serverID;
                            parameters["SendDate"]         = _sendDate;
                            parameters["Content"]          = _content;
                            data.Param = parameters;
                            MsgDispatcher.Push(data);
                        }
                    }
                }
            }
            break;

            case ChatType.System:
            {
                var cache    = new MemoryCacheStruct <ChatUser>();
                var Receiver = cache.Find(t => (t.UserId == _reveiver));
                if (Receiver != null)
                {
                    var session = GameSession.Get(_reveiver);
                    if (session != null && session.Connected && !session.IsRemote)
                    {
                        MsgData data = new MsgData();
                        data.Type   = MsgType.Chat;
                        data.UserId = _reveiver;

                        var parameters = new Parameters();
                        parameters["Type"]             = ChatType.System;
                        parameters["Sender"]           = 0;
                        parameters["SenderName"]       = "系统";
                        parameters["SenderVipLv"]      = 0;
                        parameters["SenderProfession"] = 0;
                        parameters["SenderAvatarUrl"]  = string.Empty;
                        parameters["ServerID"]         = _serverID;
                        parameters["SendDate"]         = _sendDate;
                        parameters["Content"]          = _content;
                        data.Param = parameters;
                        MsgDispatcher.Push(data);
                    }
                }
            }
            break;
            }
        }
예제 #20
0
 protected override bool DoSuccess(int userId, out IUser user)
 {
     user = null;
     var cache = new MemoryCacheStruct<ChatUser>();
     ChatUser chatUser = cache.Find(t => t.UserName == _userName);
     if (chatUser != null)
     {
         user = chatUser;
         return true;
     }
     return false;
 }
예제 #21
0
 public DataTableFactory()
 {
     m_Table = new MemoryCacheStruct <T>();
 }
예제 #22
0
파일: GameRoom.cs 프로젝트: kehaoran74/Scut
 /// <summary>
 /// 房间
 /// </summary>
 private GameRoom()
 {
     _roomStruct = new MemoryCacheStruct<RoomData>();
     _roomConfig = new ShareCacheStruct<RoomInfo>();
 }
예제 #23
0
 public Action100(HttpGet httpGet)
     : base(ActionIDDefine.Cst_Action100, httpGet)
 {
     _roomStruct = new MemoryCacheStruct<UserConnection>();
 }
예제 #24
0
        int mRole;//0:地主 -1:上家 1:下家

        public CardAILogic(int roomID, int tableID, int posID)
        {
            var      roomStruct = new MemoryCacheStruct <RoomData>();
            RoomData roomData;

            if (roomStruct.TryGet(roomID.ToString(), out roomData))
            {
                if (roomData.Tables.TryGetValue(tableID, out mTableData))
                {
                    mPlayerNum = mTableData.PlayerNum;
                }
            }

            if (null != mTableData && posID < mTableData.Positions.Length)
            {
                int tempCard = 0;
                foreach (var pos in mTableData.Positions)
                {
                    if (pos.IsLandlord)
                    {
                        mLandlordData = pos;
                    }
                    if (pos.Id == posID)
                    {
                        mSelfData = pos;
                    }

                    if (null != pos.CardData && pos.CardData.Count > 0)
                    {
                        int lastCardVal = pos.CardData[pos.CardData.Count - 1] % 100;
                        if (lastCardVal > tempCard)
                        {
                            tempCard = lastCardVal;
                        }
                    }
                }

                if (tempCard > 0)
                {
                    mLargestCardSize = (CardSize)tempCard;
                }
            }

            if (null != mLandlordData && null != mSelfData)
            {
                int nextIndex = (mSelfData.Id + 1) % mPlayerNum;
                mNextPos = mTableData.Positions[nextIndex];
                int preIndex = (mSelfData.Id + mPlayerNum - 1) % mPlayerNum;
                mPrePos = mTableData.Positions[preIndex];

                if (mLandlordData.Id == mSelfData.Id)
                {
                    mRole = 0;
                }
                else if (mLandlordData.Id == mNextPos.Id)
                {
                    mRole = -1;
                }
                else
                {
                    mRole = 1;
                }
            }
        }