/// <summary> /// Begin an asynchronous connection attempt /// </summary> /// <param name="serverAddress">the address of the target server.</param> /// <param name="port">the port of the target server</param> /// <param name="username">the username with which to authenticate, if any</param> /// <param name="password">the password with which to authenticate, if any</param> public void BeginConnect(string serverAddress, int port, string username, string password, PacketLoginRequest.ConnectionType connectionType) { if (IsAlive || ConnectionInProgress || ConnectionWasInitiated) { return; } if (username == null) { username = ""; } if (password == null) { password = ""; } m_ConnectionType = connectionType; Log.LogMsg("Connecting to " + serverAddress + ":" + port.ToString() + " as " + username); m_ConnectionWasInitiated = true; m_ConnectionInProgress = true; AccountName = username; Password = password; m_ServerAddress = serverAddress; m_Port = port; Log.LogMsg("Resolving host [" + serverAddress + "]"); Dns.BeginGetHostAddresses(serverAddress, new AsyncCallback(OnHostResolve), null); }
/// <summary> /// Begin an asynchronous connection attempt /// </summary> /// <param name="serverAddress">the address of the target server.</param> /// <param name="port">the port of the target server</param> /// <param name="username">the username with which to authenticate, if any</param> /// <param name="password">the password with which to authenticate, if any</param> /// <param name="listenForUDP">If this connection object should listen for UDP traffic (all connections can already send UDP data). On a server, this property should be false as servers make use of a global UDP listener. On a client, this property should be true. This parameter is ignored on Silverlight.</param> public void BeginConnect(string serverAddress, int port, string username, string password, PacketLoginRequest.ConnectionType connectionType) { if (IsAlive || ConnectionInProgress || ConnectionWasInitiated) { return; } if (username == null) { username = ""; } if (password == null) { password = ""; } m_ConnectionType = connectionType; Log.LogMsg("Connecting to " + serverAddress + ":" + port.ToString() + " as " + username); m_ConnectionWasInitiated = true; m_ConnectionInProgress = true; AccountName = username; Password = password; m_ServerAddress = serverAddress; m_Port = port; try { MyTCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SocketAsyncEventArgs arg = CreateNewSaeaForConnect(); DnsEndPoint dne = new DnsEndPoint(serverAddress, m_Port); arg.RemoteEndPoint = dne; arg.UserToken = MyTCPSocket; bool willRaiseEvent = MyTCPSocket.ConnectAsync(arg); if (!willRaiseEvent) { OnConnectEvent_Completed(this, arg); } } catch (Exception e) { FireConnectedEvent(false, "Unable to resolve server IPAddress. " + e.Message); return; } }
/// <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> /// Begin an asynchronous connection attempt /// </summary> /// <param name="serverAddress">the address of the target server.</param> /// <param name="port">the port of the target server</param> /// <param name="username">the username with which to authenticate, if any</param> /// <param name="password">the password with which to authenticate, if any</param> /// <param name="listenForUDP">If this connection object should listen for UDP traffic (all connections can already send UDP data). On a server, this property should be false as servers make use of a global UDP listener. On a client, this property should be true. This parameter is ignored on Silverlight.</param> public void BeginConnect(string serverAddress, int port, string username, string password, PacketLoginRequest.ConnectionType connectionType) { if (IsAlive || ConnectionInProgress || ConnectionWasInitiated) { return; } if (username == null) { username = ""; } if (password == null) { password = ""; } m_ConnectionType = connectionType; Log.LogMsg("Connecting to " + serverAddress + ":" + port.ToString() + " as " + username); m_ConnectionWasInitiated = true; m_ConnectionInProgress = true; AccountName = username; Password = password; m_ServerAddress = serverAddress; m_Port = port; try { MyTCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SocketAsyncEventArgs arg = CreateNewSaeaForConnect(); DnsEndPoint dne = new DnsEndPoint(serverAddress, m_Port); arg.RemoteEndPoint = dne; arg.UserToken = MyTCPSocket; bool willRaiseEvent = MyTCPSocket.ConnectAsync(arg); if (!willRaiseEvent) { OnConnectEvent_Completed(this, arg); } } catch (Exception e) { FireConnectedEvent(false, "Unable to resolve server IPAddress. " + e.Message); return; } }
/// <summary> /// Begin an asynchronous connection attempt /// </summary> /// <param name="serverAddress">the address of the target server.</param> /// <param name="port">the port of the target server</param> /// <param name="username">the username with which to authenticate, if any</param> /// <param name="password">the password with which to authenticate, if any</param> public void BeginConnect(string serverAddress, int port, string username, string password, PacketLoginRequest.ConnectionType connectionType) { if (IsAlive || ConnectionInProgress || ConnectionWasInitiated) { return; } if (username == null) { username = ""; } if (password == null) { password = ""; } m_ConnectionType = connectionType; Log.LogMsg("Connecting to " + serverAddress + ":" + port.ToString() + " as " + username); m_ConnectionWasInitiated = true; m_ConnectionInProgress = true; AccountName = username; Password = password; m_ServerAddress = serverAddress; m_Port = port; Log.LogMsg("Resolving host [" + serverAddress + "]"); Dns.BeginGetHostAddresses(serverAddress, new AsyncCallback(OnHostResolve), null); }