public PacketRelayPlayerHandoffRequest() : base() { m_TargetResource = Guid.Empty; Profile = new AccountProfile("-"); OwningServer = ""; }
private void OnUserDetailRequest(INetworkConnection con, Packet r) { Log1.Logger("Zeus.Inbound.Client").Debug("User detail request from " + ServerUser.AccountName + "."); PacketGenericMessage msg = r as PacketGenericMessage; Guid user = msg.Parms.GetGuidProperty(2); WispUserDetail ud = new WispUserDetail(); r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, ""); r.ReplyPacket.Parms.SetProperty(1, MyServer.ServerUserID); r.ReplyPacket.Parms.SetProperty(2, ud); MembershipUser usr = Membership.GetUser(user, false); if (usr == null) { r.ReplyPacket.ReplyCode = ReplyType.Failure; r.ReplyPacket.ReplyMessage = "User not found."; } else { ud.Email = usr.Email; ud.ID = user; ud.IsApproved = usr.IsApproved; ud.IsLocked = usr.IsLockedOut; ud.LastLogin = usr.LastLoginDate.ToUniversalTime(); ud.LastPasswordChange = usr.LastPasswordChangedDate.ToUniversalTime(); ud.Roles.AddRange(Roles.GetRolesForUser(usr.UserName)); ud.Username = usr.UserName; ud.UserSince = usr.CreationDate; ServerUser su = ConnectionManager.GetAuthorizedUser(usr.UserName, MyServer, PacketLoginRequest.ConnectionType.AssistedTransfer); ud.IsOnline = su != null; if (su != null) { ud.CurrentLoginTime = su.Profile.CurrentLoginTime; } AccountProfile prof = null; prof = new AccountProfile(usr.UserName); prof.Load(MyServer.RequireAuthentication); ud.AddedProperties = prof.AddedProperties; ud.LoginSessions = new List <AccountProfile.Session>(prof.AllSessions); if (!DB.Instance.User_GetServiceLogEntries(user, "", ud.ServiceNotes)) { ServiceLogEntry sle = new ServiceLogEntry(); sle.EntryBy = "System"; sle.Note = "Unable to retrieve service log entries from database."; ud.ServiceNotes.Add(sle); } ud.Characters = CharacterUtil.Instance.GetCharacterListing(user); } }
public override bool DeSerialize(byte[] data, Pointer p) { base.DeSerialize(data, p); Profile = (AccountProfile)BitPacker.GetSerializableWispObject(data, p); TargetResource = new Guid(BitPacker.GetString(data, p)); Player = new Guid(BitPacker.GetString(data, p)); AuthTicket = new Guid(BitPacker.GetString(data, p)); AccountName = BitPacker.GetString(data, p); return(true); }
private MembershipUser CreateNewAccount(string accountName, string password, string email, string[] roles, ref string msg) { bool rslt = true; MembershipUser newUser = null; // try creating a new account for this user try { MembershipCreateStatus status; newUser = Membership.CreateUser(accountName, password, email, null, null, true, out status); if (newUser == null) { rslt = false; msg = string.Format("Unable to create new user. " + GetCreateNewUserError(status)); } if (rslt) { ServerUser.ID = (Guid)newUser.ProviderUserKey; AccountProfile prof = new AccountProfile(newUser.UserName); prof.UserRoles = roles; if (roles == null || roles.Length < 1 || Array.IndexOf(roles, "ActiveUser") == -1) { string[] rolesEx = null; if (roles != null) { rolesEx = new string[roles.Length + 1]; Array.Copy(roles, rolesEx, roles.Length); } else { rolesEx = new string[1]; } rolesEx[rolesEx.Length - 1] = "ActiveUser"; prof.UserRoles = rolesEx; } prof.Save(MyServer.RequireAuthentication); } //--------------- } catch (Exception exc) { rslt = false; msg = "Unknow error creating user."; } return(newUser); }
/// <summary> /// Requests that a player be connected to the cluster server /// </summary> /// <param name="userId">the id of the account to be transferred</param> /// <param name="accountName">the name of the account to be transferred</param> /// <param name="remotePlayerEndpoint">the remote endpoint of the transferee</param> /// <param name="targetResource">the target content resource the player wants, or Guid.Empy if none</param> /// <param name="accountProperties">the account properties of the account to transfer</param> /// <param name="owningServer">the server in the cluster that owns the server. See ServerUser.Owner</param> public void RequestPlayerHandoff(Guid userId, string accountName, Guid targetResource, AccountProfile profile, ServerCharacterInfo characterToTransfer, string owningServer) { // request auth ticket from game server PacketRelayPlayerHandoffRequest p = (PacketRelayPlayerHandoffRequest)CreatePacket((int)ServerPacketType.RequestPlayerHandoff, 0, false, false); p.NeedsReply = true; p.Player = userId; p.SharedSecret = MyServer.SharedClusterServerSecret; p.AccountName = accountName; p.TargetResource = targetResource; p.Profile = profile; p.OwningServer = owningServer; p.Character = characterToTransfer; characterToTransfer.TargetResource = targetResource; Log1.Logger("Server.Inbound.Network").Info("Requesting authenticated client *" + p.AccountName + "* to be handed off to game server " + ServerUser.AccountName + "."); Send(p); }
public PacketPlayerAuthorizedForTransfer() : base() { Profile = new AccountProfile("-"); }
/// <summary> /// Requests that a player be connected to the cluster server /// </summary> /// <param name="userId">the id of the account to be transferred</param> /// <param name="accountName">the name of the account to be transferred</param> /// <param name="remotePlayerEndpoint">the remote endpoint of the transferee</param> /// <param name="targetResource">the target content resource the player wants, or Guid.Empy if none</param> /// <param name="accountProperties">the account properties of the account to transfer</param> /// <param name="owningServer">the server in the cluster that owns the server. See ServerUser.Owner</param> public void RequestPlayerHandoff(Guid userId, string accountName, Guid targetResource, AccountProfile profile, ServerCharacterInfo characterToTransfer, string owningServer) { // request auth ticket from game server PacketRelayPlayerHandoffRequest p = (PacketRelayPlayerHandoffRequest)CreatePacket((int)ServerPacketType.RequestPlayerHandoff, 0, false, false); p.NeedsReply = true; p.Player = userId; p.SharedSecret = Server.SharedClusterServerSecret; p.AccountName = accountName; p.TargetResource = targetResource; p.Profile = profile; p.OwningServer = owningServer; p.Character = characterToTransfer; Log1.Logger("Server.Outbound.Network").Info("Requesting authenticated client *" + p.AccountName + "* to be handed off to game server " + Name + "."); Send(p); }
/// <summary> /// Returns the authorized user object, or null if the user isn't currently authorized /// </summary> /// <param name="account"></param> /// <returns></returns> public static ServerUser GetAuthorizedUser(string account, ServerBase server, PacketLoginRequest.ConnectionType conType) { ServerUser u = null; if (conType == PacketLoginRequest.ConnectionType.AssistedTransfer) { lock (m_AuthorizedAccountsSyncRoot) { AuthorizedAccounts.TryGetValue(account.ToLower(), out u); } } else if (conType == PacketLoginRequest.ConnectionType.UnassistedTransfer) { Guid ticket = Guid.Empty; string authServer = ""; DateTime whenAuthd = DateTime.MinValue; int character = -1; string targetServerID = ""; Guid accountID = Guid.Empty; if (!DB.Instance.User_GetAuthorizationTicket(account, out authServer, out ticket, out whenAuthd, out character, out targetServerID, out accountID) || ticket == Guid.Empty) { return(null); } if (targetServerID != server.ServerUserID) { // we weren't authorized to be on this server. Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer to [" + server.ServerUserID + "], but that user was only authorized to transfer to target server ID [" + targetServerID + "]. Connection denied."); return(null); } if (whenAuthd + AuthTicketLifetime < DateTime.UtcNow) { // ticket expired. Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer to [" + server.ServerUserID + "], but that user's auth ticket is expired. Connection denied."); return(null); } // Got a ticket. Load up the user from the DB. u = new ServerUser(); u.OwningServer = server.ServerUserID; u.AuthTicket = ticket; u.ID = accountID; u.AccountName = account; // load the profile AccountProfile ap = new AccountProfile(account); u.Profile = ap; ap.Load(server.RequireAuthentication); // load the character if (character > -1) { string msg = ""; u.CurrentCharacter = CharacterUtil.Instance.LoadCharacter(u, character, ref msg); if (u.CurrentCharacter == null) { // Couldn't load character. Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer with characer [" + character + "], but that character could not be loaded from the DB: [" + msg + "]. Connection denied."); return(null); } u.CurrentCharacter.OwningAccount = u; CharacterCache.CacheCharacter(u.CurrentCharacter, server.ServerUserID); } } AuthorizeUser(u); // gotta call this to activate/renew the auth ticket on this server. return(u); }
/// <summary> /// Returns the authorized user object, or null if the user isn't currently authorized /// </summary> /// <param name="account"></param> /// <returns></returns> public static ServerUser GetAuthorizedUser(string account, ServerBase server, PacketLoginRequest.ConnectionType conType) { ServerUser u = null; if (conType == PacketLoginRequest.ConnectionType.AssistedTransfer) { lock (m_AuthorizedAccountsSyncRoot) { AuthorizedAccounts.TryGetValue(account.ToLower(), out u); } } else if (conType == PacketLoginRequest.ConnectionType.UnassistedTransfer) { Guid ticket = Guid.Empty; string authServer = ""; DateTime whenAuthd = DateTime.MinValue; int character = -1; string targetServerID = ""; Guid accountID = Guid.Empty; if (!DB.Instance.User_GetAuthorizationTicket(account, out authServer, out ticket, out whenAuthd, out character, out targetServerID, out accountID) || ticket == Guid.Empty) { return null; } if (targetServerID != server.ServerUserID) { // we weren't authorized to be on this server. Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer to [" + server.ServerUserID + "], but that user was only authorized to transfer to target server ID [" + targetServerID+ "]. Connection denied."); return null; } if (whenAuthd + AuthTicketLifetime < DateTime.UtcNow) { // ticket expired. Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer to [" + server.ServerUserID + "], but that user's auth ticket is expired. Connection denied."); return null; } // Got a ticket. Load up the user from the DB. u = new ServerUser(); u.OwningServer = server.ServerUserID; u.AuthTicket = ticket; u.ID = accountID; u.AccountName = account; // load the profile AccountProfile ap = new AccountProfile(account); u.Profile = ap; ap.Load(server.RequireAuthentication); // load the character if (character > -1) { string msg = ""; u.CurrentCharacter = CharacterUtil.Instance.LoadCharacter(u, character, ref msg); if (u.CurrentCharacter == null) { // Couldn't load character. Log1.Logger(server.ServerUserID).Error("[" + account + "] attempted unassisted transfer with characer [" + character + "], but that character could not be loaded from the DB: [" + msg + "]. Connection denied."); return null; } u.CurrentCharacter.OwningAccount = u; CharacterCache.CacheCharacter(u.CurrentCharacter, server.ServerUserID); } } AuthorizeUser(u); // gotta call this to activate/renew the auth ticket on this server. return u; }
private MembershipUser CreateNewAccount(string accountName, string password, string email, string[] roles, ref string msg) { bool rslt = true; MembershipUser newUser = null; // try creating a new account for this user try { MembershipCreateStatus status; newUser = Membership.CreateUser(accountName, password, email, null, null, true, out status); if (newUser == null) { rslt = false; msg = string.Format("Unable to create new user. " + GetCreateNewUserError(status)); } if (rslt) { ServerUser.ID = (Guid)newUser.ProviderUserKey; AccountProfile prof = new AccountProfile(newUser.UserName); prof.UserRoles = roles; if (roles == null || roles.Length < 1 || Array.IndexOf(roles, "ActiveUser") == -1) { string[] rolesEx = null; if (roles != null) { rolesEx = new string[roles.Length + 1]; Array.Copy(roles, rolesEx, roles.Length); } else { rolesEx = new string[1]; } rolesEx[rolesEx.Length - 1] = "ActiveUser"; prof.UserRoles = rolesEx; } prof.Save(MyServer.RequireAuthentication); } //--------------- } catch (Exception exc) { rslt = false; msg = "Unknow error creating user."; } return newUser; }
private void OnUserDetailRequest(INetworkConnection con, Packet r) { Log1.Logger("Zeus.Inbound.Client").Debug("User detail request from " + ServerUser.AccountName + "."); PacketGenericMessage msg = r as PacketGenericMessage; Guid user = msg.Parms.GetGuidProperty(2); WispUserDetail ud = new WispUserDetail(); r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, ""); r.ReplyPacket.Parms.SetProperty(1, MyServer.ServerUserID); r.ReplyPacket.Parms.SetProperty(2, ud); MembershipUser usr = Membership.GetUser(user, false); if (usr == null) { r.ReplyPacket.ReplyCode = ReplyType.Failure; r.ReplyPacket.ReplyMessage = "User not found."; } else { ud.Email = usr.Email; ud.ID = user; ud.IsApproved = usr.IsApproved; ud.IsLocked = usr.IsLockedOut; ud.LastLogin = usr.LastLoginDate.ToUniversalTime(); ud.LastPasswordChange = usr.LastPasswordChangedDate.ToUniversalTime(); ud.Roles.AddRange(Roles.GetRolesForUser(usr.UserName)); ud.Username = usr.UserName; ud.UserSince = usr.CreationDate; ServerUser su = ConnectionManager.GetAuthorizedUser(usr.UserName, MyServer, PacketLoginRequest.ConnectionType.AssistedTransfer); ud.IsOnline = su != null; if (su != null) { ud.CurrentLoginTime = su.Profile.CurrentLoginTime; } AccountProfile prof = null; prof = new AccountProfile(usr.UserName); prof.Load(MyServer.RequireAuthentication); ud.AddedProperties = prof.AddedProperties; ud.LoginSessions = new List<AccountProfile.Session>(prof.AllSessions); if (!DB.Instance.User_GetServiceLogEntries(user, "", ud.ServiceNotes)) { ServiceLogEntry sle = new ServiceLogEntry(); sle.EntryBy = "System"; sle.Note = "Unable to retrieve service log entries from database."; ud.ServiceNotes.Add(sle); } ud.Characters = CharacterUtil.Instance.GetCharacterListing(user); } }