/// <summary> /// 创建账号 /// </summary> /// <param name="token"></param> /// <param name="dto"></param> public void Create(UserToken token, AccountDto dto) { //验证账号密码的合法性 if (string.IsNullOrEmpty(dto.Account) || string.IsNullOrEmpty(dto.Password)) { //当账号或者密码为空的时候 //因为下面内容经常使用,所以就建一个扩展UserToken的类,内置这些内容; //NetModle modle = new NetModle(); //modle.Type = Protocol.Common; //modle.Command = CommonProtocol.S2C_ErrorCode; //modle.Message = ErrorCode.AccountPasswordIsNotSafe;//主要目的!把错误信息打包进modle中,发给客户端看 //token.Send(modle); ExUserToken.Send(token, ErrorCode.AccountPasswordIsNotSafe); return; } //验证账号是否被注册,需要调用缓存层进行验证 if (accountCache.HasAccount(dto.Account)) { token.Send(ErrorCode.AccountHasRegister); return; } //调用缓存层创建账号 accountCache.Add(token, dto); //通知客户端注册账号成功 token.Send(Protocol.Login, LoginProtocol.S2C_Login); }
private int Login(UserToken token, string username, string password) { if (username == null || password == null || username.Equals("") || password.Equals("") || !cacheInstance.HasAccount(username) || cacheInstance.IsOnline(username) || !cacheInstance.Match(username, password)) { return(Protocol.COMMAND_LOGIN_FAIL); } cacheInstance.Online(token, username); return(Protocol.COMMAND_LOGIN_SUCCESS); }
private int Register(RegisterUserInfo userInfo) { if (userInfo.Username == null || userInfo.Password == null || userInfo.Nickname == null || userInfo.Username.Equals("") || userInfo.Password.Equals("") || userInfo.Nickname.Equals("") || cacheInstance.HasAccount(userInfo.Username)) { return(Protocol.COMMAND_REGISTER_FAIL); } //写入数据库 AccountTable.AddNewAccount(userInfo); cacheInstance.Add(userInfo.Username, userInfo.Password); userCacheInstance.addUser(userInfo); return(Protocol.COMMAND_REGISTER_SUCCESS); }
/// <summary> /// 注册处理 /// </summary> private void register(MyClient client, AccountDto account) { OperationResponse response = new OperationResponse((byte)OpCode.Account, new Dictionary <byte, object>()); response.Parameters[80] = AccountCode.Register; if (cache.HasAccount(account.Account)) { response.DebugMessage = "账号已存在."; response.ReturnCode = -1; client.SendOperationResponse(response, new SendParameters()); return; } else { cache.Add(account.Account, account.Password); response.DebugMessage = "注册成功."; response.ReturnCode = 0; client.SendOperationResponse(response, new SendParameters()); } }