Advertisement
Guest User

statlogger

a guest
Jul 5th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 461.49 KB | None | 0 0
  1. /*  Copyright 2013 [GWC]XpKillerhx
  2.  
  3.     This plugin file is part of PRoCon Frostbite.
  4.  
  5.     This plugin is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This plugin is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with PRoCon Frostbite.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. using System;
  20. //using System.IO;
  21. using System.Text;
  22. using System.Text.RegularExpressions;
  23. using System.Reflection;
  24. using System.Collections;
  25. using System.Collections.Generic;
  26. using System.Collections.ObjectModel;
  27.  
  28. using System.Data;
  29. using System.Configuration;
  30. using System.ComponentModel;
  31. using System.Threading;
  32. //using System.Net;
  33.  
  34. //MySQL native includes
  35. //using MySql.Data;
  36. using MySql.Data.MySqlClient;
  37.  
  38.  
  39. //Procon includes
  40. using PRoCon.Core;
  41. using PRoCon.Core.Plugin;
  42. using PRoCon.Core.Plugin.Commands;
  43. using PRoCon.Core.Players;
  44. using PRoCon.Core.Players.Items;
  45.  
  46. namespace PRoConEvents
  47. {
  48.     public class CChatGUIDStatsLogger : PRoConPluginAPI, IPRoConPluginInterface
  49.     {
  50.         #region Variables and Constructor
  51.  
  52.         private MatchCommand loggerStatusCommand;
  53.  
  54.         //Proconvariables
  55.         private string m_strHostName;
  56.         private string m_strPort;
  57.         private string m_strPRoConVersion;
  58.  
  59.         //Tablebuilder
  60.         private readonly object tablebuilderlock;
  61.  
  62.         //other locks
  63.         private readonly object chatloglock;
  64.         private readonly object sqlquerylock;
  65.         private readonly object sessionlock;
  66.         private readonly object streamlock;
  67.         private readonly object ConnectionStringBuilderlock;
  68.         private readonly object registerallcomandslock;
  69.  
  70.         //Dateoffset
  71.         private myDateTime_W MyDateTime;
  72.         private double m_dTimeOffset;
  73.  
  74.         //Logging
  75.         private Dictionary<string, CPunkbusterInfo> m_dicPbInfo = new Dictionary<string, CPunkbusterInfo>();
  76.         //Chatlog
  77.         private static List<CLogger> ChatLog = new List<CLogger>();
  78.         private List<string> lstStrChatFilterRules;
  79.         private List<Regex> lstChatFilterRules;
  80.         //Statslog
  81.         private Dictionary<string, CStats> StatsTracker = new Dictionary<string, CStats>();
  82.         //Dogtags
  83.         private Dictionary<CKillerVictim, int> m_dicKnifeKills = new Dictionary<CKillerVictim, int>();
  84.         //Session
  85.         private Dictionary<string, CStats> m_dicSession = new Dictionary<string, CStats>();
  86.         private CMapstats Mapstats;
  87.         private CMapstats Nextmapinfo;
  88.         private List<CStats> lstpassedSessions = new List<CStats>();
  89.  
  90.         //GameMod
  91.         //private string m_strGameMod;
  92.  
  93.         //Spamprotection
  94.         private int numberOfAllowedRequests;
  95.         private CSpamprotection Spamprotection;
  96.  
  97.         //Keywords
  98.         private List<string> m_lstTableconfig = new List<string>();
  99.         private Dictionary<string, List<string>> m_dicKeywords = new Dictionary<string, List<string>>();
  100.  
  101.         //Weapondic
  102.         private Dictionary<string, Dictionary<string, CStats.CUsedWeapon>> weaponDic = new Dictionary<string, Dictionary<string, CStats.CUsedWeapon>>();
  103.  
  104.         //DamageClassDic
  105.         private Dictionary<string, string> DamageClass = new Dictionary<string, string>();
  106.  
  107.         //WelcomeStatsDic
  108.         private Dictionary<string, DateTime> welcomestatsDic = new Dictionary<string, DateTime>();
  109.  
  110.         //Weapon Mapping Dictionary
  111.         private Dictionary<string, int> WeaponMappingDic = new Dictionary<string, int>();
  112.  
  113.         //ServerID
  114.         private int ServerID;
  115.  
  116.         //Awards
  117.         private List<string> m_lstAwardTable = new List<string>();
  118.  
  119.         //Tablenames
  120.         private string tbl_playerdata;
  121.         private string tbl_playerstats;
  122.         private string tbl_weaponstats;
  123.         private string tbl_dogtags;
  124.         private string tbl_mapstats;
  125.         private string tbl_chatlog;
  126.         private string tbl_bfbcs;
  127.         private string tbl_awards;
  128.         private string tbl_server;
  129.         private string tbl_server_player;
  130.         private string tbl_server_stats;
  131.         private string tbl_playerrank;
  132.         private string tbl_sessions;
  133.         private string tbl_currentplayers;
  134.         private string tbl_weapons;
  135.         private string tbl_weapons_stats;
  136.         private string tbl_games;
  137.         private string tbl_teamscores;
  138.  
  139.         // Timelogging
  140.         private bool bool_roundStarted;
  141.         private DateTime Time_RankingStarted;
  142.  
  143.         //Other
  144.         private Dictionary<string, CPlayerInfo> m_dicPlayers = new Dictionary<string, CPlayerInfo>();   //Players
  145.  
  146.         //ID Cache
  147.         private Dictionary<string, C_ID_Cache> m_ID_cache = new Dictionary<string, C_ID_Cache>();
  148.  
  149.         //Various Variables
  150.         //private int m_strUpdateInterval;
  151.         private bool isStreaming;
  152.         private string serverName;
  153.         private bool m_isPluginEnabled;
  154.         private bool boolTableEXISTS;
  155.         private bool boolKeywordDicReady;
  156.         private string tableSuffix;
  157.         private bool MySql_Connection_is_activ;
  158.         //Last time Stat Logger actively interacted with the database
  159.         private DateTime lastDBInteraction = DateTime.MinValue;
  160.  
  161.         //Update skipswitches
  162.         private bool boolSkipGlobalUpdate;
  163.         private bool boolSkipServerUpdate;
  164.         private bool boolSkipServerStatsUpdate;
  165.  
  166.         //Transaction retry
  167.         private int TransactionRetryCount;
  168.  
  169.         //Playerstartcount
  170.         private int intRoundStartCount;
  171.         private int intRoundRestartCount;
  172.  
  173.         //Webrequest
  174.         private int m_requestIntervall;
  175.         private string m_webAddress;
  176.  
  177.         //BFBCS
  178.         //private double BFBCS_UpdateInterval;
  179.         //private int BFBCS_Min_Request;
  180.  
  181.         //Database Connection Variables
  182.         private string m_strHost;
  183.         private string m_strDBPort;
  184.         private string m_strDatabase;
  185.         private string m_strUserName;
  186.         private string m_strPassword;
  187.         //private string m_strDatabaseDriver;
  188.  
  189.         //Stats Message Variables        
  190.         private List<string> m_lstPlayerStatsMessage;
  191.         private List<string> m_lstPlayerOfTheDayMessage;
  192.         private List<string> m_lstPlayerWelcomeStatsMessage;
  193.         private List<string> m_lstNewPlayerWelcomeMsg;
  194.         private List<string> m_lstWeaponstatsMsg;
  195.         private List<string> m_lstServerstatsMsg;
  196.         //private string m_strPlayerWelcomeMsg;
  197.         //private string m_strNewPlayerWelcomeMsg;
  198.         private int int_welcomeStatsDelay;
  199.         private string m_strTop10Header;
  200.         private string m_strTop10RowFormat;
  201.         private string m_strWeaponTop10Header;
  202.         private string m_strWeaponTop10RowFormat;
  203.  
  204.         //top10 for Period
  205.         private string m_strTop10HeaderForPeriod;
  206.  
  207.         //Session
  208.         private List<string> m_lstSessionMessage;
  209.  
  210.         //Debug
  211.         private string GlobalDebugMode;
  212.  
  213.         //ServerGroup
  214.         private int intServerGroup;
  215.  
  216.         //Bools for switch on and off funktions
  217.         private enumBoolYesNo m_enNoServerMsg;  //Logging of Server Messages
  218.         private enumBoolYesNo m_enLogSTATS;     //Statslogging
  219.         private enumBoolYesNo m_enWelcomeStats; //WelcomeStats
  220.         private enumBoolYesNo m_enYellWelcomeMSG;   // Yell Welcome Message
  221.         private enumBoolYesNo m_enTop10ingame;      //Top10 ingame
  222.         private enumBoolYesNo m_enRankingByScore;   //Ranking by Score
  223.         private enumBoolYesNo m_enInstantChatlogging;   //Realtime Chatlogging
  224.         private enumBoolYesNo m_enChatloggingON;    // Chatlogging On
  225.         private enumBoolYesNo m_enChatlogFilter;    //Turn on the Chatlogfilter
  226.         private enumBoolYesNo m_enSendStatsToAll;   //All Player see the Stats if someone enter @stats  @rank
  227.         private enumBoolYesNo m_mapstatsON;         //Mapstats
  228.         private enumBoolYesNo m_sessionON;          //Sessionstats
  229.         private enumBoolYesNo m_weaponstatsON;      //Turn Weaponstats On and Off
  230.         private enumBoolYesNo m_getStatsfromBFBCS;  //Turn Statsfetching from BFBCS On and Off
  231.         private enumBoolYesNo m_awardsON;           //Turn Awards on or off
  232.         private enumBoolYesNo m_enWebrequest;       // Webrequest
  233.         private enumBoolYesNo m_enOverallRanking;   //Overall Ranking
  234.         private enumBoolYesNo m_enableInGameCommands; // Turn InGame Commands on and off
  235.         private enumBoolOnOff m_highPerformanceConnectionMode;
  236.         private enumBoolYesNo m_enSessionTracking;
  237.         private enumBoolYesNo m_kdrCorrection; //Kill death Ratio Correction
  238.         private enumBoolYesNo m_enableCurrentPlayerstatsTable; // experimental
  239.         private enumBoolYesNo m_enLogPlayerDataOnly;
  240.         private enumBoolOnOff m_connectionPooling; //Connection Pooling
  241.         private enumBoolOnOff m_Connectioncompression;
  242.  
  243.         private int m_maxPoolSize; //Connection Pooling
  244.         private int m_minPoolSize; //Connection Pooling
  245.  
  246.         //More Database Variables
  247.         //Commands
  248.         //Transactions
  249.         private MySql.Data.MySqlClient.MySqlTransaction MySqlTrans;
  250.         //Connections
  251.         private MySql.Data.MySqlClient.MySqlConnection MySqlCon; //Select Querys 1
  252.         private MySql.Data.MySqlClient.MySqlConnection MySqlChatCon; //MySqlConnection for Chatlogging
  253.         private MySql.Data.MySqlClient.MySqlConnection MySqlConn; //StartStreaming 2
  254.  
  255.         MySqlConnectionStringBuilder myCSB = new MySqlConnectionStringBuilder();
  256.  
  257.         //ServerInfo Event fix
  258.         private DateTime dtLastServerInfoEvent;
  259.         private int minIntervalllenght;
  260.  
  261.         //Double Roundendfix
  262.         private DateTime dtLastRoundendEvent;
  263.         private DateTime dtLastOnListPlayersEvent;
  264.  
  265.         //Top10 for Period
  266.         private int m_intDaysForPeriodTop10;
  267.  
  268.         //New In-Game Command System
  269.         private string m_IngameCommands_stats;
  270.         private string m_IngameCommands_serverstats;
  271.         private string m_IngameCommands_session;
  272.         private string m_IngameCommands_dogtags;
  273.         private string m_IngameCommands_top10;
  274.         private string m_IngameCommands_playerOfTheDay;
  275.         private string m_IngameCommands_top10ForPeriod;
  276.  
  277.         private Dictionary<string,CStatsIngameCommands> dicIngameCommands = new Dictionary<string,CStatsIngameCommands>();
  278.  
  279.         //ServerGametype
  280.         private string strServerGameType = String.Empty;
  281.         private int intServerGameType_ID;
  282.  
  283.         public CChatGUIDStatsLogger()
  284.         {
  285.             loggerStatusCommand = new MatchCommand("CChatGUIDStatsLogger", "GetStatus", new List<string>(), "CChatGUIDStatsLogger_Status", new List<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.None), "Useable by other plugins to determine the current status of this plugin.");
  286.  
  287.             //tablebuilderlock
  288.             this.tablebuilderlock = new object();
  289.             //other locks
  290.             this.chatloglock = new object();
  291.             this.sqlquerylock = new object();
  292.             this.sessionlock = new object();
  293.             this.streamlock = new object();
  294.             this.ConnectionStringBuilderlock = new object();
  295.             this.registerallcomandslock = new object();
  296.  
  297.  
  298.             //update skipswitch
  299.             this.boolSkipGlobalUpdate = false;
  300.             this.boolSkipServerUpdate = false;
  301.             this.boolSkipServerStatsUpdate = false;
  302.  
  303.             //Timeoffset
  304.             this.m_dTimeOffset = 0;
  305.             this.MyDateTime = new myDateTime_W(this.m_dTimeOffset);
  306.  
  307.             //this.m_strUpdateInterval = 30;
  308.             this.isStreaming = true;
  309.             this.serverName = String.Empty;
  310.             this.m_ID_cache = new Dictionary<string, C_ID_Cache>();
  311.             this.m_dicKeywords = new Dictionary<string, List<string>>();
  312.             this.boolKeywordDicReady = false;
  313.             this.tableSuffix = String.Empty;
  314.             this.Mapstats = new CMapstats(MyDateTime.Now, "START", 0, 0, this.m_dTimeOffset);
  315.             this.MySql_Connection_is_activ = false;
  316.             this.numberOfAllowedRequests = 10;
  317.  
  318.             //Transaction retry count
  319.             TransactionRetryCount = 3;
  320.  
  321.             //Chatlog
  322.             this.lstStrChatFilterRules = new List<string>();
  323.             this.lstChatFilterRules = new List<Regex>();
  324.  
  325.             //BFBCS
  326.             //this.BFBCS_UpdateInterval = 72; // hours
  327.             //this.BFBCS_Min_Request = 2; //min Packrate
  328.  
  329.             //Playerstartcount
  330.             this.intRoundStartCount = 2;
  331.             this.intRoundRestartCount = 1;
  332.  
  333.             //Webrequest
  334.             this.m_webAddress = String.Empty;
  335.             this.m_requestIntervall = 60;
  336.  
  337.             //Databasehost
  338.             this.m_strHost = String.Empty;
  339.             this.m_strDBPort = String.Empty;
  340.             this.m_strDatabase = String.Empty;
  341.             this.m_strUserName = String.Empty;
  342.             this.m_strPassword = String.Empty;
  343.  
  344.             //Various Bools
  345.             this.bool_roundStarted = false;
  346.             this.m_isPluginEnabled = false;
  347.             this.boolTableEXISTS = false;
  348.  
  349.             //ServerGroup
  350.             this.intServerGroup = 0;
  351.  
  352.             //Debug
  353.             this.GlobalDebugMode = "Error";
  354.  
  355.             //Functionswitches
  356.             this.m_enLogSTATS = enumBoolYesNo.No;
  357.             this.m_enWelcomeStats = enumBoolYesNo.No;
  358.             this.m_enYellWelcomeMSG = enumBoolYesNo.No;
  359.             this.m_enTop10ingame = enumBoolYesNo.No;
  360.             this.m_enRankingByScore = enumBoolYesNo.Yes;
  361.             this.m_enNoServerMsg = enumBoolYesNo.No;
  362.             this.m_enInstantChatlogging = enumBoolYesNo.No;
  363.             this.m_enChatloggingON = enumBoolYesNo.No;
  364.             this.m_enChatlogFilter = enumBoolYesNo.No;
  365.             this.m_enSendStatsToAll = enumBoolYesNo.No;
  366.             this.m_mapstatsON = enumBoolYesNo.No;
  367.             this.m_sessionON = enumBoolYesNo.No;
  368.             this.m_weaponstatsON = enumBoolYesNo.Yes;
  369.             this.m_getStatsfromBFBCS = enumBoolYesNo.No;
  370.             this.m_awardsON = enumBoolYesNo.No;
  371.             this.m_enOverallRanking = enumBoolYesNo.No;
  372.             this.m_enableInGameCommands = enumBoolYesNo.Yes;
  373.             this.m_highPerformanceConnectionMode = enumBoolOnOff.Off;
  374.  
  375.             this.m_kdrCorrection = enumBoolYesNo.Yes; //Kill death Ratio Correction
  376.             this.m_enableCurrentPlayerstatsTable = enumBoolYesNo.No; // experimental
  377.  
  378.             this.m_enLogPlayerDataOnly = enumBoolYesNo.No;
  379.  
  380.             this.m_connectionPooling = enumBoolOnOff.On; //Connection Pooling
  381.             this.m_Connectioncompression = enumBoolOnOff.Off;
  382.  
  383.             this.m_minPoolSize = 0; //Connection Pooling
  384.             this.m_maxPoolSize = 10; //Connection Pooling
  385.            
  386.  
  387.             //Welcomestats
  388.             //this.m_strPlayerWelcomeMsg = "[yell,4]Nice to see you on our Server again, %playerName%";
  389.             //this.m_strNewPlayerWelcomeMsg = "[yell,4]Welcome to the %serverName% Server, %playerName%";
  390.             this.int_welcomeStatsDelay = 5;
  391.             this.welcomestatsDic = new Dictionary<string, DateTime>();
  392.  
  393.             //Playerstats
  394.             this.m_lstPlayerStatsMessage = new List<string>();
  395.             this.m_lstPlayerStatsMessage.Add("Serverstats for %playerName%:");
  396.             this.m_lstPlayerStatsMessage.Add("Score: %playerScore%  %playerKills% Kills %playerHeadshots% HS  %playerDeaths% Deaths K/D: %playerKDR%");
  397.             this.m_lstPlayerStatsMessage.Add("Your Serverrank is: %playerRank% of %allRanks%");
  398.  
  399.             //Player of the day
  400.             this.m_lstPlayerOfTheDayMessage = new List<string>();
  401.             this.m_lstPlayerOfTheDayMessage.Add("%playerName% is the Player of the day");
  402.             this.m_lstPlayerOfTheDayMessage.Add("Score: %playerScore%  %playerKills% Kills %playerHeadshots% HS  %playerDeaths% Deaths K/D: %playerKDR%");
  403.             this.m_lstPlayerOfTheDayMessage.Add("His Serverrank is: %playerRank% of %allRanks%");
  404.             this.m_lstPlayerOfTheDayMessage.Add("Overall playtime for today: %playerPlaytime%");
  405.  
  406.             //Welcomestats
  407.             this.m_lstPlayerWelcomeStatsMessage = new List<string>();
  408.             this.m_lstPlayerWelcomeStatsMessage.Add("Nice to see you on our Server again, %playerName%");
  409.             this.m_lstPlayerWelcomeStatsMessage.Add("Serverstats for %playerName%:");
  410.             this.m_lstPlayerWelcomeStatsMessage.Add("Score: %playerScore%  %playerKills% Kills %playerHeadshots% HS  %playerDeaths% Deaths K/D: %playerKDR%");
  411.             this.m_lstPlayerWelcomeStatsMessage.Add("Your Serverrank is: %playerRank% of %allRanks%");
  412.  
  413.             //Welcomestats new Player
  414.             this.m_lstNewPlayerWelcomeMsg = new List<string>();
  415.             this.m_lstNewPlayerWelcomeMsg.Add("Welcome to the %serverName% Server, %playerName%");
  416.  
  417.             //Weaponstats
  418.             this.m_lstWeaponstatsMsg = new List<string>();
  419.             this.m_lstWeaponstatsMsg.Add("%playerName%'s Stats for %Weapon%:");
  420.             this.m_lstWeaponstatsMsg.Add("%playerKills% Kills  %playerHeadshots% Headshots  Headshotrate: %playerKHR%%");
  421.             this.m_lstWeaponstatsMsg.Add("Your Weaponrank is: %playerRank% of %allRanks%");
  422.  
  423.             //Serverstats
  424.             this.m_lstServerstatsMsg = new List<string>();
  425.             this.m_lstServerstatsMsg.Add("Serverstatistics for server %serverName%");
  426.             this.m_lstServerstatsMsg.Add("Unique Players: %countPlayer%  Totalplaytime: %sumPlaytime%");
  427.             this.m_lstServerstatsMsg.Add("Totalscore: %sumScore% Avg. Score: %avgScore% Avg. SPM: %avgSPM%");
  428.             this.m_lstServerstatsMsg.Add("Totalkills: %sumKills% Avg. Kills: %avgKills% Avg. KPM: %avgKPM%");
  429.  
  430.             //Session
  431.             this.m_lstSessionMessage = new List<string>();
  432.             this.m_lstSessionMessage.Add("%playerName%'s Session Data  Session started %SessionStarted%");
  433.             this.m_lstSessionMessage.Add("Score: %playerScore%  %playerKills% Kills  %playerHeadshots% HS  %playerDeaths% Deaths K/D: %playerKDR%");
  434.             this.m_lstSessionMessage.Add("Your Rank: %playerRank% (%RankDif%)  Sessionlength: %SessionDuration% Minutes");
  435.  
  436.             //Top10 Headers
  437.             this.m_strTop10Header = "Top 10 Player of the %serverName% Server";
  438.             this.m_strTop10RowFormat = "%Rank%. %playerName%  Score: %playerScore%  %playerKills% Kills  %playerHeadshots% Headshots  %playerDeaths% Deaths  KDR: %playerKDR%";
  439.             this.m_strWeaponTop10Header = "Top 10 Player with %Weapon% of the %serverName%";
  440.             this.m_strWeaponTop10RowFormat = "%Rank%.  %playerName%  %playerKills% Kills  %playerHeadshots% Headshots  %playerDeaths% Deaths Headshotrate: %playerKHR%%";
  441.  
  442.             //Top10 for Period
  443.             this.m_strTop10HeaderForPeriod = "Top 10 Player of the %serverName% Server over the last %intervaldays% days";
  444.  
  445.             //Awards
  446.             this.m_lstAwardTable = new List<string>();
  447.             this.m_lstAwardTable.Add("First");
  448.             this.m_lstAwardTable.Add("Second");
  449.             this.m_lstAwardTable.Add("Third");
  450.             this.m_lstAwardTable.Add("Purple_Heart");
  451.             this.m_lstAwardTable.Add("Best_Combat");
  452.             this.m_lstAwardTable.Add("Killstreak_5");
  453.             this.m_lstAwardTable.Add("Killstreak_10");
  454.             this.m_lstAwardTable.Add("Killstreak_15");
  455.             this.m_lstAwardTable.Add("Killstreak_20");
  456.  
  457.             //ServerID
  458.             this.ServerID = 0;
  459.  
  460.             //Tableconfig Tweaks for friendly weapon names
  461.             this.m_lstTableconfig = new List<string>();
  462.             this.m_lstTableconfig.Add("RPG-7{RPG}");
  463.             this.m_lstTableconfig.Add("Weapons/SCAR-H/SCAR-H{SCAR,SCAR-H,SCARH}");
  464.             this.m_lstTableconfig.Add("USAS-12{USAS12,USAS}");
  465.             this.m_lstTableconfig.Add("M27IAR{M27}");
  466.             this.m_lstTableconfig.Add("M16A4{M16,M16A3}");
  467.             this.m_lstTableconfig.Add("AEK-971{AEK971,AEK}");
  468.             this.m_lstTableconfig.Add("Weapons/A91/A91{A91,A-91}");
  469.             this.m_lstTableconfig.Add("Weapons/AK74M/AK74{AK74,AK74M,AK74-M}");
  470.             this.m_lstTableconfig.Add("Weapons/G36C/G36C{G36C,G36}");
  471.             this.m_lstTableconfig.Add("Weapons/G3A3/G3A3{G3A3,G3}");
  472.             this.m_lstTableconfig.Add("Weapons/Gadgets/C4/C4{C4,C-4}");
  473.             this.m_lstTableconfig.Add("Weapons/Gadgets/Claymore/Claymore{CLAYMORE,CLAY,LANDMINE}");
  474.             this.m_lstTableconfig.Add("Weapons/KH2002/KH2002{KH2002}");
  475.             this.m_lstTableconfig.Add("Weapons/Knife/Knife{KNIFE,MESSER}");
  476.             this.m_lstTableconfig.Add("Weapons/M416/M416{M416,M-416}");
  477.             this.m_lstTableconfig.Add("Weapons/MagpulPDR/MagpulPDR{MagpulPDR,PDR}");
  478.             this.m_lstTableconfig.Add("Weapons/MP412Rex/MP412REX{MP412REX,REX,MP412}");
  479.             this.m_lstTableconfig.Add("Weapons/MP443/MP443{MP443}");
  480.             this.m_lstTableconfig.Add("Taurus .44{.44,TAURUS,TAURUS.44}");
  481.             this.m_lstTableconfig.Add("Weapons/P90/P90{P90}");
  482.             this.m_lstTableconfig.Add("Weapons/Sa18IGLA/Sa18IGLA{Sa18IGLA,Sa18,IGLA}");
  483.             this.m_lstTableconfig.Add("Weapons/UMP45/UMP45{UMP,UMP-45,UMP45}");
  484.             this.m_lstTableconfig.Add("Weapons/XP1_L85A2/L85A2{L85A2,L85A,L85}");
  485.             this.m_lstTableconfig.Add("Glock18{GLOCK}");
  486.  
  487.             //ServerInfo Event fix
  488.             this.dtLastServerInfoEvent = DateTime.Now;
  489.             this.minIntervalllenght = 60;
  490.  
  491.             //Double Roundendfix
  492.             this.dtLastRoundendEvent = DateTime.MinValue;
  493.             this.dtLastOnListPlayersEvent = DateTime.MinValue;
  494.  
  495.             //Top10 for Period
  496.             this.m_intDaysForPeriodTop10 = 7;
  497.  
  498.             //New In-Game Command System
  499.             this.m_IngameCommands_stats = "stats,rank";
  500.             this.m_IngameCommands_serverstats = "serverstats";
  501.             this.m_IngameCommands_session = "session";
  502.             this.m_IngameCommands_dogtags = "dogtags";
  503.             this.m_IngameCommands_top10 = "top10";
  504.             this.m_IngameCommands_playerOfTheDay = "playeroftheday,potd";
  505.             this.m_IngameCommands_top10ForPeriod = "weektop10,wtop10";
  506.         }
  507.         #endregion
  508.  
  509.         #region PluginSetup
  510.         public string GetPluginName()
  511.         {
  512.             return "PRoCon Chat, GUID, Stats and Map Logger";
  513.         }
  514.  
  515.         public string GetPluginVersion()
  516.         {
  517.             return "1.0.0.2";
  518.         }
  519.  
  520.         public string GetPluginAuthor()
  521.         {
  522.             return "[GWC]XpKiller";
  523.         }
  524.  
  525.         public string GetPluginWebsite()
  526.         {
  527.             return "www.german-wildcards.de";
  528.         }
  529.  
  530.         public string GetPluginDescription()
  531.         {
  532.             return @"
  533. If you like my Plugins, please feel free to donate<br>
  534. <p><form action='https://www.paypal.com/cgi-bin/webscr' target='_blank' method='post'>
  535. <input type='hidden' name='cmd' value='_s-xclick'>
  536. <input type='hidden' name='hosted_button_id' value='3B2FEDDHHWUW8'>
  537. <input type='image' src='https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>
  538. <img alt='' border='0' src='https://www.paypal.com/de_DE/i/scr/pixel.gif' width='1' height='1'>
  539. </form></p>
  540.  
  541.  
  542. <h2>Description</h2>
  543.    <p>This plugin is used to log player chat, player GUID's, player Stats, Weaponstats and Mapstats.</p>
  544.    <p>This inludes: Chat, PBGUID, EAGUID, IP, Stats, Weaponstats, Dogtags, Killstreaks, Country, ClanTag, ... to be continued.. ;-)</p>
  545.    
  546. <h2>Requirements</h2>
  547.     <p>It requires the use of a MySQL database with INNODB engine, that allows remote connections.(MYSQL Version 5.1.x, 5.5.x or higher is recommendend!!!)</p>
  548.     <p>Also you should give INNODB some more Ram because the plugin mainly uses this engine if you need help feel free to ask me</p>
  549.     <p>The Plugin will create the tables by itself.</p>
  550.     <p>Pls Give FEEDBACK !!!</p>
  551.  
  552. <h2>Installation</h2>
  553. <p>Download and install this plugin</p>
  554. <p>Setup your Database, this means create a database and the user for it. I highly recommend NOT to use your root user. Just create a user with all rights for your newly created database </p>
  555. <p>I recommend MySQL 5.1.x, 5.5.x or greater (5.0.x could work too, not tested) Important: <b>Your database need INNODB Support</b></p>
  556. <p>Start Procon</p>
  557. <p>Go to Tools --> Options --> Plugins --> Enter you databaseserver under outgoing Connections and allow all outgoing connections</p>
  558. <p>Restart Procon</p>
  559. <p>Enter your settings into Plugin Settings and THEN enable the plugin</p>
  560. <p>Now the plugin should work if not request help in the <a href='https://forum.myrcon.com' target='_blank'>Forum</a></p>
  561.  
  562.    
  563. <h2>Things you have to know:</h2>
  564. You can add additional Names for weapons in the Pluginsettings
  565. Use comma to seperate the words. <br>
  566. Example: M16A4{M16} --> 40MMGL{M16,M16A3}  <br><br>
  567.  
  568.  
  569.  
  570. <h2>Ingame Commands (defaults!)</h2>
  571.     <blockquote><h4>[@,#,!]stats</h4>Tells the Player their own Serverstats</blockquote>
  572.     <blockquote><h4>[@,#,!]rank</h4>Tells the Player their own Serverstats</blockquote>
  573.     <blockquote><h4>[@,#,!]potd</h4>Show up the player of the day</blockquote>
  574.     <blockquote><h4>[@,#,!]playeroftheday</h4>Show up the player of the day</blockquote>
  575.     <blockquote><h4>[@,#,!]session</h4>Tells the Player their own Sessiondata</blockquote>
  576.     <blockquote><h4>[@,#,!]top10</h4>Tells the Player the Top10 players of the server</blockquote>
  577.     <blockquote><h4>[@,#,!]wtop10</h4>Tells the Player the Top10 players of the server for specific period</blockquote>
  578.     <blockquote><h4>[@,#,!]weektop10</h4>Tells the Player the Top10 players of the server for specific period</blockquote>
  579.     <blockquote><h4>[@,#,!]stats WeaponName</h4>Tells the Player their own Weaponstats for the specific Weapon</blockquote>
  580.     <blockquote><h4>[@,#,!]rank WeaponName</h4>Privately Tells the Player their own Weaponstats for the specific Weapon</blockquote>
  581.     <blockquote><h4>[@,#,!]top10 WeaponName</h4>Privately Tells the Player the Top10 Player for the specific Weapon of the server</blockquote>
  582.     <blockquote><h4>[@,#,!]dogtags WeaponName</h4>Privately Tells the Player his Dogtagstats </blockquote>
  583.     <blockquote><h4>[@,#,!]serverstats</h4>Tells the Player the Serverstats</blockquote>
  584.  
  585. <h2>Replacement Strings for Playerstats and Player of the day</h2>
  586.    
  587.     <table border ='1'>
  588.     <tr><th>Replacement String</th><th>Effect</th></tr>
  589.     <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  590.     <tr><td>%playerScore%</td><td>Will be replaced by the player's totalscore on this server</td></tr>
  591.     <tr><td>%SPM%</td><td>Will be replaced by the Player's score per minute on this server</td></tr>
  592.     <tr><td>%playerKills%</td><td>Will be replaced by the player's totalkills on this server</td></tr>
  593.     <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's totalheadshots on this server</td></tr>
  594.     <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths on this server</td></tr>
  595.     <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio on this server</td></tr>
  596.     <tr><td>%playerSucide%</td><td>Will be replaced by the player's sucides on this server</td></tr>
  597.     <tr><td>%playerPlaytime%</td><td>Will be replaced by the player's totalplaytime on this server in hh:mm:ss format</td></tr>
  598.     <tr><td>%rounds%</td><td>Will be replaced by the player's totalrounds played on this server</td></tr>
  599.     <tr><td>%playerRank%</td><td>Will be replaced by the player's concurrent serverrank</td></tr>
  600.     <tr><td>%allRanks%</td><td>Will be replaced by the player's concurrent serverrank</td></tr>
  601.     <tr><td>%killstreak%</td><td>Will be replaced by the player's best Killstreak</td></tr>
  602.     <tr><td>%deathstreak%</td><td>Will be replaced by the player's worst Deathstreak</td></tr>
  603.     </table>
  604.     <br>
  605.  
  606. <h2>Replacement Strings for Top10</h2>
  607.    
  608.     <table border ='1'>
  609.     <tr><th>Replacement String</th><th>Effect</th></tr>
  610.    <tr><td>%serverName%</td><td>Will be replaced by the Server name (Header only)</td></tr>
  611.    <tr><td>%Rank%</td><td>Will be replaced by the player's rank</td></tr>
  612.     <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  613.     <tr><td>%playerScore%</td><td>Will be replaced by the player's totalscore on this server</td></tr>
  614.     <tr><td>%playerKills%</td><td>Will be replaced by the player's totalkills on this server</td></tr>
  615.     <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's totalheadshots on this server</td></tr>
  616.     <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths on this server</td></tr>
  617.     <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio on this server</td></tr>
  618.    <tr><td>%playerKHR%</td><td>Will be replaced by the player's Headshot Kill ratio on this server</td></tr>
  619.    <tr><td>%intervaldays%</td><td>Will be replaced interval of days (top10 for a period only)</td></tr>
  620.     </table>
  621.     <br>
  622.    
  623.     <h2>Replacement Strings for Weaponstats</h2>
  624.    
  625.     <table border ='1'>
  626.     <tr><th>Replacement String</th><th>Effect</th></tr>
  627.     <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  628.     <tr><td>%playerKills%</td><td>Will be replaced by the player's Totalkills on this server with the specific Weapon</td></tr>
  629.     <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's Totalheadshotkills on this server the specific Weapon</td></tr>
  630.     <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths on this server caused by this specific Weapon</td></tr>
  631.     <tr><td>%playerKHR%</td><td>Will be replaced by the player's Headshotkill ratio on this server with the specific Weapon</td></tr>
  632.     <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio on this server with the specific Weapon</td></tr>
  633.     <tr><td>%playerRank%</td><td>Will be replaced by the player's current Serverrank for the specific Weapon</td></tr>
  634.     <tr><td>%allRanks%</td><td>Will be replaced by current Number of Player in Serverrank for the specific Weapon</td></tr>
  635.     <tr><td>%killstreak%</td><td>Will be replaced by the player's best Killstreak</td></tr>
  636.     <tr><td>%deathstreak%</td><td>Will be replaced by the player's worst Deathstreak</td></tr>
  637.     </table>
  638.  
  639.    <h2>Replacement Strings for serverstats</h2>
  640.    
  641.     <table border ='1'>
  642.     <tr><th>Replacement String</th><th>Effect</th></tr>
  643.     <tr><td>%countPlayer%</td><td>Will be replaced by the number of unique players on this server</td></tr>
  644.    <tr><td>%sumScore%</td><td>Will be replaced by the Totalscore of all players combined on this server</td></tr>
  645.    <tr><td>%sumKills%</td><td>Will be replaced by the Totalkills of all players combined on this server</td></tr>
  646.    <tr><td>%sumHeadshots%</td><td>Will be replaced by the TotalHeadshots of all players combined on this server</td></tr>
  647.    <tr><td>%sumDeaths%</td><td>Will be replaced by the Totaldeaths of all players combined on this server</td></tr>
  648.    <tr><td>%sumTKs%</td><td>Will be replaced by the TotalTeamkills of all players combined on this server</td></tr>
  649.    <tr><td>%sumRounds%</td><td>Will be replaced by the Totalrounds of all players combined on this server</td></tr>
  650.    <tr><td>%sumSuicide%</td><td>Will be replaced by the Totalsuicide of all players combined on this server</td></tr>
  651.    <tr><td>%avgScore%</td><td>Will be replaced by the average score of all players combined on this server</td></tr>
  652.    <tr><td>%avgKills%</td><td>Will be replaced by the average kills of all players combined on this server</td></tr>
  653.    <tr><td>%avgHeadshots%</td><td>Will be replaced by the average Headshots of all players combined on this server</td></tr>
  654.    <tr><td>%avgDeaths%</td><td>Will be replaced by the average deaths of all players combined on this server</td></tr>
  655.    <tr><td>%avgTKs%</td><td>Will be replaced by the average teamkills of all players combined on this server</td></tr>
  656.    <tr><td>%avgSuicide</td><td>Will be replaced by the average suicides of all players combined on this server</td></tr>
  657.    <tr><td>%avgRounds%</td><td>Will be replaced by the average rounds of all players combined on this server</td></tr>
  658.    <tr><td>%avgSPM%</td><td>Will be replaced by the average Score per Minute of all players combined on this server</td></tr>
  659.    <tr><td>%avgKPM%</td><td>Will be replaced by the average Kills per Minute of all players combined on this server</td></tr>
  660.    <tr><td>%avgHPM%</td><td>Will be replaced by the average Headshots per Minute of all players combined on this server</td></tr>
  661.    <tr><td>%avgHPK%</td><td>Will be replaced by the average Headshots per Kills (unit procent (%)) of all players combined on this server</td></tr>
  662.    <tr><td>%sumPlaytime%</td><td>Will be replaced by the Total Playtime (format: dd:hh:mm:ss) of all players combined on this server</td></tr>
  663.    <tr><td>%avgPlaytime%</td><td>Will be replaced by the average Playtime (format: dd:hh:mm:ss) of all players combined on this server</td></tr>
  664.    <tr><td>%sumPlaytimeHours%</td><td>Will be replaced by the Total Playtime (format rounded hours) of all players combined on this server</td></tr>
  665.    <tr><td>%avgPlaytimeHours%</td><td>Will be replaced by the average Playtime (format rounded hours) of all players combined on this server</td></tr>
  666.    <tr><td>%sumPlaytimeDays%</td><td>Will be replaced by the Total Playtime (format rounded days) of all players combined on this server</td></tr>  
  667.    <tr><td>%avgPlaytimeDays%</td><td>Will be replaced by the average Playtime (format rounded days) of all players combined on this server</td></tr>  
  668.     </table>
  669.    
  670.     <h2>Replacement Strings for PlayerSession</h2>
  671.    
  672.     <table border ='1'>
  673.     <tr><th>Replacement String</th><th>Effect</th></tr>
  674.     <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  675.     <tr><td>%playerScore%</td><td>Will be replaced by the player's totalscore of the concurrent Session</td></tr>
  676.     <tr><td>%playerKills%</td><td>Will be replaced by the player's totalkills of the concurrent Session</td></tr>
  677.     <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's totalheadshots of the concurrent Session</td></tr>
  678.     <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths of the concurrent Session</td></tr>
  679.     <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio of the concurrent Session</td></tr>
  680.     <tr><td>%playerSucide%</td><td>Will be replaced by the player's sucides of the concurrent Session</td></tr>
  681.     <tr><td>%SessionDuration%</td><td>Will be replaced by the player's totalplaytime of the concurrent Session in Minutes</td></tr>
  682.     <tr><td>%playerRank%</td><td>Will be replaced by the player's concurrent serverrank</td></tr>
  683.     <tr><td>%RankDif%</td><td>Will be replaced by the player's rank change</td></tr>
  684.     <tr><td>%SessionStarted%</td><td>Will be replaced by the player's start of the Session</td></tr>
  685.     <tr><td>%killstreak%</td><td>Will be replaced by the player's best Killstreak of the Session</td></tr>
  686.     <tr><td>%deathstreak%</td><td>Will be replaced by the player's worst Deathstreak of the Session</td></tr>
  687.     </table>
  688.     <br>
  689.    
  690.    <h2>How to yell/say messages</h2>
  691.    <p>Every ingame messages can be yelled to the Player.</p>
  692.    <p>Just add the yelltag in front of every line of you message which should be yelled.</p>
  693.    <p>Usage:[yell,duration in seconds]Your messages</p>
  694.    <p>Like:[yell,3]Welcome on our server!</p>
  695.    <p>This would be yell for 3 seconds</p>
  696.    <p>Hint: You can mixed normal say and yell without any problems.</p>
  697.    <p>Messages without Tag will will be transmitted with the say command.</p>
  698. <br>
  699.    
  700.  
  701.  
  702.     <h3>NOTE:</h3>
  703.         <p>Tracked stats are: Kills, Headshots, Deaths, All Weapons, TKs, Suicides, Score, Playtime, Rounds, MapStats, Dogtags </p>
  704.         <p>The Rank is created dynamical from Query in  my opinion much better than write it back to database.</p>
  705.         <p>The Stats are written to the Database at the end of the round</p>
  706.    
  707. <h3>Known issues:</h3>
  708. <p>Vehicles cannot be tracked due limitations in the Rcon Protocol blame EA/Dice for it</p>
  709.  
  710.        
  711. <h3>Changelog:</h3><br>
  712. <b>1.0.0.2</b><br>
  713. Bugfixes for column errors.<br>
  714. Bugfixes for the sessions streaming bug<br>
  715. Weaponstats working again. <br>
  716. Bugfix for Identifier name is too long.<br>
  717.  
  718. <br>
  719. <b>1.0.0.1</b><br>
  720. Bugfixes for value too long for column errors.<br>
  721. Bugfixes for some other bugs<br>
  722. Changed deprecated Tracemessages<br>
  723. Added an error prefix in pluginlog <br>
  724. New feature: Tickets/teamscores are now tracked in tbl_teamscores<br>
  725. New feature: Simple Stats (collects playerdata only)<br>
  726. New feature: Switch for disabling weaponstats
  727. <br><br>
  728. <b>1.0.0.0</b><br>
  729. First Release<br>
  730. Multigame Support<br>
  731. <br><br>
  732.  
  733.  
  734. ";
  735.         }
  736.  
  737.         public void OnPluginLoadingEnv(List<string> lstPluginEnv)
  738.         {  
  739.             this.strServerGameType = lstPluginEnv[1].ToUpper();
  740.         }
  741.  
  742.         public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion)
  743.         {
  744.             this.m_strHostName = strHostName;
  745.             this.m_strPort = strPort;
  746.             this.m_strPRoConVersion = strPRoConVersion;
  747.             this.RegisterEvents(this.GetType().Name, "OnListPlayers", "OnPlayerAuthenticated", "OnPlayerJoin", "OnGlobalChat", "OnTeamChat", "OnSquadChat", "OnPunkbusterMessage", "OnPunkbusterPlayerInfo", "OnServerInfo", "OnLevelLoaded",
  748.                                                      "OnPlayerKilled", "OnPlayerLeft", "OnRoundOverPlayers", "OnPlayerSpawned", "OnLoadingLevel", "OnCommandStats", "OnCommandTop10", "OnCommandDogtags", "OnCommandServerStats",
  749.                                                      "OnRoundStartPlayerCount", "OnRoundRestartPlayerCount", "OnRoundOver");
  750.  
  751.             // Register the logger status match command
  752.             // This command can be called for status whether logger is enabled or not
  753.             this.RegisterCommand(loggerStatusCommand);
  754.         }
  755.  
  756.         public void OnPluginEnable()
  757.         {
  758.             isStreaming = true;
  759.             this.serverName = String.Empty;
  760.             this.ExecuteCommand("procon.protected.pluginconsole.write", "^bPRoCon Chat, GUID and Stats Logger ^2Enabled");
  761.             this.Spamprotection = new CSpamprotection(numberOfAllowedRequests);
  762.             this.ExecuteCommand("procon.protected.pluginconsole.write", "^bPRoCon Chat, GUID and Stats Logger: ^2 Floodprotection set to " + this.numberOfAllowedRequests.ToString() + " Request per Round for each Player");
  763.             // Register Commands
  764.             this.m_isPluginEnabled = true;
  765.             this.prepareTablenames();
  766.             this.setGameMod();
  767.             this.MyDateTime = new myDateTime_W(this.m_dTimeOffset);
  768.             //Webrequest
  769.             if (this.m_enWebrequest == enumBoolYesNo.Yes)
  770.             {
  771.                 //this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", "30", (this.m_requestIntervall * 60).ToString(), "-1", "procon.protected.plugins.call", "CChatGUIDStatsLogger", "Threadstarter_Webrequest");
  772.             }
  773.             this.RegisterAllCommands();
  774.             this.generateWeaponList();
  775.             //Start intial tablebuilder thread
  776.             ThreadPool.QueueUserWorkItem(delegate { this.tablebuilder(); });
  777.         }
  778.  
  779.         public void OnPluginDisable()
  780.         {
  781.             isStreaming = false;
  782.             if (MySqlCon != null)
  783.                 if (MySqlCon.State == ConnectionState.Open)
  784.                 {
  785.                     try
  786.                     {
  787.                         MySqlCon.Close();
  788.                     }
  789.                     catch{}
  790.                 }
  791.             if (MySqlConn != null)
  792.                 if (MySqlConn.State == ConnectionState.Open)
  793.                 {
  794.                     try
  795.                     {
  796.                         MySqlConn.Close();
  797.                     }
  798.                     catch { }
  799.                 }
  800.  
  801.             //Destroying all current Coonection Pool if availble:
  802.             try
  803.             {
  804.                 MySqlConnection.ClearAllPools();
  805.             }
  806.             catch { }
  807.  
  808.             this.ExecuteCommand("procon.protected.pluginconsole.write", "^bPRoCon Chat, GUID and Stats Logger ^1Disabled");
  809.  
  810.             //Unregister Commands
  811.             this.m_isPluginEnabled = false;
  812.             //Webrequest
  813.             this.ExecuteCommand("procon.protected.tasks.remove", "CChatGUIDStatsLogger");
  814.             this.UnregisterAllCommands();
  815.         }
  816.  
  817.         // Lists only variables you want shown.. for instance enabling one option might hide another option
  818.         // It's the best I got until I implement a way for plugins to display their own small interfaces.
  819.         public List<CPluginVariable> GetDisplayPluginVariables()
  820.         {
  821.             List<CPluginVariable> lstReturn = new List<CPluginVariable>();
  822.             lstReturn.Add(new CPluginVariable("Server Details|Host", this.m_strHost.GetType(), this.m_strHost));
  823.             lstReturn.Add(new CPluginVariable("Server Details|Port", this.m_strDBPort.GetType(), this.m_strDBPort));
  824.             lstReturn.Add(new CPluginVariable("Server Details|Database Name", this.m_strDatabase.GetType(), this.m_strDatabase));
  825.             lstReturn.Add(new CPluginVariable("Server Details|UserName", this.m_strUserName.GetType(), this.m_strUserName));
  826.             lstReturn.Add(new CPluginVariable("Server Details|Password", this.m_strPassword.GetType(), this.m_strPassword));
  827.             if (this.m_connectionPooling == enumBoolOnOff.Off)
  828.             {
  829.                 lstReturn.Add(new CPluginVariable("Server Details|High performance mode(no connection limit!)", typeof(enumBoolOnOff), this.m_highPerformanceConnectionMode));
  830.             }
  831.             lstReturn.Add(new CPluginVariable("Server Details|Connection Pooling", typeof(enumBoolOnOff), this.m_connectionPooling));
  832.             if (this.m_connectionPooling == enumBoolOnOff.On)
  833.             {
  834.                 lstReturn.Add(new CPluginVariable("Server Details|Min Connection Pool Size", this.m_minPoolSize.GetType(), this.m_minPoolSize));
  835.                 lstReturn.Add(new CPluginVariable("Server Details|Max Connection Pool Size", this.m_maxPoolSize.GetType(), this.m_maxPoolSize));
  836.             }
  837.             lstReturn.Add(new CPluginVariable("Server Details|Failed Transaction retry attempts", this.TransactionRetryCount.GetType(), this.TransactionRetryCount));
  838.             lstReturn.Add(new CPluginVariable("Server Details|Minimum time(sec) between ServerInfo Updates", this.minIntervalllenght.GetType(), this.minIntervalllenght));
  839.  
  840.             lstReturn.Add(new CPluginVariable("Chatlogging|Enable Chatlogging?", typeof(enumBoolYesNo), this.m_enChatloggingON));
  841.             if (this.m_enChatloggingON == enumBoolYesNo.Yes)
  842.             {
  843.                 lstReturn.Add(new CPluginVariable("Chatlogging|Log ServerSPAM?", typeof(enumBoolYesNo), this.m_enNoServerMsg));
  844.                 lstReturn.Add(new CPluginVariable("Chatlogging|Instant Logging of Chat Messages?", typeof(enumBoolYesNo), this.m_enInstantChatlogging));
  845.                 lstReturn.Add(new CPluginVariable("Chatlogging|Enable chatlog filter(Regex)?", typeof(enumBoolYesNo), this.m_enChatlogFilter));
  846.                 if (this.m_enChatlogFilter == enumBoolYesNo.Yes)
  847.                 {
  848.                     this.lstStrChatFilterRules = new List<string>(this.ListReplace(this.lstStrChatFilterRules,"&#124","|"));
  849.                     this.lstStrChatFilterRules = this.ListReplace(this.lstStrChatFilterRules, "&#43", "+");
  850.                     lstReturn.Add(new CPluginVariable("Chatlogging|Chatfilterrules(Regex)", typeof(string[]), this.lstStrChatFilterRules.ToArray()));
  851.                 }
  852.             }
  853.             lstReturn.Add(new CPluginVariable("Stats|Enable Statslogging?", typeof(enumBoolYesNo), this.m_enLogSTATS));
  854.             if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  855.             {
  856.                 lstReturn.Add(new CPluginVariable("Stats|Enable Weaponstats?", typeof(enumBoolYesNo), this.m_weaponstatsON));
  857.                 lstReturn.Add(new CPluginVariable("Stats|Ranking by Score?", typeof(enumBoolYesNo), this.m_enRankingByScore));
  858.                 lstReturn.Add(new CPluginVariable("Stats|Enable ingame commands?", typeof(enumBoolYesNo), this.m_enableInGameCommands));
  859.                 lstReturn.Add(new CPluginVariable("Stats|Overall ranking(merged Serverranking)", typeof(enumBoolYesNo), this.m_enOverallRanking));
  860.                 lstReturn.Add(new CPluginVariable("Stats|Server group (0 - 128)", this.intServerGroup.GetType(), this.intServerGroup));
  861.                 lstReturn.Add(new CPluginVariable("Stats|Send Stats to all Players?", typeof(enumBoolYesNo), this.m_enSendStatsToAll));
  862.                 lstReturn.Add(new CPluginVariable("Stats|Enable KDR correction?", typeof(enumBoolYesNo), this.m_kdrCorrection));
  863.                 lstReturn.Add(new CPluginVariable("Stats|PlayerMessage", typeof(string[]), this.m_lstPlayerStatsMessage.ToArray()));
  864.                 //Player of the day
  865.                 lstReturn.Add(new CPluginVariable("Stats|Player of the day Message", typeof(string[]), this.m_lstPlayerOfTheDayMessage.ToArray()));
  866.                 lstReturn.Add(new CPluginVariable("Stats|Weaponstats Message ", typeof(string[]), this.m_lstWeaponstatsMsg.ToArray()));
  867.                 //Serverstats
  868.                 lstReturn.Add(new CPluginVariable("Stats|Serverstats Message", typeof(string[]), this.m_lstServerstatsMsg.ToArray()));
  869.                 lstReturn.Add(new CPluginVariable("Stats|Enable Livescoreboard in DB?", typeof(enumBoolYesNo), this.m_enableCurrentPlayerstatsTable));
  870.                 //Simplestats
  871.                 lstReturn.Add(new CPluginVariable("Stats|Log playerdata only (no playerstats)?", typeof(enumBoolYesNo), this.m_enLogPlayerDataOnly));
  872.                 //lstReturn.Add(new CPluginVariable("Stats|Awards ON?", typeof(enumBoolYesNo), this.m_awardsON));
  873.                 lstReturn.Add(new CPluginVariable("WelcomeStats|Enable Welcomestats?", typeof(enumBoolYesNo), this.m_enWelcomeStats));
  874.                 if (this.m_enWelcomeStats == enumBoolYesNo.Yes)
  875.                 {
  876.                     //lstReturn.Add(new CPluginVariable("WelcomeStats|Yell Welcome Message(not the stats)?", typeof(enumBoolYesNo), this.m_enYellWelcomeMSG));
  877.                     //lstReturn.Add(new CPluginVariable("WelcomeStats|Welcome Message", this.m_strPlayerWelcomeMsg.GetType(), this.m_strPlayerWelcomeMsg));
  878.                     lstReturn.Add(new CPluginVariable("WelcomeStats|Welcome Message", typeof(string[]), this.m_lstPlayerWelcomeStatsMessage.ToArray()));
  879.                     lstReturn.Add(new CPluginVariable("WelcomeStats|Welcome Message for new Player", typeof(string[]), this.m_lstNewPlayerWelcomeMsg.ToArray()));
  880.                     lstReturn.Add(new CPluginVariable("WelcomeStats|Welcomestats Delay", this.int_welcomeStatsDelay.GetType(), this.int_welcomeStatsDelay));
  881.                 }
  882.                 //top10
  883.                 lstReturn.Add(new CPluginVariable("Stats|Top10 ingame", this.m_enTop10ingame.GetType(), this.m_enTop10ingame));
  884.                 if (this.m_enTop10ingame == enumBoolYesNo.Yes)
  885.                 {
  886.                     lstReturn.Add(new CPluginVariable("Stats|Top10 header line", this.m_strTop10Header.GetType(), this.m_strTop10Header));
  887.                     lstReturn.Add(new CPluginVariable("Stats|Top10 row format", this.m_strTop10RowFormat.GetType(), this.m_strTop10RowFormat));
  888.                     //top10 for period
  889.                     lstReturn.Add(new CPluginVariable("Stats|Top10 for period header line", this.m_strTop10HeaderForPeriod.GetType(), this.m_strTop10HeaderForPeriod));
  890.                     lstReturn.Add(new CPluginVariable("Stats|Top10 for period interval days", this.m_intDaysForPeriodTop10.GetType(), this.m_intDaysForPeriodTop10));
  891.                     //Weapontop10
  892.                     lstReturn.Add(new CPluginVariable("Stats|WeaponTop10 header line", this.m_strWeaponTop10Header.GetType(), this.m_strWeaponTop10Header));
  893.                     lstReturn.Add(new CPluginVariable("Stats|WeaponTop10 row format", this.m_strWeaponTop10RowFormat.GetType(), this.m_strWeaponTop10RowFormat));
  894.                 }
  895.             }
  896.             lstReturn.Add(new CPluginVariable("Debug|DebugLevel", "enum.Actions(Trace|Info|Warning|Error)", this.GlobalDebugMode));
  897.             lstReturn.Add(new CPluginVariable("Table|Keywordlist", typeof(string[]), this.m_lstTableconfig.ToArray()));
  898.             lstReturn.Add(new CPluginVariable("Table|tableSuffix", this.tableSuffix.GetType(), this.tableSuffix));
  899.             lstReturn.Add(new CPluginVariable("MapStats|MapStats ON?", typeof(enumBoolYesNo), this.m_mapstatsON));
  900.             lstReturn.Add(new CPluginVariable("Session|Session ON?", typeof(enumBoolYesNo), this.m_sessionON));
  901.             lstReturn.Add(new CPluginVariable("Session|SessionMessage", typeof(string[]), this.m_lstSessionMessage.ToArray()));
  902.             lstReturn.Add(new CPluginVariable("Session|Save Sessiondata to DB?", typeof(enumBoolYesNo), this.m_enSessionTracking));
  903.             lstReturn.Add(new CPluginVariable("FloodProtection|Playerrequests per Round", this.numberOfAllowedRequests.GetType(), this.numberOfAllowedRequests));
  904.             lstReturn.Add(new CPluginVariable("TimeOffset|Servertime Offset", this.m_dTimeOffset.GetType(), this.m_dTimeOffset));
  905.             //Ingame Command Setup
  906.             /*
  907.             this.m_IngameCommands_stats = "stats,rank";
  908.             this.m_IngameCommands_serverstats = "serverstats";
  909.             this.m_IngameCommands_session = "session";
  910.             this.m_IngameCommands_dogtags = "dogtags";
  911.             this.m_IngameCommands_top10 = "top10";
  912.             this.m_IngameCommands_playerOfTheDay = "playeroftheday,potd";
  913.             this.m_IngameCommands_top10ForPeriod = "weektop10,wtop10";
  914.              */
  915.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|Stats Command:", this.m_IngameCommands_stats.GetType(), this.m_IngameCommands_stats));
  916.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|ServerStats Command:", this.m_IngameCommands_serverstats.GetType(), this.m_IngameCommands_serverstats));
  917.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|Session Command:", this.m_IngameCommands_session.GetType(), this.m_IngameCommands_session));
  918.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|Dogtags Command:", this.m_IngameCommands_dogtags.GetType(), this.m_IngameCommands_dogtags));
  919.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|Top10 Command:", this.m_IngameCommands_top10.GetType(), this.m_IngameCommands_top10));
  920.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|Player Of The Day Command:", this.m_IngameCommands_playerOfTheDay.GetType(), this.m_IngameCommands_playerOfTheDay));
  921.             lstReturn.Add(new CPluginVariable("Ingame Command Setup|Top10 for period Command:", this.m_IngameCommands_top10ForPeriod.GetType(), this.m_IngameCommands_top10ForPeriod));
  922.  
  923.  
  924.             //lstReturn.Add(new CPluginVariable("BFBCS|Fetch Stats from BFBCS", typeof(enumBoolYesNo), this.m_getStatsfromBFBCS));
  925.  
  926.             if (this.m_getStatsfromBFBCS == enumBoolYesNo.Yes)
  927.             {
  928.                 //lstReturn.Add(new CPluginVariable("BFBCS|Updateinterval (hours)", this.BFBCS_UpdateInterval.GetType(), this.BFBCS_UpdateInterval));
  929.                 //lstReturn.Add(new CPluginVariable("BFBCS|Request Packrate", this.BFBCS_Min_Request.GetType(), this.BFBCS_Min_Request));
  930.                 //lstReturn.Add(new CPluginVariable("Cheaterprotection|Statsbased Protection", typeof(enumBoolYesNo), this.m_cheaterProtection));
  931.                 //lstReturn.Add(new CPluginVariable("Ranklimiter|Ranklimiter ON?", typeof(enumBoolYesNo), this.m_enRanklimiter));
  932.             }
  933.             /*
  934.             lstReturn.Add(new CPluginVariable("Webrequest|Periodical Webrequest On?(P&S Stats)", typeof(enumBoolYesNo), this.m_enWebrequest));
  935.             if (this.m_enWebrequest == enumBoolYesNo.Yes)
  936.             {
  937.                 lstReturn.Add(new CPluginVariable("Webrequest|Webaddress", this.m_webAddress.GetType(), this.m_webAddress));
  938.                 lstReturn.Add(new CPluginVariable("Webrequest|Webrequest Intervall", this.m_requestIntervall.GetType(), this.m_requestIntervall));
  939.             }
  940.             */
  941.             return lstReturn;
  942.         }
  943.  
  944.         // Lists all of the plugin variables.
  945.         public List<CPluginVariable> GetPluginVariables()
  946.         {
  947.             List<CPluginVariable> lstReturn = new List<CPluginVariable>();
  948.  
  949.             lstReturn.Add(new CPluginVariable("Host", this.m_strHost.GetType(), this.m_strHost));
  950.             lstReturn.Add(new CPluginVariable("Port", this.m_strDBPort.GetType(), this.m_strDBPort));
  951.             lstReturn.Add(new CPluginVariable("Database Name", this.m_strDatabase.GetType(), this.m_strDatabase));
  952.             lstReturn.Add(new CPluginVariable("UserName", this.m_strUserName.GetType(), this.m_strUserName));
  953.             lstReturn.Add(new CPluginVariable("Password", this.m_strPassword.GetType(), this.m_strPassword));
  954.             if (this.m_connectionPooling == enumBoolOnOff.Off)
  955.             {
  956.                 lstReturn.Add(new CPluginVariable("High performance mode(no connection limit!)", typeof(enumBoolOnOff), this.m_highPerformanceConnectionMode));
  957.             }
  958.             lstReturn.Add(new CPluginVariable("Connection Pooling", typeof(enumBoolOnOff), this.m_connectionPooling));
  959.             if (this.m_connectionPooling == enumBoolOnOff.On)
  960.             {
  961.                 lstReturn.Add(new CPluginVariable("Min Connection Pool Size", this.m_minPoolSize.GetType(), this.m_minPoolSize));
  962.                 lstReturn.Add(new CPluginVariable("Max Connection Pool Size", this.m_maxPoolSize.GetType(), this.m_maxPoolSize));
  963.             }
  964.             lstReturn.Add(new CPluginVariable("Failed Transaction retry attempts", this.TransactionRetryCount.GetType(), this.TransactionRetryCount));
  965.             lstReturn.Add(new CPluginVariable("Minimum time(sec) between ServerInfo Updates", this.minIntervalllenght.GetType(), this.minIntervalllenght));
  966.             // Switch for Stats Logging
  967.             lstReturn.Add(new CPluginVariable("Enable Chatlogging?", typeof(enumBoolYesNo), this.m_enChatloggingON));
  968.             if (this.m_enChatloggingON == enumBoolYesNo.Yes)
  969.             {
  970.                 lstReturn.Add(new CPluginVariable("Log ServerSPAM?", typeof(enumBoolYesNo), this.m_enNoServerMsg));
  971.                 lstReturn.Add(new CPluginVariable("Instant Logging of Chat Messages?", typeof(enumBoolYesNo), this.m_enInstantChatlogging));
  972.                 lstReturn.Add(new CPluginVariable("Enable chatlog filter(Regex)?", typeof(enumBoolYesNo), this.m_enChatlogFilter));
  973.  
  974.                 if (this.m_enChatlogFilter == enumBoolYesNo.Yes)
  975.                 {
  976.                     this.lstStrChatFilterRules = new List<string>(this.ListReplace(this.lstStrChatFilterRules, "|", "&#124"));
  977.                     this.lstStrChatFilterRules = this.ListReplace(this.lstStrChatFilterRules, "&#43", "+");
  978.                     lstReturn.Add(new CPluginVariable("Chatfilterrules(Regex)", typeof(string[]), this.lstStrChatFilterRules.ToArray()));
  979.                 }
  980.             }
  981.             lstReturn.Add(new CPluginVariable("Enable Statslogging?", typeof(enumBoolYesNo), this.m_enLogSTATS));
  982.             lstReturn.Add(new CPluginVariable("Enable Weaponstats?", typeof(enumBoolYesNo), this.m_weaponstatsON));
  983.             //lstReturn.Add(new CPluginVariable("Update EA GUID?", typeof(enumBoolYesNo), this.m_UpdateEA_GUID));
  984.             //lstReturn.Add(new CPluginVariable("Update PB-GUID (NOT recommended!!!)?", typeof(enumBoolYesNo), this.m_UpdatePB_GUID));
  985.             lstReturn.Add(new CPluginVariable("Ranking by Score?", typeof(enumBoolYesNo), this.m_enRankingByScore));
  986.             lstReturn.Add(new CPluginVariable("Enable ingame commands?", typeof(enumBoolYesNo), this.m_enableInGameCommands));
  987.             lstReturn.Add(new CPluginVariable("Overall ranking(merged Serverranking)", typeof(enumBoolYesNo), this.m_enOverallRanking));
  988.             lstReturn.Add(new CPluginVariable("Server group (0 - 128)", this.intServerGroup.GetType(), this.intServerGroup));
  989.             lstReturn.Add(new CPluginVariable("Send Stats to all Players?", typeof(enumBoolYesNo), this.m_enSendStatsToAll));
  990.             lstReturn.Add(new CPluginVariable("Enable Livescoreboard in DB?", typeof(enumBoolYesNo), this.m_enableCurrentPlayerstatsTable));
  991.             lstReturn.Add(new CPluginVariable("Enable KDR correction?", typeof(enumBoolYesNo), this.m_kdrCorrection));
  992.             lstReturn.Add(new CPluginVariable("PlayerMessage", typeof(string[]), this.m_lstPlayerStatsMessage.ToArray()));
  993.             //Player of the day
  994.             lstReturn.Add(new CPluginVariable("Player of the day Message", typeof(string[]), this.m_lstPlayerOfTheDayMessage.ToArray()));
  995.             lstReturn.Add(new CPluginVariable("Weaponstats Message ", typeof(string[]), this.m_lstWeaponstatsMsg.ToArray()));
  996.             //Serverstats
  997.             lstReturn.Add(new CPluginVariable("Serverstats Message", typeof(string[]), this.m_lstServerstatsMsg.ToArray()));
  998.  
  999.             lstReturn.Add(new CPluginVariable("Awards ON?", typeof(enumBoolYesNo), this.m_awardsON));
  1000.             lstReturn.Add(new CPluginVariable("Enable Welcomestats?", typeof(enumBoolYesNo), this.m_enWelcomeStats));
  1001.             lstReturn.Add(new CPluginVariable("Yell Welcome Message(not the stats)?", typeof(enumBoolYesNo), this.m_enYellWelcomeMSG));
  1002.             lstReturn.Add(new CPluginVariable("Welcome Message", typeof(string[]), this.m_lstPlayerWelcomeStatsMessage.ToArray()));
  1003.             lstReturn.Add(new CPluginVariable("Welcome Message for new Player", typeof(string[]), this.m_lstNewPlayerWelcomeMsg.ToArray()));
  1004.             lstReturn.Add(new CPluginVariable("Welcomestats Delay", this.int_welcomeStatsDelay.GetType(), this.int_welcomeStatsDelay));
  1005.             lstReturn.Add(new CPluginVariable("Top10 ingame", this.m_enTop10ingame.GetType(), this.m_enTop10ingame));
  1006.             lstReturn.Add(new CPluginVariable("Top10 header line", this.m_strTop10Header.GetType(), this.m_strTop10Header));
  1007.             lstReturn.Add(new CPluginVariable("Top10 row format", this.m_strTop10RowFormat.GetType(), this.m_strTop10RowFormat));
  1008.             //top10 for period
  1009.             lstReturn.Add(new CPluginVariable("Top10 for period header line", this.m_strTop10HeaderForPeriod.GetType(), this.m_strTop10HeaderForPeriod));
  1010.             lstReturn.Add(new CPluginVariable("Top10 for period interval days", this.m_intDaysForPeriodTop10.GetType(), this.m_intDaysForPeriodTop10));
  1011.             //Weapontop10
  1012.             lstReturn.Add(new CPluginVariable("WeaponTop10 header line", this.m_strWeaponTop10Header.GetType(), this.m_strWeaponTop10Header));
  1013.             lstReturn.Add(new CPluginVariable("WeaponTop10 row format", this.m_strWeaponTop10RowFormat.GetType(), this.m_strWeaponTop10RowFormat));
  1014.             //
  1015.             lstReturn.Add(new CPluginVariable("DebugLevel", "enum.Actions(Trace|Info|Warning|Error)", this.GlobalDebugMode));
  1016.             lstReturn.Add(new CPluginVariable("Keywordlist", typeof(string[]), this.m_lstTableconfig.ToArray()));
  1017.             lstReturn.Add(new CPluginVariable("tableSuffix", this.tableSuffix.GetType(), this.tableSuffix));
  1018.             lstReturn.Add(new CPluginVariable("MapStats ON?", typeof(enumBoolYesNo), this.m_mapstatsON));
  1019.             lstReturn.Add(new CPluginVariable("Session ON?", typeof(enumBoolYesNo), this.m_sessionON));
  1020.             lstReturn.Add(new CPluginVariable("SessionMessage", typeof(string[]), this.m_lstSessionMessage.ToArray()));
  1021.             lstReturn.Add(new CPluginVariable("Save Sessiondata to DB?", typeof(enumBoolYesNo), this.m_enSessionTracking));
  1022.             lstReturn.Add(new CPluginVariable("Playerrequests per Round", this.numberOfAllowedRequests.GetType(), this.numberOfAllowedRequests));
  1023.             lstReturn.Add(new CPluginVariable("Servertime Offset", this.m_dTimeOffset.GetType(), this.m_dTimeOffset));
  1024.            
  1025.             //Ingame Command Setup
  1026.             /*
  1027.             this.m_IngameCommands_stats = "stats,rank";
  1028.             this.m_IngameCommands_serverstats = "serverstats";
  1029.             this.m_IngameCommands_session = "session";
  1030.             this.m_IngameCommands_dogtags = "dogtags";
  1031.             this.m_IngameCommands_top10 = "top10";
  1032.             this.m_IngameCommands_playerOfTheDay = "playeroftheday,potd";
  1033.             this.m_IngameCommands_top10ForPeriod = "weektop10,wtop10";
  1034.              */
  1035.             lstReturn.Add(new CPluginVariable("Stats Command:", this.m_IngameCommands_stats.GetType(), this.m_IngameCommands_stats));
  1036.             lstReturn.Add(new CPluginVariable("ServerStats Command:", this.m_IngameCommands_serverstats.GetType(), this.m_IngameCommands_serverstats));
  1037.             lstReturn.Add(new CPluginVariable("Session Command:", this.m_IngameCommands_session.GetType(), this.m_IngameCommands_session));
  1038.             lstReturn.Add(new CPluginVariable("Dogtags Command:", this.m_IngameCommands_dogtags.GetType(), this.m_IngameCommands_dogtags));
  1039.             lstReturn.Add(new CPluginVariable("Top10 Command:", this.m_IngameCommands_top10.GetType(), this.m_IngameCommands_top10));
  1040.             lstReturn.Add(new CPluginVariable("Player Of The Day Command:", this.m_IngameCommands_playerOfTheDay.GetType(), this.m_IngameCommands_playerOfTheDay));
  1041.             lstReturn.Add(new CPluginVariable("Top10 for period Command:", this.m_IngameCommands_top10ForPeriod.GetType(), this.m_IngameCommands_top10ForPeriod));
  1042.  
  1043.             lstReturn.Add(new CPluginVariable("Periodical Webrequest On?(P&S Stats)", typeof(enumBoolYesNo), this.m_enWebrequest));
  1044.             if (this.m_enWebrequest == enumBoolYesNo.Yes)
  1045.             {
  1046.                 lstReturn.Add(new CPluginVariable("Webaddress", this.m_webAddress.GetType(), this.m_webAddress));
  1047.                 lstReturn.Add(new CPluginVariable("Webrequest Intervall", this.m_requestIntervall.GetType(), this.m_requestIntervall));
  1048.             }
  1049.             //Simple Stats
  1050.             lstReturn.Add(new CPluginVariable("Log playerdata only (no playerstats)?", typeof(enumBoolYesNo), this.m_enLogPlayerDataOnly));
  1051.             return lstReturn;
  1052.         }
  1053.  
  1054.         public void SetPluginVariable(string strVariable, string strValue)
  1055.         {
  1056.             if (strVariable.CompareTo("Host") == 0)
  1057.             {
  1058.                 this.m_strHost = strValue;
  1059.             }
  1060.             else if (strVariable.CompareTo("Port") == 0)
  1061.             {
  1062.                 this.m_strDBPort = strValue;
  1063.             }
  1064.             else if (strVariable.CompareTo("Database Name") == 0)
  1065.             {
  1066.                 this.m_strDatabase = strValue;
  1067.             }
  1068.             else if (strVariable.CompareTo("UserName") == 0)
  1069.             {
  1070.                 this.m_strUserName = strValue;
  1071.             }
  1072.             else if (strVariable.CompareTo("Password") == 0)
  1073.             {
  1074.                 this.m_strPassword = strValue;
  1075.             }
  1076.             else if (strVariable.CompareTo("High performance mode(no connection limit!)") == 0 && Enum.IsDefined(typeof(enumBoolOnOff), strValue) == true)
  1077.             {
  1078.                 this.m_highPerformanceConnectionMode = (enumBoolOnOff)Enum.Parse(typeof(enumBoolOnOff), strValue);
  1079.             }
  1080.             else if (strVariable.CompareTo("Connection Pooling") == 0 && Enum.IsDefined(typeof(enumBoolOnOff), strValue) == true)
  1081.             {
  1082.                 this.m_connectionPooling = (enumBoolOnOff)Enum.Parse(typeof(enumBoolOnOff), strValue);
  1083.                 this.m_highPerformanceConnectionMode = enumBoolOnOff.On;
  1084.             }
  1085.             else if (strVariable.CompareTo("Min Connection Pool Size") == 0)
  1086.             {
  1087.                 Int32.TryParse(strValue, out this.m_minPoolSize);
  1088.                 if (this.m_minPoolSize < 0 || this.m_minPoolSize > this.m_maxPoolSize)
  1089.                 {
  1090.                     this.m_minPoolSize = 0;
  1091.                 }
  1092.             }
  1093.             else if (strVariable.CompareTo("Max Connection Pool Size") == 0)
  1094.             {
  1095.                 Int32.TryParse(strValue, out this.m_maxPoolSize);
  1096.                 if (this.m_maxPoolSize < 1 || this.m_minPoolSize > this.m_maxPoolSize)
  1097.                 {
  1098.                     this.m_maxPoolSize = 10;
  1099.                 }
  1100.             }
  1101.             else if (strVariable.CompareTo("Failed Transaction retry attempts") == 0)
  1102.             {
  1103.                 Int32.TryParse(strValue, out TransactionRetryCount);
  1104.                 if (TransactionRetryCount < 1)
  1105.                 {
  1106.                     TransactionRetryCount = 3;
  1107.                 }
  1108.             }
  1109.             else if (strVariable.CompareTo("Minimum time(sec) between ServerInfo Updates") == 0)
  1110.             {
  1111.                 if (Int32.TryParse(strValue, out this.minIntervalllenght))
  1112.                 {
  1113.                     if (this.minIntervalllenght < 1)
  1114.                     {
  1115.                         this.minIntervalllenght = 30;
  1116.                     }
  1117.                 }
  1118.                 else
  1119.                 {
  1120.                     this.minIntervalllenght = 30;
  1121.                 }
  1122.             }
  1123.             else if (strVariable.CompareTo("Enable Chatlogging?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1124.             {
  1125.                 this.m_enChatloggingON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1126.             }
  1127.             else if (strVariable.CompareTo("Log ServerSPAM?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1128.             {
  1129.                 this.m_enNoServerMsg = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1130.             }
  1131.             else if (strVariable.CompareTo("Instant Logging of Chat Messages?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1132.             {
  1133.                 this.m_enInstantChatlogging = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1134.             }
  1135.  
  1136.             else if (strVariable.CompareTo("Enable chatlog filter(Regex)?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1137.             {
  1138.                 this.m_enChatlogFilter = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1139.             }
  1140.             else if (strVariable.CompareTo("Chatfilterrules(Regex)") == 0)
  1141.             {
  1142.                 this.lstStrChatFilterRules = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1143.                 this.BuildRegexRuleset();
  1144.             }
  1145.             else if (strVariable.CompareTo("Enable Statslogging?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1146.             {
  1147.                 this.m_enLogSTATS = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1148.             }
  1149.             //Log playerdata only (no playerstats)?
  1150.             else if (strVariable.CompareTo("Log playerdata only (no playerstats)?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1151.             {
  1152.                 this.m_enLogPlayerDataOnly = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1153.             }
  1154.             else if (strVariable.CompareTo("Enable Weaponstats?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1155.             {
  1156.                 this.m_weaponstatsON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1157.             }
  1158.             else if (strVariable.CompareTo("Ranking by Score?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1159.             {
  1160.                 this.m_enRankingByScore = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1161.             }
  1162.             else if (strVariable.CompareTo("Enable ingame commands?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1163.             {
  1164.                 this.m_enableInGameCommands = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1165.             }
  1166.             else if (strVariable.CompareTo("Overall ranking(merged Serverranking)") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1167.             {
  1168.                 this.m_enOverallRanking = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1169.             }
  1170.             else if (strVariable.CompareTo("Server group (0 - 128)") == 0)
  1171.             {
  1172.                 if (Int32.TryParse(strValue, out this.intServerGroup))
  1173.                 {
  1174.                     if (this.intServerGroup > 128 || this.intServerGroup < 0)
  1175.                     {
  1176.                         this.intServerGroup = 0;
  1177.                     }
  1178.                 }
  1179.                 else
  1180.                 {
  1181.                     this.intServerGroup = 0;
  1182.                 }
  1183.             }
  1184.             else if (strVariable.CompareTo("Send Stats to all Players?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1185.             {
  1186.                 this.m_enSendStatsToAll = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1187.             }
  1188.             else if (strVariable.CompareTo("Enable Livescoreboard in DB?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1189.             {
  1190.                 this.m_enableCurrentPlayerstatsTable = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1191.             }
  1192.             else if (strVariable.CompareTo("Enable KDR correction?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1193.             {
  1194.                 this.m_kdrCorrection = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1195.             }
  1196.             else if (strVariable.CompareTo("PlayerMessage") == 0)
  1197.             {
  1198.                 this.m_lstPlayerStatsMessage = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1199.             }
  1200.             // player of the day
  1201.             else if (strVariable.CompareTo("Player of the day Message") == 0)
  1202.             {
  1203.                 this.m_lstPlayerOfTheDayMessage = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1204.             }
  1205.             else if (strVariable.CompareTo("Weaponstats Message ") == 0)
  1206.             {
  1207.                 this.m_lstWeaponstatsMsg = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1208.             }
  1209.             //Serverstats
  1210.             else if (strVariable.CompareTo("Serverstats Message") == 0)
  1211.             {
  1212.                 this.m_lstServerstatsMsg = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1213.             }
  1214.             else if (strVariable.CompareTo("Enable Welcomestats?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1215.             {
  1216.                 this.m_enWelcomeStats = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1217.             }
  1218.             else if (strVariable.CompareTo("Awards ON?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1219.             {
  1220.                 this.m_awardsON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1221.             }
  1222.             else if (strVariable.CompareTo("Yell Welcome Message(not the stats)?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1223.             {
  1224.                 this.m_enYellWelcomeMSG = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1225.             }
  1226.             else if (strVariable.CompareTo("Welcome Message") == 0)
  1227.             {
  1228.                 //this.m_strPlayerWelcomeMsg = strValue;
  1229.                 this.m_lstPlayerWelcomeStatsMessage = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1230.             }
  1231.             else if (strVariable.CompareTo("Welcome Message for new Player") == 0)
  1232.             {
  1233.                 this.m_lstNewPlayerWelcomeMsg = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1234.             }
  1235.             else if (strVariable.CompareTo("Welcomestats Delay") == 0 && Int32.TryParse(strValue, out int_welcomeStatsDelay) == true)
  1236.             {
  1237.                 this.int_welcomeStatsDelay = Convert.ToInt32(strValue);
  1238.             }
  1239.             else if (strVariable.CompareTo("Top10 ingame") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1240.             {
  1241.                 this.m_enTop10ingame = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1242.             }
  1243.             //top10
  1244.             else if (strVariable.CompareTo("Top10 header line") == 0)
  1245.             {
  1246.                 this.m_strTop10Header = strValue;
  1247.             }
  1248.             else if (strVariable.CompareTo("Top10 row format") == 0)
  1249.             {
  1250.                 this.m_strTop10RowFormat = strValue;
  1251.             }
  1252.             // top10 for period
  1253.             else if (strVariable.CompareTo("Top10 for period header line") == 0)
  1254.             {
  1255.                 this.m_strTop10HeaderForPeriod = strValue;
  1256.             }
  1257.             else if (strVariable.CompareTo("Top10 for period interval days") == 0)
  1258.             {
  1259.                 if (Int32.TryParse(strValue, out this.m_intDaysForPeriodTop10) == false)
  1260.                 {
  1261.                     this.m_intDaysForPeriodTop10 = 7;
  1262.                 }
  1263.             }
  1264.             else if (strVariable.CompareTo("WeaponTop10 header line") == 0)
  1265.             {
  1266.                 this.m_strWeaponTop10Header = strValue;
  1267.             }
  1268.             else if (strVariable.CompareTo("WeaponTop10 row format") == 0)
  1269.             {
  1270.                 this.m_strWeaponTop10RowFormat = strValue;
  1271.             }
  1272.             else if (strVariable.CompareTo("DebugLevel") == 0)
  1273.             {
  1274.                 this.GlobalDebugMode = strValue;
  1275.             }
  1276.             else if (strVariable.CompareTo("Keywordlist") == 0)
  1277.             {
  1278.                 this.m_lstTableconfig = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1279.             }
  1280.             else if (strVariable.CompareTo("tableSuffix") == 0)
  1281.             {
  1282.                 this.tableSuffix = strValue;
  1283.                 this.prepareTablenames();
  1284.                 this.setGameMod();
  1285.                 this.boolTableEXISTS = false;
  1286.             }
  1287.             else if (strVariable.CompareTo("MapStats ON?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1288.             {
  1289.                 this.m_mapstatsON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1290.             }
  1291.             else if (strVariable.CompareTo("Session ON?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1292.             {
  1293.                 this.m_sessionON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1294.             }
  1295.             else if (strVariable.CompareTo("SessionMessage") == 0)
  1296.             {
  1297.                 this.m_lstSessionMessage = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  1298.             }
  1299.             else if (strVariable.CompareTo("Save Sessiondata to DB?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1300.             {
  1301.                 this.m_enSessionTracking = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1302.             }
  1303.             else if (strVariable.CompareTo("Playerrequests per Round") == 0 && Int32.TryParse(strValue, out numberOfAllowedRequests) == true)
  1304.             {
  1305.                 this.numberOfAllowedRequests = Convert.ToInt32(strValue);
  1306.             }
  1307.             else if (strVariable.CompareTo("Servertime Offset") == 0 && Double.TryParse(strValue, out m_dTimeOffset) == true)
  1308.             {
  1309.                 this.m_dTimeOffset = Convert.ToDouble(strValue);
  1310.                 this.MyDateTime = new myDateTime_W(this.m_dTimeOffset);
  1311.             }
  1312.            
  1313.             //Webrequest
  1314.             /*
  1315.         else if (strVariable.CompareTo("Periodical Webrequest On?(P&S Stats)") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  1316.         {
  1317.             this.m_enWebrequest = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  1318.         }
  1319.         else if (strVariable.CompareTo("Webaddress") == 0)
  1320.         {
  1321.             this.m_webAddress = strValue;
  1322.         }
  1323.         else if (strVariable.CompareTo("Webrequest Intervall") == 0 && Int32.TryParse(strValue, out this.m_requestIntervall) == true)
  1324.         {
  1325.             this.m_requestIntervall = Convert.ToInt32(strValue);
  1326.         }
  1327.              */
  1328.             else if (strVariable.CompareTo("Stats Command:") == 0)
  1329.             {
  1330.                 this.m_IngameCommands_stats = strValue;
  1331.             }
  1332.             else if (strVariable.CompareTo("ServerStats Command:") == 0)
  1333.             {
  1334.                 this.m_IngameCommands_serverstats = strValue;
  1335.             }
  1336.             else if (strVariable.CompareTo("Session Command:") == 0)
  1337.             {
  1338.                 this.m_IngameCommands_session = strValue;
  1339.             }
  1340.             else if (strVariable.CompareTo("Dogtags Command:") == 0)
  1341.             {
  1342.                 this.m_IngameCommands_dogtags = strValue;
  1343.             }
  1344.             else if (strVariable.CompareTo("Top10 Command:") == 0)
  1345.             {
  1346.                 this.m_IngameCommands_top10 = strValue;
  1347.             }
  1348.             else if (strVariable.CompareTo("Player Of The Day Command:") == 0)
  1349.             {
  1350.                 this.m_IngameCommands_playerOfTheDay = strValue;
  1351.             }
  1352.             else if (strVariable.CompareTo("Top10 for period Command:") == 0)
  1353.             {
  1354.                 this.m_IngameCommands_top10ForPeriod = strValue;
  1355.             }
  1356.             this.RegisterAllCommands();
  1357.         }
  1358.  
  1359.         private List<string> GetExcludedCommandStrings(string strAccountName)
  1360.         {
  1361.             List<string> lstReturnCommandStrings = new List<string>();
  1362.             List<MatchCommand> lstCommands = this.GetRegisteredCommands();
  1363.             CPrivileges privileges = this.GetAccountPrivileges(strAccountName);
  1364.             foreach (MatchCommand mtcCommand in lstCommands)
  1365.             {
  1366.                 if (mtcCommand.Requirements.HasValidPermissions(privileges) == true && lstReturnCommandStrings.Contains(mtcCommand.Command) == false)
  1367.                 {
  1368.                     lstReturnCommandStrings.Add(mtcCommand.Command);
  1369.                 }
  1370.             }
  1371.             return lstReturnCommandStrings;
  1372.         }
  1373.  
  1374.         private List<string> GetCommandStrings()
  1375.         {
  1376.             List<string> lstReturnCommandStrings = new List<string>();
  1377.             List<MatchCommand> lstCommands = this.GetRegisteredCommands();
  1378.             foreach (MatchCommand mtcCommand in lstCommands)
  1379.             {
  1380.                 if (lstReturnCommandStrings.Contains(mtcCommand.Command) == false)
  1381.                 {
  1382.                     lstReturnCommandStrings.Add(mtcCommand.Command);
  1383.                 }
  1384.             }
  1385.             return lstReturnCommandStrings;
  1386.         }
  1387.  
  1388.         private void UnregisterAllCommands()
  1389.         {
  1390.             this.setupIngameCommandDic();
  1391.             try
  1392.             {
  1393.                 foreach (KeyValuePair<string, CStatsIngameCommands> kvp in this.dicIngameCommands)
  1394.                 {
  1395.                     if (kvp.Value.commands != string.Empty)
  1396.                     {
  1397.                         foreach (string command in kvp.Value.commands.Split(','))
  1398.                         {
  1399.                             this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", kvp.Value.functioncall.ToString(), this.Listify<string>("@", "!", "#"), command.ToString(), this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), kvp.Value.description.ToString()));
  1400.                         }
  1401.                     }
  1402.                 }
  1403.             }
  1404.             catch (Exception e)
  1405.             {
  1406.                 this.DebugInfo("Error", "Error in UnregisterAllCommands: " + e);
  1407.             }
  1408.         }
  1409.  
  1410.         private void SetupHelpCommands()
  1411.         {
  1412.  
  1413.         }
  1414.  
  1415.         private void RegisterAllCommands()
  1416.         {
  1417.             lock (this.registerallcomandslock)
  1418.             {
  1419.                 this.setupIngameCommandDic();
  1420.                 if (this.m_isPluginEnabled == true)
  1421.                 {
  1422.                     if (this.m_enableInGameCommands == enumBoolYesNo.No)
  1423.                     {
  1424.                         this.UnregisterAllCommands();
  1425.                         return;
  1426.                     }
  1427.                     this.SetupHelpCommands();
  1428.  
  1429.                     try
  1430.                     {
  1431.                         foreach (KeyValuePair<string, CStatsIngameCommands> kvp in this.dicIngameCommands)
  1432.                         {
  1433.                             if (kvp.Value.commands != string.Empty)
  1434.                             {
  1435.                                 foreach (string command in kvp.Value.commands.Split(','))
  1436.                                 {
  1437.                                     if (kvp.Value.boolEnabled)
  1438.                                     {
  1439.                                         this.RegisterCommand(new MatchCommand("CChatGUIDStatsLogger", kvp.Value.functioncall, this.Listify<string>("@", "!", "#"), command, this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), kvp.Value.description));
  1440.                                     }
  1441.                                     else
  1442.                                     {
  1443.                                         this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", kvp.Value.functioncall, this.Listify<string>("@", "!", "#"), command, this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), kvp.Value.description));
  1444.                                     }
  1445.                                 }
  1446.                             }
  1447.                         }
  1448.                     }
  1449.                     catch (Exception e)
  1450.                     {
  1451.                         this.DebugInfo("Error", "Error in RegisterAllCommands: " + e);
  1452.                     }
  1453.                 }
  1454.             }
  1455.         }
  1456.  
  1457.         private void setupIngameCommandDic()
  1458.         {
  1459.             lock (this.dicIngameCommands)
  1460.             {
  1461.                 bool boolenable = false;
  1462.                 this.dicIngameCommands.Clear();
  1463.                 if (this.m_enLogSTATS == enumBoolYesNo.Yes && this.m_enableInGameCommands == enumBoolYesNo.Yes)
  1464.                 {
  1465.                     boolenable = true;
  1466.                 }
  1467.                 this.dicIngameCommands.Add("playerstats", new CStatsIngameCommands(this.m_IngameCommands_stats, "OnCommandStats", boolenable, "Provides a player his personal serverstats"));
  1468.                 this.dicIngameCommands.Add("serverstats", new CStatsIngameCommands(this.m_IngameCommands_serverstats, "OnCommandServerStats", boolenable, "Provides a player his personal serverstats"));
  1469.                 this.dicIngameCommands.Add("dogtagstats", new CStatsIngameCommands(this.m_IngameCommands_dogtags, "OnCommandDogtags", boolenable, "Provides a player his personal dogtagstats"));
  1470.                 this.dicIngameCommands.Add("session", new CStatsIngameCommands(this.m_IngameCommands_session, "OnCommandSession", boolenable, "Provides a player his personal sessiondata"));
  1471.                 this.dicIngameCommands.Add("playeroftheday", new CStatsIngameCommands(this.m_IngameCommands_playerOfTheDay, "OnCommandPlayerOfTheDay", boolenable, "Provides the player of the day stats"));
  1472.  
  1473.                 if (this.m_enLogSTATS == enumBoolYesNo.Yes && this.m_enTop10ingame == enumBoolYesNo.Yes && this.m_enableInGameCommands == enumBoolYesNo.Yes)
  1474.                 {
  1475.                     this.dicIngameCommands.Add("top10", new CStatsIngameCommands(this.m_IngameCommands_top10, "OnCommandTop10", true, "Provides a player top10 Players"));
  1476.                     this.dicIngameCommands.Add("top10forperiode", new CStatsIngameCommands(this.m_IngameCommands_top10ForPeriod, "OnCommandTop10ForPeriod", true, "Provides a player top10 Players for a specific timeframe"));
  1477.                 }
  1478.                 else
  1479.                 {
  1480.                     this.dicIngameCommands.Add("top10", new CStatsIngameCommands(this.m_IngameCommands_top10, "OnCommandTop10", false, "Provides a player top10 Players"));
  1481.                     this.dicIngameCommands.Add("top10forperiode", new CStatsIngameCommands(this.m_IngameCommands_top10ForPeriod, "OnCommandTop10ForPeriod", false, "Provides a player top10 Players for a specific timeframe"));
  1482.                 }
  1483.             }
  1484.         }
  1485.         #endregion
  1486.  
  1487.         #region IPRoConPluginInterface
  1488.         /*=======ProCon Events========*/
  1489.         // Player events
  1490.         public override void OnPlayerJoin(string strSoldierName)
  1491.         {
  1492.             if (this.StatsTracker.ContainsKey(strSoldierName) == false)
  1493.             {
  1494.                 CStats newEntry = new CStats(String.Empty, 0, 0, 0, 0, 0, 0, 0, this.m_dTimeOffset, this.weaponDic);
  1495.                 StatsTracker.Add(strSoldierName, newEntry);
  1496.             }
  1497.             ThreadPool.QueueUserWorkItem(delegate { this.CreateSession(strSoldierName, 0, String.Empty); });
  1498.  
  1499.             if (bool_roundStarted == true && StatsTracker.ContainsKey(strSoldierName) == true)
  1500.             {
  1501.                 if (StatsTracker[strSoldierName].PlayerOnServer == false)
  1502.                 {
  1503.                     if (this.StatsTracker[strSoldierName].TimePlayerjoined == null)
  1504.                     {
  1505.                         this.StatsTracker[strSoldierName].TimePlayerjoined = MyDateTime.Now;
  1506.                     }
  1507.                     this.StatsTracker[strSoldierName].Playerjoined = MyDateTime.Now;
  1508.                     this.StatsTracker[strSoldierName].PlayerOnServer = true;
  1509.                 }
  1510.             }
  1511.             //Mapstatscounter for Player who joined the server
  1512.             this.Mapstats.IntplayerjoinedServer++;
  1513.  
  1514.             if (this.m_enWelcomeStats == enumBoolYesNo.Yes)
  1515.             {
  1516.                 if (this.welcomestatsDic.ContainsKey(strSoldierName))
  1517.                 {
  1518.                     //Update jointime
  1519.                     this.welcomestatsDic[strSoldierName] = MyDateTime.Now;
  1520.                 }
  1521.                 else
  1522.                 {
  1523.                     //Insert
  1524.                     this.DebugInfo("Trace", "Added Player: " + strSoldierName + " to welcomestatslist");
  1525.                     this.welcomestatsDic.Add(strSoldierName, MyDateTime.Now);
  1526.                 }
  1527.             }
  1528.         }
  1529.  
  1530.         public override void OnPlayerAuthenticated(string soldierName, string guid)
  1531.         {
  1532.             if (this.StatsTracker.ContainsKey(soldierName) == false)
  1533.             {
  1534.                 CStats newEntry = new CStats(String.Empty, 0, 0, 0, 0, 0, 0, 0, this.m_dTimeOffset, this.weaponDic);
  1535.                 StatsTracker.Add(soldierName, newEntry);
  1536.                 if (guid.Length > 0)
  1537.                 {
  1538.                     StatsTracker[soldierName].EAGuid = guid;
  1539.                 }
  1540.             }
  1541.         }
  1542.  
  1543.         // Will receive ALL chat global/team/squad in R3.
  1544.         public override void OnGlobalChat(string strSpeaker, string strMessage)
  1545.         {
  1546.             if (strMessage.Length > 0)
  1547.             {
  1548.                 ThreadPool.QueueUserWorkItem(delegate { this.LogChat(strSpeaker, strMessage, "Global"); });
  1549.             }
  1550.         }
  1551.  
  1552.         // Place holder, non-functioning in R3.  It recieves the same data as OnGlobalChat though so look out for now.
  1553.         public override void OnTeamChat(string strSpeaker, string strMessage, int iTeamID)
  1554.         {
  1555.             if (strMessage.Length > 0)
  1556.             {
  1557.                 ThreadPool.QueueUserWorkItem( delegate { this.LogChat(strSpeaker, strMessage, "Team"); });
  1558.             }
  1559.         }
  1560.  
  1561.         // Place holder, non-functioning in R3.  It recieves the same data as OnGlobalChat though so look out for now.
  1562.         public override void OnSquadChat(string strSpeaker, string strMessage, int iTeamID, int iSquadID)
  1563.         {
  1564.             if (strMessage.Length > 0)
  1565.             {
  1566.                 ThreadPool.QueueUserWorkItem(delegate { this.LogChat(strSpeaker, strMessage, "Squad"); });
  1567.             }
  1568.         }
  1569.  
  1570.         public override void OnPunkbusterMessage(string strPunkbusterMessage)
  1571.         {
  1572.             try
  1573.             {
  1574.                 // This piece of code gets the number of player out of Punkbustermessages
  1575.                 string playercount = String.Empty;
  1576.                 if (strPunkbusterMessage.Contains("End of Player List"))
  1577.                 {
  1578.                     playercount = strPunkbusterMessage.Remove(0, 1 + strPunkbusterMessage.LastIndexOf("("));
  1579.                     playercount = playercount.Replace(" ", "");
  1580.                     playercount = playercount.Remove(playercount.LastIndexOf("P"), playercount.LastIndexOf(")"));
  1581.                     //this.DebugInfo("EoPl: "+playercount);
  1582.                     int players = Convert.ToInt32(playercount);
  1583.                     if (players >= intRoundStartCount && bool_roundStarted == false)
  1584.                     {
  1585.                         bool_roundStarted = true;
  1586.                         Time_RankingStarted = MyDateTime.Now;
  1587.                         //Mapstats Roundstarted
  1588.                         this.Mapstats.MapStarted();
  1589.                     }
  1590.                     else if (players >= intRoundStartCount && this.Mapstats.TimeMapStarted == DateTime.MinValue)
  1591.                     {
  1592.                         this.Mapstats.MapStarted();
  1593.                     }
  1594.                     //MapStats Playercount
  1595.                     this.Mapstats.ListADD(players);
  1596.                 }
  1597.             }
  1598.             catch (Exception c)
  1599.             {
  1600.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OnPunkbusterMessage: " + c);
  1601.             }
  1602.         }
  1603.  
  1604.         public override void OnPunkbusterPlayerInfo(CPunkbusterInfo cpbiPlayer)
  1605.         {
  1606.             this.RegisterAllCommands();
  1607.             if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  1608.             {
  1609.                 try
  1610.                 {
  1611.                     this.AddPBInfoToStats(cpbiPlayer);
  1612.                     if (this.StatsTracker.ContainsKey(cpbiPlayer.SoldierName))
  1613.                     {
  1614.                         if (this.StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined == null)
  1615.                         {
  1616.                             this.StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined = MyDateTime.Now;
  1617.                         }
  1618.                         this.StatsTracker[cpbiPlayer.SoldierName].IP = cpbiPlayer.Ip;
  1619.                     }
  1620.                 }
  1621.                 catch (Exception c)
  1622.                 {
  1623.                     this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OnPunkbusterPlayerInfo: " + c);
  1624.                 }
  1625.             }
  1626.         }
  1627.  
  1628.         // Query Events
  1629.         public override void OnServerInfo(CServerInfo csiServerInfo)
  1630.         {
  1631.             this.serverName = csiServerInfo.ServerName;
  1632.             this.Mapstats.StrGamemode = csiServerInfo.GameMode;
  1633.             this.Mapstats.ListADD(csiServerInfo.PlayerCount);
  1634.             //Mapstats
  1635.             if (csiServerInfo.PlayerCount >= intRoundStartCount && this.Mapstats.TimeMapStarted == DateTime.MinValue)
  1636.             {
  1637.                 this.Mapstats.MapStarted();
  1638.             }
  1639.             this.Mapstats.StrMapname = csiServerInfo.Map;
  1640.             this.Mapstats.IntRound = csiServerInfo.CurrentRound;
  1641.             this.Mapstats.IntNumberOfRounds = csiServerInfo.TotalRounds;
  1642.             this.Mapstats.IntServerplayermax = csiServerInfo.MaxPlayerCount;
  1643.  
  1644.             if(this.ServerID == 0 || this.minIntervalllenght <= (DateTime.Now.Subtract(this.dtLastServerInfoEvent).TotalSeconds))
  1645.             {
  1646.                 this.dtLastServerInfoEvent = DateTime.Now;
  1647.                 try
  1648.                 {
  1649.                     ThreadPool.QueueUserWorkItem(delegate { this.getUpdateServerID(csiServerInfo); });
  1650.                 }
  1651.                 catch { };
  1652.             }
  1653.         }
  1654.  
  1655.         public override void OnListPlayers(List<CPlayerInfo> lstPlayers, CPlayerSubset cpsSubset)
  1656.         {
  1657.             //List<CPlayerInfo> PlayerList = new List<CPlayerInfo>();
  1658.             //Mapstats Add Playercount to list
  1659.             this.Mapstats.ListADD(lstPlayers.Count);
  1660.             if (bool_roundStarted == false)
  1661.             {
  1662.                 if (lstPlayers.Count >= intRoundStartCount)
  1663.                 {
  1664.                     bool_roundStarted = true;
  1665.                     Time_RankingStarted = MyDateTime.Now;
  1666.                     this.DebugInfo("Trace", "OLP: roundstarted");
  1667.                     //Mapstats Roundstarted
  1668.                     this.Mapstats.MapStarted();
  1669.                 }
  1670.             }
  1671.             if (lstPlayers.Count >= intRoundStartCount && this.Mapstats.TimeMapStarted == DateTime.MinValue)
  1672.             {
  1673.                 this.Mapstats.MapStarted();
  1674.             }
  1675.             try
  1676.             {
  1677.                 foreach (CPlayerInfo cpiPlayer in lstPlayers)
  1678.                 {
  1679.                     if (this.m_dicPlayers.ContainsKey(cpiPlayer.SoldierName) == true)
  1680.                     {
  1681.                         this.m_dicPlayers[cpiPlayer.SoldierName] = cpiPlayer;
  1682.                     }
  1683.                     else
  1684.                     {
  1685.                         this.m_dicPlayers.Add(cpiPlayer.SoldierName, cpiPlayer);
  1686.                     }
  1687.                     //Timelogging
  1688.                     if (this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  1689.                     {
  1690.                         if (this.StatsTracker[cpiPlayer.SoldierName].PlayerOnServer == false)
  1691.                         {
  1692.                             this.StatsTracker[cpiPlayer.SoldierName].Playerjoined = MyDateTime.Now;
  1693.                             this.StatsTracker[cpiPlayer.SoldierName].PlayerOnServer = true;
  1694.                         }
  1695.                         //EA-GUID, ClanTag, usw.
  1696.                         if (cpiPlayer.GUID.Length > 3)
  1697.                         {
  1698.                             this.StatsTracker[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1699.                             //ID - Cache
  1700.                             if (this.m_ID_cache.ContainsKey(cpiPlayer.GUID))
  1701.                             {
  1702.                                 this.m_ID_cache[cpiPlayer.GUID].PlayeronServer = true;
  1703.                             }
  1704.                         }
  1705.                         this.StatsTracker[cpiPlayer.SoldierName].ClanTag = cpiPlayer.ClanTag;
  1706.                         //TeamId
  1707.                         this.StatsTracker[cpiPlayer.SoldierName].TeamId = cpiPlayer.TeamID;
  1708.                         if (cpiPlayer.Score != 0)
  1709.                         {
  1710.                             this.StatsTracker[cpiPlayer.SoldierName].Score = cpiPlayer.Score;
  1711.                         }
  1712.                         //GlobalRank
  1713.                         if (cpiPlayer.Rank >= 0)
  1714.                         {
  1715.                             this.StatsTracker[cpiPlayer.SoldierName].GlobalRank = cpiPlayer.Rank;
  1716.                         }
  1717.  
  1718.                         //KDR Correction
  1719.                         if (this.m_kdrCorrection == enumBoolYesNo.Yes && ((cpiPlayer.Deaths == 0 && cpiPlayer.Kills == 0 && cpiPlayer.Score == 0) == false))
  1720.                         {
  1721.                             if (this.StatsTracker[cpiPlayer.SoldierName].Deaths > (cpiPlayer.Deaths + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftDeaths))
  1722.                             {
  1723.                                 this.DebugInfo("Trace", "OnListPlayers Player: " + cpiPlayer.SoldierName + " has " + this.StatsTracker[cpiPlayer.SoldierName].Deaths + " deaths; correcting to " + cpiPlayer.Deaths + " deaths now");
  1724.                                 this.StatsTracker[cpiPlayer.SoldierName].Deaths = (cpiPlayer.Deaths + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftDeaths);
  1725.                             }
  1726.                             if (this.StatsTracker[cpiPlayer.SoldierName].Kills > (cpiPlayer.Kills + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftKills))
  1727.                             {
  1728.                                 this.StatsTracker[cpiPlayer.SoldierName].Kills = (cpiPlayer.Kills + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftKills);
  1729.                             }
  1730.                         }
  1731.  
  1732.                     }
  1733.                     //Session Score
  1734.                     if (this.m_sessionON == enumBoolYesNo.Yes)
  1735.                     {
  1736.                         lock (this.sessionlock)
  1737.                         {
  1738.                             if (this.m_dicSession.ContainsKey(cpiPlayer.SoldierName))
  1739.                             {
  1740.                                 this.m_dicSession[cpiPlayer.SoldierName].AddScore(cpiPlayer.Score);
  1741.                                 //KDR Correction
  1742.                                 if (this.m_kdrCorrection == enumBoolYesNo.Yes && ((cpiPlayer.Deaths == 0 && cpiPlayer.Kills == 0 && cpiPlayer.Score == 0) == false))
  1743.                                 {
  1744.                                     if (this.m_dicSession[cpiPlayer.SoldierName].Deaths > (cpiPlayer.Deaths + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftDeaths))
  1745.                                     {
  1746.                                         this.DebugInfo("Trace", "Player: " + cpiPlayer.SoldierName + " has " + this.m_dicSession[cpiPlayer.SoldierName].Deaths + " deaths; correcting to " + cpiPlayer.Deaths + " deaths now");
  1747.                                         this.m_dicSession[cpiPlayer.SoldierName].Deaths = (cpiPlayer.Deaths + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftDeaths);
  1748.                                     }
  1749.                                     if (this.m_dicSession[cpiPlayer.SoldierName].Kills > (cpiPlayer.Kills + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftKills))
  1750.                                     {
  1751.                                         this.m_dicSession[cpiPlayer.SoldierName].Kills = (cpiPlayer.Kills + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftKills);
  1752.                                     }
  1753.                                 }
  1754.                                 if (cpiPlayer.GUID.Length > 2)
  1755.                                 {
  1756.                                     this.m_dicSession[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1757.                                 }
  1758.                                 //TeamId
  1759.                                 this.m_dicSession[cpiPlayer.SoldierName].TeamId = cpiPlayer.TeamID;
  1760.                             }
  1761.                             else
  1762.                             {
  1763.                                 ThreadPool.QueueUserWorkItem(delegate { this.CreateSession(cpiPlayer.SoldierName, cpiPlayer.Score, cpiPlayer.GUID); });
  1764.                             }
  1765.                         }
  1766.                     }
  1767.                     //Checking the sessiondic
  1768.                     //ThreadPool.QueueUserWorkItem(delegate { this.CheckSessionDic(lstPlayers); });
  1769.                     //this.CreateSession(cpiPlayer.SoldierName, cpiPlayer.Score);
  1770.                 }
  1771.  
  1772.                 if (this.m_enableCurrentPlayerstatsTable == enumBoolYesNo.Yes && this.ServerID > 0 && this.minIntervalllenght <= (DateTime.Now.Subtract(this.dtLastOnListPlayersEvent).TotalSeconds))
  1773.                 {
  1774.                     ThreadPool.QueueUserWorkItem(delegate { this.UpdateCurrentPlayerTable(lstPlayers); });
  1775.                     this.dtLastOnListPlayersEvent = DateTime.Now;
  1776.                 }
  1777.             }
  1778.             catch (Exception c)
  1779.             {
  1780.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OnListPlayers: " + c);
  1781.             }
  1782.         }
  1783.  
  1784.         public override void OnPlayerKilled(Kill kKillerVictimDetails)
  1785.         {
  1786.             bool_roundStarted = true;
  1787.             if (bool_roundStarted == true)
  1788.             {
  1789.                 this.playerKilled(kKillerVictimDetails);
  1790.             }
  1791.         }
  1792.  
  1793.         public override void OnPlayerLeft(CPlayerInfo cpiPlayer)
  1794.         {
  1795.             this.playerLeftServer(cpiPlayer);
  1796.             this.RegisterAllCommands();
  1797.         }
  1798.  
  1799.         public override void OnRoundOverPlayers(List<CPlayerInfo> lstPlayers)
  1800.         {
  1801.             this.DebugInfo("Trace", "OnRoundOverPlayers Event");
  1802.             foreach (CPlayerInfo cpiPlayer in lstPlayers)
  1803.             {
  1804.                 if (this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  1805.                 {
  1806.                     this.StatsTracker[cpiPlayer.SoldierName].Score = cpiPlayer.Score;
  1807.                     //EA-GUID, ClanTag, usw.
  1808.                     if (cpiPlayer.GUID.Length > 3)
  1809.                     {
  1810.                         this.StatsTracker[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1811.                         //ID - Cache
  1812.                         if (this.m_ID_cache.ContainsKey(cpiPlayer.GUID))
  1813.                         {
  1814.                             this.m_ID_cache[cpiPlayer.GUID].PlayeronServer = true;
  1815.                         }
  1816.                     }
  1817.                     this.StatsTracker[cpiPlayer.SoldierName].ClanTag = cpiPlayer.ClanTag;
  1818.                     //TeamId
  1819.                     this.StatsTracker[cpiPlayer.SoldierName].TeamId = cpiPlayer.TeamID;
  1820.  
  1821.                     //KDR Correction
  1822.                     if (this.m_kdrCorrection == enumBoolYesNo.Yes && ((cpiPlayer.Deaths == 0 && cpiPlayer.Kills == 0 && cpiPlayer.Score == 0) == false))
  1823.                     {
  1824.                         if (this.StatsTracker[cpiPlayer.SoldierName].Deaths > (cpiPlayer.Deaths + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftDeaths))
  1825.                         {
  1826.                             this.DebugInfo("Trace", "Player: " + cpiPlayer.SoldierName + " has " + this.StatsTracker[cpiPlayer.SoldierName].Deaths + " deaths; correcting to " + cpiPlayer.Deaths + " deaths now");
  1827.                             this.StatsTracker[cpiPlayer.SoldierName].Deaths = (cpiPlayer.Deaths + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftDeaths);
  1828.                         }
  1829.                         if (this.StatsTracker[cpiPlayer.SoldierName].Kills > (cpiPlayer.Kills + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftKills))
  1830.                         {
  1831.                             this.StatsTracker[cpiPlayer.SoldierName].Kills = (cpiPlayer.Kills + this.StatsTracker[cpiPlayer.SoldierName].BeforeLeftKills);
  1832.                         }
  1833.                     }
  1834.                     //GlobalRank
  1835.                     if (cpiPlayer.Rank >= 0)
  1836.                     {
  1837.                         this.StatsTracker[cpiPlayer.SoldierName].GlobalRank = cpiPlayer.Rank;
  1838.                     }
  1839.                 }
  1840.                 //Session Score
  1841.                 lock (this.sessionlock)
  1842.                 {
  1843.                     if (this.m_dicSession.ContainsKey(cpiPlayer.SoldierName) && this.m_sessionON == enumBoolYesNo.Yes)
  1844.                     {
  1845.                         //KDR Correction
  1846.                         if (this.m_kdrCorrection == enumBoolYesNo.Yes && ((cpiPlayer.Deaths == 0 && cpiPlayer.Kills == 0 && cpiPlayer.Score == 0) == false))
  1847.                         {
  1848.                             if (this.m_dicSession[cpiPlayer.SoldierName].Deaths > (cpiPlayer.Deaths + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftDeaths))
  1849.                             {
  1850.                                 this.DebugInfo("Trace", "Player: " + cpiPlayer.SoldierName + " has " + this.m_dicSession[cpiPlayer.SoldierName].Deaths + " deaths; correcting to " + cpiPlayer.Deaths + " deaths now");
  1851.                                 this.m_dicSession[cpiPlayer.SoldierName].Deaths = (cpiPlayer.Deaths + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftDeaths);
  1852.                             }
  1853.                             if (this.m_dicSession[cpiPlayer.SoldierName].Kills > (cpiPlayer.Kills + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftKills))
  1854.                             {
  1855.                                 this.m_dicSession[cpiPlayer.SoldierName].Kills = (cpiPlayer.Kills + this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftKills);
  1856.                             }
  1857.                         }
  1858.                         this.m_dicSession[cpiPlayer.SoldierName].AddScore(cpiPlayer.Score);
  1859.                         this.m_dicSession[cpiPlayer.SoldierName].LastScore = 0;
  1860.                         this.m_dicSession[cpiPlayer.SoldierName].Rounds++;
  1861.                         this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftKills += this.m_dicSession[cpiPlayer.SoldierName].Kills;
  1862.                         this.m_dicSession[cpiPlayer.SoldierName].BeforeLeftDeaths += this.m_dicSession[cpiPlayer.SoldierName].Deaths;
  1863.                         //TeamId
  1864.                         this.m_dicSession[cpiPlayer.SoldierName].TeamId = cpiPlayer.TeamID;
  1865.                         if (cpiPlayer.GUID.Length > 2)
  1866.                         {
  1867.                             this.m_dicSession[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1868.                         }
  1869.                     }
  1870.                     else
  1871.                     {
  1872.                         ThreadPool.QueueUserWorkItem(delegate { this.CreateSession(cpiPlayer.SoldierName, cpiPlayer.Score, cpiPlayer.GUID); });
  1873.                     }
  1874.                 }
  1875.             }
  1876.             this.Mapstats.MapEnd();
  1877.         }
  1878.  
  1879.         public override void OnRoundOver(int winningTeamId)
  1880.         {
  1881.             this.DebugInfo("Trace", "OnRoundOver: TeamId -> " + winningTeamId);
  1882.             //StatsTracker
  1883.             foreach (KeyValuePair<string, CStats> kvp in this.StatsTracker)
  1884.             {
  1885.                 if (kvp.Value.PlayerOnServer == true)
  1886.                 {
  1887.                     if (kvp.Value.TeamId == winningTeamId)
  1888.                     {
  1889.                         this.StatsTracker[kvp.Key].Wins++;
  1890.                     }
  1891.                     else
  1892.                     {
  1893.                         this.StatsTracker[kvp.Key].Losses++;
  1894.                     }
  1895.                 }
  1896.             }
  1897.             //Session
  1898.             lock (this.sessionlock)
  1899.             {
  1900.                 foreach (KeyValuePair<string, CStats> kvp in this.m_dicSession)
  1901.                 {
  1902.                     if (kvp.Value.PlayerOnServer == true)
  1903.                     {
  1904.                         if (kvp.Value.TeamId == winningTeamId)
  1905.                         {
  1906.                             this.m_dicSession[kvp.Key].Wins++;
  1907.                         }
  1908.                         else
  1909.                         {
  1910.                             this.m_dicSession[kvp.Key].Losses++;
  1911.                         }
  1912.                     }
  1913.                 }
  1914.             }
  1915.         }
  1916.  
  1917.         public override void OnPlayerSpawned(string soldierName, Inventory spawnedInventory)
  1918.         {
  1919.             if (bool_roundStarted == true && StatsTracker.ContainsKey(soldierName) == true)
  1920.             {
  1921.                 if (StatsTracker[soldierName].PlayerOnServer == false)
  1922.                 {
  1923.                     this.StatsTracker[soldierName].Playerjoined = MyDateTime.Now;
  1924.                     this.StatsTracker[soldierName].PlayerOnServer = true;
  1925.                 }
  1926.             }
  1927.             if (this.m_enWelcomeStats == enumBoolYesNo.Yes)
  1928.             {
  1929.                 if(this.welcomestatsDic.ContainsKey(soldierName))
  1930.                 {
  1931.                     //Call of the Welcomstatsfunction
  1932.                     ThreadPool.QueueUserWorkItem(delegate { this.WelcomeStats(soldierName); });
  1933.                     lock(this.welcomestatsDic)
  1934.                     {
  1935.                         this.welcomestatsDic.Remove(soldierName);
  1936.                     }
  1937.                 }
  1938.             }
  1939.         }
  1940.  
  1941.         public override void OnLevelLoaded(string mapFileName, string Gamemode, int roundsPlayed, int roundsTotal)
  1942.         {
  1943.             if ((DateTime.Now.Subtract(this.dtLastRoundendEvent)).TotalSeconds > 30)
  1944.             {
  1945.                 this.dtLastRoundendEvent = DateTime.Now;
  1946.                 this.DebugInfo("Info", "OnLevelLoaded: " + mapFileName + " Gamemode: " + Gamemode + " Round: " + (roundsPlayed + 1) + "/" + roundsTotal);
  1947.                 this.DebugInfo("Info", "update sql server");
  1948.                 this.Nextmapinfo = new CMapstats(MyDateTime.Now, mapFileName, (roundsPlayed + 1), roundsTotal, this.m_dTimeOffset);
  1949.                 //Calculate Awards
  1950.                 this.calculateAwards();
  1951.                 new Thread(StartStreaming).Start();
  1952.                 m_dicPlayers.Clear();
  1953.                 this.Spamprotection.Reset();
  1954.             }
  1955.         }
  1956.  
  1957.         public override void OnRoundStartPlayerCount(int limit)
  1958.         {
  1959.             this.intRoundStartCount = limit;
  1960.         }
  1961.  
  1962.         public override void OnRoundRestartPlayerCount(int limit)
  1963.         {
  1964.             this.intRoundRestartCount = limit;
  1965.         }
  1966.  
  1967.         #endregion
  1968.  
  1969.         #region External Commands (ColColonCleaner)
  1970.  
  1971.         public void GetStatus(params String[] commands)
  1972.         {
  1973.             this.DebugInfo("Info", "GetStatus starting!");
  1974.             if (commands.Length < 1)
  1975.             {
  1976.                 this.DebugInfo("Error", "Status fetch request canceled, no parameters provided.");
  1977.                 return;
  1978.             }
  1979.  
  1980.             new Thread(new ParameterizedThreadStart(SendStatus)).Start(commands[0]);
  1981.             this.DebugInfo("Info", "GetStatus finished!");
  1982.         }
  1983.  
  1984.         private void SendStatus(Object clientInformation)
  1985.         {
  1986.             this.DebugInfo("Info", "SendStatus starting!");
  1987.             try
  1988.             {
  1989.                 //Set current thread name
  1990.                 Thread.CurrentThread.Name = "SendStatus";
  1991.  
  1992.                 //Parse client plugin information
  1993.                 Hashtable parsedClientInformation = (Hashtable)JSON.JsonDecode((String)clientInformation);
  1994.                 String pluginName = String.Empty;
  1995.                 String pluginMethod = String.Empty;
  1996.                 if (!parsedClientInformation.ContainsKey("pluginName"))
  1997.                 {
  1998.                     this.DebugInfo("Error", "Parsed command didn't contain a pluginName!");
  1999.                     return;
  2000.                 }
  2001.                 else
  2002.                 {
  2003.                     pluginName = (String)parsedClientInformation["pluginName"];
  2004.                 }
  2005.  
  2006.                 if (!parsedClientInformation.ContainsKey("pluginMethod"))
  2007.                 {
  2008.                     this.DebugInfo("Error", "Parsed command didn't contain a pluginMethod!");
  2009.                     return;
  2010.                 }
  2011.                 else
  2012.                 {
  2013.                     pluginMethod = (String)parsedClientInformation["pluginMethod"];
  2014.                 }
  2015.  
  2016.                 //Check for active connection to the database using a simple query
  2017.                 Boolean activeConnection = false;
  2018.                 this.tablebuilder();
  2019.                 if ((m_strHost != null) || (m_strDatabase != null) || (m_strDBPort != null) || (m_strUserName != null) || (m_strPassword != null))
  2020.                 {
  2021.                     try
  2022.                     {
  2023.                         using (MySqlConnection Connection = new MySqlConnection(this.DBConnectionStringBuilder()))
  2024.                         {
  2025.                             Connection.Open();
  2026.                             if (Connection.State == ConnectionState.Open)
  2027.                             {
  2028.                                 string query = "SELECT `ServerID` from `" + this.tbl_server + "` LIMIT 1";
  2029.                                 using (MySqlCommand command = new MySqlCommand(query, Connection))
  2030.                                 {
  2031.                                     DataTable resultTable = this.SQLquery(command);
  2032.                                     if (resultTable.Rows != null)
  2033.                                     {
  2034.                                         activeConnection = true;
  2035.                                     }
  2036.                                 }
  2037.                             }
  2038.                             //Connection automatically closed by end of 'using' clause
  2039.                         }
  2040.                     }
  2041.                     catch (Exception e)
  2042.                     {
  2043.                         this.DebugInfo("Error", "Query could not be performed while sending plugin status.");
  2044.                     }
  2045.                 }
  2046.  
  2047.                 //Create response hashtable
  2048.                 Hashtable response = new Hashtable();
  2049.  
  2050.                 //Add Plugin General Settings
  2051.                 response["pluginVersion"] = this.GetPluginVersion();
  2052.                 response["pluginEnabled"] = this.m_isPluginEnabled.ToString();
  2053.                 //Add Database connection info, without username and password
  2054.                 response["DBHost"] = this.m_strHost;
  2055.                 response["DBPort"] = this.m_strDBPort;
  2056.                 response["DBName"] = this.m_strDatabase;
  2057.                 //Add Database time offset
  2058.                 response["DBTimeOffset"] = this.m_dTimeOffset.ToString();
  2059.                 //Add Whether the connection is active
  2060.                 response["DBConnectionActive"] = activeConnection.ToString();
  2061.                 //Add Specific logging settings
  2062.                 response["ChatloggingEnabled"] = (this.m_enChatloggingON == enumBoolYesNo.Yes).ToString();
  2063.                 response["InstantChatLoggingEnabled"] = (this.m_enInstantChatlogging == enumBoolYesNo.Yes).ToString();
  2064.                 response["StatsLoggingEnabled"] = (this.m_enLogSTATS == enumBoolYesNo.Yes).ToString();
  2065.                 response["DBliveScoreboardEnabled"] = (this.m_enableCurrentPlayerstatsTable == enumBoolYesNo.Yes).ToString();
  2066.                 //Add Plugin Debug Mode
  2067.                 response["DebugMode"] = this.GlobalDebugMode;
  2068.                 //Add Error as "no error"
  2069.                 response["Error"] = false.ToString();
  2070.  
  2071.                 //Encode JSON response
  2072.                 String JSONResponse = JSON.JsonEncode(response);
  2073.  
  2074.                 //Send the response
  2075.                 this.ExecuteCommand("procon.protected.plugins.call", pluginName, pluginMethod, JSONResponse);
  2076.             }
  2077.             catch (Exception e)
  2078.             {
  2079.                 //Log the error in console
  2080.                 this.DebugInfo("Error", e.ToString());
  2081.             }
  2082.  
  2083.             this.DebugInfo("Info", "SendStatus finished!");
  2084.         }
  2085.  
  2086.         #endregion
  2087.  
  2088.         #region In Game Commands
  2089.  
  2090.         public void OnCommandStats(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2091.         {
  2092.             /*
  2093.             this.DebugInfo("Trace", "MatchCommand:" + mtcCommand.Command);
  2094.             this.DebugInfo("Trace", "CapturedCommand:" + capCommand.Command);
  2095.             this.DebugInfo("Trace", "CapturedCommand:" + capCommand.ResposeScope);
  2096.             this.DebugInfo("Trace", "CapturedCommand:" + capCommand.ExtraArguments);
  2097.             */
  2098.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2099.             {                  
  2100.                 string scope = String.Empty;
  2101.                 if (capCommand.ResposeScope.Contains("!") == true)
  2102.                 {
  2103.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2104.                     {
  2105.                         scope = "all";
  2106.                     }
  2107.                     else
  2108.                     {
  2109.                         scope = "player";
  2110.                     }
  2111.                 }
  2112.                 else
  2113.                 {
  2114.                     scope = "player";
  2115.                 }
  2116.  
  2117.                 if (capCommand.ExtraArguments.Length > 0)
  2118.                 {
  2119.                     ThreadPool.QueueUserWorkItem(delegate { this.GetWeaponStats(this.FindKeyword(capCommand.ExtraArguments.Trim().ToUpper()), strSpeaker, scope); });
  2120.                 }
  2121.                 else
  2122.                 {
  2123.                     ThreadPool.QueueUserWorkItem( delegate { this.GetPlayerStats(strSpeaker, 0, scope); });
  2124.                 }
  2125.             }
  2126.         }
  2127.  
  2128.         public void OnCommandTop10(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2129.         {
  2130.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2131.             {
  2132.                 string scope = String.Empty;
  2133.                 if (capCommand.ResposeScope.Contains("!") == true)
  2134.                 {
  2135.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2136.                     {
  2137.                         scope = "all";
  2138.                     }
  2139.                     else
  2140.                     {
  2141.                         scope = "player";
  2142.                     }
  2143.                 }
  2144.                 else
  2145.                 {
  2146.                     scope = "player";
  2147.                 }
  2148.  
  2149.                 if (capCommand.ExtraArguments.Length > 0)
  2150.                 {
  2151.                     ThreadPool.QueueUserWorkItem(delegate { this.GetWeaponTop10(this.FindKeyword(capCommand.ExtraArguments.Trim().ToUpper()), strSpeaker, 2, scope); });
  2152.                 }
  2153.                 else
  2154.                 {
  2155.                     ThreadPool.QueueUserWorkItem( delegate { this.GetTop10(strSpeaker, 2, scope); });
  2156.                 }
  2157.             }
  2158.         }
  2159.  
  2160.         public void OnCommandDogtags(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2161.         {
  2162.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2163.             {
  2164.                 string scope = String.Empty;
  2165.                 if (capCommand.ResposeScope.Contains("!") == true)
  2166.                 {
  2167.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2168.                     {
  2169.                         scope = "all";
  2170.                     }
  2171.                     else
  2172.                     {
  2173.                         scope = "player";
  2174.                     }
  2175.                 }
  2176.                 else
  2177.                 {
  2178.                     scope = "player";
  2179.                 }
  2180.                 ThreadPool.QueueUserWorkItem(delegate { this.GetDogtags(strSpeaker, 1, scope); });
  2181.             }
  2182.         }
  2183.  
  2184.         public void OnCommandSession(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2185.         {
  2186.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2187.             {
  2188.                 string scope = String.Empty;
  2189.                 if (capCommand.ResposeScope.Contains("!") == true)
  2190.                 {
  2191.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2192.                     {
  2193.                         scope = "all";
  2194.                     }
  2195.                     else
  2196.                     {
  2197.                         scope = "player";
  2198.                     }
  2199.                 }
  2200.                 else
  2201.                 {
  2202.                     scope = "player";
  2203.                 }
  2204.                 ThreadPool.QueueUserWorkItem(delegate { this.GetSession(strSpeaker, 1, scope); });
  2205.             }
  2206.         }
  2207.  
  2208.         public void OnCommandServerStats(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2209.         {
  2210.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2211.             {
  2212.                 string scope = String.Empty;
  2213.                 if (capCommand.ResposeScope.Contains("!") == true)
  2214.                 {
  2215.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2216.                     {
  2217.                         scope = "all";
  2218.                     }
  2219.                     else
  2220.                     {
  2221.                         scope = "player";
  2222.                     }
  2223.                 }
  2224.                 else
  2225.                 {
  2226.                     scope = "player";
  2227.                 }
  2228.                 ThreadPool.QueueUserWorkItem(delegate { this.GetServerStats(strSpeaker, 1, scope); });
  2229.             }
  2230.         }
  2231.  
  2232.         public void OnCommandPlayerOfTheDay(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2233.         {
  2234.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2235.             {
  2236.                 string scope = String.Empty;
  2237.                 if (capCommand.ResposeScope.Contains("!") == true)
  2238.                 {
  2239.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2240.                     {
  2241.                         scope = "all";
  2242.                     }
  2243.                     else
  2244.                     {
  2245.                         scope = "player";
  2246.                     }
  2247.                 }
  2248.                 else
  2249.                 {
  2250.                     scope = "player";
  2251.                 }
  2252.                 ThreadPool.QueueUserWorkItem(delegate { this.GetPlayerOfTheDay(strSpeaker, 1, scope); });
  2253.             }
  2254.         }
  2255.  
  2256.         public void OnCommandTop10ForPeriod(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  2257.         {
  2258.             if ((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  2259.             {
  2260.                 string scope = String.Empty;
  2261.                 if (capCommand.ResposeScope.Contains("!") == true)
  2262.                 {
  2263.                     if (this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  2264.                     {
  2265.                         scope = "all";
  2266.                     }
  2267.                     else
  2268.                     {
  2269.                         scope = "player";
  2270.                     }
  2271.                 }
  2272.                 else
  2273.                 {
  2274.                     scope = "player";
  2275.                 }
  2276.                 ThreadPool.QueueUserWorkItem(delegate { this.GetTop10ForPeriod(strSpeaker, 2, scope, this.m_intDaysForPeriodTop10); });
  2277.             }
  2278.         }
  2279.  
  2280.         #endregion
  2281.  
  2282.         #region CChatGUIDStatsLogger Methodes
  2283.  
  2284.         private string DBConnectionStringBuilder()
  2285.         {
  2286.             string conString = String.Empty;
  2287.             lock (this.ConnectionStringBuilderlock)
  2288.             {
  2289.                 uint uintport = 3306;
  2290.                 uint.TryParse(m_strDBPort, out uintport);
  2291.                 myCSB.Port = uintport;
  2292.                 myCSB.Server = m_strHost;
  2293.                 myCSB.UserID = m_strUserName;
  2294.                 myCSB.Password = m_strPassword;
  2295.                 myCSB.Database = m_strDatabase;
  2296.                 //Connection Pool
  2297.                 if (this.m_connectionPooling == enumBoolOnOff.On)
  2298.                 {
  2299.                     myCSB.Pooling = true;
  2300.                     myCSB.MinimumPoolSize = Convert.ToUInt32(this.m_minPoolSize);
  2301.                     myCSB.MaximumPoolSize = Convert.ToUInt32(this.m_maxPoolSize);
  2302.                     myCSB.ConnectionLifeTime = 600;
  2303.                 }
  2304.                 else
  2305.                 {
  2306.                     myCSB.Pooling = false;
  2307.                 }
  2308.                 //Compression
  2309.                 if (this.m_Connectioncompression == enumBoolOnOff.On)
  2310.                 {
  2311.                     myCSB.UseCompression = true;
  2312.                 }
  2313.                 else
  2314.                 {
  2315.                     myCSB.UseCompression = false;
  2316.                 }
  2317.                 myCSB.AllowUserVariables = true;
  2318.                 myCSB.DefaultCommandTimeout = 3600;
  2319.                 myCSB.ConnectionTimeout = 50;
  2320.                 conString = myCSB.ConnectionString;
  2321.             }
  2322.             return conString;
  2323.         }
  2324.  
  2325.         private int GetPlayerTeamID(string strSoldierName)
  2326.         {
  2327.             int iTeamID = 0; // Neutral Team ID
  2328.             if (this.m_dicPlayers.ContainsKey(strSoldierName) == true)
  2329.             {
  2330.                 iTeamID = this.m_dicPlayers[strSoldierName].TeamID;
  2331.             }
  2332.             return iTeamID;
  2333.         }
  2334.  
  2335.         private void playerLeftServer(CPlayerInfo cpiPlayer)
  2336.         {
  2337.             try
  2338.             {
  2339.                 this.DebugInfo("Trace", "playerLeftServer: " + cpiPlayer.SoldierName + " EAGUID: " + cpiPlayer.GUID);
  2340.                 if (this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  2341.                 {
  2342.                     this.StatsTracker[cpiPlayer.SoldierName].Score = cpiPlayer.Score;
  2343.                     this.StatsTracker[cpiPlayer.SoldierName].TimePlayerleft = MyDateTime.Now;
  2344.                     this.StatsTracker[cpiPlayer.SoldierName].playerleft();
  2345.                     //EA-GUID, ClanTag, usw.
  2346.                     if (cpiPlayer.GUID.Length > 2)
  2347.                     {
  2348.                         this.StatsTracker[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;  
  2349.                     }
  2350.                     //ID cache System
  2351.                     if (this.StatsTracker[cpiPlayer.SoldierName].EAGuid.Length > 2)
  2352.                     {
  2353.                         if (this.m_ID_cache.ContainsKey(this.StatsTracker[cpiPlayer.SoldierName].EAGuid) == true)
  2354.                         {
  2355.                             this.m_ID_cache[this.StatsTracker[cpiPlayer.SoldierName].EAGuid].PlayeronServer = false;
  2356.                         }
  2357.                     }
  2358.                     this.StatsTracker[cpiPlayer.SoldierName].ClanTag = cpiPlayer.ClanTag;
  2359.                 }
  2360.                 //Mapstats
  2361.                 this.Mapstats.IntplayerleftServer++;
  2362.                 //Session
  2363.                 if (this.m_dicSession.ContainsKey(cpiPlayer.SoldierName) == true)
  2364.                 {
  2365.                     if (cpiPlayer.Score > 0)
  2366.                     {
  2367.                         this.m_dicSession[cpiPlayer.SoldierName].AddScore(cpiPlayer.Score);
  2368.                     }
  2369.                     this.m_dicSession[cpiPlayer.SoldierName].TimePlayerleft = MyDateTime.Now;
  2370.                     this.m_dicSession[cpiPlayer.SoldierName].playerleft();
  2371.                     this.DebugInfo("Trace", "Score: " + this.m_dicSession[cpiPlayer.SoldierName].TotalScore.ToString() + " Playtime: " + this.m_dicSession[cpiPlayer.SoldierName].TotalPlaytime.ToString());
  2372.                     if (this.m_dicSession[cpiPlayer.SoldierName].TotalScore > 10 || this.m_dicSession[cpiPlayer.SoldierName].Kills > 0 || this.m_dicSession[cpiPlayer.SoldierName].Deaths > 0)
  2373.                     {
  2374.                         if ((this.m_dicSession[cpiPlayer.SoldierName].EAGuid.Length < 2) && (this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true))
  2375.                         {
  2376.                             if (this.StatsTracker[cpiPlayer.SoldierName].EAGuid.Length > 2)
  2377.                             {
  2378.                                 this.m_dicSession[cpiPlayer.SoldierName].EAGuid = this.StatsTracker[cpiPlayer.SoldierName].EAGuid;
  2379.                             }
  2380.                         }
  2381.                         this.DebugInfo("Trace", "Adding Session of Player " + cpiPlayer.SoldierName + " to passed sessions");
  2382.                         //Adding passed session to list if player has a Score greater than 0 or a Player greater than 120 sec
  2383.                         this.lstpassedSessions.Add(this.m_dicSession[cpiPlayer.SoldierName]);
  2384.                     }
  2385.                     //Removing old session
  2386.                     lock (this.sessionlock)
  2387.                     {
  2388.                         this.m_dicSession.Remove(cpiPlayer.SoldierName);
  2389.                     }
  2390.                 }
  2391.                 else
  2392.                 {
  2393.                     this.DebugInfo("Trace", "playerLeftServer: " + cpiPlayer.SoldierName + " not in session dic");
  2394.                 }
  2395.             }
  2396.             catch (Exception c)
  2397.             {
  2398.                 this.DebugInfo("Error", "playerLeftServer:" + c);
  2399.             }
  2400.         }
  2401.  
  2402.         private void playerKilled(Kill kKillerVictimDetails)
  2403.         {
  2404.             if (this.DamageClass.ContainsKey(kKillerVictimDetails.DamageType) == false && !kKillerVictimDetails.DamageType.Equals("Death"))
  2405.             {
  2406.                 this.DebugInfo("Trace", "Weapon: " + kKillerVictimDetails.DamageType + " is missing in the " + this.strServerGameType +".def file!!!");
  2407.             }
  2408.             //this.DebugInfo("Trace","PlayerKilled Killer: "+ kKillerVictimDetails.Killer.SoldierName + "Victim: " + kKillerVictimDetails.Victim.SoldierName + "Weapon: " + kKillerVictimDetails.DamageType);
  2409.             //TEAMKILL OR SUICID
  2410.             if (String.Compare(kKillerVictimDetails.Killer.SoldierName, kKillerVictimDetails.Victim.SoldierName) == 0)
  2411.             {       //  A Suicide
  2412.                 this.AddSuicideToStats(kKillerVictimDetails.Killer.SoldierName, this.DamageClass[kKillerVictimDetails.DamageType], kKillerVictimDetails.DamageType);
  2413.             }
  2414.             else
  2415.             {
  2416.                 if (this.GetPlayerTeamID(kKillerVictimDetails.Killer.SoldierName) == this.GetPlayerTeamID(kKillerVictimDetails.Victim.SoldierName))
  2417.                 {   //TeamKill
  2418.                     this.AddTeamKillToStats(kKillerVictimDetails.Killer.SoldierName);
  2419.                     this.AddDeathToStats(kKillerVictimDetails.Victim.SoldierName, this.DamageClass[kKillerVictimDetails.DamageType], kKillerVictimDetails.DamageType);
  2420.                 }
  2421.                 else
  2422.                 {
  2423.                     //this.DebugInfo("Trace","PlayerKilled: Regular Kill");
  2424.                     //Regular Kill: Player killed an Enemy
  2425.                     this.AddKillToStats(kKillerVictimDetails.Killer.SoldierName, this.DamageClass[kKillerVictimDetails.DamageType], kKillerVictimDetails.DamageType, kKillerVictimDetails.Headshot);
  2426.                     this.AddDeathToStats(kKillerVictimDetails.Victim.SoldierName, this.DamageClass[kKillerVictimDetails.DamageType], kKillerVictimDetails.DamageType);
  2427.                     if (string.Equals(kKillerVictimDetails.DamageType, "Melee"))
  2428.                     {   //Dogtagstracking
  2429.                         CKillerVictim KnifeKill = new CKillerVictim(kKillerVictimDetails.Killer.SoldierName, kKillerVictimDetails.Victim.SoldierName);
  2430.                         if (m_dicKnifeKills.ContainsKey(KnifeKill) == true)
  2431.                         {
  2432.                             m_dicKnifeKills[KnifeKill]++;
  2433.                         }
  2434.                         else
  2435.                         {
  2436.                             m_dicKnifeKills.Add(KnifeKill, 1);
  2437.                         }
  2438.                     }
  2439.                 }
  2440.             }
  2441.         }
  2442.  
  2443.         private DataTable SQLquery(MySqlCommand selectQuery)
  2444.         {
  2445.             DataTable MyDataTable = new DataTable();
  2446.             try
  2447.             {
  2448.                 this.tablebuilder();
  2449.                 //this.DebugInfo("Trace", "SQLquery: " + selectQuery);                
  2450.                 if (selectQuery == null)
  2451.                 {
  2452.                     this.DebugInfo("Warning", "SQLquery: selectQuery is null");
  2453.                     return MyDataTable;
  2454.                 }
  2455.                 else if (selectQuery.CommandText.Equals(String.Empty) == true)
  2456.                 {
  2457.                     this.DebugInfo("Warning", "SQLquery: CommandText is empty");
  2458.                     return MyDataTable;
  2459.                 }
  2460.  
  2461.                 if (this.m_highPerformanceConnectionMode == enumBoolOnOff.On)
  2462.                 {
  2463.                     try
  2464.                     {
  2465.                         using (MySqlConnection Connection = new MySqlConnection(this.DBConnectionStringBuilder()))
  2466.                         {
  2467.                             selectQuery.Connection = Connection;
  2468.                             using (MySqlDataAdapter MyAdapter = new MySqlDataAdapter(selectQuery))
  2469.                             {
  2470.                                 if (MyAdapter != null)
  2471.                                 {
  2472.                                     MyAdapter.Fill(MyDataTable);
  2473.                                 }
  2474.                                 else
  2475.                                 {
  2476.                                     this.DebugInfo("Warning", "SQLquery: MyAdapter is null");
  2477.                                 }
  2478.                             }
  2479.                             Connection.Close();
  2480.                         }
  2481.                     }
  2482.                     catch (MySqlException me)
  2483.                     {
  2484.                         this.DebugInfo("Error", "SQLQuery:");
  2485.                         this.DisplayMySqlErrorCollection(me);
  2486.                     }
  2487.                     catch (Exception c)
  2488.                     {
  2489.                         this.DebugInfo("Error", "SQLQuery:" + c);
  2490.                     }
  2491.                 }
  2492.                 else
  2493.                 {
  2494.                     lock (this.sqlquerylock)
  2495.                     {
  2496.                         if (this.MySqlCon == null)
  2497.                         {
  2498.                             this.MySqlCon = new MySqlConnection(this.DBConnectionStringBuilder());
  2499.                         }
  2500.                         try
  2501.                         {
  2502.                             selectQuery.Connection = this.MySqlCon;
  2503.                             using (MySqlDataAdapter MyAdapter = new MySqlDataAdapter(selectQuery))
  2504.                             {
  2505.                                 if (MyAdapter != null)
  2506.                                 {
  2507.                                     MyAdapter.Fill(MyDataTable);
  2508.                                 }
  2509.                                 else
  2510.                                 {
  2511.                                     this.DebugInfo("Warning", "SQLquery: MyAdapter is null");
  2512.                                 }
  2513.                             }
  2514.                         }
  2515.                         catch (MySqlException oe)
  2516.                         {
  2517.                             this.DebugInfo("Error", "SQLQuery:");
  2518.                             this.DisplayMySqlErrorCollection(oe);
  2519.                             if (MySqlCon.State == ConnectionState.Open)
  2520.                             {
  2521.                                 MySqlCon.Close();
  2522.                                 MySqlCon = null;
  2523.                             }
  2524.                         }
  2525.                         catch (Exception c)
  2526.                         {
  2527.                             this.DebugInfo("Error", "SQLQuery:" + c);
  2528.                             if (MySqlCon.State == ConnectionState.Open)
  2529.                             {
  2530.                                 MySqlCon.Close();
  2531.                                 MySqlCon = null;
  2532.                             }
  2533.                         }
  2534.                         finally
  2535.                         {
  2536.                             try
  2537.                             {
  2538.                                 this.MySqlCon.Close();
  2539.                             }
  2540.                             catch
  2541.                             {
  2542.                                 this.MySqlCon = null;
  2543.                             }
  2544.                         }
  2545.                     }
  2546.                 }
  2547.             }
  2548.             catch (Exception c)
  2549.             {
  2550.                 this.DebugInfo("Error", "SQLQuery OuterException:" + c);
  2551.             }
  2552.             return MyDataTable;
  2553.         }
  2554.  
  2555.         // Updates database with player stats and chatlogs
  2556.         private void StartStreaming()
  2557.         {
  2558.             lock (this.streamlock)
  2559.             {
  2560.                 bool success = false;
  2561.                 int attemptCount = 0;
  2562.                 try
  2563.                 {
  2564.                     DateTime StartStreamingTime = MyDateTime.Now;
  2565.                     //Make a copy of Statstracker to prevent unwanted errors
  2566.                     Dictionary<string, CStats> StatsTrackerCopy = new Dictionary<string, CStats>(this.StatsTracker);
  2567.                     //C_ID_Cache id_cache;
  2568.                     List<string> lstEAGUIDs = new List<string>();
  2569.                     //Clearing the old Dictionary
  2570.                     StatsTracker.Clear();
  2571.                     if (isStreaming)
  2572.                     {
  2573.                         this.DebugInfo("Info", "Started streaming to the DB-Server");
  2574.                         // Uploads chat logs and Stats for round to database
  2575.                         if (ChatLog.Count > 0 || this.m_enLogSTATS == enumBoolYesNo.Yes)
  2576.                         {
  2577.                             this.tablebuilder(); //Build the tables if not exists
  2578.                             if ((m_strHost != null) && (m_strDatabase != null) && (m_strDBPort != null) && (m_strUserName != null) && (m_strPassword != null))
  2579.                             {
  2580.                                 try
  2581.                                 {
  2582.                                     this.OpenMySqlConnection(2);
  2583.                                     this.MySql_Connection_is_activ = true;
  2584.  
  2585.                                     if (ChatLog.Count > 0 && MySqlConn.State == ConnectionState.Open)
  2586.                                     {
  2587.                                         string ChatSQL = @"INSERT INTO " + this.tbl_chatlog + @" (logDate, ServerID, logSubset, logSoldierName, logMessage) VALUES ";
  2588.                                         lock (ChatLog)
  2589.                                         {
  2590.                                             int i = 0;
  2591.                                             foreach (CLogger log in ChatLog)
  2592.                                             {
  2593.                                                 ChatSQL = string.Concat(ChatSQL, "(@logDate" + i + ", @ServerID" + i + ", @logSubset" + i + ", @logSoldierName" + i + ", @logMessage" + i + "),");
  2594.                                                 i++;
  2595.                                             }
  2596.                                             ChatSQL = ChatSQL.Remove(ChatSQL.LastIndexOf(","));
  2597.                                             using (MySqlCommand OdbcCom = new MySqlCommand(ChatSQL, MySqlConn))
  2598.                                             {
  2599.                                                 i = 0;
  2600.                                                 foreach (CLogger log in ChatLog)
  2601.                                                 {
  2602.                                                     OdbcCom.Parameters.AddWithValue("@logDate" + i, log.Time);
  2603.                                                     OdbcCom.Parameters.AddWithValue("@ServerID" + i, this.ServerID);
  2604.                                                     OdbcCom.Parameters.AddWithValue("@logSubset" + i, log.Subset);
  2605.                                                     OdbcCom.Parameters.AddWithValue("@logSoldierName" + i, log.Name);
  2606.                                                     OdbcCom.Parameters.AddWithValue("@logMessage" + i, log.Message);
  2607.                                                     i++;
  2608.                                                 }
  2609.                                                 OdbcCom.ExecuteNonQuery();
  2610.                                             }
  2611.                                             ChatLog.Clear();
  2612.                                         }
  2613.                                     }
  2614.                                     if (this.m_mapstatsON == enumBoolYesNo.Yes && MySqlConn.State == ConnectionState.Open)
  2615.                                     {
  2616.                                         this.DebugInfo("Trace", "Mapstats Write querys");
  2617.                                         this.Mapstats.calcMaxMinAvgPlayers();
  2618.                                         string MapSQL = @"INSERT INTO " + tbl_mapstats + @" (ServerID, TimeMapLoad, TimeRoundStarted, TimeRoundEnd, MapName, Gamemode, Roundcount, NumberofRounds, MinPlayers, AvgPlayers, MaxPlayers, PlayersJoinedServer, PlayersLeftServer)
  2619.                                                     VALUES (@ServerID, @TimeMapLoad, @TimeRoundStarted, @TimeRoundEnd, @MapName, @Gamemode, @Roundcount, @NumberofRounds, @MinPlayers, @AvgPlayers, @MaxPlayers, @PlayersJoinedServer, @PlayersLeftServer)";
  2620.                                         using (MySqlCommand OdbcCom = new MySqlCommand(MapSQL, MySqlConn))
  2621.                                         {
  2622.                                             OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  2623.                                             OdbcCom.Parameters.AddWithValue("@TimeMapLoad", this.Mapstats.TimeMaploaded);
  2624.                                             OdbcCom.Parameters.AddWithValue("@TimeRoundStarted", this.Mapstats.TimeMapStarted);
  2625.                                             OdbcCom.Parameters.AddWithValue("@TimeRoundEnd", this.Mapstats.TimeRoundEnd);
  2626.                                             OdbcCom.Parameters.AddWithValue("@MapName", this.Mapstats.StrMapname);
  2627.                                             OdbcCom.Parameters.AddWithValue("@Gamemode", this.Mapstats.StrGamemode);
  2628.                                             OdbcCom.Parameters.AddWithValue("@Roundcount", this.Mapstats.IntRound);
  2629.                                             OdbcCom.Parameters.AddWithValue("@NumberofRounds", this.Mapstats.IntNumberOfRounds);
  2630.                                             OdbcCom.Parameters.AddWithValue("@MinPlayers", this.Mapstats.IntMinPlayers);
  2631.                                             OdbcCom.Parameters.AddWithValue("@AvgPlayers", this.Mapstats.DoubleAvgPlayers);
  2632.                                             OdbcCom.Parameters.AddWithValue("@MaxPlayers", this.Mapstats.IntMaxPlayers);
  2633.                                             OdbcCom.Parameters.AddWithValue("@PlayersJoinedServer", this.Mapstats.IntplayerjoinedServer);
  2634.                                             OdbcCom.Parameters.AddWithValue("@PlayersLeftServer", this.Mapstats.IntplayerleftServer);
  2635.                                             OdbcCom.ExecuteNonQuery();
  2636.                                         }
  2637.                                     }
  2638.                                     if (this.m_enLogSTATS == enumBoolYesNo.Yes && MySqlConn.State == ConnectionState.Open)
  2639.                                     {
  2640.                                         this.DebugInfo("Trace", "PlayerStats Write querys");
  2641.                                         //Prepare EAGUID List
  2642.                                         foreach (KeyValuePair<string, CStats> kvp in StatsTrackerCopy)
  2643.                                         {
  2644.                                             if (kvp.Value.EAGuid.Length > 1)
  2645.                                             {
  2646.                                                 if (GlobalDebugMode.Equals("Trace"))
  2647.                                                 {
  2648.                                                     this.DebugInfo("Trace", "Adding EAGUID " + kvp.Value.EAGuid + " to searchlist");
  2649.                                                 }
  2650.                                                 lstEAGUIDs.Add(kvp.Value.EAGuid);
  2651.                                             }
  2652.                                         }
  2653.                                         //Perform Cache Update
  2654.                                         this.UpdateIDCache(lstEAGUIDs);
  2655.  
  2656.                                         while (!success)
  2657.                                         {
  2658.                                             attemptCount++;
  2659.                                             try
  2660.                                             {
  2661.                                                 MySqlTrans = MySqlConn.BeginTransaction();
  2662.                                                 foreach (KeyValuePair<string, CStats> kvp in StatsTrackerCopy)
  2663.                                                 {
  2664.                                                     if (kvp.Key.Length > 0 && kvp.Value.EAGuid.Length > 1)
  2665.                                                     {
  2666.                                                         if (this.m_ID_cache.ContainsKey(kvp.Value.EAGuid) == false)
  2667.                                                         {
  2668.                                                             if (GlobalDebugMode.Equals("Trace"))
  2669.                                                             {
  2670.                                                                 this.DebugInfo("Trace", kvp.Value.EAGuid + " is not in Cache!");
  2671.                                                             }
  2672.                                                             continue;
  2673.                                                         }
  2674.                                                         if (this.m_ID_cache[kvp.Value.EAGuid].Id >= 1)
  2675.                                                         {
  2676.                                                             string UpdatedataSQL = @"UPDATE " + this.tbl_playerdata + @" SET SoldierName = @SoldierName, ClanTag = @ClanTag, PBGUID = @PBGUID, IP_Address = @IP_Address, CountryCode = @CountryCode, GlobalRank = @GlobalRank  WHERE PlayerID = @PlayerID";
  2677.                                                             using (MySqlCommand OdbcCom = new MySqlCommand(UpdatedataSQL, MySqlConn, MySqlTrans))
  2678.                                                             {
  2679.                                                                 //Update
  2680.                                                                 if (GlobalDebugMode.Equals("Trace"))
  2681.                                                                 {
  2682.                                                                     this.DebugInfo("Trace", "Update for Player " + kvp.Key);
  2683.                                                                     this.DebugInfo("Trace", "ClanTag " + kvp.Value.ClanTag);
  2684.                                                                     this.DebugInfo("Trace", "SoldierName " + kvp.Key);
  2685.                                                                     this.DebugInfo("Trace", "PBGUID " + kvp.Value.Guid);
  2686.                                                                     this.DebugInfo("Trace", "EAGUID " + kvp.Value.EAGuid);
  2687.                                                                     this.DebugInfo("Trace", "IP_Address " + kvp.Value.IP);
  2688.                                                                     this.DebugInfo("Trace", "CountryCode " + kvp.Value.PlayerCountryCode);
  2689.                                                                     this.DebugInfo("Trace", "GlobalRank " + kvp.Value.GlobalRank);
  2690.                                                                 }
  2691.                                                                 //OdbcCom.Parameters.AddWithValue("@pr", kvp.Value.ClanTag);
  2692.                                                                 OdbcCom.Parameters.AddWithValue("@SoldierName", kvp.Key);
  2693.                                                                 if (kvp.Value.ClanTag != null)
  2694.                                                                 {
  2695.                                                                     if (kvp.Value.ClanTag.Length > 0)
  2696.                                                                     {
  2697.                                                                         OdbcCom.Parameters.AddWithValue("@ClanTag", kvp.Value.ClanTag);
  2698.                                                                     }
  2699.                                                                     else
  2700.                                                                     {
  2701.                                                                         OdbcCom.Parameters.AddWithValue("@ClanTag", Convert.DBNull);
  2702.                                                                     }
  2703.                                                                 }
  2704.                                                                 else
  2705.                                                                 {
  2706.                                                                     OdbcCom.Parameters.AddWithValue("@ClanTag", Convert.DBNull);
  2707.                                                                 }
  2708.                                                                 OdbcCom.Parameters.AddWithValue("@PBGUID", kvp.Value.Guid);
  2709.                                                                 OdbcCom.Parameters.AddWithValue("@IP_Address", kvp.Value.IP);
  2710.                                                                 OdbcCom.Parameters.AddWithValue("@CountryCode", kvp.Value.PlayerCountryCode);
  2711.                                                                 OdbcCom.Parameters.AddWithValue("@PlayerID", this.m_ID_cache[kvp.Value.EAGuid].Id);
  2712.                                                                 OdbcCom.Parameters.AddWithValue("@GlobalRank", kvp.Value.GlobalRank);
  2713.                                                                 OdbcCom.ExecuteNonQuery();
  2714.                                                             }
  2715.                                                         }
  2716.                                                         else if (this.m_ID_cache[kvp.Value.EAGuid].Id <= 0)
  2717.                                                         {
  2718.                                                             string InsertdataSQL = @"INSERT INTO " + this.tbl_playerdata + @" (ClanTag, SoldierName, PBGUID, GameID, EAGUID, IP_Address, CountryCode, GlobalRank) VALUES(@ClanTag, @SoldierName, @PBGUID, @GameID, @EAGUID, @IP_Address, @CountryCode, @GlobalRank)";
  2719.                                                             using (MySqlCommand OdbcCom = new MySqlCommand(InsertdataSQL, MySqlConn, MySqlTrans))
  2720.                                                             {
  2721.                                                                 //Insert
  2722.                                                                 if (GlobalDebugMode.Equals("Trace"))
  2723.                                                                 {
  2724.                                                                     this.DebugInfo("Trace", "Insert for Player " + kvp.Key);
  2725.                                                                     this.DebugInfo("Trace", "ClanTag " + kvp.Value.ClanTag);
  2726.                                                                     this.DebugInfo("Trace", "SoldierName " + kvp.Key);
  2727.                                                                     this.DebugInfo("Trace", "PBGUID " + kvp.Value.Guid);
  2728.                                                                     this.DebugInfo("Trace", "EAGUID " + kvp.Value.EAGuid);
  2729.                                                                     this.DebugInfo("Trace", "IP_Address " + kvp.Value.IP);
  2730.                                                                     this.DebugInfo("Trace", "CountryCode " + kvp.Value.PlayerCountryCode);
  2731.                                                                     this.DebugInfo("Trace", "GlobalRank " + kvp.Value.GlobalRank);
  2732.                                                                 }
  2733.                                                                 if (kvp.Value.ClanTag != null)
  2734.                                                                 {
  2735.                                                                     if (kvp.Value.ClanTag.Length > 0)
  2736.                                                                     {
  2737.                                                                         OdbcCom.Parameters.AddWithValue("@ClanTag", kvp.Value.ClanTag);
  2738.                                                                     }
  2739.                                                                     else
  2740.                                                                     {
  2741.                                                                         OdbcCom.Parameters.AddWithValue("@ClanTag", Convert.DBNull);
  2742.                                                                     }
  2743.                                                                 }
  2744.                                                                 else
  2745.                                                                 {
  2746.                                                                     OdbcCom.Parameters.AddWithValue("@ClanTag", Convert.DBNull);
  2747.                                                                 }
  2748.                                                                 OdbcCom.Parameters.AddWithValue("@SoldierName", kvp.Key);
  2749.                                                                 OdbcCom.Parameters.AddWithValue("@PBGUID", kvp.Value.Guid);
  2750.                                                                 OdbcCom.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  2751.                                                                 OdbcCom.Parameters.AddWithValue("@EAGUID", kvp.Value.EAGuid);
  2752.                                                                 OdbcCom.Parameters.AddWithValue("@IP_Address", kvp.Value.IP);
  2753.                                                                 OdbcCom.Parameters.AddWithValue("@CountryCode", kvp.Value.PlayerCountryCode);
  2754.                                                                 OdbcCom.Parameters.AddWithValue("@GlobalRank", kvp.Value.GlobalRank);
  2755.                                                                 OdbcCom.ExecuteNonQuery();
  2756.                                                             }
  2757.                                                         }
  2758.                                                     }
  2759.                                                 }
  2760.                                                 MySqlTrans.Commit();
  2761.                                                 success = true;
  2762.                                             }
  2763.                                             catch (MySqlException ex)
  2764.                                             {
  2765.                                                 switch (ex.Number)
  2766.                                                 {
  2767.                                                     case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  2768.                                                     case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  2769.                                                         if (attemptCount < this.TransactionRetryCount)
  2770.                                                         {
  2771.                                                             this.DebugInfo("Warning", "Warning in StartStreaming: Locktimeout or Deadlock occured restarting Transaction(Playerdata). Attempt: " + attemptCount);
  2772.                                                             try
  2773.                                                             {
  2774.                                                                 MySqlTrans.Rollback();
  2775.                                                             }
  2776.                                                             catch { }
  2777.                                                             Thread.Sleep(attemptCount * 1000);
  2778.                                                         }
  2779.                                                         else
  2780.                                                         {
  2781.                                                             this.DebugInfo("Error", "Error in StartStreaming: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction Playerdata)");
  2782.                                                             throw;
  2783.                                                         }
  2784.                                                         break;
  2785.                                                     default:
  2786.                                                         throw; //Other exceptions
  2787.                                                 }
  2788.                                             }
  2789.                                         }
  2790.                                         //Reset bool and counter
  2791.                                         attemptCount = 0;
  2792.                                         success = false;
  2793.  
  2794.                                         //tbl_server_player
  2795.  
  2796.                                         this.DebugInfo("Trace", "tbl_server_player Write querys");
  2797.                                         this.UpdateIDCache(lstEAGUIDs);
  2798.                                         while (!success)
  2799.                                         {
  2800.                                             attemptCount++;
  2801.                                             try
  2802.                                             {
  2803.                                                 //Start of the Transaction
  2804.                                                 MySqlTrans = MySqlConn.BeginTransaction();
  2805.                                                 foreach (KeyValuePair<string, CStats> kvp in StatsTrackerCopy)
  2806.                                                 {
  2807.                                                     if (kvp.Value.EAGuid.Length > 0)
  2808.                                                     {
  2809.                                                         if (this.m_ID_cache.ContainsKey(kvp.Value.EAGuid) == false)
  2810.                                                         {
  2811.                                                             this.DebugInfo("Trace", kvp.Value.EAGuid + " is not in Cache!");
  2812.                                                             continue;
  2813.                                                         }
  2814.                                                         if (GlobalDebugMode.Equals("Trace"))
  2815.                                                         {
  2816.                                                             this.DebugInfo("Trace", "PlayerID: " + this.m_ID_cache[kvp.Value.EAGuid].Id);
  2817.                                                             this.DebugInfo("Trace", "StatsID: " + this.m_ID_cache[kvp.Value.EAGuid].StatsID);
  2818.                                                         }
  2819.                                                         if (this.m_ID_cache[kvp.Value.EAGuid].Id > 0 && this.m_ID_cache[kvp.Value.EAGuid].StatsID == 0)
  2820.                                                         {
  2821.                                                             string InsertdataSQL = @"INSERT INTO " + this.tbl_server_player + @" (ServerID, PlayerID) VALUES(@ServerID, @PlayerID)";
  2822.                                                             using (MySqlCommand OdbcCom = new MySqlCommand(InsertdataSQL, MySqlConn, MySqlTrans))
  2823.                                                             {
  2824.                                                                 //Insert
  2825.                                                                 this.DebugInfo("Trace", "Insert PlayerID " + this.m_ID_cache[kvp.Value.EAGuid].Id + "into tbl_server_player");
  2826.                                                                 OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  2827.                                                                 OdbcCom.Parameters.AddWithValue("@PlayerID", this.m_ID_cache[kvp.Value.EAGuid].Id);
  2828.                                                                 OdbcCom.ExecuteNonQuery();
  2829.                                                             }
  2830.                                                         }
  2831.                                                     }
  2832.                                                 }
  2833.                                                 MySqlTrans.Commit();
  2834.                                                 success = true;
  2835.                                             }
  2836.                                             catch (MySqlException ex)
  2837.                                             {
  2838.                                                 switch (ex.Number)
  2839.                                                 {
  2840.                                                     case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  2841.                                                     case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  2842.                                                         if (attemptCount < this.TransactionRetryCount)
  2843.                                                         {
  2844.                                                             this.DebugInfo("Warning", "Warning in StartStreaming: Locktimeout or Deadlock occured restarting Transaction(server_player). Attempt: " + attemptCount);
  2845.                                                             try
  2846.                                                             {
  2847.                                                                 MySqlTrans.Rollback();
  2848.                                                             }
  2849.                                                             catch { }
  2850.                                                             Thread.Sleep(attemptCount * 1000);
  2851.                                                         }
  2852.                                                         else
  2853.                                                         {
  2854.                                                             this.DebugInfo("Error", "Error in StartStreaming: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction server_player)");
  2855.                                                             throw;
  2856.                                                         }
  2857.                                                         break;
  2858.                                                     default:
  2859.                                                         throw; //Other exceptions
  2860.                                                 }
  2861.                                             }
  2862.                                         }
  2863.                                         //Reset bool and counter
  2864.                                         attemptCount = 0;
  2865.                                         success = false;
  2866.  
  2867.                                         this.DebugInfo("Trace", "Combatstats Write querys");
  2868.                                         //Perform Cache Update
  2869.                                         this.UpdateIDCache(lstEAGUIDs);
  2870.                                         if (this.m_enLogPlayerDataOnly == enumBoolYesNo.No)
  2871.                                         {
  2872.                                             while (!success)
  2873.                                             {
  2874.                                                 attemptCount++;
  2875.                                                 try
  2876.                                                 {
  2877.                                                     //Start of the Transaction
  2878.                                                     MySqlTrans = MySqlConn.BeginTransaction();
  2879.  
  2880.                                                     foreach (KeyValuePair<string, CStats> kvp in StatsTrackerCopy)
  2881.                                                     {
  2882.                                                         if (this.m_ID_cache.ContainsKey(kvp.Value.EAGuid) == false)
  2883.                                                         {
  2884.                                                             if (GlobalDebugMode.Equals("Trace"))
  2885.                                                             {
  2886.                                                                 this.DebugInfo("Trace", kvp.Value.EAGuid + " is not in Cache!(empty GUID?)");
  2887.                                                             }
  2888.                                                             continue;
  2889.                                                         }
  2890.                                                         Dictionary<string, Dictionary<string, CStats.CUsedWeapon>> tempdic;
  2891.                                                         //tempdic = StatsTrackerCopy[kvp.Key].getWeaponKills();
  2892.                                                         tempdic = new Dictionary<string, Dictionary<string, CStats.CUsedWeapon>>(kvp.Value.getWeaponKills());
  2893.                                                         if (GlobalDebugMode.Equals("Trace"))
  2894.                                                         {
  2895.                                                             this.DebugInfo("Trace", "PlayerID: " + this.m_ID_cache[kvp.Value.EAGuid].Id);
  2896.                                                             this.DebugInfo("Trace", "StatsID: " + this.m_ID_cache[kvp.Value.EAGuid].StatsID);
  2897.                                                         }
  2898.  
  2899.                                                         if (kvp.Key.Length > 0 && StatsTrackerCopy[kvp.Key].Guid.Length > 0 && this.m_ID_cache[kvp.Value.EAGuid].StatsID >= 1)
  2900.                                                         {
  2901.                                                             string playerstatsSQL = @"INSERT INTO " + this.tbl_playerstats + @"(StatsID, Score, Kills, Headshots, Deaths, Suicide, TKs, Playtime, Rounds, FirstSeenOnServer, LastSeenOnServer, Killstreak, Deathstreak, HighScore , Wins, Losses)
  2902.                                                                 VALUES(@StatsID, @Score, @Kills, @Headshots, @Deaths, @Suicide, @TKs, @Playtime, @Rounds, @FirstSeenOnServer, @LastSeenOnServer, @Killstreak, @Deathstreak, @HighScore , @Wins, @Losses)
  2903.                                                                ON DUPLICATE KEY UPDATE Score = Score + @Score, Kills = Kills + @Kills,Headshots = Headshots + @Headshots, Deaths = Deaths + @Deaths, Suicide = Suicide + @Suicide, TKs = TKs + @TKs, Playtime = Playtime + @Playtime, Rounds = Rounds + @Rounds, LastSeenOnServer = @LastSeenOnServer, Killstreak = GREATEST(Killstreak,@Killstreak),Deathstreak = GREATEST(Deathstreak, @Deathstreak) ,HighScore = GREATEST(HighScore, @HighScore), Wins = Wins + @Wins, Losses = Losses + @Losses ";
  2904.  
  2905.                                                             using (MySqlCommand OdbcCom = new MySqlCommand(playerstatsSQL, MySqlConn, MySqlTrans))
  2906.                                                             {
  2907.                                                                 //Insert
  2908.                                                                 OdbcCom.Parameters.AddWithValue("@StatsID", this.m_ID_cache[kvp.Value.EAGuid].StatsID);
  2909.                                                                 OdbcCom.Parameters.AddWithValue("@Score", kvp.Value.TotalScore);
  2910.                                                                 OdbcCom.Parameters.AddWithValue("@Kills", kvp.Value.Kills);
  2911.                                                                 OdbcCom.Parameters.AddWithValue("@Headshots", kvp.Value.Headshots);
  2912.                                                                 if (kvp.Value.Deaths >= 0)
  2913.                                                                 {
  2914.                                                                     OdbcCom.Parameters.AddWithValue("@Deaths", kvp.Value.Deaths);
  2915.                                                                 }
  2916.                                                                 else
  2917.                                                                 {
  2918.                                                                     OdbcCom.Parameters.AddWithValue("@Deaths", 0);
  2919.                                                                 }
  2920.                                                                 OdbcCom.Parameters.AddWithValue("@Suicide", kvp.Value.Suicides);
  2921.                                                                 OdbcCom.Parameters.AddWithValue("@TKs", kvp.Value.Teamkills);
  2922.                                                                 OdbcCom.Parameters.AddWithValue("@Playtime", kvp.Value.TotalPlaytime);
  2923.                                                                 OdbcCom.Parameters.AddWithValue("@Rounds", 1);
  2924.                                                                 OdbcCom.Parameters.AddWithValue("@FirstSeenOnServer", kvp.Value.TimePlayerjoined);
  2925.                                                                 if (kvp.Value.TimePlayerleft != DateTime.MinValue)
  2926.                                                                 {
  2927.                                                                     OdbcCom.Parameters.AddWithValue("@LastSeenOnServer", kvp.Value.TimePlayerleft);
  2928.                                                                 }
  2929.                                                                 else
  2930.                                                                 {
  2931.                                                                     OdbcCom.Parameters.AddWithValue("@LastSeenOnServer", MyDateTime.Now);
  2932.                                                                 }
  2933.                                                                 OdbcCom.Parameters.AddWithValue("@Killstreak", kvp.Value.Killstreak);
  2934.                                                                 OdbcCom.Parameters.AddWithValue("@Deathstreak", kvp.Value.Deathstreak);
  2935.                                                                 OdbcCom.Parameters.AddWithValue("@HighScore", kvp.Value.TotalScore);
  2936.                                                                 OdbcCom.Parameters.AddWithValue("@Wins", kvp.Value.Wins);
  2937.                                                                 OdbcCom.Parameters.AddWithValue("@Losses", kvp.Value.Losses);
  2938.  
  2939.                                                                 OdbcCom.ExecuteNonQuery();
  2940.                                                             }
  2941.  
  2942.                                                             if (this.m_weaponstatsON == enumBoolYesNo.Yes)
  2943.                                                             {
  2944.                                                                 this.DebugInfo("Trace", "Weaponstats Write querys");
  2945.  
  2946.                                                                 string NewWeaponStatsSQL = @"INSERT INTO `" + this.tbl_weapons_stats + @"` (`StatsID`,`WeaponID`,`Kills`,`Headshots`,`Deaths`)
  2947.                                                                                         VALUES(@StatsID, @WeaponID, @Kills, @Headshots, @Deaths)
  2948.                                                                                         ON DUPLICATE KEY UPDATE  `Kills` = `Kills` + @Kills ,`Headshots` = `Headshots` + @Headshots,`Deaths` = `Deaths` + @Deaths";
  2949.  
  2950.                                                                 foreach (KeyValuePair<string, Dictionary<string, CStats.CUsedWeapon>> branch in tempdic)
  2951.                                                                 {
  2952.                                                                     //Build Query for Weaponstats
  2953.                                                                     if (tempdic != null)
  2954.                                                                     {
  2955.                                                                         foreach (KeyValuePair<string, CStats.CUsedWeapon> leaf in branch.Value)
  2956.                                                                         {
  2957.                                                                             if (leaf.Value.Kills != 0 || leaf.Value.Kills != 0 || leaf.Value.Deaths != 0)
  2958.                                                                             {
  2959.                                                                                 if (this.WeaponMappingDic.ContainsKey(leaf.Value.Name))
  2960.                                                                                 {
  2961.                                                                                     using (MySqlCommand OdbcCom = new MySqlCommand(NewWeaponStatsSQL, MySqlConn, MySqlTrans))
  2962.                                                                                     {
  2963.                                                                                         OdbcCom.Parameters.AddWithValue("@StatsID", this.m_ID_cache[kvp.Value.EAGuid].StatsID);
  2964.                                                                                         OdbcCom.Parameters.AddWithValue("@WeaponID", this.WeaponMappingDic[leaf.Value.Name]);
  2965.                                                                                         OdbcCom.Parameters.AddWithValue("@Kills", leaf.Value.Kills);
  2966.                                                                                         OdbcCom.Parameters.AddWithValue("@Headshots", leaf.Value.Headshots);
  2967.                                                                                         OdbcCom.Parameters.AddWithValue("@Deaths", leaf.Value.Deaths);
  2968.                                                                                         OdbcCom.ExecuteNonQuery();
  2969.                                                                                     }
  2970.                                                                                 }
  2971.                                                                             }
  2972.                                                                         }
  2973.                                                                     }
  2974.                                                                 }
  2975.                                                             }
  2976.  
  2977.                                                             //Awards
  2978.                                                             /*
  2979.                                                             if (this.m_awardsON == enumBoolYesNo.Yes && StatsTrackerCopy[kvp.Key].Awards.DicAwards.Count > 0)
  2980.                                                             {
  2981.                                                                 string awardsInsert = "INSERT INTO " + tbl_awards + @" (`AwardID` ";
  2982.                                                                 string awardsValues = ") VALUES (" + int_id;
  2983.                                                                 string awardsUpdate = " ON DUPLICATE KEY UPDATE ";
  2984.                                                                 foreach (KeyValuePair<string, int> award in StatsTrackerCopy[kvp.Key].Awards.DicAwards)
  2985.                                                                 {
  2986.                                                                     awardsInsert = String.Concat(awardsInsert, ", `", award.Key, "`");
  2987.                                                                     awardsValues = String.Concat(awardsValues, ", ", award.Value.ToString());
  2988.                                                                     awardsUpdate = String.Concat(awardsUpdate, " `", award.Key, "` = `", award.Key, "` + ", award.Value.ToString(), ", ");
  2989.                                                                 }
  2990.                                                                 // Remove the last comma
  2991.                                                                 int charindex2 = awardsUpdate.LastIndexOf(",");
  2992.                                                                 if (charindex2 > 0)
  2993.                                                                 {
  2994.                                                                     awardsUpdate = awardsUpdate.Remove(charindex2);
  2995.                                                                 }
  2996.                                                                 awardsInsert = String.Concat(awardsInsert, awardsValues, ") ", awardsUpdate);
  2997.                                                                 //Sent Query to the Server
  2998.                                                                 this.DebugInfo("Awardquery: " + awardsInsert);
  2999.                                                                 using (MySqlCommand OdbcCom = new MySqlCommand(awardsInsert, OdbcConn, OdbcTrans))
  3000.                                                                 {
  3001.                                                                     OdbcCom.ExecuteNonQuery();
  3002.                                                                 }
  3003.                                                             }
  3004.                                                             */
  3005.                                                         }
  3006.                                                     }
  3007.                                                     MySqlTrans.Commit();
  3008.                                                     success = true;
  3009.                                                 }
  3010.                                                 catch (MySqlException ex)
  3011.                                                 {
  3012.                                                     switch (ex.Number)
  3013.                                                     {
  3014.                                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  3015.                                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  3016.                                                             if (attemptCount < this.TransactionRetryCount)
  3017.                                                             {
  3018.                                                                 this.DebugInfo("Warning", "Warning in StartStreaming: Locktimeout or Deadlock occured restarting Transaction(Stats). Attempt: " + attemptCount);
  3019.                                                                 try
  3020.                                                                 {
  3021.                                                                     MySqlTrans.Rollback();
  3022.                                                                 }
  3023.                                                                 catch { }
  3024.                                                                 Thread.Sleep(attemptCount * 1000);
  3025.                                                             }
  3026.                                                             else
  3027.                                                             {
  3028.                                                                 this.DebugInfo("Error", "Error in StartStreaming: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction Stats)");
  3029.                                                                 throw;
  3030.                                                             }
  3031.                                                             break;
  3032.                                                         default:
  3033.                                                             throw; //Other exceptions
  3034.                                                     }
  3035.                                                 }
  3036.                                             }
  3037.                                         }
  3038.                                         //Reset bool and counter
  3039.                                         attemptCount = 0;
  3040.                                         success = false;
  3041.                                         if (this.m_enLogPlayerDataOnly == enumBoolYesNo.No)
  3042.                                         {
  3043.                                             while (!success)
  3044.                                             {
  3045.                                                 attemptCount++;
  3046.                                                 try
  3047.                                                 {
  3048.                                                     //Start of the Transaction
  3049.                                                     MySqlTrans = MySqlConn.BeginTransaction();
  3050.                                                     this.DebugInfo("Trace", "Dogtagstats Write querys");
  3051.                                                     string KnifeSQL = String.Empty;
  3052.                                                     foreach (KeyValuePair<CKillerVictim, int> kvp in m_dicKnifeKills)
  3053.                                                     {
  3054.                                                         if (StatsTrackerCopy.ContainsKey(kvp.Key.Killer) == false || StatsTrackerCopy.ContainsKey(kvp.Key.Victim) == false)
  3055.                                                         {
  3056.                                                             continue;
  3057.                                                         }
  3058.                                                         if (this.m_ID_cache.ContainsKey(StatsTrackerCopy[kvp.Key.Killer].EAGuid) == false || this.m_ID_cache.ContainsKey(StatsTrackerCopy[kvp.Key.Victim].EAGuid) == false)
  3059.                                                         {
  3060.                                                             continue;
  3061.                                                         }
  3062.                                                         if (this.m_ID_cache[StatsTrackerCopy[kvp.Key.Killer].EAGuid].StatsID > 0 && this.m_ID_cache[StatsTrackerCopy[kvp.Key.Victim].EAGuid].StatsID > 0)
  3063.                                                         {
  3064.                                                             KnifeSQL = "INSERT INTO " + this.tbl_dogtags + @"(KillerID, VictimID, Count) VALUES(@KillerID, @VictimID, @Count)
  3065.                                                     ON DUPLICATE KEY UPDATE Count = Count + @Count";
  3066.                                                             using (MySqlCommand OdbcCom = new MySqlCommand(KnifeSQL, MySqlConn, MySqlTrans))
  3067.                                                             {
  3068.                                                                 OdbcCom.Parameters.AddWithValue("@KillerID", this.m_ID_cache[StatsTrackerCopy[kvp.Key.Killer].EAGuid].StatsID);
  3069.                                                                 OdbcCom.Parameters.AddWithValue("@VictimID", this.m_ID_cache[StatsTrackerCopy[kvp.Key.Victim].EAGuid].StatsID);
  3070.                                                                 OdbcCom.Parameters.AddWithValue("@Count", m_dicKnifeKills[kvp.Key]);
  3071.                                                                 OdbcCom.ExecuteNonQuery();
  3072.                                                             }
  3073.                                                         }
  3074.                                                     }
  3075.                                                     MySqlTrans.Commit();
  3076.                                                     success = true;
  3077.                                                 }
  3078.                                                 catch (MySqlException ex)
  3079.                                                 {
  3080.                                                     switch (ex.Number)
  3081.                                                     {
  3082.                                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  3083.                                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  3084.                                                             if (attemptCount < this.TransactionRetryCount)
  3085.                                                             {
  3086.                                                                 this.DebugInfo("Warning", "Warning in StartStreaming: Locktimeout or Deadlock occured restarting Transaction(Dogtags). Attempt: " + attemptCount);
  3087.                                                                 try
  3088.                                                                 {
  3089.                                                                     MySqlTrans.Rollback();
  3090.                                                                 }
  3091.                                                                 catch { }
  3092.                                                                 Thread.Sleep(attemptCount * 1000);
  3093.                                                             }
  3094.                                                             else
  3095.                                                             {
  3096.                                                                 this.DebugInfo("Error", "Error in StartStreaming: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction Dogtags)");
  3097.                                                                 throw;
  3098.                                                             }
  3099.                                                             break;
  3100.                                                         default:
  3101.                                                             throw; //Other exceptions
  3102.                                                     }
  3103.                                                 }
  3104.                                             }
  3105.                                         }
  3106.                                         //Reset bool and counter
  3107.                                         attemptCount = 0;
  3108.                                         success = false;
  3109.  
  3110.                                         while (!success)
  3111.                                         {
  3112.                                             attemptCount++;
  3113.                                             try
  3114.                                             {
  3115.                                                 //Start of the Transaction
  3116.                                                 MySqlTrans = MySqlConn.BeginTransaction();
  3117.  
  3118.                                                 //Write the Player Sessions
  3119.  
  3120.                                                 if (this.m_sessionON == enumBoolYesNo.Yes && this.m_enSessionTracking == enumBoolYesNo.Yes)
  3121.                                                 {
  3122.                                                     bool containsvaildsessions = false;
  3123.                                                     StringBuilder InsertSQLSession = new StringBuilder(500);
  3124.                                                     InsertSQLSession.Append(@"INSERT INTO " + this.tbl_sessions + @" (`StatsID`, `StartTime`,`EndTime`, `Score`, `Kills`, `Headshots`, `Deaths`, `TKs`, `Suicide`,`RoundCount`, `Playtime`, `HighScore`, `Killstreak`, `Deathstreak`, `Wins`, `Losses`) VALUES");
  3125.  
  3126.                                                     this.DebugInfo("Trace", this.lstpassedSessions.Count + " Sessions to write to Sessiontable");
  3127.                                                     int i = 0;
  3128.                                                     foreach (CStats session in this.lstpassedSessions)
  3129.                                                     {
  3130.                                                         if (this.m_ID_cache.ContainsKey(session.EAGuid) == true)
  3131.                                                         {
  3132.                                                             if (this.m_ID_cache[session.EAGuid].StatsID > 0)
  3133.                                                             {
  3134.                                                                 //write session
  3135.                                                                 containsvaildsessions = true;
  3136.                                                                 InsertSQLSession.Append(" (@StatsID" + i + ", @StartTime" + i + ", @EndTime" + i + ", @Score" + i + ", @Kills" + i + ", @Headshots" + i + ", @Deaths" + i + ", @TKs" + i + ", @Suicide" + i + ", @RoundCount" + i + ", @Playtime" + i + ", @HighScore" + i + ", @Killstreak" + i + ", @Deathstreak" + i + ", @Wins" + i + ", @Losses" + i + "),");
  3137.                                                                 i++;
  3138.                                                             }
  3139.                                                         }
  3140.                                                     }
  3141.                                                     if (containsvaildsessions)
  3142.                                                     {
  3143.                                                         //remove last comma
  3144.                                                         InsertSQLSession.Length = InsertSQLSession.Length - 1;
  3145.                                                         using (MySqlCommand sessionInsert = new MySqlCommand(InsertSQLSession.ToString(), MySqlConn, MySqlTrans))
  3146.                                                         {
  3147.                                                             i = 0;
  3148.                                                             foreach (CStats session in this.lstpassedSessions)
  3149.                                                             {
  3150.                                                                 if (this.m_ID_cache.ContainsKey(session.EAGuid) == true)
  3151.                                                                 {
  3152.                                                                     if (this.m_ID_cache[session.EAGuid].StatsID > 0)
  3153.                                                                     {
  3154.                                                                         sessionInsert.Parameters.AddWithValue("@StatsID" + i, this.m_ID_cache[session.EAGuid].StatsID);
  3155.                                                                         sessionInsert.Parameters.AddWithValue("@StartTime" + i, session.TimePlayerjoined);
  3156.                                                                         sessionInsert.Parameters.AddWithValue("@EndTime" + i, session.TimePlayerleft);
  3157.                                                                         sessionInsert.Parameters.AddWithValue("@Score" + i, session.TotalScore);
  3158.                                                                         sessionInsert.Parameters.AddWithValue("@Kills" + i, session.Kills);
  3159.                                                                         sessionInsert.Parameters.AddWithValue("@Headshots" + i, session.Headshots);
  3160.                                                                         if (session.Deaths >= 0)
  3161.                                                                         {
  3162.                                                                             sessionInsert.Parameters.AddWithValue("@Deaths" + i, session.Deaths);
  3163.                                                                         }
  3164.                                                                         else
  3165.                                                                         {
  3166.                                                                             sessionInsert.Parameters.AddWithValue("@Deaths" + i, 0);
  3167.                                                                         }
  3168.                                                                         sessionInsert.Parameters.AddWithValue("@TKs" + i, session.Teamkills);
  3169.                                                                         sessionInsert.Parameters.AddWithValue("@Suicide" + i, session.Suicides);
  3170.                                                                         sessionInsert.Parameters.AddWithValue("@RoundCount" + i, session.Rounds);
  3171.                                                                         sessionInsert.Parameters.AddWithValue("@Playtime" + i, session.TotalPlaytime);
  3172.                                                                         sessionInsert.Parameters.AddWithValue("@HighScore" + i, session.HighScore);
  3173.                                                                         sessionInsert.Parameters.AddWithValue("@Killstreak" + i, session.Killstreak);
  3174.                                                                         sessionInsert.Parameters.AddWithValue("@Deathstreak" + i, session.Deathstreak);
  3175.                                                                         sessionInsert.Parameters.AddWithValue("@Wins" + i, session.Wins);
  3176.                                                                         sessionInsert.Parameters.AddWithValue("@Losses" + i, session.Losses);
  3177.                                                                         i++;
  3178.                                                                     }
  3179.                                                                 }
  3180.                                                             }
  3181.                                                             sessionInsert.ExecuteNonQuery();
  3182.                                                             this.lstpassedSessions.Clear();
  3183.                                                         }
  3184.                                                     }
  3185.                                                 }
  3186.                                                 //Commit the Transaction for the Playerstats
  3187.                                                 MySqlTrans.Commit();
  3188.                                                 success = true;
  3189.                                             }
  3190.                                             catch (MySqlException ex)
  3191.                                             {
  3192.                                                 switch (ex.Number)
  3193.                                                 {
  3194.                                                     case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  3195.                                                     case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  3196.                                                         if (attemptCount < this.TransactionRetryCount)
  3197.                                                         {
  3198.                                                             this.DebugInfo("Warning", "Warning in StartStreaming: Locktimeout or Deadlock occured restarting Transaction(Sessions). Attempt: " + attemptCount);
  3199.                                                             try
  3200.                                                             {
  3201.                                                                 MySqlTrans.Rollback();
  3202.                                                             }
  3203.                                                             catch { }
  3204.                                                             Thread.Sleep(attemptCount * 1000);
  3205.                                                         }
  3206.                                                         else
  3207.                                                         {
  3208.                                                             this.DebugInfo("Error", "Error in StartStreaming: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction Sessions)");
  3209.                                                             throw;
  3210.                                                         }
  3211.                                                         break;
  3212.                                                     default:
  3213.                                                         throw; //Other exceptions
  3214.                                                 }
  3215.                                             }
  3216.                                         }
  3217.                                         //Reset bool and counter
  3218.                                         attemptCount = 0;
  3219.                                         success = false;
  3220.  
  3221.                                         //Calculate ServerStats
  3222.                                         if (this.boolSkipServerStatsUpdate == false && this.m_enLogPlayerDataOnly == enumBoolYesNo.No)
  3223.                                         {
  3224.                                             this.DebugInfo("Trace", "Serverstats Write query");
  3225.                                             while (!success)
  3226.                                             {
  3227.                                                 attemptCount++;
  3228.                                                 try
  3229.                                                 {
  3230.                                                     MySqlTrans = MySqlConn.BeginTransaction();
  3231.                                                     string serverstats = @"REPLACE INTO " + this.tbl_server_stats + @" SELECT tsp.ServerID, Count(*) AS CountPlayers, SUM(tps.Score) AS SumScore, AVG(tps.Score) AS AvgScore, SUM(tps.Kills) AS SumKills,  AVG(tps.Kills) AS AvgKills, SUM(tps.Headshots) AS SumHeadshots,
  3232.                                                        AVG(tps.Headshots) AS AvgHeadshots, SUM(tps.Deaths) AS SumDeaths, AVG(tps.Deaths) AS AvgDeaths, SUM(tps.Suicide) AS SumSuicide, AVG(tps.Suicide) AS AvgSuicide, SUM(tps.TKs) AS SumTKs, AVG(tps.TKs) AS AvgTKs,
  3233.                                                        SUM(tps.Playtime) AS SumPlaytime, AVG(tps.Playtime) AS AvgPlaytime, SUM(tps.Rounds) AS SumRounds, AVG(tps.Rounds) AS AvgRounds
  3234.                                                        FROM " + this.tbl_playerstats + @" tps
  3235.                                                        INNER JOIN " + this.tbl_server_player + @" tsp ON tps.StatsID = tsp.StatsID
  3236.                                                        WHERE tsp.ServerID = @ServerID GROUP BY tsp.ServerID";
  3237.                                                     using (MySqlCommand OdbcCom = new MySqlCommand(serverstats, MySqlConn, MySqlTrans))
  3238.                                                     {
  3239.                                                         OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  3240.                                                         OdbcCom.ExecuteNonQuery();
  3241.                                                     }
  3242.                                                     MySqlTrans.Commit();
  3243.                                                     success = true;
  3244.                                                 }
  3245.                                                 catch (MySqlException ex)
  3246.                                                 {
  3247.                                                     switch (ex.Number)
  3248.                                                     {
  3249.                                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  3250.                                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  3251.                                                             if (attemptCount < this.TransactionRetryCount)
  3252.                                                             {
  3253.                                                                 this.DebugInfo("Warning", "Warning in StartStreaming: Locktimeout or Deadlock occured restarting Transaction(Serverstats). Attempt: " + attemptCount);
  3254.                                                                 try
  3255.                                                                 {
  3256.                                                                     MySqlTrans.Rollback();
  3257.                                                                 }
  3258.                                                                 catch { }
  3259.                                                                 Thread.Sleep(attemptCount * 1000);
  3260.                                                             }
  3261.                                                             else
  3262.                                                             {
  3263.                                                                 this.DebugInfo("Error", "Error in StartStreaming: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction Serverstats)");
  3264.                                                                 throw;
  3265.                                                             }
  3266.                                                             break;
  3267.                                                         default:
  3268.                                                             throw; //Other exceptions
  3269.                                                     }
  3270.                                                 }
  3271.                                             }
  3272.                                         }
  3273.                                         //Reset bool and counter
  3274.                                         attemptCount = 0;
  3275.                                         success = false;
  3276.  
  3277.                                         StatsTrackerCopy.Clear();
  3278.                                         this.m_dicKnifeKills.Clear();
  3279.  
  3280.                                         List<string> leftplayerlist = new List<string>();
  3281.  
  3282.                                         foreach (KeyValuePair<string, C_ID_Cache> kvp in this.m_ID_cache)
  3283.                                         {
  3284.                                             if (this.m_ID_cache[kvp.Key].PlayeronServer == false)
  3285.                                             {
  3286.                                                 leftplayerlist.Add(kvp.Key);
  3287.                                             }
  3288.                                             // Because so playerleft event seems not been reported by the server
  3289.                                             this.m_ID_cache[kvp.Key].PlayeronServer = false;
  3290.                                         }
  3291.                                         foreach (string player in leftplayerlist)
  3292.                                         {
  3293.                                             this.m_ID_cache.Remove(player);
  3294.                                             //this.DebugInfo("Removed " + player);
  3295.                                         }
  3296.                                         this.DebugInfo("Info", "Status ID-Cache: " + m_ID_cache.Count + " ID's in cache");
  3297.                                         if (this.m_ID_cache.Count > 500)
  3298.                                         {
  3299.                                             this.DebugInfo("Warning", "Forced Cache clear due the Nummber of cached IDs reached over 500 entries(overflowProtection)");
  3300.                                             this.m_ID_cache.Clear();
  3301.                                         }
  3302.                                     }
  3303.                                     else
  3304.                                     {
  3305.                                         StatsTracker.Clear();
  3306.                                     }
  3307.                                 }
  3308.                                 catch (MySqlException oe)
  3309.                                 {
  3310.                                     this.DebugInfo("Error", "Error in Startstreaming: ");
  3311.                                     this.DisplayMySqlErrorCollection(oe);
  3312.                                     this.m_ID_cache.Clear();
  3313.                                     this.m_dicKnifeKills.Clear();
  3314.                                     try { MySqlTrans.Rollback(); }
  3315.                                     catch { }
  3316.                                 }
  3317.                                 catch (Exception c)
  3318.                                 {
  3319.                                     this.DebugInfo("Error", "Error in Startstreaming: " + c);
  3320.                                     this.m_ID_cache.Clear();
  3321.                                     this.m_dicKnifeKills.Clear();
  3322.                                     try { MySqlTrans.Rollback(); }
  3323.                                     catch { }
  3324.                                 }
  3325.                                 finally
  3326.                                 {
  3327.                                     StatsTrackerCopy = null;
  3328.                                     this.Mapstats = this.Nextmapinfo;
  3329.                                     this.MySql_Connection_is_activ = false;
  3330.                                     this.CloseMySqlConnection(2);
  3331.  
  3332.                                     //Update Serverranking
  3333.                                     this.UpdateRanking();
  3334.                                     //Welcomestats dic
  3335.                                     this.checkWelcomeStatsDic();
  3336.                                     if (GlobalDebugMode.Equals("Info"))
  3337.                                     {
  3338.                                         TimeSpan duration = MyDateTime.Now - StartStreamingTime;
  3339.                                         this.DebugInfo("Info", "Streamingprocess duration: " + Math.Round(duration.TotalSeconds, 3) + " seconds");
  3340.                                     }
  3341.                                 }
  3342.                             }
  3343.                             else
  3344.                             {
  3345.                                 this.DebugInfo("Error", "Streaming cancelled.  Please enter all database information");
  3346.                             }
  3347.                         }
  3348.                     }
  3349.                 }
  3350.                 catch (MySqlException oe)
  3351.                 {
  3352.                     this.DebugInfo("Error", "Error in Startstreaming OuterException: ");
  3353.                     this.DisplayMySqlErrorCollection(oe);
  3354.                     this.m_ID_cache.Clear();
  3355.                     this.m_dicKnifeKills.Clear();
  3356.                 }
  3357.                 catch (Exception c)
  3358.                 {
  3359.                     this.DebugInfo("Error", "Error in Startstreaming OuterException: " + c);
  3360.                     this.m_ID_cache.Clear();
  3361.                     this.m_dicKnifeKills.Clear();
  3362.                 }
  3363.             }
  3364.         }
  3365.  
  3366.         private void UpdateCurrentPlayerTable(List<CPlayerInfo> lstPlayers)
  3367.         {
  3368.             if (this.boolTableEXISTS == false || ServerID <= 0)
  3369.             {
  3370.                 return;
  3371.             }
  3372.             this.DebugInfo("Trace", "UpdateCurrentPlayerTable");
  3373.             bool success = false;
  3374.             int attemptCount = 0;
  3375.             try
  3376.             {
  3377.                 using (MySqlConnection DBConnection = new MySqlConnection(this.DBConnectionStringBuilder()))
  3378.                 {
  3379.                     string deleteSQL = "DELETE FROM " + this.tbl_currentplayers + " WHERE ServerID = @ServerID";
  3380.                     StringBuilder InsertSQL = new StringBuilder("INSERT INTO " + this.tbl_currentplayers + " (ServerID, SoldierName, ClanTag ,EA_GUID, PB_GUID, Score, Kills, Deaths, Headshots, Suicide, TeamID, SquadID, PlayerJoined, Ping, IP_aton, CountryCode, Killstreak, Deathstreak, GlobalRank ) VALUES ");
  3381.                     MySql.Data.MySqlClient.MySqlTransaction Tx = null;
  3382.  
  3383.                     DBConnection.Open();
  3384.                     while (!success)
  3385.                     {
  3386.                         attemptCount++;
  3387.                         try
  3388.                         {
  3389.                             //Start of the Transaction
  3390.                             Tx = DBConnection.BeginTransaction();
  3391.  
  3392.                             using (MySqlCommand OdbcCom = new MySqlCommand(deleteSQL, DBConnection, Tx))
  3393.                             {
  3394.                                 OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  3395.                                 OdbcCom.ExecuteNonQuery();
  3396.                             }
  3397.                             if (lstPlayers.Count > 0)
  3398.                             {
  3399.                                 int i = 0;
  3400.                                 foreach (CPlayerInfo cpiPlayer in lstPlayers)
  3401.                                 {
  3402.                                     InsertSQL.Append("( @ServerID, @SoldierName" + i + ",@ClanTag" + i + ", @EA_GUID" + i + ", @PB_GUID" + i + ", @Score" + i + ", @Kills" + i + ", @Deaths" + i + ", @Suicide" + i + ", @Headshots" + i + ",@TeamID" + i + ",@SquadID" + i + " ,@PlayerJoined" + i + ",@Ping" + i + ", INET_ATON( @IP_aton" + i + ")" + ",@CountryCode" + i + ",@Killstreak" + i + ",@Deathstreak" + i + ",@GlobalRank" + i + "),");
  3403.                                     i++;
  3404.                                 }
  3405.                                 InsertSQL.Length = InsertSQL.Length - 1;
  3406.                                 using (MySqlCommand OdbcCom = new MySqlCommand(InsertSQL.ToString(), DBConnection, Tx))
  3407.                                 {
  3408.                                     i = 0;
  3409.                                     OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  3410.                                     foreach (CPlayerInfo cpiPlayer in lstPlayers)
  3411.                                     {
  3412.                                         OdbcCom.Parameters.AddWithValue("@SoldierName" + i, cpiPlayer.SoldierName);
  3413.                                         OdbcCom.Parameters.AddWithValue("@ClanTag" + i, cpiPlayer.ClanTag + "");
  3414.                                         OdbcCom.Parameters.AddWithValue("@EA_GUID" + i, cpiPlayer.GUID);
  3415.                                         if (this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  3416.                                         {
  3417.                                             OdbcCom.Parameters.AddWithValue("@PB_GUID" + i, this.StatsTracker[cpiPlayer.SoldierName].Guid);
  3418.                                         }
  3419.                                         else
  3420.                                         {
  3421.                                             OdbcCom.Parameters.AddWithValue("@PB_GUID" + i, ""); //placeholder
  3422.                                         }
  3423.                                         OdbcCom.Parameters.AddWithValue("@Score" + i, cpiPlayer.Score);
  3424.                                         OdbcCom.Parameters.AddWithValue("@Kills" + i, cpiPlayer.Kills);
  3425.                                         OdbcCom.Parameters.AddWithValue("@Deaths" + i, cpiPlayer.Deaths);
  3426.                                         if (this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  3427.                                         {
  3428.                                             OdbcCom.Parameters.AddWithValue("@Headshots" + i, this.StatsTracker[cpiPlayer.SoldierName].Headshots);
  3429.                                             OdbcCom.Parameters.AddWithValue("@PlayerJoined" + i, this.StatsTracker[cpiPlayer.SoldierName].Playerjoined);
  3430.                                             OdbcCom.Parameters.AddWithValue("@CountryCode" + i, this.StatsTracker[cpiPlayer.SoldierName].PlayerCountryCode);
  3431.                                             OdbcCom.Parameters.AddWithValue("@Killstreak" + i, this.StatsTracker[cpiPlayer.SoldierName].Killstreak);
  3432.                                             OdbcCom.Parameters.AddWithValue("@Deathstreak" + i, this.StatsTracker[cpiPlayer.SoldierName].Deathstreak);
  3433.                                             OdbcCom.Parameters.AddWithValue("@Suicide" + i, this.StatsTracker[cpiPlayer.SoldierName].Suicides);
  3434.                                             OdbcCom.Parameters.AddWithValue("@IP_aton" + i, this.StatsTracker[cpiPlayer.SoldierName].IP);
  3435.                                         }
  3436.                                         else
  3437.                                         {
  3438.                                             OdbcCom.Parameters.AddWithValue("@Headshots" + i, 0); //Headshot placeholder
  3439.                                             OdbcCom.Parameters.AddWithValue("@PlayerJoined" + i, MyDateTime.Now);
  3440.                                             OdbcCom.Parameters.AddWithValue("@CountryCode" + i, "");
  3441.                                             OdbcCom.Parameters.AddWithValue("@Killstreak" + i, 0);
  3442.                                             OdbcCom.Parameters.AddWithValue("@Deathstreak" + i, 0);
  3443.                                             OdbcCom.Parameters.AddWithValue("@Suicide" + i, 0);
  3444.                                             OdbcCom.Parameters.AddWithValue("@IP_aton" + i, "0.0.0.0");
  3445.                                         }
  3446.                                         OdbcCom.Parameters.AddWithValue("@TeamID" + i, cpiPlayer.TeamID);
  3447.                                         OdbcCom.Parameters.AddWithValue("@SquadID" + i, cpiPlayer.SquadID);
  3448.                                         if (cpiPlayer.Ping >= 0 && cpiPlayer.Ping < 65000)
  3449.                                         {
  3450.                                             OdbcCom.Parameters.AddWithValue("@Ping" + i, cpiPlayer.Ping);
  3451.                                         }
  3452.                                         else
  3453.                                         {
  3454.                                             OdbcCom.Parameters.AddWithValue("@Ping" + i, 0);
  3455.                                         }
  3456.                                         if (cpiPlayer.Rank >= 0 && cpiPlayer.Rank < 6500)
  3457.                                         {
  3458.                                             OdbcCom.Parameters.AddWithValue("@GlobalRank" + i, cpiPlayer.Rank);
  3459.                                         }
  3460.                                         else
  3461.                                         {
  3462.                                             OdbcCom.Parameters.AddWithValue("@GlobalRank" + i, 0);
  3463.                                         }
  3464.                                         //Increment Index
  3465.                                         i++;
  3466.                                     }
  3467.                                     OdbcCom.ExecuteNonQuery();
  3468.                                 }
  3469.                             }
  3470.                             Tx.Commit();
  3471.                             success = true;
  3472.                         }
  3473.                         catch (MySqlException ex)
  3474.                         {
  3475.                             switch (ex.Number)
  3476.                             {
  3477.                                 case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  3478.                                 case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  3479.                                     if (attemptCount < this.TransactionRetryCount)
  3480.                                     {
  3481.                                         this.DebugInfo("Warning", "Warning in UpdateCurrentPlayerTable: Locktimeout or Deadlock occured restarting Transaction(delete and Insert). Attempt: " + attemptCount);
  3482.                                         try
  3483.                                         {
  3484.                                             if (Tx.Connection != null)
  3485.                                             {
  3486.                                                 Tx.Rollback();
  3487.                                             }
  3488.                                         }
  3489.                                         catch { }
  3490.                                         Thread.Sleep(attemptCount * 1000);
  3491.                                     }
  3492.                                     else
  3493.                                     {
  3494.                                         this.DebugInfo("Error", "Error in UpdateCurrentPlayerTable: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction delete und Insert)");
  3495.                                         throw;
  3496.                                     }
  3497.                                     break;
  3498.                                 default:
  3499.                                     throw; //Other exceptions
  3500.                             }
  3501.                         }
  3502.                     }
  3503.                     //Reset bool and counter
  3504.                     attemptCount = 0;
  3505.                     success = false;
  3506.                     try
  3507.                     {
  3508.                         DBConnection.Close();
  3509.                     }
  3510.                     catch {};
  3511.                 }
  3512.             }
  3513.             catch (MySqlException oe)
  3514.             {
  3515.                 this.DebugInfo("Error", "Error in UpdateCurrentPlayerTable: ");
  3516.                 this.DisplayMySqlErrorCollection(oe);
  3517.             }
  3518.             catch (Exception c)
  3519.             {
  3520.                 this.DebugInfo("Error", "Error in UpdateCurrentPlayerTable: " + c.ToString());
  3521.             }
  3522.            
  3523.         }
  3524.  
  3525.         //Fetch data from the db
  3526.  
  3527.         private C_ID_Cache GetID(string EAguid)
  3528.         {
  3529.             int playerID = 0;
  3530.             int StatsID = 0;
  3531.             if (GlobalDebugMode.Equals("Trace"))
  3532.             {
  3533.                 this.DebugInfo("Trace", "Tying to get IDs form DB or cache for EAGuid: " + EAguid);
  3534.             }
  3535.             try
  3536.             {
  3537.                 if (this.m_ID_cache.ContainsKey(EAguid) == true)
  3538.                 {
  3539.                     if (this.m_ID_cache[EAguid].Id >= 1 && this.m_ID_cache[EAguid].StatsID >= 1)
  3540.                     {
  3541.                         //CacheHit
  3542.                         if (GlobalDebugMode.Equals("Trace"))
  3543.                         {
  3544.                             this.DebugInfo("Trace", "Status ID-Cache: used IDs(" + this.m_ID_cache[EAguid].Id + " | " + this.m_ID_cache[EAguid].StatsID + ") from cache for EAGuid " + EAguid);
  3545.                         }
  3546.                         return this.m_ID_cache[EAguid];
  3547.                     }
  3548.                     else
  3549.                     {
  3550.                         //Cachemiss
  3551.                         if (this.m_ID_cache[EAguid].Id <= 0)
  3552.                         {
  3553.                             using (MySqlCommand MyCommand = new MySqlCommand(@"SELECT `PlayerID` FROM `" + this.tbl_playerdata + "` WHERE `GameID` = @GameID AND `EAGUID` = @EAGUID "))
  3554.                             {
  3555.                                 MyCommand.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  3556.                                 MyCommand.Parameters.AddWithValue("@EAGUID", EAguid);
  3557.                                 DataTable resultTable = this.SQLquery(MyCommand);
  3558.                                 if (resultTable.Rows != null)
  3559.                                 {
  3560.                                     foreach (DataRow row in resultTable.Rows)
  3561.                                     {
  3562.                                         playerID = Convert.ToInt32(row["PlayerID"]);
  3563.                                         this.m_ID_cache[EAguid].Id = playerID;
  3564.                                     }
  3565.                                 }
  3566.                             }
  3567.                         }
  3568.                         else
  3569.                         {
  3570.                             playerID = this.m_ID_cache[EAguid].Id;
  3571.                         }
  3572.                         if (playerID >= 1)
  3573.                         {
  3574.                             using (MySqlCommand MyCommand = new MySqlCommand(@"SELECT `StatsID` FROM `" + this.tbl_server_player + "` WHERE `PlayerID` = @PlayerID AND `ServerID`= @ServerID "))
  3575.                             {
  3576.                                 MyCommand.Parameters.AddWithValue("@PlayerID", playerID);
  3577.                                 MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  3578.                                 DataTable resultTable = this.SQLquery(MyCommand);
  3579.                                 if (resultTable.Rows != null)
  3580.                                 {
  3581.                                     foreach (DataRow row in resultTable.Rows)
  3582.                                     {
  3583.                                         StatsID = Convert.ToInt32(row["StatsID"]);
  3584.                                         this.m_ID_cache[EAguid].StatsID = StatsID;
  3585.                                     }
  3586.                                 }
  3587.                             }
  3588.                         }
  3589.                     }
  3590.                 }
  3591.                 else
  3592.                 {
  3593.                     //Cache has no entry
  3594.                     using (MySqlCommand MyCommand = new MySqlCommand(@"SELECT `PlayerID` FROM `" + this.tbl_playerdata + "` WHERE `GameID` = @GameID AND `EAGUID` = @EAGUID "))
  3595.                     {
  3596.                         MyCommand.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  3597.                         MyCommand.Parameters.AddWithValue("@EAGUID", EAguid);
  3598.                         DataTable resultTable = this.SQLquery(MyCommand);
  3599.                         if (resultTable.Rows != null)
  3600.                         {
  3601.                             foreach (DataRow row in resultTable.Rows)
  3602.                             {
  3603.                                 playerID = Convert.ToInt32(row["PlayerID"]);
  3604.                             }
  3605.                         }
  3606.                     }
  3607.                     if (playerID >= 1)
  3608.                     {
  3609.                         using (MySqlCommand MyCommand = new MySqlCommand(@"SELECT `StatsID` FROM `" + this.tbl_server_player + "` WHERE `PlayerID` = @PlayerID AND `ServerID`= @ServerID"))
  3610.                         {
  3611.                             MyCommand.Parameters.AddWithValue("@PlayerID", playerID);
  3612.                             MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  3613.                             DataTable resultTable = this.SQLquery(MyCommand);
  3614.                             if (resultTable.Rows != null)
  3615.                             {
  3616.                                 foreach (DataRow row in resultTable.Rows)
  3617.                                 {
  3618.                                     StatsID = Convert.ToInt32(row["StatsID"]);
  3619.                                 }
  3620.                             }
  3621.                         }
  3622.                     }
  3623.                     this.m_ID_cache.Add(EAguid, new C_ID_Cache(StatsID, playerID, true));
  3624.                 }
  3625.             }
  3626.             catch (Exception c)
  3627.             {
  3628.                 this.DebugInfo("Error", "GetID: " + c);
  3629.                 return null;
  3630.             }
  3631.             if (GlobalDebugMode.Equals("Trace"))
  3632.             {
  3633.                 this.DebugInfo("Trace", "Returning ID: PlayerID: " + playerID + " StatsID: " + StatsID);
  3634.             }
  3635.             return this.m_ID_cache[EAguid];
  3636.         }
  3637.  
  3638.         private void UpdateIDCache(List<string> lstEAGUID)
  3639.         {
  3640.             foreach (string EAGUID in lstEAGUID)
  3641.             {
  3642.                 if (this.m_ID_cache.ContainsKey(EAGUID) == false)
  3643.                 {
  3644.                     //Adding an empty entry
  3645.                     this.m_ID_cache.Add(EAGUID, new C_ID_Cache(0, 0, true));
  3646.                 }
  3647.             }
  3648.             if (lstEAGUID.Count == 0)
  3649.             {
  3650.                 this.DebugInfo("Trace", "UpdateIDCache: Empty List!");
  3651.                 return;
  3652.             }
  3653.  
  3654.             StringBuilder SQL = new StringBuilder(@"SELECT EAGUID, tpd.PlayerID, tsp.StatsID
  3655.                          FROM " + this.tbl_playerdata + @" tpd
  3656.                          LEFT JOIN " + this.tbl_server_player + @" tsp ON tpd.PlayerID = tsp.PlayerID AND ServerID = @ServerID
  3657.                          WHERE tpd.GameID = @GameID AND tpd.EAGUID IN (");
  3658.             for (int i = 1; i <= lstEAGUID.Count; i++)
  3659.             {
  3660.                 SQL.Append("@EAGUID" + i + ",");
  3661.             }
  3662.             SQL.Length = SQL.Length - 1;
  3663.             SQL.Append(')');
  3664.             try
  3665.             {
  3666.                 using (MySqlCommand SelectCommand = new MySqlCommand(SQL.ToString()))
  3667.                 {
  3668.                     SelectCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  3669.                     SelectCommand.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  3670.                     int i = 1;
  3671.                     foreach (string EAGUID in lstEAGUID)
  3672.                     {
  3673.                         SelectCommand.Parameters.AddWithValue("@EAGUID" + i, EAGUID);
  3674.                         i++;
  3675.                     }
  3676.                     DataTable result;
  3677.                     result = this.SQLquery(SelectCommand);
  3678.                     if (result != null)
  3679.                     {
  3680.                         foreach (DataRow row in result.Rows)
  3681.                         {
  3682.                             if (row[1] == Convert.DBNull)
  3683.                             {
  3684.                                 this.m_ID_cache.Add(row[0].ToString(), new C_ID_Cache(0, 0, true));
  3685.                                 continue;
  3686.                             }
  3687.                             if (this.m_ID_cache.ContainsKey(row[0].ToString()))
  3688.                             {
  3689.                                 this.m_ID_cache[row[0].ToString()].Id = Convert.ToInt32(row[1]);
  3690.                                 if (row[2] == Convert.DBNull)
  3691.                                 {
  3692.                                     this.m_ID_cache[row[0].ToString()].StatsID = 0;
  3693.                                 }
  3694.                                 else
  3695.                                 {
  3696.                                     this.m_ID_cache[row[0].ToString()].StatsID = Convert.ToInt32(row[2]);
  3697.                                 }
  3698.                             }
  3699.                             else
  3700.                             {
  3701.                                 if (row[2] == Convert.DBNull)
  3702.                                 {
  3703.                                     this.m_ID_cache.Add(row[0].ToString(), new C_ID_Cache(0, Convert.ToInt32(row[1]), true));
  3704.                                 }
  3705.                                 else
  3706.                                 {
  3707.                                     this.m_ID_cache.Add(row[0].ToString(), new C_ID_Cache(Convert.ToInt32(row[2]), Convert.ToInt32(row[1]), true));
  3708.                                 }
  3709.                             }
  3710.                         }
  3711.                     }
  3712.                 }
  3713.             }
  3714.             catch (MySqlException oe)
  3715.             {
  3716.                 this.DebugInfo("Error", "Error in UpdateCacheID: ");
  3717.                 this.DisplayMySqlErrorCollection(oe);
  3718.             }
  3719.             catch (Exception c)
  3720.             {
  3721.                 this.DebugInfo("Error", "UpdateIDCache: " + c);
  3722.             }
  3723.         }
  3724.  
  3725.         private void WelcomeStats(string strSpeaker)
  3726.         {
  3727.             List<string> result = new List<string>();
  3728.             if (this.m_enWelcomeStats == enumBoolYesNo.Yes)
  3729.             {
  3730.                 if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  3731.                 {
  3732.                     string SQL = String.Empty;
  3733.                     string strMSG = String.Empty;
  3734.                     //Statsquery with KDR
  3735.                     //Rankquery
  3736.                     if (m_enRankingByScore == enumBoolYesNo.Yes)
  3737.                     {
  3738.                         if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  3739.                         {
  3740.                             SQL = @"SELECT tpd.SoldierName, SUM(tps.Score) AS Score, SUM(tps.Kills) AS Kills, SUM(tps.Deaths) AS Deaths, SUM(tps.Suicide) AS Suicide, SUM(tps.TKs) AS TKs, tpr.rankScore AS rank, (SELECT SUM(tss.CountPlayers) FROM " + this.tbl_server_stats + @" tss INNER JOIN " + this.tbl_server + @" ts ON tss.ServerID = ts.ServerID AND ServerGroup = @ServerGroup GROUP BY ts.ServerGroup ) AS allrank , SUM(tps.Playtime) AS Playtime, SUM(tps.Headshots) AS Headshots,
  3741.                                    SUM(tps.Rounds) AS Rounds, MAX(tps.Killstreak) AS Killstreak, MAX(tps.Deathstreak) AS Deathstreak  
  3742.                                    FROM " + this.tbl_playerdata + @" tpd
  3743.                                    INNER JOIN " + this.tbl_playerrank + @" tpr ON tpd.PlayerID = tpr.PlayerID AND tpr.ServerGroup = @ServerGroup
  3744.                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3745.                                    INNER JOIN " + this.tbl_playerstats + @" tps ON tsp.StatsID = tps.StatsID
  3746.                                    WHERE tpd.SoldierName = @SoldierName
  3747.                                    GROUP BY tpd.PlayerID";
  3748.                         }
  3749.                         else
  3750.                         {
  3751.                             SQL = @"SELECT tpd.SoldierName AS SoldierName, tps.Score AS Score, tps.Kills AS Kills, tps.Deaths AS Deaths, tps.Suicide AS Suicide, tps.TKs AS TKs, tps.rankScore AS rank, (SELECT tss.CountPlayers FROM " + this.tbl_server_stats + @" tss WHERE ServerID = @ServerID ) AS allrank ,
  3752.                                    tps.Playtime AS Playtime, tps.Headshots AS Headshots, tps.Rounds AS Rounds, tps.Killstreak AS Killstreak, tps.Deathstreak AS Deathstreak
  3753.                                    FROM " + this.tbl_playerdata + @" tpd
  3754.                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3755.                                    INNER JOIN " + this.tbl_playerstats + @" tps ON tps.StatsID = tsp.StatsID
  3756.                                    WHERE  tsp.ServerID = @ServerID AND tpd.SoldierName = @SoldierName";
  3757.                         }
  3758.                     }
  3759.                     else
  3760.                     {
  3761.                         if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  3762.                         {
  3763.                             SQL = @"SELECT tpd.SoldierName, SUM(tps.Score) AS Score, SUM(tps.Kills) AS Kills, SUM(tps.Deaths) AS Deaths, SUM(tps.Suicide) AS Suicide, SUM(tps.TKs) AS TKs, tpr.rankKills AS rank, (SELECT SUM(tss.CountPlayers) FROM " + this.tbl_server_stats + @" tss INNER JOIN " + this.tbl_server + @" ts ON tss.ServerID = ts.ServerID AND ServerGroup = @ServerGroup GROUP BY ts.ServerGroup ) AS allrank , SUM(tps.Playtime) AS Playtime, SUM(tps.Headshots) AS Headshots,
  3764.                                    SUM(tps.Rounds) AS Rounds, MAX(tps.Killstreak) AS Killstreak, MAX(tps.Deathstreak) AS Deathstreak  
  3765.                                    FROM " + this.tbl_playerdata + @" tpd
  3766.                                    INNER JOIN " + this.tbl_playerrank + @" tpr ON tpd.PlayerID = tpr.PlayerID AND tpr.ServerGroup = @ServerGroup
  3767.                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3768.                                    INNER JOIN " + this.tbl_playerstats + @" tps ON tsp.StatsID = tps.StatsID
  3769.                                    WHERE tpd.SoldierName = @SoldierName
  3770.                                    GROUP BY tpd.PlayerID";
  3771.                         }
  3772.                         else
  3773.                         {
  3774.                             SQL = @"SELECT tpd.SoldierName AS SoldierName, tps.Score AS Score, tps.Kills AS Kills, tps.Deaths AS Deaths, tps.Suicide AS Suicide, tps.TKs AS TKs, tps.rankKills AS rank, (SELECT tss.CountPlayers FROM " + this.tbl_server_stats + @" tss WHERE ServerID = @ServerID ) AS allrank ,
  3775.                                    tps.Playtime AS Playtime, tps.Headshots AS Headshots, tps.Rounds AS Rounds, tps.Killstreak AS Killstreak, tps.Deathstreak AS Deathstreak
  3776.                                    FROM " + this.tbl_playerdata + @" tpd
  3777.                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3778.                                    INNER JOIN " + this.tbl_playerstats + @" tps ON tps.StatsID = tsp.StatsID
  3779.                                    WHERE  tsp.ServerID = @ServerID AND tpd.SoldierName = @SoldierName";
  3780.                         }
  3781.                     }
  3782.                     using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  3783.                     {
  3784.                         DataTable resultTable;
  3785.                         double kdr = 0;
  3786.                         if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  3787.                         {
  3788.                             MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  3789.                             MyCommand.Parameters.AddWithValue("@SoldierName", strSpeaker);
  3790.                         }
  3791.                         else
  3792.                         {
  3793.                             MyCommand.Parameters.AddWithValue("@ServerID", ServerID);
  3794.                             MyCommand.Parameters.AddWithValue("@SoldierName", strSpeaker);
  3795.                         }
  3796.                         try
  3797.                         {
  3798.                             resultTable = this.SQLquery(MyCommand);
  3799.                             if (resultTable.Rows != null)
  3800.                             {
  3801.                                 foreach (DataRow row in resultTable.Rows)
  3802.                                 {
  3803.                                     result = new List<string>(this.m_lstPlayerWelcomeStatsMessage);
  3804.                                     result = this.ListReplace(result, "%serverName%", this.serverName);
  3805.                                     result = this.ListReplace(result, "%playerName%", row["SoldierName"].ToString());
  3806.                                     result = this.ListReplace(result, "%playerScore%", row["Score"].ToString());
  3807.                                     result = this.ListReplace(result, "%playerKills%", row["Kills"].ToString());
  3808.                                     result = this.ListReplace(result, "%playerDeaths%", row["Deaths"].ToString());
  3809.                                     result = this.ListReplace(result, "%playerSuicide%", row["Suicide"].ToString());
  3810.                                     result = this.ListReplace(result, "%playerTKs%", row["TKs"].ToString());
  3811.                                     result = this.ListReplace(result, "%playerRank%", row["rank"].ToString());
  3812.                                     result = this.ListReplace(result, "%allRanks%", row["allrank"].ToString());
  3813.                                     result = this.ListReplace(result, "%playerHeadshots%", row["Headshots"].ToString());
  3814.                                     result = this.ListReplace(result, "%rounds%", row["Rounds"].ToString());
  3815.                                     result = this.ListReplace(result, "%killstreak%", row["Killstreak"].ToString());
  3816.                                     result = this.ListReplace(result, "%deathstreak%", row["Deathstreak"].ToString());
  3817.                                     //KDR
  3818.                                     if (Convert.ToInt32(row["Deaths"]) != 0)
  3819.                                     {
  3820.                                         kdr = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Deaths"]);
  3821.                                         kdr = Math.Round(kdr, 2);
  3822.                                         result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  3823.                                     }
  3824.                                     else
  3825.                                     {
  3826.                                         kdr = Convert.ToDouble(row["Kills"]);
  3827.                                         result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  3828.                                     }
  3829.                                     //Playtime
  3830.                                     TimeSpan span = new TimeSpan(0, 0, Convert.ToInt32(row["Playtime"]));
  3831.                                     result = this.ListReplace(result, "%playerPlaytime%", span.ToString());
  3832.                                     //SPM
  3833.                                     double SPM;
  3834.                                     if (Convert.ToDouble(row["Playtime"]) != 0)
  3835.                                     {
  3836.                                         SPM = (Convert.ToDouble(row["Score"]) / (Convert.ToDouble(row["Playtime"]) / 60));
  3837.                                         SPM = Math.Round(SPM, 2);
  3838.                                         result = this.ListReplace(result, "%SPM%", SPM.ToString());
  3839.                                     }
  3840.                                     else
  3841.                                     {
  3842.                                         result = this.ListReplace(result, "%SPM%", "0");
  3843.                                     }
  3844.                                 }
  3845.                             }
  3846.                         }
  3847.                         catch (Exception c)
  3848.                         {
  3849.                             this.DebugInfo("Error", "WelcomeStats: " + c);
  3850.                         }
  3851.                     }
  3852.                     if (result.Count > 0)
  3853.                     {
  3854.                         //result.Insert(0, m_strPlayerWelcomeMsg.Replace("%serverName%", this.serverName).Replace("%playerName%", strSpeaker));
  3855.                     }
  3856.                     else
  3857.                     {
  3858.                         result.Clear();
  3859.                         result = new List<string>(this.m_lstNewPlayerWelcomeMsg);
  3860.                         result = this.ListReplace(result, "%serverName%", this.serverName);
  3861.                         result = this.ListReplace(result, "%playerName%", strSpeaker);
  3862.                         //result.Add(m_strNewPlayerWelcomeMsg.Replace("%serverName%", this.serverName).Replace("%playerName%", strSpeaker));
  3863.                     }
  3864.                     this.SendMultiLineChatMessage(result, int_welcomeStatsDelay, 0, "player", strSpeaker);
  3865.                 }
  3866.             }
  3867.         }
  3868.  
  3869.         private void GetPlayerStats(string strSpeaker, int delay, string scope)
  3870.         {
  3871.             List<string> result = new List<string>();
  3872.             if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  3873.             {
  3874.                 string SQL = String.Empty;
  3875.                 string strMSG = String.Empty;
  3876.                 double kdr = 0;
  3877.                 //Statsquery with KDR
  3878.                 //Rankquery
  3879.                 if (m_enRankingByScore == enumBoolYesNo.Yes)
  3880.                 {
  3881.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  3882.                     {
  3883.                         SQL = @"SELECT tpd.SoldierName, SUM(tps.Score) AS Score, SUM(tps.Kills) AS Kills, SUM(tps.Deaths) AS Deaths, SUM(tps.Suicide) AS Suicide, SUM(tps.TKs) AS TKs, tpr.rankScore AS rank, (SELECT SUM(tss.CountPlayers) FROM " + this.tbl_server_stats + @" tss INNER JOIN " + this.tbl_server + @" ts ON tss.ServerID = ts.ServerID AND ServerGroup = @ServerGroup GROUP BY ts.ServerGroup ) AS allrank , SUM(tps.Playtime) AS Playtime, SUM(tps.Headshots) AS Headshots,
  3884.                                SUM(tps.Rounds) AS Rounds, MAX(tps.Killstreak) AS Killstreak, MAX(tps.Deathstreak) AS Deathstreak  
  3885.                                FROM " + this.tbl_playerdata + @" tpd
  3886.                                INNER JOIN " + this.tbl_playerrank + @" tpr ON tpd.PlayerID = tpr.PlayerID AND tpr.ServerGroup = @ServerGroup
  3887.                                INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3888.                                INNER JOIN " + this.tbl_playerstats + @" tps ON tsp.StatsID = tps.StatsID
  3889.                                WHERE tpd.SoldierName = @SoldierName
  3890.                                GROUP BY tpd.PlayerID";
  3891.                     }
  3892.                     else
  3893.                     {
  3894.                         SQL = @"SELECT tpd.SoldierName AS SoldierName, tps.Score AS Score, tps.Kills AS Kills, tps.Deaths AS Deaths, tps.Suicide AS Suicide, tps.TKs AS TKs, tps.rankScore AS rank, (SELECT tss.CountPlayers FROM " + this.tbl_server_stats + @" tss WHERE ServerID = @ServerID ) AS allrank ,
  3895.                                tps.Playtime AS Playtime, tps.Headshots AS Headshots, tps.Rounds AS Rounds, tps.Killstreak AS Killstreak, tps.Deathstreak AS Deathstreak
  3896.                                FROM " + this.tbl_playerdata + @" tpd
  3897.                                INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3898.                                INNER JOIN " + this.tbl_playerstats + @" tps ON tps.StatsID = tsp.StatsID
  3899.                                WHERE  tsp.ServerID = @ServerID AND tpd.SoldierName = @SoldierName";
  3900.                     }
  3901.                 }
  3902.                 else
  3903.                 {
  3904.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  3905.                     {
  3906.                         SQL = @"SELECT tpd.SoldierName, SUM(tps.Score) AS Score, SUM(tps.Kills) AS Kills, SUM(tps.Deaths) AS Deaths, SUM(tps.Suicide) AS Suicide, SUM(tps.TKs) AS TKs, tpr.rankKills AS rank, (SELECT SUM(tss.CountPlayers) FROM " + this.tbl_server_stats + @" tss INNER JOIN " + this.tbl_server + @" ts ON tss.ServerID = ts.ServerID AND ServerGroup = @ServerGroup GROUP BY ts.ServerGroup ) AS allrank , SUM(tps.Playtime) AS Playtime, SUM(tps.Headshots) AS Headshots,
  3907.                                SUM(tps.Rounds) AS Rounds, MAX(tps.Killstreak) AS Killstreak, MAX(tps.Deathstreak) AS Deathstreak  
  3908.                                FROM " + this.tbl_playerdata + @" tpd
  3909.                                INNER JOIN " + this.tbl_playerrank + @" tpr ON tpd.PlayerID = tpr.PlayerID AND tpr.ServerGroup = @ServerGroup
  3910.                                INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3911.                                INNER JOIN " + this.tbl_playerstats + @" tps ON tsp.StatsID = tps.StatsID
  3912.                                WHERE tpd.SoldierName = @SoldierName
  3913.                                GROUP BY tpd.PlayerID";
  3914.                     }
  3915.                     else
  3916.                     {
  3917.                         SQL = @"SELECT tpd.SoldierName AS SoldierName, tps.Score AS Score, tps.Kills AS Kills, tps.Deaths AS Deaths, tps.Suicide AS Suicide, tps.TKs AS TKs, tps.rankKills AS rank, (SELECT tss.CountPlayers FROM " + this.tbl_server_stats + @" tss WHERE ServerID = @ServerID ) AS allrank ,
  3918.                                tps.Playtime AS Playtime, tps.Headshots AS Headshots, tps.Rounds AS Rounds, tps.Killstreak AS Killstreak, tps.Deathstreak AS Deathstreak
  3919.                                FROM " + this.tbl_playerdata + @" tpd
  3920.                                INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.PlayerID = tpd.PlayerID
  3921.                                INNER JOIN " + this.tbl_playerstats + @" tps ON tps.StatsID = tsp.StatsID
  3922.                                WHERE  tsp.ServerID = @ServerID AND tpd.SoldierName = @SoldierName";
  3923.                     }
  3924.                 }
  3925.                 using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  3926.                 {
  3927.                     DataTable resultTable;
  3928.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  3929.                     {
  3930.                         MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  3931.                         MyCommand.Parameters.AddWithValue("@SoldierName", strSpeaker);
  3932.                     }
  3933.                     else
  3934.                     {
  3935.                         MyCommand.Parameters.AddWithValue("@ServerID", ServerID);
  3936.                         MyCommand.Parameters.AddWithValue("@SoldierName", strSpeaker);
  3937.                     }
  3938.                     try
  3939.                     {
  3940.                         resultTable = this.SQLquery(MyCommand);
  3941.                         if (resultTable.Rows != null)
  3942.                         {
  3943.                             foreach (DataRow row in resultTable.Rows)
  3944.                             {
  3945.                                 result = new List<string>(m_lstPlayerStatsMessage);
  3946.                                 result = this.ListReplace(result, "%playerName%", row["SoldierName"].ToString());
  3947.                                 result = this.ListReplace(result, "%playerScore%", row["Score"].ToString());
  3948.                                 result = this.ListReplace(result, "%playerKills%", row["Kills"].ToString());
  3949.                                 result = this.ListReplace(result, "%playerDeaths%", row["Deaths"].ToString());
  3950.                                 result = this.ListReplace(result, "%playerSuicide%", row["Suicide"].ToString());
  3951.                                 result = this.ListReplace(result, "%playerTKs%", row["TKs"].ToString());
  3952.                                 result = this.ListReplace(result, "%playerRank%", row["rank"].ToString());
  3953.                                 result = this.ListReplace(result, "%allRanks%", row["allrank"].ToString());
  3954.                                 result = this.ListReplace(result, "%playerHeadshots%", row["Headshots"].ToString());
  3955.                                 result = this.ListReplace(result, "%rounds%", row["Rounds"].ToString());
  3956.                                 result = this.ListReplace(result, "%killstreak%", row["Killstreak"].ToString());
  3957.                                 result = this.ListReplace(result, "%deathstreak%", row["Deathstreak"].ToString());
  3958.                                 //KDR
  3959.                                 if (Convert.ToInt32(row["Deaths"]) != 0)
  3960.                                 {
  3961.                                     kdr = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Deaths"]);
  3962.                                     kdr = Math.Round(kdr, 2);
  3963.                                     result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  3964.                                 }
  3965.                                 else
  3966.                                 {
  3967.                                     kdr = Convert.ToDouble(row["Kills"]);
  3968.                                     result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  3969.                                 }
  3970.                                 //Playtime
  3971.                                 TimeSpan span = new TimeSpan(0, 0, Convert.ToInt32(row["Playtime"]));
  3972.                                 result = this.ListReplace(result, "%playerPlaytime%", span.ToString());
  3973.                                 //SPM
  3974.                                 double SPM;
  3975.                                 if (Convert.ToDouble(row["Playtime"]) != 0)
  3976.                                 {
  3977.                                     SPM = (Convert.ToDouble(row["Score"]) / (Convert.ToDouble(row["Playtime"]) / 60));
  3978.                                     SPM = Math.Round(SPM, 2);
  3979.                                     result = this.ListReplace(result, "%SPM%", SPM.ToString());
  3980.                                 }
  3981.                                 else
  3982.                                 {
  3983.                                     result = this.ListReplace(result, "%SPM%", "0");
  3984.                                 }
  3985.                             }
  3986.                         }
  3987.                     }
  3988.                     catch (Exception c)
  3989.                     {
  3990.                         this.DebugInfo("Error", "GetPlayerStats: " + c);
  3991.                     }
  3992.                 }
  3993.                 if (result.Count != 0)
  3994.                 {
  3995.                     this.SendMultiLineChatMessage(result, delay,0 , scope, strSpeaker);
  3996.                 }
  3997.                 else
  3998.                 {
  3999.                     result.Clear();
  4000.                     result.Add("No Stats are available yet! Please wait one Round!");
  4001.                     this.SendMultiLineChatMessage(result, delay,0 , scope, strSpeaker);
  4002.                 }
  4003.             }
  4004.         }
  4005.  
  4006.         private void GetTop10(string strSpeaker, int delay, string scope)
  4007.         {
  4008.             List<string> result = new List<string>();
  4009.             if (this.m_enTop10ingame == enumBoolYesNo.Yes)
  4010.             {
  4011.                 string SQL = String.Empty;
  4012.                 int rank = 0;
  4013.                 //Top10 Query
  4014.                 if (this.m_enRankingByScore == enumBoolYesNo.Yes)
  4015.                 {
  4016.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4017.                     {
  4018.                         SQL = @"SELECT tpd.SoldierName, SUM(tps.Score) AS Score, SUM(tps.Kills) AS Kills, SUM(tps.Deaths) AS Deaths , SUM(tps.Headshots) AS Headshots  
  4019.                             FROM " + this.tbl_playerstats + @" tps
  4020.                             INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID
  4021.                             INNER JOIN " + this.tbl_playerdata + @" tpd ON tsp.PlayerID = tpd.PlayerID
  4022.                             INNER JOIN " + this.tbl_playerrank + @" tpr ON tpr.PlayerID = tsp.PlayerID
  4023.                             WHERE tpr.ServerGroup = @ServerGroup AND tpr.rankScore BETWEEN 1 AND 10
  4024.                             GROUP BY tsp.PlayerID
  4025.                             ORDER BY tpr.rankScore ASC";
  4026.                     }
  4027.                     else
  4028.                     {
  4029.                         SQL = @"SELECT tpd.SoldierName, tps.Score, tps.Kills, tps.Deaths, tps.Headshots
  4030.                             FROM " + this.tbl_playerstats + @" tps
  4031.                             INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID
  4032.                             INNER JOIN " + this.tbl_playerdata + @" tpd ON tsp.PlayerID = tpd.PlayerID
  4033.                             WHERE tsp.ServerID = @ServerID AND tps.rankScore BETWEEN 1 AND 10
  4034.                             ORDER BY tps.rankScore ASC";
  4035.                     }
  4036.                 }
  4037.                 else
  4038.                 {
  4039.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4040.                     {
  4041.                         SQL = @"SELECT tpd.SoldierName, SUM(tps.Score) AS Score, SUM(tps.Kills) AS Kills, SUM(tps.Deaths) AS Deaths , SUM(tps.Headshots) AS Headshots  
  4042.                             FROM " + this.tbl_playerstats + @" tps
  4043.                             INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID
  4044.                             INNER JOIN " + this.tbl_playerdata + @" tpd ON tsp.PlayerID = tpd.PlayerID
  4045.                             INNER JOIN " + this.tbl_playerrank + @" tpr ON tpr.PlayerID = tsp.PlayerID
  4046.                             WHERE tpr.ServerGroup = @ServerGroup AND tpr.rankKills BETWEEN 1 AND 10
  4047.                             GROUP BY tsp.PlayerID
  4048.                             ORDER BY tpr.rankKills ASC";
  4049.                     }
  4050.                     else
  4051.                     {
  4052.                         SQL = @"SELECT tpd.SoldierName, tps.Score, tps.Kills, tps.Deaths, tps.Headshots
  4053.                             FROM " + this.tbl_playerstats + @" tps
  4054.                             INNER JOIN " + this.tbl_server_player + @" tsp ON  tsp.StatsID = tps.StatsID
  4055.                             INNER JOIN " + this.tbl_playerdata + @" tpd ON tsp.PlayerID = tpd.PlayerID
  4056.                             WHERE tsp.ServerID = @ServerID AND tps.rankKills BETWEEN 1 AND 10
  4057.                             ORDER BY tps.rankKills ASC";
  4058.                     }
  4059.                 }
  4060.                 using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  4061.                 {
  4062.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4063.                     {
  4064.                         MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4065.                     }
  4066.                     else
  4067.                     {
  4068.                         MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4069.                     }
  4070.                     DataTable resultTable;
  4071.                     try
  4072.                     {
  4073.                         resultTable = this.SQLquery(MyCommand);
  4074.                         result = new List<string>();
  4075.                         //Top 10 Header
  4076.                         result.Add(this.m_strTop10Header.Replace("%serverName%", this.serverName));
  4077.                         StringBuilder Top10Row = new StringBuilder();
  4078.                         double kdr1;
  4079.                         double khr;
  4080.                         if (resultTable.Rows != null)
  4081.                         {
  4082.                             foreach (DataRow row in resultTable.Rows)
  4083.                             {
  4084.                                 Top10Row.Append(this.m_strTop10RowFormat);
  4085.  
  4086.                                 if (Convert.ToDouble(row["Deaths"]) != 0)
  4087.                                 {
  4088.                                     kdr1 = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Deaths"]);
  4089.                                     Top10Row.Replace("%playerKDR%", Math.Round(kdr1, 2).ToString());
  4090.                                 }
  4091.                                 else
  4092.                                 {
  4093.                                     Top10Row.Replace("%playerKDR%", Convert.ToDouble(row["Kills"]).ToString());
  4094.                                 }
  4095.  
  4096.                                 if (Convert.ToDouble(row["Headshots"]) != 0)
  4097.                                 {
  4098.                                     khr = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Headshots"]);
  4099.                                     khr = Math.Round(khr, 4);
  4100.                                     khr = khr * 100;
  4101.                                     Top10Row.Replace("%playerKHR%", khr.ToString());
  4102.                                 }
  4103.                                 else
  4104.                                 {
  4105.                                     khr = 0;
  4106.                                 }
  4107.                                 rank = rank + 1;
  4108.                                 Top10Row.Replace("%Rank%", rank.ToString()).Replace("%playerName%", row["SoldierName"].ToString()).Replace("%playerScore%", row["Score"].ToString()).Replace("%playerKills%", row["Kills"].ToString());
  4109.                                 Top10Row.Replace("%playerDeaths%", row["Deaths"].ToString()).Replace("%playerHeadshots%", row["Headshots"].ToString());
  4110.                                 result.Add(Top10Row.ToString());
  4111.                                 Top10Row.Length = 0;
  4112.                             }
  4113.                         }
  4114.                     }
  4115.                     catch (Exception c)
  4116.                     {
  4117.                         this.DebugInfo("Error", "GetTop10: " + c);
  4118.                     }
  4119.                 }
  4120.                 if (result.Count > 0)
  4121.                 {
  4122.                     this.SendMultiLineChatMessage(result, 0, delay, scope, strSpeaker);
  4123.                 }
  4124.             }
  4125.         }
  4126.  
  4127.         private void GetWeaponStats(string strWeapon, string strPlayer, string scope)
  4128.         {
  4129.  
  4130.             this.DebugInfo("Trace", "GetWeaponStats: " + strPlayer + " " + strWeapon);
  4131.             int delay = 0;
  4132.             string SQL = String.Empty;
  4133.             List<string> result = new List<string>();
  4134.  
  4135.             if (this.DamageClass.ContainsKey(strWeapon) == true)
  4136.             //if (this.WeaponMappingDic.ContainsKey(strWeapon) == true)
  4137.             {
  4138.                 if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4139.                 {
  4140.                     SQL = @"SELECT `Kills`, `Headshots`, `Deaths`, rank, (SELECT COUNT(DISTINCT PlayerID) FROM " + this.tbl_server_player + @" tsp INNER JOIN " + this.tbl_server + @" ts  ON ts.ServerID = tsp.ServerID AND ts.ServerGroup = @ServerGroup) AS allrank
  4141.                            FROM (SELECT sub.PlayerID, (@num := @num + 1) AS rank, `Kills`, `Headshots`, `Deaths`
  4142.                                 FROM
  4143.                                 (SELECT tsp.PlayerID, SUM(`Kills`) AS `Kills`, SUM(`Headshots`) AS `Headshots`, SUM(`Deaths`) AS `Deaths`
  4144.                                 FROM " + this.tbl_weapons_stats + @" tw
  4145.                                 INNER JOIN " + this.tbl_server_player + @" tsp ON tw.StatsID = tsp.StatsID
  4146.                                 INNER JOIN " + this.tbl_server + @" tserver ON tsp.ServerID = tserver.ServerID AND tserver.ServerGroup = @ServerGroup ,(SELECT @num := 0) x
  4147.                                 WHERE tw.WeaponID = @WeaponID
  4148.                                 GROUP BY tsp.PlayerID
  4149.                                 ORDER BY `Kills` DESC, `Headshots` DESC) sub )sub2
  4150.                            INNER JOIN " + this.tbl_playerdata + @" tpd ON tpd.PlayerID = sub2.PlayerID
  4151.                            WHERE tpd.SoldierName = @SoldierName AND tpd.GameID = @GameID LIMIT 1";
  4152.                 }
  4153.                 else
  4154.                 {
  4155.                     SQL = @"SELECT
  4156.                            Kills,
  4157.                            Headshots,
  4158.                            Deaths,
  4159.                            (SELECT
  4160.                                    rank
  4161.                                FROM
  4162.                                    (SELECT
  4163.                                        @rownum:=@rownum + 1 AS rank, sub.PlayerID
  4164.                                    FROM
  4165.                                        (SELECT @rownum:=0) r, (SELECT
  4166.                                        tsp.PlayerID
  4167.                                    FROM
  4168.                                         " + this.tbl_weapons_stats + @" tw
  4169.                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.ServerID = @ServerID
  4170.                                        AND tw.StatsID = tsp.StatsID
  4171.                                    WHERE
  4172.                                        tw.WeaponID = @WeaponID
  4173.                                    ORDER BY tw.Kills DESC , tw.Headshots DESC) sub) sub2
  4174.                                WHERE
  4175.                                    PlayerID = tpd.PlayerID
  4176.                                LIMIT 1) AS rank,
  4177.                            (SELECT
  4178.                                    COUNT(*)
  4179.                                FROM
  4180.                                    " + this.tbl_server_player + @"
  4181.                                WHERE
  4182.                                    ServerID = @ServerID) AS allrank
  4183.                        FROM
  4184.                            " + this.tbl_weapons_stats + @" tw
  4185.                                INNER JOIN
  4186.                            " + this.tbl_server_player + @" tsp ON tw.StatsID = tsp.StatsID
  4187.                                AND tsp.ServerID = @ServerID
  4188.                                INNER JOIN
  4189.                            " + this.tbl_playerdata + @" tpd ON tpd.PlayerID = tsp.PlayerID
  4190.                        WHERE
  4191.                            tpd.SoldierName = @SoldierName
  4192.                                AND tpd.GameID = @GameID
  4193.                                AND WeaponID = @WeaponID
  4194.                        LIMIT 1";
  4195.                 }
  4196.  
  4197.                 this.DebugInfo("Trace", "GetWeaponStats: Query:" + SQL);
  4198.                 using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  4199.                 {
  4200.                     //MyCommand.Parameters.AddWithValue("@WeaponID", this.weaponDic[this.DamageClass[strWeapon]][strWeapon].Name);
  4201.                     MyCommand.Parameters.AddWithValue("@WeaponID", this.WeaponMappingDic[this.weaponDic[this.DamageClass[strWeapon]][strWeapon].Name]);
  4202.                     MyCommand.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  4203.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4204.                     {
  4205.                         MyCommand.Parameters.AddWithValue("@SoldierName", strPlayer);
  4206.                         MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4207.                     }
  4208.                     else
  4209.                     {
  4210.                         MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4211.                         MyCommand.Parameters.AddWithValue("@SoldierName", strPlayer);
  4212.                     }
  4213.                     try
  4214.                     {
  4215.                         DataTable resultTable = this.SQLquery(MyCommand);
  4216.                         if (resultTable.Rows != null)
  4217.                         {
  4218.                             foreach (DataRow row in resultTable.Rows)
  4219.                             {
  4220.                                 result = new List<string>(this.m_lstWeaponstatsMsg);
  4221.                                 if (row[0] != Convert.DBNull || row[1] != Convert.DBNull || row[2] != Convert.DBNull)
  4222.                                 {
  4223.                                     result = this.ListReplace(result, "%playerKills%", row[0].ToString());
  4224.                                     result = this.ListReplace(result, "%playerHeadshots%", row[1].ToString());
  4225.                                     result = this.ListReplace(result, "%playerDeaths%", row[2].ToString());
  4226.                                     result = this.ListReplace(result, "%playerRank%", row[3].ToString());
  4227.                                     result = this.ListReplace(result, "%allRanks%", row[4].ToString());
  4228.  
  4229.                                     double khr = 0;
  4230.                                     if (Convert.ToDouble(row[0]) != 0)
  4231.                                     {
  4232.                                         khr = Convert.ToDouble(row[1]) / Convert.ToDouble(row[0]);
  4233.                                         khr = Math.Round(khr, 2);
  4234.                                         khr = khr * 100;
  4235.                                     }
  4236.                                     else
  4237.                                     {
  4238.                                         khr = 0;
  4239.                                     }
  4240.                                     double kdr = 0;
  4241.                                     if (Convert.ToDouble(row[2]) != 0)
  4242.                                     {
  4243.                                         kdr = Convert.ToDouble(row[0]) / Convert.ToDouble(row[2]);
  4244.                                         kdr = Math.Round(kdr, 2);
  4245.                                     }
  4246.                                     else
  4247.                                     {
  4248.                                         kdr = Convert.ToDouble(row[2]);
  4249.                                     }
  4250.                                     result = this.ListReplace(result, "%playerKHR%", khr.ToString());
  4251.                                     result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  4252.                                 }
  4253.                                 else
  4254.                                 {
  4255.                                     result.Clear();
  4256.                                 }
  4257.                             }
  4258.                         }
  4259.                     }
  4260.                     catch (Exception c)
  4261.                     {
  4262.                         this.DebugInfo("Error", "GetWeaponStats: " + c);
  4263.                     }
  4264.                 }
  4265.                 result = this.ListReplace(result, "%playerName%", strPlayer);
  4266.                 result = this.ListReplace(result, "%Weapon%", this.weaponDic[this.DamageClass[strWeapon]][strWeapon].FieldName);
  4267.                 if (result.Count > 0)
  4268.                 {
  4269.                     this.SendMultiLineChatMessage(result, delay, 0, scope, strPlayer);
  4270.                 }
  4271.                 else
  4272.                 {
  4273.                     result.Clear();
  4274.                     result.Add("No Stats are available for this Weapon!!!");
  4275.                     this.SendMultiLineChatMessage(result, delay, 0, scope, strPlayer);
  4276.                 }
  4277.             }
  4278.             else
  4279.             {
  4280.                 result.Clear();
  4281.                 result.Add("Specific Weapon not found!!");
  4282.                 this.SendMultiLineChatMessage(result, delay, 0, scope, strPlayer);
  4283.             }
  4284.         }
  4285.  
  4286.         private void GetWeaponTop10(string strWeapon, string strPlayer, int delay, string scope)
  4287.         {
  4288.             this.DebugInfo("Trace", "GetWeaponTop10: strWeapon = " + strWeapon);
  4289.             int delaytop10 = 0;
  4290.             double kdr = 0;
  4291.             double khr = 0;
  4292.             int rank = 0;
  4293.             string SQL = String.Empty;
  4294.             List<string> result = new List<string>();
  4295.             if (this.DamageClass.ContainsKey(strWeapon) == true)
  4296.             {
  4297.                 //string tbl_weapons = "tbl_weapons_" + this.DamageClass[strWeapon].ToLower() + this.tableSuffix;
  4298.                 if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4299.                 {
  4300.                     SQL = @"SELECT tpd.SoldierName, SUM(`Kills`) AS `Kills`, SUM(`Headshots`) AS `Headshots`, SUM(`Deaths`) AS `Deaths`
  4301.                             FROM " + this.tbl_weapons_stats + @" tw
  4302.                             INNER JOIN " + this.tbl_server_player + @" tsp ON tw.StatsID = tsp.StatsID
  4303.                             INNER JOIN " + this.tbl_playerdata + @" tpd ON tpd.PlayerID = tsp.PlayerID
  4304.                            INNER JOIN " + this.tbl_server + @" ts ON ts.ServerID = tsp.ServerID
  4305.                            WHERE ts.ServerGroup = @ServerGroup AND tw.WeaponID = @WeaponID
  4306.                             GROUP BY tsp.PlayerID
  4307.                             ORDER BY SUM(`Kills`)` DESC, SUM(`Headshots`) DESC
  4308.                             LIMIT 10";
  4309.                 }
  4310.                 else
  4311.                 {
  4312.                     SQL = @"SELECT tpd.SoldierName, `Kills`, `Headshots`, `Deaths`
  4313.                             FROM " + this.tbl_weapons_stats + @" tw
  4314.                             INNER JOIN " + this.tbl_server_player + @" tsp ON tw.StatsID = tsp.StatsID
  4315.                             INNER JOIN " + this.tbl_playerdata + @" tpd ON tpd.PlayerID = tsp.PlayerID
  4316.                             WHERE tsp.ServerID = @ServerID AND tw.WeaponID = @WeaponID
  4317.                             ORDER BY `Kills` DESC, `Headshots` DESC
  4318.                             LIMIT 10";
  4319.                 }
  4320.  
  4321.                 //SQL = SQL.Replace("%Weapon%", this.weaponDic[this.DamageClass[strWeapon]][strWeapon].FieldName);
  4322.  
  4323.                 this.DebugInfo("Trace", "GetWeaponTop10: Query:" + SQL);
  4324.  
  4325.                 using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  4326.                 {
  4327.                     MyCommand.Parameters.AddWithValue("@WeaponID", this.WeaponMappingDic[this.weaponDic[this.DamageClass[strWeapon]][strWeapon].Name]);
  4328.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4329.                     {
  4330.                         MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4331.                     }
  4332.                     else
  4333.                     {
  4334.                         MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4335.                     }
  4336.                     DataTable resultTable;
  4337.                     try
  4338.                     {
  4339.                         result = new List<string>();
  4340.                         //result.Add("Top 10 Killers with %Weapon%");
  4341.                         result.Add(this.m_strWeaponTop10Header.Replace("%serverName%", this.serverName));
  4342.                         resultTable = this.SQLquery(MyCommand);
  4343.                         StringBuilder Top10Row = new StringBuilder(this.m_strWeaponTop10RowFormat);
  4344.                         if (resultTable.Rows != null)
  4345.                         {
  4346.                             foreach (DataRow row in resultTable.Rows)
  4347.                             {
  4348.                                 if (Convert.ToDouble(row[3]) != 0)
  4349.                                 {
  4350.                                     kdr = Convert.ToDouble(row[1]) / Convert.ToDouble(row[3]);
  4351.                                     kdr = Math.Round(kdr, 2);
  4352.                                 }
  4353.                                 else
  4354.                                 {
  4355.                                     kdr = Convert.ToDouble(row[1]);
  4356.                                 }
  4357.                                 if (Convert.ToDouble(row[1]) != 0)
  4358.                                 {
  4359.                                     khr = Convert.ToDouble(row[2]) / Convert.ToDouble(row[1]);
  4360.                                     khr = Math.Round(khr, 4);
  4361.                                     khr = khr * 100;
  4362.                                 }
  4363.                                 else
  4364.                                 {
  4365.                                     khr = 0;
  4366.                                 }
  4367.                                 Top10Row.Length = 0;
  4368.                                 Top10Row.Append(this.m_strWeaponTop10RowFormat);
  4369.                                 rank = rank + 1;
  4370.                                 Top10Row.Replace("%Rank%", rank.ToString()).Replace("%playerName%", row[0].ToString()).Replace("%playerKills%", row[1].ToString()).Replace("%playerHeadshots%", row[2].ToString()).Replace("%playerDeaths%", row[3].ToString()).Replace("%playerKHR%", khr.ToString());
  4371.                                 result.Add(Top10Row.ToString());
  4372.                             }
  4373.                         }
  4374.                     }
  4375.                     catch (Exception c)
  4376.                     {
  4377.                         this.DebugInfo("Error", "GetWeaponTop10: " + c);
  4378.                     }
  4379.                 }
  4380.                 result = this.ListReplace(result, "%Player%", strPlayer);
  4381.                 result = this.ListReplace(result, "%Weapon%", this.weaponDic[this.DamageClass[strWeapon]][strWeapon].FieldName);
  4382.                 if (result.Count > 0)
  4383.                 {
  4384.                     this.SendMultiLineChatMessage(result, 0, delay, scope, strPlayer);
  4385.                 }
  4386.                 else
  4387.                 {
  4388.                     result.Clear();
  4389.                     result.Add("No Stats are available for this Weapon!!!");
  4390.                     this.SendMultiLineChatMessage(result, 0, delay, scope, strPlayer);
  4391.                 }
  4392.             }
  4393.             else
  4394.             {
  4395.                 result.Clear();
  4396.                 result.Add("Specific Weapon not found!!");
  4397.                 this.SendMultiLineChatMessage(result, 0, delay, scope, strPlayer);
  4398.             }
  4399.         }
  4400.  
  4401.         private void GetDogtags(string strPlayer, int delay, string scope)
  4402.         {
  4403.             int delaydogtags = 0;
  4404.             string SQL = String.Empty;
  4405.             string SQL2 = String.Empty;
  4406.             if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4407.             {
  4408.                 SQL = @"SELECT pd.SoldierName, SUM(dt.Count) AS Count
  4409.                        FROM " + this.tbl_server_player + @" sp
  4410.                        INNER JOIN " + this.tbl_server + @" ts ON ts.ServerID = sp.ServerID AND ts.ServerGroup = @ServerGroup
  4411.                        INNER JOIN " + this.tbl_dogtags + @" dt ON sp.StatsID = dt.VictimID
  4412.                        INNER JOIN " + this.tbl_playerdata + @" pd ON sp.PlayerID = pd.PlayerID
  4413.                        WHERE KillerID IN (SELECT StatsID AS KillerID FROM " + this.tbl_server_player + @" WHERE PlayerID = @KillerID)
  4414.                        GROUP BY pd.PlayerID ORDER BY Count DESC Limit 3";
  4415.  
  4416.                 SQL2 = @"SELECT pd.SoldierName, SUM(dt.Count) AS Count
  4417.                         FROM " + this.tbl_server_player + @"  sp
  4418.                         INNER JOIN " + this.tbl_server + @" ts ON ts.ServerID = sp.ServerID AND ts.ServerGroup = @ServerGroup
  4419.                         INNER JOIN " + this.tbl_dogtags + @"  dt ON sp.StatsID = dt.KillerID
  4420.                         INNER JOIN " + this.tbl_playerdata + @"  pd ON sp.PlayerID = pd.PlayerID
  4421.                         WHERE VictimID IN (SELECT StatsID AS VictimID FROM " + this.tbl_server_player + @"  WHERE PlayerID = @VictimID)
  4422.                         GROUP BY pd.PlayerID ORDER BY Count DESC Limit 3";
  4423.             }
  4424.             else
  4425.             {
  4426.                 SQL = @"SELECT pd.SoldierName, dt.Count
  4427.                        FROM " + this.tbl_server_player + @" sp
  4428.                        INNER JOIN " + this.tbl_dogtags + @" dt ON sp.StatsID = dt.VictimID
  4429.                        INNER JOIN " + this.tbl_playerdata + @" pd ON sp.PlayerID = pd.PlayerID
  4430.                        WHERE KillerID = @KillerID AND sp.ServerID = @ServerID
  4431.                        ORDER BY Count DESC Limit 3";
  4432.  
  4433.                 SQL2 = @"SELECT pd.SoldierName, dt.Count
  4434.                         FROM " + this.tbl_server_player + @" sp
  4435.                         INNER JOIN " + this.tbl_dogtags + @" dt ON sp.StatsID = dt.KillerID
  4436.                         INNER JOIN " + this.tbl_playerdata + @" pd ON sp.PlayerID = pd.PlayerID
  4437.                         WHERE VictimID = @VictimID AND sp.ServerID = @ServerID
  4438.                         ORDER BY Count DESC Limit 3";
  4439.             }
  4440.  
  4441.             List<string> result = new List<string>();
  4442.             List<string> result2 = new List<string>();
  4443.  
  4444.             if (this.StatsTracker.ContainsKey(strPlayer) == false)
  4445.             {
  4446.                 return;
  4447.             }
  4448.  
  4449.             using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  4450.             {
  4451.                 if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4452.                 {
  4453.                     MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4454.                     MyCommand.Parameters.AddWithValue("@KillerID", this.GetID(this.StatsTracker[strPlayer].EAGuid).Id);
  4455.                 }
  4456.                 else
  4457.                 {
  4458.                     MyCommand.Parameters.AddWithValue("@KillerID", this.GetID(this.StatsTracker[strPlayer].EAGuid).StatsID);
  4459.                     MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4460.                 }
  4461.                 try
  4462.                 {
  4463.                     result = new List<string>();
  4464.                     result.Add("Your favorite Victims:");
  4465.                     DataTable resultTable = this.SQLquery(MyCommand);
  4466.                     if (resultTable.Rows.Count > 0)
  4467.                     {
  4468.                         foreach (DataRow row in resultTable.Rows)
  4469.                         {
  4470.                             result.Add(" " + row["Count"] + "x  " + row["SoldierName"]);
  4471.                         }
  4472.                     }
  4473.                     else
  4474.                     {
  4475.                         result.Add("None - Get some dogtags!!");
  4476.                     }
  4477.                     resultTable.Dispose();
  4478.                 }
  4479.                 catch (Exception c)
  4480.                 {
  4481.                     this.DebugInfo("Error", "GetDogtags: " + c);
  4482.                 }
  4483.             }
  4484.             using (MySqlCommand MyCommand = new MySqlCommand(SQL2))
  4485.             {
  4486.                 if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4487.                 {
  4488.                     MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4489.                     MyCommand.Parameters.AddWithValue("@VictimID", this.GetID(this.StatsTracker[strPlayer].EAGuid).Id);
  4490.                 }
  4491.                 else
  4492.                 {
  4493.                     MyCommand.Parameters.AddWithValue("@VictimID", this.GetID(this.StatsTracker[strPlayer].EAGuid).StatsID);
  4494.                     MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4495.                 }
  4496.                 try
  4497.                 {
  4498.                     result2 = new List<string>();
  4499.                     result2.Add("Your worst Enemies:");
  4500.                     DataTable resultTable = this.SQLquery(MyCommand);
  4501.                     if (resultTable.Rows.Count > 0)
  4502.                     {
  4503.                         foreach (DataRow row in resultTable.Rows)
  4504.                         {
  4505.                             result2.Add(" " + row["Count"] + "x  " + row["SoldierName"]);
  4506.                         }
  4507.                     }
  4508.                     else
  4509.                     {
  4510.                         result2.Add("Nobody got your Tag yet!");
  4511.                     }
  4512.                     resultTable.Dispose();
  4513.                 }
  4514.                 catch (Exception c)
  4515.                 {
  4516.                     this.ExecuteCommand("procon.protected.pluginconsole.write", "Error in GetDogtags: " + c);
  4517.                 }
  4518.             }
  4519.             this.CloseMySqlConnection(1);
  4520.             result.AddRange(result2);
  4521.             if (result[0].Equals("0") == false)
  4522.             {
  4523.                 this.SendMultiLineChatMessage(result, delaydogtags, delay, scope, strPlayer);
  4524.             }
  4525.             else
  4526.             {
  4527.                 result.Clear();
  4528.                 result.Add("No Stats are available!!!");
  4529.                 this.SendMultiLineChatMessage(result, delaydogtags, delay, scope, strPlayer);
  4530.             }
  4531.         }
  4532.  
  4533.         private void GetPlayerOfTheDay(string strSpeaker, int delay, string scope)
  4534.         {
  4535.             List<string> result = new List<string>();
  4536.             if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  4537.             {
  4538.                 string SQL = string.Empty;
  4539.  
  4540.                 string SQL_SELECT = @"SELECT
  4541.                                tpd.SoldierName AS SoldierName,
  4542.                                SUM(ts.Score) AS Score,
  4543.                                SUM(ts.Kills) AS Kills,
  4544.                                SUM(ts.Headshots) AS Headshots,
  4545.                                SUM(ts.Deaths) AS Deaths,
  4546.                                SUM(ts.TKs) AS TKs,
  4547.                                SUM(ts.Suicide) AS Suicide,
  4548.                                SUM(ts.RoundCount ) AS RoundCount,
  4549.                                SUM(ts.Playtime) AS Playtime,
  4550.                                MAX(ts.Killstreak) AS Killstreak,
  4551.                                MAX(ts.Deathstreak) AS Deathstreak,
  4552.                                MAX(ts.HighScore) AS HighScore,
  4553.                                SUM(ts.Wins ) AS Wins,
  4554.                                SUM(ts.Losses ) AS Losses, ";
  4555.  
  4556.  
  4557.                 string SQL_JOINS = @" FROM " + this.tbl_sessions + @" ts
  4558.                                      INNER JOIN " + this.tbl_server_player + @" tsp USING(StatsID)
  4559.                                      INNER JOIN " + this.tbl_playerdata + @" tpd USING(PlayerID) ";
  4560.  
  4561.                 string SQL_CONDS = string.Empty;
  4562.  
  4563.                 string strMSG = String.Empty;
  4564.                 double kdr = 0;
  4565.                 //Statsquery with KDR
  4566.                 //Rankquery
  4567.                 if (m_enRankingByScore == enumBoolYesNo.Yes)
  4568.                 {
  4569.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4570.                     {
  4571.                         //Ranking by Score overall Server
  4572.                         SQL_SELECT = SQL_SELECT + @"(SELECT SUM(tss.CountPlayers) FROM " + this.tbl_server_stats + @" tss INNER JOIN " + this.tbl_server + @" ts ON tss.ServerID = ts.ServerID AND ServerGroup = @ServerGroup GROUP BY ts.ServerGroup ) AS allrank, tpr.rankScore AS rank ";
  4573.  
  4574.                         SQL_JOINS = SQL_JOINS + @" INNER JOIN " + this.tbl_server + @" ts2 USING(ServerID)
  4575.                                                   INNER JOIN " + this.tbl_playerrank + @" tpr USING(PlayerID)";
  4576.  
  4577.                         SQL_CONDS = @" WHERE ts.StartTime >= CURRENT_DATE() AND ts2.ServerGroup = @ServerGroup
  4578.                                       Group BY tsp.StatsID
  4579.                                       ORDER BY SUM(ts.Score) DESC ";
  4580.                     }
  4581.                     else
  4582.                     {
  4583.                         //Ranking by Score specfic Server
  4584.                         SQL_SELECT = SQL_SELECT + @"(SELECT tss.CountPlayers FROM " + this.tbl_server_stats + @" tss WHERE ServerID = @ServerID ) AS allrank, tps.rankScore AS rank ";
  4585.  
  4586.                         SQL_JOINS = SQL_JOINS + @" INNER JOIN " + this.tbl_playerstats + @" tps USING(StatsID) ";
  4587.  
  4588.                         SQL_CONDS = @" WHERE ts.StartTime >= CURRENT_DATE() AND tsp.ServerID = @ServerID
  4589.                                       Group BY tsp.StatsID
  4590.                                       ORDER BY SUM(ts.Score) DESC ";
  4591.                     }
  4592.                 }
  4593.                 else
  4594.                 {
  4595.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4596.                     {
  4597.  
  4598.                         //Ranking by Kills overall Server
  4599.                         SQL_SELECT = SQL_SELECT + @"(SELECT SUM(tss.CountPlayers) FROM " + this.tbl_server_stats + @" tss INNER JOIN " + this.tbl_server + @" ts ON tss.ServerID = ts.ServerID AND ServerGroup = @ServerGroup GROUP BY ts.ServerGroup ) AS allrank, tpr.rankKills AS rank ";
  4600.  
  4601.                         SQL_JOINS = SQL_JOINS + @" INNER JOIN " + this.tbl_server + @" ts2 USING(ServerID)  
  4602.                                                   INNER JOIN " + this.tbl_playerrank + @" tpr USING(PlayerID)";
  4603.  
  4604.                         SQL_CONDS = @" WHERE ts.StartTime >= CURRENT_DATE() AND ts2.ServerGroup = @ServerGroup
  4605.                                       Group BY tsp.StatsID
  4606.                                       ORDER BY SUM(ts.Kills) DESC, SUM(ts.Deaths) ASC ";
  4607.                     }
  4608.                     else
  4609.                     {
  4610.                         //Ranking by Kills specfic Server
  4611.                         SQL_SELECT = SQL_SELECT + @"(SELECT tss.CountPlayers FROM " + this.tbl_server_stats + @" tss WHERE ServerID = @ServerID ) AS allrank , tps.rankKills AS rank  ";
  4612.  
  4613.                         SQL_JOINS = SQL_JOINS + @" INNER JOIN " + this.tbl_playerstats + @" tps USING(StatsID) ";
  4614.  
  4615.                         SQL_CONDS = @" WHERE ts.StartTime >= CURRENT_DATE() AND tsp.ServerID = @ServerID
  4616.                                       Group BY tsp.StatsID
  4617.                                       ORDER BY SUM(ts.Kills) DESC, SUM(ts.Deaths) ASC ";
  4618.                     }
  4619.                 }
  4620.                 //Add LIMIT
  4621.                 SQL = SQL_SELECT + SQL_JOINS + SQL_CONDS + @" LIMIT 1";
  4622.                 using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  4623.                 {
  4624.                     DataTable resultTable;
  4625.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4626.                     {
  4627.                         MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4628.                     }
  4629.                     else
  4630.                     {
  4631.                         MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4632.                     }
  4633.                     try
  4634.                     {
  4635.                         resultTable = this.SQLquery(MyCommand);
  4636.                         if (resultTable.Rows != null)
  4637.                         {
  4638.                             foreach (DataRow row in resultTable.Rows)
  4639.                             {
  4640.                                 result = new List<string>(m_lstPlayerOfTheDayMessage);
  4641.                                 result = this.ListReplace(result, "%playerName%", row["SoldierName"].ToString());
  4642.                                 result = this.ListReplace(result, "%playerScore%", row["Score"].ToString());
  4643.                                 result = this.ListReplace(result, "%playerKills%", row["Kills"].ToString());
  4644.                                 result = this.ListReplace(result, "%playerDeaths%", row["Deaths"].ToString());
  4645.                                 result = this.ListReplace(result, "%playerSuicide%", row["Suicide"].ToString());
  4646.                                 result = this.ListReplace(result, "%playerTKs%", row["TKs"].ToString());
  4647.                                 result = this.ListReplace(result, "%playerRank%", row["rank"].ToString());
  4648.                                 result = this.ListReplace(result, "%allRanks%", row["allrank"].ToString());
  4649.                                 result = this.ListReplace(result, "%playerHeadshots%", row["Headshots"].ToString());
  4650.                                 result = this.ListReplace(result, "%rounds%", row["RoundCount"].ToString());
  4651.                                 result = this.ListReplace(result, "%killstreak%", row["Killstreak"].ToString());
  4652.                                 result = this.ListReplace(result, "%deathstreak%", row["Deathstreak"].ToString());
  4653.                                 //KDR
  4654.                                 if (Convert.ToInt32(row["Deaths"]) != 0)
  4655.                                 {
  4656.                                     kdr = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Deaths"]);
  4657.                                     kdr = Math.Round(kdr, 2);
  4658.                                     result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  4659.                                 }
  4660.                                 else
  4661.                                 {
  4662.                                     kdr = Convert.ToDouble(row["Kills"]);
  4663.                                     result = this.ListReplace(result, "%playerKDR%", kdr.ToString());
  4664.                                 }
  4665.                                 //Playtime
  4666.                                 TimeSpan span = new TimeSpan(0, 0, Convert.ToInt32(row["Playtime"]));
  4667.                                 result = this.ListReplace(result, "%playerPlaytime%", span.ToString());
  4668.                                 //SPM
  4669.                                 double SPM;
  4670.                                 if (Convert.ToDouble(row["Playtime"]) != 0)
  4671.                                 {
  4672.                                     SPM = (Convert.ToDouble(row["Score"]) / (Convert.ToDouble(row["Playtime"]) / 60));
  4673.                                     SPM = Math.Round(SPM, 2);
  4674.                                     result = this.ListReplace(result, "%SPM%", SPM.ToString());
  4675.                                 }
  4676.                                 else
  4677.                                 {
  4678.                                     result = this.ListReplace(result, "%SPM%", "0");
  4679.                                 }
  4680.                             }
  4681.                         }
  4682.                     }
  4683.                     catch (Exception c)
  4684.                     {
  4685.                         this.DebugInfo("Error", "GetPlayerOfTheDay: " + c);
  4686.                     }
  4687.                 }
  4688.                 if (result.Count != 0)
  4689.                 {
  4690.                     this.SendMultiLineChatMessage(result, delay, 0, scope, strSpeaker);
  4691.                 }
  4692.                 else
  4693.                 {
  4694.                     result.Clear();
  4695.                     result.Add("No Stats are available yet! Please wait one Round!");
  4696.                     this.SendMultiLineChatMessage(result, delay, 0, scope, strSpeaker);
  4697.                 }
  4698.             }
  4699.         }
  4700.  
  4701.         private void GetTop10ForPeriod(string strSpeaker, int delay, string scope, int intdays)
  4702.         {
  4703.             List<string> result = new List<string>();
  4704.             if (this.m_enTop10ingame == enumBoolYesNo.Yes)
  4705.             {
  4706.                 string SQL = @"SELECT
  4707.                                tpd.SoldierName AS SoldierName,
  4708.                                SUM(ts.Score) AS Score,
  4709.                                SUM(ts.Kills) AS Kills,
  4710.                                SUM(ts.Headshots) AS Headshots,
  4711.                                SUM(ts.Deaths) AS Deaths,
  4712.                                SUM(ts.TKs) AS TKs,
  4713.                                SUM(ts.Suicide) AS Suicide,
  4714.                                SUM(ts.RoundCount ) AS RoundCount,
  4715.                                SUM(ts.Playtime) AS Playtime
  4716.                                FROM " + this.tbl_sessions + @" ts
  4717.                                INNER JOIN " + this.tbl_server_player + @" tsp USING(StatsID)
  4718.                                INNER JOIN " + this.tbl_playerdata + @" tpd USING(PlayerID) ";
  4719.                 int rank = 0;
  4720.                 //Top10 Query
  4721.                 if (m_enRankingByScore == enumBoolYesNo.Yes)
  4722.                 {
  4723.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4724.                     {
  4725.                         //Ranking by Score overall Server
  4726.                         SQL = SQL + @" INNER JOIN " + this.tbl_server + @" ts2 USING(ServerID)
  4727.                                       WHERE ts.StartTime >= DATE_SUB(CURRENT_DATE(),INTERVAL @DAYS DAY) AND ts2.ServerGroup = @ServerGroup
  4728.                                       Group BY tsp.StatsID
  4729.                                       ORDER BY SUM(ts.Score) DESC ";
  4730.                     }
  4731.                     else
  4732.                     {
  4733.                         //Ranking by Score specfic Server
  4734.                         SQL = SQL + @" WHERE ts.StartTime >= DATE_SUB(CURRENT_DATE(),INTERVAL @DAYS DAY) AND tsp.ServerID = @ServerID
  4735.                                       Group BY tsp.StatsID
  4736.                                       ORDER BY SUM(ts.Score) DESC ";
  4737.                     }
  4738.                 }
  4739.                 else
  4740.                 {
  4741.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4742.                     {
  4743.                         //Ranking by Kills overall Server
  4744.                         SQL = SQL + @" INNER JOIN " + this.tbl_server + @" ts2 USING(ServerID)
  4745.                                       WHERE ts.StartTime >= DATE_SUB(CURRENT_DATE(),INTERVAL @DAYS DAY) AND ts2.ServerGroup = @ServerGroup
  4746.                                       Group BY tsp.StatsID
  4747.                                       ORDER BY SUM(ts.Kills) DESC, SUM(ts.Deaths) ASC ";
  4748.                     }
  4749.                     else
  4750.                     {
  4751.                         //Ranking by Kills specfic Server
  4752.                         SQL = SQL + @" WHERE ts.StartTime >= DATE_SUB(CURRENT_DATE(),INTERVAL @DAYS DAY) AND tsp.ServerID = @ServerID
  4753.                                       Group BY tsp.StatsID
  4754.                                       ORDER BY SUM(ts.Kills) DESC, SUM(ts.Deaths) ASC ";
  4755.                     }
  4756.                 }
  4757.                 //Add LIMIT
  4758.                 SQL = SQL + @" LIMIT 10";
  4759.  
  4760.                 using (MySqlCommand MyCommand = new MySqlCommand(SQL))
  4761.                 {
  4762.                     MyCommand.Parameters.AddWithValue("@DAYS", intdays);
  4763.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  4764.                     {
  4765.                         MyCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  4766.                     }
  4767.                     else
  4768.                     {
  4769.                         MyCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  4770.                     }
  4771.                     DataTable resultTable;
  4772.                     try
  4773.                     {
  4774.                         resultTable = this.SQLquery(MyCommand);
  4775.                         result = new List<string>();
  4776.                         //Top 10 Header
  4777.                         result.Add(this.m_strTop10HeaderForPeriod.Replace("%serverName%", this.serverName).Replace("%intervaldays%", intdays.ToString()));
  4778.                         StringBuilder Top10Row = new StringBuilder();
  4779.                         double kdr1;
  4780.                         double khr;
  4781.                         if (resultTable.Rows != null)
  4782.                         {
  4783.                             foreach (DataRow row in resultTable.Rows)
  4784.                             {
  4785.                                 Top10Row.Append(this.m_strTop10RowFormat);
  4786.  
  4787.                                 if (Convert.ToDouble(row["Deaths"]) != 0)
  4788.                                 {
  4789.                                     kdr1 = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Deaths"]);
  4790.                                     Top10Row.Replace("%playerKDR%", Math.Round(kdr1, 2).ToString());
  4791.                                 }
  4792.                                 else
  4793.                                 {
  4794.                                     Top10Row.Replace("%playerKDR%", Convert.ToDouble(row["Kills"]).ToString());
  4795.                                 }
  4796.  
  4797.                                 if (Convert.ToDouble(row["Headshots"]) != 0)
  4798.                                 {
  4799.                                     khr = Convert.ToDouble(row["Kills"]) / Convert.ToDouble(row["Headshots"]);
  4800.                                     khr = Math.Round(khr, 4);
  4801.                                     khr = khr * 100;
  4802.                                     Top10Row.Replace("%playerKHR%", khr.ToString());
  4803.                                 }
  4804.                                 else
  4805.                                 {
  4806.                                     khr = 0;
  4807.                                 }
  4808.                                 rank = rank + 1;
  4809.                                 Top10Row.Replace("%Rank%", rank.ToString()).Replace("%playerName%", row["SoldierName"].ToString()).Replace("%playerScore%", row["Score"].ToString()).Replace("%playerKills%", row["Kills"].ToString());
  4810.                                 Top10Row.Replace("%playerDeaths%", row["Deaths"].ToString()).Replace("%playerHeadshots%", row["Headshots"].ToString());
  4811.                                 result.Add(Top10Row.ToString());
  4812.                                 Top10Row.Length = 0;
  4813.                             }
  4814.                         }
  4815.                     }
  4816.                     catch (Exception c)
  4817.                     {
  4818.                         this.DebugInfo("Error", "GetTop10ForPeriod: " + c);
  4819.                     }
  4820.                 }
  4821.                 if (result.Count > 0)
  4822.                 {
  4823.                     this.SendMultiLineChatMessage(result, 0, delay, scope, strSpeaker);
  4824.                 }
  4825.             }
  4826.         }
  4827.        
  4828.         //Add to stats
  4829.         private void AddKillToStats(string strPlayerName, string DmgType, string weapon, bool headshot)
  4830.         {
  4831.             if (StatsTracker.ContainsKey(strPlayerName))
  4832.             {
  4833.                 StatsTracker[strPlayerName].addKill(DmgType, weapon, headshot);
  4834.             }
  4835.             else
  4836.             {
  4837.                 CStats newEntry = new CStats(String.Empty, 0, 0, 0, 0, 0, 0, 0, this.m_dTimeOffset, this.weaponDic);
  4838.                 StatsTracker.Add(strPlayerName, newEntry);
  4839.                 StatsTracker[strPlayerName].addKill(DmgType, weapon, headshot);
  4840.             }
  4841.             //Session
  4842.             if (m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  4843.             {
  4844.                 m_dicSession[strPlayerName].addKill(DmgType, weapon, headshot);
  4845.             }
  4846.         }
  4847.  
  4848.         public void AddDeathToStats(string strPlayerName, string DmgType, string weapon)
  4849.         {
  4850.             if (StatsTracker.ContainsKey(strPlayerName))
  4851.             {
  4852.                 StatsTracker[strPlayerName].addDeath(DmgType, weapon);
  4853.             }
  4854.             else
  4855.             {
  4856.                 CStats newEntry = new CStats(String.Empty, 0, 0, 0, 0, 0, 0, 0, this.m_dTimeOffset, this.weaponDic);
  4857.                 StatsTracker.Add(strPlayerName, newEntry);
  4858.                 StatsTracker[strPlayerName].addDeath(DmgType, weapon);
  4859.             }
  4860.  
  4861.             //Session
  4862.             if (m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  4863.             {
  4864.                 m_dicSession[strPlayerName].addDeath(DmgType, weapon);
  4865.             }
  4866.         }
  4867.  
  4868.         private void AddSuicideToStats(string strPlayerName, string DmgType, string weapon)
  4869.         {
  4870.             if (StatsTracker.ContainsKey(strPlayerName))
  4871.             {
  4872.                 StatsTracker[strPlayerName].addDeath(DmgType, weapon);
  4873.                 StatsTracker[strPlayerName].Suicides++;
  4874.             }
  4875.             else
  4876.             {
  4877.                 CStats newEntry = new CStats(String.Empty, 0, 0, 0, 0, 1, 0, 0, this.m_dTimeOffset, this.weaponDic);
  4878.                 StatsTracker.Add(strPlayerName, newEntry);
  4879.                 StatsTracker[strPlayerName].addDeath(DmgType, weapon);
  4880.             }
  4881.  
  4882.             //Session
  4883.             if (m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  4884.             {
  4885.                 m_dicSession[strPlayerName].addDeath(DmgType, weapon);
  4886.                 m_dicSession[strPlayerName].Suicides++;
  4887.             }
  4888.         }
  4889.  
  4890.         private void AddTeamKillToStats(string strPlayerName)
  4891.         {
  4892.             if (StatsTracker.ContainsKey(strPlayerName))
  4893.             {
  4894.                 StatsTracker[strPlayerName].Teamkills++;
  4895.             }
  4896.             else
  4897.             {
  4898.                 CStats newEntry = new CStats(String.Empty, 0, 0, 0, 0, 0, 1, 0, this.m_dTimeOffset, this.weaponDic);
  4899.                 StatsTracker.Add(strPlayerName, newEntry);
  4900.             }
  4901.  
  4902.             //Session
  4903.             if (m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  4904.             {
  4905.                 m_dicSession[strPlayerName].Teamkills++;
  4906.             }
  4907.         }
  4908.         //Misc
  4909.         private void AddPBInfoToStats(CPunkbusterInfo cpbiPlayer)
  4910.         {
  4911.             if (StatsTracker.ContainsKey(cpbiPlayer.SoldierName))
  4912.             {
  4913.                 StatsTracker[cpbiPlayer.SoldierName].Guid = cpbiPlayer.GUID;
  4914.                 if (cpbiPlayer.PlayerCountryCode.Length <= 2)
  4915.                 {
  4916.                     StatsTracker[cpbiPlayer.SoldierName].PlayerCountryCode = cpbiPlayer.PlayerCountryCode;
  4917.                 }
  4918.                 else
  4919.                 {
  4920.                     StatsTracker[cpbiPlayer.SoldierName].PlayerCountryCode = "--";
  4921.                 }
  4922.                 if (StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined == null)
  4923.                     StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined = MyDateTime.Now;
  4924.             }
  4925.             else
  4926.             {
  4927.                 CStats newEntry = new CStats(cpbiPlayer.GUID, 0, 0, 0, 0, 0, 0, 0, this.m_dTimeOffset, this.weaponDic);
  4928.                 StatsTracker.Add(cpbiPlayer.SoldierName, newEntry);
  4929.                 if (cpbiPlayer.PlayerCountryCode.Length <= 2)
  4930.                 {
  4931.                     StatsTracker[cpbiPlayer.SoldierName].PlayerCountryCode = cpbiPlayer.PlayerCountryCode;
  4932.                 }
  4933.                 else
  4934.                 {
  4935.                     StatsTracker[cpbiPlayer.SoldierName].PlayerCountryCode = "--";
  4936.                 }
  4937.             }
  4938.         }
  4939.  
  4940.         private void OpenMySqlConnection(int type)
  4941.         {
  4942.             try
  4943.             {
  4944.                 switch (type)
  4945.                 {
  4946.                     //OdbcCon
  4947.                     case 1:
  4948.  
  4949.                         if (MySqlCon == null)
  4950.                         {
  4951.                             MySqlCon = new MySqlConnection(this.DBConnectionStringBuilder());
  4952.                             MySqlCon.Open();
  4953.                         }
  4954.                         if (MySqlCon.State == ConnectionState.Closed)
  4955.                         {
  4956.                             MySqlCon = new MySqlConnection(this.DBConnectionStringBuilder());
  4957.                             MySqlCon.Open();
  4958.                             //this.DebugInfo("Info", "MySqlCon was close Current State is open");
  4959.                         }
  4960.  
  4961.                         break;
  4962.                     //ODBCConn
  4963.                     case 2:
  4964.                         if (MySqlConn == null)
  4965.                         {
  4966.                             MySqlConn = new MySqlConnection(this.DBConnectionStringBuilder());
  4967.                             MySqlConn.Open();
  4968.                         }
  4969.                         if (MySqlConn.State == ConnectionState.Closed)
  4970.                         {
  4971.                             MySqlConn = new MySqlConnection(this.DBConnectionStringBuilder());
  4972.                             MySqlConn.Open();
  4973.                             //this.DebugInfo("Info", "MySqlConn was close, Reopen it, Current State is open");
  4974.                         }
  4975.  
  4976.                         break;
  4977.  
  4978.                     default:
  4979.                         break;
  4980.                 }
  4981.             }
  4982.             catch (MySqlException oe)
  4983.             {
  4984.                 this.DebugInfo("Error", "OpenConnection:");
  4985.                 this.DisplayMySqlErrorCollection(oe);
  4986.             }
  4987.             catch (Exception c)
  4988.             {
  4989.                 this.DebugInfo("Error", "OpenConnection: " + c);
  4990.             }
  4991.         }
  4992.  
  4993.         private void CloseMySqlConnection(int type)
  4994.         {
  4995.             if (this.MySql_Connection_is_activ == false)
  4996.             {
  4997.                 try
  4998.                 {
  4999.                     switch (type)
  5000.                     {
  5001.                         case 1:
  5002.                             //OdbcCon
  5003.                             if (this.MySqlCon != null)
  5004.                             {
  5005.                                 this.MySqlCon.Close();
  5006.                                 this.DebugInfo("Info", "Connection MySqlCon closed");
  5007.                             }
  5008.                             break;
  5009.  
  5010.                         case 2:
  5011.                             //ODBCConn
  5012.                             if (this.MySqlConn != null)
  5013.                             {
  5014.                                 this.MySqlConn.Close();
  5015.                                 this.DebugInfo("Info", "Connection MySqlConn closed");
  5016.                             }
  5017.                             break;
  5018.                         default:
  5019.                             break;
  5020.                     }
  5021.                 }
  5022.                 catch (MySqlException oe)
  5023.                 {
  5024.                     this.DebugInfo("Error", "CloseMySqlConnection:");
  5025.                     this.DisplayMySqlErrorCollection(oe);
  5026.                 }
  5027.                 catch (Exception c)
  5028.                 {
  5029.                     this.ExecuteCommand("Error", "CloseMySqlConnection: " + c);
  5030.                 }
  5031.             }
  5032.         }
  5033.  
  5034.         private void tablebuilder()
  5035.         {
  5036.             if (boolTableEXISTS)
  5037.             {
  5038.                 return;
  5039.             }
  5040.             lock (this.tablebuilderlock)
  5041.             {
  5042.                 Thread.Sleep(3000);
  5043.                 if ((m_strHost.Length == 0) || (m_strDatabase.Length == 0) || (m_strDBPort.Length == 0) || (m_strUserName.Length == 0))
  5044.                 {
  5045.                     this.DebugInfo("Error", "Check you MySQL Server Details:, hostname, port, databasename and your login credentials!");
  5046.                     this.ExecuteCommand("procon.protected.plugins.enable", "CChatGUIDStatsLogger", "False");
  5047.                     return;
  5048.                 }
  5049.                 if ((m_strHost != null) && (m_strDatabase != null) && (m_strDBPort != null) && (m_strUserName != null) && (m_strPassword != null) && (boolTableEXISTS == false))
  5050.                 {
  5051.                     this.DebugInfo("Info", "Start tablebuilder");
  5052.                     //new
  5053.                     this.generateWeaponList();
  5054.  
  5055.                     try
  5056.                     {
  5057.                         using (MySqlConnection TablebuilderCon = new MySqlConnection(this.DBConnectionStringBuilder()))
  5058.                         {
  5059.                             MySql.Data.MySqlClient.MySqlTransaction TableTransaction = null;
  5060.                             try
  5061.                             {
  5062.                                 this.MySql_Connection_is_activ = true;
  5063.                                 MySql.Data.MySqlClient.MySqlParameter param = new MySql.Data.MySqlClient.MySqlParameter();
  5064.                                 TablebuilderCon.Open();
  5065.                                 //Chatlog Table
  5066.                                 string SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_chatlog + @"` (
  5067.                                                 `ID` INT NOT NULL AUTO_INCREMENT ,
  5068.                                                 `logDate` DATETIME NULL DEFAULT NULL ,
  5069.                                                 `ServerID` SMALLINT UNSIGNED NOT NULL ,
  5070.                                                 `logSubset` VARCHAR(45) NULL DEFAULT NULL ,
  5071.                                                 `logSoldierName` VARCHAR(45) NULL DEFAULT NULL ,
  5072.                                                 `logMessage` TEXT NULL DEFAULT NULL ,
  5073.                                                     PRIMARY KEY (`ID`),
  5074.                                                    INDEX `INDEX_SERVERID` (`ServerID` ASC),
  5075.                                                    INDEX `INDEX_logDate` (`logDate` ASC))
  5076.                                                     ENGINE = InnoDB";
  5077.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon))
  5078.                                 {
  5079.                                     OdbcCom.ExecuteNonQuery();
  5080.                                 }
  5081.  
  5082.                                 //MapStats Table
  5083.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_mapstats + @"` (
  5084.                                                       `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  5085.                                                      `ServerID` SMALLINT UNSIGNED NOT NULL DEFAULT '0' ,
  5086.                                                      `TimeMapLoad` DATETIME NULL DEFAULT NULL ,
  5087.                                                      `TimeRoundStarted` DATETIME NULL DEFAULT NULL ,
  5088.                                                      `TimeRoundEnd` DATETIME NULL DEFAULT NULL ,
  5089.                                                      `MapName` VARCHAR(45) NULL DEFAULT NULL ,
  5090.                                                      `Gamemode` VARCHAR(45) NULL DEFAULT NULL ,
  5091.                                                      `Roundcount` SMALLINT NOT NULL DEFAULT '0' ,
  5092.                                                      `NumberofRounds` SMALLINT NOT NULL DEFAULT '0' ,
  5093.                                                      `MinPlayers` SMALLINT NOT NULL DEFAULT '0' ,
  5094.                                                      `AvgPlayers` DOUBLE NOT NULL DEFAULT '0' ,
  5095.                                                      `MaxPlayers` SMALLINT NOT NULL DEFAULT '0' ,
  5096.                                                      `PlayersJoinedServer` SMALLINT NOT NULL DEFAULT '0' ,
  5097.                                                      `PlayersLeftServer` SMALLINT NOT NULL DEFAULT '0' ,
  5098.                                                      PRIMARY KEY (`ID`) ,
  5099.                                                      INDEX `ServerID_INDEX` (`ServerID` ASC) )
  5100.                                                    ENGINE = InnoDB";
  5101.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon))
  5102.                                 {
  5103.                                     OdbcCom.ExecuteNonQuery();
  5104.                                 }
  5105.  
  5106.                                 //Start of the Transaction
  5107.                                 TableTransaction = TablebuilderCon.BeginTransaction();
  5108.  
  5109.  
  5110.                                 //Table tbl_games
  5111.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_games + @"` (
  5112.                                                   `GameID` tinyint(4) unsigned NOT NULL AUTO_INCREMENT,
  5113.                                                   `Name` varchar(45) DEFAULT NULL,
  5114.                                                   PRIMARY KEY (`GameID`),
  5115.                                                   UNIQUE KEY `name_unique` (`Name`)
  5116.                                                   ) ENGINE=InnoDB";
  5117.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5118.                                 {
  5119.                                     OdbcCom.ExecuteNonQuery();
  5120.                                 }
  5121.  
  5122.                                 //Table playerdata
  5123.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_playerdata + @"` (
  5124.                                                  `PlayerID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  5125.                                                  `GameID` tinyint(4)unsigned NOT NULL DEFAULT '0',
  5126.                                                   `ClanTag` VARCHAR(10) NULL DEFAULT NULL ,
  5127.                                                   `SoldierName` VARCHAR(45) NULL DEFAULT NULL ,
  5128.                                                  `GlobalRank` SMALLINT UNSIGNED NOT NULL DEFAULT '0',
  5129.                                                   `PBGUID` VARCHAR(32) NULL DEFAULT NULL ,
  5130.                                                   `EAGUID` VARCHAR(35) NULL DEFAULT NULL ,
  5131.                                                   `IP_Address` VARCHAR(15) NULL DEFAULT NULL ,
  5132.                                                  `IPv6_Address` VARBINARY(16) NULL DEFAULT NULL ,
  5133.                                                   `CountryCode` VARCHAR(2) NULL DEFAULT NULL ,
  5134.                                                   PRIMARY KEY (`PlayerID`) ,
  5135.                                                   UNIQUE INDEX `UNIQUE_playerdata` (`GameID` ASC,`EAGUID` ASC) ,
  5136.                                                   INDEX `INDEX_SoldierName` (`SoldierName` ASC) )
  5137.                                                 ENGINE = InnoDB";
  5138.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5139.                                 {
  5140.                                     OdbcCom.ExecuteNonQuery();
  5141.                                 }
  5142.  
  5143.                                 //Server Table
  5144.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_server + @"` (
  5145.                                       `ServerID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT ,
  5146.                                      `ServerGroup` TINYINT UNSIGNED NOT NULL DEFAULT 0 ,
  5147.                                       `IP_Address` VARCHAR(45) NULL DEFAULT NULL ,
  5148.                                       `ServerName` VARCHAR(200) NULL DEFAULT NULL ,
  5149.                                      `GameID` tinyint(4)unsigned NOT NULL DEFAULT '0',
  5150.                                       `usedSlots` SMALLINT UNSIGNED NULL DEFAULT 0 ,
  5151.                                       `maxSlots` SMALLINT UNSIGNED NULL DEFAULT 0 ,
  5152.                                       `mapName` VARCHAR(45) NULL DEFAULT NULL ,
  5153.                                       `fullMapName` TEXT NULL DEFAULT NULL ,
  5154.                                      
  5155.                                       `Gamemode` VARCHAR(45) NULL DEFAULT NULL ,
  5156.                                       `GameMod` VARCHAR(45) NULL DEFAULT NULL ,
  5157.                                       `PBversion` VARCHAR(45) NULL DEFAULT NULL ,
  5158.                                       `ConnectionState` VARCHAR(45) NULL DEFAULT NULL ,
  5159.                                       PRIMARY KEY (`ServerID`) ,
  5160.                                      INDEX `INDEX_SERVERGROUP` (`ServerGroup` ASC) ,
  5161.                                       UNIQUE INDEX `IP_Address_UNIQUE` (`IP_Address` ASC) )
  5162.                                     ENGINE = InnoDB";
  5163.  
  5164.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5165.                                 {
  5166.                                     OdbcCom.ExecuteNonQuery();
  5167.                                 }
  5168.  
  5169.                                 //Server Player Table
  5170.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_server_player + @"` (
  5171.                                   `StatsID` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  5172.                                   `ServerID` SMALLINT UNSIGNED NOT NULL ,
  5173.                                   `PlayerID` INT UNSIGNED NOT NULL ,
  5174.                                   PRIMARY KEY (`StatsID`) ,
  5175.                                   UNIQUE INDEX `UNIQUE_INDEX` (`ServerID` ASC, `PlayerID` ASC) ,
  5176.                                   INDEX `fk_tbl_server_player_tbl_playerdata" + this.tableSuffix + @"` (`PlayerID` ASC) ,
  5177.                                   INDEX `fk_tbl_server_player_tbl_server" + this.tableSuffix + @"` (`ServerID` ASC) ,
  5178.                                   CONSTRAINT `fk_tbl_server_player_tbl_playerdata" + this.tableSuffix + @"`
  5179.                                     FOREIGN KEY (`PlayerID` )
  5180.                                     REFERENCES `" + this.tbl_playerdata + @"` (`PlayerID` )
  5181.                                     ON DELETE CASCADE
  5182.                                     ON UPDATE NO ACTION,
  5183.                                   CONSTRAINT `fk_tbl_server_player_tbl_server" + this.tableSuffix + @"`
  5184.                                     FOREIGN KEY (`ServerID` )
  5185.                                     REFERENCES `" + this.tbl_server + @"` (`ServerID` )
  5186.                                     ON DELETE CASCADE
  5187.                                     ON UPDATE NO ACTION)
  5188.                                 ENGINE = InnoDB";
  5189.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5190.                                 {
  5191.                                     OdbcCom.ExecuteNonQuery();
  5192.                                 }
  5193.                                 //
  5194.                                 //ServerStatistics Table
  5195.                                 SQLTable = @"CREATE  TABLE IF NOT EXISTS `" + this.tbl_server_stats + @"` (
  5196.                                  `ServerID` SMALLINT(5) UNSIGNED NOT NULL ,
  5197.                                  `CountPlayers` BIGINT NOT NULL DEFAULT 0 ,
  5198.                                  `SumScore` BIGINT NOT NULL DEFAULT 0 ,
  5199.                                  `AvgScore` FLOAT NOT NULL DEFAULT 0 ,
  5200.                                  `SumKills` BIGINT NOT NULL DEFAULT 0 ,
  5201.                                  `AvgKills` FLOAT NOT NULL DEFAULT 0 ,
  5202.                                  `SumHeadshots` BIGINT NOT NULL DEFAULT 0 ,
  5203.                                  `AvgHeadshots` FLOAT NOT NULL DEFAULT 0 ,
  5204.                                  `SumDeaths` BIGINT NOT NULL DEFAULT 0 ,
  5205.                                  `AvgDeaths` FLOAT NOT NULL DEFAULT 0 ,
  5206.                                  `SumSuicide` BIGINT NOT NULL DEFAULT 0 ,
  5207.                                  `AvgSuicide` FLOAT NOT NULL DEFAULT 0 ,
  5208.                                  `SumTKs` BIGINT NOT NULL DEFAULT 0 ,
  5209.                                  `AvgTKs` FLOAT NOT NULL DEFAULT 0 ,
  5210.                                  `SumPlaytime` BIGINT NOT NULL DEFAULT 0 ,
  5211.                                  `AvgPlaytime` FLOAT NOT NULL DEFAULT 0 ,
  5212.                                  `SumRounds` BIGINT NOT NULL DEFAULT 0 ,
  5213.                                  `AvgRounds` FLOAT NOT NULL DEFAULT 0 ,
  5214.                                  PRIMARY KEY (`ServerID`) ,
  5215.                                  INDEX `fk_tbl_server_stats_tbl_server" + this.tableSuffix + @"` (`ServerID` ASC) ,
  5216.                                  CONSTRAINT `fk_tbl_server_stats_tbl_server" + this.tableSuffix + @"`
  5217.                                    FOREIGN KEY (`ServerID` )
  5218.                                    REFERENCES `" + this.tbl_server + @"` (`ServerID` )
  5219.                                    ON DELETE CASCADE
  5220.                                    ON UPDATE NO ACTION)
  5221.                                ENGINE = InnoDB";
  5222.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5223.                                 {
  5224.                                     OdbcCom.ExecuteNonQuery();
  5225.                                 }
  5226.  
  5227.                                 //Stats Table
  5228.                                 SQLTable = @"CREATE  TABLE IF NOT EXISTS `" + this.tbl_playerstats + @"` (
  5229.                                   `StatsID` INT UNSIGNED NOT NULL ,
  5230.                                   `Score` INT NOT NULL DEFAULT '0' ,
  5231.                                   `Kills` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5232.                                   `Headshots` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5233.                                   `Deaths` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5234.                                   `Suicide` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5235.                                   `TKs` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5236.                                   `Playtime` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5237.                                   `Rounds` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5238.                                   `FirstSeenOnServer` DATETIME NULL DEFAULT NULL ,
  5239.                                   `LastSeenOnServer` DATETIME NULL DEFAULT NULL ,
  5240.                                   `Killstreak` SMALLINT UNSIGNED NOT NULL DEFAULT '0' ,
  5241.                                   `Deathstreak` SMALLINT UNSIGNED NOT NULL DEFAULT '0' ,
  5242.                                  `HighScore` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0' ,
  5243.                                  `rankScore` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5244.                                  `rankKills` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5245.                                  `Wins` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5246.                                  `Losses` INT UNSIGNED NOT NULL DEFAULT '0' ,
  5247.                                   PRIMARY KEY (`StatsID`) ,
  5248.                                  INDEX `INDEX_Score" + this.tableSuffix + @"` (`Score`),
  5249.                                  KEY `INDEX_RANK_SCORE" + this.tableSuffix + @"` (`rankScore`),
  5250.                                  KEY `INDEX_RANK_KILLS" + this.tableSuffix + @"` (`rankKills`),
  5251.                                   CONSTRAINT `fk_tbl_playerstats_tbl_server_player1" + this.tableSuffix + @"`
  5252.                                     FOREIGN KEY (`StatsID` )
  5253.                                     REFERENCES `" + this.tbl_server_player + @"` (`StatsID` )
  5254.                                     ON DELETE CASCADE
  5255.                                     ON UPDATE NO ACTION)
  5256.                                 ENGINE = InnoDB";
  5257.  
  5258.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5259.                                 {
  5260.                                     OdbcCom.ExecuteNonQuery();
  5261.                                 }
  5262.  
  5263.                                 //Playerrank Table
  5264.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_playerrank + @"` (
  5265.                                      `PlayerID` INT UNSIGNED NOT NULL DEFAULT 0 ,
  5266.                                      `ServerGroup` SMALLINT UNSIGNED NOT NULL DEFAULT 0 ,
  5267.                                      `rankScore` INT UNSIGNED NOT NULL DEFAULT 0 ,
  5268.                                      `rankKills` INT UNSIGNED NOT NULL DEFAULT 0 ,
  5269.                                      INDEX `INDEX_SCORERANKING" + this.tableSuffix + @"` (`rankScore` ASC) ,
  5270.                                      INDEX `INDEX_KILLSRANKING" + this.tableSuffix + @"` (`rankKills` ASC) ,
  5271.                                      PRIMARY KEY (`PlayerID`,`ServerGroup`) ,
  5272.                                      CONSTRAINT `fk_tbl_playerrank_tbl_playerdata" + this.tableSuffix + @"`
  5273.                                        FOREIGN KEY (`PlayerID` )
  5274.                                        REFERENCES `" + this.tbl_playerdata + @"` (`PlayerID` )
  5275.                                        ON DELETE CASCADE
  5276.                                        ON UPDATE NO ACTION)
  5277.                                    ENGINE = InnoDB";
  5278.  
  5279.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5280.                                 {
  5281.                                     OdbcCom.ExecuteNonQuery();
  5282.                                 }
  5283.  
  5284.                                 //Playersession Table
  5285.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_sessions + @"` (
  5286.                                          `SessionID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  5287.                                          `StatsID` INT UNSIGNED NOT NULL,
  5288.                                          `StartTime` DATETIME NOT NULL,
  5289.                                          `EndTime` DATETIME NOT NULL,
  5290.                                          `Score` MEDIUMINT NOT NULL DEFAULT '0',
  5291.                                          `Kills` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
  5292.                                          `Headshots` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
  5293.                                          `Deaths` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
  5294.                                          `TKs` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
  5295.                                          `Suicide` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
  5296.                                          `RoundCount` TINYINT UNSIGNED NOT NULL DEFAULT '0',
  5297.                                          `Playtime` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
  5298.                                          `Killstreak` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' ,
  5299.                                           `Deathstreak` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' ,
  5300.                                          `HighScore` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0' ,
  5301.                                          `Wins` TINYINT UNSIGNED NOT NULL DEFAULT '0' ,
  5302.                                          `Losses` TINYINT UNSIGNED NOT NULL DEFAULT '0' ,
  5303.                                          PRIMARY KEY (`SessionID`),
  5304.                                          INDEX `INDEX_STATSID" + this.tableSuffix + @"` (`StatsID` ASC),
  5305.                                          INDEX `INDEX_STARTTIME" + this.tableSuffix + @"` (`StartTime` ASC),
  5306.                                          CONSTRAINT `fk_tbl_sessions_tbl_server_player" + this.tableSuffix + @"`
  5307.                                            FOREIGN KEY (`StatsID`)
  5308.                                            REFERENCES `" + this.tbl_server_player + @"` (`StatsID`)
  5309.                                            ON DELETE CASCADE
  5310.                                            ON UPDATE NO ACTION)
  5311.                                         ENGINE=InnoDB";
  5312.  
  5313.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5314.                                 {
  5315.                                     OdbcCom.ExecuteNonQuery();
  5316.                                 }
  5317.  
  5318.                                 //currentplayers
  5319.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_currentplayers + @"` (
  5320.                                                  `ServerID` smallint(6) NOT NULL,
  5321.                                                  `Soldiername` varchar(45) NOT NULL,
  5322.                                                  `GlobalRank` SMALLINT UNSIGNED NOT NULL DEFAULT '0',
  5323.                                                  `ClanTag` varchar(45) DEFAULT NULL,
  5324.                                                  `Score` int(11) NOT NULL DEFAULT '0',
  5325.                                                  `Kills` int(11) NOT NULL DEFAULT '0',
  5326.                                                  `Headshots` int(11) NOT NULL DEFAULT '0',
  5327.                                                  `Deaths` int(11) NOT NULL DEFAULT '0',
  5328.                                                  `Suicide` int(11) DEFAULT NULL,
  5329.                                                  `Killstreak` smallint(6) DEFAULT '0',
  5330.                                                  `Deathstreak` smallint(6) DEFAULT '0',
  5331.                                                  `TeamID` tinyint(4) DEFAULT NULL,
  5332.                                                  `SquadID` tinyint(4) DEFAULT NULL,
  5333.                                                  `EA_GUID` varchar(45) NOT NULL DEFAULT '',
  5334.                                                  `PB_GUID` varchar(45) NOT NULL DEFAULT '',
  5335.                                                  `IP_aton` int(11) unsigned DEFAULT NULL,
  5336.                                                  `CountryCode` varchar(2) DEFAULT '',
  5337.                                                  `Ping` smallint(6) DEFAULT NULL,
  5338.                                                  `PlayerJoined` datetime DEFAULT NULL,
  5339.                                              PRIMARY KEY (`ServerID`,`Soldiername`)
  5340.                                            ) ENGINE=InnoDB";
  5341.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5342.                                 {
  5343.                                     OdbcCom.ExecuteNonQuery();
  5344.                                 }
  5345.  
  5346.                                 //Awards
  5347.                                 /*
  5348.                                 SQLTable = @"CREATE  TABLE IF NOT EXISTS `" + this.tbl_awards + @"` (
  5349.                                                       `AwardID` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ";
  5350.                                 foreach (string strcolumn in this.m_lstAwardTable)
  5351.                                 {
  5352.                                     SQLTable = String.Concat(SQLTable, ",`", strcolumn, "` mediumint(8) unsigned DEFAULT '0' ");
  5353.                                 }
  5354.                                 SQLTable = String.Concat(SQLTable, ")ENGINE = InnoDB DEFAULT CHARACTER SET = latin1");
  5355.                                 if (this.m_awardsON == enumBoolYesNo.Yes)
  5356.                                 {
  5357.                                     using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5358.                                     {
  5359.                                         OdbcCom.ExecuteNonQuery();
  5360.                                     }
  5361.                                 }
  5362.                                 */
  5363.  
  5364.                                 //New Weapon table
  5365.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_weapons + @"` (
  5366.                                              `WeaponID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  5367.                                              `GameID` tinyint(4)unsigned NOT NULL,
  5368.                                              `Friendlyname` varchar(45) DEFAULT NULL,
  5369.                                              `Fullname` varchar(100) DEFAULT NULL,
  5370.                                              `Damagetype` varchar(45) DEFAULT NULL,
  5371.                                              `Slot` varchar(45) DEFAULT NULL,
  5372.                                              `Kitrestriction` varchar(45) DEFAULT NULL,
  5373.                                              PRIMARY KEY (`WeaponID`),
  5374.                                              UNIQUE KEY `unique` (`GameID`,`fullname`)
  5375.                                            ) ENGINE=InnoDB";
  5376.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5377.                                 {
  5378.                                     OdbcCom.ExecuteNonQuery();
  5379.                                 }
  5380.  
  5381.                                 //New Weapon stats table
  5382.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_weapons_stats + @"` (
  5383.                                                  `StatsID` INT unsigned NOT NULL,
  5384.                                                  `WeaponID` int(11) unsigned NOT NULL,
  5385.                                                  `Kills` int(11) unsigned NOT NULL DEFAULT '0',
  5386.                                                  `Headshots` int(11) unsigned NOT NULL DEFAULT '0',
  5387.                                                  `Deaths` int(11) unsigned NOT NULL DEFAULT '0',
  5388.                                                  PRIMARY KEY (`StatsID`,`WeaponID`),
  5389.                                                  KEY `Kills_Death_idx` (`Kills`,`Deaths`),
  5390.                                                  KEY `Kills_Head_idx` (`Kills`,`Headshots`),
  5391.                                                  CONSTRAINT `fk_tbl_weapons_stats_tbl_server_player_" + this.tableSuffix + @"`
  5392.                                                     FOREIGN KEY (`StatsID` )
  5393.                                                     REFERENCES `" + this.tbl_server_player + @"` (`StatsID` )
  5394.                                                     ON DELETE CASCADE
  5395.                                                     ON UPDATE NO ACTION
  5396.                                                ) ENGINE=InnoDB";
  5397.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5398.                                 {
  5399.                                     OdbcCom.ExecuteNonQuery();
  5400.                                 }
  5401.  
  5402.                                 //Dogtagstable
  5403.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_dogtags + @"` (
  5404.                                      `KillerID` INT UNSIGNED NOT NULL ,
  5405.                                       `VictimID` INT UNSIGNED NOT NULL ,
  5406.                                       `Count` SMALLINT UNSIGNED NOT NULL DEFAULT '0' ,
  5407.                                       PRIMARY KEY (`KillerID`, `VictimID`) ,
  5408.                                       INDEX `fk_tbl_dogtags_tbl_server_player1" + this.tableSuffix + @"` (`KillerID` ASC) ,
  5409.                                       INDEX `fk_tbl_dogtags_tbl_server_player2" + this.tableSuffix + @"` (`VictimID` ASC) ,
  5410.                                       CONSTRAINT `fk_tbl_dogtags_tbl_server_player1" + this.tableSuffix + @"`
  5411.                                         FOREIGN KEY (`KillerID` )
  5412.                                         REFERENCES `" + this.tbl_server_player + @"` (`StatsID` )
  5413.                                         ON DELETE CASCADE
  5414.                                         ON UPDATE NO ACTION,
  5415.                                       CONSTRAINT `fk_tbl_dogtags_tbl_server_player2" + this.tableSuffix + @"`
  5416.                                         FOREIGN KEY (`VictimID` )
  5417.                                         REFERENCES `" + this.tbl_server_player + @"` (`StatsID` )
  5418.                                         ON DELETE CASCADE
  5419.                                         ON UPDATE NO ACTION)
  5420.                                     ENGINE = InnoDB";
  5421.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5422.                                 {
  5423.                                     OdbcCom.ExecuteNonQuery();
  5424.                                 }
  5425.  
  5426.                                 //Score and Tickettable
  5427.                                 SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_teamscores + @"` (
  5428.                                              `ServerID` smallint(5) unsigned NOT NULL,
  5429.                                              `TeamID` smallint(5) DEFAULT NULL,
  5430.                                              `Score` int(11) DEFAULT NULL,
  5431.                                              `WinningScore` int(11) DEFAULT NULL,
  5432.                                              PRIMARY KEY (`ServerID`,`TeamID` )
  5433.                                             ) ENGINE=InnoDB";
  5434.                                 using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5435.                                 {
  5436.                                     OdbcCom.ExecuteNonQuery();
  5437.                                 }
  5438.  
  5439.                                 //Commit the Transaction
  5440.                                 TableTransaction.Commit();
  5441.  
  5442.                                 this.boolTableEXISTS = true;
  5443.  
  5444.                                 //fill weapon table
  5445.                                 //get GameID
  5446.                                 this.intServerGameType_ID = this.GetGameIDfromDB(this.strServerGameType);
  5447.  
  5448.                                 List<string> addedWeaponList = new List<string>();
  5449.  
  5450.                                 foreach (KeyValuePair<string, Dictionary<string, CStats.CUsedWeapon>> branch in this.weaponDic)
  5451.                                 {
  5452.                                     string sqlCheckweapon = @"SELECT
  5453.                                                                `GameID`,
  5454.                                                                `Friendlyname`,
  5455.                                                                `Fullname`,
  5456.                                                                `Damagetype`
  5457.                                                            FROM `" + this.tbl_weapons + @"`
  5458.                                                            WHERE `GameID` = @GameID
  5459.                                                              AND `Damagetype` = @Damagetype";
  5460.                                     using (MySqlCommand MyCommand = new MySqlCommand(sqlCheckweapon))
  5461.                                     {
  5462.                                         MyCommand.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  5463.                                         MyCommand.Parameters.AddWithValue("@Damagetype", branch.Key.ToLower());
  5464.  
  5465.                                         using (DataTable result = this.SQLquery(MyCommand))
  5466.                                         {
  5467.                                             //this.DebugInfo("Info", "Rowcount:" + result.Rows.Count.ToString());
  5468.                                             if (result.Rows.Count >= 1)
  5469.                                             {
  5470.                                                 result.PrimaryKey = new DataColumn[] { result.Columns["GameID"], result.Columns["Fullname"] };
  5471.                                             }
  5472.                                             TableTransaction = null;
  5473.                                             TableTransaction = TablebuilderCon.BeginTransaction();
  5474.  
  5475.                                             foreach (KeyValuePair<string, CStats.CUsedWeapon> leap in branch.Value)
  5476.                                             {
  5477.                                                 if (result.Rows.Count == 0 || result.Rows.Contains(new object[] { this.intServerGameType_ID, leap.Value.Name }) == false || addedWeaponList.Contains(leap.Value.Name) == true)
  5478.                                                 {
  5479.                                                     addedWeaponList.Add(leap.Value.Name);
  5480.                                                     //add weapon entry
  5481.                                                     string sqlInsertQuery = "INSERT INTO `" + this.tbl_weapons + @"` ( `GameID`, `Friendlyname`, `Fullname`,`Damagetype`,`Slot`,`Kitrestriction`) VALUES(@GameID, @Friendlyname, @Fullname, @Damagetype,@Slot,@Kitrestriction)
  5482.                                                                            ON DUPLICATE KEY UPDATE `Friendlyname` = @Friendlyname ,`Damagetype` =  @Damagetype,`Slot` = @Slot,`Kitrestriction` = @Kitrestriction";
  5483.  
  5484.                                                     using (MySqlCommand OdbcCom = new MySqlCommand(sqlInsertQuery, TablebuilderCon, TableTransaction))
  5485.                                                     {
  5486.                                                         OdbcCom.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  5487.                                                         OdbcCom.Parameters.AddWithValue("@Friendlyname", leap.Value.FieldName);
  5488.                                                         OdbcCom.Parameters.AddWithValue("@Fullname", leap.Value.Name);
  5489.                                                         OdbcCom.Parameters.AddWithValue("@Damagetype", branch.Key.ToLower());
  5490.                                                         OdbcCom.Parameters.AddWithValue("@Slot", leap.Value.Slot);
  5491.                                                         OdbcCom.Parameters.AddWithValue("@Kitrestriction", leap.Value.KitRestriction);
  5492.                                                         if (this.intServerGameType_ID != 0)
  5493.                                                         {
  5494.                                                             OdbcCom.ExecuteNonQuery();
  5495.                                                         }
  5496.                                                     }
  5497.                                                 }
  5498.                                             }
  5499.                                             TableTransaction.Commit();
  5500.                                         }
  5501.                                     }
  5502.                                 }
  5503.  
  5504.                                 //Create WeaponMapping
  5505.                                 this.WeaponMappingDic = new Dictionary<string, int>(this.GetWeaponMappingfromDB());
  5506.  
  5507.  
  5508.                                 //TableCheck & Adjustemnts tbl_playerstats
  5509.                                 /*
  5510.                                 string sqlCheckplayerstats = "DESC `" + this.tbl_playerstats + "`";
  5511.                                 string sqlAltertableplayerstats = "ALTER TABLE `" + this.tbl_playerstats + "` ";
  5512.                                 string sqlIndex = "";
  5513.                                 this.DebugInfo("Trace", "Tablecheck playerstats");
  5514.                                 bool column_Missing = false;
  5515.                                 using (DataTable result = this.SQLquery(new MySqlCommand(sqlCheckplayerstats)))
  5516.                                 {
  5517.                                     DataColumn[] key = new DataColumn[1];
  5518.                                     key[0] = result.Columns[0];
  5519.                                     result.PrimaryKey = key;
  5520.                                     column_Missing = false;
  5521.  
  5522.                                     if (result.Rows.Contains("rankScore") == false)
  5523.                                     {
  5524.                                         this.DebugInfo("Trace", "Column rankScore is missing, Adding it to the table!");
  5525.                                         sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, "ADD COLUMN `rankScore` INT(10) UNSIGNED NOT NULL DEFAULT '0', ");
  5526.                                         column_Missing = true;
  5527.                                         sqlIndex = string.Concat(sqlIndex, "ADD INDEX `INDEX_RANK_SCORE" + this.tableSuffix + @"` (`rankScore` ASC), ");
  5528.                                     }
  5529.                                     if (result.Rows.Contains("rankKills") == false)
  5530.                                     {
  5531.                                         this.DebugInfo("Trace", "Column rankScore is missing, Adding it to the table!");
  5532.                                         sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, "ADD COLUMN `rankKills` INT(10) UNSIGNED NOT NULL DEFAULT '0', ");
  5533.                                         column_Missing = true;
  5534.                                         sqlIndex = string.Concat(sqlIndex, "ADD INDEX `INDEX_RANK_KILLS" + this.tableSuffix + @"` (`rankKills` ASC), ");
  5535.                                     }
  5536.                                     //Wins & Losses
  5537.                                     if (result.Rows.Contains("Wins") == false)
  5538.                                     {
  5539.                                         this.DebugInfo("Trace", "Column Wins is missing, Adding it to the table!");
  5540.                                         sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, "ADD COLUMN `Wins` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0', ");
  5541.                                         column_Missing = true;
  5542.                                     }
  5543.                                     if (result.Rows.Contains("Losses") == false)
  5544.                                     {
  5545.                                         this.DebugInfo("Trace", "Column Losses is missing, Adding it to the table!");
  5546.                                         sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, "ADD COLUMN `Losses` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0', ");
  5547.                                         column_Missing = true;
  5548.                                     }
  5549.                                     //HighScore
  5550.                                     if (result.Rows.Contains("HighScore") == false)
  5551.                                     {
  5552.                                         this.DebugInfo("Trace", "Column HighScore is missing, Adding it to the table!");
  5553.                                         sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, "ADD COLUMN `HighScore` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0' , ");
  5554.                                         column_Missing = true;
  5555.                                     }
  5556.                                 }
  5557.                                 if (column_Missing == true)
  5558.                                 {
  5559.                                     TableTransaction = null;
  5560.                                     TableTransaction = TablebuilderCon.BeginTransaction();
  5561.                                     //Adding Columns
  5562.                                     sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, sqlIndex);
  5563.                                     int charindex = sqlAltertableplayerstats.LastIndexOf(",");
  5564.                                     if (charindex > 0)
  5565.                                     {
  5566.                                         sqlAltertableplayerstats = sqlAltertableplayerstats.Remove(charindex);
  5567.                                     }
  5568.                                     using (MySqlCommand OdbcCom = new MySqlCommand(sqlAltertableplayerstats, TablebuilderCon, TableTransaction))
  5569.                                     {
  5570.                                         OdbcCom.ExecuteNonQuery();
  5571.                                     }
  5572.                                     TableTransaction.Commit();
  5573.                                 }
  5574.                                
  5575.  
  5576.                                 //TableCheck & Adjustemnts tbl_server
  5577.                                 sqlCheckplayerstats = "DESC `" + this.tbl_server + "`";
  5578.                                 sqlAltertableplayerstats = "ALTER TABLE `" + this.tbl_server + "` ";
  5579.                                 sqlIndex = "";
  5580.                                 this.DebugInfo("Trace", "Tablecheck tbl_server");
  5581.                                 column_Missing = false;
  5582.                                 using (DataTable result = this.SQLquery(new MySqlCommand(sqlCheckplayerstats)))
  5583.                                 {
  5584.                                     DataColumn[] key = new DataColumn[1];
  5585.                                     key[0] = result.Columns[0];
  5586.                                     result.PrimaryKey = key;
  5587.                                     column_Missing = false;
  5588.  
  5589.                                     if (result.Rows.Contains("ServerGroup") == false)
  5590.                                     {
  5591.                                         this.DebugInfo("Trace", "Column ServerGroup is missing, Adding it to the table!");
  5592.                                         sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, "ADD COLUMN `ServerGroup` TINYINT UNSIGNED NOT NULL DEFAULT 0 ,");
  5593.                                         column_Missing = true;
  5594.                                         sqlIndex = string.Concat(sqlIndex, "ADD INDEX `INDEX_SERVERGROUP" + this.tableSuffix + @"` (`ServerGroup` ASC) ,");
  5595.                                     }
  5596.                                 }
  5597.                                 if (column_Missing == true)
  5598.                                 {
  5599.                                     TableTransaction = null;
  5600.                                     TableTransaction = TablebuilderCon.BeginTransaction();
  5601.                                     //Adding Columns
  5602.                                     sqlAltertableplayerstats = string.Concat(sqlAltertableplayerstats, sqlIndex);
  5603.                                     int charindex = sqlAltertableplayerstats.LastIndexOf(",");
  5604.                                     if (charindex > 0)
  5605.                                     {
  5606.                                         sqlAltertableplayerstats = sqlAltertableplayerstats.Remove(charindex);
  5607.                                     }
  5608.                                     using (MySqlCommand OdbcCom = new MySqlCommand(sqlAltertableplayerstats, TablebuilderCon, TableTransaction))
  5609.                                     {
  5610.                                         OdbcCom.ExecuteNonQuery();
  5611.                                     }
  5612.                                     TableTransaction.Commit();
  5613.                                 }
  5614.  
  5615.                                 */
  5616.  
  5617.  
  5618.                                 //TableCheck  Adjustments playerstats
  5619.                                 /*
  5620.                                 //TableCheck Awards
  5621.                                 sqlCheck = "DESC `" + this.tbl_awards + "`";
  5622.                                 sqlAltertable = "ALTER TABLE `" + this.tbl_awards + "` ";
  5623.                                 //result = new List<string>(this.SQLquery(sqlCheck,9));
  5624.                                 this.DebugInfo("Tablecheck Awards");
  5625.                                 using (DataTable result = this.SQLquery(new MySqlCommand(sqlCheck)))
  5626.                                 {
  5627.                                     DataColumn[] key = new DataColumn[1];
  5628.                                     key[0] = result.Columns[0];
  5629.                                     result.PrimaryKey = key;
  5630.                                     fieldMissing = false;
  5631.  
  5632.                                     foreach (string strField in this.m_lstAwardTable)
  5633.                                     {
  5634.                                         if (result.Rows.Contains(strField) == false)
  5635.                                         {
  5636.                                             this.DebugInfo(strField + " is missing, Adding it to the table!");
  5637.                                             sqlAltertable = string.Concat(sqlAltertable, "ADD COLUMN `" + strField + "` mediumint(8) unsigned DEFAULT '0', ");
  5638.                                             fieldMissing = true;
  5639.                                         }
  5640.                                     }
  5641.                                 }
  5642.                                 if (fieldMissing == true)
  5643.                                 {
  5644.                                     TableTransaction = null;
  5645.                                     TableTransaction = TablebuilderCon.BeginTransaction();
  5646.                                     SQLTable = "ALTER TABLE `" + this.tbl_awards + "` ENGINE = MyISAM";
  5647.                                     using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5648.                                     {
  5649.                                         OdbcCom.ExecuteNonQuery();
  5650.                                     }
  5651.                                     //Adding Columns
  5652.                                     int charindex = sqlAltertable.LastIndexOf(",");
  5653.                                     if (charindex > 0)
  5654.                                     {
  5655.                                         sqlAltertable = sqlAltertable.Remove(charindex);
  5656.                                     }
  5657.                                     using (MySqlCommand OdbcCom = new MySqlCommand(sqlAltertable, TablebuilderCon, TableTransaction))
  5658.                                     {
  5659.                                         OdbcCom.ExecuteNonQuery();
  5660.                                     }
  5661.                                     SQLTable = "ALTER TABLE `" + this.tbl_awards + "` ENGINE = InnoDB";
  5662.                                     using (MySqlCommand OdbcCom = new MySqlCommand(SQLTable, TablebuilderCon, TableTransaction))
  5663.                                     {
  5664.                                         OdbcCom.ExecuteNonQuery();
  5665.                                     }
  5666.                                     TableTransaction.Commit();
  5667.                                 }
  5668.                                 */
  5669.                             }
  5670.  
  5671.                             catch (MySqlException oe)
  5672.                             {
  5673.                                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in Tablebuilder: ");
  5674.                                 this.DisplayMySqlErrorCollection(oe);
  5675.                                 TableTransaction.Rollback();
  5676.                             }
  5677.                             catch (Exception c)
  5678.                             {
  5679.                                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error: " + c);
  5680.                                 TableTransaction.Rollback();
  5681.                                 this.boolTableEXISTS = false;
  5682.                                 this.m_ID_cache.Clear();
  5683.                             }
  5684.                             finally
  5685.                             {
  5686.                                 TablebuilderCon.Close();
  5687.                             }
  5688.                         }
  5689.                     }
  5690.                     catch (MySqlException oe)
  5691.                     {
  5692.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in Tablebuilder: ");
  5693.                         this.DisplayMySqlErrorCollection(oe);
  5694.                     }
  5695.                     catch (Exception c)
  5696.                     {
  5697.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error: " + c);
  5698.                     }
  5699.                 }
  5700.             }
  5701.         }
  5702.  
  5703.         private void LogChat(string strSpeaker, string strMessage, string strType)
  5704.         {
  5705.             try
  5706.             {
  5707.                 if (this.m_enChatloggingON == enumBoolYesNo.No)
  5708.                 {
  5709.                     return;
  5710.                 }
  5711.                 if (this.m_enNoServerMsg == enumBoolYesNo.No && strSpeaker.CompareTo("Server") == 0)
  5712.                 {
  5713.                     return;
  5714.                 }
  5715.                 if (this.m_enChatlogFilter == enumBoolYesNo.Yes)
  5716.                 {
  5717.                     //Filter Messages
  5718.                     foreach (Regex FilterRule in this.lstChatFilterRules)
  5719.                     {
  5720.                         if (FilterRule.IsMatch(strMessage))
  5721.                         {
  5722.                             //dont log
  5723.                             this.DebugInfo("Trace", "Chatmessage: '" + strMessage + "' was filtered out by the Regex rule: " + FilterRule.ToString());
  5724.                             return;
  5725.                         }
  5726.                     }
  5727.                 }
  5728.                 if (m_enInstantChatlogging == enumBoolYesNo.Yes)
  5729.                 {
  5730.                     string query = "INSERT INTO " + this.tbl_chatlog + @" (logDate, ServerID, logSubset, logSoldierName, logMessage) VALUES (@logDate, @ServerID, @logSubset, @logSoldierName, @logMessage)";
  5731.                     this.tablebuilder();
  5732.                     if ((m_strHost != null) || (m_strDatabase != null) || (m_strDBPort != null) || (m_strUserName != null) || (m_strPassword != null))
  5733.                     {
  5734.                         if (this.m_highPerformanceConnectionMode == enumBoolOnOff.On)
  5735.                         {
  5736.                             try
  5737.                             {
  5738.                                 using (MySqlConnection Connection = new MySqlConnection(this.DBConnectionStringBuilder()))
  5739.                                 {
  5740.                                     Connection.Open();
  5741.                                     if (Connection.State == ConnectionState.Open)
  5742.                                     {
  5743.                                         using (MySqlCommand OdbcCom = new MySqlCommand(query, Connection))
  5744.                                         {
  5745.                                             OdbcCom.Parameters.AddWithValue("@logDate", MyDateTime.Now);
  5746.                                             OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  5747.                                             OdbcCom.Parameters.AddWithValue("@logSubset", strType);
  5748.                                             OdbcCom.Parameters.AddWithValue("@logSoldierName", strSpeaker);
  5749.                                             OdbcCom.Parameters.AddWithValue("@logMessage", strMessage);
  5750.                                             OdbcCom.ExecuteNonQuery();
  5751.                                         }
  5752.                                     }
  5753.                                     Connection.Close();
  5754.                                 }
  5755.                             }
  5756.                             catch (MySqlException oe)
  5757.                             {
  5758.                                 this.DebugInfo("Error", "LogChat: ");
  5759.                                 this.DisplayMySqlErrorCollection(oe);
  5760.                             }
  5761.                             catch (Exception c)
  5762.                             {
  5763.                                 this.DebugInfo("Error", "LogChat: " + c);
  5764.                             }
  5765.                         }
  5766.                         else
  5767.                         {
  5768.                             lock (this.chatloglock)
  5769.                             {
  5770.                                 try
  5771.                                 {
  5772.                                     if (this.MySqlChatCon == null)
  5773.                                     {
  5774.                                         this.MySqlChatCon = new MySqlConnection(this.DBConnectionStringBuilder());
  5775.                                     }
  5776.                                     if (MySqlChatCon.State != ConnectionState.Open)
  5777.                                     {
  5778.                                         this.MySqlChatCon.Open();
  5779.                                     }
  5780.                                     if (MySqlChatCon.State == ConnectionState.Open)
  5781.                                     {
  5782.                                         using (MySqlCommand OdbcCom = new MySqlCommand(query, MySqlChatCon))
  5783.                                         {
  5784.                                             OdbcCom.Parameters.AddWithValue("@logDate", MyDateTime.Now);
  5785.                                             OdbcCom.Parameters.AddWithValue("@ServerID", this.ServerID);
  5786.                                             OdbcCom.Parameters.AddWithValue("@logSubset", strType);
  5787.                                             OdbcCom.Parameters.AddWithValue("@logSoldierName", strSpeaker);
  5788.                                             OdbcCom.Parameters.AddWithValue("@logMessage", strMessage);
  5789.                                             OdbcCom.ExecuteNonQuery();
  5790.                                         }
  5791.                                     }
  5792.                                 }
  5793.                                 catch (MySqlException oe)
  5794.                                 {
  5795.                                     this.DebugInfo("Error", "LogChat: ");
  5796.                                     this.DisplayMySqlErrorCollection(oe);
  5797.                                     try
  5798.                                     {
  5799.                                         if (MySqlChatCon.State == ConnectionState.Open)
  5800.                                         {
  5801.                                             MySqlChatCon.Dispose();
  5802.                                         }
  5803.                                     }
  5804.                                     catch { }
  5805.                                 }
  5806.                                 catch (Exception c)
  5807.                                 {
  5808.                                     this.DebugInfo("Error", "LogChat: " + c);
  5809.                                     try
  5810.                                     {
  5811.                                         if (MySqlChatCon.State == ConnectionState.Open)
  5812.                                         {
  5813.                                             MySqlChatCon.Close();
  5814.                                         }
  5815.                                     }
  5816.                                     catch { }
  5817.                                 }
  5818.                                 finally
  5819.                                 {
  5820.                                     try
  5821.                                     {
  5822.                                         if (MySqlChatCon != null)
  5823.                                         {
  5824.                                             MySqlChatCon.Close();
  5825.                                         }
  5826.                                     }
  5827.                                     catch { }
  5828.  
  5829.                                 }
  5830.                             }
  5831.                         }
  5832.                     }
  5833.                 }
  5834.                 else
  5835.                 {
  5836.                     CLogger chat = new CLogger(MyDateTime.Now, strSpeaker, strMessage, strType);
  5837.                     ChatLog.Add(chat);
  5838.                 }
  5839.             }
  5840.             catch (Exception c)
  5841.             {
  5842.                 this.DebugInfo("Error", "LogChat_2: " + c);
  5843.             }
  5844.         }
  5845.  
  5846.         public void DebugInfo(string debuglevel, string DebugMessage)
  5847.         {
  5848.             switch (this.GlobalDebugMode)
  5849.             {
  5850.                 case "Trace":
  5851.                     //Post every Message
  5852.                     break;
  5853.                 case "Info":
  5854.                     if (String.Equals(debuglevel, "Trace") == true)
  5855.                     {
  5856.                         return;
  5857.                     }
  5858.                     break;
  5859.                 case "Warning":
  5860.                     if (String.Equals(debuglevel, "Trace") == true || String.Equals(debuglevel, "Info") == true)
  5861.                     {
  5862.                         return;
  5863.                     }
  5864.                     break;
  5865.                 case "Error":
  5866.                     if (String.Equals(debuglevel, "Error") == false)
  5867.                     {
  5868.                         return;
  5869.                     }
  5870.                     break;
  5871.             }
  5872.             // Post error Message in correct Format
  5873.             if (String.Equals(debuglevel, "Trace"))
  5874.             {
  5875.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "[Statslogger]Trace: " + DebugMessage);
  5876.             }
  5877.             else if (String.Equals(debuglevel, "Info"))
  5878.             {
  5879.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^2" + "[Statslogger]Info: " + DebugMessage);
  5880.             }
  5881.             else if (String.Equals(debuglevel, "Warning"))
  5882.             {
  5883.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^3" + "[Statslogger]Warning: " + DebugMessage);
  5884.             }
  5885.             else if (String.Equals(debuglevel, "Error"))
  5886.             {
  5887.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^8" + "[Statslogger]Error: " + DebugMessage);
  5888.             }
  5889.         }
  5890.  
  5891.         private void PrepareKeywordDic()
  5892.         {
  5893.             if (boolKeywordDicReady == false)
  5894.             {
  5895.                 this.DebugInfo("Trace", "PrepareKeywordDic: Preparing");
  5896.                 this.m_dicKeywords.Clear();
  5897.                 try
  5898.                 {
  5899.                     foreach (KeyValuePair<string, string> kvp in this.DamageClass)
  5900.                     {
  5901.                         if (this.m_dicKeywords.ContainsKey(kvp.Key) == false)
  5902.                         {
  5903.                             this.m_dicKeywords.Add(kvp.Key, new List<string>());
  5904.                             this.m_dicKeywords[kvp.Key].Add(kvp.Key.ToUpper());
  5905.  
  5906.                             string[] weaponName = Regex.Replace(kvp.Key.Replace("Weapons/", "").Replace("Gadgets/", ""), @"XP\d_", "").Split('/');
  5907.                             string friendlyname = weaponName[0].Replace(' ', '_').Replace(".", "").Replace("U_", "").ToUpper();
  5908.                             if (this.m_dicKeywords.ContainsKey(friendlyname) == false)
  5909.                             {
  5910.                                 this.m_dicKeywords[kvp.Key].Add(friendlyname);
  5911.                             }
  5912.                         }
  5913.                     }
  5914.                     string dicKey = String.Empty;
  5915.                     string dicValue = String.Empty;
  5916.                     foreach (string line in m_lstTableconfig)
  5917.                     {
  5918.                         if (line.Contains("{") && line.Contains("}"))
  5919.                         {
  5920.                             dicKey = line.Remove(line.IndexOf("{"));
  5921.                             dicValue = line.Replace("{", ",");
  5922.                             dicValue = dicValue.Replace("}", "").ToUpper();
  5923.                             string[] arrStrings = dicValue.Split(',');
  5924.                             if (this.m_dicKeywords.ContainsKey(dicKey))
  5925.                             {
  5926.                                 //Pr��
  5927.                                 this.m_dicKeywords[dicKey].AddRange(arrStrings);
  5928.                                 /*
  5929.                                 foreach (string entry in this.m_dicKeywords[dicKey])
  5930.                                 {
  5931.                                     this.DebugInfo("Trace", "PrepareKeywordDic: " + entry);
  5932.                                 }
  5933.                                 */
  5934.                             }
  5935.                             else
  5936.                             {
  5937.                                 this.DebugInfo("Warning", "PrepareKeywordDic: Mainkey " + dicKey + " not found!");
  5938.                             }
  5939.                         }
  5940.                     }
  5941.                 }
  5942.                 catch (Exception c)
  5943.                 {
  5944.                     this.DebugInfo("Error", "Error in PrepareKeywordDic: " + c);
  5945.                 }
  5946.             }
  5947.         }
  5948.  
  5949.         public string FindKeyword(string strToFind)
  5950.         {
  5951.             try
  5952.             {
  5953.                 this.DebugInfo("Trace", "FindKeyword: " + strToFind);
  5954.                 foreach (KeyValuePair<string, List<string>> kvp in this.m_dicKeywords)
  5955.                 {
  5956.                     if (kvp.Value.Contains(strToFind.Replace(" ", "")))
  5957.                     {
  5958.                         this.DebugInfo("Trace", "FindKeyword: Returning Key " + kvp.Key);
  5959.                         return kvp.Key;
  5960.                     }
  5961.                 }
  5962.             }
  5963.             catch (Exception c)
  5964.             {
  5965.                 this.DebugInfo("Error", "FindKeyword: " + c);
  5966.             }
  5967.             return String.Empty;
  5968.         }
  5969.  
  5970.         public List<string> ListReplace(List<string> targetlist, string wordToReplace, string replacement)
  5971.         {
  5972.             List<string> lstResult = new List<string>();
  5973.             foreach (string substring in targetlist)
  5974.             {
  5975.                 lstResult.Add(substring.Replace(wordToReplace, replacement));
  5976.             }
  5977.             return lstResult;
  5978.         }
  5979.  
  5980.         private void CheckMessageLength(string strMessage, int intMessagelength)
  5981.         {
  5982.             if (strMessage.Length > intMessagelength)
  5983.             {
  5984.                 //Send Warning
  5985.                 this.DebugInfo("Warning", strMessage);
  5986.                 this.DebugInfo("Warning", "This Ingamemessage is too long and wont sent to Server!!!");
  5987.                 this.DebugInfo("Warning", "The Message has a Length of " + strMessage.Length.ToString() + " Chars, Allow are 128 Chars");
  5988.             }
  5989.         }
  5990.  
  5991.         private void CreateSession(string SoldierName, int intScore, string EAGUID)
  5992.         {
  5993.             if (this.ServerID == 0)
  5994.             {
  5995.                 return;
  5996.             }
  5997.             try
  5998.             {
  5999.                 if (this.m_sessionON == enumBoolYesNo.Yes)
  6000.                 {
  6001.                     //Session
  6002.                     lock (this.sessionlock)
  6003.                     {
  6004.                         if (this.m_dicSession.ContainsKey(SoldierName) == false)
  6005.                         {
  6006.                             //this.DebugInfo("Trace", "Session for Player: " + SoldierName + " created");
  6007.                             this.m_dicSession.Add(SoldierName, new CStats(String.Empty,intScore, 0, 0, 0, 0, 0, 0, this.m_dTimeOffset, this.weaponDic));
  6008.                             this.m_dicSession[SoldierName].Rank = this.GetRank(SoldierName);
  6009.                         }
  6010.                     }
  6011.                 }
  6012.             }
  6013.             catch (Exception c)
  6014.             {
  6015.                 this.DebugInfo("Error", "CreateSession: " + c);
  6016.             }
  6017.             finally
  6018.             {
  6019.                 lock (this.sessionlock)
  6020.                 {
  6021.                     //Session Score
  6022.                     if (this.m_dicSession.ContainsKey(SoldierName) && this.m_sessionON == enumBoolYesNo.Yes)
  6023.                     {
  6024.                         this.m_dicSession[SoldierName].AddScore(intScore);
  6025.                         if (EAGUID.Length > 2)
  6026.                         {
  6027.                             this.m_dicSession[SoldierName].EAGuid = EAGUID;
  6028.                         }
  6029.                     }
  6030.                 }
  6031.             }
  6032.         }
  6033.         /*
  6034.         private void RemoveSession(string SoldierName)
  6035.         {
  6036.             try
  6037.             {
  6038.                 if (m_sessionON == enumBoolYesNo.Yes)
  6039.                 {
  6040.                     if (this.m_dicSession.ContainsKey(SoldierName) == true)
  6041.                     {
  6042.                         //Passed seesion to list
  6043.                         this.lstpassedSessions.Add(m_dicSession[SoldierName]);
  6044.                         this.m_dicSession.Remove(SoldierName);
  6045.                     }
  6046.                 }
  6047.             }
  6048.             catch (Exception c)
  6049.             {
  6050.                 this.DebugInfo("Error", "RemoveSession: " + c);
  6051.             }
  6052.         }
  6053.         */
  6054.         private void GetServerStats(string SoldierName, int delay, string scope)
  6055.         {
  6056.             string SQL = @"SELECT * FROM " + this.tbl_server_stats + @" WHERE ServerID = @ServerID";
  6057.             List<string> result = new List<string>(this.m_lstServerstatsMsg);
  6058.             try
  6059.             {
  6060.                 using (MySqlCommand SelectCommand = new MySqlCommand(SQL))
  6061.                 {
  6062.                     SelectCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  6063.                     DataTable sqlresult = this.SQLquery(SelectCommand);
  6064.                     if (sqlresult != null)
  6065.                     {
  6066.                         foreach (DataRow row in sqlresult.Rows)
  6067.                         {
  6068.                             result = this.ListReplace(result, "%serverName%", this.serverName);
  6069.                             //COUNT
  6070.                             result = this.ListReplace(result, "%countPlayer%", Convert.ToInt64(row["CountPlayers"]).ToString());
  6071.                             //SUM
  6072.                             result = this.ListReplace(result, "%sumScore%", Convert.ToInt64(row["SumScore"]).ToString());
  6073.                             result = this.ListReplace(result, "%sumKills%", Convert.ToInt64(row["SumKills"]).ToString());
  6074.                             result = this.ListReplace(result, "%sumHeadshots%", Convert.ToInt64(row["SumHeadshots"]).ToString());
  6075.                             result = this.ListReplace(result, "%sumDeaths%", Convert.ToInt64(row["SumDeaths"]).ToString());
  6076.                             result = this.ListReplace(result, "%sumSuicide%", Convert.ToInt64(row["SumSuicide"]).ToString());
  6077.                             result = this.ListReplace(result, "%sumTKs%", Convert.ToInt64(row["SumTKs"]).ToString());
  6078.                             result = this.ListReplace(result, "%sumRounds%", Convert.ToInt64(row["SumRounds"]).ToString());
  6079.  
  6080.                             //AVG
  6081.                             result = this.ListReplace(result, "%avgScore%", Convert.ToInt64(row["AvgScore"]).ToString());
  6082.                             result = this.ListReplace(result, "%avgKills%", Convert.ToInt64(row["AvgKills"]).ToString());
  6083.                             result = this.ListReplace(result, "%avgHeadshots%", Convert.ToInt64(row["AvgHeadshots"]).ToString());
  6084.                             result = this.ListReplace(result, "%avgDeaths%", Convert.ToInt64(row["AvgDeaths"]).ToString());
  6085.                             result = this.ListReplace(result, "%avgSuicide%", Convert.ToInt64(row["AvgSuicide"]).ToString());
  6086.                             result = this.ListReplace(result, "%avgTKs%", Convert.ToInt64(row["AvgTKs"]).ToString());
  6087.                             result = this.ListReplace(result, "%avgRounds%", Convert.ToInt64(row["AvgRounds"]).ToString());
  6088.                             //MISC.
  6089.                             //SPM
  6090.                             result = this.ListReplace(result, "%avgSPM%", Math.Round(Convert.ToDouble(row["SumScore"]) / (Convert.ToDouble(row["SumPlaytime"]) / 60), 2).ToString());
  6091.                             //KPM
  6092.                             result = this.ListReplace(result, "%avgKPM%", Math.Round(Convert.ToDouble(row["SumKills"]) / (Convert.ToDouble(row["SumPlaytime"]) / 60), 2).ToString());
  6093.                             //HPM
  6094.                             result = this.ListReplace(result, "%avgHPM%", Math.Round(Convert.ToDouble(row["SumHeadshots"]) / (Convert.ToDouble(row["SumPlaytime"]) / 60), 2).ToString());
  6095.                             //HPK
  6096.                             result = this.ListReplace(result, "%avgHPK%", Math.Round(Convert.ToDouble(row["SumHeadshots"]) / (Convert.ToDouble(row["SumKills"])), 2).ToString());
  6097.                             //Playtime
  6098.                             TimeSpan span = new TimeSpan(0, 0, Convert.ToInt32(row["SumPlaytime"]), 0, 0);
  6099.                             result = this.ListReplace(result, "%sumPlaytime%", span.Days + "d:" + span.Hours + "h:" + span.Minutes + "m:" + span.Seconds + "s");
  6100.                             result = this.ListReplace(result, "%sumPlaytimeHours%", Math.Round(span.TotalHours, 2).ToString());
  6101.                             result = this.ListReplace(result, "%sumPlaytimeDays%", Math.Round(span.TotalDays, 2).ToString());
  6102.                             //avg. Playtime
  6103.                             span = new TimeSpan(0, 0, Convert.ToInt32(row["AvgPlaytime"]), 0, 0);
  6104.                             result = this.ListReplace(result, "%avgPlaytime%", span.Days + "d:" + span.Hours + "h:" + span.Minutes + "m:" + span.Seconds + "s");
  6105.                             result = this.ListReplace(result, "%avgPlaytimeHours%", Math.Round(span.TotalHours, 2).ToString());
  6106.                             result = this.ListReplace(result, "%avgPlaytimeDays%", Math.Round(span.TotalDays, 2).ToString());
  6107.                         }
  6108.  
  6109.                         if (result.Count != 0)
  6110.                         {
  6111.                             this.SendMultiLineChatMessage(result, delay, 0, scope, SoldierName);
  6112.                         }
  6113.                         else
  6114.                         {
  6115.                             result.Clear();
  6116.                             result.Add("No Serverdata available!");
  6117.                             this.SendMultiLineChatMessage(result, delay, 0, scope, SoldierName);
  6118.                         }
  6119.                     }
  6120.                 }
  6121.             }
  6122.             catch (Exception c)
  6123.             {
  6124.                 this.DebugInfo("Error", "GetServerStats: " + c);
  6125.             }
  6126.  
  6127.         }
  6128.  
  6129.         private void GetSession(string SoldierName, int delay, string scope)
  6130.         {
  6131.             if (this.ServerID == 0)
  6132.             {
  6133.                 return;
  6134.             }
  6135.             try
  6136.             {
  6137.                 if (this.m_dicSession.ContainsKey(SoldierName) && this.m_sessionON == enumBoolYesNo.Yes)
  6138.                 {
  6139.                     List<string> result = new List<string>();
  6140.                     result = m_lstSessionMessage;
  6141.                     result = ListReplace(result, "%playerName%", SoldierName);
  6142.                     result = ListReplace(result, "%playerScore%", this.m_dicSession[SoldierName].Score.ToString());
  6143.                     result = ListReplace(result, "%playerKills%", this.m_dicSession[SoldierName].Kills.ToString());
  6144.                     result = ListReplace(result, "%killstreak%", this.m_dicSession[SoldierName].Killstreak.ToString());
  6145.                     result = ListReplace(result, "%playerDeaths%", this.m_dicSession[SoldierName].Deaths.ToString());
  6146.                     result = ListReplace(result, "%deathstreak%", this.m_dicSession[SoldierName].Deathstreak.ToString());
  6147.                     result = ListReplace(result, "%playerKDR%", this.m_dicSession[SoldierName].KDR().ToString());
  6148.                     result = ListReplace(result, "%playerHeadshots%", this.m_dicSession[SoldierName].Headshots.ToString());
  6149.                     result = ListReplace(result, "%playerSuicide%", this.m_dicSession[SoldierName].Suicides.ToString());
  6150.                     result = ListReplace(result, "%playerTK%", this.m_dicSession[SoldierName].Teamkills.ToString());
  6151.                     result = ListReplace(result, "%startRank%", this.m_dicSession[SoldierName].Rank.ToString());
  6152.                     //Rankdiff
  6153.                     int playerRank = this.GetRank(SoldierName);
  6154.                     //int playerRank = 0;
  6155.                     result = ListReplace(result, "%playerRank%", playerRank.ToString());
  6156.                     int Rankdif = this.m_dicSession[SoldierName].Rank;
  6157.                     Rankdif = Rankdif - playerRank;
  6158.                     if (Rankdif == 0)
  6159.                     {
  6160.                         result = ListReplace(result, "%RankDif%", "0");
  6161.                     }
  6162.                     else if (Rankdif > 0)
  6163.                     {
  6164.                         result = ListReplace(result, "%RankDif%", "+" + Rankdif.ToString());
  6165.                     }
  6166.                     else
  6167.                     {
  6168.                         result = ListReplace(result, "%RankDif%", Rankdif.ToString());
  6169.                     }
  6170.                     result = ListReplace(result, "%SessionStarted%", this.m_dicSession[SoldierName].TimePlayerjoined.ToString());
  6171.                     TimeSpan duration = MyDateTime.Now - this.m_dicSession[SoldierName].TimePlayerjoined;
  6172.                     result = ListReplace(result, "%SessionDuration%", Math.Round(duration.TotalMinutes, 2).ToString());
  6173.  
  6174.                     if (result.Count != 0)
  6175.                     {
  6176.                         this.SendMultiLineChatMessage(result, delay, 0, scope, SoldierName);
  6177.                     }
  6178.                     else
  6179.                     {
  6180.                         result.Clear();
  6181.                         result.Add("No Sessiondata are available!");
  6182.                         this.SendMultiLineChatMessage(result, delay, 0, scope, SoldierName);
  6183.                     }
  6184.                 }
  6185.             }
  6186.             catch (Exception c)
  6187.             {
  6188.                 this.DebugInfo("Error", "GetSession: " + c);
  6189.             }
  6190.         }
  6191.  
  6192.         private int GetRank(string SoldierName)
  6193.         {
  6194.             //this.DebugInfo("Trace", "GetRank: " + SoldierName);
  6195.             int rank = 0;
  6196.             try
  6197.             {
  6198.                 string SQL = String.Empty;
  6199.                 if (m_enRankingByScore == enumBoolYesNo.Yes)
  6200.                 {
  6201.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  6202.                     {
  6203.                         SQL = @"SELECT tpr.rankScore AS rank
  6204.                                FROM " + this.tbl_playerrank + @" tpr
  6205.                                INNER JOIN " + this.tbl_playerdata + @" tpd ON tpr.PlayerID = tpd.PlayerID
  6206.                                WHERE tpd.SoldierName = @SoldierName AND tpr.ServerGroup = @ServerGroup";
  6207.                     }
  6208.                     else
  6209.                     {
  6210.                         SQL = @"SELECT tps.rankScore AS rank
  6211.                                FROM " + this.tbl_playerstats + @" tps
  6212.                                INNER JOIN " + this.tbl_server_player + @" tsp ON tps.StatsID = tsp.StatsID
  6213.                                INNER JOIN " + this.tbl_playerdata + @" tpd ON tsp.PlayerID = tpd.PlayerID
  6214.                                WHERE  tpd.SoldierName = @SoldierName AND tsp.ServerID = @ServerID";
  6215.                     }
  6216.                 }
  6217.                 else
  6218.                 {
  6219.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  6220.                     {
  6221.                         SQL = @"SELECT tpr.rankKills AS rank
  6222.                                FROM " + this.tbl_playerrank + @" tpr
  6223.                                INNER JOIN " + this.tbl_playerdata + @" tpd ON tpr.PlayerID = tpd.PlayerID
  6224.                                WHERE tpd.SoldierName = @SoldierName AND tpr.ServerGroup = @ServerGroup";
  6225.                     }
  6226.                     else
  6227.                     {
  6228.                         SQL = @"SELECT tps.rankKills AS rank
  6229.                                FROM " + this.tbl_playerstats + @" tps
  6230.                                INNER JOIN " + this.tbl_server_player + @" tsp ON tps.StatsID = tsp.StatsID
  6231.                                INNER JOIN " + this.tbl_playerdata + @" tpd ON tsp.PlayerID = tpd.PlayerID
  6232.                                WHERE  tpd.SoldierName = @SoldierName AND tsp.ServerID = @ServerID";
  6233.                     }
  6234.                 }
  6235.                 using (MySqlCommand SelectCommand = new MySqlCommand(SQL))
  6236.                 {
  6237.                     if (this.m_enOverallRanking == enumBoolYesNo.Yes)
  6238.                     {
  6239.                         SelectCommand.Parameters.AddWithValue("@SoldierName", SoldierName);
  6240.                         SelectCommand.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  6241.                     }
  6242.                     else
  6243.                     {
  6244.                         SelectCommand.Parameters.AddWithValue("@SoldierName", SoldierName);
  6245.                         SelectCommand.Parameters.AddWithValue("@ServerID", this.ServerID);
  6246.                     }
  6247.                     DataTable result = this.SQLquery(SelectCommand);
  6248.                     if (result != null)
  6249.                     {
  6250.                         foreach (DataRow row in result.Rows)
  6251.                         {
  6252.                             if (Convert.DBNull.Equals(row[0]) == false)
  6253.                             {
  6254.                                 rank = Convert.ToInt32(row[0]);
  6255.                                 this.DebugInfo("Trace", SoldierName + " Rank: " + row[0].ToString());
  6256.                             }
  6257.                         }
  6258.                     }
  6259.                 }          
  6260.             }
  6261.             catch (MySqlException oe)
  6262.             {
  6263.                 this.DebugInfo("Error", "Error in GetRank: ");
  6264.                 this.DisplayMySqlErrorCollection(oe);
  6265.             }
  6266.             catch (Exception c)
  6267.             {
  6268.                 this.DebugInfo("Error", "Error in GetRank: " + c);
  6269.             }
  6270.             return rank;
  6271.         }
  6272.  
  6273.         public void PluginInfo(string strPlayer)
  6274.         {
  6275.             //this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger","0", "1", "1", "procon.protected.send", "admin.say","This Server running the PRoCon plugin "+this.GetPluginName+" "+this.GetPluginVersion+"running by "+ this.GetPluginAuthor,"player", strPlayer);
  6276.         }
  6277.  
  6278.         public void DisplayMySqlErrorCollection(MySqlException myException)
  6279.         {
  6280.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Message: " + myException.Message);
  6281.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Native: " + myException.ErrorCode.ToString());
  6282.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Source: " + myException.Source.ToString());
  6283.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1StackTrace: " + myException.StackTrace.ToString());
  6284.                 this.ExecuteCommand("procon.protected.pluginconsole.write", "^1InnerException: " + myException.InnerException.ToString());
  6285.                // this.ExecuteCommand("procon.protected.pluginconsole.write", "^1SQL: " + myException.);
  6286.         }
  6287.  
  6288.         private void prepareTablenames()
  6289.         {
  6290.             this.tbl_playerdata = "tbl_playerdata" + this.tableSuffix;
  6291.             this.tbl_playerstats = "tbl_playerstats" + this.tableSuffix;
  6292.             this.tbl_weaponstats = "tbl_weaponstats" + this.tableSuffix;
  6293.             this.tbl_dogtags = "tbl_dogtags" + this.tableSuffix;
  6294.             this.tbl_mapstats = "tbl_mapstats" + this.tableSuffix;
  6295.             this.tbl_chatlog = "tbl_chatlog" + this.tableSuffix;
  6296.             this.tbl_bfbcs = "tbl_bfbcs" + this.tableSuffix;
  6297.             this.tbl_awards = "tbl_awards" + this.tableSuffix;
  6298.             this.tbl_server = "tbl_server" + this.tableSuffix;
  6299.             this.tbl_server_player = "tbl_server_player" + this.tableSuffix;
  6300.             this.tbl_server_stats = "tbl_server_stats" + this.tableSuffix;
  6301.             this.tbl_playerrank = "tbl_playerrank" + this.tableSuffix;
  6302.             this.tbl_sessions = "tbl_sessions" + this.tableSuffix;
  6303.             this.tbl_currentplayers = "tbl_currentplayers" + this.tableSuffix;
  6304.             this.tbl_weapons = "tbl_weapons" + this.tableSuffix;
  6305.             this.tbl_weapons_stats = "tbl_weapons_stats" + this.tableSuffix;
  6306.             this.tbl_games = "tbl_games" + this.tableSuffix;
  6307.             this.tbl_teamscores = "tbl_teamscores" + this.tableSuffix;
  6308.  
  6309.         }
  6310.  
  6311.         private void setGameMod()
  6312.         {
  6313.             //this.PrepareKeywordDic();
  6314.             this.boolTableEXISTS = false;
  6315.         }
  6316.  
  6317.         /*private void getBFBCStats(List<CPlayerInfo> lstPlayers)
  6318.         {
  6319.             //Disabled temp
  6320.             return;
  6321.             try
  6322.             {
  6323.                 List<string> lstSoldierName = new List<string>();
  6324.                 foreach (CPlayerInfo Player in lstPlayers)
  6325.                 {
  6326.                     DateTime lastUpdate = DateTime.MinValue;
  6327.                     if (this.m_getStatsfromBFBCS == enumBoolYesNo.Yes && Player.SoldierName != null && this.StatsTracker.ContainsKey(Player.SoldierName) == true && this.StatsTracker[Player.SoldierName].BFBCS_Stats.Updated == false && this.StatsTracker[Player.SoldierName].BFBCS_Stats.Fetching == false)
  6328.                     {
  6329.                         string SQL = @"SELECT b.LastUpdate, b.Rank, b.Kills, b.Deaths, b.Score, b.Time
  6330.                                      FROM " + tbl_playerdata + @" a
  6331.                                      INNER JOIN " + tbl_bfbcs + @" b ON a.PlayerID = b.bfbcsID
  6332.                                      WHERE a.SoldierName = @SoldierName";
  6333.  
  6334.                         using (MySqlCommand SelectCommand = new MySqlCommand(SQL))
  6335.                         {
  6336.                             SelectCommand.Parameters.AddWithValue("@SoldierName", Player.SoldierName);
  6337.                             DataTable result = this.SQLquery(SelectCommand);
  6338.  
  6339.                             foreach (DataRow row in result.Rows)
  6340.                             {
  6341.                                 //this.DebugInfo("Last Update: " + row[0].ToString());
  6342.                                 lastUpdate = Convert.ToDateTime(row[0]);
  6343.                                 TimeSpan TimeDifference = MyDateTime.Now.Subtract(lastUpdate);
  6344.                                 //this.DebugInfo(TimeDifference.TotalHours.ToString());
  6345.                                 if (TimeDifference.TotalHours >= this.BFBCS_UpdateInterval && this.StatsTracker[Player.SoldierName].BFBCS_Stats.Fetching == false)
  6346.                                 {
  6347.                                     this.StatsTracker[Player.SoldierName].BFBCS_Stats.Fetching = true;
  6348.                                     lstSoldierName.Add(Player.SoldierName);
  6349.                                 }
  6350.                                 else if (this.StatsTracker.ContainsKey(Player.SoldierName) == true && this.StatsTracker[Player.SoldierName].BFBCS_Stats.Fetching == true)
  6351.                                 {
  6352.                                     //Do nothing
  6353.                                 }
  6354.                                 else
  6355.                                 {
  6356.                                     if (this.StatsTracker.ContainsKey(Player.SoldierName) == true)
  6357.                                     {
  6358.                                         //this.DebugInfo("No Update needed");
  6359.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.Updated = true;
  6360.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.Rank = Convert.ToInt32(row[1]);
  6361.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.Kills = Convert.ToInt32(row[2]);
  6362.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.Deaths = Convert.ToInt32(row[3]);
  6363.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.Score = Convert.ToInt32(row[4]);
  6364.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.Time = Convert.ToDouble(row[5]);
  6365.                                         this.StatsTracker[Player.SoldierName].BFBCS_Stats.NoUpdate = true;
  6366.                                         this.checkPlayerStats(Player.SoldierName, this.m_strReasonMsg);
  6367.                                     }
  6368.                                 }
  6369.                             }
  6370.                         }
  6371.                     }
  6372.                 }
  6373.                 if (lstSoldierName != null && lstSoldierName.Count > 0 && lstSoldierName.Count >= this.BFBCS_Min_Request)
  6374.                 {
  6375.                     //Start Fetching
  6376.                     specialArrayObject ListObject = new specialArrayObject(lstSoldierName);
  6377.                     Thread newThread = new Thread(new ParameterizedThreadStart(this.DownloadBFBCS));
  6378.                     newThread.Start(ListObject);
  6379.                 }
  6380.                 else
  6381.                 {
  6382.                     foreach (string player in lstSoldierName)
  6383.                     {
  6384.                         this.StatsTracker[player].BFBCS_Stats.Fetching = false;
  6385.                         this.StatsTracker[player].BFBCS_Stats.Updated = false;
  6386.                     }
  6387.                 }
  6388.             }
  6389.             catch (Exception c)
  6390.             {
  6391.                 this.DebugInfo("Error", " getBFBCStats: " + c);
  6392.             }
  6393.         }
  6394.  
  6395.         private void DownloadBFBCS(object ListObject)
  6396.         {
  6397.             specialArrayObject ListString = (specialArrayObject)ListObject;
  6398.             List<string> lstSoldierName = new List<string>();
  6399.             lstSoldierName = ListString.LstString;
  6400.             //Define a empty string for parameter
  6401.             string ParameterString = String.Empty;
  6402.             string result = String.Empty;
  6403.             foreach (string SoldierName in lstSoldierName)
  6404.             {
  6405.                 if (this.StatsTracker[SoldierName].BFBCS_Stats.Updated == false)
  6406.                 {
  6407.                     ParameterString = String.Concat(ParameterString, SoldierName, ",");
  6408.                     this.StatsTracker[SoldierName].BFBCS_Stats.Updated = true;
  6409.                 }
  6410.             }
  6411.             ParameterString = ParameterString.Remove(ParameterString.LastIndexOf(","));
  6412.             try
  6413.             {
  6414.                 this.DebugInfo("Trace", "Thread started and fetching Stats from BFBCS for Players: " + ParameterString);
  6415.                 using (WebClient wc = new WebClient())
  6416.                 {
  6417.                     //Thx to IIIAVIII
  6418.                     ParameterString = ParameterString.Replace("&", "%26");
  6419.                     ParameterString = ParameterString.Replace(" ", "%20");
  6420.                     ParameterString = ParameterString.Replace("$", "%24");
  6421.                     ParameterString = ParameterString.Replace("+", "%2B");
  6422.                     ParameterString = ParameterString.Replace("/", "%2F");
  6423.                     ParameterString = ParameterString.Replace("?", "%3F");
  6424.                     ParameterString = ParameterString.Replace("%", "%25");
  6425.                     ParameterString = ParameterString.Replace("#", "%23");
  6426.                     //ParameterString = ParameterString.Replace(",","%2C");
  6427.                     ParameterString = ParameterString.Replace(":", "%3A");
  6428.                     ParameterString = ParameterString.Replace(";", "%3B");
  6429.                     ParameterString = ParameterString.Replace("=", "%3D");
  6430.                     ParameterString = ParameterString.Replace("@", "%40");
  6431.                     ParameterString = ParameterString.Replace("<", "%3C");
  6432.                     ParameterString = ParameterString.Replace(">", "%3E");
  6433.                     ParameterString = ParameterString.Replace("{", "%7B");
  6434.                     ParameterString = ParameterString.Replace("}", "%7D");
  6435.                     ParameterString = ParameterString.Replace("|", "%7C");
  6436.                     ParameterString = ParameterString.Replace(@"\", @"%5C");
  6437.                     ParameterString = ParameterString.Replace("^", "%5E");
  6438.                     ParameterString = ParameterString.Replace("~", "%7E");
  6439.                     ParameterString = ParameterString.Replace("[", "%5B");
  6440.                     ParameterString = ParameterString.Replace("]", "%5D");
  6441.                     ParameterString = ParameterString.Replace("`", "%60");
  6442.  
  6443.                     result = wc.DownloadString("http://api.bfbcs.com/api/pc?players=" + ParameterString + "&fields=basic");
  6444.                 }
  6445.                 if (result == null || result.StartsWith("{") == false)
  6446.                 {
  6447.                     this.DebugInfo("Trace", "the String returned by BFBCS was invalid");
  6448.                     this.DebugInfo("Trace", "Trying to repair the String...");
  6449.                     if (result != null)
  6450.                     {
  6451.                         //result = result.Remove(result.IndexOf("<"),(result.LastIndexOf(">")+1));
  6452.                         if (result.IndexOf("{") > 0)
  6453.                         {
  6454.                             result = result.Substring(result.IndexOf("{"));
  6455.                         }
  6456.                         if (result == null || result.StartsWith("{") == false)
  6457.                         {
  6458.                             this.DebugInfo("Trace", "Repair failed!!!");
  6459.                             return;
  6460.                         }
  6461.                         else
  6462.                         {
  6463.                             this.DebugInfo("Trace", "Repair (might be) successful");
  6464.                         }
  6465.                     }
  6466.                     else
  6467.                     {
  6468.                         this.DebugInfo("Trace", "Empty String...");
  6469.                         return;
  6470.                     }
  6471.                 }
  6472.                 //JSON DECODE
  6473.                 Hashtable jsonHash = (Hashtable)JSON.JsonDecode(result);
  6474.                 if (jsonHash["players"] != null)
  6475.                 {
  6476.                     ArrayList jsonResults = (ArrayList)jsonHash["players"];
  6477.                     //Player with Stats
  6478.                     foreach (object objResult in jsonResults)
  6479.                     {
  6480.                         string stringvalue = String.Empty;
  6481.                         int intvalue = 0;
  6482.                         double doublevalue = 0;
  6483.                         Hashtable playerData = (Hashtable)objResult;
  6484.                         if (playerData != null && lstSoldierName.Contains(playerData["name"].ToString()) == true)
  6485.                         {
  6486.                             stringvalue = playerData["name"].ToString();
  6487.                             this.DebugInfo("Info", "Got BFBC2 stats for " + stringvalue);
  6488.                             int.TryParse(playerData["rank"].ToString(), out intvalue);
  6489.                             this.StatsTracker[stringvalue].BFBCS_Stats.Rank = intvalue;
  6490.                             int.TryParse(playerData["kills"].ToString(), out intvalue);
  6491.                             this.StatsTracker[stringvalue].BFBCS_Stats.Kills = intvalue;
  6492.                             int.TryParse(playerData["deaths"].ToString(), out intvalue);
  6493.                             this.StatsTracker[stringvalue].BFBCS_Stats.Deaths = intvalue;
  6494.                             int.TryParse(playerData["score"].ToString(), out intvalue);
  6495.                             this.StatsTracker[stringvalue].BFBCS_Stats.Score = intvalue;
  6496.                             double.TryParse(playerData["elo"].ToString(), out doublevalue);
  6497.                             this.StatsTracker[stringvalue].BFBCS_Stats.Elo = doublevalue;
  6498.                             double.TryParse(playerData["level"].ToString(), out doublevalue);
  6499.                             this.StatsTracker[stringvalue].BFBCS_Stats.Skilllevel = doublevalue;
  6500.                             double.TryParse(playerData["time"].ToString(), out doublevalue);
  6501.                             this.StatsTracker[stringvalue].BFBCS_Stats.Time = doublevalue;
  6502.                             this.StatsTracker[stringvalue].BFBCS_Stats.Updated = true;
  6503.                             // check Stats
  6504.                             this.checkPlayerStats(stringvalue, this.m_strReasonMsg);
  6505.  
  6506.                         }
  6507.                     }
  6508.                 }
  6509.                 if (jsonHash["players_unknown"] != null)
  6510.                 {
  6511.                     //Player without Stats
  6512.                     ArrayList jsonResults_2 = (ArrayList)jsonHash["players_unknown"];
  6513.                     foreach (object objResult in jsonResults_2)
  6514.                     {
  6515.                         Hashtable playerData = (Hashtable)objResult;
  6516.                         if (playerData != null && lstSoldierName.Contains(playerData["name"].ToString()) == true)
  6517.                         {
  6518.                             this.DebugInfo("Info", "No Stats found for Player: " + playerData["name"].ToString());
  6519.                         }
  6520.                     }
  6521.                 }
  6522.             }
  6523.             catch (Exception c)
  6524.             {
  6525.                 this.DebugInfo("Error", " DownloadBFBCS: " + c);
  6526.                 foreach (string SoldierName in lstSoldierName)
  6527.                 {
  6528.                     this.StatsTracker[SoldierName].BFBCS_Stats.Updated = false;
  6529.                 }
  6530.             }
  6531.         }
  6532.  
  6533.  
  6534.         public void RemovePlayerfromServer(string targetSoldierName, string strReason, string removeAction)
  6535.         {
  6536.             try
  6537.             {
  6538.                 if (targetSoldierName == string.Empty)
  6539.                 {
  6540.                     return;
  6541.                 }
  6542.                 switch (removeAction)
  6543.                 {
  6544.                     case "Kick":
  6545.                         this.ExecuteCommand("procon.protected.send", "admin.kickPlayer", targetSoldierName, strReason);
  6546.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Kicked Player: " + targetSoldierName + " - " + strReason);
  6547.                         break;
  6548.  
  6549.                     case "PBBan":
  6550.                         this.ExecuteCommand("procon.protected.send", "punkBuster.pb_sv_command", String.Format("pb_sv_ban \"{0}\" \"{1}\"", targetSoldierName, "BC2! " + strReason));
  6551.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1PB-Ban for Player: " + targetSoldierName + " - " + strReason);
  6552.                         break;
  6553.  
  6554.                     case "EAGUIDBan":
  6555.                         this.ExecuteCommand("procon.protected.send", "banList.add", "guid", this.StatsTracker[targetSoldierName].EAGuid, "perm", strReason);
  6556.                         this.ExecuteCommand("procon.protected.send", "banList.save");
  6557.                         this.ExecuteCommand("procon.protected.send", "banList.list");
  6558.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1EA-GUID Ban for Player: " + targetSoldierName + " - " + strReason);
  6559.                         break;
  6560.                     case "Nameban":
  6561.                         this.ExecuteCommand("procon.protected.send", "banList.add", "name", targetSoldierName, "perm", strReason);
  6562.                         this.ExecuteCommand("procon.protected.send", "banList.save");
  6563.                         this.ExecuteCommand("procon.protected.send", "banList.list");
  6564.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Nameban for Player: " + targetSoldierName + " - " + strReason);
  6565.                         break;
  6566.                     case "Warn":
  6567.                         this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Warning Player: " + targetSoldierName + " - " + strReason);
  6568.                         break;
  6569.                 }
  6570.             }
  6571.             catch (Exception c)
  6572.             {
  6573.                 this.DebugInfo("Error", " RemovePlayerfromServer: " + c);
  6574.             }
  6575.         }*/
  6576.  
  6577.         private void calculateAwards()
  6578.         {
  6579.             //Disabled temp
  6580.             return;
  6581.             /*
  6582.             string[] arrPlace = new string[] { "None", "None", "None" };
  6583.             int[] arrScores = new int[] { 0, 0, 0 };
  6584.             string BestCombat = "None";
  6585.             int BestCombat_kills = 0;
  6586.             // Place 1 to 3
  6587.             if (this.bool_roundStarted == true && this.StatsTracker.Count >= 4)
  6588.             {
  6589.                 foreach (KeyValuePair<string, CStats> kvp in this.StatsTracker)
  6590.                 {
  6591.                     //Place 1. to 3.
  6592.                     if (kvp.Value.Score > arrScores[0])
  6593.                     {
  6594.                         // 2. to 3.
  6595.                         arrScores[2] = arrScores[1];
  6596.                         arrPlace[2] = arrPlace[1];
  6597.                         // 1. to 2.
  6598.                         arrScores[1] = arrScores[0];
  6599.                         arrPlace[1] = arrPlace[0];
  6600.                         // New 1.
  6601.                         arrScores[0] = kvp.Value.Score;
  6602.                         arrPlace[0] = kvp.Key;
  6603.                     }
  6604.                     else if (kvp.Value.Score > arrScores[1])
  6605.                     {
  6606.                         // 2. to 3.
  6607.                         arrScores[2] = arrScores[1];
  6608.                         arrPlace[2] = arrPlace[1];
  6609.                         //New 2.
  6610.                         arrScores[1] = kvp.Value.Score;
  6611.                         arrPlace[1] = kvp.Key;
  6612.                     }
  6613.                     else if (kvp.Value.Score > arrScores[2])
  6614.                     {
  6615.                         //New 3.
  6616.                         arrScores[2] = kvp.Value.Score;
  6617.                         arrPlace[2] = kvp.Key;
  6618.                     }
  6619.                     //Most Kills - Best Combat
  6620.                     if (kvp.Value.Kills >= 5 && BestCombat_kills < kvp.Value.Kills)
  6621.                     {
  6622.                         BestCombat = kvp.Key;
  6623.                         BestCombat_kills = kvp.Value.Kills;
  6624.                     }
  6625.                    
  6626.                 }
  6627.                 //Set Awards
  6628.                 //1.Place
  6629.                 if (arrPlace[0] != null && String.Equals(arrPlace[0], "None") == false)
  6630.                 {
  6631.                     this.StatsTracker[arrPlace[0]].Awards.dicAdd("First", 1);
  6632.                 }
  6633.                 //2.Place
  6634.                 if (arrPlace[1] != null && String.Equals(arrPlace[1], "None") == false)
  6635.                 {
  6636.                     this.StatsTracker[arrPlace[1]].Awards.dicAdd("Second", 1);
  6637.                 }
  6638.                 //3.Place
  6639.                 if (arrPlace[1] != null && String.Equals(arrPlace[2], "None") == false)
  6640.                 {
  6641.                     this.StatsTracker[arrPlace[2]].Awards.dicAdd("Third", 1);
  6642.                 }
  6643.                 //Best Combat
  6644.                 if (BestCombat != null && String.Equals(BestCombat, "None") == false)
  6645.                 {
  6646.                     this.StatsTracker[BestCombat].Awards.dicAdd("Best_Combat", 1);
  6647.                 }
  6648.             }
  6649.             */
  6650.         }
  6651.  
  6652.         public void Threadstarter_Webrequest()
  6653.         {
  6654.             if (this.m_enWebrequest == enumBoolYesNo.Yes)
  6655.             {
  6656.                 //Temp disabled
  6657.                 // new Thread(Webrequest).Start();
  6658.             }
  6659.         }
  6660.  
  6661.         public void Webrequest()
  6662.         {
  6663.             /*
  6664.             try
  6665.             {
  6666.                 this.DebugInfo("Info", "Thread started and calling the Website:  " + this.m_webAddress);
  6667.                 using (WebClient wc = new WebClient())
  6668.                 {
  6669.                     string result = wc.DownloadString(this.m_webAddress);
  6670.                     if (result.Length > 0)
  6671.                     {
  6672.                         this.DebugInfo("Info", "Got response from Webserver!");
  6673.                     }
  6674.                     else
  6675.                     {
  6676.                         this.DebugInfo("Warning", "Webrequest: Page(" + this.m_webAddress + ") not found!");
  6677.                     }
  6678.                 }
  6679.             }
  6680.             catch (Exception c)
  6681.             {
  6682.                 this.DebugInfo("Error", "Webrequest: " + c);
  6683.             }
  6684.              */
  6685.         }
  6686.  
  6687.         public void generateWeaponList()
  6688.         {
  6689.             this.DebugInfo("Trace", "generateWeaponList");
  6690.             List<string> weapList = new List<string>();
  6691.             this.weaponDic.Clear();
  6692.             this.DamageClass.Clear();
  6693.             try
  6694.             {
  6695.                 WeaponDictionary weapons = this.GetWeaponDefines();
  6696.                 foreach (PRoCon.Core.Players.Items.Weapon weapon in weapons)
  6697.                 {
  6698.                     string[] weaponName = Regex.Replace(weapon.Name.Replace("Weapons/", "").Replace("Gadgets/", ""),@"XP\d_","").Split('/');
  6699.                     if (weapList.Contains(weaponName[0].Replace(' ', '_').Replace(".", "").Replace("U_", "")) == false)
  6700.                     {
  6701.                         weapList.Add(weaponName[0].Replace(' ', '_').Replace(".", "").Replace("U_", ""));
  6702.                     }
  6703.                     if (this.weaponDic.ContainsKey(weapon.Damage.ToString()) == false)
  6704.                     {
  6705.                         this.weaponDic.Add(weapon.Damage.ToString(), new Dictionary<string, CStats.CUsedWeapon>());
  6706.                     }
  6707.                     if (this.weaponDic[weapon.Damage.ToString()].ContainsKey(weapon.Name) == false)
  6708.                     {
  6709.                         this.weaponDic[weapon.Damage.ToString()].Add(weapon.Name, new CStats.CUsedWeapon(weapon.Name, weaponName[0].Replace(' ', '_').Replace(".", "").Replace("U_", ""),weapon.Slot.ToString(),weapon.KitRestriction.ToString()));
  6710.                     }
  6711.                     this.DamageClass.Add(weapon.Name, weapon.Damage.ToString());
  6712.                 }
  6713.                 this.PrepareKeywordDic();
  6714.             }
  6715.             catch (Exception e)
  6716.             {
  6717.                 this.DebugInfo("Error", "generateWeaponList: " + e.ToString());
  6718.             }
  6719.             foreach (KeyValuePair<string, Dictionary<string, CStats.CUsedWeapon>> branch in this.weaponDic)
  6720.             {
  6721.                 foreach (KeyValuePair<string, CStats.CUsedWeapon> leap in branch.Value)
  6722.                 {
  6723.                     this.DebugInfo("Trace", "Weaponlist: DamageType: " + branch.Key + " Name: " + leap.Key);
  6724.                 }
  6725.             }
  6726.         }
  6727.  
  6728.         private void getUpdateServerID(CServerInfo csiServerInfo)
  6729.         {
  6730.             try
  6731.             {
  6732.                 //return;
  6733.                 this.DebugInfo("Trace", "getUpdateServerID");
  6734.                 /*
  6735.                 this.DebugInfo("Trace", "ExternalGameIpandPort: " + this.m_strHostName + ":" + this.m_strPort);
  6736.                 this.DebugInfo("Trace","ExternalGameIpandPort: "+ csiServerInfo.ExternalGameIpandPort);
  6737.                 this.DebugInfo("Trace","ServerName: "+csiServerInfo.ServerName);
  6738.                 this.DebugInfo("Trace","ConnectionState: "+csiServerInfo.ConnectionState);
  6739.                 this.DebugInfo("Trace","CurrentRound: "+csiServerInfo.CurrentRound.ToString());
  6740.                 //this.DebugInfo("Trace","GameMod: "+csiServerInfo.GameMod);
  6741.                 this.DebugInfo("Trace","GameMode: "+csiServerInfo.GameMode);
  6742.                 this.DebugInfo("Trace","JoinQueueEnabled: "+csiServerInfo.JoinQueueEnabled);
  6743.                 this.DebugInfo("Trace","Map: "+csiServerInfo.Map);
  6744.                 this.DebugInfo("Trace","Mappack: "+csiServerInfo.Mappack);
  6745.                 this.DebugInfo("Trace","MaxPlayerCount: "+csiServerInfo.MaxPlayerCount);
  6746.                 this.DebugInfo("Trace","Passworded: "+csiServerInfo.Passworded.ToString());
  6747.                 this.DebugInfo("Trace","PlayerCount: "+csiServerInfo.PlayerCount);
  6748.                 this.DebugInfo("Trace","Punkbuster: "+csiServerInfo.PunkBuster.ToString());
  6749.                 this.DebugInfo("Trace","PunkBusterVersion: "+csiServerInfo.PunkBusterVersion);
  6750.                 this.DebugInfo("Trace","Ranked: "+csiServerInfo.Ranked.ToString());
  6751.                 this.DebugInfo("Trace","RoundTime: "+csiServerInfo.RoundTime.ToString());
  6752.                 this.DebugInfo("Trace","ServerRegion: "+csiServerInfo.ServerRegion);
  6753.                 this.DebugInfo("Trace","ServerUptime: "+csiServerInfo.ServerUptime.ToString());
  6754.                
  6755.                 this.DebugInfo("Trace","TotalRounds: "+csiServerInfo.TotalRounds);
  6756.                
  6757.                 */
  6758.                 //this.DebugInfo("Trace", "TeamScores: " + csiServerInfo.TeamScores.Count.ToString());
  6759.  
  6760.                 this.tablebuilder();
  6761.                 DataTable resultTable;
  6762.                 string SQL = String.Empty;
  6763.                 int attemptCount = 0;
  6764.                 bool success = false;
  6765.                 using (MySqlConnection DBConnection = new MySqlConnection(this.DBConnectionStringBuilder()))
  6766.                 {
  6767.                     MySql.Data.MySqlClient.MySqlTransaction Tx = null;
  6768.                     try
  6769.                     {
  6770.                         DBConnection.Open();
  6771.                         using (MySqlCommand MyCommand = new MySqlCommand("SELECT `ServerID` FROM " + this.tbl_server + @" WHERE IP_Address = @IP_Address"))
  6772.                         {
  6773.                             MyCommand.Parameters.AddWithValue("@IP_Address", this.m_strHostName + ":" + this.m_strPort);
  6774.                             resultTable = this.SQLquery(MyCommand);
  6775.                             if (resultTable.Rows != null)
  6776.                             {
  6777.                                 foreach (DataRow row in resultTable.Rows)
  6778.                                 {
  6779.                                     //this.ServerID = Convert.ToInt32(row[0]);
  6780.                                     int.TryParse(row[0].ToString(), out this.ServerID);
  6781.                                     this.DebugInfo("Trace", "DB returns ServerID = " + this.ServerID);
  6782.                                 }
  6783.                             }
  6784.                         }
  6785.                         if (ServerID <= 0)
  6786.                         {
  6787.                             SQL = @"INSERT INTO " + tbl_server + @" (IP_Address, ServerName, ServerGroup, usedSlots, maxSlots, mapName, GameID, Gamemode) VALUES (@IP_Address, @ServerName, @ServerGroup, @usedSlots, @maxSlots, @mapName, @GameID, @Gamemode)";
  6788.                         }
  6789.                         else
  6790.                         {
  6791.                             SQL = @"UPDATE " + tbl_server + @" SET ServerName = @ServerName, ServerGroup = @ServerGroup , usedSlots = @usedSlots, maxSlots = @maxSlots, mapName = @mapName, GameID = @GameID, Gamemode = @Gamemode WHERE IP_Address = @IP_Address";
  6792.                         }
  6793.                         while (attemptCount < this.TransactionRetryCount && !success)
  6794.                         {
  6795.                             attemptCount++;
  6796.                             try
  6797.                             {
  6798.                                 Tx = DBConnection.BeginTransaction();
  6799.                                 using (MySqlCommand MySqlCom = new MySqlCommand(SQL, DBConnection, Tx))
  6800.                                 {
  6801.                                     MySqlCom.Parameters.AddWithValue("@IP_Address", this.m_strHostName + ":" + this.m_strPort);
  6802.                                     MySqlCom.Parameters.AddWithValue("@ServerName", csiServerInfo.ServerName);
  6803.                                     MySqlCom.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  6804.                                     MySqlCom.Parameters.AddWithValue("@usedSlots", csiServerInfo.PlayerCount);
  6805.                                     MySqlCom.Parameters.AddWithValue("@maxSlots", csiServerInfo.MaxPlayerCount);
  6806.                                     MySqlCom.Parameters.AddWithValue("@mapName", csiServerInfo.Map);
  6807.                                     MySqlCom.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  6808.                                     MySqlCom.Parameters.AddWithValue("@Gamemode", csiServerInfo.GameMode);
  6809.                                     MySqlCom.ExecuteNonQuery();
  6810.                                     if (ServerID == 0)
  6811.                                     {
  6812.                                         int.TryParse(MySqlCom.LastInsertedId.ToString(), out this.ServerID);
  6813.                                     }
  6814.                                 }
  6815.                                 if (ServerID > 0 && this.m_enableCurrentPlayerstatsTable == enumBoolYesNo.Yes && csiServerInfo.TeamScores.Count > 0)
  6816.                                 {
  6817.                                     string ScoreSQL = "DELETE FROM `" + this.tbl_teamscores + "` WHERE `ServerID` = @ServerID";
  6818.                                     using (MySqlCommand MySqlCom = new MySqlCommand(ScoreSQL, DBConnection, Tx))
  6819.                                     {
  6820.                                         MySqlCom.Parameters.AddWithValue("@ServerID", ServerID);
  6821.                                         MySqlCom.ExecuteNonQuery();
  6822.                                     }
  6823.                                     foreach (TeamScore teamscore in csiServerInfo.TeamScores)
  6824.                                     {
  6825.                                         //this.DebugInfo("Trace", "Update Score Table TeamID: " + teamscore.TeamID );
  6826.                                         ScoreSQL = "INSERT INTO `" + this.tbl_teamscores + "` (`ServerID`,`TeamID`,`Score`,`WinningScore`) VALUES(@ServerID, @TeamID, @Score, @WinningScore)";
  6827.                                         using (MySqlCommand MySqlCom = new MySqlCommand(ScoreSQL, DBConnection, Tx))
  6828.                                         {
  6829.                                             MySqlCom.Parameters.AddWithValue("@ServerID", ServerID);
  6830.                                             MySqlCom.Parameters.AddWithValue("@TeamID", teamscore.TeamID);
  6831.                                             MySqlCom.Parameters.AddWithValue("@Score", teamscore.Score);
  6832.                                             MySqlCom.Parameters.AddWithValue("@WinningScore", teamscore.WinningScore);
  6833.                                             MySqlCom.ExecuteNonQuery();
  6834.                                         }
  6835.                                     }
  6836.                                 }
  6837.                                 Tx.Commit();
  6838.                                 success = true;
  6839.                             }
  6840.                             catch (MySqlException ex)
  6841.                             {
  6842.                                 switch (ex.Number)
  6843.                                 {
  6844.                                     case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  6845.                                     case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  6846.                                         this.DebugInfo("Warning", "Warning in getUpdateServer: Lock timeout or Deadlock occured restarting Transaction #1. Attempt: " + attemptCount);
  6847.                                         try
  6848.                                         {
  6849.                                             Tx.Rollback();
  6850.                                         }
  6851.                                         catch { }
  6852.                                         Thread.Sleep(attemptCount * 1000);
  6853.                                         break;
  6854.                                     default:
  6855.                                         throw; //Other exceptions
  6856.                                 }
  6857.                             }
  6858.                         }
  6859.                     }
  6860.                     catch (Exception c)
  6861.                     {
  6862.                         this.DebugInfo("Error", "getUpdateServerID1: " + c);
  6863.                         try
  6864.                         {
  6865.                             Tx.Rollback();
  6866.                         }
  6867.                         catch { }
  6868.                     }
  6869.                     finally
  6870.                     {
  6871.                         try
  6872.                         {
  6873.                             DBConnection.Close();
  6874.                         }
  6875.                         catch { }
  6876.                     }
  6877.                 }
  6878.             }
  6879.             catch (Exception c)
  6880.             {
  6881.                 this.DebugInfo("Error", "getUpdateServerID1: " + c);
  6882.             }
  6883.         }
  6884.  
  6885.         private void UpdateRanking()
  6886.         {
  6887.             try
  6888.             {
  6889.                 //retrycount
  6890.                 int attemptCount = 0;
  6891.                 bool success = false;
  6892.  
  6893.                 //ScoreRanking per server
  6894.                 /*
  6895.                 string sqlupdate1 = @"UPDATE " + this.tbl_playerstats + @" tps
  6896.                                     INNER JOIN (
  6897.                                                 SELECT(@num := @num+1) AS rankScore, tsp.StatsID
  6898.                                                 FROM " + this.tbl_playerstats + @" tps
  6899.                                                 STRAIGHT_JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID ,(SELECT @num := 0) x          
  6900.                                                 WHERE tsp.ServerID = ?
  6901.                                                 ORDER BY tps.Score DESC, tps.StatsID ASC
  6902.                                                 ) sub
  6903.                                     ON sub.StatsID = tps.StatsID
  6904.                                     SET tps.rankScore = sub.rankScore
  6905.                                     WHERE sub.rankScore != tps.rankScore";
  6906.                  */
  6907.                 string sqlupdate1 = @"UPDATE " + this.tbl_playerstats + @" tps
  6908.                                INNER JOIN (
  6909.                                            SELECT (@num := @num+1) AS rankScore, innersub.StatsID FROM
  6910.                                                (  
  6911.                                                    SELECT tsp.StatsID
  6912.                                                    FROM " + this.tbl_playerstats + @" tps
  6913.                                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID ,(SELECT @num := 0) x          
  6914.                                                    WHERE tsp.ServerID = @ServerID
  6915.                                                    ORDER BY tps.Score DESC, tps.StatsID ASC
  6916.                                                ) innersub
  6917.                                            ) sub
  6918.                                ON sub.StatsID = tps.StatsID
  6919.                                SET tps.rankScore = sub.rankScore
  6920.                                WHERE sub.rankScore != tps.rankScore";
  6921.  
  6922.  
  6923.                 //KillsRanking per server
  6924.                 /*
  6925.                 string sqlupdate2 = @"UPDATE " + this.tbl_playerstats + @" tps
  6926.                                       INNER JOIN (
  6927.                                                 SELECT(@num := @num+1) AS rankKills, tsp.StatsID
  6928.                                                 FROM " + this.tbl_playerstats + @" tps
  6929.                                                 STRAIGHT_JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID ,(SELECT @num := 0) y          
  6930.                                                 WHERE tsp.ServerID = ?
  6931.                                                 ORDER BY tps.Kills DESC, tps.Deaths ASC , tps.StatsID ASC
  6932.                                                 ) sub
  6933.                                       ON sub.StatsID = tps.StatsID
  6934.                                       SET tps.rankKills = sub.rankKills
  6935.                                       WHERE tps.rankKills != sub.rankKills";
  6936.                  */
  6937.  
  6938.                 string sqlupdate2 = @"UPDATE " + this.tbl_playerstats + @" tps
  6939.                                INNER JOIN (
  6940.                                            SELECT (@num := @num+1) AS rankKills, innersub.StatsID FROM
  6941.                                                (  
  6942.                                                    SELECT tsp.StatsID
  6943.                                                    FROM " + this.tbl_playerstats + @" tps
  6944.                                                    INNER JOIN " + this.tbl_server_player + @" tsp ON tsp.StatsID = tps.StatsID ,(SELECT @num := 0) x          
  6945.                                                    WHERE tsp.ServerID = @ServerID
  6946.                                                    ORDER BY tps.Kills DESC, tps.Deaths ASC , tps.StatsID ASC
  6947.  
  6948.                                                ) innersub
  6949.                                            ) sub
  6950.                                ON sub.StatsID = tps.StatsID
  6951.                                SET tps.rankKills = sub.rankKills
  6952.                                WHERE sub.rankKills != tps.rankKills";
  6953.  
  6954.                 // Global Updates
  6955.                 string sqlInsert = @"INSERT INTO " + this.tbl_playerrank + @" (PlayerID, ServerGroup)
  6956.                                    SELECT PlayerID, (" + this.intServerGroup + @") AS ServerGroup
  6957.                                    FROM " + this.tbl_playerdata + @"
  6958.                                    WHERE PlayerID NOT IN (SELECT PlayerID FROM " + this.tbl_playerrank + @" WHERE ServerGroup = @ServerGroup)";
  6959.  
  6960.  
  6961.                 string sqlupdate3 = @"  UPDATE " + this.tbl_playerrank + @" tpr
  6962.                                    INNER JOIN (SELECT (@num := @num + 1) AS rankKills, sub1.PlayerID ,sub1.ServerGroup
  6963.                                                      FROM(SELECT tsp.PlayerID, ts.ServerGroup
  6964.                                                           FROM " + this.tbl_server_player + @" tsp
  6965.                                                           INNER JOIN " + this.tbl_server + @" ts ON tsp.ServerID = ts.ServerID
  6966.                                                           INNER JOIN " + this.tbl_playerstats + @" tps  ON  tsp.StatsID = tps.StatsID ,(SELECT @num := 0) x
  6967.                                                           WHERE ts.ServerGroup = @ServerGroup
  6968.                                                           GROUP BY tsp.PlayerID, ts.ServerGroup
  6969.                                                           ORDER BY SUM(tps.Kills) DESC, SUM(tps.Deaths) ASC, tsp.PlayerID ASC  
  6970.                                                     ) sub1
  6971.                                                ) sub
  6972.                                    ON sub.PlayerID = tpr.PlayerID
  6973.                                    SET tpr.rankKills = sub.rankKills
  6974.                                    WHERE tpr.rankKills != sub.rankKills AND sub.ServerGroup = tpr.ServerGroup";
  6975.  
  6976.  
  6977.                 string sqlupdate4 = @"  UPDATE " + this.tbl_playerrank + @" tpr
  6978.                                    INNER JOIN (SELECT (@num := @num + 1) AS rankScore, sub1.PlayerID ,sub1.ServerGroup
  6979.                                                      FROM(SELECT tsp.PlayerID, ts.ServerGroup
  6980.                                                           FROM " + this.tbl_server_player + @" tsp
  6981.                                                           INNER JOIN " + this.tbl_server + @" ts ON tsp.ServerID = ts.ServerID
  6982.                                                           INNER JOIN " + this.tbl_playerstats + @" tps  ON  tsp.StatsID = tps.StatsID ,(SELECT @num := 0) y
  6983.                                                           WHERE ts.ServerGroup = @ServerGroup
  6984.                                                           GROUP BY tsp.PlayerID, ts.ServerGroup
  6985.                                                           ORDER BY SUM(tps.Score) DESC, tsp.PlayerID ASC  
  6986.                                                     ) sub1
  6987.                                                ) sub
  6988.                                    ON sub.PlayerID = tpr.PlayerID AND sub.ServerGroup = tpr.ServerGroup
  6989.                                    SET tpr.rankScore = sub.rankScore
  6990.                                    WHERE tpr.rankScore != sub.rankScore";
  6991.  
  6992.                 MySql.Data.MySqlClient.MySqlTransaction Tx = null;
  6993.                 using (MySqlConnection Con = new MySqlConnection(this.DBConnectionStringBuilder()))
  6994.                 {
  6995.                     try
  6996.                     {
  6997.                         if (Con.State == ConnectionState.Closed)
  6998.                         {
  6999.                             Con.Open();
  7000.                         }
  7001.  
  7002.                         if (boolSkipServerUpdate == false)
  7003.                         {
  7004.                             while (attemptCount < this.TransactionRetryCount && !success)
  7005.                             {
  7006.                                 attemptCount++;
  7007.                                 try
  7008.                                 {
  7009.                                     Tx = Con.BeginTransaction();
  7010.                                     using (MySqlCommand Command = new MySqlCommand(sqlupdate1, Con, Tx))
  7011.                                     {
  7012.                                         Command.Parameters.AddWithValue("@ServerID", this.ServerID);
  7013.                                         Command.ExecuteNonQuery();
  7014.                                     }
  7015.                                     //Commit
  7016.                                     Tx.Commit();
  7017.                                     success = true;
  7018.                                 }
  7019.                                 catch (MySqlException ex)
  7020.                                 {
  7021.                                     switch (ex.Number)
  7022.                                     {
  7023.                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  7024.                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  7025.                                             this.DebugInfo("Warning", "Warning in UpdateRanking: Lock timeout or Deadlock occured restarting Transaction #1. Attempt: " + attemptCount);
  7026.                                             try
  7027.                                             {
  7028.                                                 Tx.Rollback();
  7029.                                             }
  7030.                                             catch { }
  7031.                                             Thread.Sleep(attemptCount * 1000);
  7032.                                             break;
  7033.                                         default:
  7034.                                             throw; //Other exceptions
  7035.                                     }
  7036.                                 }
  7037.                             }
  7038.                             if (attemptCount > this.TransactionRetryCount)
  7039.                             {
  7040.                                 this.DebugInfo("Error", "Error in UpdateRanking: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction #1)");
  7041.                             }
  7042.                             attemptCount = 0;
  7043.                             success = false;
  7044.  
  7045.                             //Next query
  7046.                             while (attemptCount < this.TransactionRetryCount && !success)
  7047.                             {
  7048.                                 attemptCount++;
  7049.                                 try
  7050.                                 {
  7051.                                     //Start new Transaction
  7052.                                     Tx = Con.BeginTransaction();
  7053.                                     using (MySqlCommand Command = new MySqlCommand(sqlupdate2, Con, Tx))
  7054.                                     {
  7055.                                         Command.Parameters.AddWithValue("@ServerID", this.ServerID);
  7056.                                         Command.ExecuteNonQuery();
  7057.                                     }
  7058.                                     //Commit
  7059.                                     Tx.Commit();
  7060.                                     success = true;
  7061.                                 }
  7062.                                 catch (MySqlException ex)
  7063.                                 {
  7064.                                     switch (ex.Number)
  7065.                                     {
  7066.                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  7067.                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  7068.                                             this.DebugInfo("Warning", "Warning in UpdateRanking: Lock timeout or Deadlock occured restarting Transaction #2. Attempt: " + attemptCount);
  7069.                                             try
  7070.                                             {
  7071.                                                 Tx.Rollback();
  7072.                                             }
  7073.                                             catch { }
  7074.                                             Thread.Sleep(attemptCount * 1000);
  7075.                                             break;
  7076.                                         default:
  7077.                                             throw; //Other exceptions
  7078.                                     }
  7079.                                 }
  7080.                             }
  7081.                             if (attemptCount > this.TransactionRetryCount)
  7082.                             {
  7083.                                 this.DebugInfo("Error", "Error in UpdateRanking: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction #2)");
  7084.                             }
  7085.                         }
  7086.                         attemptCount = 0;
  7087.                         success = false;
  7088.  
  7089.                         //Next query
  7090.                         if (boolSkipGlobalUpdate == false)
  7091.                         {
  7092.                             while (attemptCount < this.TransactionRetryCount && !success)
  7093.                             {
  7094.                                 attemptCount++;
  7095.                                 try
  7096.                                 {
  7097.                                     //Start new Transaction
  7098.                                     Tx = Con.BeginTransaction();
  7099.                                     using (MySqlCommand Command = new MySqlCommand(sqlInsert, Con, Tx))
  7100.                                     {
  7101.                                         Command.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  7102.                                         Command.ExecuteNonQuery();
  7103.                                     }
  7104.                                     //Commit
  7105.                                     Tx.Commit();
  7106.                                     success = true;
  7107.                                 }
  7108.                                 catch (MySqlException ex)
  7109.                                 {
  7110.                                     switch (ex.Number)
  7111.                                     {
  7112.                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  7113.                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  7114.                                             this.DebugInfo("Warning", "Warning in UpdateRanking: Lock timeout or Deadlock occured restarting Transaction #3. Attempt: " + attemptCount);
  7115.                                             try
  7116.                                             {
  7117.                                                 Tx.Rollback();
  7118.                                             }
  7119.                                             catch { }
  7120.                                             Thread.Sleep(attemptCount * 1000);
  7121.                                             break;
  7122.                                         default:
  7123.                                             throw; //Other exceptions
  7124.                                     }
  7125.                                 }
  7126.                             }
  7127.                             if (attemptCount > this.TransactionRetryCount)
  7128.                             {
  7129.                                 this.DebugInfo("Error", "Error in UpdateRanking: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction #3)");
  7130.                             }
  7131.                             attemptCount = 0;
  7132.                             success = false;
  7133.  
  7134.                             //Next query
  7135.                             while (attemptCount < this.TransactionRetryCount && !success)
  7136.                             {
  7137.                                 attemptCount++;
  7138.                                 try
  7139.                                 {
  7140.                                     //Start new Transaction
  7141.                                     Tx = Con.BeginTransaction();
  7142.                                     using (MySqlCommand Command = new MySqlCommand(sqlupdate3, Con, Tx))
  7143.                                     {
  7144.                                         Command.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  7145.                                         Command.ExecuteNonQuery();
  7146.                                     }
  7147.                                     //Commit
  7148.                                     Tx.Commit();
  7149.                                     success = true;
  7150.                                 }
  7151.                                 catch (MySqlException ex)
  7152.                                 {
  7153.                                     switch (ex.Number)
  7154.                                     {
  7155.                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  7156.                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  7157.                                             this.DebugInfo("Warning", "Warning in UpdateRanking: Lock timeout or Deadlock occured restarting Transaction #4. Attempt: " + attemptCount);
  7158.                                             try
  7159.                                             {
  7160.                                                 Tx.Rollback();
  7161.                                             }
  7162.                                             catch { }
  7163.                                             Thread.Sleep(attemptCount * 1000);
  7164.                                             break;
  7165.                                         default:
  7166.                                             throw; //Other exceptions
  7167.                                     }
  7168.                                 }
  7169.                             }
  7170.                             if (attemptCount > this.TransactionRetryCount)
  7171.                             {
  7172.                                 this.DebugInfo("Error", "Error in UpdateRanking: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction #4)");
  7173.                             }
  7174.                             attemptCount = 0;
  7175.                             success = false;
  7176.  
  7177.                             //Next query
  7178.                             while (attemptCount < this.TransactionRetryCount && !success)
  7179.                             {
  7180.                                 attemptCount++;
  7181.                                 try
  7182.                                 {
  7183.                                     //Start new Transaction
  7184.                                     Tx = Con.BeginTransaction();
  7185.                                     using (MySqlCommand Command = new MySqlCommand(sqlupdate4, Con, Tx))
  7186.                                     {
  7187.                                         Command.Parameters.AddWithValue("@ServerGroup", this.intServerGroup);
  7188.                                         Command.ExecuteNonQuery();
  7189.                                     }
  7190.                                     Tx.Commit();
  7191.                                     success = true;
  7192.                                 }
  7193.                                 catch (MySqlException ex)
  7194.                                 {
  7195.                                     switch (ex.Number)
  7196.                                     {
  7197.                                         case 1205: //(ER_LOCK_WAIT_TIMEOUT) Lock wait timeout exceeded
  7198.                                         case 1213: //(ER_LOCK_DEADLOCK) Deadlock found when trying to get lock
  7199.                                             this.DebugInfo("Warning", "Warning in UpdateRanking: Lock timeout or Deadlock occured restarting Transaction #5. Attempt: " + attemptCount);
  7200.                                             try
  7201.                                             {
  7202.                                                 Tx.Rollback();
  7203.                                             }
  7204.                                             catch { }
  7205.                                             Thread.Sleep(attemptCount * 1000);
  7206.                                             break;
  7207.                                         default:
  7208.                                             throw; //Other exceptions
  7209.                                     }
  7210.                                 }
  7211.                             }
  7212.                             if (attemptCount > this.TransactionRetryCount)
  7213.                             {
  7214.                                 this.DebugInfo("Error", "Error in UpdateRanking: Maximum number of " + this.TransactionRetryCount + " transaction retrys exceeded (Transaction #5)");
  7215.                             }
  7216.                         }
  7217.                         attemptCount = 0;
  7218.                         success = false;
  7219.                     }
  7220.                     catch (MySqlException oe)
  7221.                     {
  7222.                         this.DebugInfo("Error", "Error in UpdateRanking: ");
  7223.                         this.DisplayMySqlErrorCollection(oe);
  7224.                         if (Tx != null)
  7225.                         {
  7226.                             try
  7227.                             {
  7228.                                 Tx.Rollback();
  7229.                             }
  7230.                             catch { };
  7231.                         }
  7232.                     }
  7233.                     catch (Exception c)
  7234.                     {
  7235.                         this.DebugInfo("Error", "Error in UpdateRanking: " + c);
  7236.                         if (Tx != null)
  7237.                         {
  7238.                             try
  7239.                             {
  7240.                                 Tx.Rollback();
  7241.                             }
  7242.                             catch { };
  7243.                         }
  7244.                     }
  7245.                     finally
  7246.                     {
  7247.                         try
  7248.                         {
  7249.                             Con.Close();
  7250.                         }
  7251.                         catch { };
  7252.                     }
  7253.                 }
  7254.             }
  7255.             catch (Exception c)
  7256.             {
  7257.                 this.DebugInfo("Error", "Error in UpdateRanking: " + c);
  7258.             }
  7259.         }
  7260.  
  7261.         private void checkWelcomeStatsDic()
  7262.         {
  7263.             try
  7264.             {
  7265.                 lock (this.welcomestatsDic)
  7266.                 {
  7267.                     TimeSpan duration = new TimeSpan(0, 10, 0);
  7268.                     List<string> entryToRemove = new List<string>();
  7269.                     foreach (KeyValuePair<string, DateTime> kvp in this.welcomestatsDic)
  7270.                     {
  7271.                         if (duration < (MyDateTime.Now - kvp.Value))
  7272.                         {
  7273.                             entryToRemove.Add(kvp.Key);
  7274.                         }
  7275.                     }
  7276.                     foreach (string entry in entryToRemove)
  7277.                     {
  7278.                         this.DebugInfo("Trace", "Removing Player " + entry + " from welcomestatslist  Timeoutlimit of 10 minutes was exceeded!");
  7279.                         this.welcomestatsDic.Remove(entry);
  7280.                     }
  7281.                 }
  7282.             }
  7283.             catch (Exception c)
  7284.             {
  7285.                 this.DebugInfo("Error", "Error in checkWelcomeStatsDic: " + c);
  7286.             }
  7287.         }
  7288.  
  7289.         private void BuildRegexRuleset()
  7290.         {
  7291.             try
  7292.             {
  7293.                 this.lstChatFilterRules = new List<Regex>();
  7294.                 foreach (string strRule in this.lstStrChatFilterRules)
  7295.                 {
  7296.                     this.lstChatFilterRules.Add(new Regex(strRule.Replace("&#124", "|").Replace("&#124","+")));
  7297.                 }
  7298.  
  7299.                 if (this.GlobalDebugMode.Equals("Trace"))
  7300.                 {
  7301.                     this.DebugInfo("Trace", "Active Regex-Ruleset:");
  7302.                     foreach (Regex regexrule in this.lstChatFilterRules)
  7303.                     {
  7304.                         this.DebugInfo("Trace", regexrule.ToString());
  7305.                     }
  7306.                 }
  7307.             }
  7308.             catch (Exception c)
  7309.             {
  7310.                 this.DebugInfo("Error", "Error in BuildRegexRuleset: " + c);
  7311.             }
  7312.         }
  7313.  
  7314.         private void SendMultiLineChatMessage(List<string> lstMultiLineChatMSG, int intDelay, int delayIncreasePerLine , string strScope, string targetPlayerName)
  7315.         {
  7316.             int totalDelay = intDelay;
  7317.             int yellduration = 8;
  7318.             string duration = string.Empty;
  7319.             string yelltagwithduration = @"^\[[y|Y][e|E][l|L]{2,2},\d+\]";
  7320.             //string yelltag = @"^\[[y|Y][e|E][l|L]{2,2},";
  7321.             try
  7322.             {
  7323.                 switch (strScope)
  7324.                 {
  7325.                     case "all":
  7326.                         foreach (string line in lstMultiLineChatMSG)
  7327.                         {
  7328.  
  7329.                             if (Regex.IsMatch(line, yelltagwithduration))
  7330.                             {
  7331.                                 MatchCollection matches = Regex.Matches(line, yelltagwithduration);
  7332.                                 foreach (Match match in matches)
  7333.                                 {
  7334.                                     foreach (Capture capture in match.Captures)
  7335.                                     {
  7336.                                         if(int.TryParse(Regex.Replace(match.Value,@"\D",""), out yellduration) == false )
  7337.                                         {
  7338.                                             this.DebugInfo("Trace", "SendMultiLineChatMessage: Could not parse Duration, using default");
  7339.                                             yellduration = 8;
  7340.                                         }
  7341.                                     }
  7342.                                 }
  7343.                                 //yell this!
  7344.                                 this.CheckMessageLength(Regex.Replace(line,yelltagwithduration,"") , 255);
  7345.                                 this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", totalDelay.ToString(), "1", "1", "procon.protected.send", "admin.yell", Regex.Replace(line, yelltagwithduration, ""), yellduration.ToString(), strScope);
  7346.                                 totalDelay += delayIncreasePerLine;
  7347.                                 totalDelay += yellduration;
  7348.                             }
  7349.                             else
  7350.                             {
  7351.                                 //default say
  7352.                                 this.CheckMessageLength(line, 128);
  7353.                                 this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", totalDelay.ToString(), "1", "1", "procon.protected.send", "admin.say", line, strScope);
  7354.                                 totalDelay += delayIncreasePerLine;
  7355.                             }
  7356.                         }
  7357.                         break;
  7358.  
  7359.                     default:
  7360.                         foreach (string line in lstMultiLineChatMSG)
  7361.                         {
  7362.                             if (Regex.IsMatch(line, yelltagwithduration))
  7363.                             {
  7364.                                 MatchCollection matches = Regex.Matches(line, yelltagwithduration);
  7365.                                 foreach (Match match in matches)
  7366.                                 {
  7367.                                     foreach (Capture capture in match.Captures)
  7368.                                     {
  7369.                                         if (int.TryParse(Regex.Replace(match.Value, @"\D", ""), out yellduration) == false)
  7370.                                         {
  7371.                                             this.DebugInfo("Trace", "SendMultiLineChatMessage: Could not parse Duration, using default");
  7372.                                             yellduration = 8;
  7373.                                         }
  7374.                                     }
  7375.                                 }
  7376.                                 //yell this!
  7377.                                 this.CheckMessageLength(line, 255);
  7378.                                 this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", totalDelay.ToString(), "1", "1", "procon.protected.send", "admin.yell", Regex.Replace(line, yelltagwithduration, ""), yellduration.ToString(), "player", targetPlayerName);
  7379.                                 totalDelay += delayIncreasePerLine;
  7380.                                 totalDelay += yellduration;
  7381.                             }
  7382.                             else
  7383.                             {
  7384.                                 //default say
  7385.                                 this.CheckMessageLength(line, 128);
  7386.                                 this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", totalDelay.ToString(), "1", "1", "procon.protected.send", "admin.say", line, "player", targetPlayerName);
  7387.                                 totalDelay += delayIncreasePerLine;
  7388.                             }
  7389.                         }
  7390.                         break;
  7391.                 }
  7392.  
  7393.             }
  7394.             catch (Exception c)
  7395.             {
  7396.                 this.DebugInfo("Error", "Error in PostMultiLineChat: " + c);
  7397.             }
  7398.         }
  7399.  
  7400.         private Dictionary<string, int> GetWeaponMappingfromDB()
  7401.         {
  7402.             Dictionary<string,int> mappingDic = new Dictionary<string,int>();
  7403.             try
  7404.             {
  7405.                 string sqlSelect = "SELECT `WeaponID`,`Fullname` FROM `" + this.tbl_weapons + @"` WHERE `GameID` = @GameID";
  7406.                 using (MySqlCommand SelectCommand = new MySqlCommand(sqlSelect))
  7407.                 {
  7408.                     SelectCommand.Parameters.AddWithValue("@GameID", this.intServerGameType_ID);
  7409.                    
  7410.                     DataTable result = this.SQLquery(SelectCommand);
  7411.                     if (result != null || result.Rows.Count != 0)
  7412.                     {
  7413.                         foreach (DataRow row in result.Rows)
  7414.                         {
  7415.                             mappingDic.Add(row["Fullname"].ToString(), Convert.ToInt32(row["WeaponID"]));
  7416.                             this.DebugInfo("Trace", "WeaponMapping: ID: " + Convert.ToInt32(row["WeaponID"]).ToString() + " <--> Weapon:" + row["Fullname"].ToString());
  7417.                         }
  7418.                     }
  7419.                 }
  7420.             }
  7421.             catch (MySqlException oe)
  7422.             {
  7423.                 this.DebugInfo("Error", "Error in GetWeaponMappingfromDB: ");
  7424.                 this.DisplayMySqlErrorCollection(oe);
  7425.             }
  7426.             catch (Exception c)
  7427.             {
  7428.                 this.DebugInfo("Error", "Error in GetWeaponMappingfromDB: " + c);
  7429.             }
  7430.  
  7431.             return mappingDic;
  7432.         }
  7433.  
  7434.         private int GetGameIDfromDB(string strGame)
  7435.         {
  7436.             this.DebugInfo("Trace", "GetGameIDfromDB Game: " + strGame);
  7437.             int intGameID = 0;
  7438.             try
  7439.             {
  7440.                 string sqlSelect = "SELECT `GameID` FROM `" + this.tbl_games + @"` WHERE `Name` = @Name";
  7441.                 using (MySqlCommand SelectCommand = new MySqlCommand(sqlSelect))
  7442.                 {
  7443.                     SelectCommand.Parameters.AddWithValue("@Name", strGame);
  7444.  
  7445.                     DataTable result = this.SQLquery(SelectCommand);
  7446.                     if (result.Rows.Count != 0)
  7447.                     {
  7448.                         intGameID = Convert.ToInt32(result.Rows[0][0]);
  7449.                     }
  7450.                     else
  7451.                     {
  7452.                         this.DebugInfo("Trace", "GetGameIDfromDB Game:  no gameID found");
  7453.                         //Insert Game
  7454.                         using (MySqlConnection Con = new MySqlConnection(this.DBConnectionStringBuilder()))
  7455.                         {
  7456.                             Con.Open();
  7457.                             MySqlTransaction Transaction = null;
  7458.                             //Start of the Transaction
  7459.                             Transaction = Con.BeginTransaction();
  7460.  
  7461.                             string SQL = @"INSERT INTO `" + this.tbl_games + @"` (`Name`) VALUES (@Name)";
  7462.                             using (MySqlCommand MyCom = new MySqlCommand(SQL, Con, Transaction))
  7463.                             {
  7464.                                 MyCom.Parameters.AddWithValue("@Name", this.strServerGameType);
  7465.                                 MyCom.ExecuteNonQuery();
  7466.                                 this.DebugInfo("Trace", "GetGameIDfromDB LastInsertedId: " + MyCom.LastInsertedId.ToString());
  7467.                                 intGameID = Convert.ToInt32(MyCom.LastInsertedId);
  7468.                             }
  7469.                             Transaction.Commit();
  7470.                         }
  7471.                     }
  7472.                 }
  7473.             }
  7474.             catch (MySqlException oe)
  7475.             {
  7476.                 this.DebugInfo("Error", "Error in GetGameIDfromDB: ");
  7477.                 this.DisplayMySqlErrorCollection(oe);
  7478.             }
  7479.             catch (Exception c)
  7480.             {
  7481.                 this.DebugInfo("Error", "Error in GetGameIDfromDB: " + c);
  7482.             }
  7483.             this.DebugInfo("Trace", "GetGameIDfromDB GameID: " + intGameID);
  7484.             return intGameID;
  7485.         }
  7486.     }
  7487.  
  7488.         #endregion
  7489.  
  7490.     #region Classes
  7491.     /*==========Classes========*/
  7492.     class CLogger
  7493.     {
  7494.         private readonly string _Name;
  7495.         private string _Message = String.Empty;
  7496.         private string _Subset = String.Empty;
  7497.         private DateTime _Time;
  7498.  
  7499.         public string Name
  7500.         {
  7501.             get { return _Name; }
  7502.         }
  7503.  
  7504.         public string Message
  7505.         {
  7506.             get { return _Message; }
  7507.         }
  7508.  
  7509.         public string Subset
  7510.         {
  7511.             get { return _Subset; }
  7512.         }
  7513.  
  7514.         public DateTime Time
  7515.         {
  7516.             get { return _Time; }
  7517.         }
  7518.  
  7519.         public CLogger(DateTime time, string name, string message, string subset)
  7520.         {
  7521.             _Name = name;
  7522.             _Message = message;
  7523.             _Subset = subset;
  7524.             _Time = time;
  7525.         }
  7526.     }
  7527.  
  7528.     class CStats
  7529.     {
  7530.         private string _ClanTag;
  7531.         private string _Guid;
  7532.         private string _EAGuid;
  7533.         private string _IP;
  7534.         private string _PlayerCountryCode;
  7535.         private int _Score = 0;
  7536.         private int _HighScore = 0;
  7537.         private int _LastScore = 0;
  7538.         private int _Kills = 0;
  7539.         private int _Headshots = 0;
  7540.         private int _Deaths = 0;
  7541.         private int _Suicides = 0;
  7542.         private int _Teamkills = 0;
  7543.         private int _Playtime = 0;
  7544.         private int _Rounds = 0;
  7545.         private DateTime _Playerjoined;
  7546.         private DateTime _TimePlayerleft;
  7547.         private DateTime _TimePlayerjoined;
  7548.         private int _PlayerleftServerScore = 0;
  7549.         private bool _playerOnServer = true;
  7550.         private int _rank = 0;
  7551.         //KD Correction
  7552.         private int _beforeleftKills = 0;
  7553.         private int _beforeleftDeaths = 0;
  7554.         //Streaks
  7555.         private int _Killstreak;
  7556.         private int _Deathstreak;
  7557.         private int _Killcount;
  7558.         private int _Deathcount;
  7559.         //Wins&Loses
  7560.         private int _Wins = 0;
  7561.         private int _Losses = 0;
  7562.         //TeamID
  7563.         private int _TeamId = 0;
  7564.         //BFBCS
  7565.         private CBFBCS _BFBCS_Stats;
  7566.         private myDateTime MyDateTime = new myDateTime(0);
  7567.         public Dictionary<string, Dictionary<string, CStats.CUsedWeapon>> dicWeap = new Dictionary<string, Dictionary<string, CStats.CUsedWeapon>>();
  7568.  
  7569.         //Awards
  7570.         private CAwards _Awards;
  7571.  
  7572.         //global Rank
  7573.         private int _GlobalRank = 0;
  7574.  
  7575.         public string ClanTag
  7576.         {
  7577.             get { return _ClanTag; }
  7578.             set { _ClanTag = value; }
  7579.         }
  7580.  
  7581.         public string Guid
  7582.         {
  7583.             get { return _Guid; }
  7584.             set { _Guid = value; }
  7585.         }
  7586.  
  7587.         public string EAGuid
  7588.         {
  7589.             get { return _EAGuid; }
  7590.             set { _EAGuid = value; }
  7591.         }
  7592.  
  7593.         public string IP
  7594.         {
  7595.             get { return _IP; }
  7596.             set { _IP = value.Remove(value.IndexOf(":")); }
  7597.         }
  7598.  
  7599.         public string PlayerCountryCode
  7600.         {
  7601.             get { return _PlayerCountryCode; }
  7602.             set { _PlayerCountryCode = value; }
  7603.         }
  7604.  
  7605.         public int Score
  7606.         {
  7607.             get { return _Score; }
  7608.             set { _Score = value; }
  7609.         }
  7610.  
  7611.         public int HighScore
  7612.         {
  7613.             get { return _HighScore; }
  7614.             set { _HighScore = value; }
  7615.         }
  7616.  
  7617.         public int LastScore
  7618.         {
  7619.             get { return _LastScore; }
  7620.             set { _LastScore = value; }
  7621.         }
  7622.  
  7623.         public int Kills
  7624.         {
  7625.             get { return _Kills; }
  7626.             set { _Kills = value; }
  7627.         }
  7628.  
  7629.         public int BeforeLeftKills
  7630.         {
  7631.             get { return _beforeleftKills; }
  7632.             set { _beforeleftKills = value; }
  7633.         }
  7634.  
  7635.         public int Headshots
  7636.         {
  7637.             get { return _Headshots; }
  7638.             set { _Headshots = value; }
  7639.         }
  7640.  
  7641.         public int Deaths
  7642.         {
  7643.             get { return _Deaths; }
  7644.             set { _Deaths = value; }
  7645.         }
  7646.  
  7647.         public int BeforeLeftDeaths
  7648.         {
  7649.             get { return _beforeleftDeaths; }
  7650.             set { _beforeleftDeaths = value; }
  7651.         }
  7652.  
  7653.         public int Suicides
  7654.         {
  7655.             get { return _Suicides; }
  7656.             set { _Suicides = value; }
  7657.         }
  7658.  
  7659.         public int Teamkills
  7660.         {
  7661.             get { return _Teamkills; }
  7662.             set { _Teamkills = value; }
  7663.         }
  7664.  
  7665.         public int Playtime
  7666.         {
  7667.             get { return _Playtime; }
  7668.             set { _Playtime = value; }
  7669.         }
  7670.  
  7671.         public int Rounds
  7672.         {
  7673.             get { return _Rounds; }
  7674.             set { _Rounds = value; }
  7675.         }
  7676.  
  7677.         public DateTime Playerjoined
  7678.         {
  7679.             get { return _Playerjoined; }
  7680.             set { _Playerjoined = value; }
  7681.         }
  7682.  
  7683.         public DateTime TimePlayerleft
  7684.         {
  7685.             get { return _TimePlayerleft; }
  7686.             set { _TimePlayerleft = value; }
  7687.         }
  7688.  
  7689.         public DateTime TimePlayerjoined
  7690.         {
  7691.             get { return _TimePlayerjoined; }
  7692.             set { _TimePlayerjoined = value; }
  7693.         }
  7694.  
  7695.         public int PlayerleftServerScore
  7696.         {
  7697.             get { return _PlayerleftServerScore; }
  7698.             set { _PlayerleftServerScore = value; }
  7699.         }
  7700.  
  7701.         public bool PlayerOnServer
  7702.         {
  7703.             get { return _playerOnServer; }
  7704.             set { _playerOnServer = value; }
  7705.         }
  7706.  
  7707.         public int Rank
  7708.         {
  7709.             get { return _rank; }
  7710.             set { _rank = value; }
  7711.         }
  7712.  
  7713.         public int Killstreak
  7714.         {
  7715.             get { return _Killstreak; }
  7716.             set { _Killstreak = value; }
  7717.         }
  7718.  
  7719.         public int Deathstreak
  7720.         {
  7721.             get { return _Deathstreak; }
  7722.             set { _Deathstreak = value; }
  7723.         }
  7724.  
  7725.         public int Wins
  7726.         {
  7727.             get { return _Wins; }
  7728.             set { _Wins = value; }
  7729.         }
  7730.  
  7731.         public int Losses
  7732.         {
  7733.             get { return _Losses; }
  7734.             set { _Losses = value; }
  7735.         }
  7736.  
  7737.         public int TeamId
  7738.         {
  7739.             get { return _TeamId; }
  7740.             set { _TeamId = value; }
  7741.         }
  7742.  
  7743.         public int GlobalRank
  7744.         {
  7745.             get { return _GlobalRank; }
  7746.             set { _GlobalRank = value; }
  7747.         }
  7748.  
  7749.         //Methodes 
  7750.         public void AddScore(int intScore)
  7751.         {
  7752.             if (intScore != 0)
  7753.             {
  7754.                 this._Score = this._Score + (intScore - this._LastScore);
  7755.                 this._LastScore = intScore;
  7756.                 if (intScore > this._HighScore)
  7757.                 {
  7758.                     this._HighScore = intScore;
  7759.                 }
  7760.             }
  7761.             else
  7762.             {
  7763.                 this._LastScore = 0;
  7764.             }
  7765.         }
  7766.  
  7767.         public double KDR()
  7768.         {
  7769.             double ratio = 0;
  7770.             if (this._Deaths != 0)
  7771.             {
  7772.                 ratio = Math.Round(Convert.ToDouble(this._Kills) / Convert.ToDouble(this._Deaths), 2);
  7773.             }
  7774.             else
  7775.             {
  7776.                 ratio = this._Kills;
  7777.             }
  7778.             return ratio;
  7779.         }
  7780.  
  7781.         public Dictionary<string, Dictionary<string, CStats.CUsedWeapon>> getWeaponKills()
  7782.         {
  7783.             return this.dicWeap;
  7784.         }
  7785.  
  7786.         public void addKill(string strDmgType, string strweaponType, bool blheadshot)
  7787.         {
  7788.             this._Kills++;
  7789.             if (blheadshot)
  7790.             {
  7791.                 if (this.dicWeap.ContainsKey(strDmgType))
  7792.                 {
  7793.                     if (this.dicWeap[strDmgType].ContainsKey(strweaponType))
  7794.                     {
  7795.                         this.dicWeap[strDmgType][strweaponType].Kills++;
  7796.                         this.dicWeap[strDmgType][strweaponType].Headshots++;
  7797.                     }
  7798.                 }
  7799.                 this._Headshots++;
  7800.             }
  7801.             else
  7802.             {
  7803.                 if (this.dicWeap.ContainsKey(strDmgType))
  7804.                 {
  7805.                     if (this.dicWeap[strDmgType].ContainsKey(strweaponType))
  7806.                     {
  7807.                         this.dicWeap[strDmgType][strweaponType].Kills++;
  7808.                     }
  7809.                 }
  7810.             }
  7811.             //Killstreaks
  7812.             this._Killcount++;
  7813.             this._Deathcount = 0;
  7814.             if (this._Killcount > this._Killstreak)
  7815.             {
  7816.                 this._Killstreak = this._Killcount;
  7817.             }
  7818.             //Awardchecks
  7819.             this._Awards.CheckOnKill(_Kills, _Headshots, _Deaths, _Killcount, _Deathcount);
  7820.         }
  7821.  
  7822.         public void addDeath(string strDmgType, string strweaponType)
  7823.         {
  7824.             this._Deaths++;
  7825.             if (this.dicWeap.ContainsKey(strDmgType))
  7826.             {
  7827.                 if (this.dicWeap[strDmgType].ContainsKey(strweaponType))
  7828.                 {
  7829.                     this.dicWeap[strDmgType][strweaponType].Deaths++;
  7830.                 }
  7831.             }
  7832.             //Deathstreak
  7833.             this._Deathcount++;
  7834.             this._Killcount = 0;
  7835.             if (this._Deathcount > this._Deathstreak)
  7836.             {
  7837.                 this._Deathstreak = this._Deathcount;
  7838.             }
  7839.             //Awardchecks
  7840.             this._Awards.CheckOnDeath(_Kills, _Headshots, _Deaths, _Killcount, _Deathcount);
  7841.         }
  7842.  
  7843.         public void playerleft()
  7844.         {
  7845.             //Score
  7846.             this._PlayerleftServerScore += this._Score;
  7847.             this._Score = 0;
  7848.             //Kd Correction
  7849.             this._beforeleftKills += this._Kills;
  7850.             this._beforeleftDeaths += this._Deaths;
  7851.  
  7852.             //Time
  7853.             TimeSpan duration = MyDateTime.Now - this._Playerjoined;
  7854.             this._Playtime += Convert.ToInt32(duration.TotalSeconds);
  7855.             this._playerOnServer = false;
  7856.         }
  7857.  
  7858.         public int TotalScore
  7859.         {
  7860.             get { return (this._PlayerleftServerScore + this._Score); }
  7861.         }
  7862.  
  7863.         public int TotalPlaytime
  7864.         {
  7865.             get
  7866.             {
  7867.                 if (this._playerOnServer)
  7868.                 {
  7869.                     TimeSpan duration = MyDateTime.Now - this._Playerjoined;
  7870.                     return (this._Playtime + Convert.ToInt32(duration.TotalSeconds));
  7871.                 }
  7872.                 return this._Playtime;
  7873.             }
  7874.         }
  7875.  
  7876.         public CStats.CBFBCS BFBCS_Stats
  7877.         {
  7878.             get { return _BFBCS_Stats; }
  7879.             set { _BFBCS_Stats = value; }
  7880.         }
  7881.  
  7882.         public CStats.CAwards Awards
  7883.         {
  7884.             get { return _Awards; }
  7885.             set { _Awards = value; }
  7886.         }
  7887.  
  7888.         public class CUsedWeapon
  7889.         {
  7890.             private string _Name = "";
  7891.             private string _FieldName = "";
  7892.             private string _Slot = "";
  7893.             private string _KitRestriction = "";
  7894.             private int _Kills = 0;
  7895.             private int _Headshots = 0;
  7896.             private int _Deaths = 0;
  7897.  
  7898.             public int Kills
  7899.             {
  7900.                 get { return _Kills; }
  7901.                 set { _Kills = value; }
  7902.             }
  7903.  
  7904.             public int Headshots
  7905.             {
  7906.                 get { return _Headshots; }
  7907.                 set { _Headshots = value; }
  7908.             }
  7909.  
  7910.             public int Deaths
  7911.             {
  7912.                 get { return _Deaths; }
  7913.                 set { _Deaths = value; }
  7914.             }
  7915.  
  7916.             public string Name
  7917.             {
  7918.                 get { return _Name; }
  7919.                 set { _Name = value; }
  7920.             }
  7921.  
  7922.             public string FieldName
  7923.             {
  7924.                 get { return _FieldName; }
  7925.                 set { _FieldName = value; }
  7926.             }
  7927.  
  7928.             public string Slot
  7929.             {
  7930.                 get { return _Slot; }
  7931.                 set { _Slot = value; }
  7932.             }
  7933.  
  7934.             public string KitRestriction
  7935.             {
  7936.                 get { return _KitRestriction; }
  7937.                 set { _KitRestriction = value; }
  7938.             }
  7939.  
  7940.             public CUsedWeapon(string name, string fieldname, string slot, string kitrestriction)
  7941.             {
  7942.                 this._Name = name;
  7943.                 this._FieldName = fieldname;
  7944.                 this._Slot = slot;
  7945.                 this._KitRestriction = kitrestriction;
  7946.                 this._Kills = 0;
  7947.                 this._Headshots = 0;
  7948.                 this._Deaths = 0;
  7949.             }
  7950.         }
  7951.  
  7952.         public class CBFBCS
  7953.         {
  7954.             private int _rank;
  7955.             private int _kills;
  7956.             private int _deaths;
  7957.             private int _score;
  7958.             private double _skilllevel;
  7959.             private double _time;
  7960.             private double _elo;
  7961.             private bool _Updated;
  7962.             private bool _fetching;
  7963.             private bool _noUpdate;
  7964.  
  7965.             public int Rank
  7966.             {
  7967.                 get { return _rank; }
  7968.                 set { _rank = value; }
  7969.             }
  7970.  
  7971.             public int Kills
  7972.             {
  7973.                 get { return _kills; }
  7974.                 set { _kills = value; }
  7975.             }
  7976.  
  7977.             public int Deaths
  7978.             {
  7979.                 get { return _deaths; }
  7980.                 set { _deaths = value; }
  7981.             }
  7982.  
  7983.             public double KDR
  7984.             {
  7985.                 get
  7986.                 {
  7987.                     double ratio = 0;
  7988.                     if (this._deaths != 0)
  7989.                     {
  7990.                         ratio = Math.Round(Convert.ToDouble(this._kills) / Convert.ToDouble(this._deaths), 2);
  7991.                     }
  7992.                     else
  7993.                     {
  7994.                         ratio = this._kills;
  7995.                     }
  7996.                     return ratio;
  7997.                 }
  7998.             }
  7999.             public double SPM
  8000.             {
  8001.                 get
  8002.                 {
  8003.                     return Convert.ToDouble(this._score) / (this._time / 60);
  8004.                 }
  8005.             }
  8006.  
  8007.             public int Score
  8008.             {
  8009.                 get { return _score; }
  8010.                 set { _score = value; }
  8011.             }
  8012.  
  8013.             public double Skilllevel
  8014.             {
  8015.                 get { return _skilllevel; }
  8016.                 set { _skilllevel = value; }
  8017.             }
  8018.  
  8019.             public double Time
  8020.             {
  8021.                 get { return _time; }
  8022.                 set { _time = value; }
  8023.             }
  8024.  
  8025.             public double Elo
  8026.             {
  8027.                 get { return _elo; }
  8028.                 set { _elo = value; }
  8029.             }
  8030.  
  8031.             public bool Updated
  8032.             {
  8033.                 get { return _Updated; }
  8034.                 set { _Updated = value; }
  8035.             }
  8036.  
  8037.             public bool Fetching
  8038.             {
  8039.                 get { return _fetching; }
  8040.                 set { _fetching = value; }
  8041.             }
  8042.  
  8043.             public bool NoUpdate
  8044.             {
  8045.                 get { return _noUpdate; }
  8046.                 set { _noUpdate = value; }
  8047.             }
  8048.  
  8049.             public CBFBCS()
  8050.             {
  8051.                 this._rank = 0;
  8052.                 this._kills = 0;
  8053.                 this._deaths = 0;
  8054.                 this._score = 0;
  8055.                 this._skilllevel = 0;
  8056.                 this._time = 0;
  8057.                 this._elo = 0;
  8058.                 this._Updated = false;
  8059.                 this._fetching = false;
  8060.                 this._noUpdate = false;
  8061.             }
  8062.         }
  8063.  
  8064.         public class CAwards
  8065.         {
  8066.             //Awards
  8067.             private Dictionary<string, int> _dicAwards = new Dictionary<string, int>();
  8068.  
  8069.             //Constructor
  8070.             public CAwards()
  8071.             {
  8072.                 this._dicAwards = new Dictionary<string, int>();
  8073.             }
  8074.  
  8075.             //Get and Set
  8076.             public Dictionary<string, int> DicAwards
  8077.             {
  8078.                 get { return _dicAwards; }
  8079.                 set { _dicAwards = value; }
  8080.             }
  8081.  
  8082.             //Methodes
  8083.             public void dicAdd(string strAward, int count)
  8084.             {
  8085.                 if (this._dicAwards.ContainsKey(strAward))
  8086.                 {
  8087.                     this._dicAwards[strAward] = this._dicAwards[strAward] + count;
  8088.                 }
  8089.                 else
  8090.                 {
  8091.                     this._dicAwards.Add(strAward, count);
  8092.                 }
  8093.             }
  8094.  
  8095.             public void CheckOnKill(int kills, int hs, int deaths, int ks, int ds)
  8096.             {
  8097.                 //Purple Heart
  8098.                 if (kills >= 5 && deaths >= 20 && ((Double)kills / (Double)deaths) == 0.25)
  8099.                 {
  8100.                     this.dicAdd("Purple_Heart", 1);
  8101.                 }
  8102.                 //Killstreaks
  8103.                 if (ks == 5)
  8104.                 {
  8105.                     //5 Kills in a row
  8106.                     this.dicAdd("Killstreak_5", 1);
  8107.                 }
  8108.                 else if (ks == 10)
  8109.                 {
  8110.                     //10 kills in a row
  8111.                     this.dicAdd("Killstreak_10", 1);
  8112.                 }
  8113.                 else if (ks == 15)
  8114.                 {
  8115.                     //15 kills in a row
  8116.                     this.dicAdd("Killstreak_15", 1);
  8117.                 }
  8118.                 else if (ks == 20)
  8119.                 {
  8120.                     //20 kills in a row
  8121.                     this.dicAdd("Killstreak_20", 1);
  8122.                 }
  8123.             }
  8124.  
  8125.             public void CheckOnDeath(int kills, int hs, int deaths, int ks, int ds)
  8126.             {
  8127.                 //Purple Heart
  8128.                 if (kills >= 5 && deaths >= 20 && ((Double)kills / (Double)deaths) == 0.25)
  8129.                 {
  8130.                     this.dicAdd("Purple_Heart", 1);
  8131.                 }
  8132.             }
  8133.         }
  8134.  
  8135.         public class myDateTime
  8136.         {
  8137.             private double _offset = 0;
  8138.  
  8139.             public DateTime Now
  8140.             {
  8141.                 get
  8142.                 {
  8143.                     DateTime dateValue = DateTime.Now;
  8144.                     return dateValue.AddHours(_offset);
  8145.                 }
  8146.             }
  8147.             public myDateTime(double offset)
  8148.             {
  8149.                 this._offset = offset;
  8150.             }
  8151.         }
  8152.  
  8153.         public CStats(string guid, int score, int kills, int headshots, int deaths, int suicides, int teamkills, int playtime, double timeoffset, Dictionary<string, Dictionary<string, CStats.CUsedWeapon>> _weaponDic)
  8154.         {
  8155.             this.MyDateTime = new myDateTime(timeoffset);
  8156.             this._ClanTag = String.Empty;
  8157.             this._Guid = guid;
  8158.             this._EAGuid = String.Empty;
  8159.             this._IP = String.Empty;
  8160.             this._Score = score;
  8161.             this._LastScore = 0;
  8162.             this._HighScore = score;
  8163.             this._Kills = kills;
  8164.             this._Headshots = headshots;
  8165.             this._Deaths = deaths;
  8166.             this._Suicides = suicides;
  8167.             this._Teamkills = teamkills;
  8168.             this._Playtime = playtime;
  8169.             this._Rounds = 0;
  8170.             this._PlayerleftServerScore = 0;
  8171.             this._PlayerCountryCode = String.Empty;
  8172.             this._Playerjoined = MyDateTime.Now;
  8173.             this._TimePlayerjoined = this._Playerjoined;
  8174.             this._TimePlayerleft = DateTime.MinValue;
  8175.             this._rank = 0;
  8176.             this._Killcount = 0;
  8177.             this._Killstreak = 0;
  8178.             this._Deathcount = 0;
  8179.             this._Deathstreak = 0;
  8180.             this._Wins = 0;
  8181.             this._Losses = 0;
  8182.             this.BFBCS_Stats = new CStats.CBFBCS();    
  8183.             this._Awards = new CAwards();
  8184.             //this.dicWeap = new Dictionary<string,Dictionary<string,CUsedWeapon>>(_weaponDic);
  8185.             foreach (KeyValuePair<string, Dictionary<string, CStats.CUsedWeapon>> pair in _weaponDic)
  8186.             {
  8187.                 this.dicWeap.Add(pair.Key, new Dictionary<string, CStats.CUsedWeapon>());
  8188.                 foreach (KeyValuePair<string, CStats.CUsedWeapon> subpair in pair.Value)
  8189.                 {
  8190.                     this.dicWeap[pair.Key].Add(subpair.Key, new CStats.CUsedWeapon(subpair.Value.Name, subpair.Value.FieldName,subpair.Value.Slot,subpair.Value.KitRestriction));
  8191.                 }
  8192.             }
  8193.         }
  8194.     }
  8195.  
  8196.     class C_ID_Cache
  8197.     {
  8198.         private int _Id;
  8199.         private int _StatsID;
  8200.         private bool _PlayeronServer;
  8201.  
  8202.         public int Id
  8203.         {
  8204.             get { return _Id; }
  8205.             set { _Id = value; }
  8206.         }
  8207.  
  8208.         public int StatsID
  8209.         {
  8210.             get { return _StatsID; }
  8211.             set { _StatsID = value; }
  8212.         }
  8213.  
  8214.         public bool PlayeronServer
  8215.         {
  8216.             get { return _PlayeronServer; }
  8217.             set { _PlayeronServer = value; }
  8218.         }
  8219.         //Constructor
  8220.         public C_ID_Cache(int statsid, int id, bool playeronServer)
  8221.         {
  8222.             this._Id = id;
  8223.             this._StatsID = statsid;
  8224.             this._PlayeronServer = playeronServer;
  8225.         }
  8226.     }
  8227.  
  8228.     class CKillerVictim
  8229.     {
  8230.         string _Killer = String.Empty;
  8231.         string _Victim = String.Empty;
  8232.  
  8233.         public string Killer
  8234.         {
  8235.             get { return _Killer; }
  8236.             set { _Killer = value; }
  8237.         }
  8238.  
  8239.         public string Victim
  8240.         {
  8241.             get { return _Victim; }
  8242.             set { _Victim = value; }
  8243.         }
  8244.  
  8245.         public CKillerVictim(string killer, string victim)
  8246.         {
  8247.             this._Killer = killer;
  8248.             this._Victim = victim;
  8249.         }
  8250.     }
  8251.  
  8252.     class CMapstats
  8253.     {
  8254.         private DateTime _timeMaploaded;
  8255.         private DateTime _timeMapStarted;
  8256.         private DateTime _timeRoundEnd;
  8257.         private string _strMapname = String.Empty;
  8258.         private string _strGamemode = String.Empty;
  8259.         private int _intRound;
  8260.         private int _intNumberOfRounds;
  8261.         private List<int> _lstPlayers;
  8262.         private int _intMinPlayers;
  8263.         private int _intMaxPlayers;
  8264.         private int _intServerplayermax;
  8265.         private double _doubleAvgPlayers;
  8266.         private int _intplayerleftServer;
  8267.         private int _intplayerjoinedServer;
  8268.         private myDateTime MyDateTime = new myDateTime(0);
  8269.  
  8270.         public DateTime TimeMaploaded
  8271.         {
  8272.             get { return _timeMaploaded; }
  8273.             set { _timeMaploaded = value; }
  8274.         }
  8275.  
  8276.         public DateTime TimeMapStarted
  8277.         {
  8278.             get { return _timeMapStarted; }
  8279.             set { _timeMapStarted = value; }
  8280.         }
  8281.  
  8282.         public DateTime TimeRoundEnd
  8283.         {
  8284.             get { return _timeRoundEnd; }
  8285.             set { _timeRoundEnd = value; }
  8286.         }
  8287.  
  8288.         public string StrMapname
  8289.         {
  8290.             get { return _strMapname; }
  8291.             set { _strMapname = value; }
  8292.         }
  8293.  
  8294.         public string StrGamemode
  8295.         {
  8296.             get { return _strGamemode; }
  8297.             set { _strGamemode = value; }
  8298.         }
  8299.  
  8300.         public int IntRound
  8301.         {
  8302.             get { return _intRound; }
  8303.             set { _intRound = value; }
  8304.         }
  8305.  
  8306.         public int IntNumberOfRounds
  8307.         {
  8308.             get { return _intNumberOfRounds; }
  8309.             set { _intNumberOfRounds = value; }
  8310.         }
  8311.  
  8312.         public List<int> LstPlayers
  8313.         {
  8314.             get { return _lstPlayers; }
  8315.             set { _lstPlayers = value; }
  8316.         }
  8317.  
  8318.         public int IntMinPlayers
  8319.         {
  8320.             get { return _intMinPlayers; }
  8321.             set { _intMinPlayers = value; }
  8322.         }
  8323.  
  8324.         public int IntMaxPlayers
  8325.         {
  8326.             get { return _intMaxPlayers; }
  8327.             set { _intMaxPlayers = value; }
  8328.         }
  8329.  
  8330.         public int IntServerplayermax
  8331.         {
  8332.             get { return _intServerplayermax; }
  8333.             set { _intServerplayermax = value; }
  8334.         }
  8335.  
  8336.         public double DoubleAvgPlayers
  8337.         {
  8338.             get { return _doubleAvgPlayers; }
  8339.             set { _doubleAvgPlayers = value; }
  8340.         }
  8341.  
  8342.         public int IntplayerleftServer
  8343.         {
  8344.             get { return _intplayerleftServer; }
  8345.             set { _intplayerleftServer = value; }
  8346.         }
  8347.  
  8348.         public int IntplayerjoinedServer
  8349.         {
  8350.             get { return _intplayerjoinedServer; }
  8351.             set { _intplayerjoinedServer = value; }
  8352.         }
  8353.  
  8354.         public void MapStarted()
  8355.         {
  8356.             this._timeMapStarted = MyDateTime.Now;
  8357.         }
  8358.  
  8359.         public void MapEnd()
  8360.         {
  8361.             this._timeRoundEnd = MyDateTime.Now;
  8362.         }
  8363.  
  8364.         public void ListADD(int entry)
  8365.         {
  8366.             this._lstPlayers.Add(entry);
  8367.         }
  8368.  
  8369.         public void calcMaxMinAvgPlayers()
  8370.         {
  8371.             this._intMaxPlayers = 0;
  8372.             this._intMinPlayers = _intServerplayermax;
  8373.             this._doubleAvgPlayers = 0;
  8374.             int entries = 0;
  8375.             foreach (int playercount in this._lstPlayers)
  8376.             {
  8377.                 if (playercount >= this._intMaxPlayers)
  8378.                     this._intMaxPlayers = playercount;
  8379.  
  8380.                 if (playercount <= this._intMinPlayers)
  8381.                     this._intMinPlayers = playercount;
  8382.  
  8383.                 this._doubleAvgPlayers = this._doubleAvgPlayers + playercount;
  8384.                 entries = entries + 1;
  8385.  
  8386.             }
  8387.             if (entries != 0)
  8388.             {
  8389.                 this._doubleAvgPlayers = this._doubleAvgPlayers / (Convert.ToDouble(entries));
  8390.                 this._doubleAvgPlayers = Math.Round(this._doubleAvgPlayers, 1);
  8391.             }
  8392.             else
  8393.             {
  8394.                 this._doubleAvgPlayers = 0;
  8395.                 this._intMaxPlayers = 0;
  8396.                 this._intMinPlayers = 0;
  8397.             }
  8398.         }
  8399.  
  8400.         public class myDateTime
  8401.         {
  8402.             private double _offset = 0;
  8403.  
  8404.             public DateTime Now
  8405.             {
  8406.                 get
  8407.                 {
  8408.                     DateTime dateValue = DateTime.Now;
  8409.                     return dateValue.AddHours(_offset);
  8410.                 }
  8411.             }
  8412.             public myDateTime(double offset)
  8413.             {
  8414.                 this._offset = offset;
  8415.             }
  8416.         }
  8417.  
  8418.         public CMapstats(DateTime timeMaploaded, string strMapname, int intRound, int intNumberOfRounds, double timeoffset)
  8419.         {
  8420.             this._timeMaploaded = timeMaploaded;
  8421.             this._strMapname = strMapname;
  8422.             this._intRound = intRound;
  8423.             this._intNumberOfRounds = intNumberOfRounds;
  8424.             this._intMaxPlayers = 32;
  8425.             this._intServerplayermax = 32;
  8426.             this._intMinPlayers = 0;
  8427.             this._intplayerjoinedServer = 0;
  8428.             this._intplayerleftServer = 0;
  8429.             this._lstPlayers = new List<int>();
  8430.             this._timeMapStarted = DateTime.MinValue;
  8431.             this._timeRoundEnd = DateTime.MinValue;
  8432.             this._strGamemode = String.Empty;
  8433.             this.MyDateTime = new myDateTime(timeoffset);
  8434.         }
  8435.     }
  8436.  
  8437.     class CSpamprotection
  8438.     {
  8439.         private Dictionary<string, int> dicplayer;
  8440.         private int _allowedRequests;
  8441.  
  8442.         public CSpamprotection(int allowedRequests)
  8443.         {
  8444.             this._allowedRequests = allowedRequests;
  8445.             this.dicplayer = new Dictionary<string, int>();
  8446.         }
  8447.  
  8448.         public bool isAllowed(string strSpeaker)
  8449.         {
  8450.             bool result = false;
  8451.             if (this.dicplayer.ContainsKey(strSpeaker) == true)
  8452.             {
  8453.                 int i = this.dicplayer[strSpeaker];
  8454.                 if (0 >= i)
  8455.                 {
  8456.                     //Player is blocked
  8457.                     result = false;
  8458.                     this.dicplayer[strSpeaker]--;
  8459.                 }
  8460.                 else
  8461.                 {
  8462.                     //Player is not blocked
  8463.                     result = true;
  8464.                     this.dicplayer[strSpeaker]--;
  8465.                 }
  8466.             }
  8467.             else
  8468.             {
  8469.                 this.dicplayer.Add(strSpeaker, this._allowedRequests);
  8470.                 result = true;
  8471.                 this.dicplayer[strSpeaker]--;
  8472.             }
  8473.             return result;
  8474.         }
  8475.  
  8476.         public void Reset()
  8477.         {
  8478.             this.dicplayer.Clear();
  8479.         }
  8480.     }
  8481.  
  8482.     class myDateTime_W
  8483.     {
  8484.         private double _offset = 0;
  8485.  
  8486.         public DateTime Now
  8487.         {
  8488.             get
  8489.             {
  8490.                 DateTime dateValue = DateTime.Now;
  8491.                 return dateValue.AddHours(_offset);
  8492.             }
  8493.         }
  8494.         public myDateTime_W(double offset)
  8495.         {
  8496.             this._offset = offset;
  8497.         }
  8498.     }
  8499.  
  8500.     class CStatsIngameCommands
  8501.     {
  8502.         //Class variables
  8503.         private string _functioncall;
  8504.         private string _commands;
  8505.         private string _description;
  8506.         private bool _boolEnabled;
  8507.  
  8508.  
  8509.         public CStatsIngameCommands(string commands, string functioncall, bool boolEnabled, string description)
  8510.         {
  8511.             this._commands = commands;
  8512.             this._functioncall = functioncall;
  8513.             this._boolEnabled = boolEnabled;
  8514.             this._description = description;
  8515.  
  8516.         }
  8517.  
  8518.         public string commands
  8519.         {
  8520.             get { return this._commands; }
  8521.             set { this._commands = value; }
  8522.         }
  8523.  
  8524.         public string functioncall
  8525.         {
  8526.             get { return this._functioncall; }
  8527.             set { this._functioncall = value; }
  8528.         }
  8529.  
  8530.         public string description
  8531.         {
  8532.             get { return this._description; }
  8533.             set { this._description = value; }
  8534.         }
  8535.  
  8536.         public bool boolEnabled
  8537.         {
  8538.             get { return this._boolEnabled; }
  8539.             set { this._boolEnabled = value; }
  8540.         }
  8541.     }
  8542.  
  8543.    #endregion
  8544. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement