www.pudn.com > Wcell.rar > AddUser.cs


/************************************************************************* 
 * 
 *   file		: AddUser.cs 
 *   copyright		: (C) The WCell Team 
 *   email		: info@wcell.org 
 *   last changed	: $LastChangedDate: 2008-03-29 11:01:47 +0800 (星期六, 29 三月 2008) $ 
 *   last author	: $LastChangedBy: tobz $ 
 *   revision		: $Rev: 205 $ 
 * 
 *   This program is free software; you can redistribute it and/or modify 
 *   it under the terms of the GNU General Public License as published by 
 *   the Free Software Foundation; either version 2 of the License, or 
 *   (at your option) any later version. 
 * 
 *************************************************************************/ 
 
using System; 
using System.Data.Linq; 
using NLog; 
using WCell.AuthServer; 
using WCell.AuthServer.Database; 
using Castle.ActiveRecord; 
using Castle.ActiveRecord.Queries; 
using NHibernate.Expression; 
 
namespace WCell.AuthServerConsole.Commands 
{ 
    ///  
    /// Command for adding a user to the database 
    ///  
    public class AddUser 
    { 
        private static Logger s_log = LogManager.GetLogger("Application"); 
 
        ///  
        /// Adds a user to the database with the given username and given password 
        ///  
        /// the arguments of the command 
        [ConsoleCommand("adduser")] 
        public static void Execute(string[] arguments) 
        { 
            if (arguments.Length < 3) 
            { 
                s_log.Error("You must supply a username and a password and TBC flag in order to create a new user!"); 
                return; 
            } 
 
            if (Account.DoesAccountExist(arguments[0])) 
            { 
                s_log.Error("The account \"{0}\" already exists!", arguments[0]); 
                return; 
            } 
 
			bool tbcFlag = false; 
			if (!Boolean.TryParse(arguments[2], out tbcFlag)) 
			{ 
				// maybe they used 0/1, check that. 
				int tbcFlagIntegral = 0; 
				if(Int32.TryParse(arguments[2], out tbcFlagIntegral)) 
				{ 
					// check value 
					if (tbcFlagIntegral != 0 || tbcFlagIntegral != 1) 
					{ 
						s_log.Error("You can only use 0 (false), 1 (true), true, or false to specify the TBC flag."); 
						return; 
					} 
					else 
					{ 
						tbcFlag = (tbcFlagIntegral == 0 ? false : true); 
					} 
				} 
 
				s_log.Error("You can only use 0 (false), 1 (true), true, or false to specify the TBC flag."); 
				return; 
			} 
 
            Account.CreateAccount(arguments[0], arguments[1], tbcFlag); 
 
            s_log.Info("User {0} created successfully!", arguments[0]); 
        } 
    } 
}