Exemplo n.º 1
0
        /// <summary>
        /// 解散牌桌
        /// </summary>
        /// <param name="r"></param>
        /// <param name="messageNum">返回消息号</param>
        /// <param name="type">解散类型</param>
        public void DissolutionRoom(Room r, int messageNum, int type)
        {
            List <mjuser> listuser = Gongyong.mulist.FindAll(u => u.RoomID == r.RoomID);
            var           Returnjs = ReturnAllIdea.CreateBuilder().SetState(1).SetMessgaeType(type);

            byte[] Sdata = Returnjs.Build().ToByteArray();
            //if (Gongyong.userlist.Count == 0)
            //    return;
            foreach (var item in listuser)
            {
                UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                if (user != null)
                {
                    //RedisUtility.Get<RedisLoginModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERLIST, gameOperation.Openid, gameOperation.Unionid));
                    //将用户游戏信息更新
                    RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, user.openid, user.unionid));
                    //RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERLIST, user.openid, user.unionid));
                    user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5007, Sdata.Length, messageNum, Sdata)));
                }
            }

            Gongyong.roomlist.Remove(r);
            Gongyong.mulist.RemoveAll(u => u.RoomID == r.RoomID);
            RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), ""));
            new RoomInfoDAL().UpdateEndRoomInfoByRoomInfoID(new RoomInfo {
                RoomInfoID = r.RoomInfoID, EndTime = DateTime.Now, EndStatus = type
            });
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //RedisUtility.SetCatch<string>("teststring", "helloword", 24 * 60 * 60);
            string testStr = RedisUtility.GetCatch <string>("teststring");

            Response.Write(testStr);
        }
Exemplo n.º 3
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            var             gameOperation = SendGetRoomCard.ParseFrom(requestInfo.Body);
            RedisLoginModel olduser       = RedisUtility.Get <RedisLoginModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERLIST, gameOperation.Openid, gameOperation.Unionid));

            if (olduser == null)
            {
                return;
            }
            var info = Gongyong.userlist.First(w => w.openid.Equals(olduser.Openid));

            if (info == null)
            {
                return;
            }
            if (info.Type == 0)
            {
                var msg = ReturnGetRoomCard.CreateBuilder().SetUserRoomCard(RoomCardUtility.GetRoomCard(gameOperation.UserID)).Build().ToByteArray();
                session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1023, msg.Length, requestInfo.MessageNum, msg)));
            }
            else
            {
                var msg = ReturnGetRoomCard.CreateBuilder().SetUserRoomCard(RoomCardUtility.GetLongBaoNumber(info.unionid)).Build().ToByteArray();
                session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1023, msg.Length, requestInfo.MessageNum, msg)));
            }
        }
Exemplo n.º 4
0
        public void AppendRemoveItemsInList_NothingDeleted()
        {
            ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();

            sessionItems["key"] = "val";
            Assert.Equal(0, RedisUtility.AppendRemoveItemsInList(sessionItems, null));
        }
        private StackExchangeClientConnection GetStackExchangeClientConnection(ProviderConfiguration configuration)
        {
            var sharedConnection = new RedisSharedConnection(configuration);
            var redisUtility     = new RedisUtility(configuration);

            return(new StackExchangeClientConnection(configuration, redisUtility, sharedConnection));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="tabName"></param>
        /// <param name="uid"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public string Get(string tabName, string uid, string key)
        {
            string strKey = tabName + "_" + uid + "_" + key;

            if (RedisUtility.KeyExist(strKey))
            {
                return(RedisUtility.StringGet(strKey));
            }
            var sqlParams = new MySqlParameter[]
            {
                new MySqlParameter("@openid", MySqlDbType.VarChar)
                {
                    Value = uid
                },
            };
            var strsql  = "select " + key + " from " + tabName + " where uid=@uid limit 1";
            var dataset = MysqlUtility.ExecuteQuery(strsql, sqlParams);
            var obj     = dataset.Tables[0].Rows[0][key].ToString();

            if (obj != null)
            {
                logger.Warn("strKey:  " + strKey + " obj: " + obj);
                RedisUtility.StringSet(strKey, obj, expireTime);
            }
            return(obj);
        }
Exemplo n.º 7
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (requestInfo.MessageResNum != 19990)
            {
                session.Close();
                session.Logger.Debug("非法用户请求 " + session.RemoteEndPoint.AddressFamily);
                return;
            }
            var RoomExist = SendRoomExist.ParseFrom(requestInfo.Body);
            var muInfo    = Gongyong.mulist.Find(w => w.Openid.Equals(RoomExist.Openid));

            if (muInfo == null)
            {
                var roomInfo = Gongyong.roomlist.Find(w => w.RoomID == RoomExist.RoomID);
                if (roomInfo != null)
                {
                    Gongyong.roomlist.Remove(roomInfo);
                }
                else
                {
                    RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, RoomExist.RoomID.ToString(), ""));
                }
                RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, RoomExist.Openid, RoomExist.Unionid));
                var data = ReturnRoomExist.CreateBuilder().SetIsExist(0).Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 9902, data.Length, 19990, data)));
            }
            else
            {
                var data = ReturnRoomExist.CreateBuilder().SetIsExist(1).Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 9902, data.Length, 19990, data)));
            }
        }
