public override bool TakeAction() { GameUser user = null; BaseUser usertype = null; int userid = 0; if ((null != _useridreq) &&("" != _useridreq)) { userid = Convert.ToInt32(_useridreq); } /*获取用户信息*/ GameUser userinfo = new GameUser(userid); userinfo.UserName = _username; userinfo.UserType = _usertype; userinfo.ClientOS = _clientos; userinfo.ClientVersion = _clientversion; if (userinfo.UserType != "guest") { usertype = new ExternalAccountTypeUser(userinfo); } else { usertype = new GuestTypeUser(userinfo); } /*插入新的用户*/ if (false == usertype.IsExistGameUser() && (true == usertype.BUserInfo.IsValid)) { usertype.CreateGameuser(); } if (false == usertype.BUserInfo.IsValid) { return false; } user = usertype.GetGameuserInfo(); /*返回UserID信息、Magic以及存档信息(如果有的话)给客户端*/ if (null != user) { _usermagic = user.UserMagic; _useridres = user.UserId.ToString(); _clientarchive = user.ClientArchive; return true; } return false; }
public BaseUser(GameUser user) { _userinfo = new GameUser(user.UserId); /*传入客户端上报过来的用户信息*/ _userinfo.UserName = user.UserName; _userinfo.UserType = user.UserType; _userinfo.ClientOS = user.ClientOS; _userinfo.ClientVersion = user.ClientVersion; _userinfo.UserMagic = RandomGen.Instance.UserMagic; _userinfo.UserBirthday = DateTime.Now; _buserinfo = new BriefUserInfo(); }
/// <summary> /// 创建用户 /// </summary> public GameUser CreateGameuser() { GameUser newuser = new GameUser(_buserinfo.UserId); newuser.UserName = _userinfo.UserName; newuser.UserType = _userinfo.UserType; newuser.ClientOS = _userinfo.ClientOS; newuser.ClientVersion = _userinfo.ClientVersion; newuser.UserMagic = _userinfo.UserMagic; newuser.UserBirthday = _userinfo.UserBirthday; var cacheSet = new GameDataCacheSet<GameUser>(); cacheSet.Add(newuser); cacheSet.Update(); return _userinfo; }
public override bool IsExistGameUser() { /*直接通过直接访问数据库的方式查询用户*/ GameUserRef userref = new GameUserRef(_userinfo); _buserinfo.UserId = userref.GetUserId(); if (0 == _buserinfo.UserId) { _buserinfo.UserId = userref.InsertGameUser(); if (0 == _buserinfo.UserId) { _buserinfo.IsValid = false; return false; } _userinfo.UserName = _buserinfo.UserId.ToString(); /*更新用户索引表*/ GameUser updateuser = new GameUser(_buserinfo.UserId); updateuser.UserName = _buserinfo.UserId.ToString(); updateuser.UserType = _userinfo.UserType; GameUserRef userupdateref = new GameUserRef(updateuser); userupdateref.UpdateGameUser(); } else { /*客户端上送的用户信息是错的*/ if ((0 != _userinfo.UserId) && (_userinfo.UserId != _buserinfo.UserId)) { _buserinfo.IsValid = false; return false; } } /*尝试刷新缓存,并且检测用户是否给的UserID是否正确*/ var usercache = new GameDataCacheSet<GameUser>().FindKey(_buserinfo.UserId.ToString()); if (null != usercache) { _buserinfo.IsValid = true; return true; } /*插入新的用户*/ else { _buserinfo.IsValid = true; return false; } }
public ExternalAccountTypeUser(GameUser user) : base(user) { }
public GuestTypeUser(GameUser user) : base(user) { }
public GameUserRef(GameUser gameuser) { _gameuser = gameuser; }