1. /* Copyright 2010 [GWC]XpKillerhx
  2. This plugin file is part of BFBC2 PRoCon.
  3. BFBC2 PRoCon is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. BFBC2 PRoCon is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with BFBC2 PRoCon. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. using System;
  15. using System.IO;
  16. using System.Text;
  17. using System.Reflection;
  18. using System.Collections;
  19. using System.Collections.Generic;
  20. using System.Collections.ObjectModel;
  21. using System.Data;
  22. using System.Data.Odbc;
  23. using System.Configuration;
  24. using System.ComponentModel;
  25. using System.Text.RegularExpressions;
  26. using System.Threading;
  27. using System.Net;
  28. //Procon includes
  29. using PRoCon.Core;
  30. using PRoCon.Core.Plugin;
  31. using PRoCon.Core.Plugin.Commands;
  32. using PRoCon.Core.Players;
  33. using PRoCon.Core.Players.Items;
  34. namespace PRoConEvents {
  35. public class CChatGUIDStatsLogger : PRoConPluginAPI, IPRoConPluginInterface {
  36. #region Variables and Constructor
  37. //Proconvariables
  38. private string m_strHostName;
  39. private string m_strPort;
  40. private string m_strPRoConVersion;
  41. //Dateoffset
  42. private myDateTime_W MyDateTime;
  43. private double m_dTimeOffset;
  44. //Logging
  45. private Dictionary<string, CPunkbusterInfo> m_dicPbInfo = new Dictionary<string, CPunkbusterInfo>();
  46. //Chatlog
  47. private static List<CLogger> ChatLog = new List<CLogger>();
  48. //Statslog
  49. private Dictionary<string, CStats> StatsTracker = new Dictionary<string, CStats>();
  50. //Dogtags
  51. private Dictionary<CKillerVictim, int> m_dicKnifeKills = new Dictionary<CKillerVictim, int>();
  52. //Session
  53. private Dictionary<string, CStats> m_dicSession = new Dictionary<string, CStats>();
  54. private CMapstats Mapstats;
  55. private CMapstats Nextmapinfo;
  56. //GameMod
  57. private string m_strGameMod;
  58. //Spamprotection
  59. private int numberOfAllowedRequests;
  60. private CSpamprotection Spamprotection;
  61. //Keywords
  62. private List<string> m_lstTableconfig = new List<string>();
  63. private List<string> m_lstTableschema = new List<string>();
  64. private List<string> m_lstTableconfig_bc2 = new List<string>();
  65. private List<string> m_lstTableschema_bc2 = new List<string>();
  66. private List<string> m_lstTableconfig_bfv = new List<string>();
  67. private List<string> m_lstTableschema_bfv = new List<string>();
  68. private Dictionary<string, List<string>> m_dicKeywords = new Dictionary<string, List<string>>();
  69. //Tablenames
  70. private string tbl_playerdata;
  71. private string tbl_playerstats;
  72. private string tbl_weaponstats;
  73. private string tbl_dogtags;
  74. private string tbl_mapstats;
  75. private string tbl_chatlog;
  76. private string tbl_bfbcs;
  77. // Timelogging
  78. private bool bool_roundStarted;
  79. private DateTime Time_RankingStarted;
  80. //Other
  81. private Dictionary<string, CPlayerInfo> m_dicPlayers = new Dictionary<string, CPlayerInfo>(); //Players
  82. //ID Cache
  83. private Dictionary<string,C_ID_Cache> m_ID_cache = new Dictionary<string, C_ID_Cache>();
  84. //Various Variables
  85. private int m_strUpdateInterval;
  86. private bool isStreaming;
  87. private string serverName;
  88. private bool m_isPluginEnabled;
  89. private bool boolTableEXISTS;
  90. private int m_iDisplayTime;
  91. private bool boolKeywordDicReady;
  92. private string tableSuffix;
  93. private bool ODBC_Connection_is_activ;
  94. //BFBCS
  95. private double BFBCS_UpdateInterval;
  96. private int BFBCS_Min_Request;
  97. //Database Connection Variables
  98. private string m_strHost;
  99. private string m_strDBPort;
  100. private string m_strDatabase;
  101. private string m_strUserName;
  102. private string m_strPassword;
  103. //Stats Message Variables
  104. private List<string> m_lstPlayerStatsMessage;
  105. private List<string> m_lstWeaponstatsMsg;
  106. private string m_strPlayerWelcomeMsg;
  107. private string m_strNewPlayerWelcomeMsg;
  108. private int int_welcomeStatsDelay;
  109. //Session
  110. private List<string> m_lstSessionMessage;
  111. //Cheaterprotection
  112. private double m_dMaxAllowedKDR;
  113. private double m_dMaxScorePerMinute;
  114. private double m_dminimumPlaytime; // hours
  115. private string m_strRemoveMethode;
  116. private string m_strReasonMsg;
  117. //Bools for switch on and off funktions
  118. private enumBoolYesNo m_enNoServerMsg; //Logging of Server Messages
  119. private enumBoolYesNo m_enLogSTATS; //Statslogging
  120. private enumBoolYesNo m_enWelcomeStats; //WelcomeStats
  121. private enumBoolYesNo m_enYellWelcomeMSG; // Yell Welcome Message
  122. private enumBoolYesNo m_enTop10ingame; //Top10 ingame
  123. private enumBoolYesNo m_enDebugMode; //Debug Mode
  124. private enumBoolYesNo m_enRankingByScore; //Ranking by Score
  125. private enumBoolYesNo m_enInstantChatlogging; //Realtime Chatlogging
  126. private enumBoolYesNo m_enChatloggingON; // Chatlogging On
  127. private enumBoolYesNo m_enSendStatsToAll; //All Player see the Stats if someone enter @stats @rank
  128. private enumBoolYesNo m_mapstatsON; //Mapstats
  129. private enumBoolYesNo m_sessionON; //Sessionstats
  130. private enumBoolYesNo m_UpdateEA_GUID; //Update EA_GUID
  131. private enumBoolYesNo m_UpdatePB_GUID; //Upate PB_GUID NOT recommended
  132. private enumBoolYesNo m_weaponstatsON; //Turn Weaponstats On and Off
  133. private enumBoolYesNo m_getStatsfromBFBCS; //Turn Statsfetching from BFBCS On and Off
  134. private enumBoolYesNo m_cheaterProtection; // Turn Statschecks On or Off
  135. //More Database Variables
  136. //Commands
  137. private System.Data.Odbc.OdbcCommand OdbcComChat;
  138. private System.Data.Odbc.OdbcCommand OdbcCom;
  139. private System.Data.Odbc.OdbcCommand OdbcComm;
  140. //Transactions
  141. private System.Data.Odbc.OdbcTransaction OdbcTrans;
  142. //Connections
  143. private System.Data.Odbc.OdbcConnection OdbcCon; //instant Chatlog and Select Querys 1
  144. private System.Data.Odbc.OdbcConnection OdbcConn; //StartStreaming and InstantKillLogging 2
  145. //Reader
  146. private System.Data.Odbc.OdbcDataReader OdbcDR;
  147. public CChatGUIDStatsLogger()
  148. {
  149. //Timeoffset
  150. this.m_dTimeOffset = 0;
  151. this.MyDateTime = new myDateTime_W(this.m_dTimeOffset);
  152. this.m_strUpdateInterval = 30;
  153. this.isStreaming = true;
  154. this.serverName = "";
  155. this.m_iDisplayTime = 3000;
  156. this.m_ID_cache = new Dictionary<string, C_ID_Cache>();
  157. this.m_dicKeywords = new Dictionary<string, List<string>>();
  158. this.boolKeywordDicReady = false;
  159. this.tableSuffix = "";
  160. this.Mapstats = new CMapstats(MyDateTime.Now,"START",0,0,this.m_dTimeOffset);
  161. this.ODBC_Connection_is_activ = false;
  162. this.numberOfAllowedRequests = 10;
  163. //BFBCS
  164. this.BFBCS_UpdateInterval = 72; // hours
  165. this.BFBCS_Min_Request = 2; //min Packrate
  166. //Cheaterprotection
  167. this.m_dMaxAllowedKDR = 5;
  168. this.m_dMaxScorePerMinute = 500;
  169. this.m_dminimumPlaytime = 10;
  170. this.m_strRemoveMethode = "Warn";
  171. this.m_strReasonMsg = "%SoldierName% has been kicked for violating KDR or SPM Limits!";
  172. //Databasehost
  173. this.m_strHost = "";
  174. this.m_strDBPort ="";
  175. this.m_strDatabase = "";
  176. this.m_strUserName = "";
  177. this.m_strPassword = "";
  178. //Various Bools
  179. this.bool_roundStarted = false;
  180. this.m_isPluginEnabled = false;
  181. this.boolTableEXISTS = false;
  182. //Functionswitches
  183. this.m_enLogSTATS = enumBoolYesNo.No;
  184. this.m_enWelcomeStats = enumBoolYesNo.No;
  185. this.m_enYellWelcomeMSG = enumBoolYesNo.No;
  186. this.m_enTop10ingame = enumBoolYesNo.No;
  187. this.m_enDebugMode = enumBoolYesNo.No;
  188. this.m_enRankingByScore = enumBoolYesNo.No;
  189. this.m_enNoServerMsg = enumBoolYesNo.No;
  190. this.m_enInstantChatlogging = enumBoolYesNo.No;
  191. this.m_enChatloggingON = enumBoolYesNo.No;
  192. this.m_enSendStatsToAll = enumBoolYesNo.No;
  193. this.m_mapstatsON = enumBoolYesNo.No;
  194. this.m_sessionON = enumBoolYesNo.No;
  195. this.m_UpdateEA_GUID = enumBoolYesNo.No;
  196. this.m_UpdatePB_GUID = enumBoolYesNo.No;
  197. this.m_weaponstatsON = enumBoolYesNo.Yes;
  198. this.m_getStatsfromBFBCS = enumBoolYesNo.No;
  199. this.m_cheaterProtection = enumBoolYesNo.No;
  200. //Welcomestats
  201. this.m_strPlayerWelcomeMsg = "Nice to see you on our Server again, %playerName%";
  202. this.m_strNewPlayerWelcomeMsg ="Welcome to the %serverName% Server, %playerName%";
  203. this.int_welcomeStatsDelay = 60;
  204. //Playerstats
  205. this.m_lstPlayerStatsMessage = new List<string>();
  206. this.m_lstPlayerStatsMessage.Add("Serverstats for %playerName%:");
  207. this.m_lstPlayerStatsMessage.Add("Score: %playerScore% %playerKills% Kills %playerHeadshots% HS %playerDeaths% Deaths K/D: %playerKDR%");
  208. this.m_lstPlayerStatsMessage.Add("Your Serverrank is: %playerRank% of %allRanks%");
  209. //Weaponstats
  210. this.m_lstWeaponstatsMsg = new List<string>();
  211. this.m_lstWeaponstatsMsg.Add("%playerName%'s Stats for %Weapon%:");
  212. this.m_lstWeaponstatsMsg.Add("%playerKills% Kills %playerHeadshots% Headshots Headshotrate: %playerKHR%% %playerDeaths% died by this Weapon");
  213. this.m_lstWeaponstatsMsg.Add("Your Weaponrank is: %playerRank% of %allRanks%");
  214. //Session
  215. this.m_lstSessionMessage = new List<string>();
  216. this.m_lstSessionMessage.Add("%playerName%'s Session Data Session started %SessionStarted%");
  217. this.m_lstSessionMessage.Add("Score: %playerScore% %playerKills% Kills %playerHeadshots% HS %playerDeaths% Deaths K/D: %playerKDR%");
  218. this.m_lstSessionMessage.Add("Your Rank: %playerRank% (%RankDif%) Sessionlength: %SessionDuration% Minutes");
  219. //GameMod
  220. this.m_strGameMod = "BC2";
  221. //Tableconfig BFBC2
  222. this.m_lstTableconfig_bc2.Add("//YOU WILL NEED TO START AND STOP THE PLUGIN SO THAT CHANGES IN THIS SSETTINGS WILL TAKE EFFECT");
  223. this.m_lstTableconfig_bc2.Add("//USE SLASHES FOR COMMENTS ONLY OTHERWISE STRANGE ERROR WILL APPEAR");
  224. this.m_lstTableconfig_bc2.Add("//DONT CHANGE THE FIRST WORD ADD WORDS TO THE BRACKETS ONLY, IF THERE ARE NO BRACKETS U CAN ADD THEM");
  225. this.m_lstTableconfig_bc2.Add("//USE UPPERCASE ONLY!!!");
  226. this.m_lstTableconfig_bc2.Add("//ASSAULT");
  227. this.m_lstTableconfig_bc2.Add("AEK971{AEK-971}");
  228. this.m_lstTableconfig_bc2.Add("XM8{XM8P,XM8-P}");
  229. this.m_lstTableconfig_bc2.Add("F2000{F-2000}");
  230. this.m_lstTableconfig_bc2.Add("AUG");
  231. this.m_lstTableconfig_bc2.Add("AN94{AN-94}");
  232. this.m_lstTableconfig_bc2.Add("M416{M-416}");
  233. this.m_lstTableconfig_bc2.Add("M16{M-16,M16A2}");
  234. this.m_lstTableconfig_bc2.Add("M16K{M-16K,M16SA}");
  235. this.m_lstTableconfig_bc2.Add("40MMGL{NOOBTUBE,GL,40MM,GRENADELAUNCHER}");
  236. this.m_lstTableconfig_bc2.Add("40MMSG{40MMSHOTGUN}");
  237. this.m_lstTableconfig_bc2.Add("40MMSMK{SMOKELAUNCHER,SMOKE}");
  238. this.m_lstTableconfig_bc2.Add("//ENGINEER");
  239. this.m_lstTableconfig_bc2.Add("9A91{9A-91}");
  240. this.m_lstTableconfig_bc2.Add("SCAR{SCAR-L,SCARL}");
  241. this.m_lstTableconfig_bc2.Add("XM8C{COMPACT,XM8-C,XM8COMPACT}");
  242. this.m_lstTableconfig_bc2.Add("AKS74U{AKS-74U,AKS74,AKS-74,AKS}");
  243. this.m_lstTableconfig_bc2.Add("UZI");
  244. this.m_lstTableconfig_bc2.Add("PP2000{PP-2000}");
  245. this.m_lstTableconfig_bc2.Add("UMP{UMP-45,UMP45}");
  246. this.m_lstTableconfig_bc2.Add("UMPK{UMP-45K,UMP45SA}");
  247. this.m_lstTableconfig_bc2.Add("//Repairtool");
  248. this.m_lstTableconfig_bc2.Add("PWR-700{REPAIRTOOL,REPAIR,REPAIR-TOOL,PWR}");
  249. this.m_lstTableconfig_bc2.Add("//AT-Rockets");
  250. this.m_lstTableconfig_bc2.Add("RPG7{RPG-7,RPG}");
  251. this.m_lstTableconfig_bc2.Add("M2CG{HOTCARL,GUSTAV,CG,CARL,CARLGUSTAV,M2}");
  252. this.m_lstTableconfig_bc2.Add("M136{AT4,M136AT4}");
  253. this.m_lstTableconfig_bc2.Add("//AT-Mine");
  254. this.m_lstTableconfig_bc2.Add("ATM-00{ATMINE,AT-MINE,ANTITANKMINE}");
  255. this.m_lstTableconfig_bc2.Add("//MEDIC");
  256. this.m_lstTableconfig_bc2.Add("PKM");
  257. this.m_lstTableconfig_bc2.Add("M249{SAW,M249SAW}");
  258. this.m_lstTableconfig_bc2.Add("QJU88{T88LMG}");
  259. this.m_lstTableconfig_bc2.Add("M60");
  260. this.m_lstTableconfig_bc2.Add("XM8LMG");
  261. this.m_lstTableconfig_bc2.Add("MG36");
  262. this.m_lstTableconfig_bc2.Add("MG3");
  263. this.m_lstTableconfig_bc2.Add("MG3K{MG3SA}");
  264. this.m_lstTableconfig_bc2.Add("DEFIB{DEFI}");
  265. this.m_lstTableconfig_bc2.Add("//SNIPER");
  266. this.m_lstTableconfig_bc2.Add("M24{M-24}");
  267. this.m_lstTableconfig_bc2.Add("QBU88{T88SNIPER}");
  268. this.m_lstTableconfig_bc2.Add("SV98{SV-98}");
  269. this.m_lstTableconfig_bc2.Add("SVU");
  270. this.m_lstTableconfig_bc2.Add("GOL{MAGNUMSNIPER}");
  271. this.m_lstTableconfig_bc2.Add("VSS");
  272. this.m_lstTableconfig_bc2.Add("M95");
  273. this.m_lstTableconfig_bc2.Add("M95K{M95SA,M95K}");
  274. this.m_lstTableconfig_bc2.Add("//Mortar");
  275. this.m_lstTableconfig_bc2.Add("MRTR-5{MORTAR}");
  276. this.m_lstTableconfig_bc2.Add("//PISTOLS");
  277. this.m_lstTableconfig_bc2.Add("M9");
  278. this.m_lstTableconfig_bc2.Add("M1911{COLT,M-1911}");
  279. this.m_lstTableconfig_bc2.Add("MP443{MP-443}");
  280. this.m_lstTableconfig_bc2.Add("MP412{MP-412,REX}");
  281. this.m_lstTableconfig_bc2.Add("M9-3{M93R}");
  282. this.m_lstTableconfig_bc2.Add("//ALLKITS");
  283. this.m_lstTableconfig_bc2.Add("//SHOTGUN");
  284. this.m_lstTableconfig_bc2.Add("870MCS{COMBATSHOTGUN}");
  285. this.m_lstTableconfig_bc2.Add("NS2000{NEOSTEAD,NS-2000}");
  286. this.m_lstTableconfig_bc2.Add("SPAS12{SPAS,SPAS-12}");
  287. this.m_lstTableconfig_bc2.Add("S20K{SAIGA}");
  288. this.m_lstTableconfig_bc2.Add("USAS12{USAS12,USAS-12,USAS}");
  289. this.m_lstTableconfig_bc2.Add("//SMG");
  290. this.m_lstTableconfig_bc2.Add("M1A1THOMPSON{THOMPSON,M1A1}");
  291. this.m_lstTableconfig_bc2.Add("//RIFLE");
  292. this.m_lstTableconfig_bc2.Add("MK14EBR{M14,M14EBR}");
  293. this.m_lstTableconfig_bc2.Add("G3");
  294. this.m_lstTableconfig_bc2.Add("GARAND{M1}");
  295. this.m_lstTableconfig_bc2.Add("//EXPLOSIVES");
  296. this.m_lstTableconfig_bc2.Add("DTN-4{C4,C-4}");
  297. this.m_lstTableconfig_bc2.Add("HG-2{GRANATE, HANDGRANATE,GRENADE,HANDGRENADE,HANDGND}");
  298. this.m_lstTableconfig_bc2.Add("//KNIFE");
  299. this.m_lstTableconfig_bc2.Add("KNV-1{KNIFE,MESSER,COMBATKNIFE,KAMPFMESSER}");
  300. this.m_lstTableconfig_bc2.Add("//VEHCLES");
  301. this.m_lstTableconfig_bc2.Add("ROADKILL");
  302. this.m_lstTableconfig_bc2.Add("ZU23{ANTIAIR}");
  303. this.m_lstTableconfig_bc2.Add("KORN");
  304. this.m_lstTableconfig_bc2.Add("TOW2{TOW}");
  305. this.m_lstTableconfig_bc2.Add("X312");
  306. this.m_lstTableconfig_bc2.Add("KORD");
  307. this.m_lstTableconfig_bc2.Add("VADS{MINIGUN,AAMINIGUN,AA-MINIGUN,VULCAN}");
  308. this.m_lstTableconfig_bc2.Add("X307");
  309. this.m_lstTableconfig_bc2.Add("PBLB{BOAT,BOOT,PATROLBOAT}");
  310. this.m_lstTableconfig_bc2.Add("//HELIS");
  311. this.m_lstTableconfig_bc2.Add("MI28{HAVOC,MI-28}");
  312. this.m_lstTableconfig_bc2.Add("MI24{HIND,MI-24}");
  313. this.m_lstTableconfig_bc2.Add("UAV1{UAV,DROHNE}");
  314. this.m_lstTableconfig_bc2.Add("AH60{BLACKHAWK,AH-60}");
  315. this.m_lstTableconfig_bc2.Add("AH64{APACHE,AH-64}");
  316. this.m_lstTableconfig_bc2.Add("KA52{ALLIGATOR,HOKUM-B,KA-52,HOKUM}");
  317. this.m_lstTableconfig_bc2.Add("//JEEPS QUADS");
  318. this.m_lstTableconfig_bc2.Add("COBR{COBRA}");
  319. this.m_lstTableconfig_bc2.Add("HUMV{HUMVEE,HMMWV}");
  320. this.m_lstTableconfig_bc2.Add("CAVJ");
  321. this.m_lstTableconfig_bc2.Add("VODN");
  322. this.m_lstTableconfig_bc2.Add("//TANKS");
  323. this.m_lstTableconfig_bc2.Add("T90R{T90,T90MBT}");
  324. this.m_lstTableconfig_bc2.Add("M1A2{ABRAMS}");
  325. this.m_lstTableconfig_bc2.Add("//APC");
  326. this.m_lstTableconfig_bc2.Add("BMD3");
  327. this.m_lstTableconfig_bc2.Add("M3A3{BRADLEY}");
  328. this.m_lstTableconfig_bc2.Add("//AA-Tanks");
  329. this.m_lstTableconfig_bc2.Add("BMDA");
  330. this.m_lstTableconfig_bc2.Add("ACV-S{ANTIAIRBRADLEY}");
  331. this.m_lstTableconfig_bc2.Add("//DESTRUCTION 2.0");
  332. this.m_lstTableconfig_bc2.Add("D2.0{DESTRUCTION,DESTRUCTION2.0}");
  333. this.m_lstTableconfig_bc2.Add("//UNKNOWN");
  334. this.m_lstTableconfig_bc2.Add("UNKNOWN");
  335. this.m_lstTableconfig_bc2.Add("COAXMG");
  336. this.m_lstTableconfig_bc2.Add("MP7");
  337. this.m_lstTableconfig_bc2.Add("QLZ8");
  338. this.m_lstTableschema_bc2 = new List<string>(this.m_lstTableconfig_bc2);
  339. //BFBC2 Vietnam
  340. this.m_lstTableconfig_bfv.Add("//ASSAULT");
  341. this.m_lstTableconfig_bfv.Add("M16A1V{M16A1}");
  342. this.m_lstTableconfig_bfv.Add("AK47V{AK47,AK-47}");
  343. this.m_lstTableconfig_bfv.Add("M79V{M79}");
  344. this.m_lstTableconfig_bfv.Add("M14V{M14}");
  345. this.m_lstTableconfig_bfv.Add("M2V{M2}");
  346. this.m_lstTableconfig_bfv.Add("//ENGINEER");
  347. this.m_lstTableconfig_bfv.Add("MAC10V{MAC10,MAC-10}");
  348. this.m_lstTableconfig_bfv.Add("PPSHV{PPSH}");
  349. this.m_lstTableconfig_bfv.Add("UZIV{UZI}");
  350. this.m_lstTableconfig_bfv.Add("ATM-00{ATMINE,AT-MINE,ANTITANKMINE}");
  351. this.m_lstTableconfig_bfv.Add("RPG7{RPG-7}");
  352. this.m_lstTableconfig_bfv.Add("TORCHV{TORCH}");
  353. this.m_lstTableconfig_bfv.Add("//MEDIC");
  354. this.m_lstTableconfig_bfv.Add("M60V{M60}");
  355. this.m_lstTableconfig_bfv.Add("RPKV{RPK}");
  356. this.m_lstTableconfig_bfv.Add("XM22V{XM22}");
  357. this.m_lstTableconfig_bfv.Add("SYRINGEV{SYRINGE}");
  358. this.m_lstTableconfig_bfv.Add("//SNIPER");
  359. this.m_lstTableconfig_bfv.Add("M21V{M21}");
  360. this.m_lstTableconfig_bfv.Add("SVDV{SVD}");
  361. this.m_lstTableconfig_bfv.Add("M40V{M40}");
  362. this.m_lstTableconfig_bfv.Add("TNTV{TNT}");
  363. this.m_lstTableconfig_bfv.Add("MORTARV{MORTAR}");
  364. this.m_lstTableconfig_bfv.Add("//PISTOLS");
  365. this.m_lstTableconfig_bfv.Add("M1911");
  366. this.m_lstTableconfig_bfv.Add("TT33V{T33V}");
  367. this.m_lstTableconfig_bfv.Add("//HANDGRANATE");
  368. this.m_lstTableconfig_bfv.Add("HG-2{GRANATE, HANDGRANATE,GRENADE,HANDGRENADE,HANDGND}");
  369. this.m_lstTableconfig_bfv.Add("//KNIFE");
  370. this.m_lstTableconfig_bfv.Add("KNV-1{KNIFE,MESSER,COMBATKNIFE,KAMPFMESSER}");
  371. this.m_lstTableconfig_bfv.Add("//ALLKITS");
  372. this.m_lstTableconfig_bfv.Add("FLAMETHROWER");
  373. this.m_lstTableconfig_bfv.Add("GARAND{M1}");
  374. this.m_lstTableconfig_bfv.Add("//SHOTGUN");
  375. this.m_lstTableconfig_bfv.Add("870MCS");
  376. this.m_lstTableconfig_bfv.Add("//SMG");
  377. this.m_lstTableconfig_bfv.Add("M1A1THOMPSON");
  378. this.m_lstTableconfig_bfv.Add("//VEHCLES");
  379. this.m_lstTableconfig_bfv.Add("//LIGHT VEHCLES");
  380. this.m_lstTableconfig_bfv.Add("M151V{M151}");
  381. this.m_lstTableconfig_bfv.Add("ROADKILL");
  382. this.m_lstTableconfig_bfv.Add("//HELIS");
  383. this.m_lstTableconfig_bfv.Add("HUEYV{UH-1,HUEY}");
  384. this.m_lstTableconfig_bfv.Add("//TANKS");
  385. this.m_lstTableconfig_bfv.Add("T54V{T54}");
  386. this.m_lstTableconfig_bfv.Add("M48V{M48}");
  387. this.m_lstTableconfig_bfv.Add("//Boat");
  388. this.m_lstTableconfig_bfv.Add("PBRV{PATROLBOAT,BOAT}");
  389. this.m_lstTableconfig_bfv.Add("//UNKNOWN");
  390. this.m_lstTableconfig_bfv.Add("UNKNOWN");
  391. this.m_lstTableconfig_bfv.Add("G69V");
  392. this.m_lstTableconfig_bfv.Add("//DESTRUCTION 2.0");
  393. this.m_lstTableconfig_bfv.Add("D2.0{DESTRUCTION,DESTRUCTION2.0}");
  394. this.m_lstTableschema_bfv = new List<string>(this.m_lstTableconfig_bfv);
  395. }
  396. #endregion
  397. #region PluginSetup
  398. public string GetPluginName()
  399. {
  400. return "BFBC2 Chat, GUID, Stats and Map Logger";
  401. }
  402. public string GetPluginVersion()
  403. {
  404. return "3.0.2.2";
  405. }
  406. public string GetPluginAuthor()
  407. {
  408. return "[GWC]XpKiller";
  409. }
  410. public string GetPluginWebsite()
  411. {
  412. return "www.german-wildcards.de";
  413. }
  414. public string GetPluginDescription()
  415. {
  416. return @"
  417. If you like my Plugins, please feel free to donate<br>
  418. <p><form action='https://www.paypal.com/cgi-bin/webscr' method='post'>
  419. <input type='hidden' name='cmd' value='_s-xclick'>
  420. <input type='hidden' name='hosted_button_id' value='VW7CR5B8ZQ7S6'>
  421. <input type='image' src='https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>
  422. <img alt='' border='0' src='https://www.paypal.com/de_DE/i/scr/pixel.gif' width='1' height='1'></p>
  423. </form>
  424. <h2>Description</h2>
  425. <p>This plugin is used to log player chat, player GUID's und player Stats and Weaponstats and Mapstats.</p>
  426. <p>This inludes: Chat, PBGUID, EAGUID, IP, Stats, Weaponstats, Dogtags, Killstreaks, Country, ClanTag to be continued.. ;-)</p>
  427. <h2>Requirements</h2>
  428. <p>It reqiues the use of a MySQL database with INNODB engine that allows remote connections.(MYSQL Version 5.1.x or higher is recommendend!!!)</p>
  429. <p>Also you should give INNODB some more Ram because the plugin mainly uses this engine if you need help ask me</p>
  430. <p>You will also need to download the MySQL ODBC 5.1 Driver(the latest is 5.1.7(24.08.2010)), and enable ODBC connections in the procon options.</p>
  431. <p>The Plugin will create the tables by itself.</p>
  432. <p>Pls Give FEEDBACK !!!</p>
  433. <h2>Installation</h2>
  434. <p>Download and install this plugin</p>
  435. <p>Download and install the <a href='http://www.mysql.com/downloads/connector/odbc/' target='_blank'>MYSQL ODBC Connector 5.1 Driver (the latest is 5.1.7(24.08.2010))</a></p>
  436. <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>
  437. <p>I recommend MySQL 5.1.x or greater (5.0.x should work too) Important: <b>Your database need INNODB Support</b></p>
  438. <p>Start Procon</p>
  439. <p>Go to Tools --> Options --> Plugins --> Enter you databaseserver under outgoing Connections and allow all outgoing connections</p>
  440. <p>Restart Procon</p>
  441. <p>Select the GameMod (BC2 / VIETNAM / Shared) Default is BC2 or let the plugin detect the GameMod </p>
  442. <p>Enter your settings into Plugin Settings and THEN enable the plugin</p>
  443. <p>Now the plugin should work if not request help in the <a href='http://phogue.net/forum/viewtopic.php?f=18&t=694' target='_blank'>Forum</a></p>
  444. <h2>Things you have to know:</h2>
  445. You need to drop your old tables or use the mysql script in the zip file<br>
  446. Now you can have more than one server per database if you use the tableSuffix feature, if you dont want to use it keep this field blank.<br>
  447. You can add additional Names for weapons in the Pluginsettings
  448. But only use UpperCase, no Spaces and comma to seperate the words.<br>
  449. Example: 40MMGL{NOOBTUBE} --> 40MMGL{NOOBTUBE,GL,TUBE}<br>
  450. Dont change the first word!!! only these in brackets if there are no brackets you can add them.<br><br>
  451. <h2>Ingame Commands</h2>
  452. <blockquote><h4>[@,#,!]stats</h4>Tells the Player their own Serverstats</blockquote>
  453. <blockquote><h4>[@,#,!]rank</h4>Tells the Player their own Serverstats</blockquote>
  454. <blockquote><h4>[@,#,!]session</h4>Tells the Player their own Sessiondata</blockquote>
  455. <blockquote><h4>[@,#,!]top10</h4>Tells the Player the Top10 players of the server</blockquote>
  456. <blockquote><h4>[@,#,!]stats WeaponName</h4>Tells the Player their own Weaponstats for the specific Weapon</blockquote>
  457. <blockquote><h4>[@,#,!]rank WeaponName</h4>Privately Tells the Player their own Weaponstats for the specific Weapon</blockquote>
  458. <blockquote><h4>[@,#,!]top10 WeaponName</h4>Privately Tells the Player the Top10 Player for the specific Weapon of the server</blockquote>
  459. <blockquote><h4>[@,#,!]dogtags WeaponName</h4>Privately Tells the Player his Dogtagstats </blockquote>
  460. <h2>Replacement String for Playerstats</h2>
  461. <table border ='1'>
  462. <tr><th>Replacement String</th><th>Effect</th></tr>
  463. <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  464. <tr><td>%playerScore%</td><td>Will be replaced by the player's totalscore on this server</td></tr>
  465. <tr><td>%SPM%</td><td>Will be replaced by the Player's score per minute on this server</td></tr>
  466. <tr><td>%playerKills%</td><td>Will be replaced by the player's totalkills on this server</td></tr>
  467. <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's totalheadshots on this server</td></tr>
  468. <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths on this server</td></tr>
  469. <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio on this server</td></tr>
  470. <tr><td>%playerSucide%</td><td>Will be replaced by the player's sucides on this server</td></tr>
  471. <tr><td>%playerPlaytime%</td><td>Will be replaced by the player's totalplaytime on this server in hh:mm:ss format</td></tr>
  472. <tr><td>%rounds%</td><td>Will be replaced by the player's totalrounds played on this server</td></tr>
  473. <tr><td>%playerRank%</td><td>Will be replaced by the player's concurrent serverrank</td></tr>
  474. <tr><td>%allRanks%</td><td>Will be replaced by the player's concurrent serverrank</td></tr>
  475. <tr><td>%killstreak%</td><td>Will be replaced by the player's best Killstreak</td></tr>
  476. <tr><td>%deathstreak%</td><td>Will be replaced by the player's worst Deathstreak</td></tr>
  477. </table>
  478. <br>
  479. <h2>Replacement String for Weaponstats</h2>
  480. <table border ='1'>
  481. <tr><th>Replacement String</th><th>Effect</th></tr>
  482. <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  483. <tr><td>%playerKills%</td><td>Will be replaced by the player's Totalkills on this server with the specific Weapon</td></tr>
  484. <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's Totalheadshotkills on this server the specific Weapon</td></tr>
  485. <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths on this server caused by this specific Weapon</td></tr>
  486. <tr><td>%playerKDH%</td><td>Will be replaced by the player's Headshotkill ratio on this server with the specific Weapon</td></tr>
  487. <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio on this server with the specific Weapon</td></tr>
  488. <tr><td>%playerRank%</td><td>Will be replaced by the player's current Serverrank for the specific Weapon</td></tr>
  489. <tr><td>%allRanks%</td><td>Will be replaced by current Number of Player in Serverrank for the specific Weapon</td></tr>
  490. <tr><td>%killstreak%</td><td>Will be replaced by the player's best Killstreak</td></tr>
  491. <tr><td>%deathstreak%</td><td>Will be replaced by the player's worst Deathstreak</td></tr>
  492. </table>
  493. <h2>Replacement String for PlayerSession</h2>
  494. <table border ='1'>
  495. <tr><th>Replacement String</th><th>Effect</th></tr>
  496. <tr><td>%playerName%</td><td>Will be replaced by the player's name</td></tr>
  497. <tr><td>%playerScore%</td><td>Will be replaced by the player's totalscore of the concurrent Session</td></tr>
  498. <tr><td>%playerKills%</td><td>Will be replaced by the player's totalkills of the concurrent Session</td></tr>
  499. <tr><td>%playerHeadshots%</td><td>Will be replaced by the player's totalheadshots of the concurrent Session</td></tr>
  500. <tr><td>%playerDeaths%</td><td>Will be replaced by the player's totaldeaths of the concurrent Session</td></tr>
  501. <tr><td>%playerKDR%</td><td>Will be replaced by the player's kill death ratio of the concurrent Session</td></tr>
  502. <tr><td>%playerSucide%</td><td>Will be replaced by the player's sucides of the concurrent Session</td></tr>
  503. <tr><td>%SessionDuration%</td><td>Will be replaced by the player's totalplaytime of the concurrent Session in Minutes</td></tr>
  504. <tr><td>%playerRank%</td><td>Will be replaced by the player's concurrent serverrank</td></tr>
  505. <tr><td>%RankDif%</td><td>Will be replaced by the player's rank change</td></tr>
  506. <tr><td>%SessionStarted%</td><td>Will be replaced by the player's start of the Session</td></tr>
  507. <tr><td>%killstreak%</td><td>Will be replaced by the player's best Killstreak of the Session</td></tr>
  508. <tr><td>%deathstreak%</td><td>Will be replaced by the player's worst Deathstreak of the Session</td></tr>
  509. </table>
  510. <br>
  511. <h3>NOTE:</h3>
  512. <p>Tracked stats are: Kills, Headshots, Deaths, All Weapons, TKs, Suicides, Score, Playtime, Rounds, MapStats, Dogtags </p>
  513. <p>The Rank is created dynamical from Query in my opinion much better than write it back to database.</p>
  514. <p>The Stats are written to the Database at the end of the round</p>
  515. <p>Cheaterprotection uses Stats from BFBCS only!!!</p>
  516. <p>Cheaterprotection kicks in if both values are over the limit</p>
  517. <h3>Known issues:</h3>
  518. <p> If you reason is too long the Ban wont work(Eaguid Ban, Nameban)</p>
  519. <p> Avoid using Special characters in the Reason Messages</p>
  520. <h3>Changelog:</h3><br>
  521. <b>3.0.2.2</b>
  522. Fixed Bug that a player is not in the Database because he got kicked be the the cheaterprotection<br>
  523. Improved BFBCS Statsfetch by packing multiply players in one query to bfbcs. The Plugin waits now until the minimum playercount is reached<br>
  524. This optimization can be disabled by setting the the Request Packrate to 0. <br>
  525. Recommend values are 2-3 or higher.<br><br>
  526. <b>3.0.2.1</b>
  527. Fixed Bug might cause false entry in tbl_bfbcs(overwritting existent entries)<br><br>
  528. <b>3.0.2.0 </b><br>
  529. Now able to pull Stats from BFBCS and able to warn/kick/ban Player with high kdr and high Score per Minute (Globalstats)<br>
  530. The Stats of BFBCS will be stored in the DB to reduce stress on BFBCS api.
  531. The Updateinterval (in hours) for the BFBCS Stats is variable and configurable (pls dont choose to low values)<br>
  532. The plugin fetches up to 32 Players in one query from BFBCS and is able to repair JSON Objects containing Error messages from BFBCS API.<br>
  533. The plugin tries to get the stats onetime only at the moment.<br>
  534. Some Improvements in Code<br>
  535. Cheater and Statspadder Protection based on Globalstats of BFBCS with configurable Limits and minimum values.<br>
  536. Chatlog can be turned off now<br>
  537. Option for Update empty PB-Guids(not recommend) <br>
  538. Added Servertimeoffset feature<br><br>
  539. <b>3.0.1.3 -->3.0.1.4 </b><br>
  540. Added missing Weapon <br><br>
  541. <b>3.0.1.2 -->3.0.1.3 </b><br>
  542. Added missing Weapons thx to Sir_Duck for the report <br><br>
  543. <b>3.0.1.1 -->3.0.1.2 </b><br>
  544. Added missing Weapons thx to Hellokitty for the report <br>
  545. Fixed Typo thx to HunterBfV <br><br>
  546. <b>3.0.1.0 -->3.0.1.1 </b><br>
  547. New Shared Mode -> BC2 and Vietnam in the same tables.<br>
  548. Several Bugfixes<br>
  549. Added Option to disable Weaponstatslogging on Request<br>
  550. <b>3.0.0.7 -->3.0.1.0 </b><br>
  551. Automatic detection of the Gamemod(BC2 / Vietnam)<br>
  552. Added Support for BFBC2 Vietnam just select the right Gamemod in Pluginsettings or let it set by the Plugin automatically <br>
  553. Tables of Vietnam are called (tbl_playerstats_bfv, tbl_weaponstats_bfv, tbl_chatlog_bfv, tbl_dogtags_bfv, tbl_mapstats_bfv) + your suffix<br>
  554. BC2 and Vietnam share the same tbl_playerdata + you Suffix<br>
  555. You will need a new Version of Webstats for Vietnam which i will provide later<br>
  556. Serveral small fixes and improvements<br><br>
  557. <b>3.0.0.6 -->3.0.0.7 </b><br>
  558. Some Bugfixes<br>
  559. New Feature: The plugin is now checking the the weapontable if it contains all needed fields(weapons)<br>
  560. Dont worry about the weapons anymore.<br><br>
  561. <b>3.0.0.5 -->3.0.0.6 </b><br>
  562. Bugfixes<br><br>
  563. Scorebug is not fully fixed atm
  564. <b>3.0.0.4 -->3.0.0.5 </b><br>
  565. Bugfixes in tablebuilder<br><br>
  566. <b>3.0.0.3 -->3.0.0.4 </b><br>
  567. Bugfixes<br><br>
  568. <b>3.0.0.2 -->3.0.0.3 </b><br>
  569. Bugfixes<br><br>
  570. <b>3.0.0.1 -->3.0.0.2 /b><br>
  571. Bugfix<br>
  572. New Replacements<br><br>
  573. <b>3.0.0.0 -->3.0.0.1 </b><br>
  574. IMPORTANT BUGFIX<br><br>
  575. <b>2.0.6.4 -->3.0.0.0 </b><br>
  576. NEW TABLE DESIGN --> FASTER!!!<br>
  577. Floodprotection<br>
  578. Killstreak and Deathstreak Tracking<br><br>
  579. <b>2.0.6.3 --> 2.0.6.4</b><br>
  580. New @session Command Player now can call there Sessiondata.<br>
  581. Some small improvements<br><br>
  582. ";
  583. }
  584. public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion) {
  585. this.m_strHostName = strHostName;
  586. this.m_strPort = strPort;
  587. this.m_strPRoConVersion = strPRoConVersion;
  588. this.RegisterEvents(this.GetType().Name, "OnListPlayers", "OnPlayerJoin","OnGlobalChat","OnTeamChat","OnSquadChat","OnPunkbusterMessage","OnPunkbusterPlayerInfo","OnServerInfo",
  589. "OnPlayerKilled","OnPlayerLeft","OnRoundOverPlayers","OnPlayerSpawned","OnLoadingLevel","OnCommandStats","OnCommandTop10","OnCommandDogtags");
  590. }
  591. public void OnPluginEnable() {
  592. isStreaming = true;
  593. this.serverName = "";
  594. this.ExecuteCommand("procon.protected.pluginconsole.write", "^bBF BC2 Chat, GUID and Stats Logger ^2Enabled");
  595. this.Spamprotection = new CSpamprotection(numberOfAllowedRequests);
  596. this.ExecuteCommand("procon.protected.pluginconsole.write", "^bBF BC2 Chat, GUID and Stats Logger: ^2 Floodprotection set to "+ this.numberOfAllowedRequests.ToString() + " Request per Round for each Player");
  597. // Register Commands
  598. this.m_isPluginEnabled = true;
  599. this.prepareTablenames(this.m_strGameMod);
  600. this.setGameMod(this.m_strGameMod);
  601. this.MyDateTime = new myDateTime_W(this.m_dTimeOffset);
  602. this.RegisterAllCommands();
  603. }
  604. public void OnPluginDisable()
  605. {
  606. isStreaming = false;
  607. if(OdbcCon != null)
  608. if (OdbcCon.State == ConnectionState.Open)
  609. {
  610. OdbcCon.Close();
  611. }
  612. if(OdbcConn != null)
  613. if (OdbcConn.State == ConnectionState.Open)
  614. {
  615. OdbcConn.Close();
  616. }
  617. this.ExecuteCommand("procon.protected.pluginconsole.write", "^bBF BC2 Chat, GUID and Stats Logger ^1Disabled");
  618. //Unregister Commands
  619. this.m_isPluginEnabled = false;
  620. this.UnregisterAllCommands();
  621. }
  622. // Lists only variables you want shown.. for instance enabling one option might hide another option
  623. // It's the best I got until I implement a way for plugins to display their own small interfaces.
  624. public List<CPluginVariable> GetDisplayPluginVariables() {
  625. List<CPluginVariable> lstReturn = new List<CPluginVariable>();
  626. lstReturn.Add(new CPluginVariable("Server Details|Host", this.m_strHost.GetType(), this.m_strHost));
  627. lstReturn.Add(new CPluginVariable("Server Details|Port", this.m_strDBPort.GetType(), this.m_strDBPort));
  628. lstReturn.Add(new CPluginVariable("Server Details|Database Name", this.m_strDatabase.GetType(), this.m_strDatabase));
  629. lstReturn.Add(new CPluginVariable("Server Details|UserName", this.m_strUserName.GetType(), this.m_strUserName));
  630. lstReturn.Add(new CPluginVariable("Server Details|Password", this.m_strPassword.GetType(), this.m_strPassword));
  631. lstReturn.Add(new CPluginVariable("Chatlogging|Enable Chatlogging?", typeof(enumBoolYesNo), this.m_enChatloggingON));
  632. if(this.m_enChatloggingON == enumBoolYesNo.Yes)
  633. {
  634. lstReturn.Add(new CPluginVariable("Chatlogging|Log ServerSPAM?", typeof(enumBoolYesNo), this.m_enNoServerMsg));
  635. lstReturn.Add(new CPluginVariable("Chatlogging|Instant Logging of Chat Messages?", typeof(enumBoolYesNo), this.m_enInstantChatlogging));
  636. }
  637. lstReturn.Add(new CPluginVariable("Stats|Enable Statslogging?", typeof(enumBoolYesNo), this.m_enLogSTATS));
  638. lstReturn.Add(new CPluginVariable("Stats|Enable Weaponstats?", typeof(enumBoolYesNo), this.m_weaponstatsON));
  639. lstReturn.Add(new CPluginVariable("Stats|Update EA GUID?", typeof(enumBoolYesNo), this.m_UpdateEA_GUID));
  640. lstReturn.Add(new CPluginVariable("Stats|Update PB-GUID (NOT recommended!!!)?", typeof(enumBoolYesNo), this.m_UpdatePB_GUID));
  641. lstReturn.Add(new CPluginVariable("Stats|Ranking by Score?", typeof(enumBoolYesNo), this.m_enRankingByScore));
  642. lstReturn.Add(new CPluginVariable("Stats|Send Stats to all Players?", typeof(enumBoolYesNo), this.m_enSendStatsToAll));
  643. lstReturn.Add(new CPluginVariable("Stats|PlayerMessage", typeof(string[]), this.m_lstPlayerStatsMessage.ToArray()));
  644. lstReturn.Add(new CPluginVariable("Stats|Weaponstats Message", typeof(string[]), this.m_lstWeaponstatsMsg.ToArray()));
  645. lstReturn.Add(new CPluginVariable("WelcomeStats|Enable Welcomestats?", typeof(enumBoolYesNo), this.m_enWelcomeStats));
  646. lstReturn.Add(new CPluginVariable("WelcomeStats|Yell Welcome Message(not the stats)?", typeof(enumBoolYesNo), this.m_enYellWelcomeMSG));
  647. lstReturn.Add(new CPluginVariable("WelcomeStats|Welcome Message", this.m_strPlayerWelcomeMsg.GetType(), this.m_strPlayerWelcomeMsg));
  648. lstReturn.Add(new CPluginVariable("WelcomeStats|Welcome Message for new Player", this.m_strNewPlayerWelcomeMsg.GetType(), this.m_strNewPlayerWelcomeMsg));
  649. lstReturn.Add(new CPluginVariable("WelcomeStats|Welcomestats Delay", this.int_welcomeStatsDelay.GetType(), this.int_welcomeStatsDelay));
  650. lstReturn.Add(new CPluginVariable("Stats|Top10 ingame", this.m_enTop10ingame.GetType(), this.m_enTop10ingame));
  651. lstReturn.Add(new CPluginVariable("Debug|Debugmode on?", typeof(enumBoolYesNo), this.m_enDebugMode));
  652. lstReturn.Add(new CPluginVariable("Table|Keywordlist BC2", typeof(string[]), this.m_lstTableconfig_bc2.ToArray()));
  653. lstReturn.Add(new CPluginVariable("Table|Keywordlist Vietnam", typeof(string[]), this.m_lstTableconfig_bfv.ToArray()));
  654. lstReturn.Add(new CPluginVariable("Table|tableSuffix", this.tableSuffix.GetType(), this.tableSuffix));
  655. lstReturn.Add(new CPluginVariable("MapStats|MapStats ON?", typeof(enumBoolYesNo), this.m_mapstatsON));
  656. lstReturn.Add(new CPluginVariable("Session|Session ON?", typeof(enumBoolYesNo), this.m_sessionON));
  657. lstReturn.Add(new CPluginVariable("Session|SessionMessage", typeof(string[]), this.m_lstSessionMessage.ToArray()));
  658. lstReturn.Add(new CPluginVariable("FloodProtection|Playerrequests per Round", this.numberOfAllowedRequests.GetType(), this.numberOfAllowedRequests));
  659. lstReturn.Add(new CPluginVariable("TimeOffset|Servertime Offset", this.m_dTimeOffset.GetType(), this.m_dTimeOffset));
  660. lstReturn.Add(new CPluginVariable("Stats|Default GameMod", "enum.GameMods(BC2|VIETNAM|SHARED)", this.m_strGameMod));
  661. lstReturn.Add(new CPluginVariable("BFBCS|Fetch Stats from BFBCS", typeof(enumBoolYesNo), this.m_getStatsfromBFBCS));
  662. if(this.m_getStatsfromBFBCS == enumBoolYesNo.Yes)
  663. {
  664. lstReturn.Add(new CPluginVariable("BFBCS|Updateinterval (hours)", this.BFBCS_UpdateInterval.GetType(), this.BFBCS_UpdateInterval));
  665. lstReturn.Add(new CPluginVariable("BFBCS|Request Packrate", this.BFBCS_Min_Request.GetType(), this.BFBCS_Min_Request));
  666. lstReturn.Add(new CPluginVariable("Cheaterprotection|Statsbased Protection", typeof(enumBoolYesNo), this.m_cheaterProtection));
  667. }
  668. if(this.m_cheaterProtection == enumBoolYesNo.Yes)
  669. {
  670. lstReturn.Add(new CPluginVariable("Cheaterprotection|Max. KDR:", this.m_dMaxAllowedKDR.GetType(), this.m_dMaxAllowedKDR));
  671. lstReturn.Add(new CPluginVariable("Cheaterprotection|Max. SPM:", this.m_dMaxScorePerMinute.GetType(), this.m_dMaxScorePerMinute));
  672. lstReturn.Add(new CPluginVariable("Cheaterprotection|Min. Playtime(hours):", this.m_dminimumPlaytime.GetType(), this.m_dminimumPlaytime));
  673. lstReturn.Add(new CPluginVariable("Cheaterprotection|Reason Message:", this.m_strReasonMsg.GetType(), this.m_strReasonMsg));
  674. lstReturn.Add(new CPluginVariable("Cheaterprotection|Perform Action", "enum.Actions(Warn|Kick|Nameban|EAGUIDBan|PBBan)", this.m_strRemoveMethode));
  675. }
  676. return lstReturn;
  677. }
  678. // Lists all of the plugin variables.
  679. public List<CPluginVariable> GetPluginVariables() {
  680. List<CPluginVariable> lstReturn = new List<CPluginVariable>();
  681. lstReturn.Add(new CPluginVariable("Host", this.m_strHost.GetType(), this.m_strHost));
  682. lstReturn.Add(new CPluginVariable("Port", this.m_strDBPort.GetType(), this.m_strDBPort));
  683. lstReturn.Add(new CPluginVariable("Database Name", this.m_strDatabase.GetType(), this.m_strDatabase));
  684. lstReturn.Add(new CPluginVariable("UserName", this.m_strUserName.GetType(), this.m_strUserName));
  685. lstReturn.Add(new CPluginVariable("Password", this.m_strPassword.GetType(), this.m_strPassword));
  686. // Switch for Stats Logging
  687. lstReturn.Add(new CPluginVariable("Enable Chatlogging?", typeof(enumBoolYesNo), this.m_enChatloggingON));
  688. if(this.m_enChatloggingON == enumBoolYesNo.Yes)
  689. {
  690. lstReturn.Add(new CPluginVariable("Log ServerSPAM?", typeof(enumBoolYesNo), this.m_enNoServerMsg));
  691. lstReturn.Add(new CPluginVariable("Instant Logging of Chat Messages?", typeof(enumBoolYesNo), this.m_enInstantChatlogging));
  692. }
  693. lstReturn.Add(new CPluginVariable("Enable Statslogging?", typeof(enumBoolYesNo), this.m_enLogSTATS));
  694. lstReturn.Add(new CPluginVariable("Enable Weaponstats?", typeof(enumBoolYesNo), this.m_weaponstatsON));
  695. lstReturn.Add(new CPluginVariable("Update EA GUID?", typeof(enumBoolYesNo), this.m_UpdateEA_GUID));
  696. lstReturn.Add(new CPluginVariable("Update PB-GUID (NOT recommended!!!)?", typeof(enumBoolYesNo), this.m_UpdatePB_GUID));
  697. lstReturn.Add(new CPluginVariable("Ranking by Score?", typeof(enumBoolYesNo), this.m_enRankingByScore));
  698. lstReturn.Add(new CPluginVariable("Send Stats to all Players?", typeof(enumBoolYesNo), this.m_enSendStatsToAll));
  699. lstReturn.Add(new CPluginVariable("PlayerMessage", typeof(string[]), this.m_lstPlayerStatsMessage.ToArray()));
  700. lstReturn.Add(new CPluginVariable("Weaponstats Message", typeof(string[]), this.m_lstWeaponstatsMsg.ToArray()));
  701. lstReturn.Add(new CPluginVariable("Enable Welcomestats?", typeof(enumBoolYesNo), this.m_enWelcomeStats));
  702. lstReturn.Add(new CPluginVariable("Yell Welcome Message(not the stats)?", typeof(enumBoolYesNo), this.m_enYellWelcomeMSG));
  703. lstReturn.Add(new CPluginVariable("Welcome Message", this.m_strPlayerWelcomeMsg.GetType(), this.m_strPlayerWelcomeMsg));
  704. lstReturn.Add(new CPluginVariable("Welcome Message for new Player", this.m_strNewPlayerWelcomeMsg.GetType(), this.m_strNewPlayerWelcomeMsg));
  705. lstReturn.Add(new CPluginVariable("Welcomestats Delay", this.int_welcomeStatsDelay.GetType(), this.int_welcomeStatsDelay));
  706. lstReturn.Add(new CPluginVariable("Top10 ingame", this.m_enTop10ingame.GetType(), this.m_enTop10ingame));
  707. lstReturn.Add(new CPluginVariable("Debugmode on?", typeof(enumBoolYesNo), this.m_enDebugMode));
  708. lstReturn.Add(new CPluginVariable("Keywordlist BC2", typeof(string[]), this.m_lstTableconfig_bc2.ToArray()));
  709. lstReturn.Add(new CPluginVariable("Keywordlist Vietnam", typeof(string[]), this.m_lstTableconfig_bfv.ToArray()));
  710. lstReturn.Add(new CPluginVariable("tableSuffix", this.tableSuffix.GetType(), this.tableSuffix));
  711. lstReturn.Add(new CPluginVariable("MapStats ON?", typeof(enumBoolYesNo), this.m_mapstatsON));
  712. lstReturn.Add(new CPluginVariable("Session ON?", typeof(enumBoolYesNo), this.m_sessionON));
  713. lstReturn.Add(new CPluginVariable("SessionMessage", typeof(string[]), this.m_lstSessionMessage.ToArray()));
  714. lstReturn.Add(new CPluginVariable("Playerrequests per Round", this.numberOfAllowedRequests.GetType(), this.numberOfAllowedRequests));
  715. lstReturn.Add(new CPluginVariable("Servertime Offset", this.m_dTimeOffset.GetType(), this.m_dTimeOffset));
  716. lstReturn.Add(new CPluginVariable("Default GameMod", "enum.GameMods(BC2|VIETNAM|SHARED)", this.m_strGameMod));
  717. lstReturn.Add(new CPluginVariable("Fetch Stats from BFBCS", typeof(enumBoolYesNo), this.m_getStatsfromBFBCS));
  718. if(this.m_getStatsfromBFBCS == enumBoolYesNo.Yes)
  719. {
  720. lstReturn.Add(new CPluginVariable("Updateinterval (hours)", this.BFBCS_UpdateInterval.GetType(), this.BFBCS_UpdateInterval));
  721. lstReturn.Add(new CPluginVariable("Request Packrate", this.BFBCS_Min_Request.GetType(), this.BFBCS_Min_Request));
  722. lstReturn.Add(new CPluginVariable("Statsbased Protection", typeof(enumBoolYesNo), this.m_cheaterProtection));
  723. }
  724. if(this.m_cheaterProtection == enumBoolYesNo.Yes)
  725. {
  726. lstReturn.Add(new CPluginVariable("Max. KDR:", this.m_dMaxAllowedKDR.GetType(), this.m_dMaxAllowedKDR));
  727. lstReturn.Add(new CPluginVariable("Max. SPM:", this.m_dMaxScorePerMinute.GetType(), this.m_dMaxScorePerMinute));
  728. lstReturn.Add(new CPluginVariable("Min. Playtime(hours):", this.m_dminimumPlaytime.GetType(), this.m_dminimumPlaytime));
  729. lstReturn.Add(new CPluginVariable("Reason Message:", this.m_strReasonMsg.GetType(), this.m_strReasonMsg));
  730. lstReturn.Add(new CPluginVariable("Perform Action", "enum.Actions(Kick|Nameban|EAGUIDBan|PBBan)", this.m_strRemoveMethode));
  731. }
  732. return lstReturn;
  733. }
  734. public void SetPluginVariable(string strVariable, string strValue)
  735. {
  736. if (strVariable.CompareTo("Host") == 0)
  737. {
  738. this.m_strHost = strValue;
  739. }
  740. else if (strVariable.CompareTo("Port") == 0)
  741. {
  742. this.m_strDBPort = strValue;
  743. }
  744. else if (strVariable.CompareTo("Database Name") == 0)
  745. {
  746. this.m_strDatabase = strValue;
  747. }
  748. else if (strVariable.CompareTo("UserName") == 0)
  749. {
  750. this.m_strUserName = strValue;
  751. }
  752. else if (strVariable.CompareTo("Password") == 0)
  753. {
  754. this.m_strPassword = strValue;
  755. }
  756. else if (strVariable.CompareTo("Enable Chatlogging?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  757. {
  758. this.m_enChatloggingON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  759. }
  760. else if (strVariable.CompareTo("Log ServerSPAM?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  761. {
  762. this.m_enNoServerMsg = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  763. }
  764. else if (strVariable.CompareTo("Instant Logging of Chat Messages?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  765. {
  766. this.m_enInstantChatlogging = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  767. }
  768. else if (strVariable.CompareTo("Enable Statslogging?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  769. {
  770. this.m_enLogSTATS = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  771. }
  772. else if (strVariable.CompareTo("Enable Weaponstats?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  773. {
  774. this.m_weaponstatsON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  775. }
  776. else if (strVariable.CompareTo("Update EA GUID?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  777. {
  778. this.m_UpdateEA_GUID = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  779. }
  780. else if (strVariable.CompareTo("Update PB-GUID (NOT recommended!!!)?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  781. {
  782. this.m_UpdatePB_GUID = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  783. }
  784. else if (strVariable.CompareTo("Ranking by Score?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  785. {
  786. this.m_enRankingByScore = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  787. }
  788. else if (strVariable.CompareTo("Send Stats to all Players?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  789. {
  790. this.m_enSendStatsToAll = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  791. }
  792. else if (strVariable.CompareTo("PlayerMessage") == 0)
  793. {
  794. this.m_lstPlayerStatsMessage = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  795. }
  796. else if (strVariable.CompareTo("Weaponstats Message") == 0)
  797. {
  798. this.m_lstWeaponstatsMsg = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  799. }
  800. else if (strVariable.CompareTo("Enable Welcomestats?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  801. {
  802. this.m_enWelcomeStats = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  803. }
  804. else if (strVariable.CompareTo("Yell Welcome Message(not the stats)?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  805. {
  806. this.m_enYellWelcomeMSG = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  807. }
  808. else if (strVariable.CompareTo("Welcome Message") == 0)
  809. {
  810. this.m_strPlayerWelcomeMsg = strValue;
  811. }
  812. else if (strVariable.CompareTo("Welcome Message for new Player") == 0)
  813. {
  814. this.m_strNewPlayerWelcomeMsg = strValue;
  815. }
  816. else if (strVariable.CompareTo("Welcomestats Delay") == 0 && Int32.TryParse(strValue, out int_welcomeStatsDelay) == true)
  817. {
  818. this.int_welcomeStatsDelay = Convert.ToInt32(strValue);
  819. }
  820. else if (strVariable.CompareTo("Top10 ingame") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  821. {
  822. this.m_enTop10ingame = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  823. }
  824. else if (strVariable.CompareTo("Debugmode on?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  825. {
  826. this.m_enDebugMode = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  827. }
  828. else if (strVariable.CompareTo("Keywordlist BC2") == 0)
  829. {
  830. this.m_lstTableconfig_bc2 = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  831. }
  832. else if (strVariable.CompareTo("Keywordlist Vietnam") == 0)
  833. {
  834. this.m_lstTableconfig_bfv = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  835. }
  836. else if (strVariable.CompareTo("tableSuffix") == 0)
  837. {
  838. this.tableSuffix = strValue;
  839. if(this.m_enDebugMode == enumBoolYesNo.Yes)
  840. {
  841. this.m_enDebugMode = enumBoolYesNo.No;
  842. this.prepareTablenames(this.m_strGameMod);
  843. this.setGameMod(this.m_strGameMod);
  844. this.m_enDebugMode = enumBoolYesNo.Yes;
  845. }
  846. else
  847. {
  848. this.prepareTablenames(this.m_strGameMod);
  849. this.setGameMod(this.m_strGameMod);
  850. }
  851. this.boolTableEXISTS = false;
  852. }
  853. else if (strVariable.CompareTo("MapStats ON?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  854. {
  855. this.m_mapstatsON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  856. }
  857. else if (strVariable.CompareTo("Session ON?") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  858. {
  859. this.m_sessionON = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  860. }
  861. else if (strVariable.CompareTo("SessionMessage") == 0)
  862. {
  863. this.m_lstSessionMessage = new List<string>(CPluginVariable.DecodeStringArray(strValue));
  864. }
  865. else if (strVariable.CompareTo("Playerrequests per Round") == 0 && Int32.TryParse(strValue, out numberOfAllowedRequests) == true)
  866. {
  867. this.numberOfAllowedRequests = Convert.ToInt32(strValue);
  868. }
  869. else if (strVariable.CompareTo("Servertime Offset") == 0 && Double.TryParse(strValue, out m_dTimeOffset) == true)
  870. {
  871. this.m_dTimeOffset = Convert.ToDouble(strValue);
  872. this.MyDateTime = new myDateTime_W(this.m_dTimeOffset);
  873. }
  874. else if(strVariable.CompareTo("Default GameMod") == 0)
  875. {
  876. this.m_strGameMod = strValue;
  877. if(this.m_enDebugMode == enumBoolYesNo.Yes)
  878. {
  879. this.m_enDebugMode = enumBoolYesNo.No;
  880. this.prepareTablenames(this.m_strGameMod);
  881. this.setGameMod(this.m_strGameMod);
  882. this.m_enDebugMode = enumBoolYesNo.Yes;
  883. }
  884. else
  885. {
  886. this.prepareTablenames(this.m_strGameMod);
  887. this.setGameMod(this.m_strGameMod);
  888. }
  889. this.boolTableEXISTS = false;
  890. }
  891. else if(strVariable.CompareTo("Fetch Stats from BFBCS") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  892. {
  893. this.m_getStatsfromBFBCS = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo), strValue);
  894. }
  895. else if(strVariable.CompareTo("Request Packrate") == 0 && Int32.TryParse(strValue, out this.BFBCS_Min_Request) == true)
  896. {
  897. this.BFBCS_Min_Request = Convert.ToInt32(strValue);
  898. }
  899. else if(strVariable.CompareTo("Updateinterval (hours)") == 0 && Double.TryParse(strValue, out this.BFBCS_UpdateInterval) == true)
  900. {
  901. this.BFBCS_UpdateInterval = Convert.ToDouble(strValue);
  902. }
  903. else if(strVariable.CompareTo("Statsbased Protection") == 0 && Enum.IsDefined(typeof(enumBoolYesNo), strValue) == true)
  904. {
  905. this.m_cheaterProtection = (enumBoolYesNo)Enum.Parse(typeof(enumBoolYesNo),strValue);
  906. }
  907. else if(strVariable.CompareTo("Max. KDR:") == 0 && Double.TryParse(strValue, out this.m_dMaxAllowedKDR) == true)
  908. {
  909. this.m_dMaxAllowedKDR = Convert.ToDouble(strValue);
  910. }
  911. else if(strVariable.CompareTo("Max. SPM:") == 0 && Double.TryParse(strValue, out this.m_dMaxScorePerMinute) == true )
  912. {
  913. this.m_dMaxScorePerMinute = Convert.ToDouble(strValue);
  914. }
  915. else if(strVariable.CompareTo("Min. Playtime(hours):") == 0 && Double.TryParse(strValue, out this.m_dminimumPlaytime) == true)
  916. {
  917. this.m_dminimumPlaytime = Convert.ToDouble(strValue);
  918. }
  919. else if(strVariable.CompareTo("Reason Message:") == 0)
  920. {
  921. this.m_strReasonMsg = strValue;
  922. }
  923. else if(strVariable.CompareTo("Perform Action") == 0)
  924. {
  925. this.m_strRemoveMethode = strValue;
  926. }
  927. this.RegisterAllCommands();
  928. }
  929. private List<string> GetExcludedCommandStrings(string strAccountName) {
  930. List<string> lstReturnCommandStrings = new List<string>();
  931. List<MatchCommand> lstCommands = this.GetRegisteredCommands();
  932. CPrivileges privileges = this.GetAccountPrivileges(strAccountName);
  933. foreach (MatchCommand mtcCommand in lstCommands) {
  934. if (mtcCommand.Requirements.HasValidPermissions(privileges) == true && lstReturnCommandStrings.Contains(mtcCommand.Command) == false) {
  935. lstReturnCommandStrings.Add(mtcCommand.Command);
  936. }
  937. }
  938. return lstReturnCommandStrings;
  939. }
  940. private List<string> GetCommandStrings() {
  941. List<string> lstReturnCommandStrings = new List<string>();
  942. List<MatchCommand> lstCommands = this.GetRegisteredCommands();
  943. foreach (MatchCommand mtcCommand in lstCommands) {
  944. if (lstReturnCommandStrings.Contains(mtcCommand.Command) == false) {
  945. lstReturnCommandStrings.Add(mtcCommand.Command);
  946. }
  947. }
  948. return lstReturnCommandStrings;
  949. }
  950. private void UnregisterAllCommands() {
  951. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandStats", this.Listify<string>("@", "!", "#"), "stats", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  952. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandStats", this.Listify<string>("@", "!", "#"), "rank", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  953. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandTop10", this.Listify<string>("@", "!", "#"), "top10", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player top10 Players"));
  954. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandDogtags", this.Listify<string>("@", "!", "#"), "dogtags", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  955. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandSession", this.Listify<string>("@", "!", "#"), "session", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal Session data"));
  956. }
  957. private void SetupHelpCommands() {
  958. }
  959. private void RegisterAllCommands() {
  960. if (this.m_isPluginEnabled == true) {
  961. this.SetupHelpCommands();
  962. if(this.m_enLogSTATS == enumBoolYesNo.Yes){
  963. this.RegisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandStats", this.Listify<string>("@", "!", "#"), "stats", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  964. }
  965. else{
  966. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandStats", this.Listify<string>("@", "!", "#"), "stats", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  967. }
  968. if(this.m_enLogSTATS == enumBoolYesNo.Yes){
  969. this.RegisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandStats", this.Listify<string>("@", "!", "#"), "rank", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  970. }
  971. else{
  972. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandStats", this.Listify<string>("@", "!", "#"), "rank", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  973. }
  974. if(this.m_enLogSTATS == enumBoolYesNo.Yes){
  975. this.RegisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandDogtags", this.Listify<string>("@", "!", "#"), "dogtags", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  976. }
  977. else{
  978. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandDogtags", this.Listify<string>("@", "!", "#"), "dogtags", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal serverstats"));
  979. }
  980. if(this.m_enLogSTATS == enumBoolYesNo.Yes && this.m_enTop10ingame == enumBoolYesNo.Yes){
  981. this.RegisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandTop10", this.Listify<string>("@", "!", "#"), "top10", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player top10 Players"));
  982. }
  983. else{
  984. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandTop10", this.Listify<string>("@", "!", "#"), "top10", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player top10 Players"));
  985. }
  986. if(this.m_sessionON == enumBoolYesNo.Yes){
  987. this.RegisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandSession", this.Listify<string>("@", "!", "#"), "session", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal Session data"));
  988. }
  989. else{
  990. this.UnregisterCommand(new MatchCommand("CChatGUIDStatsLogger", "OnCommandSession", this.Listify<string>("@", "!", "#"), "session", this.Listify<MatchArgumentFormat>(), new ExecutionRequirements(ExecutionScope.All), "Provides a player his personal Session data"));
  991. }
  992. }
  993. }
  994. #endregion
  995. #region IPRoConPluginInterface
  996. /*=======ProCon Events========*/
  997. // Player events
  998. public override void OnPlayerJoin(string strSoldierName)
  999. {
  1000. if(this.StatsTracker.ContainsKey(strSoldierName) == false)
  1001. {
  1002. CStats newEntry = new CStats("",0,0,0,0,0,0,0,this.m_dTimeOffset);
  1003. StatsTracker.Add(strSoldierName,newEntry);
  1004. }
  1005. this.CreateSession(strSoldierName);
  1006. if(bool_roundStarted == true && StatsTracker.ContainsKey(strSoldierName) == true)
  1007. {
  1008. if(StatsTracker[strSoldierName].PlayerOnServer == false)
  1009. {
  1010. if(this.StatsTracker[strSoldierName].TimePlayerjoined == null)
  1011. {
  1012. this.StatsTracker[strSoldierName].TimePlayerjoined = MyDateTime.Now;
  1013. }
  1014. this.StatsTracker[strSoldierName].Playerjoined = MyDateTime.Now;
  1015. this.StatsTracker[strSoldierName].PlayerOnServer = true;
  1016. }
  1017. }
  1018. //Mapstatscounter for Player who joined the server
  1019. this.Mapstats.IntplayerjoinedServer++;
  1020. //Call of the Welcomstatsfunction
  1021. this.WelcomeStats(strSoldierName);
  1022. }
  1023. // Will receive ALL chat global/team/squad in R3.
  1024. public override void OnGlobalChat(string strSpeaker, string strMessage)
  1025. {
  1026. this.LogChat(strSpeaker,strMessage,"Global");
  1027. }
  1028. // Place holder, non-functioning in R3. It recieves the same data as OnGlobalChat though so look out for now.
  1029. public override void OnTeamChat(string strSpeaker, string strMessage, int iTeamID)
  1030. {
  1031. this.LogChat(strSpeaker,strMessage,"Team");
  1032. }
  1033. // Place holder, non-functioning in R3. It recieves the same data as OnGlobalChat though so look out for now.
  1034. public override void OnSquadChat(string strSpeaker, string strMessage, int iTeamID, int iSquadID)
  1035. {
  1036. this.LogChat(strSpeaker,strMessage,"Squad");
  1037. }
  1038. public override void OnPunkbusterMessage(string strPunkbusterMessage)
  1039. {
  1040. try
  1041. {
  1042. // This piece of code gets the number of player out of Punkbustermessages
  1043. string playercount ="";
  1044. if(strPunkbusterMessage.Contains("End of Player List"))
  1045. {
  1046. playercount = strPunkbusterMessage.Remove(0,1+strPunkbusterMessage.LastIndexOf("("));
  1047. playercount = playercount.Replace(" ","");
  1048. playercount = playercount.Remove(playercount.LastIndexOf("P"),playercount.LastIndexOf(")"));
  1049. //this.DebugInfo("EoPl: "+playercount);
  1050. int players = Convert.ToInt32(playercount);
  1051. if( players >= 4 && bool_roundStarted == false)
  1052. {
  1053. bool_roundStarted = true;
  1054. Time_RankingStarted = MyDateTime.Now;
  1055. //Mapstats Roundstarted
  1056. this.Mapstats.MapStarted();
  1057. }
  1058. else if(players >= 4 && this.Mapstats.TimeMapStarted == DateTime.MinValue)
  1059. {
  1060. this.Mapstats.MapStarted();
  1061. }
  1062. //MapStats Playercount
  1063. this.Mapstats.ListADD(players);
  1064. }
  1065. }
  1066. catch(Exception c)
  1067. {
  1068. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OnPunkbusterMessage: " + c);
  1069. }
  1070. }
  1071. public override void OnPunkbusterPlayerInfo(CPunkbusterInfo cpbiPlayer)
  1072. {
  1073. this.RegisterAllCommands();
  1074. if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  1075. {
  1076. try
  1077. {
  1078. this.AddPBInfoToStats(cpbiPlayer);
  1079. if(this.StatsTracker.ContainsKey(cpbiPlayer.SoldierName))
  1080. {
  1081. if(this.StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined == null)
  1082. {
  1083. this.StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined = MyDateTime.Now;
  1084. }
  1085. this.StatsTracker[cpbiPlayer.SoldierName].IP = cpbiPlayer.Ip;
  1086. }
  1087. }
  1088. catch (Exception c)
  1089. {
  1090. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OnPunkbusterPlayerInfo: " + c);
  1091. }
  1092. }
  1093. }
  1094. // Query Events
  1095. public override void OnServerInfo(CServerInfo csiServerInfo)
  1096. {
  1097. this.serverName = csiServerInfo.ServerName;
  1098. this.Mapstats.StrGamemode = csiServerInfo.GameMode;
  1099. this.Mapstats.ListADD(csiServerInfo.PlayerCount);
  1100. //Mapstats
  1101. if(csiServerInfo.PlayerCount >= 4 && this.Mapstats.TimeMapStarted == DateTime.MinValue)
  1102. {
  1103. this.Mapstats.MapStarted();
  1104. }
  1105. this.Mapstats.StrMapname = csiServerInfo.Map;
  1106. this.Mapstats.IntRound = csiServerInfo.CurrentRound;
  1107. this.Mapstats.IntNumberOfRounds = csiServerInfo.TotalRounds;
  1108. this.Mapstats.IntServerplayermax = csiServerInfo.MaxPlayerCount;
  1109. if(String.Equals(csiServerInfo.GameMod.ToString(),this.m_strGameMod) != true && String.Equals(csiServerInfo.GameMod.ToString(),"None") != true && String.Equals(this.m_strGameMod, "SHARED") != true)
  1110. {
  1111. this.DebugInfo("GameMod change detected to: " + csiServerInfo.GameMod.ToString());
  1112. this.setGameMod(csiServerInfo.GameMod.ToString());
  1113. this.prepareTablenames(csiServerInfo.GameMod.ToString());
  1114. this.m_strGameMod = csiServerInfo.GameMod.ToString();
  1115. this.boolTableEXISTS = false;
  1116. }
  1117. }
  1118. public override void OnListPlayers(List<CPlayerInfo> lstPlayers, CPlayerSubset cpsSubset)
  1119. {
  1120. int i = lstPlayers.Count;
  1121. List<CPlayerInfo> PlayerList = new List<CPlayerInfo>();
  1122. //Mapstats Add Playercount to list
  1123. this.Mapstats.ListADD(i);
  1124. if(bool_roundStarted == false)
  1125. {
  1126. if (i >= 4)
  1127. {
  1128. bool_roundStarted = true;
  1129. Time_RankingStarted = MyDateTime.Now;
  1130. this.DebugInfo("OLP: roundstarted");
  1131. //Mapstats Roundstarted
  1132. this.Mapstats.MapStarted();
  1133. }
  1134. }
  1135. if(i >= 4 && this.Mapstats.TimeMapStarted == DateTime.MinValue)
  1136. {
  1137. this.Mapstats.MapStarted();
  1138. }
  1139. try
  1140. {
  1141. foreach (CPlayerInfo cpiPlayer in lstPlayers)
  1142. {
  1143. if (this.m_dicPlayers.ContainsKey(cpiPlayer.SoldierName) == true)
  1144. {
  1145. this.m_dicPlayers[cpiPlayer.SoldierName] = cpiPlayer;
  1146. }
  1147. else
  1148. {
  1149. this.m_dicPlayers.Add(cpiPlayer.SoldierName, cpiPlayer);
  1150. }
  1151. //Timelogging
  1152. if(this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  1153. {
  1154. if(this.StatsTracker[cpiPlayer.SoldierName].PlayerOnServer == false)
  1155. {
  1156. this.StatsTracker[cpiPlayer.SoldierName].Playerjoined = MyDateTime.Now;
  1157. this.StatsTracker[cpiPlayer.SoldierName].PlayerOnServer = true;
  1158. }
  1159. //EA-GUID, ClanTag, usw.
  1160. this.StatsTracker[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1161. this.StatsTracker[cpiPlayer.SoldierName].ClanTag = cpiPlayer.ClanTag;
  1162. if(cpiPlayer.Score != 0)
  1163. {
  1164. this.StatsTracker[cpiPlayer.SoldierName].Score = cpiPlayer.Score;
  1165. }
  1166. //BFBCS
  1167. if(String.Equals(this.StatsTracker[cpiPlayer.SoldierName].Guid,"") == false && String.Equals(this.StatsTracker[cpiPlayer.SoldierName].EAGuid,"") == false)
  1168. {
  1169. PlayerList.Add(cpiPlayer);
  1170. }
  1171. }
  1172. //ID - Cache
  1173. if(this.m_ID_cache.ContainsKey(cpiPlayer.SoldierName))
  1174. {
  1175. this.m_ID_cache[cpiPlayer.SoldierName].PlayeronServer = true;
  1176. }
  1177. this.CreateSession(cpiPlayer.SoldierName);
  1178. //Session Score
  1179. if(this.m_dicSession.ContainsKey(cpiPlayer.SoldierName) && this.m_sessionON == enumBoolYesNo.Yes)
  1180. {
  1181. this.m_dicSession[cpiPlayer.SoldierName].AddScore(cpiPlayer.Score);
  1182. }
  1183. }
  1184. if(PlayerList.Count >= this.BFBCS_Min_Request == true)
  1185. {
  1186. this.getBFBCStats(PlayerList);
  1187. }
  1188. }
  1189. catch(Exception c)
  1190. {
  1191. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OnListPlayers: " + c);
  1192. }
  1193. }
  1194. #endregion
  1195. #region IPRoConPluginInterface2
  1196. //
  1197. // IPRoConPluginInterface2
  1198. //
  1199. public override void OnPlayerKilled(Kill kKillerVictimDetails)
  1200. {
  1201. if(bool_roundStarted == true)
  1202. {
  1203. this.playerKilled(kKillerVictimDetails);
  1204. }
  1205. }
  1206. public override void OnPlayerLeft(CPlayerInfo cpiPlayer)
  1207. {
  1208. this.playerLeftServer(cpiPlayer);
  1209. this.RegisterAllCommands();
  1210. }
  1211. public override void OnRoundOverPlayers(List<CPlayerInfo> lstPlayers)
  1212. {
  1213. foreach(CPlayerInfo cpiPlayer in lstPlayers)
  1214. {
  1215. if(this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  1216. {
  1217. this.StatsTracker[cpiPlayer.SoldierName].Score = cpiPlayer.Score;
  1218. //EA-GUID, ClanTag, usw.
  1219. this.StatsTracker[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1220. this.StatsTracker[cpiPlayer.SoldierName].ClanTag = cpiPlayer.ClanTag;
  1221. }
  1222. //Session Score
  1223. if(this.m_dicSession.ContainsKey(cpiPlayer.SoldierName) && this.m_sessionON == enumBoolYesNo.Yes )
  1224. {
  1225. this.m_dicSession[cpiPlayer.SoldierName].AddScore(cpiPlayer.Score);
  1226. }
  1227. this.m_dicSession[cpiPlayer.SoldierName].LastScore = 0;
  1228. }
  1229. this.Mapstats.MapEnd();
  1230. }
  1231. public override void OnPlayerSpawned(string soldierName, Inventory spawnedInventory)
  1232. {
  1233. if(bool_roundStarted == true && StatsTracker.ContainsKey(soldierName) == true)
  1234. {
  1235. if(StatsTracker[soldierName].PlayerOnServer == false)
  1236. {
  1237. this.StatsTracker[soldierName].Playerjoined = MyDateTime.Now;
  1238. this.StatsTracker[soldierName].PlayerOnServer = true;
  1239. }
  1240. }
  1241. }
  1242. #endregion
  1243. #region IPRoConPluginInterface3
  1244. //
  1245. // IPRoConPluginInterface3
  1246. //
  1247. public override void OnLoadingLevel(string mapFileName, int roundsPlayed, int roundsTotal)
  1248. {
  1249. this.DebugInfo("OnLoadingLevel: " + mapFileName +" Round: " + roundsPlayed + "/" + roundsTotal);
  1250. this.DebugInfo("update sql server");
  1251. this.Nextmapinfo = new CMapstats(MyDateTime.Now,mapFileName,roundsPlayed,roundsTotal,this.m_dTimeOffset);
  1252. new Thread(StartStreaming).Start();
  1253. m_dicPlayers.Clear();
  1254. this.Spamprotection.Reset();
  1255. }
  1256. #endregion
  1257. #region In Game Commands
  1258. public void OnCommandStats(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  1259. {
  1260. if((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  1261. {
  1262. string scope ="";
  1263. string newText = strText.ToUpper();
  1264. newText = newText.Replace("STATS","");
  1265. newText = newText.Replace("RANK","");
  1266. newText = newText.Replace("#","");
  1267. if(newText.Contains("!") == true)
  1268. {
  1269. if(this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  1270. {
  1271. scope = "all";
  1272. }
  1273. else
  1274. {
  1275. scope = "player";
  1276. }
  1277. }
  1278. else
  1279. {
  1280. scope = "player";
  1281. }
  1282. newText = newText.Replace("!","");
  1283. newText = newText.Replace("@","");
  1284. newText = newText.Replace(" ","");
  1285. if(newText.Length > 0)
  1286. {
  1287. string weaponName = newText;
  1288. this.GetWeaponStats(this.FindKeyword(weaponName),strSpeaker,scope);
  1289. }
  1290. else
  1291. {
  1292. this.GetPlayerStats(strSpeaker,0,scope);
  1293. }
  1294. }
  1295. }
  1296. public void OnCommandTop10(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  1297. {
  1298. if((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  1299. {
  1300. string scope ="";
  1301. string newText = strText.ToUpper();
  1302. newText = newText.Replace("TOP10","");
  1303. newText = newText.Replace("#","");
  1304. if(newText.Contains("!") == true)
  1305. {
  1306. if(this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  1307. {
  1308. scope = "all";
  1309. }
  1310. else
  1311. {
  1312. scope = "player";
  1313. }
  1314. }
  1315. else
  1316. {
  1317. scope = "player";
  1318. }
  1319. newText = newText.Replace("!","");
  1320. newText = newText.Replace("@","");
  1321. newText = newText.Replace(" ","");
  1322. if(newText.Length > 0)
  1323. {
  1324. string weaponName = newText;
  1325. this.GetWeaponTop10(this.FindKeyword(weaponName), strSpeaker,2, scope);
  1326. }
  1327. else
  1328. {
  1329. this.GetTop10(strSpeaker,2,scope);
  1330. }
  1331. }
  1332. }
  1333. public void OnCommandDogtags(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  1334. {
  1335. if((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  1336. {
  1337. string scope ="";
  1338. string newText = strText.ToUpper();
  1339. newText = newText.Replace("DOGTAGS","");
  1340. newText = newText.Replace("#","");
  1341. if(newText.Contains("!") == true)
  1342. {
  1343. if(this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  1344. {
  1345. scope = "all";
  1346. }
  1347. else
  1348. {
  1349. scope = "player";
  1350. }
  1351. }
  1352. else
  1353. {
  1354. scope = "player";
  1355. }
  1356. this.GetDogtags(strSpeaker,1,scope);
  1357. }
  1358. }
  1359. public void OnCommandSession(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
  1360. {
  1361. if((this.m_enLogSTATS == enumBoolYesNo.Yes) && (this.Spamprotection.isAllowed(strSpeaker) == true))
  1362. {
  1363. string scope ="";
  1364. string newText = strText.ToUpper();
  1365. newText = newText.Replace("SESSION","");
  1366. newText = newText.Replace("#","");
  1367. if(newText.Contains("!") == true)
  1368. {
  1369. if(this.m_enSendStatsToAll == enumBoolYesNo.Yes)
  1370. {
  1371. scope = "all";
  1372. }
  1373. else
  1374. {
  1375. scope = "player";
  1376. }
  1377. }
  1378. else
  1379. {
  1380. scope = "player";
  1381. }
  1382. this.GetSession(strSpeaker,1,scope);
  1383. }
  1384. }
  1385. #endregion
  1386. #region CChatGUIDStatsLogger Methodes
  1387. private int GetPlayerTeamID(string strSoldierName)
  1388. {
  1389. int iTeamID = 0; // Neutral Team ID
  1390. if (this.m_dicPlayers.ContainsKey(strSoldierName) == true)
  1391. {
  1392. iTeamID = this.m_dicPlayers[strSoldierName].TeamID;
  1393. }
  1394. return iTeamID;
  1395. }
  1396. public void playerLeftServer(CPlayerInfo cpiPlayer)
  1397. {
  1398. if(this.StatsTracker.ContainsKey(cpiPlayer.SoldierName) == true)
  1399. {
  1400. this.StatsTracker[cpiPlayer.SoldierName].Score = cpiPlayer.Score;
  1401. this.StatsTracker[cpiPlayer.SoldierName].TimePlayerleft = MyDateTime.Now;
  1402. this.StatsTracker[cpiPlayer.SoldierName].playerleft();
  1403. //EA-GUID, ClanTag, usw.
  1404. this.StatsTracker[cpiPlayer.SoldierName].EAGuid = cpiPlayer.GUID;
  1405. this.StatsTracker[cpiPlayer.SoldierName].ClanTag = cpiPlayer.ClanTag;
  1406. }
  1407. //ID cache System
  1408. if(this.m_ID_cache.ContainsKey(cpiPlayer.SoldierName) == true)
  1409. {
  1410. this.m_ID_cache[cpiPlayer.SoldierName].PlayeronServer = false;
  1411. }
  1412. //Mapstats
  1413. this.Mapstats.IntplayerleftServer++;
  1414. //Session
  1415. if(this.m_dicSession.ContainsKey(cpiPlayer.SoldierName) == true && this.m_sessionON == enumBoolYesNo.Yes)
  1416. {
  1417. this.m_dicSession.Remove(cpiPlayer.SoldierName);
  1418. }
  1419. }
  1420. public void playerKilled(Kill kKillerVictimDetails)
  1421. {
  1422. string strKillerSoldierName = kKillerVictimDetails.Killer.SoldierName;
  1423. string strVictimSoldierName = kKillerVictimDetails.Victim.SoldierName;
  1424. //TEAMKILL OR SUICID
  1425. if (String.Compare(strKillerSoldierName, strVictimSoldierName) == 0) { // A Suicide
  1426. this.AddSuicideToStats(strKillerSoldierName,kKillerVictimDetails.DamageType);
  1427. }
  1428. else
  1429. {
  1430. if (this.GetPlayerTeamID(strKillerSoldierName) == this.GetPlayerTeamID(strVictimSoldierName))
  1431. { //TeamKill
  1432. this.AddTeamKillToStats(strKillerSoldierName);
  1433. this.AddDeathToStats(strVictimSoldierName,kKillerVictimDetails.DamageType);
  1434. }
  1435. else
  1436. {
  1437. //Regular Kill: Player killed an Enemy
  1438. this.AddKillToStats(strKillerSoldierName,kKillerVictimDetails.DamageType, kKillerVictimDetails.Headshot);
  1439. this.AddDeathToStats(strVictimSoldierName,kKillerVictimDetails.DamageType);
  1440. if(string.Equals(kKillerVictimDetails.DamageType,"KNV-1"))
  1441. { //Dogtagstracking
  1442. CKillerVictim KnifeKill = new CKillerVictim(strKillerSoldierName,strVictimSoldierName);
  1443. if(m_dicKnifeKills.ContainsKey(KnifeKill) == true)
  1444. {
  1445. m_dicKnifeKills[KnifeKill]++;
  1446. }
  1447. else
  1448. {
  1449. m_dicKnifeKills.Add(KnifeKill,1);
  1450. }
  1451. }
  1452. }
  1453. }
  1454. }
  1455. public List<string> SQLquery(string str_selectSQL, int sort)
  1456. {
  1457. this.tablebuilder();
  1458. List<string> query = new List<string>();
  1459. int int_counter = 0;
  1460. double khr = 0;
  1461. double kdr = 0;
  1462. int rank = 0;
  1463. string strRow = "";
  1464. if ((m_strHost != null) || (m_strDatabase != null) || (m_strDBPort != null) || (m_strUserName != null) || (m_strPassword != null))
  1465. {
  1466. try
  1467. {
  1468. this.ODBC_Connection_is_activ = true;
  1469. this.OpenOdbcConnection(1);
  1470. OdbcParameter param = new OdbcParameter();
  1471. if(OdbcCon.State == ConnectionState.Open)
  1472. {
  1473. //Reader
  1474. using(OdbcComm = new System.Data.Odbc.OdbcCommand(str_selectSQL,OdbcCon))
  1475. {
  1476. OdbcDR = OdbcComm.ExecuteReader();
  1477. // i known it is a work around got trouble return an array
  1478. switch(sort)
  1479. {
  1480. case 1:
  1481. while(OdbcDR.Read())
  1482. {
  1483. //SELECT SoldierName,playerScore, playerKills, playerDeaths, playerSuicide, playerTKs, rank, allrank ,playerPlaytime, playerHeadshots, playerRounds, killstreak, deathstreak
  1484. // 0 1 2 3 4 5 6 7 8 9 10 11 12
  1485. query = new List<string>(m_lstPlayerStatsMessage);
  1486. query = this.ListReplace(query,"%playerName%",OdbcDR[0].ToString());
  1487. query = this.ListReplace(query,"%playerScore%",OdbcDR[1].ToString());
  1488. query = this.ListReplace(query,"%playerKills%",OdbcDR[2].ToString());
  1489. query = this.ListReplace(query,"%playerDeaths%",OdbcDR[3].ToString());
  1490. query = this.ListReplace(query,"%playerSuicide%",OdbcDR[4].ToString());
  1491. query = this.ListReplace(query,"%playerTKs%",OdbcDR[5].ToString());
  1492. query = this.ListReplace(query,"%playerRank%",OdbcDR[6].ToString());
  1493. query = this.ListReplace(query,"%allRanks%",OdbcDR[7].ToString());
  1494. query = this.ListReplace(query,"%playerHeadshots%",OdbcDR[9].ToString());
  1495. query = this.ListReplace(query,"%rounds%",OdbcDR[10].ToString());
  1496. query = this.ListReplace(query,"%killstreak%",OdbcDR[11].ToString());
  1497. query = this.ListReplace(query,"%deathstreak%",OdbcDR[12].ToString());
  1498. //KDR
  1499. if(Convert.ToInt32(OdbcDR[3]) !=0)
  1500. {
  1501. kdr = Convert.ToDouble(OdbcDR[2])/Convert.ToDouble(OdbcDR[3]);
  1502. kdr = Math.Round(kdr,2);
  1503. query = this.ListReplace(query,"%playerKDR%",kdr.ToString());
  1504. }
  1505. else
  1506. {
  1507. kdr = Convert.ToDouble(OdbcDR[2]);
  1508. query = this.ListReplace(query,"%playerKDR%",kdr.ToString());
  1509. }
  1510. //Playtime
  1511. int playtime_sek = Convert.ToInt32(OdbcDR[8]) % 3600;
  1512. int hours = (Convert.ToInt32(OdbcDR[8]) - playtime_sek)/ 3600;
  1513. int sekunds = playtime_sek % 60;
  1514. int minutes = (playtime_sek - sekunds) / 60;
  1515. query = this.ListReplace(query,"%playerPlaytime%",hours.ToString() + ":"+ minutes.ToString() + ":"+ sekunds.ToString());
  1516. //SPM
  1517. double SPM;
  1518. if(Convert.ToDouble(OdbcDR[8]) !=0)
  1519. {
  1520. SPM =(Convert.ToDouble(OdbcDR[1])/(Convert.ToDouble(OdbcDR[8])/60));
  1521. SPM = Math.Round(SPM,2);
  1522. query = this.ListReplace(query,"%SPM%",SPM.ToString());
  1523. }
  1524. else
  1525. {
  1526. query = this.ListReplace(query,"%SPM%","0");
  1527. }
  1528. }
  1529. break;
  1530. case 2:
  1531. query = new List<string>();
  1532. if(m_enRankingByScore == enumBoolYesNo.Yes)
  1533. {
  1534. query.Add("Top 10 Player of the "+this.serverName+" Server");
  1535. }
  1536. else
  1537. {
  1538. query.Add("Top 10 Killers of the "+this.serverName+" Server");
  1539. }
  1540. double kdr1;
  1541. while(OdbcDR.Read())
  1542. {
  1543. if(Convert.ToDouble(OdbcDR[2]) != 0)
  1544. {
  1545. kdr1 = Convert.ToDouble(OdbcDR[2])/Convert.ToDouble(OdbcDR[3]);
  1546. kdr1 = Math.Round(kdr1,2);
  1547. }
  1548. else
  1549. {
  1550. kdr1 = Convert.ToDouble(OdbcDR[2]);
  1551. }
  1552. rank = rank + 1;
  1553. if(m_enRankingByScore == enumBoolYesNo.Yes)
  1554. {
  1555. query.Add(rank.ToString()+". "+OdbcDR[0]+" Score: "+OdbcDR[1]+" "+OdbcDR[2]+" Kills "+OdbcDR[4]+" Headshots "+OdbcDR[3]+" Deaths KDR: "+kdr1.ToString());
  1556. }
  1557. else
  1558. {
  1559. query.Add(rank.ToString()+". "+OdbcDR[0]+" "+OdbcDR[2]+" Kills "+OdbcDR[4]+" Headshots "+OdbcDR[3]+" Deaths KDR: "+kdr1.ToString());
  1560. }
  1561. }
  1562. break;
  1563. case 3:
  1564. query = new List<string>();
  1565. query.Add("0");
  1566. while(OdbcDR.Read())
  1567. {
  1568. if(OdbcDR[0].ToString() != null)
  1569. {
  1570. query[0] = OdbcDR[0].ToString();
  1571. }
  1572. else
  1573. {
  1574. query[0] = "0";
  1575. }
  1576. }
  1577. break;
  1578. case 4:
  1579. while(OdbcDR.Read())
  1580. {
  1581. query = new List<string>(this.m_lstWeaponstatsMsg);
  1582. if(OdbcDR[0].ToString() != null || OdbcDR[1].ToString() != null || OdbcDR[2].ToString() != null)
  1583. {
  1584. query = this.ListReplace(query,"%playerKills%",OdbcDR[0].ToString());
  1585. query = this.ListReplace(query,"%playerHeadshots%",OdbcDR[1].ToString());
  1586. query = this.ListReplace(query,"%playerDeaths%",OdbcDR[2].ToString());
  1587. query = this.ListReplace(query,"%playerRank%",OdbcDR[3].ToString());
  1588. query = this.ListReplace(query,"%allRanks%",OdbcDR[4].ToString());
  1589. if(Convert.ToDouble(OdbcDR[0]) != 0)
  1590. {
  1591. khr = Convert.ToDouble(OdbcDR[1])/Convert.ToDouble(OdbcDR[0]);
  1592. khr = Math.Round(khr,2);
  1593. khr = khr*100;
  1594. }
  1595. else
  1596. {
  1597. khr = 0;
  1598. }
  1599. if(Convert.ToDouble(OdbcDR[2]) != 0)
  1600. {
  1601. kdr = Convert.ToDouble(OdbcDR[0])/Convert.ToDouble(OdbcDR[2]);
  1602. kdr = Math.Round(kdr,2);
  1603. }
  1604. else
  1605. {
  1606. kdr = Convert.ToDouble(OdbcDR[2]);
  1607. }
  1608. query = this.ListReplace(query,"%playerKHR%",khr.ToString());
  1609. query = this.ListReplace(query,"%playerKDR%",kdr.ToString());
  1610. }
  1611. else
  1612. {
  1613. query.Clear();
  1614. }
  1615. }
  1616. break;
  1617. case 5:
  1618. query = new List<string>();
  1619. query.Add("Top 10 Killers with %Weapon% of the "+this.serverName+" Server");
  1620. while(OdbcDR.Read())
  1621. {
  1622. if(Convert.ToDouble(OdbcDR[3]) != 0)
  1623. {
  1624. kdr = Convert.ToDouble(OdbcDR[1])/Convert.ToDouble(OdbcDR[3]);
  1625. kdr = Math.Round(kdr,2);
  1626. }
  1627. else
  1628. {
  1629. kdr = Convert.ToDouble(OdbcDR[1]);
  1630. }
  1631. if(Convert.ToDouble(OdbcDR[1]) != 0)
  1632. {
  1633. khr = Convert.ToDouble(OdbcDR[2])/Convert.ToDouble(OdbcDR[1]);
  1634. khr = Math.Round(khr,4);
  1635. khr = khr*100;
  1636. }
  1637. else
  1638. {
  1639. khr = 0;
  1640. }
  1641. rank = rank +1;
  1642. query.Add(rank.ToString()+". "+OdbcDR[0]+" "+OdbcDR[1]+" Kills "+OdbcDR[2]+" |Headshots "+OdbcDR[3]+" killed by this Weapon |Headshotrate: "+khr.ToString());
  1643. }
  1644. break;
  1645. case 6:
  1646. query = new List<string>();
  1647. query.Add("Your favorite Victims:");
  1648. while(OdbcDR.Read())
  1649. {
  1650. query.Add(" "+OdbcDR[1]+"x "+OdbcDR[0]);
  1651. }
  1652. break;
  1653. case 7:
  1654. query = new List<string>();
  1655. query.Add("Your worst Enemies:");
  1656. while(OdbcDR.Read())
  1657. {
  1658. query.Add(" "+OdbcDR[1]+"x "+OdbcDR[0]);
  1659. }
  1660. break;
  1661. case 8:
  1662. query = new List<string>();
  1663. query.Add("0");
  1664. while(OdbcDR.Read())
  1665. {
  1666. query = new List<string>();
  1667. query.Add(OdbcDR[0].ToString());
  1668. }
  1669. break;
  1670. //Tablecheck
  1671. case 9:
  1672. query = new List<string>();
  1673. while(OdbcDR.Read())
  1674. {
  1675. query.Add(OdbcDR[0].ToString());
  1676. }
  1677. break;
  1678. case 10:
  1679. query = new List<string>();
  1680. query.Add("0");
  1681. while(OdbcDR.Read())
  1682. {
  1683. query = new List<string>();
  1684. query.Add(OdbcDR[0].ToString());
  1685. query.Add(OdbcDR[1].ToString());
  1686. query.Add(OdbcDR[2].ToString());
  1687. query.Add(OdbcDR[3].ToString());
  1688. query.Add(OdbcDR[4].ToString());
  1689. query.Add(OdbcDR[5].ToString());
  1690. }
  1691. break;
  1692. default:
  1693. query = new List<string>();
  1694. query.Add("Error: No data");
  1695. break;
  1696. }
  1697. }
  1698. }
  1699. }
  1700. catch(OdbcException oe)
  1701. {
  1702. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in SQLQuery in Case "+ sort +": ");
  1703. this.DisplayOdbcErrorCollection(oe);
  1704. }
  1705. catch (Exception c)
  1706. {
  1707. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in SQLQuery in Case "+ sort +": " + c);
  1708. if (OdbcConn.State == ConnectionState.Open)
  1709. {
  1710. OdbcCon.Close();
  1711. }
  1712. this.ODBC_Connection_is_activ = false;
  1713. }
  1714. }
  1715. this.ODBC_Connection_is_activ = false;
  1716. return query;
  1717. }
  1718. public int GetID(string strSoldierName)
  1719. {
  1720. string CHECK ="SELECT `PlayerID` FROM " + this.tbl_playerdata + @" WHERE SoldierName ='"+ strSoldierName +"'";
  1721. int playerID = 0;
  1722. List<string> result;
  1723. try
  1724. {
  1725. if(this.m_ID_cache.ContainsKey(strSoldierName))
  1726. {
  1727. if(this.m_ID_cache[strSoldierName].Id >= 1)
  1728. {
  1729. playerID = this.m_ID_cache[strSoldierName].Id;
  1730. //this.DebugInfo("Status ID-Cache: used ID from cache "+ playerID);
  1731. }
  1732. else
  1733. {
  1734. result = new List<string>(this.SQLquery(CHECK,3));
  1735. if(result != null)
  1736. {
  1737. foreach(string entry in result)
  1738. {
  1739. playerID = Convert.ToInt32(entry);
  1740. }
  1741. }
  1742. else
  1743. {
  1744. playerID = -1;
  1745. }
  1746. //this.DebugInfo("Received ID from Database ID: "+ playerID);
  1747. }
  1748. }
  1749. else
  1750. {
  1751. result = new List<string>(this.SQLquery(CHECK,3));
  1752. if(result != null)
  1753. {
  1754. playerID = Convert.ToInt32(result[0]);
  1755. if(playerID >= 1)
  1756. {
  1757. //this.DebugInfo("Received ID from Database ID: "+ playerID+ "Added to cache");
  1758. C_ID_Cache AddID = new C_ID_Cache(playerID,true);
  1759. this.m_ID_cache.Add(strSoldierName,AddID);
  1760. }
  1761. }
  1762. else
  1763. {
  1764. playerID = 0;
  1765. }
  1766. }
  1767. }
  1768. catch (Exception c)
  1769. {
  1770. this.ExecuteCommand("procon.protected.pluginconsole.write", "Error GetID: "+c);
  1771. playerID = -1;
  1772. }
  1773. return playerID;
  1774. }
  1775. // Updates database with player stats and chatlogs
  1776. public void StartStreaming()
  1777. {
  1778. //Make a copy of Statstracker to prevent unwanted errors
  1779. Dictionary<string, CStats> StatsTrackerCopy = new Dictionary<string, CStats>(this.StatsTracker);
  1780. int icharindex;
  1781. int int_id = 0;
  1782. //Clearing the old Dictionary
  1783. StatsTracker.Clear();
  1784. if (isStreaming)
  1785. {
  1786. // Uploads chat logs and Stats for round to database
  1787. if (ChatLog.Count > 0 || this.m_enLogSTATS == enumBoolYesNo.Yes)
  1788. {
  1789. this.tablebuilder(); //Build the tables if not exists
  1790. if ((m_strHost != null) && (m_strDatabase != null) && (m_strDBPort != null) && (m_strUserName != null) && (m_strPassword != null))
  1791. {
  1792. try
  1793. {
  1794. this.ODBC_Connection_is_activ = true;
  1795. OdbcParameter param = new OdbcParameter();
  1796. this.OpenOdbcConnection(2);
  1797. if(ChatLog.Count > 0 && OdbcConn.State == ConnectionState.Open)
  1798. {
  1799. string ChatSQL = @"INSERT INTO "+ this.tbl_chatlog + @" (logDate, logServer, logSubset, logSoldierName, logMessage)
  1800. VALUES ";
  1801. lock(ChatLog)
  1802. {
  1803. foreach (CLogger log in ChatLog)
  1804. {
  1805. ChatSQL = string.Concat(ChatSQL,"(?,?,?,?,?),");
  1806. }
  1807. ChatSQL = ChatSQL.Remove(ChatSQL.LastIndexOf(","));
  1808. using (OdbcCommand OdbcCom = new OdbcCommand(ChatSQL, OdbcConn))
  1809. {
  1810. foreach (CLogger log in ChatLog)
  1811. {
  1812. OdbcCom.Parameters.AddWithValue("@pr", log.Time);
  1813. OdbcCom.Parameters.AddWithValue("@pr", this.serverName);
  1814. OdbcCom.Parameters.AddWithValue("@pr", log.Subset);
  1815. OdbcCom.Parameters.AddWithValue("@pr", log.Name);
  1816. OdbcCom.Parameters.AddWithValue("@pr", log.Message);
  1817. }
  1818. OdbcCom.ExecuteNonQuery();
  1819. }
  1820. ChatLog.Clear();
  1821. }
  1822. }
  1823. if( this.m_mapstatsON == enumBoolYesNo.Yes && OdbcConn.State == ConnectionState.Open)
  1824. {
  1825. this.Mapstats.calcMaxMinAvgPlayers();
  1826. string MapSQL = @"INSERT INTO "+ tbl_mapstats + @" (TimeMapLoad, TimeRoundStarted, TimeRoundEnd, MapName, Gamemode, Roundcount, NumberofRounds, MinPlayers, AvgPlayers, MaxPlayers, PlayersJoinedServer, PlayersLeftServer)
  1827. VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
  1828. using (OdbcCommand OdbcCom = new OdbcCommand(MapSQL, OdbcConn))
  1829. {
  1830. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.TimeMaploaded);
  1831. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.TimeMapStarted);
  1832. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.TimeRoundEnd);
  1833. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.StrMapname);
  1834. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.StrGamemode);
  1835. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.IntRound);
  1836. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.IntNumberOfRounds);
  1837. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.IntMinPlayers);
  1838. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.DoubleAvgPlayers);
  1839. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.IntMaxPlayers);
  1840. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.IntplayerjoinedServer);
  1841. OdbcCom.Parameters.AddWithValue("@pr", this.Mapstats.IntplayerleftServer);
  1842. OdbcCom.ExecuteNonQuery();
  1843. }
  1844. }
  1845. if (this.m_enLogSTATS == enumBoolYesNo.Yes && OdbcConn.State == ConnectionState.Open)
  1846. {
  1847. OdbcTrans = OdbcConn.BeginTransaction();
  1848. foreach(KeyValuePair<string, CStats> kvp in StatsTrackerCopy)
  1849. {
  1850. if(kvp.Key.Length > 0 && StatsTrackerCopy[kvp.Key].Guid.Length > 0)
  1851. {
  1852. int_id = GetID(kvp.Key);//Call of the ID Cache
  1853. if(int_id >= 1)
  1854. {
  1855. string UpdatedataSQL ="";
  1856. if(this.m_UpdateEA_GUID == enumBoolYesNo.Yes)
  1857. {
  1858. UpdatedataSQL = @"UPDATE " + tbl_playerdata + @" SET ClanTag = ?, EAGUID = ?, IP_Address = ?, CountryCode = ? WHERE PlayerID = ?";
  1859. }
  1860. else
  1861. {
  1862. UpdatedataSQL = @"UPDATE " + tbl_playerdata + @" SET ClanTag = ?, IP_Address = ?, CountryCode = ? WHERE PlayerID = ?";
  1863. }
  1864. using (OdbcCommand OdbcCom = new OdbcCommand(UpdatedataSQL, OdbcConn, OdbcTrans))
  1865. {
  1866. //Insert
  1867. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].ClanTag);
  1868. if(this.m_UpdateEA_GUID == enumBoolYesNo.Yes)
  1869. {
  1870. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].EAGuid);
  1871. }
  1872. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].IP);
  1873. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].PlayerCountryCode);
  1874. OdbcCom.Parameters.AddWithValue("@pr", int_id);
  1875. OdbcCom.ExecuteNonQuery();
  1876. }
  1877. if(this.m_UpdatePB_GUID == enumBoolYesNo.Yes)
  1878. {
  1879. UpdatedataSQL = @"UPDATE " + tbl_playerdata + @" SET GUID = ? WHERE PlayerID = ? AND GUID = NULL";
  1880. using (OdbcCommand OdbcCom = new OdbcCommand(UpdatedataSQL, OdbcConn, OdbcTrans))
  1881. {
  1882. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Guid);
  1883. OdbcCom.Parameters.AddWithValue("@pr", int_id);
  1884. OdbcCom.ExecuteNonQuery();
  1885. }
  1886. }
  1887. }
  1888. else if(int_id != -1)
  1889. {
  1890. string InsertdataSQL = @"INSERT INTO " + tbl_playerdata + @" (ClanTag, SoldierName, GUID, EAGUID, IP_Address, CountryCode) VALUES(?,?,?,?,?,?)";
  1891. using (OdbcCommand OdbcCom = new OdbcCommand(InsertdataSQL, OdbcConn, OdbcTrans))
  1892. {
  1893. //Insert
  1894. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].ClanTag);
  1895. OdbcCom.Parameters.AddWithValue("@pr", kvp.Key);
  1896. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Guid);
  1897. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].EAGuid);
  1898. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].IP);
  1899. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].PlayerCountryCode);
  1900. OdbcCom.ExecuteNonQuery();
  1901. }
  1902. }
  1903. }
  1904. }
  1905. OdbcTrans.Commit();
  1906. //Start of the Transaction
  1907. OdbcTrans = OdbcConn.BeginTransaction();
  1908. foreach(KeyValuePair<string, CStats> kvp in StatsTrackerCopy)
  1909. {
  1910. Dictionary<string, CStats.CUsedWeapon> tempdic = new Dictionary<string, CStats.CUsedWeapon>();
  1911. tempdic = StatsTrackerCopy[kvp.Key].getWeaponKills();
  1912. int_id = GetID(kvp.Key);//Call of the ID Cache
  1913. if(kvp.Key.Length > 0 && StatsTrackerCopy[kvp.Key].Guid.Length > 0 && int_id > 0)
  1914. {
  1915. string playerstatsSQL= @"INSERT INTO " + this.tbl_playerstats + @"(StatsID, playerScore, playerKills, playerHeadshots, playerDeaths, playerSuicide, playerTKs, playerPlaytime, playerRounds, FirstSeenOnServer, LastSeenOnServer, Killstreak, Deathstreak)
  1916. VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE playerScore = playerScore + ?,
  1917. playerKills = playerKills + ?,
  1918. playerHeadshots = playerHeadshots + ?,
  1919. playerDeaths = playerDeaths + ?,
  1920. playerSuicide = playerSuicide + ?,
  1921. playerTKs = playerTKs + ?,
  1922. playerPlaytime = playerPlaytime + ?,
  1923. playerRounds = playerRounds + ?,
  1924. LastSeenOnServer = ?,
  1925. Killstreak = GREATEST(Killstreak,?),
  1926. Deathstreak = GREATEST(Deathstreak, ?)";
  1927. using (OdbcCommand OdbcCom = new OdbcCommand(playerstatsSQL, OdbcConn, OdbcTrans))
  1928. {
  1929. //Insert
  1930. OdbcCom.Parameters.AddWithValue("@pr", int_id);
  1931. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TotalScore);
  1932. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Kills);
  1933. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Headshots);
  1934. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Deaths);
  1935. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Suicides);
  1936. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Teamkills);
  1937. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TotalPlaytime);
  1938. OdbcCom.Parameters.AddWithValue("@pr", 1);
  1939. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TimePlayerjoined);
  1940. if(StatsTrackerCopy[kvp.Key].TimePlayerleft != DateTime.MinValue)
  1941. {
  1942. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TimePlayerleft);
  1943. }
  1944. else
  1945. {
  1946. OdbcCom.Parameters.AddWithValue("@pr",MyDateTime.Now);
  1947. }
  1948. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Killstreak);
  1949. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Deathstreak);
  1950. //Update
  1951. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TotalScore);
  1952. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Kills);
  1953. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Headshots);
  1954. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Deaths);
  1955. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Suicides);
  1956. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Teamkills);
  1957. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TotalPlaytime);
  1958. OdbcCom.Parameters.AddWithValue("@pr", 1);
  1959. if(StatsTrackerCopy[kvp.Key].TimePlayerleft != DateTime.MinValue)
  1960. {
  1961. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].TimePlayerleft);
  1962. }
  1963. else
  1964. {
  1965. OdbcCom.Parameters.AddWithValue("@pr",MyDateTime.Now);
  1966. }
  1967. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Killstreak);
  1968. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].Deathstreak);
  1969. OdbcCom.ExecuteNonQuery();
  1970. }
  1971. string InsertSQL = "INSERT INTO " + this.tbl_weaponstats + @" (WeaponStatsID";
  1972. string ValuesSQL = "VALUES(?";
  1973. string UpdateSQL= "ON DUPLICATE KEY UPDATE UNKNOWN_hs = UNKNOWN_hs + 0";
  1974. if(this.m_weaponstatsON == enumBoolYesNo.Yes)
  1975. {
  1976. //Build Query for Weaponstats
  1977. if(tempdic !=null)
  1978. {
  1979. foreach(KeyValuePair<string, CStats.CUsedWeapon> entry in tempdic)
  1980. {
  1981. if(tempdic[entry.Key].Kills != 0)
  1982. {
  1983. InsertSQL = String.Concat(InsertSQL,", `", entry.Key, "_kills`");
  1984. ValuesSQL = String.Concat(ValuesSQL, ", " , tempdic[entry.Key].Kills);
  1985. }
  1986. if(tempdic[entry.Key].Headshots != 0)
  1987. {
  1988. InsertSQL = String.Concat(InsertSQL,", `", entry.Key, "_hs`");
  1989. ValuesSQL = String.Concat(ValuesSQL, ", " , tempdic[entry.Key].Headshots);
  1990. }
  1991. if(tempdic[entry.Key].Deaths != 0)
  1992. {
  1993. InsertSQL = String.Concat(InsertSQL,", `", entry.Key, "_deaths`");
  1994. ValuesSQL = String.Concat(ValuesSQL, ", " , tempdic[entry.Key].Deaths);
  1995. }
  1996. }
  1997. }
  1998. if(tempdic !=null)
  1999. {
  2000. foreach(KeyValuePair<string, CStats.CUsedWeapon> entry in tempdic)
  2001. {
  2002. if(tempdic[entry.Key].Kills != 0)
  2003. {
  2004. UpdateSQL = String.Concat(UpdateSQL," `",entry.Key, "_kills` = `",entry.Key,"_kills` + ",tempdic[entry.Key].Kills," ,");
  2005. UpdateSQL = UpdateSQL.Replace("UNKNOWN_hs = UNKNOWN_hs + 0","");
  2006. }
  2007. if(tempdic[entry.Key].Headshots != 0)
  2008. {
  2009. UpdateSQL = String.Concat(UpdateSQL," `",entry.Key, "_hs` = `",entry.Key,"_hs` + ",tempdic[entry.Key].Headshots," ,");
  2010. UpdateSQL = UpdateSQL.Replace("UNKNOWN_hs = UNKNOWN_hs + 0","");
  2011. }
  2012. if(tempdic[entry.Key].Deaths != 0)
  2013. {
  2014. UpdateSQL = String.Concat(UpdateSQL," `",entry.Key, "_deaths` = `",entry.Key,"_deaths` + ",tempdic[entry.Key].Deaths," ,");
  2015. UpdateSQL = UpdateSQL.Replace("UNKNOWN_hs = UNKNOWN_hs + 0","");
  2016. }
  2017. }
  2018. }
  2019. int charindex = UpdateSQL.LastIndexOf(",");
  2020. if(charindex > 0)
  2021. {
  2022. UpdateSQL = UpdateSQL.Remove(charindex);
  2023. }
  2024. InsertSQL = String.Concat(InsertSQL,") ",ValuesSQL,") ",UpdateSQL);
  2025. using (OdbcCommand OdbcCom = new OdbcCommand(InsertSQL, OdbcConn, OdbcTrans))
  2026. {
  2027. OdbcCom.Parameters.AddWithValue("@pr", int_id);
  2028. OdbcCom.ExecuteNonQuery();
  2029. }
  2030. }
  2031. string sqlBfbcs = "INSERT INTO " + tbl_bfbcs + @" (bfbcsID, Rank, Kills, Deaths, Score, Elo, Level, Time, LastUpdate) VALUES (?,?,?,?,?,?,?,?,?)
  2032. ON DUPLICATE KEY UPDATE Rank = ?, Kills = ?, Deaths = ?, Score = ?, Elo = ?, Level = ?, Time = ?, LastUpdate = ?";
  2033. if(StatsTrackerCopy[kvp.Key].BFBCS_Stats.Rank > 0 && StatsTrackerCopy[kvp.Key].BFBCS_Stats.NoUpdate == false)
  2034. using (OdbcCommand OdbcCom = new OdbcCommand(sqlBfbcs, OdbcConn, OdbcTrans))
  2035. {
  2036. OdbcCom.Parameters.AddWithValue("@pr", int_id);
  2037. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Rank);
  2038. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Kills);
  2039. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Deaths);
  2040. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Score);
  2041. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Elo);
  2042. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Skilllevel);
  2043. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Time);
  2044. OdbcCom.Parameters.AddWithValue("@pr", MyDateTime.Now);
  2045. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Rank);
  2046. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Kills);
  2047. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Deaths);
  2048. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Score);
  2049. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Elo);
  2050. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Skilllevel);
  2051. OdbcCom.Parameters.AddWithValue("@pr", StatsTrackerCopy[kvp.Key].BFBCS_Stats.Time);
  2052. OdbcCom.Parameters.AddWithValue("@pr", MyDateTime.Now);
  2053. OdbcCom.ExecuteNonQuery();
  2054. }
  2055. }
  2056. }
  2057. string KnifeSQL = "";
  2058. foreach(KeyValuePair<CKillerVictim, int> kvp in m_dicKnifeKills)
  2059. {
  2060. int killerID = this.GetID(kvp.Key.Killer);
  2061. int victimID = this.GetID(kvp.Key.Victim);
  2062. if( killerID > 0 && victimID > 0)
  2063. {
  2064. KnifeSQL = "INSERT INTO " + this.tbl_dogtags + @"( KillerID, VictimID, Count) VALUES(?,?,?)
  2065. ON DUPLICATE KEY UPDATE Count = Count + ?";
  2066. using (OdbcCommand OdbcCom = new OdbcCommand(KnifeSQL, OdbcConn, OdbcTrans))
  2067. {
  2068. OdbcCom.Parameters.AddWithValue("@pr",killerID);
  2069. OdbcCom.Parameters.AddWithValue("@pr",victimID);
  2070. OdbcCom.Parameters.AddWithValue("@pr",m_dicKnifeKills[kvp.Key]);
  2071. OdbcCom.Parameters.AddWithValue("@pr",m_dicKnifeKills[kvp.Key]);
  2072. OdbcCom.ExecuteNonQuery();
  2073. }
  2074. }
  2075. }
  2076. //Commit the Transaction for the Playerstats
  2077. OdbcTrans.Commit();
  2078. StatsTrackerCopy.Clear();
  2079. this.m_dicKnifeKills.Clear();
  2080. List<string> leftplayerlist = new List<string>();
  2081. foreach(KeyValuePair<string,C_ID_Cache> kvp in this.m_ID_cache)
  2082. {
  2083. if(this.m_ID_cache[kvp.Key].PlayeronServer == false)
  2084. {
  2085. leftplayerlist.Add(kvp.Key);
  2086. }
  2087. // Because so playerleft event seems not been reported by the server
  2088. this.m_ID_cache[kvp.Key].PlayeronServer = false;
  2089. }
  2090. foreach(string player in leftplayerlist)
  2091. {
  2092. this.m_ID_cache.Remove(player);
  2093. //this.DebugInfo("Removed " + player);
  2094. }
  2095. this.DebugInfo("Status ID-Cache: "+m_ID_cache.Count+" ID's in cache");
  2096. if(this.m_ID_cache.Count > 300)
  2097. {
  2098. this.ExecuteCommand("procon.protected.pluginconsole.write","Forced Cache clear due the Nummber of cached IDs reached over 300 entry(overflowProtection)");
  2099. }
  2100. }
  2101. else
  2102. {
  2103. StatsTracker.Clear();
  2104. }
  2105. this.ODBC_Connection_is_activ = false;
  2106. }
  2107. catch(OdbcException oe)
  2108. {
  2109. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in Startstreaming: ");
  2110. this.DisplayOdbcErrorCollection(oe);
  2111. }
  2112. catch (Exception c)
  2113. {
  2114. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in Startstreaming: " + c);
  2115. OdbcTrans.Rollback();
  2116. this.m_ID_cache.Clear();
  2117. this.m_dicKnifeKills.Clear();
  2118. }
  2119. finally
  2120. {
  2121. this.Mapstats = this.Nextmapinfo;
  2122. this.ODBC_Connection_is_activ = false;
  2123. this.CloseOdbcConnection(1);
  2124. this.CloseOdbcConnection(2);
  2125. }
  2126. }
  2127. else
  2128. {
  2129. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Streaming cancelled. Please enter all database information");
  2130. }
  2131. }
  2132. }
  2133. }
  2134. public void WelcomeStats(string strSpeaker)
  2135. {
  2136. if(this.m_enWelcomeStats == enumBoolYesNo.Yes)
  2137. {
  2138. if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  2139. {
  2140. string SQL ="";
  2141. string strMSG ="";
  2142. int sort =0;
  2143. //Statsquery with KDR
  2144. //Rankquery
  2145. if(m_enRankingByScore == enumBoolYesNo.Yes)
  2146. {
  2147. SQL =@"SELECT a.SoldierName,y.playerScore, y.playerKills, y.playerDeaths, y.playerSuicide, y.playerTKs, y.rank, y.allrank ,y.playerPlaytime, y.playerHeadshots, y.playerRounds, y.Killstreak, y.Deathstreak
  2148. FROM (SELECT(@num := @num+1) rank, (SELECT count(*)
  2149. FROM "+ this.tbl_playerstats + @") allrank, StatsID, b.playerScore, b.playerKills, b.playerDeaths, b.playerSuicide, b.playerTKs, b.playerPlaytime, b.playerHeadshots, b.playerRounds, b.Killstreak, b.Deathstreak
  2150. FROM " + this.tbl_playerstats + @" b , (SELECT @num := 0) x
  2151. ORDER BY playerScore DESC) y
  2152. INNER JOIN " + tbl_playerdata + @" a ON a.PlayerID = y.StatsID
  2153. WHERE SoldierName ='"+strSpeaker+"'";
  2154. }
  2155. else
  2156. {
  2157. SQL =@"SELECT a.SoldierName,y.playerScore, y.playerKills, y.playerDeaths, y.playerSuicide, y.playerTKs, y.rank, y.allrank ,y.playerPlaytime, y.playerHeadshots, y.playerRounds, y.Killstreak, y.Deathstreak
  2158. FROM (SELECT(@num := @num+1) rank, (SELECT count(*)
  2159. FROM " + this.tbl_playerstats + @") allrank, StatsID, b.playerScore, b.playerKills, b.playerDeaths, b.playerSuicide, b.playerTKs, b.playerPlaytime, b.playerHeadshots, b.playerRounds, b.Killstreak, b.Deathstreak
  2160. FROM " + this.tbl_playerstats + @" b , (SELECT @num := 0) x
  2161. ORDER BY playerKills DESC, playerDeaths ASC) y
  2162. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = y.StatsID
  2163. WHERE SoldierName ='"+strSpeaker+"'";
  2164. }
  2165. sort = 1;
  2166. List<string> result = new List<string>(this.SQLquery(SQL,sort));
  2167. this.CloseOdbcConnection(1);
  2168. if(result.Count > 0)
  2169. {
  2170. strMSG = m_strPlayerWelcomeMsg;
  2171. strMSG = strMSG.Replace("%serverName%",this.serverName);
  2172. strMSG = strMSG.Replace("%playerName%",strSpeaker);
  2173. this.CheckMessageLength(strMSG);
  2174. if(m_enYellWelcomeMSG == enumBoolYesNo.Yes)
  2175. {
  2176. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", int_welcomeStatsDelay.ToString(), "1", "1", "procon.protected.send", "admin.yell", strMSG,this.m_iDisplayTime.ToString(),"player", strSpeaker);
  2177. }
  2178. else
  2179. {
  2180. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", int_welcomeStatsDelay.ToString(), "1", "1", "procon.protected.send", "admin.say", strMSG, "player", strSpeaker);
  2181. }
  2182. foreach(string line in result)
  2183. {
  2184. this.CheckMessageLength(line);
  2185. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", int_welcomeStatsDelay.ToString(), "1", "1", "procon.protected.send", "admin.say", line, "player", strSpeaker);
  2186. }
  2187. }
  2188. else
  2189. { strMSG = m_strNewPlayerWelcomeMsg;
  2190. strMSG = strMSG.Replace("%serverName%",this.serverName);
  2191. strMSG = strMSG.Replace("%playerName%",strSpeaker);
  2192. this.CheckMessageLength(strMSG);
  2193. if(m_enYellWelcomeMSG == enumBoolYesNo.Yes)
  2194. {
  2195. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", int_welcomeStatsDelay.ToString(), "1", "1", "procon.protected.send" , "admin.yell", strMSG, this.m_iDisplayTime.ToString(),"player", strSpeaker);
  2196. }
  2197. else
  2198. {
  2199. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", int_welcomeStatsDelay.ToString(), "1", "1", "procon.protected.send", "admin.say", strMSG,"player", strSpeaker);
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. public void GetPlayerStats(string strSpeaker,int delay, string scope)
  2206. {
  2207. if (this.m_enLogSTATS == enumBoolYesNo.Yes)
  2208. {
  2209. string SQL ="";
  2210. int sort =0;
  2211. //Statsquery with KDR
  2212. //Rankquery
  2213. if(m_enRankingByScore == enumBoolYesNo.Yes)
  2214. {
  2215. SQL =@"SELECT a.SoldierName,y.playerScore, y.playerKills, y.playerDeaths, y.playerSuicide, y.playerTKs, y.rank, y.allrank ,y.playerPlaytime, y.playerHeadshots, y.playerRounds, y.Killstreak, y.Deathstreak
  2216. FROM (SELECT(@num := @num+1) rank, (SELECT count(*)
  2217. FROM "+ this.tbl_playerstats + @") allrank, StatsID, b.playerScore, b.playerKills, b.playerDeaths, b.playerSuicide, b.playerTKs, b.playerPlaytime, b.playerHeadshots, b.playerRounds, b.Killstreak, b.Deathstreak
  2218. FROM " + this.tbl_playerstats+ @" b , (SELECT @num := 0) x
  2219. ORDER BY playerScore DESC) y
  2220. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = y.StatsID
  2221. WHERE SoldierName ='"+strSpeaker+"'";
  2222. }
  2223. else
  2224. {
  2225. SQL =@"SELECT a.SoldierName,y.playerScore, y.playerKills, y.playerDeaths, y.playerSuicide, y.playerTKs, y.rank, y.allrank ,y.playerPlaytime, y.playerHeadshots, y.playerRounds, y.Killstreak, y.Deathstreak
  2226. FROM (SELECT(@num := @num+1) rank, (SELECT count(*)
  2227. FROM " + this.tbl_playerstats + @") allrank, StatsID, b.playerScore, b.playerKills, b.playerDeaths, b.playerSuicide, b.playerTKs, b.playerPlaytime, b.playerHeadshots, b.playerRounds, b.Killstreak, b.Deathstreak
  2228. FROM " + this.tbl_playerstats + @" b , (SELECT @num := 0) x
  2229. ORDER BY playerKills DESC, playerDeaths ASC) y
  2230. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = y.StatsID
  2231. WHERE SoldierName ='"+strSpeaker+"'";
  2232. }
  2233. sort = 1;
  2234. List<string> result = new List<string>(this.SQLquery(SQL,sort));
  2235. this.CloseOdbcConnection(1);
  2236. //if(result[0].Equals("0") == false)
  2237. if(result.Count != 0)
  2238. {
  2239. foreach(string line in result)
  2240. {
  2241. this.CheckMessageLength(line);
  2242. if(String.Equals(scope,"all"))
  2243. {
  2244. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"all");
  2245. }
  2246. else
  2247. {
  2248. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"player",strSpeaker);
  2249. }
  2250. }
  2251. }
  2252. else
  2253. {
  2254. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","No Stats are available yet! Please wait one Round!","player", strSpeaker);
  2255. }
  2256. }
  2257. }
  2258. public void GetTop10(string strSpeaker,int delay, string scope)
  2259. {
  2260. if (this.m_enTop10ingame == enumBoolYesNo.Yes)
  2261. {
  2262. int sort =0;
  2263. string SQL ="";
  2264. //Top10 Query
  2265. if(this.m_enRankingByScore == enumBoolYesNo.Yes)
  2266. {
  2267. SQL =@"SELECT SoldierName,playerScore, playerKills, playerDeaths, playerHeadshots
  2268. FROM " + this.tbl_playerstats + @" b
  2269. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = b.StatsID
  2270. ORDER BY playerScore DESC LIMIT 10";
  2271. }
  2272. else
  2273. {
  2274. SQL =@"SELECT SoldierName,playerScore, playerKills, playerDeaths, playerHeadshots
  2275. FROM " + this.tbl_playerstats + @" b
  2276. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = b.StatsID
  2277. ORDER BY playerKills DESC, playerDeaths ASC LIMIT 10";
  2278. }
  2279. sort = 2;
  2280. List<string> result = new List<string>(this.SQLquery(SQL,sort));
  2281. this.CloseOdbcConnection(1);
  2282. if(result[0].Equals("0") == false)
  2283. {
  2284. int top10Delay = 0;
  2285. foreach(string line in result)
  2286. {
  2287. this.CheckMessageLength(line);
  2288. if(String.Equals(scope,"all"))
  2289. {
  2290. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", top10Delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"all");
  2291. }
  2292. else
  2293. {
  2294. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", top10Delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"player", strSpeaker);
  2295. }
  2296. top10Delay += delay;
  2297. }
  2298. }
  2299. }
  2300. }
  2301. public void GetWeaponStats(string strWeapon, string strPlayer, string scope)
  2302. {
  2303. int delay = 0;
  2304. string query = "";
  2305. if(String.Equals(strWeapon,"") == false)
  2306. {
  2307. query = @"SELECT `%Weapon%_kills`, `%Weapon%_hs`, `%Weapon%_deaths`, rank, allrank
  2308. FROM (select(@num := @num+1) rank, (SELECT count(*)
  2309. FROM " + this.tbl_weaponstats + @") allrank,WeaponStatsID, `%Weapon%_kills`, `%Weapon%_hs`, `%Weapon%_deaths`
  2310. FROM " + this.tbl_weaponstats + @", (select @num := 0) x
  2311. ORDER BY `%Weapon%_kills` DESC, `%Weapon%_hs` DESC) y
  2312. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = y.WeaponStatsID
  2313. WHERE a.SoldierName = '%Player%'";
  2314. query = query.Replace("%Weapon%",strWeapon);
  2315. query = query.Replace("%Player%",strPlayer);
  2316. List<string> result = new List<string>(this.SQLquery(query,4));
  2317. this.CloseOdbcConnection(1);
  2318. result = this.ListReplace(result,"%playerName%",strPlayer);
  2319. result = this.ListReplace(result,"%Weapon%",strWeapon);
  2320. if(result[0].Equals("0") == false)
  2321. {
  2322. foreach(string line in result)
  2323. {
  2324. this.CheckMessageLength(line);
  2325. if(String.Equals(scope,"all"))
  2326. {
  2327. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"all");
  2328. }
  2329. else
  2330. {
  2331. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"player", strPlayer);
  2332. }
  2333. }
  2334. }
  2335. else
  2336. {
  2337. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","No Stats are available for this Weapon!!!","player", strPlayer);
  2338. }
  2339. }
  2340. else
  2341. {
  2342. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","Specifc Weapon not found!!","player", strPlayer);
  2343. }
  2344. }
  2345. public void GetWeaponTop10(string strWeapon, string strPlayer,int delay, string scope)
  2346. {
  2347. int delaytop10 = 0;
  2348. if(String.Equals(strWeapon,"") == false)
  2349. {
  2350. string query = @"SELECT `b`.`SoldierName`,`%Weapon%_kills`, `%Weapon%_hs`, `%Weapon%_deaths`
  2351. FROM " + this.tbl_weaponstats + @" a
  2352. INNER JOIN " + this.tbl_playerdata + @" b ON b.PlayerID = a.WeaponstatsID
  2353. ORDER BY `%Weapon%_kills` DESC, `%Weapon%_hs` DESC
  2354. LIMIT 10";
  2355. query = query.Replace("%Weapon%",strWeapon);
  2356. List<string> result = new List<string>(this.SQLquery(query,5));
  2357. this.CloseOdbcConnection(1);
  2358. result = this.ListReplace(result,"%Player%",strPlayer);
  2359. result = this.ListReplace(result,"%Weapon%",strWeapon);
  2360. if(result[0].Equals("0") == false)
  2361. {
  2362. foreach(string line in result)
  2363. {
  2364. this.CheckMessageLength(line);
  2365. if(String.Equals(scope,"all"))
  2366. {
  2367. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delaytop10.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"all");
  2368. }
  2369. else
  2370. {
  2371. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delaytop10.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"player", strPlayer);
  2372. }
  2373. delaytop10 = delaytop10 +delay;
  2374. }
  2375. }
  2376. else
  2377. {
  2378. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","No Stats are available for this Weapon!!!","player", strPlayer);
  2379. }
  2380. }
  2381. else
  2382. {
  2383. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","Specifc Weapon not found!!","player", strPlayer);
  2384. }
  2385. }
  2386. public void GetDogtags(string strPlayer,int delay, string scope)
  2387. {
  2388. int delaydogtags = 0;
  2389. string query = @"SELECT `SoldierName`,`Count` from " + this.tbl_dogtags + @" d
  2390. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = d.VictimID
  2391. WHERE `KillerID` =" +this.GetID(strPlayer)+ @"
  2392. ORDER BY `Count` DESC Limit 3";
  2393. string query2 = @"SELECT `SoldierName`,`Count` FROM " + this.tbl_dogtags + @" d
  2394. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = d.KillerID
  2395. WHERE `VictimID` = " +this.GetID(strPlayer)+@"
  2396. ORDER BY `Count` DESC Limit 3";
  2397. List<string> result = new List<string>(this.SQLquery(query,6));
  2398. List<string> result2 = new List<string>(this.SQLquery(query2,7));
  2399. this.CloseOdbcConnection(1);
  2400. result.AddRange(result2);
  2401. if(result[0].Equals("0") == false)
  2402. {
  2403. foreach(string line in result)
  2404. {
  2405. this.CheckMessageLength(line);
  2406. if(String.Equals(scope,"all"))
  2407. {
  2408. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delaydogtags.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"all");
  2409. }
  2410. else
  2411. {
  2412. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delaydogtags.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"player", strPlayer);
  2413. }
  2414. delaydogtags = delaydogtags +delay;
  2415. }
  2416. }
  2417. else
  2418. {
  2419. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","No Stats are available!!!","player", strPlayer);
  2420. }
  2421. }
  2422. public void AddKillToStats(string strPlayerName,string weapon, bool headshot )
  2423. {
  2424. if(StatsTracker.ContainsKey(strPlayerName))
  2425. {
  2426. StatsTracker[strPlayerName].addKill(weapon,headshot);
  2427. }
  2428. else
  2429. {
  2430. CStats newEntry = new CStats("",0,0,0,0,0,0,0,this.m_dTimeOffset);
  2431. StatsTracker.Add(strPlayerName,newEntry);
  2432. StatsTracker[strPlayerName].addKill(weapon,headshot);
  2433. }
  2434. //Session
  2435. if(m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  2436. {
  2437. m_dicSession[strPlayerName].addKill(weapon,headshot);
  2438. }
  2439. }
  2440. public void AddDeathToStats(string strPlayerName,string weapon)
  2441. {
  2442. if(StatsTracker.ContainsKey(strPlayerName))
  2443. {
  2444. StatsTracker[strPlayerName].addDeath(weapon);
  2445. }
  2446. else
  2447. {
  2448. CStats newEntry = new CStats("",0,0,0,0,0,0,0,this.m_dTimeOffset);
  2449. StatsTracker.Add(strPlayerName,newEntry);
  2450. StatsTracker[strPlayerName].addDeath(weapon);
  2451. }
  2452. //Session
  2453. if(m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  2454. {
  2455. m_dicSession[strPlayerName].addDeath(weapon);
  2456. }
  2457. }
  2458. public void AddSuicideToStats(string strPlayerName, string weapon)
  2459. {
  2460. if(StatsTracker.ContainsKey(strPlayerName))
  2461. {
  2462. StatsTracker[strPlayerName].addDeath(weapon);
  2463. StatsTracker[strPlayerName].Suicides ++;
  2464. }
  2465. else
  2466. {
  2467. CStats newEntry = new CStats("",0,0,0,0,1,0,0,this.m_dTimeOffset);
  2468. StatsTracker.Add(strPlayerName,newEntry);
  2469. StatsTracker[strPlayerName].addDeath(weapon);
  2470. }
  2471. //Session
  2472. if(m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  2473. {
  2474. m_dicSession[strPlayerName].addDeath(weapon);
  2475. m_dicSession[strPlayerName].Suicides ++;
  2476. }
  2477. }
  2478. public void AddTeamKillToStats(string strPlayerName)
  2479. {
  2480. if(StatsTracker.ContainsKey(strPlayerName))
  2481. {
  2482. StatsTracker[strPlayerName].Teamkills ++;
  2483. }
  2484. else
  2485. {
  2486. CStats newEntry = new CStats("",0,0,0,0,0,1,0,this.m_dTimeOffset);
  2487. StatsTracker.Add(strPlayerName,newEntry);
  2488. }
  2489. //Session
  2490. if(m_dicSession.ContainsKey(strPlayerName) && this.m_sessionON == enumBoolYesNo.Yes)
  2491. {
  2492. m_dicSession[strPlayerName].Teamkills ++;
  2493. }
  2494. }
  2495. public void AddPBInfoToStats(CPunkbusterInfo cpbiPlayer)
  2496. {
  2497. if(StatsTracker.ContainsKey(cpbiPlayer.SoldierName))
  2498. {
  2499. StatsTracker[cpbiPlayer.SoldierName].Guid = cpbiPlayer.GUID;
  2500. StatsTracker[cpbiPlayer.SoldierName].PlayerCountryCode = cpbiPlayer.PlayerCountryCode;
  2501. if(StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined == null)
  2502. StatsTracker[cpbiPlayer.SoldierName].TimePlayerjoined = MyDateTime.Now;
  2503. }
  2504. else
  2505. {
  2506. CStats newEntry = new CStats(cpbiPlayer.GUID,0,0,0,0,0,0,0,this.m_dTimeOffset);
  2507. StatsTracker.Add(cpbiPlayer.SoldierName,newEntry);
  2508. StatsTracker[cpbiPlayer.SoldierName].PlayerCountryCode = cpbiPlayer.PlayerCountryCode;
  2509. }
  2510. }
  2511. public void OpenOdbcConnection(int type)
  2512. {
  2513. try
  2514. {
  2515. switch(type)
  2516. {
  2517. //OdbcCon
  2518. case 1:
  2519. if(OdbcCon == null)
  2520. {
  2521. OdbcCon = new System.Data.Odbc.OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};" +
  2522. "SERVER=" + m_strHost + ";" +
  2523. "PORT=" + m_strDBPort + ";" +
  2524. "DATABASE=" + m_strDatabase + ";" +
  2525. "UID=" + m_strUserName + ";" +
  2526. "PWD=" + m_strPassword + ";" +
  2527. "OPTION=3;");
  2528. }
  2529. if (OdbcCon.State == ConnectionState.Closed)
  2530. {
  2531. OdbcCon = new System.Data.Odbc.OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};" +
  2532. "SERVER=" + m_strHost + ";" +
  2533. "PORT=" + m_strDBPort + ";" +
  2534. "DATABASE=" + m_strDatabase + ";" +
  2535. "UID=" + m_strUserName + ";" +
  2536. "PWD=" + m_strPassword + ";" +
  2537. "OPTION=3;");
  2538. OdbcCon.Open();
  2539. this.DebugInfo("OdbcCon open");
  2540. }
  2541. break;
  2542. //ODBCConn
  2543. case 2:
  2544. if(OdbcConn == null)
  2545. {
  2546. OdbcConn = new System.Data.Odbc.OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};" +
  2547. "SERVER=" + m_strHost + ";" +
  2548. "PORT=" + m_strDBPort + ";" +
  2549. "DATABASE=" + m_strDatabase + ";" +
  2550. "UID=" + m_strUserName + ";" +
  2551. "PWD=" + m_strPassword + ";" +
  2552. "OPTION=3;");
  2553. }
  2554. if (OdbcConn.State == ConnectionState.Closed)
  2555. {
  2556. OdbcConn = new System.Data.Odbc.OdbcConnection("DRIVER={MySQL ODBC 5.1 Driver};" +
  2557. "SERVER=" + m_strHost + ";" +
  2558. "PORT=" + m_strDBPort + ";" +
  2559. "DATABASE=" + m_strDatabase + ";" +
  2560. "UID=" + m_strUserName + ";" +
  2561. "PWD=" + m_strPassword + ";" +
  2562. "OPTION=3;");
  2563. OdbcConn.Open();
  2564. this.DebugInfo("OdbcConn open");
  2565. }
  2566. break;
  2567. default:
  2568. break;
  2569. }
  2570. }
  2571. catch(OdbcException oe)
  2572. {
  2573. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OpenConnection:");
  2574. this.DisplayOdbcErrorCollection(oe);
  2575. }
  2576. catch(Exception c)
  2577. {
  2578. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in OpenConnection: " + c);
  2579. }
  2580. }
  2581. public void CloseOdbcConnection(int type)
  2582. {
  2583. if(this.ODBC_Connection_is_activ == false)
  2584. {
  2585. try
  2586. {
  2587. switch(type)
  2588. {
  2589. case 1:
  2590. //OdbcCon
  2591. if(this.OdbcCon != null)
  2592. if(this.OdbcCon.State == ConnectionState.Open)
  2593. {
  2594. this.OdbcCon.Close();
  2595. this.DebugInfo("Connection OdbcCon closed");
  2596. }
  2597. break;
  2598. case 2:
  2599. //ODBCConn
  2600. if(this.OdbcConn != null)
  2601. if(this.OdbcConn.State == ConnectionState.Open)
  2602. {
  2603. this.OdbcConn.Close();
  2604. this.DebugInfo("Connection OdbcConn closed");
  2605. }
  2606. break;
  2607. default:
  2608. break;
  2609. }
  2610. }
  2611. catch(OdbcException oe)
  2612. {
  2613. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in CloseOdbcConnection:");
  2614. this.DisplayOdbcErrorCollection(oe);
  2615. }
  2616. catch(Exception c)
  2617. {
  2618. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in CloseOdbcConnection: " + c);
  2619. }
  2620. }
  2621. }
  2622. public void tablebuilder()
  2623. {
  2624. if ((m_strHost != null) && (m_strDatabase != null) && (m_strDBPort != null) && (m_strUserName != null) && (m_strPassword != null) && (boolTableEXISTS == false))
  2625. {
  2626. this.DebugInfo("Start tablebuilder");
  2627. try
  2628. {
  2629. this.ODBC_Connection_is_activ = true;
  2630. OdbcParameter param = new OdbcParameter();
  2631. this.OpenOdbcConnection(1);
  2632. //Chatlog Table
  2633. string SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_chatlog + @"` (
  2634. `ID` INT NOT NULL AUTO_INCREMENT ,
  2635. `logDate` DATETIME NULL DEFAULT NULL ,
  2636. `logServer` TEXT NULL DEFAULT NULL ,
  2637. `logSubset` TEXT NULL DEFAULT NULL ,
  2638. `logSoldierName` TEXT NULL DEFAULT NULL ,
  2639. `logMessage` TEXT NULL DEFAULT NULL ,
  2640. PRIMARY KEY (`ID`) )
  2641. ENGINE = MyISAM
  2642. DEFAULT CHARACTER SET = utf8";
  2643. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon))
  2644. {
  2645. OdbcCom.ExecuteNonQuery();
  2646. }
  2647. //MapStats Table
  2648. SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_mapstats + @"` (
  2649. `ID` INT NOT NULL AUTO_INCREMENT ,
  2650. `TimeMapLoad` DATETIME NULL ,
  2651. `TimeRoundStarted` DATETIME NULL ,
  2652. `TimeRoundEnd` DATETIME NULL ,
  2653. `MapName` VARCHAR(32) NULL ,
  2654. `Gamemode` VARCHAR(20) NULL ,
  2655. `Roundcount` INT NOT NULL DEFAULT 0 ,
  2656. `NumberofRounds` INT NOT NULL DEFAULT 0 ,
  2657. `MinPlayers` INT NOT NULL DEFAULT 0 ,
  2658. `AvgPlayers` double NOT NULL DEFAULT 0 ,
  2659. `MaxPlayers` INT NOT NULL DEFAULT 0 ,
  2660. `PlayersJoinedServer` INT NOT NULL DEFAULT 0 ,
  2661. `PlayersLeftServer` INT NOT NULL DEFAULT 0 ,
  2662. PRIMARY KEY (`ID`) )
  2663. ENGINE = MyISAM
  2664. DEFAULT CHARACTER SET = utf8";
  2665. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon))
  2666. {
  2667. OdbcCom.ExecuteNonQuery();
  2668. }
  2669. //Start of the Transaction
  2670. OdbcTrans = OdbcCon.BeginTransaction();
  2671. //Table playerdata
  2672. SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_playerdata + @"` (
  2673. `PlayerID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  2674. `ClanTag` varchar(45) DEFAULT NULL,
  2675. `SoldierName` varchar(16) DEFAULT NULL,
  2676. `GUID` varchar(32) DEFAULT NULL,
  2677. `EAGUID` varchar(35) DEFAULT NULL,
  2678. `IP_Address` varchar(15) DEFAULT NULL,
  2679. `CountryCode` varchar(4) DEFAULT NULL,
  2680. PRIMARY KEY (`PlayerID`),
  2681. UNIQUE KEY `UNIQUE_playerdata` (`SoldierName`,`GUID`))
  2682. ENGINE = InnoDB DEFAULT CHARACTER SET = utf8";
  2683. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2684. {
  2685. OdbcCom.ExecuteNonQuery();
  2686. }
  2687. //BFBCS Table
  2688. SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_bfbcs + @"` (
  2689. `bfbcsID` INT NOT NULL ,
  2690. `Rank` INT NOT NULL DEFAULT 0 ,
  2691. `Kills` INT NOT NULL DEFAULT 0 ,
  2692. `Deaths` INT NOT NULL DEFAULT 0 ,
  2693. `Score` INT NOT NULL DEFAULT 0 ,
  2694. `Elo` DOUBLE NOT NULL DEFAULT 0 ,
  2695. `Level` DOUBLE NOT NULL DEFAULT 0 ,
  2696. `Time` DOUBLE NOT NULL DEFAULT 0 ,
  2697. `LastUpdate` DATETIME NULL DEFAULT NULL ,
  2698. PRIMARY KEY (`bfbcsID`) )
  2699. ENGINE = InnoDB";
  2700. if(this.m_getStatsfromBFBCS == enumBoolYesNo.Yes)
  2701. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2702. {
  2703. OdbcCom.ExecuteNonQuery();
  2704. }
  2705. //Stats Table
  2706. SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_playerstats + @"` (
  2707. `StatsID` INT UNSIGNED NULL PRIMARY KEY ,
  2708. `playerScore` int(11) NOT NULL DEFAULT 0,
  2709. `playerKills` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2710. `playerHeadshots` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2711. `playerDeaths` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2712. `playerSuicide` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2713. `playerTKs` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2714. `playerPlaytime` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2715. `playerRounds` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2716. `FirstSeenOnServer` DATETIME NULL DEFAULT NULL,
  2717. `LastSeenOnServer` DATETIME NULL DEFAULT NULL ,
  2718. `Killstreak` INT UNSIGNED NOT NULL DEFAULT 0,
  2719. `Deathstreak`INT UNSIGNED NOT NULL DEFAULT 0)
  2720. ENGINE = InnoDB DEFAULT CHARACTER SET = utf8";
  2721. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2722. {
  2723. OdbcCom.ExecuteNonQuery();
  2724. }
  2725. //Weapon Table
  2726. SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_weaponstats + @"` (
  2727. `WeaponStatsID` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ";
  2728. List<string> columnlist = new List<string>();
  2729. foreach(string substring in m_lstTableschema)
  2730. {
  2731. int charindex = substring.IndexOf("{");
  2732. string columnName = substring;
  2733. if(charindex > 0)
  2734. columnName = substring.Remove(charindex);
  2735. if(substring.Contains("/") == false && substring.Length > 0)
  2736. {
  2737. if(columnlist.Contains(columnName) == false)
  2738. {
  2739. columnlist.Add(columnName);
  2740. }
  2741. }
  2742. }
  2743. foreach(string strcolumn in columnlist)
  2744. {
  2745. SQLTable = String.Concat(SQLTable,",`",strcolumn,"_kills` INT UNSIGNED NOT NULL DEFAULT 0, ");
  2746. SQLTable = String.Concat(SQLTable,"`",strcolumn,"_hs` INT UNSIGNED NOT NULL DEFAULT 0, ");
  2747. SQLTable = String.Concat(SQLTable,"`",strcolumn,"_deaths` INT UNSIGNED NOT NULL DEFAULT 0 ");
  2748. }
  2749. SQLTable = String.Concat(SQLTable,")ENGINE = InnoDB DEFAULT CHARACTER SET = utf8");
  2750. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2751. {
  2752. OdbcCom.ExecuteNonQuery();
  2753. }
  2754. //Dogtagstable
  2755. SQLTable = @"CREATE TABLE IF NOT EXISTS `" + this.tbl_dogtags + @"` (
  2756. `KillerID` INT(10) UNSIGNED NOT NULL ,
  2757. `VictimID` INT(10) UNSIGNED NOT NULL ,
  2758. `Count` INT UNSIGNED NOT NULL DEFAULT 0 ,
  2759. PRIMARY KEY (`KillerID`, `VictimID`) ,
  2760. INDEX `VictimID_Index` (`VictimID` ASC))
  2761. ENGINE = InnoDB
  2762. DEFAULT CHARACTER SET = utf8";
  2763. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2764. {
  2765. OdbcCom.ExecuteNonQuery();
  2766. }
  2767. //Commit the Transaction
  2768. OdbcTrans.Commit();
  2769. this.boolTableEXISTS = true;
  2770. //TableCheck
  2771. string sqlCheck ="DESC `" + this.tbl_weaponstats +"`";
  2772. string sqlAltertable = "ALTER TABLE `" + this.tbl_weaponstats +"` ";
  2773. List<string> result = new List<string>(this.SQLquery(sqlCheck,9));
  2774. bool fieldMissing = false;
  2775. foreach(string substring in columnlist)
  2776. {
  2777. string strField = substring;
  2778. if(result.Contains(strField + "_kills") == false)
  2779. {
  2780. this.DebugInfo(strField + "_kills" +" is missing, Adding it to the table!");
  2781. sqlAltertable = string.Concat(sqlAltertable,"ADD COLUMN `"+ strField + "_kills`" +" INT(10) UNSIGNED NOT NULL DEFAULT 0, ");
  2782. fieldMissing = true;
  2783. }
  2784. if(result.Contains(strField + "_hs") == false)
  2785. {
  2786. this.DebugInfo(strField + "_hs" +" is missing, Adding it to the table!");
  2787. sqlAltertable = string.Concat(sqlAltertable,"ADD COLUMN `"+ strField + "_hs`" +" INT(10) UNSIGNED NOT NULL DEFAULT 0, ");
  2788. fieldMissing = true;
  2789. }
  2790. if(result.Contains(strField + "_deaths") == false)
  2791. {
  2792. this.DebugInfo(strField + "_deaths" +" is missing, Adding it to the table!");
  2793. sqlAltertable = string.Concat(sqlAltertable,"ADD COLUMN `"+ strField + "_deaths`" +" INT(10) UNSIGNED NOT NULL DEFAULT 0, ");
  2794. fieldMissing = true;
  2795. }
  2796. }
  2797. if(fieldMissing == true)
  2798. {
  2799. OdbcTrans = OdbcCon.BeginTransaction();
  2800. SQLTable = "ALTER TABLE `" + this.tbl_weaponstats +"` ENGINE = MyISAM";
  2801. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2802. {
  2803. OdbcCom.ExecuteNonQuery();
  2804. }
  2805. //Adding Columns
  2806. int charindex = sqlAltertable.LastIndexOf(",");
  2807. if(charindex > 0)
  2808. {
  2809. sqlAltertable = sqlAltertable.Remove(charindex);
  2810. }
  2811. using (OdbcCommand OdbcCom = new OdbcCommand(sqlAltertable, OdbcCon, OdbcTrans))
  2812. {
  2813. OdbcCom.ExecuteNonQuery();
  2814. }
  2815. SQLTable = "ALTER TABLE `" + this.tbl_weaponstats +"` ENGINE = InnoDB";
  2816. using (OdbcCommand OdbcCom = new OdbcCommand(SQLTable, OdbcCon, OdbcTrans))
  2817. {
  2818. OdbcCom.ExecuteNonQuery();
  2819. }
  2820. OdbcTrans.Commit();
  2821. }
  2822. else
  2823. {
  2824. this.DebugInfo("Your Weapontable is containing all weapons known so far, if you got Error after this( missing Weapons) contact me pls");
  2825. }
  2826. }
  2827. catch(OdbcException oe)
  2828. {
  2829. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in Tablebuilder: ");
  2830. this.DisplayOdbcErrorCollection(oe);
  2831. }
  2832. catch (Exception c)
  2833. {
  2834. OdbcTrans.Rollback();
  2835. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error: " + c);
  2836. this.boolTableEXISTS = false;
  2837. this.m_ID_cache.Clear();
  2838. if (OdbcCon.State == ConnectionState.Open)
  2839. {
  2840. OdbcCon.Close();
  2841. }
  2842. }
  2843. this.ODBC_Connection_is_activ = false;
  2844. }
  2845. }
  2846. public void LogChat(string strSpeaker, string strMessage, string strType)
  2847. {
  2848. if(this.m_enChatloggingON == enumBoolYesNo.No)
  2849. {
  2850. return;
  2851. }
  2852. if(this.m_enNoServerMsg == enumBoolYesNo.No && strSpeaker.CompareTo("Server") == 0)
  2853. {
  2854. return;
  2855. }
  2856. else if(m_enInstantChatlogging == enumBoolYesNo.Yes)
  2857. {
  2858. string query = "INSERT INTO " + this.tbl_chatlog + @" (logDate, logServer, logSubset, logSoldierName, logMessage) VALUES (?,?,?,?,?)";
  2859. this.tablebuilder();
  2860. if ((m_strHost != null) || (m_strDatabase != null) || (m_strDBPort != null) || (m_strUserName != null) || (m_strPassword != null))
  2861. {
  2862. try
  2863. {
  2864. this.ODBC_Connection_is_activ = true;
  2865. this.OpenOdbcConnection(1);
  2866. OdbcParameter param = new OdbcParameter();
  2867. if (OdbcCon.State == ConnectionState.Open)
  2868. {
  2869. using (OdbcCommand OdbcCom = new OdbcCommand(query, OdbcCon))
  2870. {
  2871. OdbcCom.Parameters.AddWithValue("@pr", MyDateTime.Now);
  2872. OdbcCom.Parameters.AddWithValue("@pr", this.serverName);
  2873. OdbcCom.Parameters.AddWithValue("@pr", strType);
  2874. OdbcCom.Parameters.AddWithValue("@pr", strSpeaker);
  2875. OdbcCom.Parameters.AddWithValue("@pr", strMessage);
  2876. OdbcCom.ExecuteNonQuery();
  2877. }
  2878. this.CloseOdbcConnection(1);
  2879. }
  2880. }
  2881. catch(OdbcException oe)
  2882. {
  2883. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in LogChat: ");
  2884. this.DisplayOdbcErrorCollection(oe);
  2885. }
  2886. catch(Exception c)
  2887. {
  2888. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in LogChat: " + c);
  2889. if (OdbcCon.State == ConnectionState.Open)
  2890. {
  2891. OdbcCon.Close();
  2892. }
  2893. this.ODBC_Connection_is_activ = false;
  2894. }
  2895. this.ODBC_Connection_is_activ = false;
  2896. }
  2897. }
  2898. else
  2899. {
  2900. CLogger chat = new CLogger(MyDateTime.Now, strSpeaker, strMessage, strType);
  2901. ChatLog.Add(chat);
  2902. }
  2903. }
  2904. public ArrayList TextFileReader(string textfile)
  2905. {
  2906. StreamReader objReader = new StreamReader(textfile);
  2907. string sline ="";
  2908. ArrayList arrText = new ArrayList();
  2909. while(sline != null)
  2910. {
  2911. sline = objReader.ReadLine();
  2912. if(sline != null)
  2913. {
  2914. arrText.Add(sline);
  2915. }
  2916. }
  2917. objReader.Close();
  2918. return arrText;
  2919. }
  2920. public void DebugInfo(string DebugMessage)
  2921. {
  2922. if(m_enDebugMode == enumBoolYesNo.Yes)
  2923. {
  2924. this.ExecuteCommand("procon.protected.pluginconsole.write","^4" + DebugMessage);
  2925. }
  2926. }
  2927. public void PrepareKeywordDic()
  2928. {
  2929. this.m_dicKeywords.Clear();
  2930. if(boolKeywordDicReady == false)
  2931. {
  2932. try
  2933. {
  2934. string dicKey = "";
  2935. string dicValue = "";
  2936. int bracket1 = 0;
  2937. int bracket2 = 0;
  2938. /*
  2939. ArrayList arrText = this.TextFileReader("tableconfig.cfg");
  2940. arrText.Sort();
  2941. foreach(string line in arrText)
  2942. */
  2943. foreach(string line in m_lstTableconfig)
  2944. {
  2945. if(line.Contains("/") == false)
  2946. {
  2947. if(line.Contains("{") && line.Contains("}"))
  2948. {
  2949. bracket1 = line.IndexOf("{");
  2950. dicKey = line.Remove(bracket1);
  2951. dicValue = line.Replace("{",",");
  2952. dicValue = dicValue.Replace("}","");
  2953. string[] arrStrings = Regex.Split(dicValue,",");
  2954. if(this.m_dicKeywords.ContainsKey(dicKey) == false)
  2955. {
  2956. this.m_dicKeywords.Add(dicKey,new List<string>());
  2957. }
  2958. foreach(string substring in arrStrings)
  2959. {
  2960. this.m_dicKeywords[dicKey].Add(substring);
  2961. }
  2962. this.m_dicKeywords[dicKey].Sort();
  2963. }
  2964. else
  2965. {
  2966. dicKey = line.Replace(" ","");
  2967. bracket1 = dicKey.IndexOf("{");
  2968. if(bracket1 > 0)
  2969. dicKey = dicKey.Remove(bracket1);
  2970. if(this.m_dicKeywords.ContainsKey(dicKey) == false)
  2971. {
  2972. this.m_dicKeywords.Add(dicKey,new List<string>());
  2973. this.m_dicKeywords[dicKey].Add(dicKey);
  2974. }
  2975. }
  2976. }
  2977. }
  2978. }
  2979. catch(Exception c)
  2980. {
  2981. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1PrepareKeywordDic: " + c);
  2982. }
  2983. }
  2984. }
  2985. public string FindKeyword(string strToFind)
  2986. {
  2987. string foundKey ="";
  2988. string keyvalue = "";
  2989. strToFind = strToFind.ToUpper();
  2990. strToFind = strToFind.Replace(" ","");
  2991. foreach(KeyValuePair<string, List<string>> kvp in this.m_dicKeywords)
  2992. {
  2993. if(this.m_dicKeywords[kvp.Key].Contains(strToFind))
  2994. {
  2995. foundKey = kvp.Key;
  2996. break;
  2997. }
  2998. }
  2999. return foundKey;
  3000. }
  3001. public List<string> ListReplace(List<string> targetlist, string wordToReplace, string replacement)
  3002. {
  3003. List<string> lstResult = new List<string>();
  3004. foreach(string substring in targetlist)
  3005. {
  3006. lstResult.Add(substring.Replace(wordToReplace,replacement));
  3007. }
  3008. return lstResult;
  3009. }
  3010. public void CheckMessageLength(string strMessage)
  3011. {
  3012. if(strMessage.Length > 100)
  3013. {
  3014. //Send Warning
  3015. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Warning: "+ strMessage);
  3016. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Warning: This Ingamemessage is too long and wont sent to Server!!!" );
  3017. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Warning: The Message has a Length of "+ strMessage.Length.ToString() +" Chars, Allow are 100 Chars" );
  3018. }
  3019. }
  3020. public void CreateSession(string SoldierName)
  3021. {
  3022. try
  3023. {
  3024. if(this.m_sessionON == enumBoolYesNo.Yes)
  3025. {
  3026. //Session
  3027. if(this.m_dicSession.ContainsKey(SoldierName) == false)
  3028. {
  3029. CStats Entry = new CStats("",0,0,0,0,0,0,0,this.m_dTimeOffset);
  3030. this.m_dicSession.Add(SoldierName,Entry);
  3031. this.m_dicSession[SoldierName].Rank = this.GetRank(SoldierName);
  3032. }
  3033. }
  3034. }
  3035. catch(Exception c)
  3036. {
  3037. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in CreateSession: " + c);
  3038. }
  3039. }
  3040. public void RemoveSession(string SoldierName)
  3041. {
  3042. try
  3043. {
  3044. if(m_sessionON == enumBoolYesNo.Yes)
  3045. {
  3046. if(this.m_dicSession.ContainsKey(SoldierName) == true)
  3047. {
  3048. this.m_dicSession.Remove(SoldierName);
  3049. }
  3050. }
  3051. }
  3052. catch(Exception c)
  3053. {
  3054. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in RemoveSession: " + c);
  3055. }
  3056. }
  3057. public void GetSession(string SoldierName, int delay, string scope)
  3058. {
  3059. try
  3060. {
  3061. if(this.m_dicSession.ContainsKey(SoldierName) && this.m_sessionON == enumBoolYesNo.Yes)
  3062. {
  3063. List<string> result = new List<string>();
  3064. result = m_lstSessionMessage;
  3065. result = ListReplace(result, "%playerName%", SoldierName);
  3066. result = ListReplace(result, "%playerScore%", this.m_dicSession[SoldierName].Score.ToString());
  3067. result = ListReplace(result, "%playerKills%", this.m_dicSession[SoldierName].Kills.ToString());
  3068. result = ListReplace(result, "%killstreak%", this.m_dicSession[SoldierName].Killstreak.ToString());
  3069. result = ListReplace(result, "%playerDeaths%", this.m_dicSession[SoldierName].Deaths.ToString());
  3070. result = ListReplace(result, "%deathstreak%", this.m_dicSession[SoldierName].Deathstreak.ToString());
  3071. result = ListReplace(result, "%playerKDR%", this.m_dicSession[SoldierName].KDR().ToString());
  3072. result = ListReplace(result, "%playerHeadshots%", this.m_dicSession[SoldierName].Headshots.ToString());
  3073. result = ListReplace(result, "%playerSuicide%", this.m_dicSession[SoldierName].Suicides.ToString());
  3074. result = ListReplace(result, "%playerTK%", this.m_dicSession[SoldierName].Teamkills.ToString());
  3075. result = ListReplace(result, "%startRank%", this.m_dicSession[SoldierName].Rank.ToString());
  3076. //Rankdiff
  3077. int playerRank = this.GetRank(SoldierName);
  3078. result = ListReplace(result, "%playerRank%", playerRank.ToString());
  3079. int Rankdif = this.m_dicSession[SoldierName].Rank;
  3080. Rankdif = Rankdif - playerRank;
  3081. if(Rankdif == 0)
  3082. {
  3083. result = ListReplace(result, "%RankDif%","0");
  3084. }
  3085. else if(Rankdif > 0)
  3086. {
  3087. result = ListReplace(result, "%RankDif%","+" + Rankdif.ToString());
  3088. }
  3089. else
  3090. {
  3091. result = ListReplace(result, "%RankDif%",Rankdif.ToString());
  3092. }
  3093. result = ListReplace(result, "%SessionStarted%",this.m_dicSession[SoldierName].TimePlayerjoined.ToString());
  3094. TimeSpan duration = MyDateTime.Now - this.m_dicSession[SoldierName].TimePlayerjoined;
  3095. result = ListReplace(result, "%SessionDuration%",Math.Round(duration.TotalMinutes,2).ToString());
  3096. if(result.Count != 0)
  3097. {
  3098. foreach(string line in result)
  3099. {
  3100. this.CheckMessageLength(line);
  3101. if(String.Equals(scope,"all"))
  3102. {
  3103. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"all");
  3104. }
  3105. else
  3106. {
  3107. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say",line,"player",SoldierName);
  3108. }
  3109. }
  3110. }
  3111. else
  3112. {
  3113. this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger", delay.ToString(), "1", "1", "procon.protected.send", "admin.say","No Sessiondata are available!","player", SoldierName);
  3114. }
  3115. }
  3116. }
  3117. catch(Exception c)
  3118. {
  3119. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in GetSession: " + c);
  3120. }
  3121. }
  3122. public int GetRank(string SoldierName)
  3123. {
  3124. List<string> result = new List<string>();
  3125. int rank = 0;
  3126. try
  3127. {
  3128. string SQL = "";
  3129. this.tablebuilder();
  3130. if(m_enRankingByScore == enumBoolYesNo.Yes)
  3131. {
  3132. SQL = @"SELECT rank FROM(
  3133. SELECT(@num := @num+1) rank, a.SoldierName
  3134. FROM " + this.tbl_playerstats + @" b
  3135. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = b.StatsID
  3136. , (select @num := 0) x
  3137. ORDER BY playerScore DESC) y
  3138. WHERE SoldierName ='"+SoldierName+"'";
  3139. }
  3140. else
  3141. {
  3142. SQL = @"SELECT rank FROM(
  3143. SELECT(@num := @num+1) rank, a.SoldierName
  3144. FROM " + this.tbl_playerstats + @" b
  3145. INNER JOIN " + this.tbl_playerdata + @" a ON a.PlayerID = b.StatsID
  3146. , (select @num := 0) x
  3147. ORDER BY playerKills DESC, playerDeaths ASC) Y
  3148. WHERE SoldierName ='"+SoldierName+"'";
  3149. }
  3150. result = this.SQLquery(SQL,8);
  3151. //this.CloseOdbcConnection(1);
  3152. foreach(string entry in result)
  3153. {
  3154. rank = Convert.ToInt32(entry);
  3155. }
  3156. }
  3157. catch(Exception c)
  3158. {
  3159. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in GetRank: " + c);
  3160. }
  3161. return rank;
  3162. }
  3163. public void PluginInfo(string strPlayer)
  3164. {
  3165. //this.ExecuteCommand("procon.protected.tasks.add", "CChatGUIDStatsLogger","0", "1", "1", "procon.protected.send", "admin.say","This Server has the PRoCon plugin "+this.GetPluginName+" "+this.GetPluginVersion+"running by "+ this.GetPluginAuthor,"player", strPlayer);
  3166. }
  3167. public void DisplayOdbcErrorCollection(OdbcException myException)
  3168. {
  3169. for (int i=0; i < myException.Errors.Count; i++)
  3170. {
  3171. this.ExecuteCommand("procon.protected.pluginconsole.write","^1Index #" + i);
  3172. this.ExecuteCommand("procon.protected.pluginconsole.write","^1Message: " + myException.Errors[i].Message);
  3173. this.ExecuteCommand("procon.protected.pluginconsole.write","^1Native: " + myException.Errors[i].NativeError.ToString());
  3174. this.ExecuteCommand("procon.protected.pluginconsole.write","^1Source: " + myException.Errors[i].Source);
  3175. this.ExecuteCommand("procon.protected.pluginconsole.write","^1SQL: " + myException.Errors[i].SQLState );
  3176. }
  3177. }
  3178. public void prepareTablenames(string gamemod)
  3179. {
  3180. if(gamemod != this.m_strGameMod)
  3181. {
  3182. this.boolTableEXISTS = false;
  3183. }
  3184. switch (gamemod) {
  3185. case "BC2":
  3186. this.tbl_playerdata = "tbl_playerdata" + this.tableSuffix;
  3187. this.tbl_playerstats = "tbl_playerstats" + this.tableSuffix;
  3188. this.tbl_weaponstats = "tbl_weaponstats" + this.tableSuffix;
  3189. this.tbl_dogtags = "tbl_dogtags" + this.tableSuffix;
  3190. this.tbl_mapstats = "tbl_mapstats" + this.tableSuffix;
  3191. this.tbl_chatlog = "tbl_chatlog" + this.tableSuffix;
  3192. this.tbl_bfbcs = "tbl_bfbcs" + this.tableSuffix;
  3193. this.DebugInfo("Gamemod Tableschema set to: BC2");
  3194. break;
  3195. case "VIETNAM":
  3196. this.tbl_playerdata = "tbl_playerdata" + this.tableSuffix;
  3197. this.tbl_playerstats = "tbl_playerstats_bfv" + this.tableSuffix;
  3198. this.tbl_weaponstats = "tbl_weaponstats_bfv" + this.tableSuffix;
  3199. this.tbl_dogtags = "tbl_dogtags_bfv" + this.tableSuffix;
  3200. this.tbl_mapstats = "tbl_mapstats_bfv" + this.tableSuffix;
  3201. this.tbl_chatlog = "tbl_chatlog" + this.tableSuffix;
  3202. this.tbl_bfbcs = "tbl_bfbcs" + this.tableSuffix;
  3203. this.DebugInfo("Gamemod Tableschema set to: VIETNAM");
  3204. break;
  3205. case "SHARED":
  3206. this.tbl_playerdata = "tbl_playerdata" + this.tableSuffix;
  3207. this.tbl_playerstats = "tbl_playerstats" + this.tableSuffix;
  3208. this.tbl_weaponstats = "tbl_weaponstats" + this.tableSuffix;
  3209. this.tbl_dogtags = "tbl_dogtags" + this.tableSuffix;
  3210. this.tbl_mapstats = "tbl_mapstats" + this.tableSuffix;
  3211. this.tbl_chatlog = "tbl_chatlog" + this.tableSuffix;
  3212. this.tbl_bfbcs = "tbl_bfbcs" + this.tableSuffix;
  3213. this.DebugInfo("Gamemod Tableschema set to: SHARED");
  3214. break;
  3215. default:
  3216. break;
  3217. }
  3218. }
  3219. public void setGameMod(string gamemod)
  3220. {
  3221. switch (gamemod)
  3222. {
  3223. case "BC2":
  3224. this.m_lstTableconfig = this.m_lstTableconfig_bc2;
  3225. this.m_lstTableschema = this.m_lstTableschema_bc2;
  3226. this.PrepareKeywordDic();
  3227. this.boolTableEXISTS = false;
  3228. this.DebugInfo("Gamemod Weaponlist set to: BC2");
  3229. break;
  3230. case "VIETNAM":
  3231. this.m_lstTableconfig = this.m_lstTableconfig_bfv;
  3232. this.m_lstTableschema = this.m_lstTableschema_bfv;
  3233. this.PrepareKeywordDic();
  3234. this.boolTableEXISTS = false;
  3235. this.DebugInfo("Gamemod Weaponlist set to: VIETNAM");
  3236. break;
  3237. case "SHARED":
  3238. this.m_lstTableconfig = this.m_lstTableconfig_bc2;
  3239. this.m_lstTableschema = this.m_lstTableschema_bc2;
  3240. this.m_lstTableconfig.AddRange(this.m_lstTableconfig_bfv);
  3241. this.m_lstTableschema.AddRange(this.m_lstTableschema_bfv);
  3242. this.PrepareKeywordDic();
  3243. this.boolTableEXISTS = false;
  3244. this.DebugInfo("Gamemod Weaponlist set to: SHARED");
  3245. break;
  3246. default:
  3247. break;
  3248. }
  3249. }
  3250. public void getBFBCStats(List<CPlayerInfo> lstPlayers)
  3251. {
  3252. List<string> lstSoldierName = new List<string>();
  3253. string SoldierName = "";
  3254. try
  3255. {
  3256. foreach(CPlayerInfo Player in lstPlayers)
  3257. {
  3258. SoldierName = Player.SoldierName;
  3259. DateTime lastUpdate = DateTime.MinValue;
  3260. if (this.m_getStatsfromBFBCS == enumBoolYesNo.Yes && SoldierName != null && this.StatsTracker.ContainsKey(SoldierName) == true && this.StatsTracker[SoldierName].BFBCS_Stats.Updated == false && this.StatsTracker[SoldierName].BFBCS_Stats.Fetching == false )
  3261. {
  3262. string query = @"SELECT b.LastUpdate, b.Rank, b.Kills, b.Deaths, b.Score, b.Time
  3263. FROM "+ tbl_playerdata + @" a
  3264. INNER JOIN " + tbl_bfbcs + @" b ON a.PlayerID = b.bfbcsID
  3265. WHERE a.SoldierName = '"+ SoldierName + "'";
  3266. List<string> result = new List<string>(this.SQLquery(query,10));
  3267. if(result[0] != null)
  3268. {
  3269. //this.DebugInfo("Last Update: " + result[0].ToString());
  3270. if(result[0] != "0")
  3271. {
  3272. lastUpdate = Convert.ToDateTime(result[0]);
  3273. }
  3274. TimeSpan TimeDifference = MyDateTime.Now.Subtract(lastUpdate);
  3275. //this.DebugInfo(TimeDifference.TotalHours.ToString());
  3276. if(TimeDifference.TotalHours >= this.BFBCS_UpdateInterval && this.StatsTracker[SoldierName].BFBCS_Stats.Fetching == false)
  3277. {
  3278. this.StatsTracker[SoldierName].BFBCS_Stats.Fetching = true;
  3279. lstSoldierName.Add(SoldierName);
  3280. }
  3281. else if( this.StatsTracker.ContainsKey(SoldierName) == true && this.StatsTracker[SoldierName].BFBCS_Stats.Fetching == true)
  3282. {
  3283. //Do nothing
  3284. }
  3285. else
  3286. {
  3287. if( this.StatsTracker.ContainsKey(SoldierName) == true)
  3288. {
  3289. //this.DebugInfo("No Update needed");
  3290. this.StatsTracker[SoldierName].BFBCS_Stats.Updated = true;
  3291. this.StatsTracker[SoldierName].BFBCS_Stats.Rank = Convert.ToInt32(result[1]);
  3292. this.StatsTracker[SoldierName].BFBCS_Stats.Kills = Convert.ToInt32(result[2]);
  3293. this.StatsTracker[SoldierName].BFBCS_Stats.Deaths = Convert.ToInt32(result[3]);
  3294. this.StatsTracker[SoldierName].BFBCS_Stats.Score = Convert.ToInt32(result[4]);
  3295. this.StatsTracker[SoldierName].BFBCS_Stats.Time = Convert.ToDouble(result[5]);
  3296. this.StatsTracker[SoldierName].BFBCS_Stats.NoUpdate = true;
  3297. this.checkPlayerStats(SoldierName,this.m_strReasonMsg);
  3298. }
  3299. }
  3300. }
  3301. }
  3302. }
  3303. if(lstSoldierName != null && lstSoldierName.Count > 0 && lstSoldierName.Count >= this.BFBCS_Min_Request)
  3304. {
  3305. //Start Fetching
  3306. specialArrayObject ListObject = new specialArrayObject(lstSoldierName);
  3307. Thread newThread = new Thread(new ParameterizedThreadStart(this.DownloadBFBCS));
  3308. newThread.Start(ListObject);
  3309. }
  3310. else
  3311. {
  3312. foreach(string player in lstSoldierName)
  3313. {
  3314. this.StatsTracker[player].BFBCS_Stats.Fetching = false;
  3315. this.StatsTracker[player].BFBCS_Stats.Updated = false;
  3316. }
  3317. }
  3318. }
  3319. catch (Exception c)
  3320. {
  3321. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in getBFBCStats: " + c);
  3322. }
  3323. }
  3324. public void DownloadBFBCS(object ListObject)
  3325. {
  3326. specialArrayObject ListString = (specialArrayObject)ListObject;
  3327. List<string> lstSoldierName = new List<string>();
  3328. lstSoldierName = ListString.LstString;
  3329. string ParameterString ="";
  3330. foreach(string SoldierName in lstSoldierName)
  3331. {
  3332. if(this.StatsTracker[SoldierName].BFBCS_Stats.Updated == false)
  3333. {
  3334. ParameterString = String.Concat(ParameterString,SoldierName,",");
  3335. this.StatsTracker[SoldierName].BFBCS_Stats.Updated = true;
  3336. }
  3337. }
  3338. ParameterString = ParameterString.Remove(ParameterString.LastIndexOf(","));
  3339. try
  3340. {
  3341. this.DebugInfo("Thread started and fetching Stats from BFBCS for Players: " + ParameterString);
  3342. WebClient wc = new WebClient();
  3343. string result = wc.DownloadString("http://api.bfbcs.com/api/pc?players=" + ParameterString + "&fields=basic");
  3344. if(result == null || result.StartsWith("{") == false)
  3345. {
  3346. this.DebugInfo("the String returned by BFBCS was invalid");
  3347. this.DebugInfo("Trying to repair the String...");
  3348. if(result != null)
  3349. {
  3350. //result = result.Remove(result.IndexOf("<"),(result.LastIndexOf(">")+1));
  3351. if(result.IndexOf("{") > 0)
  3352. {
  3353. result = result.Substring(result.IndexOf("{"));
  3354. }
  3355. if(result == null || result.StartsWith("{") == false)
  3356. {
  3357. this.DebugInfo("Repair failed!!!");
  3358. return;
  3359. }
  3360. else
  3361. {
  3362. this.DebugInfo("Repair (might be) successful");
  3363. }
  3364. }
  3365. else
  3366. {
  3367. this.DebugInfo("Empty String...");
  3368. return;
  3369. }
  3370. }
  3371. //JSON DECODE
  3372. Hashtable jsonHash = (Hashtable)JSON.JsonDecode(result);
  3373. if(jsonHash["players"] != null)
  3374. {
  3375. ArrayList jsonResults = (ArrayList)jsonHash["players"];
  3376. //Player with Stats
  3377. foreach(object objResult in jsonResults)
  3378. {
  3379. string stringvalue ="";
  3380. int intvalue = 0;
  3381. double doublevalue = 0;
  3382. Hashtable playerData = (Hashtable)objResult;
  3383. if(playerData != null && lstSoldierName.Contains(playerData["name"].ToString()) == true)
  3384. {
  3385. stringvalue = playerData["name"].ToString();
  3386. this.DebugInfo("Got BFBC2 stats for " + stringvalue);
  3387. int.TryParse(playerData["rank"].ToString(), out intvalue);
  3388. this.StatsTracker[stringvalue].BFBCS_Stats.Rank = intvalue;
  3389. int.TryParse(playerData["kills"].ToString(), out intvalue);
  3390. this.StatsTracker[stringvalue].BFBCS_Stats.Kills = intvalue;
  3391. int.TryParse(playerData["deaths"].ToString(), out intvalue);
  3392. this.StatsTracker[stringvalue].BFBCS_Stats.Deaths = intvalue;
  3393. int.TryParse(playerData["score"].ToString(), out intvalue);
  3394. this.StatsTracker[stringvalue].BFBCS_Stats.Score = intvalue;
  3395. double.TryParse(playerData["elo"].ToString(), out doublevalue);
  3396. this.StatsTracker[stringvalue].BFBCS_Stats.Elo = doublevalue;
  3397. double.TryParse(playerData["level"].ToString(), out doublevalue);
  3398. this.StatsTracker[stringvalue].BFBCS_Stats.Skilllevel = doublevalue;
  3399. double.TryParse(playerData["time"].ToString(), out doublevalue);
  3400. this.StatsTracker[stringvalue].BFBCS_Stats.Time = doublevalue;
  3401. this.StatsTracker[stringvalue].BFBCS_Stats.Updated = true;
  3402. // check Stats
  3403. if(this.m_cheaterProtection == enumBoolYesNo.Yes == true)
  3404. {
  3405. this.checkPlayerStats(stringvalue, this.m_strReasonMsg);
  3406. }
  3407. }
  3408. }
  3409. }
  3410. if(jsonHash["players_unknown"] != null)
  3411. {
  3412. //Player without Stats
  3413. ArrayList jsonResults_2 = (ArrayList)jsonHash["players_unknown"];
  3414. foreach(object objResult in jsonResults_2)
  3415. {
  3416. Hashtable playerData = (Hashtable)objResult;
  3417. if(playerData != null && lstSoldierName.Contains(playerData["name"].ToString()) == true)
  3418. {
  3419. this.DebugInfo("No Stats found for Player: " + playerData["name"].ToString());
  3420. }
  3421. }
  3422. }
  3423. }
  3424. catch (Exception c)
  3425. {
  3426. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in DownloadBFBCS: " + c);
  3427. foreach(string SoldierName in lstSoldierName)
  3428. {
  3429. this.StatsTracker[SoldierName].BFBCS_Stats.Updated = false;
  3430. }
  3431. }
  3432. }
  3433. public void checkPlayerStats(string SoldierName, string Reason)
  3434. {
  3435. try
  3436. {
  3437. if(this.StatsTracker.ContainsKey(SoldierName) == true)
  3438. {
  3439. if((this.StatsTracker[SoldierName].BFBCS_Stats.KDR >= this.m_dMaxAllowedKDR && this.StatsTracker[SoldierName].BFBCS_Stats.SPM >= this.m_dMaxScorePerMinute) && (this.StatsTracker[SoldierName].BFBCS_Stats.Time/60)/60 >= this.m_dminimumPlaytime )
  3440. //if(this.StatsTracker[SoldierName].BFBCS_Stats.KDR >= this.m_dMaxAllowedKDR)
  3441. {
  3442. this.RemovePlayerfromServer(SoldierName, Reason.Replace("%SoldierName%", SoldierName));
  3443. }
  3444. }
  3445. }
  3446. catch(Exception c)
  3447. {
  3448. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in checkPlayerStats: " + c);
  3449. }
  3450. }
  3451. public void RemovePlayerfromServer(string targetSoldierName, string strReason)
  3452. {
  3453. try
  3454. {
  3455. if(targetSoldierName == string.Empty)
  3456. {
  3457. return;
  3458. }
  3459. switch (this.m_strRemoveMethode) {
  3460. case "Kick" :
  3461. this.ExecuteCommand("procon.protected.send", "admin.kickPlayer", targetSoldierName, strReason);
  3462. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Kicked Player: " + targetSoldierName + " - " + strReason);
  3463. break;
  3464. case "PBBan" :
  3465. this.ExecuteCommand("procon.protected.send", "punkBuster.pb_sv_command", String.Format("pb_sv_ban \"{0}\" \"{1}\"", targetSoldierName, "BC2! " + strReason));
  3466. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1PB-Ban for Player: " + targetSoldierName + " - " + strReason);
  3467. break;
  3468. case "EAGUIDBan" :
  3469. this.ExecuteCommand("procon.protected.send", "banList.add", "guid", this.StatsTracker[targetSoldierName].EAGuid, "perm", strReason);
  3470. this.ExecuteCommand("procon.protected.send", "banList.save");
  3471. this.ExecuteCommand("procon.protected.send", "banList.list");
  3472. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1EA-GUID Ban for Player: " + targetSoldierName + " - " + strReason);
  3473. break;
  3474. case "Nameban" :
  3475. this.ExecuteCommand("procon.protected.send", "banList.add", "name", targetSoldierName, "perm", strReason);
  3476. this.ExecuteCommand("procon.protected.send", "banList.save");
  3477. this.ExecuteCommand("procon.protected.send", "banList.list");
  3478. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Nameban for Player: " + targetSoldierName + " - " + strReason);
  3479. break;
  3480. case "Warn" :
  3481. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Warning Player: " + targetSoldierName + " - " + strReason);
  3482. break;
  3483. }
  3484. }
  3485. catch (Exception c)
  3486. {
  3487. this.ExecuteCommand("procon.protected.pluginconsole.write", "^1Error in RemovePlayerfromServer: " + c);
  3488. }
  3489. }
  3490. }
  3491. #endregion
  3492. #region Classes
  3493. /*==========Classes========*/
  3494. class CLogger
  3495. {
  3496. private readonly string _Name;
  3497. private string _Message = "";
  3498. private string _Subset ="";
  3499. private DateTime _Time;
  3500. public string Name
  3501. {
  3502. get { return _Name; }
  3503. }
  3504. public string Message
  3505. {
  3506. get { return _Message; }
  3507. }
  3508. public string Subset
  3509. {
  3510. get { return _Subset; }
  3511. }
  3512. public DateTime Time
  3513. {
  3514. get { return _Time; }
  3515. }
  3516. public CLogger(DateTime time, string name, string message, string subset)
  3517. {
  3518. _Name = name;
  3519. _Message = message;
  3520. _Subset = subset;
  3521. _Time = time;
  3522. }
  3523. }
  3524. class CStats
  3525. {
  3526. private string _ClanTag;
  3527. private string _Guid;
  3528. private string _EAGuid;
  3529. private string _IP;
  3530. private string _PlayerCountryCode;
  3531. private int _Score = 0;
  3532. private int _LastScore = 0;
  3533. private int _Kills = 0;
  3534. private int _Headshots = 0;
  3535. private int _Deaths = 0;
  3536. private int _Suicides = 0;
  3537. private int _Teamkills = 0;
  3538. private int _Playtime = 0;
  3539. private DateTime _Playerjoined;
  3540. private DateTime _TimePlayerleft;
  3541. private DateTime _TimePlayerjoined;
  3542. private int _PlayerleftServerScore = 0;
  3543. private bool _playerOnServer = false;
  3544. private int _rank = 0;
  3545. //Streaks
  3546. private int _Killstreak;
  3547. private int _Deathstreak;
  3548. private int _Killcount;
  3549. private int _Deathcount;
  3550. //BFBCS
  3551. private CBFBCS _BFBCS_Stats;
  3552. private myDateTime MyDateTime = new myDateTime(0);
  3553. public Dictionary<string, CUsedWeapon> dicWeap = new Dictionary<string, CUsedWeapon>();
  3554. public string ClanTag {
  3555. get { return _ClanTag; }
  3556. set { _ClanTag = value; }
  3557. }
  3558. public string Guid {
  3559. get { return _Guid; }
  3560. set { _Guid = value; }
  3561. }
  3562. public string EAGuid {
  3563. get { return _EAGuid; }
  3564. set { _EAGuid = value; }
  3565. }
  3566. public string IP {
  3567. get { return _IP; }
  3568. set { _IP = value.Remove(value.IndexOf(":")); }
  3569. }
  3570. public string PlayerCountryCode {
  3571. get { return _PlayerCountryCode; }
  3572. set { _PlayerCountryCode = value; }
  3573. }
  3574. public int Score {
  3575. get { return _Score; }
  3576. set { _Score = value; }
  3577. }
  3578. public int LastScore {
  3579. get { return _LastScore; }
  3580. set { _LastScore = value; }
  3581. }
  3582. public int Kills {
  3583. get { return _Kills; }
  3584. set { _Kills = value; }
  3585. }
  3586. public int Headshots {
  3587. get { return _Headshots; }
  3588. set { _Headshots = value; }
  3589. }
  3590. public int Deaths {
  3591. get { return _Deaths; }
  3592. set { _Deaths = value; }
  3593. }
  3594. public int Suicides {
  3595. get { return _Suicides; }
  3596. set { _Suicides = value; }
  3597. }
  3598. public int Teamkills {
  3599. get { return _Teamkills; }
  3600. set { _Teamkills = value; }
  3601. }
  3602. public int Playtime {
  3603. get { return _Playtime; }
  3604. set { _Playtime = value; }
  3605. }
  3606. public DateTime Playerjoined {
  3607. get { return _Playerjoined; }
  3608. set { _Playerjoined = value; }
  3609. }
  3610. public DateTime TimePlayerleft {
  3611. get { return _TimePlayerleft; }
  3612. set { _TimePlayerleft = value; }
  3613. }
  3614. public DateTime TimePlayerjoined {
  3615. get { return _TimePlayerjoined; }
  3616. set { _TimePlayerjoined = value; }
  3617. }
  3618. public int PlayerleftServerScore {
  3619. get { return _PlayerleftServerScore; }
  3620. set { _PlayerleftServerScore = value; }
  3621. }
  3622. public bool PlayerOnServer {
  3623. get { return _playerOnServer; }
  3624. set { _playerOnServer = value; }
  3625. }
  3626. public int Rank {
  3627. get { return _rank; }
  3628. set { _rank = value; }
  3629. }
  3630. public int Killstreak {
  3631. get { return _Killstreak; }
  3632. set { _Killstreak = value; }
  3633. }
  3634. public int Deathstreak {
  3635. get { return _Deathstreak; }
  3636. set { _Deathstreak = value; }
  3637. }
  3638. //Methodes
  3639. public void AddScore(int intScore)
  3640. {
  3641. if(intScore != 0)
  3642. {
  3643. this._Score = this._Score + (intScore - this._LastScore);
  3644. this._LastScore = intScore;
  3645. }
  3646. else
  3647. {
  3648. this._LastScore = 0;
  3649. }
  3650. }
  3651. public double KDR()
  3652. {
  3653. double ratio = 0;
  3654. if(this._Deaths != 0)
  3655. {
  3656. ratio = Math.Round(Convert.ToDouble(this._Kills)/Convert.ToDouble(this._Deaths),2);
  3657. }
  3658. else
  3659. {
  3660. ratio = this._Kills;
  3661. }
  3662. return ratio;
  3663. }
  3664. public Dictionary<string, CUsedWeapon> getWeaponKills()
  3665. {
  3666. return this.dicWeap;
  3667. }
  3668. public void addKill(string strweaponType, bool blheadshot)
  3669. {
  3670. //Start of the convert block
  3671. strweaponType = strweaponType.Replace(" ","");
  3672. if((String.Equals(strweaponType,""))||(String.Equals(strweaponType," ")))
  3673. {
  3674. strweaponType = "UNKNOWN";
  3675. }
  3676. if(strweaponType.Contains("#"))
  3677. {
  3678. int intindex = strweaponType.IndexOf("#");
  3679. strweaponType = strweaponType.Remove(intindex);
  3680. }
  3681. strweaponType = strweaponType.ToUpper();
  3682. //End of the convert block
  3683. if(this.dicWeap.ContainsKey(strweaponType))
  3684. {
  3685. if(blheadshot)
  3686. {
  3687. this.dicWeap[strweaponType].Kills++;
  3688. this.dicWeap[strweaponType].Headshots++;
  3689. this._Kills++;
  3690. this._Headshots++;
  3691. }
  3692. else
  3693. {
  3694. this.dicWeap[strweaponType].Kills++;
  3695. this._Kills++;
  3696. }
  3697. }
  3698. else
  3699. {
  3700. if(blheadshot)
  3701. {
  3702. CUsedWeapon killinfo = new CUsedWeapon(1,1,0);
  3703. this.dicWeap.Add(strweaponType,killinfo);
  3704. this._Kills++;
  3705. this._Headshots++;
  3706. }
  3707. else
  3708. {
  3709. CUsedWeapon killinfo = new CUsedWeapon(1,0,0);
  3710. this.dicWeap.Add(strweaponType,killinfo);
  3711. this._Kills++;
  3712. }
  3713. }
  3714. //Killstreaks
  3715. this._Killcount++;
  3716. this._Deathcount = 0;
  3717. if(this._Killcount > this._Killstreak)
  3718. {
  3719. this._Killstreak = this._Killcount;
  3720. }
  3721. }
  3722. public void addDeath(string strweaponType)
  3723. {
  3724. //Start of the convert block
  3725. strweaponType = strweaponType.Replace(" ","");
  3726. if((String.Equals(strweaponType,""))||(String.Equals(strweaponType," ")))
  3727. {
  3728. strweaponType = "UNKNOWN";
  3729. }
  3730. if(strweaponType.Contains("#"))
  3731. {
  3732. int intindex = strweaponType.IndexOf("#");
  3733. strweaponType = strweaponType.Remove(intindex);
  3734. }
  3735. strweaponType = strweaponType.ToUpper();
  3736. //End of the convert block
  3737. if(this.dicWeap.ContainsKey(strweaponType))
  3738. {
  3739. this.dicWeap[strweaponType].Deaths++;
  3740. this._Deaths++;
  3741. }
  3742. else
  3743. {
  3744. CUsedWeapon deathinfo = new CUsedWeapon(0,0,1);
  3745. this.dicWeap.Add(strweaponType,deathinfo);
  3746. this._Deaths++;
  3747. }
  3748. //Deathstreak
  3749. this._Deathcount++;
  3750. this._Killcount = 0;
  3751. if(this._Deathcount > this._Deathstreak)
  3752. {
  3753. this._Deathstreak = this._Deathcount;
  3754. }
  3755. }
  3756. public void playerleft()
  3757. {
  3758. //Score
  3759. this._PlayerleftServerScore += this._Score;
  3760. this._Score = 0;
  3761. //Time
  3762. TimeSpan duration = MyDateTime.Now - this._Playerjoined;
  3763. this._Playtime += Convert.ToInt32(duration.TotalSeconds);
  3764. this._playerOnServer = false;
  3765. }
  3766. public int TotalScore
  3767. {
  3768. get{ return (this._PlayerleftServerScore + this._Score);}
  3769. }
  3770. public int TotalPlaytime
  3771. {
  3772. get
  3773. {
  3774. if(this._playerOnServer)
  3775. {
  3776. TimeSpan duration = MyDateTime.Now - this._Playerjoined;
  3777. this._Playtime += Convert.ToInt32(duration.TotalSeconds);
  3778. }
  3779. return this._Playtime;
  3780. }
  3781. }
  3782. public CStats.CBFBCS BFBCS_Stats {
  3783. get { return _BFBCS_Stats; }
  3784. set { _BFBCS_Stats = value; }
  3785. }
  3786. public class CUsedWeapon
  3787. {
  3788. private int _Kills = 0;
  3789. private int _Headshots = 0;
  3790. private int _Deaths = 0;
  3791. public int Kills {
  3792. get { return _Kills; }
  3793. set { _Kills = value; }
  3794. }
  3795. public int Headshots {
  3796. get { return _Headshots; }
  3797. set { _Headshots = value; }
  3798. }
  3799. public int Deaths {
  3800. get { return _Deaths; }
  3801. set { _Deaths = value; }
  3802. }
  3803. public CUsedWeapon(int kills, int headshots, int deaths)
  3804. {
  3805. this._Kills = kills;
  3806. this._Headshots = headshots;
  3807. this._Deaths = deaths;
  3808. }
  3809. }
  3810. public class CBFBCS
  3811. {
  3812. private int _rank;
  3813. private int _kills;
  3814. private int _deaths;
  3815. private int _score;
  3816. private double _skilllevel;
  3817. private double _time;
  3818. private double _elo;
  3819. private bool _Updated;
  3820. private bool _fetching;
  3821. private bool _noUpdate;
  3822. public int Rank {
  3823. get { return _rank; }
  3824. set { _rank = value; }
  3825. }
  3826. public int Kills {
  3827. get { return _kills; }
  3828. set { _kills = value; }
  3829. }
  3830. public int Deaths {
  3831. get { return _deaths; }
  3832. set { _deaths = value; }
  3833. }
  3834. public double KDR {
  3835. get{
  3836. double ratio = 0;
  3837. if(this._deaths != 0)
  3838. {
  3839. ratio = Math.Round(Convert.ToDouble(this._kills)/Convert.ToDouble(this._deaths),2);
  3840. }
  3841. else
  3842. {
  3843. ratio = this._kills;
  3844. }
  3845. return ratio;
  3846. }
  3847. }
  3848. public double SPM {
  3849. get{
  3850. return Convert.ToDouble(this._score)/(this._time/60);
  3851. }
  3852. }
  3853. public int Score {
  3854. get { return _score; }
  3855. set { _score = value; }
  3856. }
  3857. public double Skilllevel {
  3858. get { return _skilllevel; }
  3859. set { _skilllevel = value; }
  3860. }
  3861. public double Time {
  3862. get { return _time; }
  3863. set { _time = value; }
  3864. }
  3865. public double Elo {
  3866. get { return _elo; }
  3867. set { _elo = value; }
  3868. }
  3869. public bool Updated {
  3870. get { return _Updated; }
  3871. set { _Updated = value; }
  3872. }
  3873. public bool Fetching {
  3874. get { return _fetching; }
  3875. set { _fetching = value; }
  3876. }
  3877. public bool NoUpdate {
  3878. get { return _noUpdate; }
  3879. set { _noUpdate = value; }
  3880. }
  3881. public CBFBCS()
  3882. {
  3883. this._rank = 0;
  3884. this._kills = 0;
  3885. this._deaths = 0;
  3886. this._score = 0;
  3887. this._skilllevel = 0;
  3888. this._time = 0;
  3889. this._elo = 0;
  3890. this._Updated = false;
  3891. this._fetching = false;
  3892. this._noUpdate = false;
  3893. }
  3894. }
  3895. public class myDateTime
  3896. {
  3897. private double _offset = 0;
  3898. public DateTime Now {
  3899. get {
  3900. DateTime dateValue = DateTime.Now;
  3901. return dateValue.AddHours(_offset); }
  3902. }
  3903. public myDateTime(double offset)
  3904. {
  3905. this._offset = offset;
  3906. }
  3907. }
  3908. public CStats(string guid, int score, int kills, int headshots, int deaths, int suicides, int teamkills, int playtime, double timeoffset)
  3909. {
  3910. this._ClanTag = String.Empty;
  3911. this._Guid = guid;
  3912. this._EAGuid = String.Empty;
  3913. this._IP = String.Empty;
  3914. this._Score = score;
  3915. this._LastScore = 0;
  3916. this._Kills = kills;
  3917. this._Headshots = headshots;
  3918. this._Deaths = deaths;
  3919. this._Suicides = suicides;
  3920. this._Teamkills = teamkills;
  3921. this._Playtime = playtime;
  3922. this._PlayerleftServerScore = 0;
  3923. this._PlayerCountryCode= String.Empty;
  3924. this._TimePlayerjoined = MyDateTime.Now;
  3925. this._TimePlayerleft = DateTime.MinValue;
  3926. this._rank = 0;
  3927. this._Killcount = 0;
  3928. this._Killstreak = 0;
  3929. this._Deathcount = 0;
  3930. this._Deathstreak = 0;
  3931. this.BFBCS_Stats = new CStats.CBFBCS();
  3932. this.MyDateTime = new myDateTime(timeoffset);
  3933. }
  3934. }
  3935. class C_ID_Cache
  3936. {
  3937. private int _Id;
  3938. private bool _PlayeronServer;
  3939. public int Id {
  3940. get { return _Id; }
  3941. set { _Id = value; }
  3942. }
  3943. public bool PlayeronServer {
  3944. get { return _PlayeronServer; }
  3945. set { _PlayeronServer = value; }
  3946. }
  3947. //Constructor
  3948. public C_ID_Cache(int id, bool playeronServer)
  3949. {
  3950. this._Id = id;
  3951. this._PlayeronServer = playeronServer;
  3952. }
  3953. }
  3954. class CKillerVictim
  3955. {
  3956. string _Killer;
  3957. string _Victim;
  3958. public string Killer {
  3959. get { return _Killer; }
  3960. set { _Killer = value; }
  3961. }
  3962. public string Victim {
  3963. get { return _Victim; }
  3964. set { _Victim = value; }
  3965. }
  3966. public CKillerVictim(string killer, string victim)
  3967. {
  3968. this._Killer = killer;
  3969. this._Victim = victim;
  3970. }
  3971. }
  3972. class CMapstats
  3973. {
  3974. private DateTime _timeMaploaded;
  3975. private DateTime _timeMapStarted;
  3976. private DateTime _timeRoundEnd;
  3977. private string _strMapname;
  3978. private string _strGamemode;
  3979. private int _intRound;
  3980. private int _intNumberOfRounds;
  3981. private List<int> _lstPlayers;
  3982. private int _intMinPlayers;
  3983. private int _intMaxPlayers;
  3984. private int _intServerplayermax;
  3985. private double _doubleAvgPlayers;
  3986. private int _intplayerleftServer;
  3987. private int _intplayerjoinedServer;
  3988. private myDateTime MyDateTime = new myDateTime(0);
  3989. public DateTime TimeMaploaded {
  3990. get { return _timeMaploaded; }
  3991. set { _timeMaploaded = value; }
  3992. }
  3993. public DateTime TimeMapStarted {
  3994. get { return _timeMapStarted; }
  3995. set { _timeMapStarted = value; }
  3996. }
  3997. public DateTime TimeRoundEnd {
  3998. get { return _timeRoundEnd; }
  3999. set { _timeRoundEnd = value; }
  4000. }
  4001. public string StrMapname {
  4002. get { return _strMapname; }
  4003. set { _strMapname = value; }
  4004. }
  4005. public string StrGamemode {
  4006. get { return _strGamemode; }
  4007. set { _strGamemode = value; }
  4008. }
  4009. public int IntRound {
  4010. get { return _intRound; }
  4011. set { _intRound = value; }
  4012. }
  4013. public int IntNumberOfRounds {
  4014. get { return _intNumberOfRounds; }
  4015. set { _intNumberOfRounds = value; }
  4016. }
  4017. public List<int> LstPlayers {
  4018. get { return _lstPlayers; }
  4019. set { _lstPlayers = value; }
  4020. }
  4021. public int IntMinPlayers {
  4022. get { return _intMinPlayers; }
  4023. set { _intMinPlayers = value; }
  4024. }
  4025. public int IntMaxPlayers {
  4026. get { return _intMaxPlayers; }
  4027. set { _intMaxPlayers = value; }
  4028. }
  4029. public int IntServerplayermax {
  4030. get { return _intServerplayermax; }
  4031. set { _intServerplayermax = value; }
  4032. }
  4033. public double DoubleAvgPlayers {
  4034. get { return _doubleAvgPlayers; }
  4035. set { _doubleAvgPlayers = value; }
  4036. }
  4037. public int IntplayerleftServer {
  4038. get { return _intplayerleftServer; }
  4039. set { _intplayerleftServer = value; }
  4040. }
  4041. public int IntplayerjoinedServer {
  4042. get { return _intplayerjoinedServer; }
  4043. set { _intplayerjoinedServer = value; }
  4044. }
  4045. public void MapStarted()
  4046. {
  4047. this._timeMapStarted = MyDateTime.Now;
  4048. }
  4049. public void MapEnd()
  4050. {
  4051. this._timeRoundEnd = MyDateTime.Now;
  4052. }
  4053. public void ListADD(int entry)
  4054. {
  4055. this._lstPlayers.Add(entry);
  4056. }
  4057. public void calcMaxMinAvgPlayers()
  4058. {
  4059. this._intMaxPlayers = 0;
  4060. this._intMinPlayers = _intServerplayermax;
  4061. this._doubleAvgPlayers = 0;
  4062. int entries = 0;
  4063. foreach(int playercount in this._lstPlayers)
  4064. {
  4065. if( playercount >= this._intMaxPlayers)
  4066. this._intMaxPlayers = playercount;
  4067. if( playercount <= this._intMinPlayers)
  4068. this._intMinPlayers = playercount;
  4069. this._doubleAvgPlayers = this._doubleAvgPlayers + playercount;
  4070. entries = entries + 1;
  4071. }
  4072. if(entries != 0)
  4073. {
  4074. this._doubleAvgPlayers = this._doubleAvgPlayers/(Convert.ToDouble(entries));
  4075. this._doubleAvgPlayers = Math.Round(this._doubleAvgPlayers,1);
  4076. }
  4077. else
  4078. {
  4079. this._doubleAvgPlayers = 0;
  4080. this._intMaxPlayers = 0;
  4081. this._intMinPlayers = 0;
  4082. }
  4083. }
  4084. public class myDateTime
  4085. {
  4086. private double _offset = 0;
  4087. public DateTime Now {
  4088. get {
  4089. DateTime dateValue = DateTime.Now;
  4090. return dateValue.AddHours(_offset); }
  4091. }
  4092. public myDateTime(double offset)
  4093. {
  4094. this._offset = offset;
  4095. }
  4096. }
  4097. public CMapstats(DateTime timeMaploaded, string strMapname, int intRound, int intNumberOfRounds, double timeoffset)
  4098. {
  4099. this._timeMaploaded = timeMaploaded;
  4100. this._strMapname = strMapname;
  4101. this._intRound = intRound;
  4102. this._intNumberOfRounds = intNumberOfRounds;
  4103. this._intMaxPlayers = 32;
  4104. this._intServerplayermax= 32;
  4105. this._intMinPlayers = 0;
  4106. this._intplayerjoinedServer = 0;
  4107. this._intplayerleftServer = 0;
  4108. this._lstPlayers = new List<int>();
  4109. this._timeMapStarted = DateTime.MinValue;
  4110. this._timeRoundEnd = DateTime.MinValue;
  4111. this._strGamemode = "";
  4112. this.MyDateTime = new myDateTime(timeoffset);
  4113. }
  4114. }
  4115. class CSpamprotection
  4116. {
  4117. private Dictionary<string, int> dicplayer;
  4118. private int _allowedRequests;
  4119. public CSpamprotection(int allowedRequests)
  4120. {
  4121. this._allowedRequests = allowedRequests;
  4122. this.dicplayer = new Dictionary<string, int>();
  4123. }
  4124. public bool isAllowed(string strSpeaker)
  4125. {
  4126. bool result = false;
  4127. if(this.dicplayer.ContainsKey(strSpeaker) == true)
  4128. {
  4129. int i = this.dicplayer[strSpeaker];
  4130. if(0 >= i)
  4131. {
  4132. //Player is blocked
  4133. result = false;
  4134. this.dicplayer[strSpeaker]--;
  4135. }
  4136. else
  4137. {
  4138. //Player is not blocked
  4139. result = true;
  4140. this.dicplayer[strSpeaker] --;
  4141. }
  4142. }
  4143. else
  4144. {
  4145. this.dicplayer.Add(strSpeaker,this._allowedRequests);
  4146. result = true;
  4147. this.dicplayer[strSpeaker] --;
  4148. }
  4149. return result;
  4150. }
  4151. public void Reset()
  4152. {
  4153. this.dicplayer.Clear();
  4154. }
  4155. }
  4156. class specialArrayObject
  4157. {
  4158. private List<string> lstString = new List<string>();
  4159. public List<string> LstString {
  4160. get { return lstString; }
  4161. set { lstString = value; }
  4162. }
  4163. public specialArrayObject(List<string> LstString)
  4164. {
  4165. lstString = LstString;
  4166. }
  4167. }
  4168. class myDateTime_W
  4169. {
  4170. private double _offset = 0;
  4171. public DateTime Now {
  4172. get {
  4173. DateTime dateValue = DateTime.Now;
  4174. return dateValue.AddHours(_offset); }
  4175. }
  4176. public myDateTime_W(double offset)
  4177. {
  4178. this._offset = offset;
  4179. }
  4180. }
  4181. #endregion
  4182. }