public static void UserFromGroup(Packet packet) { Packet sendPacket; try { string[] combine = packet.Argument.Split(char.Parse("|")); string username = combine[0]; string group = combine[1]; ConsoleUtils.Print(string.Format("[{0}]'s Request: Remove user from group {1} [{2}]", packet.ClientIP, group, packet.Username)); UserInfoInserter.RemoveUserFromGroup(username, group); MySQLAccountParsing.RemoveUserFromGroup(username, group); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); ConsoleUtils.Print(string.Format("[{0}]'s Request: Removing user from group success: {1} [{2}]", packet.ClientIP, username, packet.Username)); } catch (Exception e) { ConsoleUtils.Print(string.Format("User From Group Error: [{0}] {1}", e.GetType().ToString(), e.Message)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } }
public static void DeleteUser(Packet packet) { Packet sendPacket; try { ConsoleUtils.Print(string.Format("[{0}]'s Request: Delete user to the server [{1}]", packet.ClientIP, packet.Username)); string username = packet.Argument; if (username == "root" || username == Environment.UserName) { ConsoleUtils.Print(string.Format("[{0}]'s Denied: User requesting to remove unallowed name: {1} [{2}]", packet.ClientIP, username, packet.Username)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } UserInfoInserter.DeleteUser(username); using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb")) { dbCon.Username = "******"; dbCon.Password = "******"; dbCon.Connect(); string command = string.Format("DELETE FROM `userDB` WHERE (`username`= '{0}')", username); dbCon.ExecuteCommand(command); command = string.Empty; dbCon.Close(); } UserCleaner.RemoveUserInEveryGroup(username); UserCleaner.RemoveUserInEveryProject(username); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); ConsoleUtils.Print(string.Format("[{0}]'s Request: Successfully deleting user {1} [{2}]", packet.ClientIP, username, packet.Username)); } catch (Exception e) { ConsoleUtils.Print(string.Format("Delete User Error: {0}", e.Message)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } }
public static void CreateUser(Packet packet) { Packet sendPacket; try { ConsoleUtils.Print(string.Format("[{0}]'s Request: Create new user to the server [{1}]", packet.ClientIP, packet.Username)); string[] store = packet.Argument.Split(char.Parse("|")); string name = store[0]; string username = store[1]; if (username.ToLower().Contains("root") || username == Environment.UserName) { ConsoleUtils.Print(string.Format("Adding User Error: User requesting to create unallowed name [{0}]", username)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } string password = store[2]; UserInfoInserter.AddUser(username, password); using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb")) { dbCon.Username = "******"; dbCon.Password = "******"; dbCon.Connect(); string command = string.Format("INSERT INTO `exceeddb`.`userDB` (`name`, `username`, `password`, `dateCreated`," + " `token`, `tokenExpired`) VALUES ('{0}', '{1}', '{2}', '{3}', '', '')", name, username, CryptSharp.Crypter.Sha512.Crypt(password), DateTime.Now.ToString()); dbCon.ExecuteCommand(command); command = string.Empty; dbCon.Close(); } sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); ConsoleUtils.Print(string.Format("[{0}]'s Success: Successfully creating user {1} [{2}]", packet.ClientIP, username, packet.Username)); } catch (Exception e) { ConsoleUtils.Print(string.Format("Adding User Error: {0}", e.Message)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } }
public static void ChangePassword(Packet packet) { Packet sendPacket; try { string[] store = packet.Argument.Split(char.Parse("|")); string username = store[0]; string password = store[1]; ConsoleUtils.Print(string.Format("[{0}]'s Request: Changing password of user [{1}] in the server [{2}]", packet.ClientIP, username, packet.Username)); if (username == "root" || username == Environment.UserName) { ConsoleUtils.Print(string.Format("Change Password Error: User requesting to change password of unallowed name [{0}]", username)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } UserInfoInserter.ChangeUserPassword(username, password); using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb")) { dbCon.Username = "******"; dbCon.Password = "******"; dbCon.Connect(); string command = string.Format("UPDATE `userDB` SET `password`='{0}' WHERE `username`='{1}'", CryptSharp.Crypter.Sha512.Crypt(password), username); dbCon.ExecuteCommand(command); command = string.Empty; dbCon.Close(); } sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); } catch (Exception e) { ConsoleUtils.Print(string.Format("Change Password Error: {0}", e.Message)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } }
public static void RemoveGroup(Packet packet) { Packet sendPacket; try { string group = packet.Argument; ConsoleUtils.Print(string.Format("[{0}]'s Request: Remove group from the server [{2}]", packet.ClientIP, group, packet.Username)); UserInfoInserter.RemoveGroup(group); using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb")) { dbCon.Username = "******"; dbCon.Password = "******"; dbCon.Connect(); string command = string.Format("DELETE FROM `groupDB` WHERE (`groupname`= '{0}')", group); dbCon.ExecuteCommand(command); command = string.Empty; dbCon.Close(); } GroupCleaner.RemoveGroupFromEveryProject(group); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); ConsoleUtils.Print(string.Format("[{0}]'s Request: Removing group success: {1} [{2}]", packet.ClientIP, group, packet.Username)); } catch (Exception e) { ConsoleUtils.Print(string.Format("Remove Group Error: [{0}] {1}", e.GetType().ToString(), e.Message)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } }
public static void CreateGroup(Packet packet) { Packet sendPacket; try { string group = packet.Argument; ConsoleUtils.Print(string.Format("[{0}]'s Request: Add group to the server [{2}]", packet.ClientIP, group, packet.Username)); int gid = UserInfoInserter.AddGroup(group); using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb")) { dbCon.Username = "******"; dbCon.Password = "******"; dbCon.Connect(); string command = string.Format("INSERT INTO `exceeddb`.`groupDB` (`groupid`, `groupname`, `dateCreated`, `member`)" + " VALUES ('{0}', '{1}', '{2}', '')", gid, group, DateTime.Now.ToString()); dbCon.ExecuteCommand(command); command = string.Empty; dbCon.Close(); } sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); ConsoleUtils.Print(string.Format("[{0}]'s Request: Adding group success: {1} [{2}]", packet.ClientIP, group, packet.Username)); } catch (Exception e) { ConsoleUtils.Print(string.Format("Adding Group Error: [{0}] {1}", e.GetType().ToString(), e.Message)); sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token); packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length); return; } }