Advertisement
Guest User

Automerge 0.4b

a guest
Jul 18th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function widget:GetInfo()
  2.     local version = "0.4 beta"
  3.     return {
  4.         name      = "Commshare: Auto Inviter v" .. version,
  5.         desc      = "Automatically invites players to squad.",
  6.         author    = "_Shaman",
  7.         date      = "7-15-2018",
  8.         license   = "OH LET IT BURN CUZ I NEED MOAR MONEY",
  9.         layer     = -99999999,  
  10.         enabled   = true,
  11.     }
  12. end
  13.  
  14.  
  15. --      Config
  16. local friends        = false                                                            -- do we invite our friends automatically?
  17. local clanmembers    = false                                                            -- do we invite our clanmates automatically?
  18. local invitebyelo    = false                                                            -- do we attempt to merge with strongest / weaker players? **May require redesign**
  19. local autoaccept     = false                                                            -- do we automatically accept lower player's requests?
  20. local automergecfg   = {ignore = {}, automerge = {}, autoaccept = {}, whitelist = {},
  21. version = 0.4}  -- config table. Contains ignore and automerge.
  22. local ignoreall      = "none"
  23. local autodefeat     = false
  24.  
  25. --      variables
  26. local numcoms        = 0                                -- Number of commanders remaining for us
  27. local numfacs        = 0                                -- Number of factories remaining for us.
  28. local numworkers     = 0                                -- Number of constructors remaining for us.
  29. local isdead         = false                            -- Are we currently dead?
  30. local clan, friendlist, myelo, mylevel, ignorelist      -- These are used for determining merges.
  31. local mergelist      = ""                               -- list of players to merge with.
  32. local mergecount     = 0                                -- count of the number of players we're merging with.
  33. local allylist       = {}                               -- Processed Alliance members.
  34. local autoinvited    = false                            -- have we automatically invited people?
  35. local enabledplayers = {}                               -- table of players who have this widget.
  36. local candidates     = {}
  37. local spec           = false
  38. local needsproc      = false
  39. local nextspam       = -1
  40.  
  41. --      Options
  42. options_path = 'Settings/Interface/Commshare'
  43.  
  44. options_order = {
  45.     'invitefriends',
  46.     'inviteclanmembers',
  47.     --'invitebyelo',
  48.     'autodefeated',
  49.     'autoaccept',
  50.     'ignoreall',
  51.     'reset',
  52. }
  53.  
  54. options = {
  55.     invitefriends = {
  56.         name  = "Automatically Invite Friends",
  57.         type  = "bool",
  58.         value = false,
  59.         OnChange = function(self)
  60.             friends = self.value
  61.         end,
  62.         noHotkey = true,
  63.         desc = "Automatically invites your friends to a commshare merger."
  64.     },
  65.     inviteclanmembers = {
  66.         name  = "Automatically Invite Clan Members",
  67.         type  = "bool",
  68.         value = false,
  69.         OnChange = function(self)
  70.             clanmembers = self.value
  71.         end,
  72.         noHotkey = true,
  73.         desc = "Automatically invites your fellow clan members to a commshare merger."
  74.     },
  75.     invitebyelo = {
  76.         name  = "Invite Strongest Player",
  77.         type  = "bool",
  78.         value = false,
  79.         OnChange = function(self)
  80.             invitebyelo = self.value
  81.         end,
  82.         noHotkey = true,
  83.         desc = "Automatically requests a merge with the strongest player."
  84.     },
  85.     autodefeated = {
  86.         name  = "Automerge When Defeated",
  87.         type  = "bool",
  88.         value = false,
  89.         OnChange = function(self)
  90.             autodefeat = self.value
  91.         end,
  92.         noHotkey = true,
  93.         desc = "When you have been defeated (no com + no factory + no workers), attempt to automatically merge with the highest elo player with this widget. This option does not merge you with dead players, and tries to merge you with someone with at least a commander and a factory."
  94.     },
  95.     ignoreall = {
  96.         name  = "Decline mode:",
  97.         type  = "radioButton",
  98.         items = {
  99.             {name = 'All',key='all',description="Ignore all invites."},
  100.             {name = 'Non-whitelist', key='whitelist', description="Ignore all non whitelisted players."},
  101.             {name = 'Non-clan members', key='nonclan',description="Ignore all nonclan members."},
  102.             {name = 'Non-friend', key='nonfriend', description="Ignore all nonfriends."},
  103.             {name = 'Non-clan/friends', key='nonfriendclan', description="Ignore everyone who isn't your friend or in your clan."},
  104.             {name = 'None', key='none', description="Don't ignore any invites."}
  105.         },
  106.         value = 'none',
  107.         OnChange = function(self)
  108.             ignoreall = self.value
  109.         end,
  110.         noHotkey = true,
  111.         desc = "Declines certain users based on this param."
  112.     },
  113.     autoaccept = {
  114.         name = "Autoaccept level:",
  115.         type = "radioButton",
  116.         items = {
  117.             {name = 'All',key='all',description="Accepts all invites. Not recommended."},
  118.             {name = 'Clan+Friends',key='clan+friends',description="Accepts all clan/friend invites."},
  119.             {name = 'Clan members',key='clan',description="Accepts all clan invites."},
  120.             {name = 'Friends',key='friends',description="Accepts all friend's merges."},
  121.             {name = 'Only specified',key='none',description="Only automerge selected players."},
  122.         },
  123.         value = 'none',
  124.         OnChange = function(self)
  125.             autoaccept = self.value
  126.         end,
  127.         noHotkey = true,
  128.         desc = "Accepts certain users based on this param.",
  129.     },
  130.     reset = {
  131.         name = "Reset configuration",
  132.         type = "button",
  133.         OnChange = function(self)
  134.             automergecfg = {ignore = {}, automerge = {}, autoaccept = {}, whitelist = {}, version = 0.4};Spring.Echo("User requested reset.")
  135.         end,
  136.         noHotkey = true,
  137.         desc = "Clears your whitelist, ignore list, automerge list and autoaccept list.",
  138.     },
  139. }
  140.  
  141. -- Loading tables used--
  142. function widget:GetConfigData()
  143.     return automergecfg
  144. end
  145.  
  146. function widget:SetConfigData(data)
  147.     Spring.Echo("Automerge: version is: " .. tostring(data.version))
  148.     if data.version ~= 0.4 then
  149.         Spring.Echo("Automerge: updating table structure.")
  150.         data.whitelist = {}
  151.         data.version = 0.4
  152.         data.automerge = {}
  153.     end
  154.     automergecfg = data
  155. end
  156.  
  157. local function ProcessAllyTeam()
  158.     local teamlist = Spring.GetTeamList(Spring.GetMyAllyTeamID())
  159.     for i=1, #teamlist do
  160.         local playerlist = Spring.GetPlayerList(teamlist[i])
  161.         for j=1, #playerlist do
  162.             local playerID, _, spec, teamID, _, _, _, _, _, playerKeys = Spring.GetPlayerInfo(playerlist[j])
  163.             if not spec then
  164.                 allylist[playerID] = {
  165.                 team = playerlist[j],
  166.                 elo = playerKeys.elo,
  167.                 level = playerKeys.level,
  168.                 clan = playerKeys.clanfull or "",
  169.                 }
  170.             end
  171.         end
  172.     end
  173. end
  174.  
  175. local function ProccessCommand(str)
  176.     local strtbl = {}
  177.     for w in string.gmatch(str, "%S+") do
  178.         if #strtbl < 5 then
  179.             strtbl[#strtbl+1] = w
  180.         else
  181.             strtbl[5] = strtbl .. " " .. w
  182.         end
  183.     end
  184.     return strtbl
  185. end
  186.  
  187. local function GetHighestElo(tab)
  188.     local highestteamid = -1
  189.     local highestelo = 0
  190.     for name,data in pairs(tab) do
  191.         if data["elo"] > highestelo then
  192.             highestelo = data["elo"]
  193.             highestteamid = data["team"]
  194.         end
  195.     end
  196.     return highestteamid
  197. end
  198.  
  199. function widget:GamePreload()
  200.     Spring.SendLuaUIMsg("automerger", "a")
  201. end
  202.  
  203. function widget:RecvLuaMsg(msg, playerID)
  204.     local name,_ = Spring.GetPlayerInfo(playerID)
  205.     if msg == "automerger" then
  206.         enabledplayers[name] = playerID
  207.         Spring.Echo("player " .. name .. " is using automerge!")
  208.     end
  209.     if msg == "automerge dead" and playerID ~= Spring.GetMyPlayerID() and (automergecfg.autoaccept[name] or ((friends or autoaccept == "friends" or autoaccept == "clan+friends") and friendlist:find(name)) or ((clanmembers or autoaccept == "clan" or autoaccept == "clan+friends") and select(10, Spring.GetPlayerInfo(playerID)).clan == clan) or autoaccept == "all") then
  210.         if not isdead and numcoms > 0 and numfacs > 0 then
  211.             Spring.SendLuaUIMsg("automerge accepting","a")
  212.         elseif not isdead and numcoms > 0 and numfacs == 0 then
  213.             Spring.SendLuaUIMsg("automerge nonideal","a")
  214.         elseif not isdead and numcoms == 0 numfacs > 0 then
  215.             Spring.SendLuaUIMsg("automerge nonideal","a")
  216.         end
  217.     end
  218.     if msg == "automerge accepting" then
  219.         candidates[name] = 2
  220.     elseif msg == "automerge nonideal" then
  221.         candidates[name] = 1
  222.     elseif msg == "autoinvite " .. Spring.GetMyPlayerID() and (automergecfg.autoaccept[name] or ((friends or autoaccept == "friends") and friendlist:find(name)) or ((clanmembers or autoaccept == "clan") and select(10, Spring.GetPlayerInfo(playerID)).clan == clan) or autoaccept == "all") then
  223.         Spring.SendLuaRulesMsg("sharemode invite " .. playerID)
  224.     end
  225. end
  226.  
  227. function widget:Initialize()
  228.     _,_,spec,_ = Spring.GetPlayerInfo(Spring.GetMyPlayerID())
  229.     if spec then
  230.         autoinvited = true -- turn off the widget's functions, but don't remove the widget so user can mess with settings.
  231.         return
  232.     end
  233.     if Spring.GetGameFrame() > 0 then
  234.         ProcessUnits()
  235.     end
  236.     local customkeys = select(10, Spring.GetPlayerInfo(Spring.GetMyPlayerID()))
  237.     clan = customkeys["clanfull"] -- the full name of your clan.
  238.     friendlist = customkeys["friends"] -- your friends list.
  239.     myelo = customkeys["elo"] -- your elo.
  240.     ignorelist = customkeys["ignored"] -- your ignore list. We automatically ignore requests from these users.
  241.     mylevel = customkeys["level"] -- your level.
  242.     ProcessAllyTeam()
  243.     Spring.Echo("Automerge: Determing merge list. Config:\nClan: " .. tostring(clanmembers) .. "\nfriends: " .. tostring(friends))
  244.     for name, data in pairs(allylist) do
  245.         if automergecfg.automerge[name] or (friends and friendlist[name]) or (clanmembers and data.clan == clan) then
  246.             if (ignoreall == "whitelist" and automerge.cfg.whitelist[name]) or ignoreall ~= "whitelist" then
  247.                 mergelist = mergelist .. " " .. name -- clever way of working around table creation.
  248.                 mergecount = mergecount + 1
  249.             end
  250.         end
  251.     end
  252. end
  253.  
  254. function ProcessUnits()
  255.     local myunits = Spring.GetTeamUnits(Spring.GetMyTeamID())
  256.     local unitdef
  257.     for i=1,#myunits do
  258.         unitdef = UnitDefs[Spring.GetUnitDefID(myunits[i])]
  259.         if unitdef.isFactory then
  260.             numfacs = numfacs+1
  261.         end
  262.         if unitdef.isMobileBuilder then
  263.             numworkers = numworkers+1
  264.         end
  265.         if unitdef.customParams.level or unitdef.customParams.dynamic_comm or unitdef.customParams.commtype then
  266.             numcoms = numcoms +1
  267.         end
  268.     end
  269.     if numfacs > 0 or numcoms > 0 or numworkers > 0 then
  270.         isdead = false
  271.     end
  272. end
  273.  
  274. function widget:TextCommand(msg)
  275.     if msg:find("automerge") then
  276.         local command = ProccessCommand(msg)
  277.         if command[2] == nil then
  278.             Spring.Echo("Automerge: Invalid command.")
  279.             return
  280.         end
  281.         if command[2] == "ignore" then
  282.             if command[3] == "add" and command[4] and command[4] ~= "" then
  283.                 Spring.Echo("game_message: ignoring invites from " .. command[4] .. ".")
  284.                 if command[5] == nil or command[5] == "" then
  285.                     local randomnum = math.random(1,5)
  286.                     if randomnum == 1 then
  287.                         command[5] = "Reasons"
  288.                     elseif randomnum == 2 then
  289.                         command[5] = "You're too ugly"
  290.                     elseif randomnum == 3 then
  291.                         command[5] = "Don't know"
  292.                     elseif randomnum == 4 then
  293.                         command[5] = "Wubwub"
  294.                     else
  295.                         command[5] = "Lobster"
  296.                     end
  297.                 end
  298.                 automergecfg.ignore[command[4]] = command[5]
  299.                 automergecfg.automerge[command[4]] = nil
  300.             elseif command[3] == "remove" and command[4] and command[4] ~= "" then
  301.                 if automergecfg.ignore[command[4]] then
  302.                     automergecfg.ignore[command[4]] = nil
  303.                     Spring.Echo("game_message: You are no longer ignoring " .. command[4] .. ".")
  304.                 else
  305.                     Spring.Echo("game_message: You aren't ignoring " .. command[4] .. "'s requests.")
  306.                 end
  307.             elseif command[3] == "list" then
  308.                 local ignorelist = ""
  309.                 local count = 0
  310.                 for name,reason in pairs(automergecfg.ignore) do
  311.                     ignorelist = ignorelist .. name .. ": " .. reason .. "\n"
  312.                     count = count+1
  313.                 end
  314.                 if count > 1 then
  315.                     Spring.Echo("game_message: You are ignoring " .. count .. " users' requests:\n" .. ignorelist)
  316.                 elseif count == 1 then
  317.                     Spring.Echo("game_message: You are ignoring " .. count .. " user's request:\n" .. ignorelist)
  318.                 else
  319.                     Spring.Echo("game_message: You aren't ignoring any user's request.")
  320.                 end
  321.             end
  322.         elseif command[2] == "add" then
  323.             if command[3] and command[3] ~= "" then
  324.                 if automergecfg.ignore[command[3]] or ignorelist:find(command[3]) then
  325.                     Spring.Echo("game_message: Remove " .. command[3] .. " from your ignore list first.")
  326.                 end
  327.                 automergecfg.automerge[command[3]] = true
  328.                 Spring.Echo("game_message:Added " .. command[3] .. " to automerge.")
  329.             else
  330.                 Spring.Echo("game_message: Invalid param for add.")
  331.             end
  332.         elseif command[2] == "remove" then
  333.             if command[3] and command[3] ~= "" then
  334.                 automergecfg.automerge[command[3]] = nil
  335.                 Spring.Echo("game_message:Removed " .. command[3] .. " from automerge.")
  336.             else
  337.                 Spring.Echo("game_message: Invalid param for remove.")
  338.             end
  339.         elseif command[2] == "list" then
  340.             local ignorelist = ""
  341.             local count = 0
  342.             for id,_ in pairs(automergecfg.automerge) do
  343.                 if count == 0 then
  344.                     ignorelist = ignorelist .. id
  345.                 else
  346.                     ignorelist = ignorelist .. ", "
  347.                 end
  348.                 count = count+1
  349.             end
  350.             if count > 1 then
  351.                 Spring.Echo("game_message: You are automerging with " .. count .. " users:\n" .. ignorelist)
  352.             elseif count == 1 then
  353.                 Spring.Echo("game_message: You are automerging with " .. count .. " user:\n" .. ignorelist)
  354.             else
  355.                 Spring.Echo("game_message: You aren't automerging with anyone.")
  356.             end
  357.         elseif command[2] == "autoaccept" then
  358.             if command[3] then
  359.                 if command[3] == "add" and command[4] then
  360.                     automergecfg.autoaccept[command[4]] = true
  361.                     Spring.Echo("game_message: Autoaccepting invites from " .. command[4] .. ".")
  362.                 elseif command[3] == "remove" and command[4] then
  363.                     if automergecfg.autoaccept[command[4]] then
  364.                         automergecfg.autoaccept[command[4]] = nil
  365.                         Spring.Echo("game_message: You are no longer autoaccepting invites from " .. command[4] .. ".")
  366.                     else
  367.                         Spring.Echo("game_message: You aren't autoaccepting " .. command[4] .. "'s requests.")
  368.                     end
  369.                 elseif command[3] == "list" then
  370.                     -- list the stuff here.
  371.                 end
  372.             end
  373.         elseif command[2] == "whitelist" then
  374.             if command[3] and command[3] == "add" and command[4] then
  375.                 Spring.Echo("game_message: Added " .. command[4] .. " to whitelist.")
  376.                 automergecfg.whitelist[command[4]] = true
  377.                 automergecfg.whitelist[command[4]] = true
  378.             elseif command[3] and command[3] == "remove" and command[4] then
  379.                 Spring.Echo("game_message: Removed " .. command[4] .. " from whitelist.")
  380.                 automergecfg.whitelist[command[4]] = nil
  381.             elseif command[3] and command[3] == "list" then
  382.                 local ignorelist = ""
  383.                 local count = 0
  384.                 for id,_ in pairs(automergecfg.whitelist) do
  385.                     if count == 0 then
  386.                         ignorelist = ignorelist .. id
  387.                     else
  388.                         ignorelist = ignorelist .. ", "
  389.                     end
  390.                     count = count+1
  391.                 end
  392.                 if count > 1 then
  393.                     Spring.Echo("game_message: You have " .. count .. " users whitelisted:\n" .. ignorelist)
  394.                 elseif count == 1 then
  395.                     Spring.Echo("game_message: You have " .. count .. " user whitelisted:\n" .. ignorelist)
  396.                 else
  397.                     Spring.Echo("game_message: You don't have anyone whitelisted.")
  398.                 end
  399.             end
  400.         else
  401.             Spring.Echo("game_message: Invalid automerge command.")
  402.         end
  403.     end
  404. end
  405.  
  406. function widget:UnitGiven(unitID, unitDefID, newTeam, oldTeam)
  407.     if newTeam == Spring.GetMyTeamID() then
  408.         local unitdef = Spring.GetUnitDefID(unitID)
  409.         if unitdef.isFactory then
  410.             numfacs = numfacs+1
  411.         end
  412.         if unitdef.isMobileBuilder then
  413.             numworkers = numworkers+1
  414.         end
  415.         if unitdef.customParams.level or unitdef.customParams.dynamic_comm or unitdef.customParams.commtype then
  416.             numcoms = numcoms +1
  417.         end
  418.     end
  419.     if oldTeam == Spring.GetMyTeamID() then -- I gave away a unitDefID
  420.         if unitdef.isFactory then
  421.             numfacs = numfacs-1
  422.         end
  423.         if unitdef.isMobileBuilder then
  424.             numworkers = numworkers-1
  425.         end
  426.         if unitdef.customParams.level or unitdef.customParams.dynamic_comm or unitdef.customParams.commtype then
  427.             numcoms = numcoms -1
  428.         end
  429.     end
  430. end
  431.  
  432. function widget:UnitFinished(unitID, unitDefID, unitTeam)
  433.     if unitTeam == Spring.GetMyTeamID() then
  434.         local unitdef = UnitDefs[unitDefID]
  435.         if unitdef.isFactory then
  436.             numfacs = numfacs+1
  437.         end
  438.         if unitdef.isMobileBuilder then
  439.             numworkers = numworkers+1
  440.         end
  441.         if unitdef.customParams.level or unitdef.customParams.dynamic_comm or unitdef.customParams.commtype then
  442.             numcoms = numcoms +1
  443.         end
  444.     end
  445. end
  446.  
  447. function widget:UnitReverseBuilt(unitID, unitDefID, unitTeam)
  448.     if unitTeam == Spring.GetMyTeamID() then
  449.         local unitdef = UnitDefs[unitDefID]
  450.         if unitdef.isFactory then
  451.             numfacs = numfacs-1
  452.         end
  453.         if unitdef.isMobileBuilder then
  454.             numworkers = numworkers-1
  455.         end
  456.         if unitdef.customParams.level or unitdef.customParams.dynamic_comm or unitdef.customParams.commtype then
  457.             numcoms = numcoms -1
  458.         end
  459.     end
  460. end
  461.  
  462. function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
  463.     if unitTeam == Spring.GetMyTeamID() then
  464.         local unitdef = UnitDefs[unitDefID]
  465.         if unitdef.isFactory then
  466.             numfacs = numfacs-1
  467.         end
  468.         if unitdef.isMobileBuilder then
  469.             numworkers = numworkers-1
  470.         end
  471.         if unitdef.customParams.level or unitdef.customParams.dynamic_comm or unitdef.customParams.commtype then
  472.             numcoms = numcoms -1
  473.         end
  474.     end
  475. end
  476.  
  477. function widget:GameFrame(f)
  478.     if spec then
  479.         return
  480.     end
  481.     --if f%60 == 0 then
  482.         --Spring.Echo("Automerge debug:\n Constructors: " .. numworkers .. "\nCommanders: " .. numcoms .. "\nFactories: " .. numfacs)
  483.     --end
  484.     if needsproc then
  485.         ProcessUnits()
  486.         needsproc = false
  487.     end
  488.     if autoinvited == false and f> 10 then
  489.         autoinvited = true
  490.         local invited = "I invited " -- list of players we've invited.
  491.         for name,data in pairs(allylist) do
  492.             if mergelist:find(name) then
  493.                 Spring.SendLuaRulesMsg("sharemode invite " .. data["team"])
  494.                 if enabledplayers[name] == nil then
  495.                     invited = invited .. name .. ","
  496.                 end
  497.             end
  498.         end
  499.         if invited ~= "I invited " then
  500.             invited = invited:sub(1, -2)
  501.             Spring.SendCommands("say a:" .. invited .. " to join my squad.")
  502.         end
  503.         if invitebyelo then
  504.             local highestplayer = GetHighestElo(playerlistprocessed)
  505.             if highestplayer == Spring.GetMyTeamID() then
  506.                 for name,data in pairs(enabledplayers) do
  507.                     if automergecfg.ignore[name] == nil and not ignorelist:find(name) then
  508.                         Spring.SendLuaRulesMsg("sharemode invite " .. data["team"])
  509.                     end
  510.                 end
  511.             end
  512.         end
  513.     end
  514.     if autodefeat and f%15 == 6 then
  515.         if not isdead and numcoms == 0 and numworkers == 0 and numfacs == 0 then
  516.             isdead = true
  517.             Spring.Echo("Automerge: User is dead!")
  518.         end
  519.         if f > nextspam then
  520.             Spring.SendLuaUIMsg("automerge dead","a")
  521.             candidates = {}
  522.         end
  523.     end
  524.     if autodefeat and f%15 == 12 and isdead and (numcoms > 0 or numworkers > 0 or numfacs > 0) then
  525.         isdead = false
  526.         Spring.Echo("Automerge: User revived.")
  527.     end
  528.     if autodefeat and f%15 == 13 and isdead and numcoms == 0 and numworkers == 0 and numfacs == 0 then
  529.         local players = {}
  530.         local hasgoodplayers = false
  531.         for name,value in pairs(candidates) do
  532.             if value == 2 then -- prioritize putting us with someone in a okay position
  533.                 players[#players+1] = name
  534.                 hasgoodplayers = true
  535.             end
  536.         end
  537.         if not hasgoodplayers then
  538.             for name, value in pairs(candidates) do
  539.                 players[#players+1] = name
  540.             end
  541.         end
  542.         if #players == 1 then
  543.             Spring.SendLuaUIMsg("autoinvite " .. allylist[name].team)
  544.         elseif #players > 1 then
  545.             candidates = {}
  546.             local name = ""
  547.             for i=1,#players do
  548.                 name = players[i]
  549.                 candidates[name] = {elo=allylist[name].elo, team=allylist[name].team}
  550.             end
  551.             Spring.SendLuaUIMsg("autodead " .. GetHighestElo(candidates))
  552.         elseif f > nextspam then
  553.             Spring.SendCommands("say a:Need constructor or factory!")
  554.             nextspam = f + 1800 -- try again in a minute.
  555.         end
  556.     end
  557.     if f%15 == 0 then
  558.         local invitecount = Spring.GetPlayerRulesParam(Spring.GetMyPlayerID(), "commshare_invitecount") or 0
  559.         if invitecount > 0 then
  560.             for i=1, invitecount do
  561.                 local id = Spring.GetPlayerRulesParam(Spring.GetMyPlayerID(), "commshare_invite_" .. i .. "_id")
  562.                 local name,_ = Spring.GetPlayerInfo(id)
  563.                 local clanname = select(10,Spring.GetPlayerInfo(id)).clanfull
  564.                 if clanname == nil then clanname = "" end
  565.                 if ((candidates[name] and autodefeat) or automergecfg.autoaccept[name] or ((autoaccept == "friends" or autoaccept == "clan+friends") and friendlist:find(name)) or autoaccept=="all" or ((autoaccept == "clan" or autoaccept == "clan+friends") and clanname == clan)) and ignoreall ~= "all" and ignorelist:find(name) == nil and automergecfg.ignore[name] == nil then
  566.                     Spring.SendLuaRulesMsg("sharemode accept " .. id)
  567.                     needsproc = true
  568.                 elseif automergecfg.ignore[name] or string.find(ignorelist,name) or ((ignoreall == "nonfriend" or ignoreall == "nonfriendclan") and not friendlist:find(name)) or ((ignoreall == "nonclan" or ignoreall == "nonfriendclan") and clan ~= allylist[name].clan) or (ignoreall== "whitelisted" and automergecfg.whitelist[name] == nil) then
  569.                     Spring.SendLuaRulesMsg("sharemode decline " .. id)
  570.                     local reason = ""
  571.                     if string.find(ignorelist,name) then
  572.                         reason = "You are ignored by this user."
  573.                     end
  574.                     if reason == "" and ignoreall == "whitelist" and automergecfg.whitelist[name] == nil then
  575.                         reason = "You need to be whitelisted by this user."
  576.                     end
  577.                     if reason == "" and automergecfg.ignore[name] then
  578.                         reason = automergecfg.ignore[name]
  579.                     end
  580.                     if reason == "" and ignoreall ~= "none" and ignoreall ~= "all" then
  581.                         reason = "Not interested in random invites."
  582.                     else
  583.                         reason = "Not interested in commshare."
  584.                     end
  585.                     Spring.SendCommands("w " .. name .. " is not interested in merging with you. Reason: " .. reason)
  586.                 end
  587.             end
  588.         end
  589.     end
  590. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement