Esempio n. 1
0
        // extrawords
        // 1 - username
        // 2 - password
        public void Execute(List <string> extraWords, AttachedClient executingClient)
        {
            if (executingClient == null)
            {
                return;
            }

            if (extraWords.Count != 2)
            {
                var errorMsgDto = new DescriptiveTextDto("Wrong number of parameters.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            if (AttachedClients.IsAccountLoggedIn(extraWords[0]))
            {
                var errorMsgDto = new DescriptiveTextDto("Account is already logged in.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            var potentialAccount = GrainClusterClient.Accounts.GetAccount(extraWords[0]).Result;

            if (potentialAccount != null && potentialAccount.ValidatePassword(extraWords[1]).Result)
            {
                executingClient.AttachedAccount = potentialAccount;
                var successMsgDto = new DescriptiveTextDto("Login success.");
                executingClient?.SendDtoMessage(successMsgDto);
            }
            else
            {
                var errorMsgDto = new DescriptiveTextDto("Either the username or password were incorrect.");
                executingClient?.SendDtoMessage(errorMsgDto);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a message to the character that only the receiving character can see
        /// </summary>
        /// <param name="text">The text to send</param>
        public void SendDtoMessage(FiniteDto dto)
        {
            // Is any client focusing on this character? If not then no message is sent.
            var focusedClient = AttachedClients.GetCharacterFocusedClient(this.TrackingId);

            if (focusedClient == null)
            {
                return;
            }

            focusedClient.SendDtoMessage(dto);
        }
Esempio n. 3
0
        public static bool TryRunCommandFromCharacter(string word, List <string> extraWords, Character executingCharacter)
        {
            // Try to get an associated account if we can, but if we can't find an account (such as for NPCs)
            // then continue with default permissions
            var permissionsToUse = new List <string>();
            var client           = AttachedClients.GetCharacterFocusedClient(executingCharacter.TrackingId);

            if (client?.AttachedAccount != null)
            {
                permissionsToUse = client.AttachedAccount.GetPermissions().Result;
            }
            return(TryRunCommandFromCharacter(word, extraWords, executingCharacter, permissionsToUse));
        }
Esempio n. 4
0
        internal static bool TryRunCommandFromClient(string word, List <string> extraWords, AttachedClient executingClient)
        {
            // Built in anonymous commands
            var anonCommandToRun = BuildInAnonymousCommands
                                   .Where(c => c.ActivatingWords.Any(w => w.Equals(word, StringComparison.OrdinalIgnoreCase)))
                                   .FirstOrDefault(); // No permission check on anon commands

            if (anonCommandToRun != null)
            {
                anonCommandToRun.Execute(extraWords, executingClient);
                return(true);
            }

            // Anything further requires an account attached to the client
            if (executingClient?.AttachedAccount == null)
            {
                return(false);
            }

            // Try to run an account level command
            if (TryRunCommandFromAccount(word, extraWords, executingClient.AttachedAccount))
            {
                return(true);
            }

            // Anything further requires a player logged into the game
            var playerCharacter = AttachedClients.GetClientFocusedCharacter(executingClient.TrackingId);

            if (playerCharacter == null)
            {
                return(false);
            }

            if (!playerCharacter.CanTakeTurn())
            {
                var secondsLeft = playerCharacter.GetSecondsTillNextTurn();
                playerCharacter.SendDescriptiveTextDtoMessage($"You cannot take your next turn yet. ({secondsLeft} seconds left).");
                return(true);
            }
            else
            {
                bool commandResult = TryRunCommandFromCharacter(word, extraWords, playerCharacter, executingClient.AttachedAccount.GetPermissions().Result);
                playerCharacter.TurnComplete();
                return(commandResult);
            }
        }
Esempio n. 5
0
        public void Execute(List <string> extraWords, IAccountGrain executingAccount)
        {
            AttachedClient executingClient = AttachedClients.GetAccountFocusedClient(executingAccount);

            if (executingAccount == null || executingClient == null)
            {
                var errorMsgDto = new DescriptiveTextDto("The use player command is currently unavailable.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            if (extraWords.Count != 1)
            {
                var errorMsgDto = new DescriptiveTextDto("Wrong number of parameters.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            var character = executingAccount.GetCharacter(extraWords[0]).Result;;

            if (character == null)
            {
                var errorMsgDto = new DescriptiveTextDto("Unknown character.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            // TODO: this instantly will switch active players in an account.. there needs to be a cooldown time here to logout then login
            AttachedClients.SetClientFocusedCharacter(executingClient.TrackingId, character.TrackingId);
            if (character.IsNew)
            {
                character.IsNew = false;
                var gameIntroMsgDto = new DescriptiveTextDto(GrainClusterClient.Universe.GetGameIntroductionText().Result);
                executingClient?.SendDtoMessage(gameIntroMsgDto);
            }
            else
            {
                var successMsgDto = new DescriptiveTextDto($"You have entered {character.GetLocation().LocationName}.");
                executingClient?.SendDtoMessage(successMsgDto);
            }
            var othersMsgDto = new DescriptiveTextDto($"{character.Name} has entered the area.");

            character.GetLocation().SendDescriptiveTextDtoMessage($"{character.Name} has entered the area.", character);
        }
Esempio n. 6
0
        void ILinkProcessor.Process(AttachContext attachContext)
        {
            var client = AttachedClients.GetClientFromConnection(attachContext.Link.Session.Connection);

            // If a Receiver link is attaching
            if (attachContext.Attach.Role)
            {
                var endpoint = new ServerToClientLinkEndpoint(attachContext.Link);
                client.SetServerToClientLinkEndpoint(endpoint);

                // Completes the attach operation with success
                attachContext.Complete(endpoint, 0);
            }
            else
            {
                var endpoint = new ClientToServerLinkEndpoint(attachContext.Link);
                client.SetClientToServerLinkEndpoint(endpoint);

                // Completes the attach operation with success
                attachContext.Complete(endpoint, 1);
            }
        }
        public void Execute(List <string> extraWords, IAccountGrain executingAccount)
        {
            AttachedClient executingClient = AttachedClients.GetAccountFocusedClient(executingAccount);

            if (executingAccount == null || executingClient == null || !executingAccount.CanCreateNewPlayer().Result)
            {
                var errorMsgDto = new DescriptiveTextDto("The create new player command is currently unavailable.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            if (extraWords.Count != 1)
            {
                var errorMsgDto = new DescriptiveTextDto("Wrong number of parameters.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            if (GrainClusterClient.Universe.IsPlayerCharacterNameInUse(extraWords[0]).Result)
            {
                var errorMsgDto = new DescriptiveTextDto("This character name is already taken.");
                executingClient?.SendDtoMessage(errorMsgDto);
                return;
            }

            var newPlayerCharacter = EngineInternal.NewPlayerCreator();

            newPlayerCharacter.Name = extraWords[0];

            // Mark all player characters as needing focus to stay in the world
            newPlayerCharacter.NeedsFocus = true;
            executingAccount.AddCharacter(newPlayerCharacter.TrackingId).Wait();

            var successMsgDto = new DescriptiveTextDto("New player created.");

            executingClient?.SendDtoMessage(successMsgDto);
        }
Esempio n. 8
0
        /// <summary>
        /// Indicates if there is a client currently focusing on this character
        /// </summary>
        /// <returns>True if there is a focusing client</returns>
        public bool HasClientFocus()
        {
            var client = AttachedClients.GetCharacterFocusedClient(this.TrackingId);

            return(client != null);
        }
Esempio n. 9
0
 public AttachedClient GetClient()
 {
     return(AttachedClients.GetCharacterFocusedClient(this.TrackingId));
 }