Exemplo n.º 8
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            GroupInfoDAL       groupInfoDAL    = new GroupInfoDAL();
            var                sendApplyToJoin = SendApplyToJoin.ParseFrom(requestInfo.Body);
            RedisUserInfoModel user            = RedisUtility.Get <RedisUserInfoModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERINFO, sendApplyToJoin.Openid, sendApplyToJoin.Unionid));

            if (groupInfoDAL.GetGroupInfoByGroupID(sendApplyToJoin.GroupID, user.Type) == null)
            {
                var returnApplyToJoin = ReturnApplyToJoin.CreateBuilder().SetStatus(0).SetMessage("圈子不存在").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1041, returnApplyToJoin.Length, requestInfo.MessageNum, returnApplyToJoin)));
            }
            else if (groupInfoDAL.PlayerApplyRecord(user.UserID, sendApplyToJoin.GroupID, 0) == 1)
            {
                var returnApplyToJoin = ReturnApplyToJoin.CreateBuilder().SetStatus(0).SetMessage("已申请,待群主通过").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1041, returnApplyToJoin.Length, requestInfo.MessageNum, returnApplyToJoin)));
            }
            else if (groupInfoDAL.PlayerApplyRecord(user.UserID, sendApplyToJoin.GroupID, 1) == 1 || groupInfoDAL.IsUserInGroup(sendApplyToJoin.GroupID, user.UserID) != 0)
            {
                var returnApplyToJoin = ReturnApplyToJoin.CreateBuilder().SetStatus(0).SetMessage("已再圈子中,请勿重复申请").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1041, returnApplyToJoin.Length, requestInfo.MessageNum, returnApplyToJoin)));
            }
            //else if (true)
            //{
            //    var returnApplyToJoin = ReturnApplyToJoin.CreateBuilder().SetStatus(0).SetMessage("已再圈子中,请勿重复申请").Build().ToByteArray();
            //    session.Send(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1041, returnApplyToJoin.Length, requestInfo.MessageNum, returnApplyToJoin)));
            //}
            else
            {
                groupInfoDAL.ApplyToJoin(sendApplyToJoin.GroupID, user.UserID);
                var returnApplyToJoin = ReturnApplyToJoin.CreateBuilder().SetStatus(1).SetMessage("申请成功").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1041, returnApplyToJoin.Length, requestInfo.MessageNum, returnApplyToJoin)));
            }
        }
Exemplo n.º 9
0
        public void GetNewItemsAsList_EmptySessionData()
        {
            ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();
            List <object> list = RedisUtility.GetNewItemsAsList(sessionItems);

            Assert.Equal(0, list.Count);
        }
