Ejemplo n.º 1
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));
     }
 }
Ejemplo n.º 2
0
        private void SyncUserFriends(Account account)
        {
            string[] friendIds = account.FriendIdentities.ToArray();

            for (int i = friendIds.Length - 1; i >= 0; i--)
            {
                Account friendAccount = new Account
                                            (AccountDatabaseHandler.GetAccountNameFromId(friendIds[i]));

                ClientManager.SendMessageToClientByAccount
                    (account, GetFriendSyncCommand(friendAccount));
            }
        }
Ejemplo n.º 3
0
        private void HandleFriendRequest_One(string clientId, string[] segments)
        {
            //protocol#|frndrq#|id
            ClientState client = ClientManager.GetClientById(clientId);
            string      idTo   = segments[2];

            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.FriendRequest),
                                       client.AccountRelative.AccountId);

            if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
            {
                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idTo), cmd);
            }
        }
Ejemplo n.º 4
0
        private void PopulateFriends()
        {
            try
            {
                string[] friendIdCache =
                    AccountDatabaseHandler.GetUserFriends(m_AccountId);

                for (int i = friendIdCache.Length - 1; i >= 0; i--)
                {
                    AddFriend(friendIdCache[i]);
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 5
0
        private void HandleFriendAddition_One(string clientId, string[] segments)
        {
            try //protocol#|adfrnd#|id
            {
                string idFrom = ClientManager.GetClientById(clientId).AccountRelative.AccountId;
                string idTo   = segments[2];

                AccountDatabaseHandler.AddFriendRelationship(idFrom, idTo);
                AccountDatabaseHandler.AddFriendRelationship(idTo, idFrom);

                if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idFrom)))
                {
                    AccountHandler.GetAccountById(idFrom).AddFriend(idTo);
                }

                if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
                {
                    AccountHandler.GetAccountById(idTo).AddFriend(idFrom);
                }

                string cmd = string.Format("{0}{1}{2}{1}{3}",
                                           (int)ReadProtocol.GetVersion(),
                                           m_SegmentTerminator,
                                           NetworkCommand.GetCommand(NetworkCommandType.AddFriend),
                                           idTo);

                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idFrom), cmd);

                cmd = string.Format("{0}{1}{2}{1}{3}",
                                    (int)ReadProtocol.GetVersion(),
                                    m_SegmentTerminator,
                                    NetworkCommand.GetCommand(NetworkCommandType.AddFriend),
                                    idFrom);

                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idTo), cmd);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 6
0
        private void HandleFriendRemoval_One(string clientId, string[] segments)
        {
            //protocol#|rmfrnd#|id
            string idTo   = segments[2];
            string idFrom = ClientManager.GetClientById(clientId).AccountRelative.AccountId;

            AccountDatabaseHandler.RemoveUserRelationships(idFrom, idTo);
            AccountDatabaseHandler.RemoveUserRelationships(idTo, idFrom);

            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.RemoveFriend),
                                       idFrom);

            if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
            {
                ClientManager.SendMessageToClientByAccount(AccountHandler.GetAccountById(idTo), cmd);
            }
        }
Ejemplo n.º 7
0
        private void PopulateDetails()
        {
            try
            {
                string[] detailCache =
                    AccountDatabaseHandler.GetAccountDetails(m_Username);

                m_Email     = detailCache[0];
                m_AccountId = detailCache[4];

                Int32.TryParse(detailCache[1], out m_Rating);
                Int32.TryParse(detailCache[2], out m_Wins);
                Int32.TryParse(detailCache[3], out m_Losses);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 8
0
        private static void LoopReadInput()
        {
            while ((m_ServerCommand = Console.ReadLine()).ToLowerInvariant() != m_TerminationCommand)
            {
                if (m_ServerCommand.IndexOf("decrsa") != -1)
                {
                    RSAModule.ParseDecryptCommand(m_ServerCommand);
                    continue;
                }

                else if (m_ServerCommand.IndexOf("encrsa") != -1)
                {
                    RSAModule.ParseEncryptCommand(m_ServerCommand);
                    continue;
                }

                else if (m_ServerCommand.IndexOf("decaes") != -1)
                {
                    m_AesModule.ParseDecryptCommand(m_ServerCommand);
                    continue;
                }

                else if (m_ServerCommand.IndexOf("encaes") != -1)
                {
                    m_AesModule.ParseEncryptCommand(m_ServerCommand);
                    continue;
                }

                else if (m_ServerCommand.IndexOf("crtacct") != -1)
                {
                    AccountDatabaseHandler.CreateAccountFromConsole(m_ServerCommand);
                    continue;
                }

                else if (m_ServerCommand.IndexOf("getsalt") != -1)
                {
                    AccountDatabaseHandler.GetUserSaltFromConsole(m_ServerCommand);
                    continue;
                }

                else if (m_ServerCommand.IndexOf("auth") != -1)
                {
                    AccountDatabaseHandler.ChallengeAuthenticationFromConsole(m_ServerCommand);
                    continue;
                }

                switch (m_ServerCommand.ToLowerInvariant())
                {
                case "count":
                {
                    Console.WriteLine
                        ("Number Of Authorized Clients Connected: {0}", ClientManager.ClientCount);
                    break;
                }

                case "debug":
                {
                    if (DebugMode)
                    {
                        Console.WriteLine("Debug Mode Disabled.");
                        DebugMode = false;
                    }

                    else
                    {
                        Console.WriteLine("Debug Mode Enabled.");
                        DebugMode = true;
                    }
                    break;
                }

                case "genrsa":
                {
                    Task.Run(() =>
                        {
                            RSAModule.GenerateNewRsaKeys();
                            Console.WriteLine("New Rsa Keys Generated..");
                        });

                    break;
                }

                case "outrsa":
                {
                    Task.Run(() =>
                        {
                            RSAModule.OutputCurrentRsaKeys();
                            Console.WriteLine("Current Rsa Keys Cached..");
                        });
                    break;
                }

                case "genaes":
                {
                    Task.Run(() =>
                        {
                            m_AesModule.GenerateProviderAndOutput();
                            Console.WriteLine("Aes Key And Vector Generated..");
                        });
                    break;
                }

                case "threadinfo":
                {
                    Diagnostics.OutputThreadCountData();
                    break;
                }

                case "allthreads":
                {
                    Diagnostics.OutputIndividualThreadData();
                    break;
                }

                default: Console.WriteLine("Invalid Command, Please Enter Valid Input."); break;
                }
            }
            ;
        }
Ejemplo n.º 9
0
 private void HandleAccountCreationRequest_One(string id, string[] segments)
 {
     AccountDatabaseHandler.AttemptAccountCreation(id, segments[2], segments[3], segments[4]);
 }