mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 15:55:39 +02:00
Code cleanup
This commit is contained in:
@@ -143,19 +143,23 @@ public class DatabaseController
|
|||||||
// Add parameters - prevent SQL injection
|
// Add parameters - prevent SQL injection
|
||||||
if (TCPFrameType == "50")
|
if (TCPFrameType == "50")
|
||||||
{
|
{
|
||||||
|
// Chat entry
|
||||||
DatabaseCommand.Parameters.AddWithValue("@PAR_payload_player", TCPFrame.payload.player);
|
DatabaseCommand.Parameters.AddWithValue("@PAR_payload_player", TCPFrame.payload.player);
|
||||||
DatabaseCommand.Parameters.AddWithValue("@PAR_payload_msg", TCPFrame.payload.msg);
|
DatabaseCommand.Parameters.AddWithValue("@PAR_payload_msg", TCPFrame.payload.msg);
|
||||||
}
|
}
|
||||||
else if (TCPFrameType == "51")
|
else if (TCPFrameType == "51")
|
||||||
{
|
{
|
||||||
|
// Event entry
|
||||||
DatabaseCommand.Parameters.AddWithValue("@PAR_log_content", TCPFrame.payload.log_content);
|
DatabaseCommand.Parameters.AddWithValue("@PAR_log_content", TCPFrame.payload.log_content);
|
||||||
}
|
}
|
||||||
else if (TCPFrameType == "53")
|
else if (TCPFrameType == "53")
|
||||||
{
|
{
|
||||||
|
// Stats entry
|
||||||
DatabaseCommand.Parameters.AddWithValue("@PAR_login_name", TCPFrame.payload.login_name);
|
DatabaseCommand.Parameters.AddWithValue("@PAR_login_name", TCPFrame.payload.login_name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Others
|
||||||
TCPFramePayload = JsonConvert.SerializeObject(TCPFrame.payload); // Deserialize payload
|
TCPFramePayload = JsonConvert.SerializeObject(TCPFrame.payload); // Deserialize payload
|
||||||
DatabaseCommand.Parameters.AddWithValue("@PAR_TCPFramePayload", TCPFramePayload);
|
DatabaseCommand.Parameters.AddWithValue("@PAR_TCPFramePayload", TCPFramePayload);
|
||||||
}
|
}
|
||||||
@@ -179,6 +183,7 @@ public class DatabaseController
|
|||||||
|
|
||||||
DatabaseReader.Close();
|
DatabaseReader.Close();
|
||||||
|
|
||||||
|
// Add information to log
|
||||||
switch (Int32.Parse(TCPFrameType))
|
switch (Int32.Parse(TCPFrameType))
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@@ -230,13 +235,13 @@ public class DatabaseController
|
|||||||
// MySQL exception found
|
// MySQL exception found
|
||||||
switch (m_ex.Number)
|
switch (m_ex.Number)
|
||||||
{
|
{
|
||||||
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
case 0: // Access denied (Check DB name,username,password)
|
||||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1, TCPFrameType);
|
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message, 1, 1, TCPFrameType);
|
||||||
DatabaseStatus = false;
|
DatabaseStatus = false;
|
||||||
ReturnValue = 0;
|
ReturnValue = 0;
|
||||||
break;
|
break;
|
||||||
case 0: // Access denied (Check DB name,username,password)
|
case 1042: // Unable to connect to any of the specified MySQL hosts (Check Server,Port)
|
||||||
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - access denied, error: " + m_ex.Message,1,1, TCPFrameType);
|
PerunHelper.LogError(ref Globals.AppLogHistory, "ERROR MySQL - unable to connect, error: " + m_ex.Message,1,1, TCPFrameType);
|
||||||
DatabaseStatus = false;
|
DatabaseStatus = false;
|
||||||
ReturnValue = 0;
|
ReturnValue = 0;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -5,18 +5,22 @@
|
|||||||
class CurrentMissionClass
|
class CurrentMissionClass
|
||||||
{
|
{
|
||||||
|
|
||||||
public string Theatre = "";
|
public string Theatre = ""; // Mission theathre
|
||||||
public string Mission = "";
|
public string Mission = ""; // Mission name
|
||||||
public string Pause = "";
|
|
||||||
public int PlayerCount = 0;
|
public string Pause = ""; // Mission pause
|
||||||
|
public int PlayerCount = 0; // Actual player time
|
||||||
|
|
||||||
public string ToInfoString()
|
public string ToInfoString()
|
||||||
{
|
{
|
||||||
|
// Return mission information as string
|
||||||
if (this.Mission != "")
|
if (this.Mission != "")
|
||||||
{
|
{
|
||||||
|
// Return mission information as string
|
||||||
return "Mission: " + this.Mission + "(" + this.Theatre + ") Pause:" + this.Pause + " Players: " + this.PlayerCount;
|
return "Mission: " + this.Mission + "(" + this.Theatre + ") Pause:" + this.Pause + " Players: " + this.PlayerCount;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
// Mission information is not available
|
||||||
return "Mission: Unknown";
|
return "Mission: Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,6 +39,7 @@ internal class Globals
|
|||||||
public static bool StatusLotATC = false; // Historic lotatc connection status
|
public static bool StatusLotATC = false; // Historic lotatc connection status
|
||||||
public static bool StatusHistoryConnection = false; // Historic tcp connection status
|
public static bool StatusHistoryConnection = false; // Historic tcp connection status
|
||||||
public static bool StatusConnection = false; // Flag if is TCP connectionstill alive
|
public static bool StatusConnection = false; // Flag if is TCP connectionstill alive
|
||||||
|
|
||||||
public static int ErrorsDatabase = 0; // MySQL - Error counter
|
public static int ErrorsDatabase = 0; // MySQL - Error counter
|
||||||
public static int ErrorsGame = 0; // TCP connection - Error counter
|
public static int ErrorsGame = 0; // TCP connection - Error counter
|
||||||
public static int ErrorsHistoryGame = 0; // TCP connection - historic value of Error counter
|
public static int ErrorsHistoryGame = 0; // TCP connection - historic value of Error counter
|
||||||
@@ -44,6 +49,7 @@ internal class Globals
|
|||||||
public static string VersionDCSHook = ""; // Version - DCS hook
|
public static string VersionDCSHook = ""; // Version - DCS hook
|
||||||
public static string VersionDatabase = ""; // Version - Database
|
public static string VersionDatabase = ""; // Version - Database
|
||||||
public static string VersionPerun = "DEBUG"; // Version - Perun
|
public static string VersionPerun = "DEBUG"; // Version - Perun
|
||||||
public static CurrentMissionClass CurrentMission = new CurrentMissionClass(); // Mission - name
|
|
||||||
|
public static CurrentMissionClass CurrentMission = new CurrentMissionClass(); // Actual mission information
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,44 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
|
// Singleton class - log controller
|
||||||
class LogController
|
class LogController
|
||||||
{
|
{
|
||||||
private static LogController _instance = new LogController();
|
private static LogController _instance = new LogController(); // Singleton instance
|
||||||
|
|
||||||
public static LogController instance
|
public static LogController instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _instance;
|
return _instance; // Return current instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int level
|
public int level
|
||||||
{
|
{
|
||||||
get;
|
get; // Get debug level
|
||||||
set;
|
set; // Set debug level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log error information
|
||||||
public void LogError(string strLog)
|
public void LogError(string strLog)
|
||||||
{
|
{
|
||||||
this.WriteLog(0, strLog);
|
this.WriteLog(0, strLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log warning information
|
||||||
public void LogWarning(string strLog)
|
public void LogWarning(string strLog)
|
||||||
{
|
{
|
||||||
this.WriteLog(1, strLog);
|
this.WriteLog(1, strLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log info information
|
||||||
public void LogInfo(string strLog)
|
public void LogInfo(string strLog)
|
||||||
{
|
{
|
||||||
this.WriteLog(2, strLog);
|
this.WriteLog(2, strLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log debug information
|
||||||
public void LogDebug(string strLog)
|
public void LogDebug(string strLog)
|
||||||
{
|
{
|
||||||
this.WriteLog(3, strLog);
|
this.WriteLog(3, strLog);
|
||||||
@@ -79,5 +84,7 @@ class LogController
|
|||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TBD: log rotation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,26 +5,31 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
internal class PerunHelper
|
internal class PerunHelper
|
||||||
{
|
{
|
||||||
|
// Add error infomation
|
||||||
public static void LogError(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
public static void LogError(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||||
{
|
{
|
||||||
AddLog(0, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
AddLog(0, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add warning information
|
||||||
public static void LogWarning(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
public static void LogWarning(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||||
{
|
{
|
||||||
AddLog(1, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
AddLog(1, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add info information
|
||||||
public static void LogInfo(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
public static void LogInfo(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||||
{
|
{
|
||||||
AddLog(2, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
AddLog(2, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add debug information
|
||||||
public static void LogDebug(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
public static void LogDebug(ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||||
{
|
{
|
||||||
AddLog(3, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
AddLog(3, ref arrLogHistory, strEntryToAdd, intDirection, intMarker, strType, bSkipGui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add log
|
||||||
private static void AddLog(int logLevel, ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
private static void AddLog(int logLevel, ref string[] arrLogHistory, string strEntryToAdd, int intDirection = 0, int intMarker = 0, string strType = " ", bool bSkipGui = false)
|
||||||
{
|
{
|
||||||
// Declare values
|
// Declare values
|
||||||
@@ -71,15 +76,16 @@ internal class PerunHelper
|
|||||||
LogController.instance.WriteLog(logLevel, DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd);
|
LogController.instance.WriteLog(logLevel, DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: "+ Globals.AppInstanceID + " | " + LogMarker + " | "+ LogDirection + " | "+ strType + " | " + strEntryToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets build version
|
||||||
public static string GetAppVersion(string strBeginning)
|
public static string GetAppVersion(string strBeginning)
|
||||||
{
|
{
|
||||||
// Gets build version
|
|
||||||
Globals.VersionPerun = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
Globals.VersionPerun = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||||
return strBeginning + "v" + Globals.VersionPerun;
|
return strBeginning + "v" + Globals.VersionPerun;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int CheckVersions()
|
public static int CheckVersions()
|
||||||
{
|
{
|
||||||
|
// Checks if all versions (mysql, winapp, lua) are the same - ommit if run as debug build
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
// Checks the versions of APP, DCS Hook and MySQL database
|
// Checks the versions of APP, DCS Hook and MySQL database
|
||||||
Match match = Regex.Match(Globals.VersionPerun, @"^\d+.\d+.\d+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
Match match = Regex.Match(Globals.VersionPerun, @"^\d+.\d+.\d+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||||
|
|||||||
Reference in New Issue
Block a user