Exemplo n.º 10
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            var sendData = SendGroupInfoByGroupID.ParseFrom(requestInfo.Body);
            var userInfo = RedisUtility.Get <RedisUserInfoModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERINFO, sendData.Openid, sendData.Unionid));

            if (userInfo == null || !userInfo.GroupID.Any(w => w == sendData.GroupID))
            {
                session.Close();
                return;
            }
            GroupInfoDAL groupInfoDAL    = new GroupInfoDAL();
            var          groupInfo       = groupInfoDAL.GetGroupInfoByGroupID(sendData.GroupID, userInfo.Type);
            var          returnGroupInfo = ReturnGroupInfoByGroupID.CreateBuilder();

            if (groupInfo != null)
            {
                var data = returnGroupInfo.SetStatus(1).SetCreateTime(TimeToLong.ConvertDateTimeInt(groupInfo.CreateTime)).SetGroupID(groupInfo.GroupID)
                           .SetGroupName(HttpUtility.UrlDecode(HttpUtility.UrlDecode(groupInfo.GroupName))).SetNikeName(HttpUtility.UrlDecode(HttpUtility.UrlDecode(groupInfo.NikeName))).SetCreateUserID(groupInfo.CreateUserID)
                           .SetGroupNumberPeople(groupInfoDAL.GetGroupPeopleNumber(sendData.GroupID)).Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1033, data.Length, requestInfo.MessageNum, data)));
            }
            else
            {
                var data = returnGroupInfo.SetStatus(0).Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1033, data.Length, requestInfo.MessageNum, data)));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void Initialize()
        {
            dataMgr = this;

            RedisUtility.Initialize();
            MysqlUtility.Initialize();
        }
 public object GetActualValue(RedisUtility utility)
 {
     if (_actualValue == null)
     {
         _actualValue = utility.GetObjectFromBytes(_serializedvalue);
     }
     return(_actualValue);
 }
Exemplo n.º 13
0
        public void GetObjectFromBytes_WithValidObject()
        {
            Object obj = "hi";

            byte[] data = RedisUtility.GetBytesFromObject(obj);

            Assert.Equal(obj.ToString(), RedisUtility.GetObjectFromBytes(data).ToString());
        }
Exemplo n.º 14
0
 public void GetObjectFromBytes_GetBytesFromObject_WithEmptyByteArray()
 {
     byte[] data           = new byte[0];
     byte[] serializedData = RedisUtility.GetBytesFromObject(data);
     Assert.NotNull(serializedData);
     byte[] deserializedData = (byte[])RedisUtility.GetObjectFromBytes(serializedData);
     Assert.NotNull(deserializedData);
     Assert.Equal(deserializedData.Length, data.Length);
 }
Exemplo n.º 15
0
        public void AppendUpdatedOrNewItemsInList_SuccessfulUpdated()
        {
            ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();
            List <object> list = new List <object>();

            sessionItems["key"] = "val";
            Assert.Equal(1, RedisUtility.AppendUpdatedOrNewItemsInList(sessionItems, list));
            Assert.Equal(2, list.Count);
        }
Exemplo n.º 16
0
        public void NullActualValue()
        {
            RedisUtility utility = new RedisUtility(Utility.GetDefaultConfigUtility());
            ChangeTrackingSessionStateItemCollection items = Utility.GetChangeTrackingSessionStateItemCollection();

            items.SetDataWithoutUpdatingModifiedKeys("k1", null);

            Assert.Single(items);
            Assert.Null(items["k1"]);
        }
Exemplo n.º 17
0
        public void NullActualValue()
        {
            RedisUtility utility = new RedisUtility(Utility.GetDefaultConfigUtility());
            ChangeTrackingSessionStateItemCollection items = Utility.GetChangeTrackingSessionStateItemCollection();

            items.SetData("k1", null);

            Assert.Equal(1, items.Count);
            Assert.Null(items["k1"]);
        }
        public void CustomSerializer_ByAssemblyQualifiedName()
        {
            var serTypeName = typeof(TestSerializer).AssemblyQualifiedName;
            var utility     = new RedisUtility(new ProviderConfiguration()
            {
                RedisSerializerType = serTypeName
            });

            Assert.IsType <TestSerializer>(utility._serializer);
        }
Exemplo n.º 19
0
        public void GetNewItemsAsList_WithNullSessionData()
        {
            ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();

            sessionItems["key"]  = "val";
            sessionItems["key1"] = null;
            List <object> list = RedisUtility.GetNewItemsAsList(sessionItems);

            Assert.Equal(4, list.Count);
        }
