Exemplo n.º 1
0
        public bool addSource(IChatSource newSource)
        {
            if (!chatSources.ContainsKey(newSource.SourceName))
            {
                chatSources.Add(newSource.SourceName.ToUpper(), newSource);
                newSource.IncomingMessage += new IncomingMessageEventHandler(newSource_IncomingMessage);

                if (MainUser != null)
                {
                    //Assume that either there is only either none or at least one user account
                    if (MainUser.retrieve(newSource) == null)
                    {
                        UserAccount masterAccount;
                        if (MainUser.Profile != null)
                        {
                            masterAccount = newSource.createUser(MainUser.Profile.Name);
                        }
                        else
                        {
                            masterAccount = newSource.createUser("Boss");
                        }
                    }
                    else
                    {
                        newSource.setup(MainUser.retrieve(newSource)[0]);
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public override bool execute(ICommand command)
        {
            if (command is ChatCommand)
            {
                ChatCommandType type     = ((ChatCommand)command).Type;
                IChatSource     source   = ChatManager.getSource(((ChatCommand)command).SourceName);
                string          username = ((ChatCommand)command).Username;

                if (type == ChatCommandType.Create)
                {
                    if (source.findUser(username) != null)
                    {
                        MessageLogger.log("Cannot create account. Username \"" + username + "\" already existed.");
                        command.Status = CommandStatus.FAILED;
                        return(true);
                    }
                    UserAccount account = source.createUser(username);
                    source.addUser(account);
                }
                else //if command is either log in, log off, or remove account
                {
                    UserAccount account = source.findUser(username);
                    if (account == null)
                    {
                        MessageLogger.log("No account found with username \"" + username + "\".");
                        command.Status = CommandStatus.FAILED;
                        return(true);
                    }

                    if (type == ChatCommandType.Setup)
                    {
                        source.setup(account);
                    }
                    else if (source is IChatSourceAccountManager)
                    {
                        if (command is ChatModifyCommand)
                        {
                            account.Password = ((ChatModifyCommand)command).Password;
                            ((IChatSourceAccountManager)source).modifyAccount(account);
                        }
                        else if (type == ChatCommandType.Login)
                        {
                            ((IChatSourceAccountManager)source).login(account);
                        }
                        else if (type == ChatCommandType.Logout)
                        {
                            ((IChatSourceAccountManager)source).logoff(account);
                        }
                        else if (type == ChatCommandType.Remove)
                        {
                            ((IChatSourceAccountManager)source).removeAccount(account);
                        }
                        else
                        {
                            MessageLogger.log("Chat command type is not supported.");
                            command.Status = CommandStatus.FAILED;
                            return(true);
                        }
                    }
                    else
                    {
                        MessageLogger.log("Account modification is unavailable for this source.", MessageType.WARNING);
                        command.Status = CommandStatus.FAILED;
                        return(true);
                    }
                }

                //Command Successfully Executed
                command.Status = CommandStatus.COMPLETED;
                return(true);
            }
            else
            {
                return(false);
            }
        }