Guest User

broseem+json

a guest
Nov 7th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.26 KB | None | 0 0
  1. --[[
  2. broseem v1.20161007
  3.  
  4. Copyright © 2016, Mojo
  5. All rights reserved.
  6.  
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are met:
  9.  
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. * Neither the name of timestamp nor the
  16. names of its contributors may be used to endorse or promote products
  17. derived from this software without specific prior written permission.
  18.  
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. DISCLAIMED. IN NO EVENT SHALL Giuliano Riccio BE LIABLE FOR ANY
  23. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. ]]
  30.  
  31. _addon.name     = 'broseem'
  32. _addon.author   = 'Mojo'
  33. _addon.version  = '1.20161007'
  34. _addon.commands = {}
  35.  
  36. require('pack')
  37. require('lists')
  38. require('logger')
  39. require('sets')
  40.  
  41. files = require('files')
  42. extdata = require('extdata')
  43. packets = require('packets')
  44. local http = require("socket.http")
  45. local ltn12 = require("ltn12")
  46.  
  47. local path = 'data/augments.csv'
  48. local item = {}
  49. local hook = false
  50. local jsonserver = "http://10.0.0.10:8080/oseem/"
  51.  
  52. local stones = {
  53.     [0] = 'pellucid',
  54.     [1] = 'fern',
  55.     [2] = 'taupe',
  56.     [3] = 'dark matter',
  57. }
  58.  
  59. local paths = {
  60.     [8] = 'melee',
  61.     [264] = 'ranged',
  62.     [520] = 'magic',
  63.     [776] = 'familiar',
  64.     [1032] = 'healing',
  65.     [1290] = 'techniques',
  66. }
  67.  
  68. local gear = {
  69.     [27496] = 'Herculean Boots',
  70.     [27140] = 'Herculean Gloves',
  71.     [25642] = 'Herculean Helm',
  72.     [25842] = 'Herculean Trousers',
  73.     [25718] = 'Herculean Vest',
  74.     [27497] = 'Merlinic Crackows',
  75.     [27141] = 'Merlinic Dastanas',
  76.     [25643] = 'Merlinic Hood',
  77.     [25719] = 'Merlinic Jubbah',
  78.     [25843] = 'Merlinic Shalwar',
  79.     [25716] = 'Odyssean Chestplate',
  80.     [25840] = 'Odyssean Cuisses',
  81.     [27138] = 'Odyssean Gauntlets',
  82.     [27494] = 'Odyssean Greaves',
  83.     [25640] = 'Odyssean Helm',
  84.     [25841] = 'Valorous Hose',
  85.     [27495] = 'Valorous Greaves',
  86.     [25717] = 'Valorous Mail',
  87.     [25641] = 'Valorous Mask',
  88.     [27139] = 'Valorous Mitts',
  89.     [25720] = 'Chironic Doublet',
  90.     [27142] = 'Chironic Gloves',
  91.     [25644] = 'Chironic Hat',
  92.     [25844] = 'Chironic Hose',
  93.     [27498] = 'Chironic Slippers',
  94.     [21754] = 'Aganoshe',
  95.     [20677] = 'Colada',
  96.     [20505] = 'Condemners',
  97.     [21746] = 'Digirbalag',
  98.     [21072] = 'Gada',
  99.     [22054] = 'Grioavolr',
  100.     [22134] = 'Holliday',
  101.     [21904] = 'Kanaria',
  102.     [21804] = 'Obschine',
  103.     [21854] = 'Reienkyo',
  104.     [20579] = 'Skinflayer',
  105.     [22113] = 'Teller',
  106.     [21021] = 'Umaru',
  107.     [21686] = 'Zulfiqar',
  108. }
  109.  
  110. function make_timestamp()
  111.     return os.date('%Y:%m:%d %H:%M:%S')
  112. end
  113.  
  114. local function save_augments()
  115.     local fh
  116.     if not files.exists(path) then
  117.         files.create_path('data')
  118.         fh = io.open(windower.addon_path .. path, 'w')
  119.         local header = "timestamp,name,stone,path,augment 1,augment 2,augment 3,augment 4,augment5\r"
  120.         fh:write(header)
  121.         fh:close()
  122.     end
  123.     fh = fh or io.open(windower.addon_path .. path, 'a')
  124.     local output = "%s,%s,%s,%s,":format(make_timestamp(),item.name, item.stone, item.path)
  125.     for i = 1, 4 do
  126.         output = output.."%s,":format(item.augments.augments[i])
  127.     end
  128.     output = output.."%s\r":format(item.augments.augments[5])
  129.     local fh = io.open(windower.addon_path .. path, 'a')
  130.     fh:write(output)
  131.     fh:flush()
  132.     --local http = '"timestamp":"'..make_timestamp()..'","name":"'..item.name..'","stone":"'..item.stone..'","path":"'..item.path..'","augment1":"'..item.augments.augments[1]..'","augment2":"'..item.augments.augments[2]..'","augment3":"'..item.augments.augments[3]..'","augment4":"'..item.augments.augments[4]..'","augment5":"'..item.augments.augments[5]..'"'
  133.     --print(http)
  134. end
  135.  
  136. function sendRequest()
  137.     if jsonserver ~= nil then
  138.         local jsonserver = "http://10.0.0.10:8080/oseem/"
  139.         local payload = '{"timestamp":"'..make_timestamp()..'","name":"'..item.name..'","stone":"'..item.stone..'","path":"'..item.path..'","augment1":"'..item.augments.augments[1]..'","augment2":"'..item.augments.augments[2]..'","augment3":"'..item.augments.augments[3]..'","augment4":"'..item.augments.augments[4]..'","augment5":"'..item.augments.augments[5]..'"}'
  140.         local response_body = { }
  141.         local res, code, response_headers, status = http.request
  142.         {
  143.         url = jsonserver,
  144.         method = "POST",
  145.         headers =
  146.         {
  147.             ["Content-Type"] = "application/json",
  148.             ["Content-Length"] = payload:len()
  149.         },
  150.         source = ltn12.source.string(payload),
  151.         sink = ltn12.sink.table(response_body)
  152.         }
  153.     end
  154. end
  155.  
  156. local function watch_trade(id, org)
  157.     if id == 0x36 then
  158.         local p = packets.parse('outgoing', org)
  159.         local name = (windower.ffxi.get_mob_by_id(p['Target']) or {}).name
  160.         if (name == 'Oseem') and (p['Number of Items'] == 1) then
  161.             item = windower.ffxi.get_items(0, p['Item Index 1'])
  162.         end
  163.     end
  164. end
  165.  
  166. local function broseemify(id, org)
  167.     if (id == 0x5B) and item.id then
  168.         local p = packets.parse('outgoing', org)
  169.         local name = (windower.ffxi.get_mob_by_id(p['Target']) or {}).name
  170.         if name == 'Oseem' and paths[p['Option Index']] then
  171.             item.stone = stones[p['_unknown1']]
  172.             item.path = paths[p['Option Index']]
  173.             hook = true
  174.         end
  175.     end
  176. end
  177.  
  178. local function log_augments(id, data)
  179.     if (id == 0x5c) and hook then
  180.         local p = packets.parse('incoming', data)
  181.         item.extdata = p['Menu Parameters']:sub(21)..item.extdata:sub(13)
  182.         item.augments = extdata.decode(item)
  183.         item.name = gear[item.id]
  184.         save_augments()
  185.         sendRequest()
  186.         hook = false
  187.     end
  188. end
  189.  
  190. windower.register_event('outgoing chunk', watch_trade)
  191. windower.register_event('incoming chunk', log_augments)
  192. windower.register_event('outgoing chunk', broseemify)
  193.  
  194. windower.register_event('addon command', function (...)
  195.     local args    = T{...}:map(string.lower)
  196.     log('%s v%s':format(_addon.name, _addon.version))
  197.     log('There are no commands for this add-on. You just have it on while your augmenting you Reisenjima Gear will log it.')
  198.     log('Please just once in a while upload your augments.csv file located in the folder: broseem/data to')
  199.     log('http://tinyurl.com/Broseem')
  200.     log('Full Length URL: https://drive.google.com/drive/folders/0B8xuIyjPy66QYlJLRWt5ZVBQTnM?usp=sharing')
  201.     log('There is no need for you to worry about clearing out old augments for us we can handle duplicates no problem!')
  202. end)
Add Comment
Please, Sign In to add comment