Exemplo n.º 20
0
        public void Count_AfterLazyDeserialization()
        {
            RedisUtility utility = new RedisUtility(Utility.GetDefaultConfigUtility());
            ChangeTrackingSessionStateItemCollection items = Utility.GetChangeTrackingSessionStateItemCollection();

            items.SetDataWithoutUpdatingModifiedKeys("k1", utility.GetBytesFromObject("v1"));
            items.SetDataWithoutUpdatingModifiedKeys("k2", utility.GetBytesFromObject("v2"));

            Assert.Equal(2, items.Count);
            items["k3"] = "v3";
            Assert.Equal(3, items.Count);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 用户退出牌桌
        /// </summary>
        /// <param name="usermj"></param>
        /// <param name="roomID"></param>
        /// <param name="openid"></param>
        /// <param name="messageNum"></param>
        /// <param name="session"></param>
        /// <param name="isExit">是否已退出</param>
        public void UserExit(mjuser usermj, int roomID, string openid, int messageNum, GameSession session, bool isExit = false)
        {
            List <mjuser> listmjuser = Gongyong.mulist.FindAll(u => u.RoomID == roomID);

            ///判断是否该房间是否存在用户
            if (listmjuser.Count <= 0)
            {
                return;
            }

            ///向剩余用户下发推出玩家
            var  returnData = ReturnRemoveUser.CreateBuilder().SetOpenid(openid).SetStatus(1);
            Room r          = Gongyong.roomlist.Find(u => u.RoomID == roomID);

            if (r == null)
            {
                return;
            }
            //判断房间已开始游戏
            if (r.startgame == 1)
            {
                returnData.SetStatus(0);
                byte[] returnbyte = returnData.Build().ToByteArray();
                if (!isExit)
                {
                    session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5009, returnbyte.Length, messageNum, returnbyte)));
                }
            }
            else
            {
                byte[] returnbyte = returnData.Build().ToByteArray();
                if (isExit)
                {
                    listmjuser.Remove(listmjuser.First(w => w.Openid.Equals(openid)));
                }
                r.listOpenid.Remove(openid);
                foreach (var item in listmjuser)
                {
                    UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                    if (user != null && user.session != null)
                    {
                        user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5009, returnbyte.Length, messageNum, returnbyte)));
                    }

                    if (user.openid.Equals(usermj.Openid))
                    {
                        //将用户游戏信息更新
                        RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, user.openid, user.unionid));
                    }
                }
                Gongyong.mulist.Remove(usermj);
            }
        }
        public void GetObjectFromBytes_GetBytesFromObject_CustomSerializer()
        {
            var serTypeName = typeof(TestSerializer).AssemblyQualifiedName;
            var utility     = new RedisUtility(new ProviderConfiguration()
            {
                RedisSerializerType = serTypeName
            });

            var bytes          = utility.GetBytesFromObject("test");
            var obj            = utility.GetObjectFromBytes(bytes);
            var testSerializer = (TestSerializer)utility._serializer;

            Assert.Equal("test", obj);
            Assert.Equal(1, testSerializer.DeserializeCount);
            Assert.Equal(1, testSerializer.SerializeCount);
        }
Exemplo n.º 23
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            var sendData = SendGroupUserInfoByGroupID.ParseFrom(requestInfo.Body);
            var userInfo = RedisUtility.Get <RedisUserInfoModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERINFO, sendData.Openid, sendData.Unionid));

            if (userInfo == null || !userInfo.GroupID.Any(w => w == sendData.GroupID))
            {
                // session.Close();
                return;
            }
            GroupInfoDAL groupInfoDAL    = new GroupInfoDAL();
            var          groupInfo       = groupInfoDAL.GetGroupInfoByGroupID(sendData.GroupID, userInfo.Type);
            var          returnGroupInfo = ReturnGroupUserInfoByGroupID.CreateBuilder();

            if (groupInfo != null)
            {
                var list = groupInfoDAL.GetGroupStaffInfoByGroupID(sendData.GroupID);
                if (list != null)
                {
                    foreach (var item in list)
                    {
                        var userInfoDB = new mjuserinfoDAL().GetModel(item.GroupUserID);
                        if (userInfoDB != null)
                        {
                            var groupUserInfo = GroupUserInfo.CreateBuilder();
                            groupUserInfo.SetGroupUserID(item.GroupUserID).SetNickName(HttpUtility.UrlDecode(HttpUtility.UrlDecode(userInfoDB.nickname)))
                            .SetPicture(userInfoDB.headimg).SetStatus(0);
                            if (Gongyong.userlist.Any(w => w.UserID.Equals(item.GroupUserID)))
                            {
                                groupUserInfo.SetStatus(1);
                            }
                            if (RedisUtility.Get <RedisGameModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, userInfoDB.openid, userInfoDB.unionid)) != null)
                            {
                                groupUserInfo.SetStatus(2);
                            }
                            returnGroupInfo.AddUserList(groupUserInfo);
                        }
                    }
                    var data = returnGroupInfo.SetStatus(1).Build().ToByteArray();
                    session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1035, data.Length, requestInfo.MessageNum, data)));
                    return;
                }
            }
            var dataF = returnGroupInfo.SetStatus(0).Build().ToByteArray();

            session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1035, dataF.Length, requestInfo.MessageNum, dataF)));
        }
