예제 #1
0
        /// <summary>
        /// Default No IRC flood exceed error timeout 750ms
        /// </summary>

        #region CMD Clash of Clan

        private void PluginClan(bool isPrivate, string channel, string nik, string [] cmd, string cmds)
        {
            if (this.Conf.Api == null)
            {
                this._SendNotice(nik, (string)Properties.Resources.ResourceManager.GetString("cmdNoSQL", this._ci));
                return;
            }

            isPrivate = true;
            string        query  = null;
            List <string> txtout = new List <string>();

            stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq cReq = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None;

            try
            {
                query = this.Conf.Api.GetQueryString(cmd, ref cReq, this.Conf.Opt.SQLDBFilterMemberTag.collection, this.Conf.ILog.LogError);

#if DEBUG_PluginClanQuery
                stConsole.WriteHeader("Plugin Clan Query: " + query);
#endif

                if (string.IsNullOrWhiteSpace(query))
                {
                    throw new ArgumentNullException((string)Properties.Resources.ResourceManager.GetString("cmdIrcQueryEmpty", this._ci));
                }
            }
            catch (CoCDBException e)
            {
                string msg;

                switch (e.enumId)
                {
                case stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtNone:
                {
                    msg = ((string.IsNullOrWhiteSpace(e.Message)) ? null : e.Message);
                    break;
                }

                case stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtClanHelp:
                {
                    msg = (string)Properties.Resources.ResourceManager.GetString("fmtClanHelp", this._ci);
                    break;
                }

                case stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtClanPlayerHelp:
                {
                    msg = (string)Properties.Resources.ResourceManager.GetString("fmtClanPlayerHelp", this._ci);
                    break;
                }

                case stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtWarLog:
                {
                    msg = (string)Properties.Resources.ResourceManager.GetString("fmtWarLogHelp", this._ci);
                    break;
                }

                case stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtWarLast:
                {
                    msg = (string)Properties.Resources.ResourceManager.GetString("fmtWarLastHelp", this._ci);
                    break;
                }

                case stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtDonation:
                {
                    msg = (string)Properties.Resources.ResourceManager.GetString("fmtClanDonationHelp", this._ci);
                    break;
                }

                default:
                {
                    msg = null;
                    break;
                }
                }
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    this._SendNotice(nik, msg);
                    return;
                }
            }
            catch (Exception e)
            {
                this._SendNotice(nik, e.Message);
                return;
            }
            if (
                (cReq == stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None) ||
                (string.IsNullOrWhiteSpace(query))
                )
            {
                this._SendNotice(nik,
                                 ((cReq == stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None) ?
                                  (string)Properties.Resources.ResourceManager.GetString("cmdQueryWrong", this._ci) :
                                  (string)Properties.Resources.ResourceManager.GetString("cmdQueryError", this._ci)
                                 )
                                 );
                return;
            }

            DataTable dTable = null;

            try
            {
                dTable = this.Conf.Api.QueryData(query);

#if DEBUG_DataTablePrint
                dTable.DataTableToPrint();
#endif
            }
            catch (Exception e)
            {
                if (dTable != null)
                {
                    dTable.Dispose();
                }
                this._SendNotice(nik, e.Message);
                return;
            }
            if ((dTable == null) || (dTable.Rows.Count == 0))
            {
                this._SendNotice(nik, (string)Properties.Resources.ResourceManager.GetString("cmdQueryEmpty", this._ci));
                return;
            }
            switch (cReq)
            {
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.List:
            {
                txtout.Add(
                    string.Format(
                        (string)Properties.Resources.ResourceManager.GetString("fmtMembersTotal", this._ci),
                        dTable.Rows.Count.ToString()
                        ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkViolet)
                    );
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationSend:
            {
                txtout.Add(
                    string.Format(
                        (string)Properties.Resources.ResourceManager.GetString("fmtClanDonation", this._ci),
                        dTable.Rows.Count.ToString(),
                        "sender"
                        ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkViolet)
                    );
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationReceive:
            {
                txtout.Add(
                    string.Format(
                        (string)Properties.Resources.ResourceManager.GetString("fmtClanDonation", this._ci),
                        dTable.Rows.Count.ToString(),
                        "reciver"
                        ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkViolet)
                    );
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationRatio:
            {
                txtout.Add(
                    string.Format(
                        (string)Properties.Resources.ResourceManager.GetString("fmtClanDonation", this._ci),
                        dTable.Rows.Count.ToString(),
                        "ratio"
                        ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkViolet)
                    );
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationTotal:
            {
                txtout.Add(
                    string.Format(
                        (string)Properties.Resources.ResourceManager.GetString("fmtClanDonation", this._ci),
                        dTable.Rows.Count.ToString(),
                        "total"
                        ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkViolet)
                    );
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.WarLog:
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.WarLast:
            {
                txtout.Add(
                    string.Format(
                        (string)Properties.Resources.ResourceManager.GetString("fmtClanWar", this._ci),
                        dTable.Rows.Count.ToString()
                        ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkViolet)
                    );
                break;
            }
            }
            switch (cReq)
            {
            default:
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None:
            {
                dTable.Dispose();
                this._SendNotice(nik, (string)Properties.Resources.ResourceManager.GetString("cmdQueryWrong", this._ci));
                return;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Info:
            {
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            " Clan: ", (string)row["name"],
                            " / Level: ", ((Int64)row["level"]).ToString(),
                            " / Country: ", (string)row["locname"],
                            " | Tag: ", (string)row["tag"],
                            " | Members: ", ((Int64)row["members"]).ToString(), "/50 "
                        },
                            null,
                            this.Conf.ILog.LogError
                            ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkGray)
                        );
                }
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.War:
            {
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            " Clan: ", (string)row["name"],
                            " | War freq: ", (string)row["warfreq"],
                            " | War win: ", ((Int64)row["warwin"]).ToString(),
                            " | War strenght: ", ((Int64)row["warstr"]).ToString(),
                            " | War public: ",
                            ((
                                 ((Int64)row["warpub"]).Equals(1)
                                 ) ?
                             (string)Properties.Resources.ResourceManager.GetString("prnYes", this._ci) :
                             (string)Properties.Resources.ResourceManager.GetString("prnNo", this._ci)
                            )
                        },
                            null,
                            this.Conf.ILog.LogError
                            ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkGray)
                        );
                }
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.WarLog:
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.WarLast:
            {
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            " ", ((DateTime)row["dtend"]).ToString(),
                            " : ", (string)row["result"],
                            " | \"", (string)row["cname"],
                            "\" (", ((Int64)row["clevel"]).ToString(),
                            ") vs \"", (string)row["opname"],
                            "\" (", ((Int64)row["oplevel"]).ToString(),
                            ") <", ((Int64)row["members"]).ToString(),
                            "> | attacks: ", ((Int64)row["cattacks"]).ToString(), "/", ((Int64)row["opattacks"]).ToString(),
                            " | stars: ", ((Int64)row["cstars"]).ToString(), "/", ((Int64)row["opstars"]).ToString(),
                            " | destruct: ", ((System.Single)row["cdestruct"]).ToString(), "/", ((System.Single)row["opdestruct"]).ToString()
                        },
                            null,
                            this.Conf.ILog.LogError
                            ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkGray)
                        );
                }
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Statistic:
            {
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            " Clan: ", (string)row["name"],
                            " | Type: ", (string)row["type"],
                            " | Points: ", ((Int64)row["points"]).ToString(),
                            " | Needed trophies: ", ((Int64)row["trophies"]).ToString()
                        },
                            null,
                            this.Conf.ILog.LogError
                            ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkGray)
                        );
                }
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Description:
            {
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            " Clan: ", (string)row["name"],
                            " | Description: \"", (string)row["desc"], "\""
                        },
                            null,
                            this.Conf.ILog.LogError
                            ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkBlue)
                        );
                }
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.List:
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Player:
            {
                int i = 1;
                txtout.Add(
                    ((string)Properties.Resources.ResourceManager.GetString("fmtAnswerList", this._ci)).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.Orange)
                    );
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            ((i < 10) ? "  " : "") + i.ToString(), " | ",
                            CreateString.Build(
                                new string[] {
                                " ",
                                (string)row["nik"], " | ",
                                (string)row["tag"], " | ",
                                ((Int64)row["level"]).ToString(), " | ",
                                ((Int64)row["rank"]).ToString(), "/", ((Int64)row["prank"]).ToString(), " | ",
                                ((Int64)row["trophies"]).ToString(), " | '",
                                (string)row["league"], "' | '",
                                (string)row["role"], "' | ",
                                ((Int64)row["send"]).ToString(), " | ",
                                ((Int64)row["receive"]).ToString(), " | ",
                                ((System.Single)row["ratio"]).ToString(), " | "
                            }
                                ).ColorText(IrcFormatText.Color.Black, IrcFormatText.Color.LightGray)
                        },
                            null,
                            this.Conf.ILog.LogError
                            )
                        );
                    i++;
                }
