Beispiel #1
0
        public static void AddAnswer(Client player, int repID, string response, bool deleted = false)
        {
            try
            {
                response = Main.BlockSymbols(response);

                if (!Main.Players.ContainsKey(player))
                {
                    return;
                }
                if (Main.Players[player].AdminLVL == 0)
                {
                    if (Main.Players[player].FractionID != 15)
                    {
                        return;
                    }
                }
                if (!Adverts.ContainsKey(repID))
                {
                    if (deleted)
                    {
                        player.SendChatMessage("Объявления с подобным номером не было найдено.");
                    }
                    return;
                }
                DateTime now = DateTime.Now;

                if (!deleted)
                {
                    try
                    {
                        int moneyad = Adverts[repID].AD.Length / 15 * 6;
                        MoneySystem.Bank.Change(Main.Players[player].Bank, (moneyad * 60 / 100), false);
                        Stocks.fracStocks[6].Money += moneyad * 40 / 100;
                        if (Adverts[repID].AuthorSIM >= 1)
                        {
                            NAPI.Chat.SendChatMessageToAll("!{#00BCD4}" + $"Объявление от {Adverts[repID].Author.Replace('_', ' ')}: {response} | Тел: {Adverts[repID].AuthorSIM}");
                        }
                        else
                        {
                            NAPI.Chat.SendChatMessageToAll("!{#00BCD4}" + $"Объявление от {Adverts[repID].Author.Replace('_', ' ')}: {response}");
                        }
                        NAPI.Chat.SendChatMessageToAll("!{#00BCD4}" + $"Редактор объявления: {player.Name.Replace('_', ' ')}.");
                    } catch {
                    }
                }
                else
                {
                    if (Main.Players[player].AdminLVL != 0)
                    {
                        GameLog.Admin($"{player.Name}", $"delAd", $"{Adverts[repID].Author}");
                    }
                    Notify.Send(player, NotifyType.Info, NotifyPosition.BottomCenter, $"Вы удалили объявление игрока {Adverts[repID].Author}", 3000);
                    Client target = NAPI.Player.GetPlayerFromName(Adverts[repID].Author);
                    if (target != null)
                    {
                        Notify.Send(target, NotifyType.Error, NotifyPosition.BottomCenter, $"{player.Name} удалил Ваше объявление по причине: {response}.", 3000);
                    }
                    response += " | Удалено";
                }

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "UPDATE advertised SET Editor=@resp,EditedAD=@res,Status=@st,Closed=@time WHERE ID=@repid LIMIT 1";
                cmd.Parameters.AddWithValue("@resp", player.Name);
                cmd.Parameters.AddWithValue("@res", response);
                cmd.Parameters.AddWithValue("@st", true);
                cmd.Parameters.AddWithValue("@time", MySQL.ConvertTime(now));
                cmd.Parameters.AddWithValue("@repid", repID);
                MySQL.Query(cmd);

                AdvertNames.Remove(Adverts[repID].Author);

                Adverts[repID].Author     = player.Name;
                Adverts[repID].EditedAD   = response;
                Adverts[repID].ClosedDate = now;
                Adverts[repID].Status     = true;
                Remove(repID);
            }
            catch (Exception e)
            {
                Log.Write(e.ToString(), nLog.Type.Error);
            }
        }