Exemplo n.º 24
0
        public void TryUpdateIfLockIdMatch_WithOnlyUpdateAndNoDelete()
        {
            using (RedisServer redisServer = new RedisServer())
            {
                RedisConnectionWrapper redisConn = GetRedisConnectionWrapperWithUniqueSession();

                // Inserting data into redis server
                ChangeTrackingSessionStateItemCollection data = new ChangeTrackingSessionStateItemCollection();
                data["key1"] = "value1";
                data["key2"] = "value2";
                data["key3"] = "value3";
                redisConn.Set(data, 900);

                int      lockTimeout = 900;
                DateTime lockTime    = DateTime.Now;
                object   lockId;
                ISessionStateItemCollection dataFromRedis;
                int sessionTimeout;
                Assert.True(redisConn.TryTakeWriteLockAndGetData(lockTime, lockTimeout, out lockId, out dataFromRedis, out sessionTimeout));
                Assert.Equal(lockTime.Ticks.ToString(), lockId.ToString());
                Assert.Equal(3, dataFromRedis.Count);
                Assert.Equal("value1", dataFromRedis["key1"]);
                Assert.Equal("value2", dataFromRedis["key2"]);
                Assert.Equal("value3", dataFromRedis["key3"]);

                dataFromRedis["key2"] = "value2-updated";
                redisConn.TryUpdateAndReleaseLockIfLockIdMatch(lockId, dataFromRedis, 900);

                // Get actual connection and get data from redis
                IDatabase   actualConnection     = GetRealRedisConnection(redisConn);
                HashEntry[] sessionDataFromRedis = actualConnection.HashGetAll(redisConn.Keys.DataKey);
                Assert.Equal(3, sessionDataFromRedis.Length);
                ChangeTrackingSessionStateItemCollection sessionDataFromRedisAsCollection = new ChangeTrackingSessionStateItemCollection();
                foreach (HashEntry entry in sessionDataFromRedis)
                {
                    sessionDataFromRedisAsCollection[entry.Name] = RedisUtility.GetObjectFromBytes(entry.Value).ToString();
                }
                Assert.Equal("value1", sessionDataFromRedisAsCollection["key1"]);
                Assert.Equal("value2-updated", sessionDataFromRedisAsCollection["key2"]);
                Assert.Equal("value3", sessionDataFromRedisAsCollection["key3"]);

                // check lock removed and remove data from redis
                actualConnection.KeyDelete(redisConn.Keys.DataKey);
                Assert.False(actualConnection.KeyExists(redisConn.Keys.LockKey));
                DisposeRedisConnectionWrapper(redisConn);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 加入服务器
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            SendAddServer sendInfo = SendAddServer.ParseFrom(requestInfo.Body);
            var           key      = RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERINFO, sendInfo.Openid, sendInfo.Unionid);

            var userInfo = RedisUtility.Get <RedisUserInfoModel>(key);

            var returnAddServer = ReturnAddServer.CreateBuilder();

            if (userInfo == null)
            {
                returnAddServer.SetStatus(2);
            }
            else
            {
                returnAddServer.SetStatus(1);
                var info = Gongyong.userlist.Find(w => w.openid.Equals(userInfo.Openid));
                if (info == null)
                {
                    var user = new UserInfo(userInfo);
                    user.session = session;
                    Gongyong.userlist.Add(user);
                    session.Logger.Debug("加入游戏服务器成功----" + sendInfo.Openid + "------" + DateTime.Now);
                }
                else
                {
                    info.nickname = userInfo.Nickname;
                    info.sex      = userInfo.Sex;
                    info.headimg  = userInfo.Headimg;
                    if (info.session != null)
                    {
                        info.session.Close();
                    }
                    info.session = session;
                    mjuser mju = Gongyong.mulist.Find(u => u.Openid == info.openid);

                    if (mju != null)
                    {
                        mju.ConnectionStatus = 1;
                        // SendCL(session, info.openid, requestInfo);
                    }
                }
            }
            var data = returnAddServer.Build().ToByteArray();

            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1012, data.Length, requestInfo.MessageNum, data)));
        }
