From 02eebc5f1e5ca030236f32221f642d55c83caea2 Mon Sep 17 00:00:00 2001 From: Szymon Porwolik Date: Sat, 23 Feb 2019 17:47:38 +0100 Subject: [PATCH] First working version --- 01_DCS/Hooks/Perun.lua | 123 +++++++++++++++--- 02_Windows_App/Perun_v1/App.config | 30 +++++ 02_Windows_App/Perun_v1/Perun_v1.csproj | 13 +- .../Perun_v1/Properties/AssemblyInfo.cs | 4 +- .../Perun_v1/Properties/Resources.resx | 13 +- .../Perun_v1/Properties/Settings.Designer.cs | 12 ++ .../Perun_v1/Properties/Settings.settings | 5 +- 02_Windows_App/Perun_v1/form_Main.Designer.cs | 54 +++++--- 02_Windows_App/Perun_v1/form_Main.cs | 72 +++++++--- README.md | 32 +++-- 10 files changed, 283 insertions(+), 75 deletions(-) diff --git a/01_DCS/Hooks/Perun.lua b/01_DCS/Hooks/Perun.lua index ad50650..4642079 100644 --- a/01_DCS/Hooks/Perun.lua +++ b/01_DCS/Hooks/Perun.lua @@ -7,16 +7,19 @@ -- ########### SETTINGS ########### - Perun.Refresh = 15 -- base refresh rate in secounds (values lower than 60 may affect performance!) - Perun.JsonLocation = "Scripts\\Json\\perun_export.json" -- relatve do user's SaveGames DCS folder - Perun.UDPTargetPort = 48620 -- UDP port to send data to + Perun.Refresh = 15 -- base refresh rate in secounds (values lower than 60 may affect performance!) + Perun.JsonLocation = "Scripts\\Json\\perun_export.json" -- relatve do user's SaveGames DCS folder + Perun.UDPTargetPort = 48620 -- UDP port to send data to + Perun.MOTD_L1 = "Witamy na serwerze Gildia.org" -- Message send to players connecting the server - Line 1 + Perun.MOTD_L2 = "Wymagamy obecnoci na 255Mhz (DCS SRS)" -- Message send to players connecting the server - Line 2 + Perun.MOTD_L3 = "Udanej zabawy" -- Message send to players connecting the server - Line 3 -- ########### END OF SETTINGS ########### -- Variable init - Perun.Version = "v0.1.1" + Perun.Version = "v0.2.1" Perun.StatusData = {} - Perun.MissionData = {} + Perun.SlotsData = {} Perun.VersionData = {} Perun.lastSent =0 Perun.JsonLocation = lfs.writedir() .. Perun.JsonLocation @@ -25,7 +28,6 @@ Perun.UDP:settimeout(0) Perun.UDP:setsockname("*", 48621) Perun.UDP:setpeername("127.0.0.1",Perun.UDPTargetPort) - Perun.UDP:send("{'type':999,'payload':'Perun is onlne!'}") -- send welcome message -- Function definition Perun.AddLog = function(text) @@ -38,7 +40,7 @@ TempData={} TempData["1"]=Perun.VersionData TempData["2"]=Perun.StatusData - TempData["3"]=Perun.MissionData + TempData["3"]=Perun.SlotsData io.open(Perun.JsonLocation,"w"):close() perun_export = io.open(Perun.JsonLocation, "w") @@ -79,7 +81,6 @@ -- 1 - Mission temp={} temp['name']=DCS.getMissionName() - temp['filename']=DCS.getMissionFilename() temp['modeltime']=DCS.getModelTime() temp['realtime']=DCS.getRealTime() temp['pause']=DCS.getPause() @@ -101,22 +102,36 @@ -- Main function for mission information updates -- Update Mission data - Perun.MissionData['name']=DCS.getMissionName() - Perun.MissionData['description']=DCS.getMissionDescription() - Perun.MissionData['filename']=DCS.getMissionFilename() - Perun.MissionData['modeltime']=DCS.getModelTime() - Perun.MissionData['realtime']=DCS.getRealTime() - Perun.MissionData['data']=DCS.getCurrentMission() - Perun.MissionData['coalitions']=DCS.getAvailableCoalitions() - Perun.MissionData['slots']={} + Perun.SlotsData['coalitions']=DCS.getAvailableCoalitions() + Perun.SlotsData['slots']={} - for j, i in pairs(Perun.MissionData['coalitions']) do - Perun.MissionData['slots'][j]=DCS.getAvailableSlots(j) + for j, i in pairs(Perun.SlotsData['coalitions']) do + Perun.SlotsData['slots'][j]=DCS.getAvailableSlots(j) end -- Send - Perun.Send(3,Perun.MissionData) + Perun.Send(3,Perun.SlotsData) + end + + Perun.LogChat = function(playerID,msg,all) + -- Log chat messages + + data={} + data['player']= net.get_player_info(playerID, "name") + data['msg']=msg + data['all']=all + + Perun.Send(50,data) + end + + Perun.LogEvent = function(log_type,log_content) + -- Log chat messages + + data={} + data['log_type']= log_type + data['log_content']=log_content + + Perun.Send(51,data) end - --- Event callbacks Perun.onSimulationFrame = function() @@ -137,6 +152,74 @@ Perun.UpdateMission() Perun.UpdateJson() end + + Perun.onPlayerStart = function (id) + net.send_chat(Perun.MOTD_L1, id); + net.send_chat(Perun.MOTD_L2, id); + net.send_chat(Perun.MOTD_L3, id); + end + + Perun.onPlayerTrySendChat = function (playerID, msg, all) + Perun.LogChat(playerID,msg,all) + return msg + end + + Perun.onGameEvent = function (eventName,arg1,arg2,arg3,arg4) + + + if eventName == "friendly_fire" then + --"friendly_fire", playerID, weaponName, victimPlayerID + Perun.LogEvent(eventName,net.get_player_info(arg1, "name").." killed " .. net.get_player_info(arg3, "name") .. " using " .. arg2); + + elseif eventName == "mission_end" then + --"mission_end", winner, msg + Perun.LogEvent(eventName,"Mission end, winner " .. arg1 .. " message: " .. arg2); + + elseif eventName == "kill" then + --"kill", killerPlayerID, killerUnitType, killerSide, victimPlayerID, victimUnitType, victimSide, weaponName + Perun.LogEvent(eventName,net.get_player_info(arg1, "name").. " in " .. arg3 .. " " .. arg2 .. " killed " .. net.get_player_info(arg4, "name") .. " in " .. arg6 .. " " .. arg5 .. " using " .. arg7); + + elseif eventName == "self_kill" then + --"self_kill", playerID + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " killed himself"); + + elseif eventName == "change_slot" then + --"change_slot", playerID, slotID, prevSide + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " changed slot to " .. arg2); + + elseif eventName == "connect" then + --"connect", playerID, name + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " connected"); + + elseif eventName == "disconnect" then + --"disconnect", playerID, name, playerSide, reason_code + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " disconnected; reason: " .. arg4); + + elseif eventName == "crash" then + --"crash", playerID, unit_missionID + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " crashed"); + + elseif eventName == "eject" then + --"eject", playerID, unit_missionID + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " ejected"); + + elseif eventName == "takeoff" then + --"takeoff", playerID, unit_missionID, airdromeName + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " took off from " .. arg3); + + elseif eventName == "landing" then + --"landing", playerID, unit_missionID, airdromeName + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. " landed at " .. arg3); + + elseif eventName == "pilot_death" then + --"pilot_death", playerID, unit_missionID + Perun.LogEvent(eventName,net.get_player_info(arg1, "name") .. "died"); + + else + Perun.LogEvent(eventName,"Unknown event type"); + end + + end -- Finalize and set callbacks DCS.setUserCallbacks(Perun) diff --git a/02_Windows_App/Perun_v1/App.config b/02_Windows_App/Perun_v1/App.config index 1a14eda..06d45f7 100644 --- a/02_Windows_App/Perun_v1/App.config +++ b/02_Windows_App/Perun_v1/App.config @@ -2,6 +2,7 @@ +
@@ -9,6 +10,35 @@ + + + + + + + + + + + + + + + + + + + + + False + + + False + + + + + diff --git a/02_Windows_App/Perun_v1/Perun_v1.csproj b/02_Windows_App/Perun_v1/Perun_v1.csproj index e9bf3b5..65d7b32 100644 --- a/02_Windows_App/Perun_v1/Perun_v1.csproj +++ b/02_Windows_App/Perun_v1/Perun_v1.csproj @@ -7,7 +7,7 @@ {5A710507-92E9-4664-9B91-918B8B82F107} WinExe Perun_v1 - Perun_v1 + Perun v4.6.1 512 true @@ -23,8 +23,9 @@ false false true - 1 - 1.0.0.%2a + true + 2 + 0.2.1.%2a false true true @@ -55,7 +56,8 @@ 2ACE4C8C2C325A04CA5986B1CD76744B4B03755D - Perun_v1_TemporaryKey.pfx + + true @@ -144,5 +146,8 @@ + + + \ No newline at end of file diff --git a/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs b/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs index 02a1660..71e7591 100644 --- a/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs +++ b/02_Windows_App/Perun_v1/Properties/AssemblyInfo.cs @@ -33,7 +33,7 @@ using System.Runtime.InteropServices; // Możesz określić wszystkie wartości lub użyć domyślnych numerów kompilacji i poprawki // przy użyciu symbolu „*”, tak jak pokazano poniżej: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] +[assembly: AssemblyVersion("0.2.0.0")] +[assembly: AssemblyFileVersion("0.2.0.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/02_Windows_App/Perun_v1/Properties/Resources.resx b/02_Windows_App/Perun_v1/Properties/Resources.resx index af7dbeb..1af7de1 100644 --- a/02_Windows_App/Perun_v1/Properties/Resources.resx +++ b/02_Windows_App/Perun_v1/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file diff --git a/02_Windows_App/Perun_v1/Properties/Settings.Designer.cs b/02_Windows_App/Perun_v1/Properties/Settings.Designer.cs index 1b53716..925a3b4 100644 --- a/02_Windows_App/Perun_v1/Properties/Settings.Designer.cs +++ b/02_Windows_App/Perun_v1/Properties/Settings.Designer.cs @@ -118,5 +118,17 @@ namespace Perun_v1.Properties { this["OTHER_SRS_USE"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string MYSQL_Port { + get { + return ((string)(this["MYSQL_Port"])); + } + set { + this["MYSQL_Port"] = value; + } + } } } diff --git a/02_Windows_App/Perun_v1/Properties/Settings.settings b/02_Windows_App/Perun_v1/Properties/Settings.settings index e967b56..1b55d4d 100644 --- a/02_Windows_App/Perun_v1/Properties/Settings.settings +++ b/02_Windows_App/Perun_v1/Properties/Settings.settings @@ -1,5 +1,5 @@  - + @@ -26,5 +26,8 @@ False + + + \ No newline at end of file diff --git a/02_Windows_App/Perun_v1/form_Main.Designer.cs b/02_Windows_App/Perun_v1/form_Main.Designer.cs index 65867ed..7f1b65a 100644 --- a/02_Windows_App/Perun_v1/form_Main.Designer.cs +++ b/02_Windows_App/Perun_v1/form_Main.Designer.cs @@ -36,6 +36,8 @@ this.con_GroupBox_1 = new System.Windows.Forms.GroupBox(); this.tim_1000ms = new System.Windows.Forms.Timer(this.components); this.con_GroupBox_2 = new System.Windows.Forms.GroupBox(); + this.label6 = new System.Windows.Forms.Label(); + this.con_txt_mysql_port = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.con_txt_mysql_username = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); @@ -83,7 +85,7 @@ // // con_Button_Listen_ON // - this.con_Button_Listen_ON.Location = new System.Drawing.Point(12, 405); + this.con_Button_Listen_ON.Location = new System.Drawing.Point(12, 434); this.con_Button_Listen_ON.Name = "con_Button_Listen_ON"; this.con_Button_Listen_ON.Size = new System.Drawing.Size(86, 39); this.con_Button_Listen_ON.TabIndex = 2; @@ -94,7 +96,7 @@ // con_Button_Listen_OFF // this.con_Button_Listen_OFF.Enabled = false; - this.con_Button_Listen_OFF.Location = new System.Drawing.Point(104, 405); + this.con_Button_Listen_OFF.Location = new System.Drawing.Point(104, 434); this.con_Button_Listen_OFF.Name = "con_Button_Listen_OFF"; this.con_Button_Listen_OFF.Size = new System.Drawing.Size(86, 39); this.con_Button_Listen_OFF.TabIndex = 3; @@ -105,9 +107,9 @@ // con_GroupBox_1 // this.con_GroupBox_1.Controls.Add(this.con_List_Received); - this.con_GroupBox_1.Location = new System.Drawing.Point(12, 235); + this.con_GroupBox_1.Location = new System.Drawing.Point(12, 261); this.con_GroupBox_1.Name = "con_GroupBox_1"; - this.con_GroupBox_1.Size = new System.Drawing.Size(324, 164); + this.con_GroupBox_1.Size = new System.Drawing.Size(324, 167); this.con_GroupBox_1.TabIndex = 4; this.con_GroupBox_1.TabStop = false; this.con_GroupBox_1.Text = "UDP log"; @@ -119,6 +121,8 @@ // // con_GroupBox_2 // + this.con_GroupBox_2.Controls.Add(this.label6); + this.con_GroupBox_2.Controls.Add(this.con_txt_mysql_port); this.con_GroupBox_2.Controls.Add(this.label4); this.con_GroupBox_2.Controls.Add(this.con_txt_mysql_username); this.con_GroupBox_2.Controls.Add(this.label3); @@ -129,15 +133,31 @@ this.con_GroupBox_2.Controls.Add(this.con_txt_mysql_password); this.con_GroupBox_2.Location = new System.Drawing.Point(12, 27); this.con_GroupBox_2.Name = "con_GroupBox_2"; - this.con_GroupBox_2.Size = new System.Drawing.Size(324, 127); + this.con_GroupBox_2.Size = new System.Drawing.Size(324, 154); this.con_GroupBox_2.TabIndex = 5; this.con_GroupBox_2.TabStop = false; this.con_GroupBox_2.Text = "MySQL"; // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(41, 48); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(59, 13); + this.label6.TabIndex = 9; + this.label6.Text = "Server port"; + // + // con_txt_mysql_port + // + this.con_txt_mysql_port.Location = new System.Drawing.Point(106, 45); + this.con_txt_mysql_port.Name = "con_txt_mysql_port"; + this.con_txt_mysql_port.Size = new System.Drawing.Size(207, 20); + this.con_txt_mysql_port.TabIndex = 8; + // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(45, 74); + this.label4.Location = new System.Drawing.Point(45, 100); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(55, 13); this.label4.TabIndex = 7; @@ -145,7 +165,7 @@ // // con_txt_mysql_username // - this.con_txt_mysql_username.Location = new System.Drawing.Point(106, 71); + this.con_txt_mysql_username.Location = new System.Drawing.Point(106, 97); this.con_txt_mysql_username.Name = "con_txt_mysql_username"; this.con_txt_mysql_username.Size = new System.Drawing.Size(207, 20); this.con_txt_mysql_username.TabIndex = 6; @@ -153,7 +173,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(47, 100); + this.label3.Location = new System.Drawing.Point(47, 126); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(53, 13); this.label3.TabIndex = 5; @@ -162,7 +182,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(47, 48); + this.label2.Location = new System.Drawing.Point(47, 74); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(53, 13); this.label2.TabIndex = 4; @@ -179,7 +199,7 @@ // // con_txt_mysql_database // - this.con_txt_mysql_database.Location = new System.Drawing.Point(106, 45); + this.con_txt_mysql_database.Location = new System.Drawing.Point(106, 71); this.con_txt_mysql_database.Name = "con_txt_mysql_database"; this.con_txt_mysql_database.Size = new System.Drawing.Size(207, 20); this.con_txt_mysql_database.TabIndex = 2; @@ -193,7 +213,7 @@ // // con_txt_mysql_password // - this.con_txt_mysql_password.Location = new System.Drawing.Point(106, 97); + this.con_txt_mysql_password.Location = new System.Drawing.Point(106, 123); this.con_txt_mysql_password.Name = "con_txt_mysql_password"; this.con_txt_mysql_password.PasswordChar = '*'; this.con_txt_mysql_password.Size = new System.Drawing.Size(207, 20); @@ -205,9 +225,9 @@ this.con_GroupBox_3.Controls.Add(this.con_txt_3rd_srs); this.con_GroupBox_3.Controls.Add(this.con_check_3rd_lotatc); this.con_GroupBox_3.Controls.Add(this.con_check_3rd_srs); - this.con_GroupBox_3.Location = new System.Drawing.Point(12, 160); + this.con_GroupBox_3.Location = new System.Drawing.Point(12, 187); this.con_GroupBox_3.Name = "con_GroupBox_3"; - this.con_GroupBox_3.Size = new System.Drawing.Size(324, 69); + this.con_GroupBox_3.Size = new System.Drawing.Size(324, 68); this.con_GroupBox_3.TabIndex = 6; this.con_GroupBox_3.TabStop = false; this.con_GroupBox_3.Text = "3rd Party"; @@ -250,7 +270,7 @@ // // con_Button_Quit // - this.con_Button_Quit.Location = new System.Drawing.Point(250, 405); + this.con_Button_Quit.Location = new System.Drawing.Point(250, 434); this.con_Button_Quit.Name = "con_Button_Quit"; this.con_Button_Quit.Size = new System.Drawing.Size(86, 39); this.con_Button_Quit.TabIndex = 7; @@ -298,14 +318,14 @@ // // tim_10000ms // - this.tim_10000ms.Interval = 10000; + this.tim_10000ms.Interval = 30000; this.tim_10000ms.Tick += new System.EventHandler(this.tim_10000ms_Tick); // // form_Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(348, 456); + this.ClientSize = new System.Drawing.Size(349, 483); this.Controls.Add(this.label5); this.Controls.Add(this.con_lab_github); this.Controls.Add(this.con_Button_Quit); @@ -361,6 +381,8 @@ private System.Windows.Forms.OpenFileDialog openFileDialog_SRS; private System.Windows.Forms.OpenFileDialog openFileDialog_LotATC; private System.Windows.Forms.Timer tim_10000ms; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox con_txt_mysql_port; } } diff --git a/02_Windows_App/Perun_v1/form_Main.cs b/02_Windows_App/Perun_v1/form_Main.cs index fc7617c..1c77715 100644 --- a/02_Windows_App/Perun_v1/form_Main.cs +++ b/02_Windows_App/Perun_v1/form_Main.cs @@ -36,16 +36,15 @@ namespace Perun_v1 public void SendToMySql(string raw_udp_frame) { // Main function to send data to mysql - // TODO : persistent connection and error handling - dynamic udp_frame = JsonConvert.DeserializeObject(raw_udp_frame); // Cut raw data to type and paylod for proper mysql insert - string type = udp_frame.type; - + string type = udp_frame.type; + string payload = ""; + string sql = ""; - // Type specyfic - if (type == "1") // Inject app version information + // Modify specific + if (type == "1") // Inject app version information { Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); @@ -53,7 +52,21 @@ namespace Perun_v1 udp_frame.payload["v_win"] = "v"+version; } - string payload = JsonConvert.SerializeObject(udp_frame.payload); + // Specific SQL + if(type == "50") + { + sql = "INSERT INTO `pe_LogChat` (`pe_LogChat_id`, `pe_LogChat_playerid`, `pe_LogChat_msg`, `pe_LogChat_all`) VALUES (NULL, '"+udp_frame.payload.player+ "', '" + udp_frame.payload.msg + "', '" + udp_frame.payload.all + "');"; + } + else if(type == "51") + { + sql = "INSERT INTO `pe_LogEvent` (`pe_LogEvent_id`, `pe_LogEvent_datetime`, `pe_LogEvent_type`, `pe_LogEvent_content`) VALUES (NULL, CURRENT_TIMESTAMP, '" + udp_frame.payload.log_type + "', '" + udp_frame.payload.log_content + "');"; + } + else + { + payload = JsonConvert.SerializeObject(udp_frame.payload); + sql = "INSERT INTO pe_DataRaw(pe_dataraw_type,pe_dataraw_payload) VALUES (" + type + ",JSON_QUOTE('" + payload + "')) ON DUPLICATE KEY UPDATE pe_dataraw_payload = JSON_QUOTE('" + payload + "')"; + } + // Connect to mysql MySqlConnection conn = new MySqlConnection(MySql_connStr); try @@ -61,8 +74,6 @@ namespace Perun_v1 Console.WriteLine("Sending data to MySQL - Begin"); conn.Open(); - string sql = "INSERT INTO pe_DataRaw(pe_dataraw_type,pe_dataraw_payload) VALUES (" + type+",JSON_QUOTE('" + payload + "')) ON DUPLICATE KEY UPDATE pe_dataraw_payload = JSON_QUOTE('" + payload + "')"; - MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); @@ -162,10 +173,16 @@ namespace Perun_v1 con_txt_mysql_username.Text = Properties.Settings.Default.MYSQL_User; con_txt_mysql_password.Text = Properties.Settings.Default.MYSQL_Password; con_txt_mysql_server.Text = Properties.Settings.Default.MYSQL_Server; + con_txt_mysql_port.Text = Properties.Settings.Default.MYSQL_Port; con_txt_3rd_lotatc.Text = Properties.Settings.Default.OTHER_LOTATC_FILE; con_txt_3rd_srs.Text = Properties.Settings.Default.OTHER_SRS_FILE; con_check_3rd_lotatc.Checked = Properties.Settings.Default.OTHER_LOTATC_USE; con_check_3rd_srs.Checked = Properties.Settings.Default.OTHER_SRS_USE; + + // Version to title header + Assembly assembly = Assembly.GetExecutingAssembly(); + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); + this.Text = this.Text + " - v" + fileVersionInfo.ProductVersion; } private void con_Button_Listen_ON_Click(object sender, EventArgs e) @@ -178,21 +195,22 @@ namespace Perun_v1 // Update form controls con_Button_Listen_ON.Enabled = false; con_Button_Listen_OFF.Enabled = true; - con_txt_mysql_database.Enabled = false; con_txt_mysql_username.Enabled = false; con_txt_mysql_password.Enabled = false; con_txt_mysql_server.Enabled = false; + con_txt_mysql_port.Enabled = false; con_txt_3rd_lotatc.Enabled = false; con_txt_3rd_srs.Enabled = false; con_check_3rd_lotatc.Enabled = false; con_check_3rd_srs.Enabled = false; // Prepare connection string - MySql_connStr = "server="+con_txt_mysql_server.Text+";user="+con_txt_mysql_username.Text+";database="+con_txt_mysql_database.Text+";port=3306;password="+con_txt_mysql_password.Text; + MySql_connStr = "server="+con_txt_mysql_server.Text+";user="+con_txt_mysql_username.Text+";database="+con_txt_mysql_database.Text+";port="+ con_txt_mysql_port.Text + ";password="+con_txt_mysql_password.Text; // Start timmers tim_1000ms.Enabled = true; tim_10000ms.Enabled = true; + } private void con_Button_Listen_OFF_Click(object sender, EventArgs e) @@ -207,6 +225,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_server.Enabled = true; con_txt_3rd_lotatc.Enabled = true; con_txt_3rd_srs.Enabled = true; @@ -261,7 +280,9 @@ namespace Perun_v1 Properties.Settings.Default.MYSQL_DB = con_txt_mysql_database.Text; Properties.Settings.Default.MYSQL_User = con_txt_mysql_username.Text; Properties.Settings.Default.MYSQL_Password = con_txt_mysql_password.Text; + Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text; Properties.Settings.Default.MYSQL_Server = con_txt_mysql_server.Text; + Properties.Settings.Default.MYSQL_Port = con_txt_mysql_port.Text; Properties.Settings.Default.OTHER_LOTATC_FILE = con_txt_3rd_lotatc.Text; Properties.Settings.Default.OTHER_SRS_FILE = con_txt_3rd_srs.Text; Properties.Settings.Default.OTHER_LOTATC_USE = con_check_3rd_lotatc.Checked; @@ -333,14 +354,31 @@ namespace Perun_v1 private void tim_10000ms_Tick(object sender, EventArgs e) { // Main timer to send JSON files to MySQL - string strSRSJson = System.IO.File.ReadAllText(con_txt_3rd_srs.Text); - LogHistoryAdd(ref LogHistory, "SRS data loaded"); - string strLotATCJson = System.IO.File.ReadAllText(con_txt_3rd_lotatc.Text); - LogHistoryAdd(ref LogHistory, "LotATC data loaded"); + string strSRSJson; + string strLotATCJson; + + if (con_check_3rd_srs.Checked) + { + strSRSJson = System.IO.File.ReadAllText(con_txt_3rd_srs.Text); + LogHistoryAdd(ref LogHistory, "SRS data loaded"); + strSRSJson = "{'type':'100','payload':'" + strSRSJson + "'}"; + } + else + { + strSRSJson = "{'type':'100','payload':{'ignore':'true'}}"; + } - strSRSJson = "{'type':'100','payload':'" + strSRSJson + "'}"; SendToMySql(strSRSJson); - strLotATCJson = "{'type':'101','payload':'" + strLotATCJson + "'}"; + if (con_check_3rd_lotatc.Checked) + { + strLotATCJson = System.IO.File.ReadAllText(con_txt_3rd_lotatc.Text); + LogHistoryAdd(ref LogHistory, "LotATC data loaded"); + strLotATCJson = "{'type':'101','payload':'" + strLotATCJson + "'}"; + + } else + { + strLotATCJson = "{'type':'101','payload':{'ignore':'true'}}"; + } SendToMySql(strLotATCJson); } } diff --git a/README.md b/README.md index 77e665e..171d6cb 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,17 @@ # Perun for DCS World This toolset extracts data from DCS World server and export it to local json file and UDP port. **Optional** windows app puts JSON data to MySQL database. +Additionaly windows app can be used to merge LotATC and DCS SRS data in one database making Perun for DCS World ultimate integration tool for server admins. ## Getting Started -You can use this toolkit with or without Windows app. Simple DCS export scripts will create JSON file which can be used for further processing. +You can use this toolkit with or without Windows app. Simple DCS export scripts will create JSON file which can be used for further processing, by default this file is created in Scripts\Json folder located in your Saved Games DCS folder tree. ### Prerequisites Core: * For JSON Export: * DCS World stable or DCS World beta - * For UDP Export: - * Windows app which handles UDP readouts * **(Optional)** For MySQL Export: * MySQL server with read/write access @@ -24,15 +23,28 @@ Core: * Download latest [release](https://github.com/szporwolik/perun/releases) **optionaly** together with Win32 binary file for MySQL export * Copy contents of DCS folder to you \Scripts folder (inside DCS folder in your Saved Games) -* Add the following line to your Export.lua : TBD -* Run the Win32 application +* create MySQL server 03_MySQL folder contains creation SQL file +* **optionaly** Run the Win32 application + * set MySQL connection data + * point LotATC json file location + * point DCS SRS json file location + * click connect and leave the app running * Start DCS World and host multiplayer session - * by default the JSON is written into : TBD - * by default the UDP port TBD is in use + * by default the JSON is written into Scripts\Json folder located in your Saved Games DCS folder tree + * by default the UDP port 48620 is in use as target -## Testing - -TBD +## Data packets +* ID: 1, contains version information +* ID: 2, contains status data in the following sections + * mission + * players +* ID: 3, available slots list and coalitions + * coalitions + * slots +* ID: 50, chat event +* ID: 51, game event +* ID: 100, DCS SRS's client-list.json +* ID: 101, LotATC's stats.json ## Built With