public static bool CreateClan(Clan clan, ClanMember member) { try { Database.Query("INSERT INTO Clans (Name, Owner, InviteMode, ChatColor, Bans) VALUES (@0, @1, @2, @3, @4)", clan.Name, clan.Owner, (int)InviteMode.False, Config.DefaultChatColor, "[]"); Clans.Add(clan.Name, clan); JoinClan(clan, member); ClanHooks.OnClanCreated(getClanMember(member.Name), clan.Name); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); return false; } }
static void LoadClans() { try { using (var reader = Database.QueryReader("SELECT * FROM Clans")) { while (reader.Read()) { string name = reader.Get <string>("Name"); string owner = reader.Get <string>("Owner"); int inviteMode = reader.Get <int>("InviteMode"); int tileX = reader.Get <int>("TileX"); int tileY = reader.Get <int>("TileY"); string bans = reader.Get <string>("Bans"); Color color; ParseColor(reader.Get <string>("ChatColor"), out color); Clan clan = new Clan() { Name = name, Owner = owner, InviteMode = (InviteMode)inviteMode, TileX = tileX, TileY = tileY, Color = color, Bans = JsonConvert.DeserializeObject <List <string> >(bans) }; Clans.Add(name, clan); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static bool InsertBan(Clan clan, ClanMember member) { if (clan.Bans.Contains(member.Name)) return false; clan.Bans.Add(member.Name); LeaveClan(clan, member); UpdateBans(clan); return true; }
public static bool SetColor(Clan clan, string color) { Color temp; if (!ParseColor(color, out temp)) return false; clan.Color = temp; Database.Query("UPDATE Clans SET ChatColor = @0 WHERE Name = @1", color, clan.Name); return true; }
public static void LeaveClan(TSPlayer ts, Clan clan) { try { ClanHooks.OnClanLeave(ts, clan); if (ts.UserAccountName == clan.Owner) { ClanHooks.OnClanRemoved(clan); RemoveClan(clan); } else { clan.OnlineClanMembers.Remove(ts.Index); Database.Query("DELETE FROM ClanMembers WHERE Username = @0 AND ClanName = @1", ts.UserAccountName, clan.Name); } ClanMembers[ts.Index] = string.Empty; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void Kick(Clan clan, string name) { Database.Query("REMOVE FROM ClanMembers WHERE ClanName = @0 AND Username = @1", clan.Name, name); }
public static bool InsertBan(Clan clan, TSPlayer ts) { if (clan.Bans.Contains(ts.UserAccountName)) return false; clan.Bans.Add(ts.UserAccountName); UpdateBans(clan); return true; }
public static bool CreateClan(TSPlayer ts, Clan clan) { try { Database.Query("INSERT INTO Clans (Name, Owner, InviteMode, ChatColor, Bans) VALUES (@0, @1, @2, @3, @4)", clan.Name, clan.Owner, (int)InviteMode.False, Config.DefaultChatColor, "[]"); Clans.Add(clan.Name, clan); JoinClan(ts, clan); ClanHooks.OnClanCreated(ts, clan.Name); return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } }
public static void LoadClan(Clan clan) { Clans.Add(clan.Name, clan); foreach (TSPlayer ts in TShock.Players) { if (ts != null) { if (!ClanMembers.ContainsKey(ts.Index)) LoadMember(ts); } } }
public static void LeaveClan(Clan clan, ClanMember member) { try { ClanHooks.OnClanLeave(member, clan); if (member.Name == clan.Owner) { ClanHooks.OnClanRemoved(clan); RemoveClan(clan); } else { Database.Query("DELETE FROM ClanMembers WHERE UserID = @0 AND ClanName = @1", member.UserID, clan.Name); } if (ClanMembers.ContainsKey(member.UserID)) ClanMembers.Remove(member.UserID); UserSpecificFunctions.UserSpecificFunctions.LatestInstance.removeUserSuffix(member.UserID); } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } }
public static void UpdateTag(Clan clan, string tag) { Database.Query("UPDATE Clans SET Tag = @0 WHERE Name = @1", tag, clan.Name); Clans[clan.Name].Tag = tag; try { using (var reader = Database.QueryReader("SELECT * FROM ClanMembers WHERE ClanName = @0", clan.Name)) { while (reader.Read()) { int userID = reader.Get<int>("UserID"); UserSpecificFunctions.UserSpecificFunctions.LatestInstance.setUserSuffix(userID, tag); } } } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } }
static void LoadClans() { Clans.Clear(); try { using (var reader = Database.QueryReader("SELECT * FROM Clans")) { while (reader.Read()) { string name = reader.Get<string>("Name"); string tag = reader.Get<string>("Tag"); string owner = reader.Get<string>("Owner"); int inviteMode = reader.Get<int>("InviteMode"); int spawnX = reader.Get<int>("SpawnX"); int spawnY = reader.Get<int>("SpawnY"); string bans = reader.Get<string>("Bans"); Color color; ParseColor(reader.Get<string>("ChatColor"), out color); Clan clan = new Clan(name, owner) { InviteMode = (InviteMode)inviteMode, Tag = tag, SpawnX = spawnX, SpawnY = spawnY, Color = color, Bans = JsonConvert.DeserializeObject<List<string>>(bans) }; Clans.Add(name, clan); } } } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } }
public static void SetSpawn(Clan clan, int spawnX, int spawnY) { clan.SpawnX = spawnX; clan.SpawnY = spawnY; Database.Query("UPDATE Clans SET SpawnX = @0, SpawnY = @1 WHERE Name = @2", clan.SpawnX, clan.SpawnY, clan.Name); }
public static void Rename(Clan clan, string newname) { Database.Query("UPDATE Clans SET Name = @0 WHERE Name = @1", newname, clan.Name); Database.Query("UPDATE ClanMembers SET ClanName = @0 WHERE ClanName = @1", newname, clan.Name); ClanMembers.Values.Where(c => c.ClanName == clan.Name) .ForEach(delegate (ClanMember member) { member.ClanName = newname; }); Clans.Remove(clan.Name); clan.Name = newname; Clans.Add(newname,clan); }
public static void RemoveClan(Clan clan) { UserSpecificFunctions.UserSpecificFunctions.LatestInstance.removeAllSuffix(clan.Tag); Database.Query("DELETE FROM ClanMembers WHERE ClanName = @0", clan.Name); Database.Query("DELETE FROM Clans WHERE Name = @0", clan.Name); Clans.Remove(clan.Name); }
public static void Rename(Clan clan, TSPlayer ts, string newname) { Database.Query("UPDATE Clans SET Name = @0 WHERE Name = @1", newname ,clan.Name); Database.Query("UPDATE ClanMembers SET ClanName = @0 WHERE ClanName = @1",newname, clan.Name); UnLoadClan(clan); clan.Name = newname; LoadClan(clan); }
public static void SetInviteMode(Clan clan, InviteMode mode) { if (clan.InviteMode == mode) return; clan.InviteMode = mode; Database.Query("UPDATE Clans SET InviteMode = @0 WHERE Name = @1", (int)mode, clan.Name); }
public static void UnLoadClan(Clan clan) { Clans.Remove(clan.Name); int[] ids = ClanMembers.Where(c => c.Value == clan.Name).Select(c => c.Key).ToArray(); for (int i = 0; i < ids.Length; i++) UnLoadMember(TShock.Players[ids[i]]); }
public static bool JoinClan(Clan clan, ClanMember member) { try { if (ClanMembers.ContainsKey(member.UserID)) { ClanMembers[member.UserID] = member; } else { ClanMembers.Add(member.UserID, member); } Database.Query("INSERT INTO ClanMembers (UserID, PlayerName, ClanName) VALUES (@0, @1, @2)", member.UserID, member.Name, clan.Name); if (member.Name != clan.Owner) ClanHooks.OnClanJoin(member, clan); UpdateTag(clan, clan.Tag); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); return false; } }
public static void SetSpawn(Clan clan, TSPlayer ts) { clan.TileX = ts.TileX; clan.TileY = ts.TileY; Database.Query("UPDATE Clans SET TileX = @0, TileY = @1 WHERE Name = @2", clan.TileX, clan.TileY, clan.Name); }
static void UpdateBans(Clan clan) { Database.Query("UPDATE Clans SET Bans = @0 WHERE Name = @1", JsonConvert.SerializeObject(clan.Bans), clan.Name); }
public static bool RemoveBan(Clan clan, string name) { if (clan.Bans.Contains(name)) return false; clan.Bans.Remove(name); UpdateBans(clan); return true; }
public static void RemoveClan(Clan clan) { Database.Query("DELETE FROM ClanMembers WHERE ClanName = @0", clan.Name); Database.Query("DELETE FROM Clans WHERE Name = @0", clan.Name); Clans.Remove(clan.Name); }
public static bool JoinClan(TSPlayer ts, Clan clan) { try { ClanMembers[ts.Index] = clan.Name; Database.Query("INSERT INTO ClanMembers (Username, ClanName) VALUES (@0, @1)", ts.UserAccountName, clan.Name); clan.OnlineClanMembers.Add(ts.Index, new ClanMember() { Index = ts.Index, ClanName = ClanMembers[ts.Index] }); if (ts.UserAccountName != clan.Owner) ClanHooks.OnClanJoin(ts, clan); return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } }
static void LoadClans() { try { using (var reader = Database.QueryReader("SELECT * FROM Clans")) { while (reader.Read()) { string name = reader.Get<string>("Name"); string owner = reader.Get<string>("Owner"); int inviteMode = reader.Get<int>("InviteMode"); int tileX = reader.Get<int>("TileX"); int tileY = reader.Get<int>("TileY"); string bans = reader.Get<string>("Bans"); Color color; ParseColor(reader.Get<string>("ChatColor"), out color); Clan clan = new Clan() { Name = name, Owner = owner, InviteMode = (InviteMode)inviteMode, TileX = tileX, TileY = tileY, Color = color, Bans = JsonConvert.DeserializeObject<List<string>>(bans) }; Clans.Add(name, clan); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
void ClanCmd(CommandArgs args) { string cmd = args.Parameters.Count > 0 ? args.Parameters[0].ToLower() : "help"; Clan MyClan = null; if (args.Player != TSPlayer.Server) { MyClan = ClanManager.FindClanByPlayer(args.Player); } switch (cmd) { #region checkupdate case "checkupdate": { if (!args.Player.Group.HasPermission(Permission.Create)) { args.Player.SendErrorMessage("You do not have permission to check for updates!"); return; } if (!updateChecker.UpdateAvailable) { updateChecker.CheckForUpdate(); } if (updateChecker.UpdateAvailable) { args.Player.SendInfoMessage("There is an update available for the Clans plugin!"); args.Player.SendInfoMessage("Type /clan changelog to see the changelog!"); } args.Player.SendErrorMessage("No update available!"); } break; #endregion checkupdate #region changelog case "changelog": { if (!updateChecker.UpdateAvailable) { args.Player.SendErrorMessage("There is no update available! Type \"/clan checkupdate\" to check for updates!"); return; } args.Player.SendSuccessMessage("Changelog for the latest version (" + updateChecker.NewVersion + "):"); for (int i = 0; i < updateChecker.ChangeLog.Length; i++) { args.Player.SendInfoMessage(updateChecker.ChangeLog[i]); } } break; #endregion changelog #region create case "create": { if (!args.Player.Group.HasPermission(Permission.Create)) { args.Player.SendErrorMessage("You do not have permission to create a clan!"); return; } if (args.Parameters.Count < 2) { args.Player.SendErrorMessage("Invalid syntax! proper syntax: /clan create <name>"); return; } if (ClanManager.Config.MaxNumberOfClans > 0 && ClanManager.Clans.Keys.Count >= ClanManager.Config.MaxNumberOfClans) { args.Player.SendErrorMessage("The maximum amount of clans has been reached, sorry mate."); return; } string name = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)); if (MyClan != null) { args.Player.SendErrorMessage("You are already in a clan!"); return; } if (ClanManager.FindClanByName(name) != null) { args.Player.SendErrorMessage("This clan already exists!"); return; } if (!ClanManager.CreateClan(args.Player, new Clan() { Name = name, Owner = args.Player.UserAccountName })) { args.Player.SendErrorMessage("Something went wrong! Please contact an administrator."); } } break; #endregion create #region join case "join": { if (args.Parameters.Count < 2) { args.Player.SendErrorMessage("Invalid syntax! proper syntax: /clan join <clan name>"); return; } string name = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)); if (MyClan != null) { args.Player.SendErrorMessage("You are already in a clan!"); return; } Clan c = ClanManager.FindClanByName(name); if (c == null) { args.Player.SendErrorMessage("This clan does not exists!"); return; } if (c.IsBanned(args.Player.UserAccountName)) { args.Player.SendErrorMessage("You have been banned from this clan!"); return; } if (c.InviteMode == InviteMode.True) { args.Player.SendErrorMessage("This clan is in invite-only mode, please ask for an invitation."); return; } ClanManager.JoinClan(args.Player, c); } break; #endregion join #region leave case "leave": { if (MyClan == null) { args.Player.SendErrorMessage("You are not in a clan!"); return; } if (args.Parameters.Count == 2) { if (args.Parameters[1].ToLower() == "confirm") { ClanManager.LeaveClan(args.Player, MyClan); } else { args.Player.SendErrorMessage("Invalid syntax! proper syntax: /clan leave confirm"); } } else { if (args.Player.UserAccountName == MyClan.Owner) { args.Player.SendErrorMessage("You are the owner of this clan, this means that if you leave, the clan will disband!"); } args.Player.SendInfoMessage("Are you sure you want to leave this clan? type \"/clan leave confirm\""); } } break; #endregion leave #region inviteMode case "invitemode": { if (MyClan == null) { args.Player.SendErrorMessage("You are not in a clan!"); return; } if (MyClan.Owner != args.Player.UserAccountName) { args.Player.SendErrorMessage("You are not allowed to alter the clan's invitemode settings!"); return; } string subcmd = args.Parameters.Count == 2 ? args.Parameters[1].ToLower() : string.Empty; switch (subcmd) { case "true": ClanManager.SetInviteMode(MyClan, InviteMode.True); break; case "false": ClanManager.SetInviteMode(MyClan, InviteMode.False); break; default: args.Player.SendErrorMessage("Invalid syntax! proper syntax: /clan invitemode <true/false>"); return; } args.Player.SendInfoMessage("Clan invite mode has been set to " + (MyClan.InviteMode == InviteMode.True ? "true" : "false")); } break; #endregion inviteMode #region reloadclans case "reloadclans": { if (!args.Player.Group.HasPermission(Permission.Reload)) { args.Player.SendErrorMessage("You do not have permission to create a clan!"); return; } ClanManager.ReloadAll(); args.Player.SendInfoMessage("All clans and their members have been reloaded!"); break; } #endregion reloadclans #region reloadconfig case "reloadconfig": { if (!args.Player.Group.HasPermission(Permission.Reload)) { args.Player.SendErrorMessage("You do not have permission to create a clan!"); return; } ClanManager.ReloadConfig(args.Player); } break; #endregion reloadconfig #region list case "list": { int pageNumber; if (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out pageNumber)) { return; } IEnumerable <string> clanNames = ClanManager.Clans.Keys; PaginationTools.SendPage(args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(clanNames), new PaginationTools.Settings { HeaderFormat = "Clans ({0}/{1}):", FooterFormat = "Type /clan list {0} for more.", NothingToDisplayString = "There aren't any clans!", }); } break; #endregion list #region tp case "tp": { if (MyClan == null) { args.Player.SendErrorMessage("You are not in a clan!"); return; } if (MyClan.TileX == 0 || MyClan.TileY == 0) { args.Player.SendErrorMessage("Your clan has no spawn point defined!"); return; } args.Player.Teleport(MyClan.TileX * 16, MyClan.TileY * 16); } break; #endregion tp #region setspawn case "setspawn": { if (MyClan == null) { args.Player.SendErrorMessage("You are not in a clan!"); return; } if (MyClan.Owner != args.Player.UserAccountName) { args.Player.SendErrorMessage("You are not allowed to alter the clan's spawnpoint!"); return; } ClanManager.SetSpawn(MyClan, args.Player); args.Player.SendInfoMessage(string.Format("Your clan's spawnpoint has been changed to X:{0}, Y:{1}", MyClan.TileX, MyClan.TileY)); } break; #endregion setspawn #region setcolor case "setcolor": { if (MyClan == null) { args.Player.SendErrorMessage("You are not in a clan!"); return; } if (MyClan.Owner != args.Player.UserAccountName) { args.Player.SendErrorMessage("You are not allowed to alter the clan's chatcolor!"); return; } if (args.Parameters.Count < 2) { args.Player.SendErrorMessage("Invalid syntax! proper syntax: /clan setcolor <0-255,0-255,0-255>"); return; } if (!ClanManager.SetColor(MyClan, args.Parameters[1])) { args.Player.SendErrorMessage("Invalid color format! proper example: /clan setcolor 125,255,137"); } } break; #endregion setcolor #region who case "who": { int pageNumber; if (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out pageNumber)) { return; } IEnumerable <string> clanMembers = MyClan.OnlineClanMembers.Values.Select(m => m.TSPlayer.Name); PaginationTools.SendPage(args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(clanMembers), new PaginationTools.Settings { HeaderFormat = "Online Clanmembers ({0}/{1}):", FooterFormat = "Type /clan who {0} for more.", }); } break; #endregion who #region find case "find": { if (args.Parameters.Count < 2) { args.Player.SendErrorMessage("Invalid syntax! proper syntax: /clan find <player>"); return; } var foundplr = TShock.Utils.FindPlayer(args.Parameters[1]); if (foundplr.Count == 0) { args.Player.SendMessage("Invalid player!", Color.Red); return; } else if (foundplr.Count > 1) { args.Player.SendMessage(string.Format("More than one ({0}) player matched!", foundplr.Count), Color.Red); return; } TSPlayer plr = foundplr[0]; Clan c = ClanManager.FindClanByPlayer(plr); if (c == null) { args.Player.SendErrorMessage(string.Format("{0} is not in a clan!", plr.Name)); return; } args.Player.SendInfoMessage(string.Format("{0} is in clan: {1}", plr.Name, c.Name)); } break; #endregion find #region togglechat case "togglechat": { MyClan.OnlineClanMembers[args.Player.Index].DefaultToClanChat = !MyClan.OnlineClanMembers[args.Player.Index].DefaultToClanChat; args.Player.SendInfoMessage(MyClan.OnlineClanMembers[args.Player.Index].DefaultToClanChat ? "You will now automaticly talk in the clanchat!" : "You are now using global chat, use /c to talk in clanchat"); } break; #endregion togglechat #region rename case "rename": { if (MyClan == null) { args.Player.SendErrorMessage("You are not in a clan!"); return; } if (MyClan.Owner != args.Player.UserAccountName) { args.Player.SendErrorMessage("You are not allowed to alter the clan's name!"); return; } string name = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)); if (ClanManager.FindClanByName(name) != null) { args.Player.SendErrorMessage("A clan with this name already exists!"); return; } ClanManager.Rename(MyClan, args.Player, name); MyClan.Broadcast("Your clan has been renamed to " + MyClan.Name); } break; #endregion rename #region help default: case "help": { int pageNumber; if (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out pageNumber)) { return; } PaginationTools.SendPage(args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(HelpMsg), new PaginationTools.Settings { HeaderFormat = "Clans help page ({0}/{1})", FooterFormat = "Type /clan help {0} for more.", }); } break; #endregion help } }
public static bool InsertBan(Clan clan, string name) { if (clan.Bans.Contains(name)) return false; clan.Bans.Add(name); UpdateBans(clan); return true; }