Exemplo n.º 26
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            List <GroupInfo> groupInfoList = new List <GroupInfo>();
            var requestGroupInfo           = SendGroupInfo.ParseFrom(requestInfo.Body);
            RedisUserInfoModel user        = RedisUtility.Get <RedisUserInfoModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERINFO, requestGroupInfo.Openid, requestGroupInfo.Unionid));

            if (user == null)
            {
                session.Logger.Debug(string.Format("缓存无此用户{0}", string.IsNullOrEmpty(requestGroupInfo.Openid) ? "用户openid为空" : ""));
                return;
            }
            GroupInfoDAL groupInfoDAL    = new GroupInfoDAL();
            var          list            = groupInfoDAL.GetGroupIDListByUserID(user.UserID, user.Type);
            var          returnGroupInfo = ReturnGroupInfo.CreateBuilder();
            var          GroupInfodata   = GroupInfo.CreateBuilder();

            Byte[] returnGroupInfoData = null;
            if (list == null || list.Count == 0)
            {
                returnGroupInfoData = returnGroupInfo.Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1031, returnGroupInfoData.Length, requestInfo.MessageNum, returnGroupInfoData)));
            }
            else
            {
                foreach (var GroupID in list.Distinct())
                {
                    DAL.Model.GroupInfo groupInfoModel = groupInfoDAL.GetGroupInfoByGroupID(GroupID, user.Type);
                    if (groupInfoModel != null)
                    {
                        if (groupInfoModel.CreateUserID == user.UserID)
                        {
                            GroupInfodata.SetGroupID(GroupID).SetGroupIntroduction(groupInfoModel.GroupIntroduction ?? "").SetGroupName(HttpUtility.UrlDecode(HttpUtility.UrlDecode(groupInfoModel.GroupName))).SetNikeName(groupInfoModel.GroupName).SetRoomCardCounts(RoomCardUtility.GetRoomCard(groupInfoModel.CreateUserID)).SetCreateTime(TimeToLong.ConvertDateTimeInt(groupInfoModel.CreateTime)).SetIsGroupLord(true);
                            returnGroupInfo.AddGroupInfo(GroupInfodata);
                            //data.SetGroupInfo(1,GroupInfo)
                        }
                        else
                        {
                            GroupInfodata.SetGroupID(GroupID).SetGroupIntroduction(groupInfoModel.GroupIntroduction ?? "").SetGroupName(HttpUtility.UrlDecode(HttpUtility.UrlDecode(groupInfoModel.GroupName))).SetNikeName(groupInfoModel.GroupName).SetRoomCardCounts(RoomCardUtility.GetRoomCard(groupInfoModel.CreateUserID)).SetCreateTime(TimeToLong.ConvertDateTimeInt(groupInfoModel.CreateTime)).SetIsGroupLord(false);
                            returnGroupInfo.AddGroupInfo(GroupInfodata);
                        }
                    }
                }
                returnGroupInfoData = returnGroupInfo.Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1031, returnGroupInfoData.Length, requestInfo.MessageNum, returnGroupInfoData)));
            }
        }
