mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 14:45:39 +02:00
Code cleanup
This commit is contained in:
@@ -19,7 +19,7 @@ public class DatabaseController
|
||||
string strUDPFramePayload;
|
||||
string strUDPFramePayload_Perun;
|
||||
string strSQLQueryTxt;
|
||||
|
||||
|
||||
|
||||
// Some frames may come without timestamp, use database currrent timestampe then
|
||||
if (strUDPFrameTimestamp != null)
|
||||
@@ -32,7 +32,7 @@ public class DatabaseController
|
||||
}
|
||||
|
||||
// Modify specific types
|
||||
if (strUDPFrameType == "1")
|
||||
if (strUDPFrameType == "1")
|
||||
{
|
||||
strUDPFrame.payload["v_win"] = "v" + Globals.strPerunVersion; // Inject app version information
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class DatabaseController
|
||||
// Add entry to chat log
|
||||
strSQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strUDPFrame.payload.ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.ucid + "' );";
|
||||
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET `pe_DataPlayers_updated` = " + strUDPFrameTimestamp + ",`pe_DataPlayers_lastname`='" + strUDPFrame.payload.player + "' WHERE `pe_DataPlayers_ucid`='" + strUDPFrame.payload.ucid + "' ;";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strUDPFrame.payload.missionhash + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` ='" + strUDPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`="+ strUDPFrameInstance + ");";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strUDPFrame.payload.missionhash + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` ='" + strUDPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + ");";
|
||||
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strUDPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + " ;";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_LogChat` (`pe_LogChat_id`,`pe_LogChat_datetime`, `pe_LogChat_playerid`, `pe_LogChat_msg`, `pe_LogChat_all`,`pe_LogChat_missionhash_id`) VALUES (NULL,'" + strUDPFrame.payload.datetime + "', (SELECT `pe_DataPlayers_id` from `pe_DataPlayers` WHERE `pe_DataPlayers_ucid` = '" + strUDPFrame.payload.ucid + "'), '" + strUDPFrame.payload.msg + "', '" + strUDPFrame.payload.all + "',(SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.missionhash + "'));";
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class DatabaseController
|
||||
// Add entry to event log
|
||||
strSQLQueryTxt = "INSERT INTO `pe_DataMissionHashes` (`pe_DataMissionHashes_hash`,`pe_DataMissionHashes_instance`) SELECT '" + strUDPFrame.payload.log_missionhash + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataMissionHashes` where `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + ");";
|
||||
strSQLQueryTxt += "UPDATE `pe_DataMissionHashes` SET `pe_DataMissionHashes_datetime` = " + strUDPFrameTimestamp + " WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "' AND `pe_DataMissionHashes_instance`=" + strUDPFrameInstance + ";";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_LogEvent` (`pe_LogEvent_arg1`,`pe_LogEvent_arg2`,`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`,`pe_LogEvent_missionhash_id`) VALUES ('"+ strUDPFrame.payload.log_arg_1 + "','"+ strUDPFrame.payload.log_arg_2 + "', NULL, '" + strUDPFrame.payload.log_datetime + "', '" + strUDPFrame.payload.log_type + "', '" + strUDPFrame.payload.log_content + "', (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "'));";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_LogEvent` (`pe_LogEvent_arg1`,`pe_LogEvent_arg2`,`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`,`pe_LogEvent_missionhash_id`) VALUES ('" + strUDPFrame.payload.log_arg_1 + "','" + strUDPFrame.payload.log_arg_2 + "', NULL, '" + strUDPFrame.payload.log_datetime + "', '" + strUDPFrame.payload.log_type + "', '" + strUDPFrame.payload.log_content + "', (SELECT `pe_DataMissionHashes_id` FROM `pe_DataMissionHashes` WHERE `pe_DataMissionHashes_hash` = '" + strUDPFrame.payload.log_missionhash + "'));";
|
||||
}
|
||||
else if (strUDPFrameType == "52")
|
||||
{
|
||||
@@ -74,15 +74,15 @@ public class DatabaseController
|
||||
|
||||
strSQLQueryTxt = "INSERT INTO `pe_DataPlayers` (`pe_DataPlayers_ucid`) SELECT '" + strUDPFrame.payload.login_ucid + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataPlayers` where pe_DataPlayers_ucid='" + strUDPFrame.payload.login_ucid + "');";
|
||||
strSQLQueryTxt += "UPDATE `pe_DataPlayers` SET pe_DataPlayers_lastip='" + strUDPFrame.payload.login_ipaddr + "', pe_DataPlayers_lastname='" + strUDPFrame.payload.login_name + "',pe_DataPlayers_updated='" + strUDPFrame.payload.login_datetime + "' WHERE `pe_DataPlayers_ucid`= '" + strUDPFrame.payload.login_ucid + "';";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_LogLogins` (`pe_LogLogins_datetime`, `pe_LogLogins_playerid`, `pe_LogLogins_name`, `pe_LogLogins_ip`,`pe_LogLogins_instance`) VALUES ('" + strUDPFrame.payload.login_datetime + "', (SELECT pe_DataPlayers_id from pe_DataPlayers WHERE pe_DataPlayers_ucid = '" + strUDPFrame.payload.login_ucid + "'), '" + strUDPFrame.payload.login_name + "', '" + strUDPFrame.payload.login_ipaddr + "','"+ strUDPFrameInstance + "');";
|
||||
strSQLQueryTxt += "INSERT INTO `pe_LogLogins` (`pe_LogLogins_datetime`, `pe_LogLogins_playerid`, `pe_LogLogins_name`, `pe_LogLogins_ip`,`pe_LogLogins_instance`) VALUES ('" + strUDPFrame.payload.login_datetime + "', (SELECT pe_DataPlayers_id from pe_DataPlayers WHERE pe_DataPlayers_ucid = '" + strUDPFrame.payload.login_ucid + "'), '" + strUDPFrame.payload.login_name + "', '" + strUDPFrame.payload.login_ipaddr + "','" + strUDPFrameInstance + "');";
|
||||
}
|
||||
else
|
||||
{
|
||||
// General definition used for 1-10 type packets
|
||||
strUDPFramePayload = JsonConvert.SerializeObject(strUDPFrame.payload); // Deserialize payload
|
||||
|
||||
strSQLQueryTxt = "INSERT INTO `pe_DataRaw` (`pe_dataraw_type`,`pe_dataraw_instance`) SELECT '" + strUDPFrameType + "','"+ strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataRaw` WHERE `pe_dataraw_type` = '" + strUDPFrameType + "' AND `pe_dataraw_instance` = " + strUDPFrameInstance + ");";
|
||||
strSQLQueryTxt += "UPDATE `pe_DataRaw` SET `pe_dataraw_payload` = JSON_QUOTE('" + strUDPFramePayload + "'), `pe_dataraw_updated`=" + strUDPFrameTimestamp + " WHERE `pe_dataraw_type`=" + strUDPFrameType + " AND `pe_dataraw_instance` = "+ strUDPFrameInstance + ";";
|
||||
strSQLQueryTxt = "INSERT INTO `pe_DataRaw` (`pe_dataraw_type`,`pe_dataraw_instance`) SELECT '" + strUDPFrameType + "','" + strUDPFrameInstance + "' FROM DUAL WHERE NOT EXISTS (SELECT * FROM `pe_DataRaw` WHERE `pe_dataraw_type` = '" + strUDPFrameType + "' AND `pe_dataraw_instance` = " + strUDPFrameInstance + ");";
|
||||
strSQLQueryTxt += "UPDATE `pe_DataRaw` SET `pe_dataraw_payload` = JSON_QUOTE('" + strUDPFramePayload + "'), `pe_dataraw_updated`=" + strUDPFrameTimestamp + " WHERE `pe_dataraw_type`=" + strUDPFrameType + " AND `pe_dataraw_instance` = " + strUDPFrameInstance + ";";
|
||||
}
|
||||
|
||||
// Connect to mysql and execute sql
|
||||
@@ -139,7 +139,7 @@ public class DatabaseController
|
||||
{
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + strUDPFrameInstance + " > ERROR MySQL - unable to connect > " + x_ex.Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// This class gathers all global variable
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
internal class Globals
|
||||
{
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class LogController
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ internal class PerunHelper
|
||||
|
||||
// Add new entry
|
||||
arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("yyyy-dd-MM HH:mm:ss") + " > " + strEntryToAdd; // Add entry at the last position
|
||||
|
||||
|
||||
// Add the entry to log file
|
||||
LogController.WriteLog(arrLogHistory[arrLogHistory.Length - 1]);
|
||||
|
||||
@@ -35,6 +35,6 @@ internal class PerunHelper
|
||||
// For other cases
|
||||
Globals.strPerunVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
}
|
||||
return strBeginning+"v" + Globals.strPerunVersion;
|
||||
return strBeginning + "v" + Globals.strPerunVersion;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Perun_v1
|
||||
@@ -14,7 +13,7 @@ namespace Perun_v1
|
||||
|
||||
static void Main()
|
||||
{
|
||||
// Main entry point to the app
|
||||
// Main entry point to the app
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class TCPController
|
||||
public string[] arrGUILogHistory; // Log history for GUI
|
||||
public string[] arrMySQLSendBuffer; // MySQL send buffer
|
||||
public Thread thrTCPListener; // Seperate thread for TCP
|
||||
|
||||
|
||||
public void Create(int par_intListenPort, ref string[] par_arrLogHistory, ref string[] par_arrSendBuffer)
|
||||
{
|
||||
// Create class and map creation arguments to class
|
||||
@@ -39,8 +39,8 @@ public class TCPController
|
||||
public void StartListen()
|
||||
{
|
||||
// Start listening
|
||||
NetworkStream nsReadStream=null;
|
||||
TcpClient tcpClient=null;
|
||||
NetworkStream nsReadStream = null;
|
||||
TcpClient tcpClient = null;
|
||||
bool bTCPConnectionOnline = false;
|
||||
|
||||
// Main loop - do until diconnect button is clicked
|
||||
@@ -73,13 +73,13 @@ public class TCPController
|
||||
nsReadStream = tcpClient.GetStream(); //networkstream is used to send/receive messages
|
||||
nsReadStream.ReadTimeout = 6000;
|
||||
tcpClient.ReceiveTimeout = 6000;
|
||||
|
||||
|
||||
|
||||
while (tcpClient.Connected && !bCloseConnection && bTCPConnectionOnline) //while the client is connected, we look for incoming messages
|
||||
{
|
||||
StringBuilder CompleteMessage = new StringBuilder();
|
||||
Globals.bClientConnected = true;
|
||||
|
||||
|
||||
if (nsReadStream.CanRead)
|
||||
{
|
||||
Console.WriteLine("TCP: Can read");
|
||||
@@ -124,7 +124,8 @@ public class TCPController
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
bTCPConnectionOnline = false;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Perun_v1
|
||||
{
|
||||
@@ -14,7 +14,7 @@ namespace Perun_v1
|
||||
public bool bAllowAppClosure = false; // Helper to handle system tray
|
||||
|
||||
public DatabaseController dcConnection = new DatabaseController(); // MySQL controller
|
||||
public TCPController tcpServer=new TCPController(); // TCP controller
|
||||
public TCPController tcpServer = new TCPController(); // TCP controller
|
||||
|
||||
public bool bSRSStatus; // Use empty/default SRS status
|
||||
public bool bLotATCStatus; // Use empty/default LotATC status
|
||||
@@ -26,48 +26,48 @@ namespace Perun_v1
|
||||
Globals.arrGUILogHistory[0] = DateTime.Now.ToString("HH:mm:ss") + " > " + "Perun started";
|
||||
|
||||
// Display build version in title bar
|
||||
Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - ");
|
||||
Globals.strPerunTitleText = PerunHelper.GetAppVersion(this.Text + " - ");
|
||||
this.Text = Globals.strPerunTitleText;
|
||||
|
||||
// Load settings from registry
|
||||
form_Main_LoadSettings();
|
||||
form_Main_LoadSettings();
|
||||
|
||||
// Use command line parameters
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
if (args.Length > 1)
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
// Get argument server port
|
||||
if (args[1] != null)
|
||||
{
|
||||
// Get argument server port
|
||||
if (args[1] != null)
|
||||
{
|
||||
con_txt_dcs_server_port.Text = args[1];
|
||||
}
|
||||
con_txt_dcs_server_port.Text = args[1];
|
||||
}
|
||||
if (args.Length > 2)
|
||||
}
|
||||
if (args.Length > 2)
|
||||
{
|
||||
// Get argument instance id
|
||||
if (args[2] != null)
|
||||
{
|
||||
// Get argument instance id
|
||||
if (args[2] != null)
|
||||
{
|
||||
con_txt_dcs_instance.Text = args[2];
|
||||
}
|
||||
con_txt_dcs_instance.Text = args[2];
|
||||
}
|
||||
if (args.Length > 3)
|
||||
}
|
||||
if (args.Length > 3)
|
||||
{
|
||||
// Get argument DCS SRS file path
|
||||
if (args[3] != null)
|
||||
{
|
||||
// Get argument DCS SRS file path
|
||||
if (args[3] != null)
|
||||
{
|
||||
con_txt_3rd_srs.Text = args[3];
|
||||
con_check_3rd_srs.Checked = true;
|
||||
}
|
||||
con_txt_3rd_srs.Text = args[3];
|
||||
con_check_3rd_srs.Checked = true;
|
||||
}
|
||||
if (args.Length > 4)
|
||||
}
|
||||
if (args.Length > 4)
|
||||
{
|
||||
// Get argument lotATC file path
|
||||
if (args[4] != null)
|
||||
{
|
||||
// Get argument lotATC file path
|
||||
if (args[4] != null)
|
||||
{
|
||||
con_txt_3rd_lotatc.Text = args[4];
|
||||
con_check_3rd_lotatc.Checked = true;
|
||||
}
|
||||
con_txt_3rd_lotatc.Text = args[4];
|
||||
con_check_3rd_lotatc.Checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public form_Main()
|
||||
@@ -141,7 +141,7 @@ namespace Perun_v1
|
||||
con_txt_mysql_database.Enabled = true;
|
||||
con_txt_mysql_username.Enabled = true;
|
||||
con_txt_mysql_password.Enabled = true;
|
||||
con_txt_mysql_port.Enabled = true;
|
||||
con_txt_mysql_port.Enabled = true;
|
||||
con_txt_mysql_server.Enabled = true;
|
||||
con_txt_3rd_lotatc.Enabled = true;
|
||||
con_txt_3rd_srs.Enabled = true;
|
||||
@@ -156,7 +156,7 @@ namespace Perun_v1
|
||||
{
|
||||
// Start listening
|
||||
// Set globals
|
||||
Globals.intInstanceId= Int32.Parse(con_txt_dcs_instance.Text);
|
||||
Globals.intInstanceId = Int32.Parse(con_txt_dcs_instance.Text);
|
||||
Globals.bStatusIconsForce = true;
|
||||
|
||||
Globals.intMysqlErros = 0; // Reset error counter
|
||||
@@ -196,7 +196,7 @@ namespace Perun_v1
|
||||
{
|
||||
// Stop listening
|
||||
// Prepare GUI
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId +" > " + "Closing connections");
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId + " > " + "Closing connections");
|
||||
con_Button_Listen_OFF.Enabled = false;
|
||||
Tim_GUI_Tick(null, null);
|
||||
this.Refresh();
|
||||
@@ -229,7 +229,7 @@ namespace Perun_v1
|
||||
con_img_srs.Image = (Image)Properties.Resources.ResourceManager.GetObject("status_disconnected");
|
||||
|
||||
// Display information about closed connections
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId +" > " + "Connections closed");
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Globals.intInstanceId + " > " + "Connections closed");
|
||||
Tim_GUI_Tick(null, null);
|
||||
|
||||
// Set title bar
|
||||
@@ -246,7 +246,7 @@ namespace Perun_v1
|
||||
Globals.bSRSStatus = false;
|
||||
Globals.bLotATCStatus = false;
|
||||
Globals.bClientConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void con_lab_github_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||
{
|
||||
@@ -351,7 +351,7 @@ namespace Perun_v1
|
||||
private void Tim_GUI_Tick(object sender, EventArgs e)
|
||||
{
|
||||
// Main timer to sync GUI with background tasks and flush buffers
|
||||
|
||||
|
||||
// Refresh Log Window
|
||||
if (Globals.bGUILogHistoryUpdate)
|
||||
{
|
||||
@@ -364,7 +364,8 @@ namespace Perun_v1
|
||||
}
|
||||
}
|
||||
Globals.bGUILogHistoryUpdate = false;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do nothing , control does not require update
|
||||
}
|
||||
@@ -553,7 +554,7 @@ namespace Perun_v1
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data loaded");
|
||||
bLotATCStatus = true;
|
||||
}
|
||||
catch(Exception exc_lotatc)
|
||||
catch (Exception exc_lotatc)
|
||||
{
|
||||
PerunHelper.GUILogHistoryAdd(ref Globals.arrGUILogHistory, "#" + Int32.Parse(con_txt_dcs_instance.Text) + " > LotATC data ERROR > " + exc_lotatc.Message);
|
||||
bLotATCStatus = false;
|
||||
|
||||
Reference in New Issue
Block a user