public static void Execute(User UserThatCalled, params string[] Params) { if (Params.Length > 1) { if (!Permissions.IsStaff(UserThatCalled)) return; User TargetUser = UserManager.GetUserByName(Params[1]); if (TargetUser == null) { UserThatCalled.ClientConnection.SendData("CHAT;Couldn't find that user!"); return; } if (UserThatCalled == TargetUser) return; using(DatabaseConnection DB = new DatabaseConnection()) { DB.SetQuery("UPDATE users SET banned = '1' WHERE id = @id"); DB.AddParam("id", TargetUser.UserID); DB.ExecuteQuery(); } TargetUser.ClientConnection.SendData("CHAT;You were banned by " + UserThatCalled.Username + "!"); TargetUser.ClientConnection.Disconnect(); UserManager.SendMassData("CHAT;" + TargetUser.Username + " was banned by " + UserThatCalled.Username + "!"); } else { UserThatCalled.ClientConnection.SendData("CHAT;Invalid syntax, correct: /ban USERNAME"); } }
public static void ExecutePendingQueries() { int TotalQueries = QueryStack.Count; if (TotalQueries > 1500000) Logging.Message("Executing {0} queries, this may take a while...", TotalQueries); else Logging.Message("Executing {0} queries..", TotalQueries); using (DatabaseConnection DB = new DatabaseConnection()) { foreach (KeyValuePair<Dictionary<string, string>, string> KvP in QueryStack) { DB.SetQuery(KvP.Value); foreach (KeyValuePair<string, string> KvPParams in KvP.Key) { DB.AddParam(KvPParams.Key, KvPParams.Value); } DB.ExecuteQuery(); } } QueryStack.Clear(); Logging.Message("Successfully executed {0} queries from the stack! Stack cleared!", TotalQueries); }
// USERNAME@PASSWORD public static void Execute(string MessageBody, object[] Objects) { string[] MessageBodyArray = MessageBody.Split('@'); string Username = MessageBodyArray[0]; string Password = MessageBodyArray[1]; DataRow User; using (DatabaseConnection DB = new DatabaseConnection()) { DB.SetQuery("SELECT * FROM users WHERE username = @username AND password = @password"); DB.AddParam("username", Username); DB.AddParam("password", Password); User = DB.GetRow(); } Connection ClientConnection = (Connection)Objects[0]; if (User == null) { ClientConnection.SendData("LOGIN;INVALID"); return; } User ClientUser = UserFactory.GenerateUserFromRow(User, ClientConnection); if (ClientUser.Banned) { ClientConnection.SendData("LOGIN;BANNED"); ClientUser = null; return; } if (UserManager.Users.ContainsKey(ClientUser.UserID)) { ClientConnection.SendData("LOGIN;ALREADY"); ClientUser = null; return; } Logging.Message("{0} logged in!", ClientUser.Username); ClientConnection.SendData("LOGIN;SUCCESS"); UserManager.SendMassData("CHAT;" + ClientUser.Username + " joined the room!"); UserManager.SendMassData("NEWUSR;" + ClientUser.Username); UserManager.Users.Add(ClientUser.UserID, ClientUser); }
public static void Boot() { #region Starting credentials Console.Title = "Flexi Server ~ 1.0.0"; Logging.Message("Flexi Server ~ 1.0.0"); Console.WriteLine(); #endregion #region Load config Config Config = new Config(); Config.GetAllData("Config/MySQL.txt"); #endregion #region MySQL test run using (DatabaseConnection DB = new DatabaseConnection()) { } Logging.Message("Successfully connected to the MySQL server!"); #endregion #region Initialize user manager UserManager.Initialize(); #endregion #region Initialize message handlers MessageHandler.RegisterMessages(); #endregion #region Initialize commands CommandParser.RegisterCommands(); #endregion #region Start server listener Console.WriteLine(); Server = new Server(); Console.WriteLine(); #endregion }