Exemplo n.º 27
0
        public void Dirty_AfterLazyDeserialization()
        {
            RedisUtility utility = new RedisUtility(Utility.GetDefaultConfigUtility());
            ChangeTrackingSessionStateItemCollection items = Utility.GetChangeTrackingSessionStateItemCollection();

            items.SetDataWithoutUpdatingModifiedKeys("Test", utility.GetBytesFromObject("v1"));
            items.Dirty = false;

            Assert.False(items.Dirty);
            // read operation should not change value of Dirty
            var val = items["Test"];

            Assert.False(items.Dirty);

            items["Test"] = "v2";
            Assert.True(items.Dirty);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 移除某个字段
        /// </summary>
        /// <param name="tabName"></param>
        /// <param name="uid"></param>
        /// <param name="key"></param>
        public void Remove(string tabName, string uid, string key)
        {
            if (RedisUtility.KeyExist(key))
            {
                RedisUtility.KeyDelete(key);
            }
            var sqlParams = new MySqlParameter[]
            {
                new MySqlParameter("@openid", MySqlDbType.VarChar)
                {
                    Value = uid
                },
            };
            var strsql = "update " + tabName + " set " + key + "='' where openid =@openid";

            MysqlUtility.ExecuteSql(strsql, sqlParams);
        }
Exemplo n.º 29
0
        private void OnRedisKeyEvent(string channel, string message)
        {
            // INFO: "message" is the cache key

            var key = RedisUtility.GetEventFromChannel(channel);

            switch (key)
            {
            //case "expire":
            case "expired":
            case "evicted":
                Expired?.Invoke(this, new CacheEntryExpiredEventArgs {
                    Key = NormalizeKey(message)
                });
                RemoveDependingEntries(new string[] { message });
                //Debug.WriteLine("Expiration occurred for {0}".FormatInvariant(message));
                break;
            }
        }
        public RedisConnectionWrapper(ProviderConfiguration configuration, string id)
        {
            this.configuration = configuration;
            Keys = new KeyGenerator(id, configuration.ApplicationName);

            // Pool is created by server when it starts. don't want to lock everytime when check pool == null.
            // so that is why pool == null exists twice.
            if (sharedConnection == null)
            {
                lock (lockForSharedConnection)
                {
                    if (sharedConnection == null)
                    {
                        sharedConnection = new RedisSharedConnection(configuration, () => new StackExchangeClientConnection(configuration));
                        redisUtility     = new RedisUtility(configuration);
                    }
                }
            }
            redisConnection = sharedConnection.TryGetConnection();
        }
 public void CustomSerializer_ByAssemblyQualifiedName()
 {
     var serTypeName = typeof(TestSerializer).AssemblyQualifiedName;
     var utility = new RedisUtility(new ProviderConfiguration() { RedisSerializerType = serTypeName });
     Assert.IsType<TestSerializer>(utility._serializer);
 }
        public void GetObjectFromBytes_GetBytesFromObject_CustomSerializer()
        {
            var serTypeName = typeof(TestSerializer).AssemblyQualifiedName;
            var utility = new RedisUtility(new ProviderConfiguration() { RedisSerializerType = serTypeName });

            var bytes = utility.GetBytesFromObject("test");
            var obj = utility.GetObjectFromBytes(bytes);
            var testSerializer = (TestSerializer) utility._serializer;
            Assert.Equal("test", obj);
            Assert.Equal(1, testSerializer.DeserializeCount);
            Assert.Equal(1, testSerializer.SerializeCount);
        }
        public void Set_ValidData_WithCustomSerializer()
        {
            // this also tests host:port config part
            ProviderConfiguration pc = Utility.GetDefaultConfigUtility();
            pc.RedisSerializerType = typeof(TestSerializer).AssemblyQualifiedName;
            pc.ApplicationName = "APPTEST";
            pc.Port = 6379;
            RedisUtility testSerializerRedisUtility = new RedisUtility(pc);

            using (RedisServer redisServer = new RedisServer())
            {
                RedisConnectionWrapper redisConn = GetRedisConnectionWrapperWithUniqueSession(pc);

                // Inserting data into redis server
                ChangeTrackingSessionStateItemCollection data = new ChangeTrackingSessionStateItemCollection();
                data["key"] = "value";
                data["key1"] = "value1";
                redisConn.Set(data, 900);

                // Get actual connection and get data blob from redis
                IDatabase actualConnection = GetRealRedisConnection(redisConn);
                HashEntry[] sessionDataFromRedis = actualConnection.HashGetAll(redisConn.Keys.DataKey);

                // Check that data shoud be same as what inserted
                Assert.Equal(2, sessionDataFromRedis.Length);
                ChangeTrackingSessionStateItemCollection dataFromRedis = new ChangeTrackingSessionStateItemCollection();
                foreach (HashEntry entry in sessionDataFromRedis)
                {
                    dataFromRedis[entry.Name] = testSerializerRedisUtility.GetObjectFromBytes(entry.Value).ToString();
                }
                Assert.Equal("value", dataFromRedis["key"]);
                Assert.Equal("value1", dataFromRedis["key1"]);

                // remove data from redis
                actualConnection.KeyDelete(redisConn.Keys.DataKey);
                DisposeRedisConnectionWrapper(redisConn);
            }
        }