From 36c713ba3fc3f02a196056df1259c37bbb029407 Mon Sep 17 00:00:00 2001 From: szporowolik Date: Thu, 12 Sep 2019 18:14:05 +0200 Subject: [PATCH] Updated perun.lua for 8.0.0 --- 01_DCS/Hooks/Perun.lua | 45 +++++++++++++------ .../Perun_v1/01_Classes/TCPController.cs | 3 +- 02_Windows_App/Perun_v1/02_Forms/form_Main.cs | 2 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/01_DCS/Hooks/Perun.lua b/01_DCS/Hooks/Perun.lua index 7dd6fb1..07c84d0 100644 --- a/01_DCS/Hooks/Perun.lua +++ b/01_DCS/Hooks/Perun.lua @@ -9,9 +9,9 @@ package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll" Perun.RefreshStatus = 15 -- (int) base refresh rate in seconds to send status update (values lower than 60 may affect performance!) Perun.RefreshMission = 60 -- (int) refresh rate in seconds to send mission information (values lower than 60 may affect performance!) -Perun.UDPTargetPort = 48620 -- (int) UDP port to send data to -Perun.UDPSourcePort = 48621 -- (int) UDP port to send data from -Perun.Instance = 1 -- (int) Id number of instance (if multiple DCS instances are to run at the same PC) +Perun.TCPTargetPort = 48620 -- (int) TCP port to send data to +Perun.TCPPerunHost = "localhost" -- (string) IP adress of the Perun instance or "localhost" +Perun.Instance = 2 -- (int) Id number of instance (if multiple DCS instances are to run at the same PC) Perun.JsonStatusLocation = "Scripts\\Json\\" -- (string) folder relative do user's SaveGames DCS folder -> status file updated each RefreshMission Perun.MOTD_L1 = "Witamy na serwerze Gildia.org !" -- (string) Message send to players connecting the server - Line 1 Perun.MOTD_L2 = "Wymagamy obecnosci DCS SRS oraz TeamSpeak - szczegoly na forum" -- (string) Message send to players connecting the server - Line 2 @@ -20,7 +20,7 @@ Perun.MOTD_L2 = "Wymagamy obecnosci DCS SRS oraz TeamSpeak - szczegoly na forum" -- Variable init -Perun.Version = "v0.6.0" +Perun.Version = "v0.8.0" Perun.StatusData = {} Perun.SlotsData = {} Perun.MissionData = {} @@ -33,7 +33,7 @@ Perun.lastSentMission =0 Perun.JsonStatusLocation = lfs.writedir() .. Perun.JsonStatusLocation Perun.socket = require("socket") Perun.IsServer = true --DCS.isServer( ) -- TBD looks like DCS API error, always returning True -Perun.UDPSourcePort = Perun.UDPSourcePort + Perun.Instance - 1 +Perun.TCPSourcePort = Perun.TCPTargetPort + 10 + Perun.Instance - 1 -- ########### Helper function definitions ########### function stripChars(str) @@ -153,11 +153,34 @@ Perun.SideID2Name = function(id) end -- ########### Main code ########### + Perun.AddLog = function(text) -- Adds logs to DCS.log file net.log("Perun : ".. text) end +Perun.ConnectToPerun = function () + Perun.AddLog("Connecting to TCP server") + Perun.TCP = assert(Perun.socket.tcp()) + Perun.TCP:settimeout(2000) + _, err = Perun.TCP:connect(Perun.TCPPerunHost, Perun.TCPTargetPort) + if err then + Perun.AddLog("TCP connection error : " .. err) + else + Perun.AddLog("Connected to TCP server") + end +end + +Perun.SendPacket = function (data_id,temp) + _, err = Perun.TCP:send(temp) + if err then + Perun.AddLog("Packed drop " .. data_id .. ", error: " .. err) + Perun.ConnectToPerun() + else + Perun.AddLog("Packet send " .. data_id) + end +end + Perun.UpdateJsonStatus = function() -- Updates status json file TempData={} @@ -184,8 +207,7 @@ Perun.Send = function(data_id, data_package) temp=net.lua2json(TempData) temp=stripChars(temp) - Perun.UDP:send(temp) - Perun.AddLog("Packet send "..data_id) + Perun.SendPacket(data_id,temp) end Perun.UpdateStatusPart = function(part_id, data_package) @@ -259,6 +281,7 @@ end Perun.UpdateMission = function() -- Main function for mission information updates Perun.MissionData=DCS.getCurrentMission() + -- Perun.Send(4,Perun.MissionData) end Perun.LogChat = function(playerID,msg,all) @@ -655,11 +678,7 @@ end -- ########### Finalize and set callbacks ########### if Perun.IsServer then - Perun.UDP = assert(Perun.socket.udp()) - Perun.UDP:settimeout(0) - Perun.UDP:setsockname("*", Perun.UDPSourcePort) - Perun.UDP:setpeername("127.0.0.1",Perun.UDPTargetPort) - DCS.setUserCallbacks(Perun) - net.log("Loaded - Perun - VladMordock - " .. Perun.Version ) + net.log("Perun by VladMordock was loaded: " .. Perun.Version ) + Perun.ConnectToPerun() end diff --git a/02_Windows_App/Perun_v1/01_Classes/TCPController.cs b/02_Windows_App/Perun_v1/01_Classes/TCPController.cs index d1e4c80..dbe0f35 100644 --- a/02_Windows_App/Perun_v1/01_Classes/TCPController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/TCPController.cs @@ -63,10 +63,11 @@ internal class TCPController Console.WriteLine("TCP: Waiting for packet"); TcpClient tcpClient = tcpServer.AcceptTcpClient(); //if a connection exists, the server will accept it NetworkStream ns = tcpClient.GetStream(); //networkstream is used to send/receive messages + //tcpClient.ReceiveBufferSize = 65534; while (tcpClient.Connected && !TCPController.boolDone) //while the client is connected, we look for incoming messages { - arrReceiveByteArray = new byte[1024]; //the messages arrive as byte array + arrReceiveByteArray = new byte[65534]; //the messages arrive as byte array ns.Read(arrReceiveByteArray, 0, arrReceiveByteArray.Length); //the same networkstream reads the message sent by the client strReceivedData = Encoding.ASCII.GetString(arrReceiveByteArray, 0, arrReceiveByteArray.Length); Console.WriteLine("Sender: {0} Payload: {1}", null, strReceivedData); diff --git a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs index fbaee8e..7dc1eec 100644 --- a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs +++ b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs @@ -9,7 +9,7 @@ namespace Perun_v1 public partial class form_Main : Form { // Variable definitions - public string[] arrSendBuffer = new string[100]; // Mysql send buffer + public string[] arrSendBuffer = new string[65534]; // Mysql send buffer public bool boolLetMeOut = false; // Helper to handle system tray // ################################ Main ################################