public void AddandGet() { var watch = Stopwatch.StartNew(); int userId = 138001; var cache = new ShareCacheStruct <KeyData>(); cache.AddOrUpdate(new KeyData() { Key = userId.ToString(), Value = "aa" }); var list = cache.FindKey(userId.ToString()); Assert.IsNotNull(list); var key = userId + cache.GetNextNo(); cache.Add(new KeyData() { Key = key.ToString(), Value = "aa" }); Assert.IsNotNull(cache.FindKey(key.ToString())); key = userId + cache.GetNextNo(); cache.AddOrUpdate(new KeyData() { Key = key.ToString(), Value = "aa" }); Assert.IsNotNull(cache.FindKey(key.ToString())); WaitEnd(watch); }
public void AddFieldAll() { var watch = Stopwatch.StartNew(); var cache = new ShareCacheStruct <FieldTypeData>(); var t = cache.FindKey(1); if (t != null) { } Assert.IsTrue(cache.Add(new FieldTypeData() { Id = cache.GetNextNo(), FieldBool = true, FieldByte = 98, FieldBytes = new byte[] { 100, 102 }, FieldDateTime = DateTime.Now, FieldDecimal = 1.0001m, FieldDouble = 1.000001d, FieldFloat = 1.0000001f, FieldGuid = Guid.NewGuid(), FieldInt = -1000001, FieldShort = -2555, FieldStr = "hello", FieldUint = 10000, FieldUlong = 100000000, FieldUshort = 6222, })); WaitEnd(watch); }
public override bool TakeAction() { var cache = new ShareCacheStruct <UserRanking>(); var ranking = cache.Find(m => m.UserName == requestPack.UserName); if (ranking == null) { var user = new GameUser() { UserId = (int)cache.GetNextNo(), NickName = requestPack.UserName }; new PersonalCacheStruct <GameUser>().Add(user); ranking = new UserRanking(); ranking.UserID = user.UserId; ranking.UserName = requestPack.UserName; ranking.Score = requestPack.Score; cache.Add(ranking); } else { ranking.UserName = requestPack.UserName; ranking.Score = requestPack.Score; } return(true); }
Response1001Pack cbFunc(object obj) { List <object> objList = obj as List <object>; if (objList.Count != 2) { return(null); } List <UserRanking> rankingList = objList[1] as List <UserRanking>; // save to ....where.... var shareCache = new ShareCacheStruct <HistoryUserRanking>(); int num = (int)shareCache.GetNextNo(); var saveData = new HistoryUserRanking(); saveData.ID = num; // get data if (rankingList.Count >= 3) { UserRanking first = rankingList[0]; UserRanking second = rankingList[1]; UserRanking thrid = rankingList[2]; saveData.Items.Add(first); saveData.Items.Add(second); saveData.Items.Add(thrid); } shareCache.Add(saveData); return(null); }
private int getID() { var cache = new ShareCacheStruct <ServerInfoMode>(); var info = cache.Find((o) => { if (o.userd == false && o.type == serverType) { return(true); } return(false); }); int id = -1; if (info != null) { info.ModifyLocked(() => { if (info.userd == false) { id = info.id; info.userd = true; } }); } return(id < 0 ? (int)cache.GetNextNo() : id); }
public override bool TakeAction() { var cache = new ShareCacheStruct <UserRanking>(); var ranking = cache.Find(m => m.UserName == UserName); if (ranking == null) { var user = new GameUser() { UserId = (int)cache.GetNextNo(), NickName = UserName }; new PersonalCacheStruct <GameUser>().Add(user); ranking = new UserRanking(); ranking.UserID = user.UserId; ranking.UserName = UserName; ranking.Score = Score; if (!cache.Add(ranking)) { ErrorCode = Language.Instance.ErrorCode; ErrorInfo = string.Format("add fail, UserID {0} is exist.", ranking.UserID); return(false); } } else { ranking.UserName = UserName; ranking.Score = Score; } return(true); }
public override bool TakeAction() { var cache = new ShareCacheStruct<UserRanking>(); var ranking = cache.Find(m => m.UserName == UserName); if (ranking == null) { var user = new GameUser() { UserId = (int)cache.GetNextNo(), NickName = UserName}; new PersonalCacheStruct<GameUser>().Add(user); ranking = new UserRanking(); ranking.UserID = user.UserId; ranking.UserName = UserName; ranking.Score = Score; if (!cache.Add(ranking)) { ErrorCode = Language.Instance.ErrorCode; ErrorInfo = string.Format("add fail, UserID {0} is exist.", ranking.UserID); return false; } } else { ranking.UserName = UserName; ranking.Score = Score; } return true; }
public override bool TakeAction() { var cache = new ShareCacheStruct <testUpdate>(); var tu = new testUpdate(); tu.index = (int)cache.GetNextNo(); tu.itemID = 0; tu.ModifyLocked(() => { tu.itemID = 1; }); tu = cache.FindKey(tu.index); tu = new testUpdate(); tu.index = (int)cache.GetNextNo(); tu.itemID = 100; cache.Add(tu); tu = cache.FindKey(tu.index); // try // { // var UA = new UserAnalysis(); // foreach (logData d in requestPack.items) // { // UA.DeviceId = d.DeviceID; // UA.Channel = d.Channel; // UA.SimType = d.SimType; // UA.ActionType = (UserAnalysis.E_ActionType)d.ActionType; // UA.ProductionId = d.ProductionId; // UA.ActionTime = System.DateTime.Now; // //DataSyncQueueManager.SendToDb(UA); // Console.WriteLine("{0}GameSession:{1}", DateTime.Now.ToString("HH:mm:ss"), GameSession.Count); // } // responsePack = new ResponsePack(); // responsePack.ActionId = 80000; // responsePack.ErrorCode = 101; // responsePack.ErrorInfo = "Success"; // return true; // } // catch (Exception ex) // { // TraceLog.WriteError("TakeAction:{0} error:{1}", actionId, ex); // return false; // } return(true); }
public override bool TakeAction() { var cache = new ShareCacheStruct<testUpdate>(); var tu = new testUpdate(); tu.index = (int)cache.GetNextNo(); tu.itemID = 0; tu.ModifyLocked(() => { tu.itemID = 1; }); tu = cache.FindKey(tu.index); tu = new testUpdate(); tu.index = (int)cache.GetNextNo(); tu.itemID = 100; cache.Add(tu); tu = cache.FindKey(tu.index); // try // { // var UA = new UserAnalysis(); // foreach (logData d in requestPack.items) // { // UA.DeviceId = d.DeviceID; // UA.Channel = d.Channel; // UA.SimType = d.SimType; // UA.ActionType = (UserAnalysis.E_ActionType)d.ActionType; // UA.ProductionId = d.ProductionId; // UA.ActionTime = System.DateTime.Now; // //DataSyncQueueManager.SendToDb(UA); // Console.WriteLine("{0}GameSession:{1}", DateTime.Now.ToString("HH:mm:ss"), GameSession.Count); // } // responsePack = new ResponsePack(); // responsePack.ActionId = 80000; // responsePack.ErrorCode = 101; // responsePack.ErrorInfo = "Success"; // return true; // } // catch (Exception ex) // { // TraceLog.WriteError("TakeAction:{0} error:{1}", actionId, ex); // return false; // } return true; }
void addLog(ShareCacheStruct <DataLog> cache, int userid, int dimond) { int index = (int)cache.GetNextNo(); DataLog dl = new DataLog(); dl.Index = index; dl.UserID = userid; dl.Dimond = dimond; cache.Add(dl); }
void addAuthory() { var cache = new ShareCacheStruct <Authority>(); Authority au = new Authority(); au.id = (int)cache.GetNextNo(); au.name = "guccang"; au.pwd = ZyGames.Framework.Common.Security.CryptoHelper.MD5_Encrypt("Sally@123456"); au.level = 0xfffffff; cache.Add(au); }
public override bool TakeAction() { // 存入数据库 var hmdCache = new PersonalCacheStruct <HappyModeData>(); var cache = new ShareCacheStruct <PayOrder>(); int index = (int)cache.GetNextNo(); PayOrder PayData = new PayOrder(); string ServerOrderId = System.Guid.NewGuid().ToString("N"); int keyid = utils.KeyUInt2Int(requestPack.the3rdUserId); PayData.Index = index; PayData.UserId = requestPack.UserID; PayData.Identify = requestPack.identify; PayData.typeUser = requestPack.typeUser; // 360Pay..maybe PayData.ProductId = requestPack.productId; PayData.num = requestPack.num; PayData.the3rdUserId = keyid;// utils.KeyUInt2Int(requestPack.the3rdUserId); PayData.strThe3rdOrderId = requestPack.strThe3rdUserId; PayData.ServerOrderId = ServerOrderId; PayData.the3rdOrderId = ""; cache.Add(PayData); // hmd persion HappyModeData hmd = hmdCache.FindKey(keyid.ToString()); int happyPointMaxEnterNum = GameConfigMgr.Instance().getInt("happyPointMaxEnterNum", 3); if (null == hmd) { responsePack.errorCode = 1; return(true); } PayOrderPersion pop = new PayOrderPersion(); pop.Index = index; pop.UserId = requestPack.UserID; pop.Identify = requestPack.identify; pop.typeUser = requestPack.typeUser; // 360Pay..maybe pop.ProductId = requestPack.productId; pop.num = requestPack.num; pop.the3rdUsrID = (int)requestPack.the3rdUserId;// utils.KeyUInt2Int(requestPack.the3rdUserId); pop.strThe3rdOrderId = requestPack.strThe3rdUserId; pop.ServerOrderId = ServerOrderId; pop.the3rdOrderId = ""; hmd.PayInfoDic.Add(ServerOrderId, pop); // end return responsePack.errorCode = 0; responsePack.typeUser = requestPack.typeUser; responsePack.result = PayData.ServerOrderId; // 服务器订单号 ConsoleLog.showErrorInfo(0, "create order success" + requestPack.the3rdUserId + ":" + ServerOrderId); return(true); }
private void InitNotice() { var cacheSet = new ShareCacheStruct<Notice>(); for (int i = 0; i < 5; i++) { int id = (int)cacheSet.GetNextNo(); Notice notice = new Notice(id); notice.Title = "tile" + id; notice.Content = "Content" + id; notice.CreateDate = DateTime.Now; cacheSet.Add(notice); } }
private void InitNotice() { var cacheSet = new ShareCacheStruct <Notice>(); for (int i = 0; i < 5; i++) { int id = (int)cacheSet.GetNextNo(); Notice notice = new Notice(id); notice.Title = "tile" + id; notice.Content = "Content" + id; notice.CreateDate = DateTime.Now; cacheSet.Add(notice); } }
public void UnLoad() { var watch = Stopwatch.StartNew(); var cache = new ShareCacheStruct <SingleData>(); cache.UnLoad(); for (int i = 0; i < 10; i++) { cache.AddOrUpdate(new SingleData() { ChildId = cache.GetNextNo().ToInt() }); Thread.Sleep(100); } WaitEnd(watch); }
public override bool TakeAction() { var cache = new ShareCacheStruct<UserRanking>(); var ranking = cache.Find(m => m.UserName == userName); if (ranking == null) { var user = new GameUser() { UserId = (int)cache.GetNextNo(), NickName = userName }; new PersonalCacheStruct<GameUser>().Add(user); ranking = new UserRanking(); ranking.UserId = user.UserId; ranking.UserName = userName; ranking.Score = score; cache.Add(ranking); } else { ranking.UserName = userName; ranking.Score = score; } return true; }
void doAdd_allServerCompensation(string parm) { string[] strS = parm.Split(','); CompensationInfo ci = new CompensationInfo(); var cache = new ShareCacheStruct <CompensationInfo>(); int index = (int)cache.GetNextNo(); byte type = byte.Parse(strS[0]); string message = strS[1]; string ItemInfo = strS[2]; // 5012*1:5023*4 //check ci.index = index; ci.message = message; ci.ItemInfo = ItemInfo; ci.type = type; cache.Add(ci); }
public override bool TakeAction() { var cache = new ShareCacheStruct<UserRanking>(); var ranking = cache.Find(m => m.UserName == UserName); if (ranking == null) { ranking = new UserRanking(); ranking.UserID = (int)cache.GetNextNo(); ranking.UserName = UserName; ranking.Score = Score; cache.Add(ranking); } else { ranking.UserName = UserName; ranking.Score = Score; } return true; }
private User CreateUser(ShareCacheStruct <User> userCache) { var userData = new UserData() { UserId = (int)userCache.GetNextNo(), NickName = _loginData.Username, Hp = 100 }; _userData = userData; new PersonalCacheStruct <UserData>().Add(userData); var user = new User(); user.UserId = userData.UserId; user.Username = _loginData.Username; user.Password = _loginData.Password; userCache.Add(user); return(user); }
public override bool TakeAction() { var cache = new ShareCacheStruct <UserRanking>(); var ranking = cache.Find(m => m.UserName == UserName); if (ranking == null) { ranking = new UserRanking(); ranking.UserID = (int)cache.GetNextNo(); ranking.UserName = UserName; ranking.Score = Score; cache.Add(ranking); } else { ranking.UserName = UserName; ranking.Score = Score; } return(true); }
public void RemoveeCache() { var watch = Stopwatch.StartNew(); var cache = new ShareCacheStruct <ChildData>(); int key = (int)cache.GetNextNo(); var data = cache.FindKey(key); if (data == null) { data = new ChildData() { ChildId = key, Age = 20 }; Assert.IsTrue(cache.Add(data), "add cache faild."); } Assert.IsTrue(cache.Delete(data), "delete cache faild"); cache.UnLoad(); data = cache.FindKey(key); Assert.IsTrue(data == null, "delete cache faild."); WaitEnd(watch); }
public override bool TakeAction() { var cache = new ShareCacheStruct<UserScore>(); var ranking = cache.Find(m => m.username == _username); if (ranking == null) { var user = new User() { userid = (int)cache.GetNextNo(), nickname = _username }; new PersonalCacheStruct<User>().Add(user); ranking = new UserScore(); ranking.userid = user.userid; ranking.username = _username; ranking.score = _score; cache.Add(ranking); } else { ranking.username = _username; ranking.score = _score; } return true; }
void doAdd_HappyDataAddItem(string parm) { string[] stringS = parm.Split(','); int UserID = int.Parse(stringS[0]); int the3rdUserID = int.Parse(stringS[1]); int itemId = int.Parse(stringS[2]); var cache = new PersonalCacheStruct <HappyModeData>(); var hmd = cache.FindKey(stringS[1]); if (null == hmd) { return; } persionRealItemInfo rii = new persionRealItemInfo(); rii.Index = hmd.RealItemInfoLst.Count; rii.UserId = UserID; rii.the3rdUserId = the3rdUserID; rii.Identify = "GM_ADD"; rii.happyPoint = hmd.HappyPoint; rii.needHappyPoint = 0; rii.realItemID = itemId; hmd.RealItemInfoLst.Add(rii); // save to db for .... var shareRealItemCache = new ShareCacheStruct <shareRealItemInfo>(); shareRealItemInfo shareRII = new shareRealItemInfo(); shareRII.Index = (int)shareRealItemCache.GetNextNo(); shareRII.UserId = UserID; shareRII.the3rdUserId = the3rdUserID; shareRII.Identify = "GM_ADD"; shareRII.happyPoint = hmd.HappyPoint; shareRII.needHappyPoint = 0; shareRII.realItemID = itemId; shareRealItemCache.Add(shareRII); }
public void AddProcessCache() { var watch = Stopwatch.StartNew(); int userId = 1157; int questIdx = 345; var questProcessCache = new ShareCacheStruct <QuestProcess>(); var list = new List <QuestProcess>(); int repNum = 0; long no = questProcessCache.GetNextNo(true); Trace.WriteLine("running time:" + watch.ElapsedMilliseconds); uint count = 20000; for (int i = 0; i < count; i++) { QuestProcess qProcess = new QuestProcess(); qProcess.Suoyin = Convert.ToInt32(no); qProcess.Character = userId; qProcess.QuestIndex = questIdx; qProcess.RegisterDate = DateTime.Now; if (qProcess.Suoyin >= 10000 && qProcess.Suoyin < 10001) { Trace.WriteLine("GetNextNo:" + no); Trace.WriteLine("json:" + JsonUtils.SerializeCustom(qProcess)); repNum++; } list.Add(qProcess); no++; } questProcessCache.SetNoAddCount(count); Trace.WriteLine("running time:" + watch.ElapsedMilliseconds); Assert.IsTrue(questProcessCache.AddRange(list)); WaitEnd(watch); //Assert.IsTrue(repNum > 1); }
void addAuthory() { var cache = new ShareCacheStruct<Authority>(); Authority au = new Authority(); au.id = (int)cache.GetNextNo(); au.name = "guccang"; au.pwd = ZyGames.Framework.Common.Security.CryptoHelper.MD5_Encrypt("Sally@123456"); au.level = 0xfffffff; cache.Add(au); }
public override bool TakeAction() { // 存入数据库 var hmdCache = new PersonalCacheStruct<HappyModeData>(); var cache = new ShareCacheStruct<PayOrder>(); int index = (int)cache.GetNextNo(); PayOrder PayData = new PayOrder(); string ServerOrderId = System.Guid.NewGuid().ToString("N"); int keyid = utils.KeyUInt2Int(requestPack.the3rdUserId); PayData.Index = index; PayData.UserId = requestPack.UserID; PayData.Identify = requestPack.identify; PayData.typeUser = requestPack.typeUser; // 360Pay..maybe PayData.ProductId = requestPack.productId; PayData.num = requestPack.num; PayData.the3rdUserId = keyid;// utils.KeyUInt2Int(requestPack.the3rdUserId); PayData.strThe3rdOrderId = requestPack.strThe3rdUserId; PayData.ServerOrderId = ServerOrderId; PayData.the3rdOrderId = ""; cache.Add(PayData); // hmd persion HappyModeData hmd = hmdCache.FindKey(keyid.ToString()); int happyPointMaxEnterNum = GameConfigMgr.Instance().getInt("happyPointMaxEnterNum", 3); if (null == hmd) { responsePack.errorCode = 1; return true; } PayOrderPersion pop = new PayOrderPersion(); pop.Index = index; pop.UserId = requestPack.UserID; pop.Identify = requestPack.identify; pop.typeUser = requestPack.typeUser; // 360Pay..maybe pop.ProductId = requestPack.productId; pop.num = requestPack.num; pop.the3rdUsrID = (int)requestPack.the3rdUserId;// utils.KeyUInt2Int(requestPack.the3rdUserId); pop.strThe3rdOrderId = requestPack.strThe3rdUserId; pop.ServerOrderId = ServerOrderId; pop.the3rdOrderId = ""; hmd.PayInfoDic.Add(ServerOrderId, pop); // end return responsePack.errorCode = 0; responsePack.typeUser = requestPack.typeUser; responsePack.result = PayData.ServerOrderId; // 服务器订单号 ConsoleLog.showErrorInfo(0,"create order success"+requestPack.the3rdUserId+":"+ServerOrderId); return true; }
static Response1001Pack cbFunc(object obj) { List<object> objList = obj as List<object>; if (objList.Count != 2) return null; List<UserRanking> rankingList = objList[1] as List<UserRanking>; // save to ....where.... var shareCache = new ShareCacheStruct<HistoryUserRanking>(); int num = (int)shareCache.GetNextNo(); var saveData = new HistoryUserRanking(); saveData.ID = num; // get data if (rankingList.Count >= 3) { UserRanking first = rankingList[0]; UserRanking second = rankingList[1]; UserRanking thrid = rankingList[2]; saveData.Items.Add(first); saveData.Items.Add(second); saveData.Items.Add(thrid); } shareCache.Add(saveData); return null; }
public override bool TakeAction() { int itemIndex = requestPack.realItemID; // int var happyPersionCache = new PersonalCacheStruct <HappyModeData>(); int keyId = utils.KeyUInt2Int(requestPack.the3rdUserID); HappyModeData hmd = happyPersionCache.FindKey(keyId.ToString()); if (hmd == null) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_happymodedata; return(true); } // happData 01 memoryRealInfoDataModel.HappyData happyData = GameConfigMgr.Instance().getHappyData(requestPack.realItemID); if (null == happyData) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_happPointConfig; return(true); } // share realitem modify 02 var itemcntCache = new ShareCacheStruct <ShareRealItemCnt>(); ShareRealItemCnt sric = itemcntCache.FindKey(requestPack.realItemID); if (null == sric) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_item_cnt_data; return(true); } if (false == checkRefleshReplace(hmd, happyData)) { return(true); } int needHappyPoint = happyData.needHappyPoint; // 配置文件总获得 if (hmd.HappyPoint < needHappyPoint) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_enought_happyPoint; return(true); } if (sric.num <= 0) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.realitem_is_empty; return(true); } bool buyOK = false; if (sric.num > 0) { sric.ModifyLocked(() => { sric.num -= 1; if (sric.num >= 0) { buyOK = true; } }); } if (false == buyOK) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.realitem_is_empty; return(true); } persionRealItemInfo rii = new persionRealItemInfo(); rii.Index = hmd.RealItemInfoLst.Count; rii.UserId = requestPack.UserID; rii.the3rdUserId = utils.KeyUInt2Int(requestPack.the3rdUserID); rii.Identify = requestPack.identify; rii.happyPoint = hmd.HappyPoint; rii.needHappyPoint = needHappyPoint; rii.realItemID = requestPack.realItemID; hmd.RealItemInfoLst.Add(rii); // save to db for .... var shareRealItemCache = new ShareCacheStruct <shareRealItemInfo>(); shareRealItemInfo shareRII = new shareRealItemInfo(); shareRII.Index = (int)shareRealItemCache.GetNextNo(); shareRII.UserId = requestPack.UserID; shareRII.the3rdUserId = utils.KeyUInt2Int(requestPack.the3rdUserID); shareRII.Identify = requestPack.identify; shareRII.happyPoint = hmd.HappyPoint; shareRII.needHappyPoint = needHappyPoint; shareRII.realItemID = requestPack.realItemID; shareRealItemCache.Add(shareRII); hmd.ModifyLocked(() => { hmd.HappyPoint -= needHappyPoint; hmd.realItemBuyCntInRefleshTime[itemIndex].cnt = hmd.realItemBuyCntInRefleshTime[itemIndex].cnt + 1; }); responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.ok; responsePack.realItemID = rii.realItemID; return(true); }
public override bool TakeAction() { int itemIndex = requestPack.realItemID; // int var happyPersionCache = new PersonalCacheStruct<HappyModeData>(); int keyId = utils.KeyUInt2Int(requestPack.the3rdUserID); HappyModeData hmd = happyPersionCache.FindKey(keyId.ToString()); if(hmd == null) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_happymodedata; return true; } // happData 01 memoryRealInfoDataModel.HappyData happyData = GameConfigMgr.Instance().getHappyData(requestPack.realItemID); if (null == happyData) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_happPointConfig; return true; } // share realitem modify 02 var itemcntCache = new ShareCacheStruct<ShareRealItemCnt>(); ShareRealItemCnt sric = itemcntCache.FindKey(requestPack.realItemID); if(null == sric) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_item_cnt_data; return true; } if(false == checkRefleshReplace(hmd,happyData)) { return true; } int needHappyPoint = happyData.needHappyPoint; // 配置文件总获得 if (hmd.HappyPoint < needHappyPoint) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_enought_happyPoint; return true; } if(sric.num <= 0) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.realitem_is_empty; return true; } bool buyOK = false; if(sric.num>0) { sric.ModifyLocked(() => { sric.num -= 1; if (sric.num >= 0) buyOK = true; }); } if (false == buyOK) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.realitem_is_empty; return true; } persionRealItemInfo rii = new persionRealItemInfo(); rii.Index = hmd.RealItemInfoLst.Count; rii.UserId = requestPack.UserID; rii.the3rdUserId = utils.KeyUInt2Int( requestPack.the3rdUserID); rii.Identify = requestPack.identify; rii.happyPoint = hmd.HappyPoint; rii.needHappyPoint = needHappyPoint; rii.realItemID = requestPack.realItemID; hmd.RealItemInfoLst.Add(rii); // save to db for .... var shareRealItemCache = new ShareCacheStruct<shareRealItemInfo>(); shareRealItemInfo shareRII = new shareRealItemInfo(); shareRII.Index = (int)shareRealItemCache.GetNextNo(); shareRII.UserId = requestPack.UserID; shareRII.the3rdUserId = utils.KeyUInt2Int( requestPack.the3rdUserID); shareRII.Identify = requestPack.identify; shareRII.happyPoint = hmd.HappyPoint; shareRII.needHappyPoint = needHappyPoint; shareRII.realItemID = requestPack.realItemID; shareRealItemCache.Add(shareRII); hmd.ModifyLocked(() => { hmd.HappyPoint -= needHappyPoint; hmd.realItemBuyCntInRefleshTime[itemIndex].cnt = hmd.realItemBuyCntInRefleshTime[itemIndex].cnt + 1; }); responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.ok; responsePack.realItemID = rii.realItemID; return true; }
public override bool TakeAction() { ShareCacheStruct <UserInfo> cache = new ShareCacheStruct <UserInfo>(); var listUser = cache.FindAll(t => t.Account == mUserName); UserInfo userInfo = null; if (listUser.Count >= 1) { userInfo = listUser[0]; } if (userInfo == null) { userInfo = new UserInfo(); userInfo.UserId = (int)cache.GetNextNo(); userInfo.Account = mUserName; userInfo.Platform = mPlatform; userInfo.DeviceID = mDeviceID; userInfo.DeviceModel = mDeviceModel; userInfo.DeviceType = mDeviceType; userInfo.RegisterTime = DateTime.Now; userInfo.LastLoginTime = DateTime.Now; userInfo.Token = 1; if (!cache.Add(userInfo)) { Console.WriteLine("Regist UserInfo Failed!"); } mRegist = true; } else { mNickName = userInfo.NickName; userInfo.ModifyLocked(() => { userInfo.Account = mUserName; userInfo.Platform = mPlatform; userInfo.DeviceID = mDeviceID; userInfo.DeviceModel = mDeviceModel; userInfo.DeviceType = mDeviceType; userInfo.LastLoginTime = DateTime.Now; userInfo.Token = userInfo.Token + 1; }); mRegist = false; if (string.IsNullOrEmpty(mNickName)) { mRegist = true; } } int uid = (int)userInfo.UserId; SessionUser user = new SessionUser(); user.UserId = uid; GameSession session = httpGet.GetSession(); var OldSession = GameSession.Get(uid); if (OldSession != null) { OldSession.Close(); } session.Bind(user); return(true); }
void addLog(ShareCacheStruct<DataLog> cache, int userid, int dimond) { int index = (int)cache.GetNextNo(); DataLog dl = new DataLog(); dl.Index = index; dl.UserID = userid; dl.Dimond = dimond; cache.Add(dl); }
void InitNotices() { /* * new ShareCacheStruct<Notice> 实际上不是一个存储空间, * 而是指向redis数据库的一个入口, * 这里通过指定类型Notice来获得Notice表的指针, * 然后就可以做查询或修改操作 * * public abstract class BaseCacheStruct<T> : BaseDisposable where T : AbstractEntity, new() * { * static BaseCacheStruct() * { * // 这里根据<T>中的类型来确定表的名字, * // 再根据T上面的EntityTable来确定连接的数据库, * // [EntityTable(CacheType.Entity, "TestGameData")] * // * // 如果已经有表就操作表,没有就新建后操作, * // 如果使用这个接口来将数据直接保存到sql数据库中的话,需要连接数据库,而且可能操作磁盘 * EntitySchemaSet.InitSchema(typeof(T)); * CacheFactory.RegistUpdateNotify(new DefaultCacheStruct<T>()); * } * ... * } */ var cacheSet = new ShareCacheStruct<Notice>(); for (int i = 0; i < 50; i++) { int id = (int)cacheSet.GetNextNo(); Notice notice = new Notice(id); notice.title = "tile" + id; notice.content = "Content" + id; notice.time = DateTime.Now; cacheSet.Add(notice); } }