示例#1
0
        public static void TCGreetPlayer(int plr)
        {
            string clanName = "";
            string motd     = "";
            bool   valid    = false;
            string plName   = TShock.Players[plr].UserAccountName;
            var    DBQuery  = TCdb.DB.QueryReader("SELECT clanname, motd FROM Clans WHERE leaders LIKE '%" + plName + "%' OR members LIKE '%" + plName + "%'");

            while (DBQuery.Read())
            {
                clanName = DBQuery.Get <string>("clanname");
                motd     = DBQuery.Get <string>("motd");
            }
            if (clanName != "")
            {
                List <string> members = new List <string>();
                members = TCutils.GetMembers(clanName);
                foreach (string i in members)
                {
                    if (i == plName)
                    {
                        valid = true;
                    }
                }
                List <string> leaders = new List <string>();
                leaders = TCutils.GetLeaders(clanName);
                foreach (string i in leaders)
                {
                    if (i == plName)
                    {
                        valid = true;
                    }
                }
                if (valid)
                {
                    TShock.Players[plr].SendMessage("[" + clanName + " MotD]:", Color.GreenYellow);
                    if (motd != "")
                    {
                        TShock.Players[plr].SendMessage(motd, Color.Yellow);
                    }
                    else
                    {
                        TShock.Players[plr].SendMessage("No message.", Color.Yellow);
                    }
                }
            }

            List <string> invites = new List <string>();

            invites = TCutils.GetAllInvites();
            bool isInvited = false;

            {
                for (int i = 0; i < invites.Count; i++)
                {
                    if (plName == invites[i])
                    {
                        isInvited = true;
                        break;
                    }
                }
            }
            if (isInvited)
            {
                DBQuery = TCdb.DB.QueryReader("SELECT clanname FROM Clans WHERE invites LIKE '%" + plName + "%'");
                while (DBQuery.Read())
                {
                    clanName = DBQuery.Get <string>("clanname");
                }

                TShock.Players[plr].SendMessage("You have been invited to join the clan: " + clanName, Color.Orange);
                TShock.Players[plr].SendMessage("/tclan accept - to join", Color.Orange);
                TShock.Players[plr].SendMessage("/tclan decline - to decline invitation.", Color.Orange);
            }

            string clCoFounder = "";
            string clName      = "";
            string clFounder   = "";

            DBQuery = TCdb.DB.QueryReader("SELECT * FROM FoundQueue WHERE cofounder == '" + plName + "' OR founder='" + plName + "'");
            while (DBQuery.Read())
            {
                clName      = DBQuery.Get <string>("clanname");
                clFounder   = DBQuery.Get <string>("founder");
                clCoFounder = DBQuery.Get <string>("cofounder");
            }
            if (clName != "" && clFounder != "" && clCoFounder == plName)
            {
                TShock.Players[plr].SendMessage("You have been invited by to found the clan: " + clanName, Color.Orange);
                TShock.Players[plr].SendMessage("/tcfound accept - to join", Color.Orange);
                TShock.Players[plr].SendMessage("/tcfound decline - to decline invitation.", Color.Orange);
            }
            else if (clName != "" && clFounder == plName && clCoFounder != "")
            {
                TShock.Players[plr].SendMessage("You are gonna found the clan: " + clanName, Color.Orange);
                TShock.Players[plr].SendMessage("/tcfound revoke - revokes invitation.", Color.Orange);
            }
        }
