Пример #1
0
        private void OARead(CommandArgs args)
        {
            bool isGreet = args.Message.StartsWith("readgreet") ? true : false;

            if (args.Parameters.Count == 0)
            {
                args.Player.SendErrorMessage("Invalid player name.");
                return;
            }

            string playerName = string.Join(" ", args.Parameters);

            var pList = TShock.Utils.FindPlayer(playerName);

            if (pList.Count == 0)
            {
                args.Player.SendErrorMessage("No players found by the name: " + playerName);
                return;
            }
            if (pList.Count > 1)
            {
                TShock.Utils.SendMultipleMatchError(args.Player, pList.Select(e => e.Name));
                return;
            }
            OAInfo info = pList[0].GetData <OAInfo>(OAString);

            args.Player.SendSuccessMessage($"{pList[0].Name}'s greeting and leaving announcements:");
            args.Player.SendMessage(info.greet, config.ToColor());
            args.Player.SendMessage(info.leave, config.ToColor());
        }
Пример #2
0
        public static void UpdateAnnouncement(OAInfo info)
        {
            int result = db.Query("UPDATE `onlineannounce` SET `greet` = @0, `leaving` = @1 WHERE `userid` = @2; ", info.greet, info.leave, info.userid);

            if (result != 1)
            {
                TShock.Log.ConsoleError("Error updating entry in database for user: " + info.userid);
            }
        }
Пример #3
0
        public static void AddAnnouncement(OAInfo info)
        {
            int result = db.Query("INSERT INTO `onlineannounce` (`userid`, `greet`, `leaving`) VALUES (@0, @1, @2);", info.userid, info.greet, info.leave);

            if (result != 1)
            {
                TShock.Log.ConsoleError("Error adding entry to database for user: " + info.userid);
            }
        }
Пример #4
0
        public static void UpdateAnnouncement(OAInfo info)
        {
            string query  = $"UPDATE `onlineannounce` SET `greet` = '{info.greet}', `leaving` = '{info.leave}' WHERE `userid` = {info.userid};";
            int    result = db.Query(query);

            if (result != 1)
            {
                TShock.Log.ConsoleError("Error updating entry in database for user: " + info.userid);
            }
        }
Пример #5
0
        public static void AddAnnouncement(OAInfo info)
        {
            string query  = $"INSERT INTO `onlineannounce` (`userid`, `greet`, `leaving`) VALUES ({info.userid}, '{info.greet}', '{info.leave}');";
            int    result = db.Query(query);

            if (result != 1)
            {
                TShock.Log.ConsoleError("Error adding entry to database for user: " + info.userid);
            }
        }
Пример #6
0
        private void OASet(CommandArgs args)
        {
            bool isGreet = args.Message.StartsWith("setgreet") ? true : false;

            if (args.Parameters.Count < 2)
            {
                args.Player.SendErrorMessage($"Invalid syntax: {(isGreet ? "setgreet" : "setleave")} <player> <announcement>");
                return;
            }

            string playerName = args.Parameters[0];
            string message    = string.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));

            var pList = TShock.Utils.FindPlayer(playerName);

            if (pList.Count == 0)
            {
                args.Player.SendErrorMessage("No players found by the name: " + playerName);
                return;
            }
            if (pList.Count > 1)
            {
                TShock.Utils.SendMultipleMatchError(args.Player, pList.Select(e => e.Name));
                return;
            }
            OAInfo info = pList[0].GetData <OAInfo>(OAString);

            if (isGreet)
            {
                info.greet = message;
            }
            else
            {
                info.leave = message;
            }

            if (info.wasInDatabase)
            {
                DB.UpdateAnnouncement(info);
            }
            else
            {
                DB.AddAnnouncement(info);
            }

            info.wasInDatabase = true;
            pList[0].SetData(OAString, info);
            args.Player.SendSuccessMessage($"You have successfully set {pList[0].Name}'s {(isGreet.OAType())} to {message}");
        }
Пример #7
0
        public static string SetInfo(TSPlayer plr)
        {
            //Using null to signify that it was not in database
            OAInfo newInfo = new OAInfo(plr.Account.ID, false, null, null);

            using (var reader = db.QueryReader("SELECT * FROM `onlineannounce` WHERE `userid` = @0;", plr.Account.ID))
            {
                if (reader.Read())
                {
                    newInfo.wasInDatabase = true;
                    newInfo.greet         = reader.Get <string>("greet");
                    newInfo.leave         = reader.Get <string>("leaving");
                }
            }

            plr.SetData(OAMain.OAString, newInfo);
            return(newInfo.greet);
        }
Пример #8
0
        private void OACommand(CommandArgs args)
        {
            bool isGreet;

            if (args.Message.ToLower().StartsWith("greet"))
            {
                isGreet = true;
            }
            else
            {
                isGreet = false;
            }

            OAInfo info = args.Player.GetData <OAInfo>(OAString);

            if (args.Parameters.Count == 0)
            {
                args.Player.SendErrorMessage($"Invalid syntax: /{(isGreet ? "greet" : "leave")} <announcement/-none>");
                return;
                //if (!info.wasInDatabase)


                //if (isGreet)
                //	info.greet = "";
                //else
                //	info.leave = "";

                //args.Player.SendSuccessMessage($"You removed your {isGreet.OAType()} announcement.");
                //args.Player.SetData(OAString, info);
                //DB.UpdateAnnouncement(info);
                //return;
            }

            string message = string.Join(" ", args.Parameters);

            if (!args.Player.HasPermission("oa.mod"))
            {
                message.StripColors();
            }

            if (message.ToLower() == "-none")
            {
                message = "";
            }

            if (isGreet)
            {
                info.greet = message;
            }
            else
            {
                info.leave = message;
            }

            args.Player.SendSuccessMessage($"You set your {isGreet.OAType()} announcement to: " + (isGreet ? info.greet : info.leave));
            args.Player.SetData(OAString, info);

            if (info.wasInDatabase)
            {
                DB.UpdateAnnouncement(info);
            }
            else
            {
                DB.AddAnnouncement(info);
            }
        }