#if DEBUG_ListPrint
                foreach (string str in txtout)
                {
                    stConsole.WriteLine(str);
                }
#endif
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationSend:
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationReceive:
            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationRatio:
            {
                int i = 1;
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            i.ToString(), " | ",
                            CreateString.Build(
                                new string[] {
                                " ",
                                (string)row["nik"], " | '",
                                (string)row["role"], "' | ",
                                ((Int64)row["send"]).ToString(), " | ",
                                ((Int64)row["receive"]).ToString(), " | ",
                                ((System.Single)row["ratio"]).ToString(), " | "
                            }
                                ).ColorText(IrcFormatText.Color.Black, IrcFormatText.Color.LightGray)
                        },
                            null,
                            this.Conf.ILog.LogError
                            )
                        );
                    i++;
                }
                break;
            }

            case stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationTotal:
            {
                foreach (DataRow row in dTable.Rows)
                {
                    txtout.Add(
                        CreateString.Build(
                            new string[] {
                            "   Total send in Clan: ", ((Int64)row["tsend"]).ToString(),
                            " | Total recive in Clan: ", ((Int64)row["treceive"]).ToString(),
                            " | Total send  out Clan: ", ((Int64)row["tsend"] - (Int64)row["treceive"]).ToString(),
                            "   "
                        },
                            null,
                            this.Conf.ILog.LogError
                            ).ColorText(IrcFormatText.Color.White, IrcFormatText.Color.DarkBlue)
                        );
                }
                break;
            }
            }

            dTable.Dispose();

            if (txtout.Count == 0)
            {
                this._SendNotice(nik, (string)Properties.Resources.ResourceManager.GetString("cmdQueryEmpty", this._ci));
            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    AutoResetEvent are = new AutoResetEvent(false);
                    foreach (string str in txtout)
                    {
                        if (!string.IsNullOrWhiteSpace(str))
                        {
                            this._SendFromTask(isPrivate, channel, nik, str);
                            are.WaitOne(TimeSpan.FromMilliseconds(this.Conf.Opt.IRCFloodTimeOut.num), true);
                        }
                    }
                    are.Close();
                    are.Dispose();
                });
            }
        }
