mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 17:45:38 +02:00
First working version
This commit is contained in:
@@ -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 obecno<6E>ci 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)
|
||||
|
||||
Reference in New Issue
Block a user