示例#2
0
        public static void TCFound(CommandArgs incArgs)
        {
            if (!incArgs.Player.IsLoggedIn)
            {
                incArgs.Player.SendMessage("You are not logged in!", Color.Red);
                return;
            }
            if (TCutils.AlreadyInClan(incArgs.Player.UserAccountName))
            {
                incArgs.Player.SendMessage("You are already in clan!", Color.Red);
                return;
            }
            if (incArgs.Player.Name == incArgs.Parameters[1])
            {
                incArgs.Player.SendMessage("You cannot invite yourself!", Color.Red);
                return;
            }
            List <Player> coFounder = new List <Player>();

            coFounder = TCutils.GetPlayersByName(incArgs.Parameters[1]);
            if (coFounder.Count == 0)
            {
                incArgs.Player.SendMessage("Player " + incArgs.Parameters[1] + " doesn't exist!", Color.Red);
                return;
            }
            if (!coFounder[0].TSPlayer.IsLoggedIn)
            {
                incArgs.Player.SendMessage("Player " + coFounder[0].TSPlayer.Name + " is not logged in!", Color.Red);
                return;
            }
            if (TCutils.AlreadyInClan(coFounder[0].TSPlayer.UserAccountName))
            {
                incArgs.Player.SendMessage("Player " + coFounder[0].TSPlayer.Name + " is already in clan!", Color.Red);
                return;
            }
            List <string> invites = new List <string>();

            invites = TCutils.GetAllInvites();
            foreach (string i in invites)
            {
                if (i == incArgs.Player.UserAccountName)
                {
                    incArgs.Player.SendMessage("You are invited to another clan! Decline the invitation first!", Color.Red);
                    incArgs.Player.SendMessage("Type /tclan decline", Color.Red);
                    return;
                }
                if (i == coFounder[0].TSPlayer.UserAccountName)
                {
                    incArgs.Player.SendMessage("Player " + coFounder[0].TSPlayer.Name + " is invited to another clan!", Color.Red);
                    return;
                }
            }
            List <string> strQueue = TCutils.InQueue(incArgs.Parameters[0], TCutils.GetPlayersByName(incArgs.Player.Name)[0], coFounder[0]);

            if (strQueue.Count > 0)
            {
                foreach (string i in strQueue)
                {
                    incArgs.Player.SendMessage(i, Color.Red);
                }
                return;
            }

            TCdb.DB.QueryReader("INSERT INTO FoundQueue (clanname, founder, cofounder) VALUES ('" + incArgs.Parameters[0] + "', '" + incArgs.Player.UserAccountName + "', '" + coFounder[0].TSPlayer.UserAccountName + "')");

            coFounder[0].TSPlayer.SendMessage(incArgs.Player.Name + " invites you to found new clan: " + incArgs.Parameters[0], Color.Orange);
            coFounder[0].TSPlayer.SendMessage("/tcfound accept - accepts the invitation. ", Color.Orange);
            coFounder[0].TSPlayer.SendMessage("/tcfound decline - declines the invitation. ", Color.Orange);
            incArgs.Player.SendMessage("You have invited " + coFounder[0].TSPlayer.Name + " to found new clan.", Color.Orange);
        }
示例#3
0
        public static void TCAdd(CommandArgs incArgs)
        {
            bool error = false;

            var           DBQuery      = TCdb.DB.QueryReader("SELECT clangroup FROM Clans WHERE clangroup='" + incArgs.Parameters[3] + "'");
            List <string> existedGroup = new List <string>();

            while (DBQuery.Read())
            {
                existedGroup.Add(DBQuery.Get <string>("clangroup"));
            }

            DBQuery = TCdb.DB.QueryReader("SELECT clanname FROM Clans WHERE clanname='" + incArgs.Parameters[1] + "'");
            List <string> existedClan = new List <string>();

            while (DBQuery.Read())
            {
                existedClan.Add(DBQuery.Get <string>("clanname"));
            }

            List <Player> players = new List <Player>();

            players = TCutils.GetPlayersByName(incArgs.Parameters[2]);
            if (players.Count == 0)
            {
                incArgs.Player.SendMessage("Player " + incArgs.Parameters[2] + " doesn't exist!", Color.Red);
                error = true;
            }
            else
            {
                var leader = players[0].TSPlayer.IsLoggedIn;
                if (!leader)
                {
                    incArgs.Player.SendMessage("Player " + incArgs.Parameters[2] + " is not logged in!", Color.Red);
                    error = true;
                }
                else if (TCutils.AlreadyInClan(players[0].TSPlayer.UserAccountName))
                {
                    incArgs.Player.SendMessage("One of " + incArgs.Parameters[2] + "'s characters is alredy in clan!", Color.Red);
                    error = true;
                }
                List <string> invites = new List <string>();
                invites = TCutils.GetAllInvites();
                foreach (string pl in invites)
                {
                    if (pl == TCutils.GetPlayersByName(incArgs.Parameters[2])[0].TSPlayer.UserAccountName)
                    {
                        incArgs.Player.SendMessage(incArgs.Parameters[2] + " is already invited to another clan!", Color.Red);
                        error = true;
                    }
                }
            }

            var group = TShock.Groups.GroupExists(incArgs.Parameters[3]);

            if (existedGroup.Count > 0)
            {
                incArgs.Player.SendMessage("Group " + incArgs.Parameters[3] + " is already bound to another clan!", Color.Red);
                error = true;
            }
            if (existedClan.Count > 0)
            {
                incArgs.Player.SendMessage("Clan " + incArgs.Parameters[1] + " is already exist!", Color.Red);
                error = true;
            }
            List <string> strQueue = TCutils.InQueue(incArgs.Parameters[1], TCutils.GetPlayersByName(incArgs.Parameters[2])[0], TCutils.GetPlayersByName(incArgs.Parameters[2])[0]);

            if (strQueue.Count > 0)
            {
                incArgs.Player.SendMessage("Clan name is occupied or player is gonna found his own clan.", Color.Red);
                error = true;
            }

            if (!error)
            {
                if (!group)
                {
                    TShock.Groups.AddGroup(incArgs.Parameters[3], "default", "");
                    incArgs.Player.SendMessage("Creating new group: " + incArgs.Parameters[3], Color.LawnGreen);
                }
                else
                {
                    List <string> perms = new List <string>();
                    perms = TShock.Utils.GetGroup(incArgs.Parameters[3]).permissions;
                    //perms.Add("clanchat");
                    incArgs.Player.SendMessage("Binding clan to existing group: " + incArgs.Parameters[3], Color.LawnGreen);
                    TShock.Groups.AddPermissions(incArgs.Parameters[3], perms);
                }
                TCdb.DB.QueryReader("INSERT INTO Clans (clanname, clangroup, leaders, members, motd, invites) VALUES ('" + incArgs.Parameters[1] + "', '" + incArgs.Parameters[3] + "', '" + players[0].TSPlayer.UserAccountName + "', '', 'Welcome to " + incArgs.Parameters[1] + "!', '')");
                incArgs.Player.SendMessage("Added clan: " + incArgs.Parameters[1], Color.LawnGreen);
                var user = new User();
                user.Name = players[0].TSPlayer.UserAccountName;
                if (!players[0].TSPlayer.Group.HasPermission("terraclans"))
                {
                    TShock.Users.SetUserGroup(user, incArgs.Parameters[3]);
                }
                players[0].TSPlayer.SendMessage(incArgs.Player.Name + " created clan \"" + incArgs.Parameters[1] + "\" with you as leader!", Color.YellowGreen);
                players[0].TSPlayer.SendMessage("Please, relogin to apply new settings for your account.", Color.Orange);
            }
        }
