コード例 #1
0
        public ClientState(Socket socket)
        {
            try
            {
                m_Socket = socket;

                m_ClientIdentifier = Guid.NewGuid().ToString();

                m_AesModule       = new AesModule();
                m_MessageIsolator = new MessageIsolator(this, m_AesModule);

                m_AsyncCallback = new AsyncCallback(ReadCallback);

                NetworkEventDispatcher.
                InvokeClientConnectionEvent(new ClientConnectionEventArgs(this));

                Socket.BeginReceive
                    (Buffer, 0, BufferSize, 0, m_AsyncCallback, this);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #2
0
        internal static void CreateAccount(string clientId, string accountId, string username, string password, string email)
        {
            string passwordSalt = GenerateHashSalt(m_HashSize);
            string passwordHash = GenerateHash(password + passwordSalt);

            try
            {
                using (MySqlConnection mySqlConnection = MySqlConnector.InitializeMySqlConnection())
                {
                    if (MySqlConnector.OpenConnection(mySqlConnection))
                    {
                        using (MySqlCommand c = new MySqlCommand(m_CreateAccountString, mySqlConnection))
                        {
                            c.Parameters.Add(new MySqlParameter("?id", accountId));
                            c.Parameters.Add(new MySqlParameter("?account", username));
                            c.Parameters.Add(new MySqlParameter("?passHash", passwordHash));
                            c.Parameters.Add(new MySqlParameter("?passSalt", passwordSalt));
                            c.Parameters.Add(new MySqlParameter("?email", email));

                            int i = c.ExecuteNonQuery();

                            if (i > 0)
                            {
                                if (clientId != string.Empty)
                                {
                                    NetworkEventDispatcher.InvokeAccountCreationSuccessEvent
                                        (new AccountCreationSuccessArgs(clientId));
                                }

                                Console.WriteLine("Account Successfully Created For: {0}", username);
                            }

                            else
                            {
                                if (clientId != string.Empty)
                                {
                                    NetworkEventDispatcher.InvokeAccountCreationFailedEvent
                                        (new AccountCreationFailedArgs(clientId, AccountCreationFailType.Unknown));
                                }

                                Console.WriteLine("Failed To Create New Account For: {0}", username);
                            }

                            MySqlConnector.CloseConnection(mySqlConnection);
                        }
                    }

                    else
                    {
                        Console.WriteLine("[Error]: Unable To Contact Database During: (CreateAccount).");
                    }
                }
            }

            catch (Exception e) { Console.WriteLine(e.ToString()); }
        }
コード例 #3
0
        internal static void AttemptLogin(string clientId, string username, string passwordAttempt)
        {
            if (ChallengeAccountAuthentication(clientId, username, passwordAttempt))
            {
                NetworkEventDispatcher.InvokeUserLoginEvent(new UserLoginEventArgs(clientId, username, true, false));
            }

            else
            {
                NetworkEventDispatcher.InvokeUserLoginEvent(new UserLoginEventArgs(clientId, username, false, false));
            }
        }
コード例 #4
0
 private void HandleAccountLoginRequest_One(string id, string[] segments)
 {
     if (!AccountHandler.AccountOnline(segments[2]))
     {
         AccountDatabaseHandler.AttemptLogin(id, segments[2], segments[3]);
     }
     else
     {
         NetworkEventDispatcher.InvokeUserLoginEvent
             (new UserLoginEventArgs(id, segments[2], false, true));
     }
 }
コード例 #5
0
        internal void RelayMessages(IEnumerable <string> messages)
        {
            foreach (string message in messages)
            {
                m_IsolationArgs.UpdateMessage(m_ClientState.ClientId, m_Aes.DecryptStringToString(message));
                NetworkEventDispatcher.InvokeClientMessageEvent(m_IsolationArgs);

                if (ServerCore.DebugMode)
                {
                    Console.WriteLine("Relay Event Invoked On Thread: " + Thread.CurrentThread.ManagedThreadId);
                }
            }
        }
コード例 #6
0
        internal static void RemoveClient(ClientState client)
        {
            if (m_Clients.ContainsKey(client.ClientId))
            {
                m_Clients.Remove(client.ClientId);

                if (client.AccountRelative != null &&
                    m_ClientAccountPairs.ContainsKey(client.AccountRelative))
                {
                    m_ClientAccountPairs.Remove(client.AccountRelative);
                }

                NetworkEventDispatcher.InvokeClientDisconnectEvent(new ClientDisconnectEventArgs(client));

                if (ServerCore.DebugMode)
                {
                    Console.WriteLine("Removing [{0}] From Client List.", client.ClientId);
                }
            }
        }
コード例 #7
0
        internal static void CycleClientHeartbeats()
        {
            try
            {
                while (true)
                {
                    Thread.Sleep(1500 * 10);

                    ClientState[] clientCache = m_Clients.Values.ToArray();
                    for (int i = clientCache.Length - 1; i >= 0; i--)
                    {
                        Thread.Sleep(50);
                        if (clientCache[i].RequiresCirculation())
                        {
                            if (!m_ClientHeartbeatCache.Contains(clientCache[i]))
                            {
                                m_ClientHeartbeatCache.Add(clientCache[i]);
                            }

                            NetworkEventDispatcher.InvokeClientCirculationEvent
                                (new ClientCirculationEventArgs(clientCache[i]));
                        }
                    }

                    clientCache = m_ClientHeartbeatCache.ToArray();
                    for (int i = clientCache.Length - 1; i >= 0; i--)
                    {
                        Thread.Sleep(50);
                        if (clientCache[i].HeartbeatExpired() && m_ClientHeartbeatCache.Contains(clientCache[i]))
                        {
                            clientCache[i].DisposeOfClientAndConnection();
                        }
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #8
0
        internal static bool?QueryAccountExists(string clientId, string username, string email)
        {
            try
            {
                using (MySqlConnection mySqlConnection = MySqlConnector.InitializeMySqlConnection())
                {
                    if (MySqlConnector.OpenConnection(mySqlConnection))
                    {
                        using (MySqlCommand c = new MySqlCommand(m_QueryAccountNameExistsString, mySqlConnection))
                        {
                            c.Parameters.Add(new MySqlParameter("?account", username));

                            using (MySqlDataReader reader = c.ExecuteReader())
                            {
                                if (reader.Read())
                                {
                                    if (clientId != string.Empty)
                                    {
                                        NetworkEventDispatcher. //Notify Client Account Name Exists
                                        InvokeAccountCreationFailedEvent
                                            (new AccountCreationFailedArgs(clientId, AccountCreationFailType.UsernameExists));
                                    }

                                    Console.WriteLine
                                        ("Failed To Create New Account For: {0} (Username [{1}] Already Exists)",
                                        username, reader["account_name"].ToString());

                                    return(true);
                                }
                            }
                        }

                        using (MySqlCommand c = new MySqlCommand(m_QueryAccountEmailExistsString, mySqlConnection))
                        {
                            c.Parameters.Add(new MySqlParameter("?email", email));

                            using (MySqlDataReader reader = c.ExecuteReader())
                            {
                                if (reader.Read())
                                {
                                    if (clientId != string.Empty)
                                    {
                                        NetworkEventDispatcher. //Notify Client Email Already In Use
                                        InvokeAccountCreationFailedEvent
                                            (new AccountCreationFailedArgs(clientId, AccountCreationFailType.EmailExists));
                                    }

                                    Console.WriteLine("Failed To Create New Account For: {0} (Email Already Exists)", username);

                                    return(true);
                                }
                            }
                        }

                        MySqlConnector.CloseConnection(mySqlConnection);
                        return(false);
                    }

                    return(null); //Unable To Open Database Connection
                }
            }

            catch (Exception e) { Console.WriteLine(e.ToString()); return(null); }
        }