private void Logout() { Token = null; if (User != null) { User.PostOffice.Deactivate(); // deactivate mailbox User.IsOnline = false; this.User = null; } this.Phase = ConnectionPhase.P1Connected; }
/// <summary> /// update user info, if the specified user does not exist(identified by UsernName), then a new user will be created. /// </summary> /// <param name="iuser"></param> public void Update(IUser iuser) { rwlsDictName2User.EnterUpgradeableReadLock(); if (dictName2User.ContainsKey(iuser.Name)) { var oldUser = dictName2User[iuser.Name]; oldUser.UpdateServerUserInfo(iuser); } else { var newUser = new ServerUser(iuser); Register(newUser); } rwlsDictName2User.ExitUpgradeableReadLock(); }
protected override void ProcessRequest(ref EMessage msg) { if (server.BlockMessage != null) { msg = new EMError(msg, server.BlockMessage, ErrorCode.ServerBlocked); } else if (msg.HasFlag(StatusCode.Login)) { var login = msg as EMLogin; bool hasLoggedIn; hasLoggedIn = server.MailCenter.IsOnline(login.Username); if (hasLoggedIn) { server.PushOut(login.Username, $"You have been signed out because your account is logged in elsewhere."); } if (server.MailCenter.Contains(login.Username)) { var user = server.MailCenter.GetUser(login.Username, login.Password); if (user != null) { TeleClientName = login.Username; this.logger.SetOwner(TeleClientName); // reset owner of logger User = user; Token = server.GenToken(TeleClientName); msg = new EMLoggedin(login, ClientName, user, Token); msg.Status |= StatusCode.Duplex; // sync time command logger.SetOwner(TeleClientName); Phase = ConnectionPhase.P2LoggedIn; user.PostOffice.Activate(this); // activate mailbox user.IsOnline = true; (msg as EMLoggedin).ServerTime = server.Now; // set sync time } else { msg = new EMError(msg, $"incorrect username/password.", ErrorCode.IncorrectUsernameOrPassword); } } else { msg = new EMError(msg, $"user '{login.Username}' is not registered.", ErrorCode.UnregisteredUser); } } else if (User == null || !User.IsOnline) { msg = new EMError(msg, "please login first."); } else if (msg.HasFlag(StatusCode.Logout)) { Logout(); msg = new EMessage(msg, StatusCode.Ok); } else if (msg.HasFlag(StatusCode.Letter)) { var letter = msg as EMLetter; try { var result = server.MailCenter.Deliver(letter); if (result == null) { msg = new EMessage(msg, StatusCode.Ok); // Post, or SafePost } else { result.SetEnvelope(new Envelope(msg.ID)); msg = result; } } catch (Exception ex) { msg = new EMError(msg, ex.Message); } } else if (msg.HasFlag(StatusCode.Register)) { if (msg.HasFlag(StatusCode.Entity)) { var entityNames = (msg as EMText).Text.Split(','); foreach (var name in entityNames) { User.PostOffice.Register(name); } msg = new EMessage(msg, StatusCode.Ok); } } else { msg = new EMError(msg, $"current request is not supported by this server.", ErrorCode.InvalidOperation); } }
public void Destroy() { this.client.Dispose(); this.client = null; this.User = null; }
public ServerPostOffice(ServerUser owner) { this.owner = owner; this.dispatcherMutex = new Mutex(); }
public void Destroy() { this.owner = null; this.dispatcher = null; }