示例#4
0
        public static void TCInvite(CommandArgs incArgs)
        {
            List <Player> players = new List <Player>();

            players = TCutils.GetPlayersByName(incArgs.Parameters[1]);
            if (players.Count == 0)
            {
                incArgs.Player.SendMessage("Player " + incArgs.Parameters[1] + " doesn't exist!", Color.Red);
            }
            else if (players.Count > 1)
            {
                incArgs.Player.SendMessage("There are at least 2 players match to " + incArgs.Parameters[1] + "!", Color.Red);
            }
            else
            {
                var reciever = players[0].TSPlayer.IsLoggedIn;
                if (!reciever)
                {
                    incArgs.Player.SendMessage("Player " + players[0].TSPlayer.Name + " is not logged in!", Color.Red);
                }
                else if (TCutils.AlreadyInClan(players[0].TSPlayer.UserAccountName))
                {
                    incArgs.Player.SendMessage("One of " + players[0].TSPlayer.Name + "'s characters is alredy in clan!", Color.Red);
                }
                else
                {
                    var           DBQuery = TCdb.DB.QueryReader("SELECT clanname FROM Clans WHERE leaders LIKE '%" + incArgs.Player.UserAccountName + "%' OR members LIKE '%" + incArgs.Player.UserAccountName + "%'");
                    List <string> Clan    = new List <string>();
                    while (DBQuery.Read())
                    {
                        Clan.Add(DBQuery.Get <string>("clanname"));
                    }
                    string        clanName = Clan[0];
                    List <string> invites  = new List <string>();
                    List <string> strQueue = TCutils.InQueue(clanName, players[0], players[0]);
                    if (strQueue.Count > 0)
                    {
                        incArgs.Player.SendMessage(incArgs.Parameters[1] + "is gonna found his own clan!", Color.Red);
                        return;
                    }
                    invites = TCutils.GetAllInvites();
                    bool isInvited = false;
                    if (invites.Count > 0)
                    {
                        for (int i = 0; i < invites.Count; i++)
                        {
                            if (players[0].TSPlayer.UserAccountName == invites[i])
                            {
                                isInvited = true;
                            }
                        }
                    }
                    if (isInvited)
                    {
                        incArgs.Player.SendMessage("Player " + players[0].TSPlayer.Name + " is already invited to another clan!", Color.Red);
                    }
                    else
                    {
                        invites = TCutils.GetInvites(clanName);
                        invites.Add(players[0].TSPlayer.UserAccountName);
                        string str = string.Join(",", invites.ToArray());
                        TCdb.DB.QueryReader("UPDATE Clans SET invites='" + str + "' WHERE clanname='" + clanName + "'");
                        players[0].TSPlayer.SendMessage(incArgs.Player.Name + " invites you to join the clan: " + clanName, Color.Orange);
                        players[0].TSPlayer.SendMessage("/tclan accept - to join", Color.Orange);
                        players[0].TSPlayer.SendMessage("/tclan decline - to decline invitation.", Color.Orange);
                        incArgs.Player.SendMessage("You invited " + players[0].TSPlayer.Name + " to join your clan!", Color.Yellow);
                    }
                }
            }
        }