/
DCS-SRS-AutoConnectGameGUI.lua
60 lines (47 loc) · 1.85 KB
/
DCS-SRS-AutoConnectGameGUI.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Version 1.4.2.0
-- ONLY COPY THIS FILE IS YOU ARE GOING TO HOST A SERVER!
-- The file must be in Saved Games\DCS\Scripts or Saved Games\DCS.openalpha\Scripts
-- Make sure you enter the correct address into SERVER_SRS_HOST below.
-- You can add an optional Port. e.g. "127.0.0.1:5002"
-- User options --
local SRSAuto = {}
SRSAuto.SERVER_SRS_HOST = "127.0.0.1"
SRSAuto.SERVER_SEND_AUTO_CONNECT = true -- set to false to disable auto connect or just remove this file
-- DO NOT EDIT BELOW HERE --
SRSAuto.unicast = true
-- Utils --
local HOST_PLAYER_ID = 1
SRSAuto.MESSAGE_PREFIX = "SRS Running @ " -- DO NOT MODIFY!!!
package.path = package.path..";.\\LuaSocket\\?.lua;"
package.cpath = package.cpath..";.\\LuaSocket\\?.dll;"
local socket = require("socket")
SRSAuto.UDPSendSocket = socket.udp()
SRSAuto.UDPSendSocket:settimeout(0)
SRSAuto.logFile = io.open(lfs.writedir()..[[Logs\DCS-SRS-AutoConnect.log]], "w")
function SRSAuto.log(str)
if SRSAuto.logFile then
SRSAuto.logFile:write(str.."\n")
SRSAuto.logFile:flush()
end
end
-- Register callbacks --
SRSAuto.onPlayerConnect = function(id)
if not DCS.isServer() then
return
end
if SRSAuto.SERVER_SEND_AUTO_CONNECT and id ~= HOST_PLAYER_ID then
SRSAuto.log(string.format("Sending auto connect message to player %d on connect ", id))
net.send_chat_to(string.format(SRSAuto.MESSAGE_PREFIX .. "%s", SRSAuto.SERVER_SRS_HOST), id)
end
end
SRSAuto.onPlayerChangeSlot = function(id)
if not DCS.isServer() then
return
end
if SRSAuto.SERVER_SEND_AUTO_CONNECT and id ~= HOST_PLAYER_ID then
SRSAuto.log(string.format("Sending auto connect message to player %d on switch ", id))
net.send_chat_to(string.format(SRSAuto.MESSAGE_PREFIX .. "%s", SRSAuto.SERVER_SRS_HOST), id)
end
end
DCS.setUserCallbacks(SRSAuto)
net.log("Loaded - DCS-SRS-AutoConnect")