예제 #2
0
            /// <summary>
            /// Get Sqlite DB Query string
            /// </summary>
            /// <param name="cmd">array Query string</param>
            /// <param name="cReq">enum ClanTypeReq</param>
            /// <param name="LogError">Log Error <code>Action{string}</code></param>
            /// <returns>DB query syting</returns>
            public static string _GetQueryString(
                string[] cmd,
                ref stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq cReq,
                StringCollection hide,
                Action <string> LogError
                )
            {
                cReq = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None;
                string query    = String.Empty,
                       playerId = "";

                switch (cmd.Length)
                {
                default:
                case 0:
                case 1:
                {
                    throw new CoCDBException(
                              stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtClanHelp,
                              string.Format(
                                  Properties.Resources.CoCDBExceptionLength,
                                  "QueryString->begin"
                                  )
                              );
                }

                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                {
                    int idx = 1;
                    if (cmd[1].Equals("setup"))
                    {
                        cReq = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.ServerSetup;
                        return(String.Empty);
                    }
                    else if (cmd[1].Equals("notify"))
                    {
                        cReq = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.None;
                        throw new CoCDBException(
                                  stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtNone,
                                  CoCDB.thisClass
                                  );
                    }
                    else if ((cmd[1].Equals("info")) || (cmd[1].Equals("clan")))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Info;
                        query = Properties.Settings.Default.DBSelectClanInfo;
                    }
                    else if (cmd[1].Equals("war"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.War;
                        query = Properties.Settings.Default.DBSelectClanInfo;
                    }
                    else if (cmd[1].Equals("stat"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Statistic;
                        query = Properties.Settings.Default.DBSelectClanInfo;
                    }
                    else if (cmd[1].Equals("desc"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Description;
                        query = Properties.Settings.Default.DBSelectClanInfo;
                    }
                    else if (cmd[1].Equals("warlog"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.WarLog;
                        query = Properties.Settings.Default.DBSelectWarClan;
                    }
                    else if (cmd[1].Equals("warlast"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.WarLast;
                        query = CreateString.Build(
                            new string[] {
                                Properties.Settings.Default.DBSelectWarClan,
                                Properties.Settings.Default.DBSelectWarLast
                            }, " ",
                            LogError);
                    }
                    else if (cmd[1].Equals("list"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.List;
                        query = CreateString.Build(
                            new string[] {
                                string.Format(
                                    Properties.Settings.Default.DBSelectMember, 1
                                    ),
                                CoCSeason.GetSeasonDateDB(idx, cmd),
                                CoCDB._GetHideTagSelect(hide),
                                Properties.Settings.Default.DBSelectMemberListOrder
                            }, " ",
                            LogError);
                    }
                    else if (cmd[1].Equals("random"))
                    {
                        cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Player;
                        query = CreateString.Build(
                            new string[] {
                                string.Format(
                                    Properties.Settings.Default.DBSelectMember, 1
                                    ),
                                CoCSeason.GetSeasonDateDB(idx, cmd),
                                CoCDB._GetHideTagSelect(hide),
                                Properties.Settings.Default.DBSelectMemberRand
                            }, " ",
                            LogError);
                    }
                    else if ((cmd[1].Equals("player")) || (cmd[1].Equals("member")))
                    {
                        if (cmd.Length == 2)
                        {
                            throw new CoCDBException(
                                      stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtClanPlayerHelp,
                                      string.Format(
                                          Properties.Resources.CoCDBExceptionLength,
                                          "QueryString->player"
                                          )
                                      );
                        }
                        idx++;
                        cReq     = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.Player;
                        playerId = ((cmd[2].StartsWith("#")) ? cmd[2].Substring(1) : cmd[2]);
                        query    = CreateString.Build(
                            new string[] {
                                string.Format(
                                    Properties.Settings.Default.DBSelectMember, 1
                                    ),
                                CoCSeason.GetSeasonDateDB(idx, cmd),
                                CoCDB._GetHideTagSelect(hide),
                                // add
                                string.Format(
                                    Properties.Settings.Default.DBSelectMemberTag,
                                    playerId
                                    )
                            }, " ",
                            LogError);
                    }
                    else if (cmd[1].Equals("donation"))
                    {
                        if (cmd.Length > 2)
                        {
                            if (cmd[2].Equals("send"))
                            {
                                cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationSend;
                                query = CreateString.Build(
                                    new string[] {
                                        Properties.Settings.Default.DBSelectDonation,
                                        CoCSeason.GetSeasonDateDB(idx, cmd),
                                        CoCDB._GetHideTagSelect(hide),
                                        Properties.Settings.Default.DBSelectDonationSendOrder
                                    }, " ",
                                    LogError);
                                idx++;
                            }
                            else if (cmd[2].Equals("receive"))
                            {
                                cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationReceive;
                                query = CreateString.Build(
                                    new string[] {
                                        Properties.Settings.Default.DBSelectDonation,
                                        CoCSeason.GetSeasonDateDB(idx, cmd),
                                        CoCDB._GetHideTagSelect(hide),
                                        Properties.Settings.Default.DBSelectDonationReceiveOrder
                                    }, " ",
                                    LogError);
                                idx++;
                            }
                            else if ((cmd[2].Equals("ratio")) || (cmd[2].Equals("rate")))
                            {
                                cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationRatio;
                                query = CreateString.Build(
                                    new string[] {
                                        Properties.Settings.Default.DBSelectDonation,
                                        Properties.Settings.Default.DBSelectDonationRatio,
                                        CoCSeason.GetSeasonDateDB(idx, cmd),
                                        CoCDB._GetHideTagSelect(hide),
                                        Properties.Settings.Default.DBSelectDonationRatioOrder
                                    }, " ",
                                    LogError);
                                idx++;
                            }
                            else if (cmd[2].Equals("total"))
                            {
                                cReq  = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationTotal;
                                query = CreateString.Build(
                                    new string[] {
                                        Properties.Settings.Default.DBSelectDonationTotal,
                                        CoCSeason.GetSeasonDateDB(idx, cmd)
                                    }, " ",
                                    LogError);
                                idx++;
                            }
                        }
                        else
                        {
                            cReq = stCoCAPI.CoCAPI.CoCEnum.ClanTypeReq.DonationSend;
                            throw new CoCDBException(
                                      stCoCAPI.CoCAPI.CoCEnum.ClanFmtReq.fmtDonation,
                                      CoCDB.thisClass
                                      );
                        }
                    }
                    else
                    {
                        return(String.Empty);
                    }
                    return(query);
                }
                }
            }