Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.73 KB | None | 0 0
  1. -- w = window, tx = text, l = list, b = button
  2. package.loaded.gml=nil
  3. package.loaded.gfxbuffer=nil
  4. local gml = require('gml')
  5. local event = require('event')
  6. local utf8 = require('unicode')
  7. local computer = require('computer')
  8. local component = require('component')
  9. local serialization = require('serialization')
  10. local modem = component.modem
  11. local i_c = component.inventory_controller
  12. local interface = component.me_interface
  13. component.gpu.setResolution(48, 17)
  14. local W, H = component.gpu.getResolution()
  15. local hW = W/2
  16. local db = {}
  17. --th=require('thread').create(function()while true do pcall(os.sleep, 1)end end):detach()
  18. --th=require('thread').create(function()while true do pcall(os.sleep, 1)end end):detach()
  19. function event.shouldInterrupt() return false end
  20. function event.shouldSoftInterrupt() return false end
  21.  
  22. local cfg = {
  23.   port = 3215,
  24.   operator = 'Doob',
  25.   logins = 30,
  26.   fee = 0.01,
  27.   max = 100000, -- maximum cost
  28.   ic_side = 1, -- chest for i_c
  29.   mei_side = 'WEST' -- chest for me_interface
  30. }
  31.  
  32. local tmpData = {
  33.   price_selected = 0,
  34.   CURRENT_USER = '',
  35.   BALANCE_TEXT = '',
  36.   BTXT_LEN = 0,
  37.   lastlogin = 0,
  38.   tooltip = '',
  39.   ttp_len = 0,
  40.   BUFFER = {},
  41.   uiBuffer = {},
  42.   uiStorage = {}
  43. }
  44.  
  45. local loc = {
  46.   buy = 'Купить',
  47.   sell = 'Продать',
  48.   sell_all = 'Продать всё',
  49.   info = 'Информация',
  50.   cancel = 'Отмена',
  51.   next = 'Далее',
  52.   apply = 'Принять',
  53.   exit = 'Выход',
  54.   label = 'Наименование',
  55.   amount = 'Количество',
  56.   inStock = 'В наличии: ',
  57.   total = 'Сумма',
  58.   price = 'Цена',
  59.   sell_items = 'Продать предметы?',
  60.   sell_amount = 'Количество: ',
  61.   sell_profit = 'На сумму: $_ (комиссия ~%)',
  62.   operations = 'Доступно операций: ',
  63.   reset = 'Сброс через _ минут',
  64.   drop = 'Брось предметы для продажи перед роботом'
  65. }
  66.  
  67. local function save_db()
  68.   local file = io.open('market.db', 'w')
  69.   file:write(serialization.serialize(db))
  70.   file:close()
  71. end
  72.  
  73. local function load_db()
  74.   local file = io.open('market.db', 'r')
  75.   if not file then
  76.     file = io.open('market.db', 'w')
  77.     file:write(serialization.serialize(db))
  78.   else
  79.     local serdb = file:read('a')
  80.     db = serialization.unserialize(serdb)
  81.   end
  82.   file:close()
  83. end
  84.  
  85. local function log_add(str)
  86.   local file = io.open('market.log', 'a')
  87.   file:write(str..'\n')
  88.   file:close()
  89. end
  90.  
  91. local function add_sp(str, n)
  92.   if n-1 < utf8.len(str) then
  93.     return utf8.sub(str, 1, n)
  94.   else
  95.     for i = 1, n-utf8.len(str) do
  96.       str = str..' '
  97.     end
  98.     return str
  99.   end
  100. end
  101.  
  102. local function logout()
  103.   save_db()
  104.   computer.beep(220, 0.1)
  105.   modem.broadcast(cfg.port, 'export')
  106.   computer.removeUser(tmpData.CURRENT_USER)
  107.   tmpData.CURRENT_USER = nil
  108. end
  109.  
  110. local function updateCost(item)
  111.   -- O/(I-O[+1])/I*M
  112.   -- ((R-C)/R)*C+C
  113.   -- (C-R)/3+R
  114.   local R_cost = math.ceil(db.items[item].o/(db.items[item].i-db.items[item].o+1)/db.items[item].i*cfg.max)
  115.   local C_cost = db.items[item].cost
  116.   if C_cost <= R_cost then
  117.     C_cost = ((R_cost-C_cost)/R_cost)*C_cost+C_cost
  118.   elseif C_cost > R_cost then
  119.     C_cost = (C_cost-R_cost)/3+R_cost
  120.   end
  121.   if C_cost < 1 then C_cost = 1 end
  122.   db.items[item].cost = math.ceil(C_cost)
  123.   --db.items[item].cost = R_cost
  124.   if os.time()-db.users[tmpData.CURRENT_USER].lastlogin < 259200 then
  125.     if db.users[tmpData.CURRENT_USER].count <= cfg.logins then
  126.       db.users[tmpData.CURRENT_USER].count = db.users[tmpData.CURRENT_USER].count + 1
  127.     end
  128.   else
  129.     db.users[tmpData.CURRENT_USER].count = 1
  130.     db.users[tmpData.CURRENT_USER].lastlogin = os.time()
  131.   end
  132. end
  133.  
  134. local function buy(item, amount)
  135.   local n = item:find('|')
  136.   local fprint = {id = item:sub(1, n-1), dmg = item:sub(1, n+1)}
  137.   local item_dmp = interface.getItemDetail(fprint)
  138.   local current, result, size = amount, 0
  139.   if item_dmp then
  140.     item_dmp = item_dmp.basic()
  141.     if item_dmp.qty < amount then
  142.       amount = item_dmp.qty
  143.     end
  144.     for stack = 1, math.ceil(amount/item_dmp.max_size) do
  145.       size = interface.exportItem(fprint, cfg.mei_side, current).size
  146.       current, result = current - size, result + size
  147.     end
  148.   end
  149.   db.items[tmpData.selected].o = db.items[tmpData.selected].o + result
  150.   log_add(os.time()..'@'..tmpData.CURRENT_USER..'@'..db.users[tmpData.CURRENT_USER].balance..'@<@'..item..'@'..amount..'@'..db.items[item].i-db.items[item].o..'@'..db.items[item].cost)
  151.   db.users[tmpData.CURRENT_USER].balance = db.users[tmpData.CURRENT_USER].balance - tmpData.price_selected * result
  152.   updateCost(item)
  153.   logout()
  154.   computer.beep(440, 0.05)
  155. end
  156.  
  157. local function sell()
  158.   for item, amount in pairs(tmpData.selected) do
  159.     local result = 0
  160.     for slot = 1, i_c.getInventorySize(cfg.ic_side) do
  161.       local fitem = i_c.getStackInSlot(cfg.ic_side, slot)
  162.       if fitem and item == fitem.name..'|'..fitem.damage then
  163.         local size
  164.         if fitem.size < amount then
  165.           size = interface.pullItem(cfg.mei_side, slot, fitem.qty)
  166.         elseif fitem.size >= amount then
  167.           size = interface.pullItem(cfg.mei_side, slot, amount)
  168.         end
  169.         amount, result = amount - size, result + size
  170.         if amount == 0 then
  171.           break
  172.         end
  173.       end
  174.     end
  175.     db.items[item].i = db.items[item].i + result
  176.     log_add(os.time()..'@'..tmpData.CURRENT_USER..'@'..db.users[tmpData.CURRENT_USER].balance..'@>@'..item..'@'..result..'@'..db.items[item].i-db.items[item].o..'@'..db.items[item].cost)
  177.     updateCost(item)
  178.   end
  179.   db.users[tmpData.CURRENT_USER].balance = db.users[tmpData.CURRENT_USER].balance+tmpData.price_selected
  180.   db.users[cfg.operator].balance = db.users[cfg.operator].balance + tmpData.fee
  181.   logout()
  182.   computer.beep(440, 0.05)
  183. end
  184.  
  185. local function netScan()
  186.   tmpData.uiStorage = {[0]={}}
  187.   for name, item in pairs(db.items) do
  188.     if item.i and item.o and item.label and item.cost then
  189.       local size = item.i-item.o
  190.       if size > 0 then
  191.         local text = add_sp(add_sp(item.label, W-26)..size, W-15)..item.cost
  192.         table.insert(tmpData.uiStorage, text)
  193.         tmpData.uiStorage[0][text] = name
  194.       end
  195.     end
  196.   end
  197. end
  198.  
  199. local function bufferScan()
  200.   tmpData.BUFFER = {}
  201.   local item, name
  202.   for slot = 1, i_c.getInventorySize(cfg.ic_side) do
  203.     item = i_c.getStackInSlot(cfg.ic_side, slot)
  204.     if item then
  205.       name = item.name..'|'..item.damage
  206.       if db.items[name] then
  207.         if not tmpData.BUFFER[name] then
  208.           tmpData.BUFFER[name] = item.size
  209.         else
  210.           tmpData.BUFFER[name] = tmpData.BUFFER[name]+item.size
  211.         end
  212.       end
  213.     end
  214.   end
  215.   tmpData.uiBuffer = {[0] = {}}
  216.   for item, size in pairs(tmpData.BUFFER) do
  217.     local text = add_sp(add_sp(db.items[item].label, W-26)..size, W-15)..db.items[item].cost
  218.     table.insert(tmpData.uiBuffer, text)
  219.     tmpData.uiBuffer[0][text] = item
  220.   end
  221. end
  222.  
  223. local function utf_find(str, match)
  224.   local match_len = utf8.len(match)
  225.   for i = 1, utf8.len(str) do
  226.     if utf8.sub(str, i, i+match_len-1) == match then
  227.       return i
  228.     end
  229.   end
  230.   return 0
  231. end
  232.  
  233. local function update_txBalance()
  234.   tmpData.BALANCE_TEXT = tmpData.CURRENT_USER..': '..db.users[tmpData.CURRENT_USER].balance
  235.   tmpData.BTXT_LEN = #tmpData.BALANCE_TEXT
  236. end
  237.  
  238. local wMain = gml.create(1, 1, W, H)
  239. local wBuyList = gml.create(1, 1, W, H)
  240. local wBuy = gml.create(1, 1, W, H)
  241. local wSellLoad = gml.create(1, 1, W, H)
  242. local wSellList = gml.create(1, 1, W, H)
  243. local wSell = gml.create(1, 1, W, H)
  244. local wInfo = gml.create(1, 1, W, H)
  245. wMain.style = gml.loadStyle('style')
  246. wBuyList.style = wMain.style
  247. wBuy.style = wMain.style
  248. wSellLoad.style = wMain.style
  249. wSellList.style = wMain.style
  250. wSell.style = wMain.style
  251. wInfo.style = wMain.style
  252.  
  253. -- Buy List -----------------------
  254. local txBalance_wBuyList = wBuyList:addLabel(2, 1, 1, '')
  255. local txTooltip_wBuyList = wBuyList:addLabel(2, 2, 1, '')
  256. local lItems_wBuyList = wBuyList:addListBox('center', 3, W-4, H-6, {})
  257. local tfFind_wBuyList = wBuyList:addTextField(W-24,1,17)
  258. local bFind_wBuyList = wBuyList:addButton('right', 1, 6, 1, 'Find', function()
  259.   if #tfFind_wBuyList.text > 0 and #lItems_wBuyList.list > 1 then
  260.     local tmpList = {table.unpack(lItems_wBuyList.list)}
  261.     for i = 1, #tmpList do
  262.       if utf_find(utf8.lower(tmpList[i]), utf8.lower(tfFind_wBuyList.text)) > 0 then
  263.         local tmpItem = tmpList[i]
  264.         table.remove(tmpList, i)
  265.         table.insert(tmpList, 1, tmpItem)
  266.       end
  267.     end
  268.     tfFind_wBuyList.text = ''
  269.     lItems_wBuyList:updateList(tmpList)
  270.     wBuyList:draw()
  271.   end
  272. end)
  273. local bCancel_wBuyList = wBuyList:addButton('left', H-2, 13, 1, loc.cancel, function()
  274.   logout()
  275.   wBuyList:hide()
  276.   wBuyList.close()
  277. end)
  278. -----------------------------------
  279.  
  280. -- Buy ----------------------------
  281. local txBalance_wBuy = wBuy:addLabel(1, 1, 1, '')
  282. local txItemName_wBuy = wBuy:addLabel(1, 2, 1, '')
  283. local txInStock_wBuy = wBuy:addLabel(1, 3, 1, '')
  284. local txItemPrice_wBuy = wBuy:addLabel(1, 4, 1, '')
  285. local txTotalSum_wBuy = wBuy:addLabel(1, 6, 1, '')
  286. local txAmount_wBuy = wBuy:addLabel(1, 7, 1, '')
  287. local nAmount_wBuy = 0
  288. local function nUpdate(n)
  289.   if nAmount_wBuy == 0 then
  290.     nAmount_wBuy = n
  291.   else
  292.     nAmount_wBuy = nAmount_wBuy*10+n
  293.   end
  294.   if nAmount_wBuy*tmpData.price_selected > db.users[tmpData.CURRENT_USER].balance then
  295.     nAmount_wBuy = math.floor(db.users[tmpData.CURRENT_USER].balance/tmpData.price_selected)
  296.   end
  297.   local item = db.items[tmpData.selected]
  298.   local size = item.i-item.o
  299.   if nAmount_wBuy > size then
  300.     nAmount_wBuy = size
  301.   end
  302.   txTotalSum_wBuy.text = loc.total..': '..nAmount_wBuy*tmpData.price_selected
  303.   txTotalSum_wBuy.width = utf8.len(txTotalSum_wBuy.text)
  304.   txTotalSum_wBuy.posX = hW-utf_find(txTotalSum_wBuy.text, ':')
  305.   txAmount_wBuy.text = loc.amount..': '..nAmount_wBuy
  306.   txAmount_wBuy.width = utf8.len(txAmount_wBuy.text)
  307.   txAmount_wBuy.posX = hW-utf_find(txAmount_wBuy.text, ':')
  308.   wBuy:draw()
  309. end
  310. local num0 = wBuy:addButton(hW-1, 15, 3, 1, '0', function()nUpdate(0)end)
  311. local num1 = wBuy:addButton(hW-6, 9, 3, 1, '1', function()nUpdate(1)end)
  312. local num2 = wBuy:addButton(hW-1, 9, 3, 1, '2', function()nUpdate(2)end)
  313. local num3 = wBuy:addButton(hW+4, 9, 3, 1, '3', function()nUpdate(3)end)
  314. local num4 = wBuy:addButton(hW-6, 11, 3, 1, '4', function()nUpdate(4)end)
  315. local num5 = wBuy:addButton(hW-1, 11, 3, 1, '5', function()nUpdate(5)end)
  316. local num6 = wBuy:addButton(hW+4, 11, 3, 1, '6', function()nUpdate(6)end)
  317. local num7 = wBuy:addButton(hW-6, 13, 3, 1, '7', function()nUpdate(7)end)
  318. local num8 = wBuy:addButton(hW-1, 13, 3, 1, '8', function()nUpdate(8)end)
  319. local num9 = wBuy:addButton(hW+4, 13, 3, 1, '9', function()nUpdate(9)end)
  320. local numB = wBuy:addButton(hW-6, 15, 3, 1, '<', function() -- backspace
  321.   if nAmount_wBuy == 0 then
  322.     wBuy.close()
  323.   elseif #tostring(nAmount_wBuy) == 1 and nAmount_wBuy ~= 0 then
  324.     nAmount_wBuy = 0
  325.   elseif #tostring(nAmount_wBuy) > 1 then
  326.     nAmount_wBuy = (nAmount_wBuy-(nAmount_wBuy%10))/10
  327.   end
  328.   txTotalSum_wBuy.text = loc.total..': '..nAmount_wBuy*tmpData.price_selected
  329.   txTotalSum_wBuy.width = utf8.len(txTotalSum_wBuy.text)
  330.   txTotalSum_wBuy.posX = hW-utf_find(txTotalSum_wBuy.text, ':')
  331.   txAmount_wBuy.text = loc.amount..': '..tostring(nAmount_wBuy)
  332.   txAmount_wBuy.width = utf8.len(txAmount_wBuy.text)
  333.   txAmount_wBuy.posX = hW-utf_find(txAmount_wBuy.text, ':')
  334.   wBuy:draw()
  335. end)
  336. local numOk = wBuy:addButton(hW+4, 15, 3, 1, 'ok', function()
  337.   if nAmount_wBuy > 0 then
  338.     buy(tmpData.selected, nAmount_wBuy)
  339.     nAmount_wBuy = 0
  340.     wBuyList:hide()
  341.     wBuyList.close()
  342.     wBuy:hide()
  343.     wBuy.close()
  344.   end
  345. end)
  346. -----------------------------------
  347.  
  348. -- Buy List -- NEXT BTN -----------
  349. local bNext_wBuyList = wBuyList:addButton('right', H-2, 13, 1, loc.next, function()
  350.   tmpData.selected = tmpData.uiStorage[0][lItems_wBuyList:getSelected()]
  351.   if tmpData.selected then
  352.     tmpData.price_selected = db.items[tmpData.selected].cost
  353.     tmpData.amount_selected = db.items[tmpData.selected].i-db.items[tmpData.selected].o
  354.     txBalance_wBuy.text = tmpData.BALANCE_TEXT
  355.     txBalance_wBuy.width = tmpData.BTXT_LEN
  356.     txBalance_wBuy.posX = hW-utf_find(tmpData.BALANCE_TEXT, ':')
  357.     txInStock_wBuy.text = loc.inStock..tmpData.amount_selected
  358.     txInStock_wBuy.width = utf8.len(txInStock_wBuy.text)
  359.     txInStock_wBuy.posX = hW-utf_find(txInStock_wBuy.text, ':')
  360.     txItemName_wBuy.text = loc.label..': '..db.items[tmpData.selected].label
  361.     txItemName_wBuy.width = utf8.len(txItemName_wBuy.text)
  362.     txItemName_wBuy.posX = hW-utf_find(txItemName_wBuy.text, ':')
  363.     txItemPrice_wBuy.text = loc.price..': '..tmpData.price_selected
  364.     txItemPrice_wBuy.width = utf8.len(txItemPrice_wBuy.text)
  365.     txItemPrice_wBuy.posX = hW-utf_find(txItemPrice_wBuy.text, ':')
  366.     txTotalSum_wBuy.text = loc.total..': 0'
  367.     txTotalSum_wBuy.width = utf8.len(txTotalSum_wBuy.text)
  368.     txTotalSum_wBuy.posX = hW-utf_find(txTotalSum_wBuy.text, ':')
  369.     txAmount_wBuy.text = loc.amount..': 0'
  370.     txAmount_wBuy.width = utf8.len(txAmount_wBuy.text)
  371.     txAmount_wBuy.posX = hW-utf_find(txAmount_wBuy.text, ':')
  372.     wBuy:run()
  373.   end
  374. end)
  375. -----------------------------------
  376.  
  377. -- Sell ---------------------------
  378. local txToSell = wSell:addLabel('center', H/3, utf8.len(loc.sell_items), loc.sell_items)
  379. local txAmount_wSell = wSell:addLabel('center', H/3+1, 1, '')
  380. local txProfit_wSell = wSell:addLabel('center', H/3+2, 1, '')
  381. local bCancel_wSell = wSell:addButton('left', H-2, 20, 3, loc.cancel, function()
  382.   logout()
  383.   wSell.close()
  384. end)
  385. local bNext_wSell = wSell:addButton('right', H-2, 20, 3, loc.apply, function()
  386.   if tmpData.selected then
  387.     sell()
  388.     wSell.close()
  389.   end
  390. end)
  391. -----------------------------------
  392.  
  393. -- Sell List ----------------------
  394. local txBalance_wSellList = wSellList:addLabel('center', 1, 1, '')
  395. local txTooltip_wSellList = wSellList:addLabel(2, 2, 1, '')
  396. local lItems_wSellList = wSellList:addListBox('center', 3, W-4, H-6, {})
  397. local bCancel_wSellList = wSellList:addButton('left', H-2, 13, 1, loc.cancel, function()
  398.   logout()
  399.   wSellList:hide()
  400.   wSellList.close()
  401. end)
  402. local function sell_prepare(all)
  403.   if #lItems_wSellList.list > 0 then
  404.     local amount, item = 0
  405.     tmpData.price_selected = 0
  406.     if all then
  407.       tmpData.selected = tmpData.BUFFER
  408.       for i = 1, #lItems_wSellList.list do
  409.         item = tmpData.uiBuffer[0][lItems_wSellList.list[i]]
  410.         tmpData.price_selected = tmpData.price_selected + (db.items[item].cost*tmpData.BUFFER[item])
  411.         amount = amount + tmpData.BUFFER[item]
  412.       end
  413.     else
  414.       tmpData.selected = tmpData.uiBuffer[0][lItems_wSellList:getSelected()]
  415.       if tmpData.selected then
  416.         amount = tmpData.BUFFER[tmpData.selected]
  417.         tmpData.price_selected = db.items[tmpData.selected].cost*amount
  418.         tmpData.selected = {[tmpData.selected] = amount}
  419.       end
  420.     end
  421.     tmpData.fee = math.ceil(tmpData.price_selected*cfg.fee)
  422.     tmpData.price_selected = tmpData.price_selected-tmpData.fee
  423.     txAmount_wSell.text = loc.amount..': '..amount
  424.     txAmount_wSell.width = utf8.len(txAmount_wSell.text)
  425.     txAmount_wSell.posX = hW-(txAmount_wSell.width/2)
  426.     txProfit_wSell.text = loc.sell_profit:gsub('_', tmpData.price_selected):gsub('~', cfg.fee*100)
  427.     txProfit_wSell.width = utf8.len(txProfit_wSell.text)
  428.     txProfit_wSell.posX = hW-(txProfit_wSell.width/2)
  429.     wSell:run()
  430.     wSellList.close()
  431.   end
  432. end
  433. local bNext1_wSellList = wSellList:addButton('center', H-2, 13, 1, loc.sell_all, function()
  434.   sell_prepare(true)
  435. end)
  436. local bNext2_wSellList = wSellList:addButton('right', H-2, 13, 1, loc.sell, function()
  437.   sell_prepare()
  438. end)
  439. -----------------------------------
  440.  
  441. -- Sell Load ----------------------
  442. local txSellInfo = wSellLoad:addLabel('center', H/3, utf8.len(loc.drop), loc.drop)
  443. local bCancel_wSellLoad = wSellLoad:addButton('left', H-2, 20, 3, loc.cancel, function()
  444.   logout()
  445.   wSellLoad.close()
  446. end)
  447. local bNext_wSellLoad = wSellLoad:addButton('right', H-2, 20, 3, loc.next, function()
  448.   modem.broadcast(cfg.port, 'stop')
  449.   bufferScan()
  450.   lItems_wSellList:updateList(tmpData.uiBuffer)
  451.   wSellList:run()
  452.   wSellLoad.close()
  453. end)
  454. -----------------------------------
  455.  
  456. -- Info ---------------------------
  457. local txBalance_wInfo = wInfo:addLabel(1, H/2-3, 1, '')
  458. local txOperations_wInfo = wInfo:addLabel(1, H/2-1, 1, '')
  459. local txReset_wInfo = wInfo:addLabel(1, H/2, 1, '')
  460. local bExit_wInfo = wInfo:addButton('center', 10+(H-15)/2, 20+W%2, 3, loc.exit, function()
  461.   logout()
  462.   wInfo:hide()
  463.   wInfo.close()
  464. end)
  465. -----------------------------------
  466.  
  467. -- Main ---------------------------
  468. --local bExit_wMain = wMain:addButton('left', H-1, 4, 1, loc.exit, wMain.close)
  469. local bToBuy_wMain = wMain:addButton('center', 2+(H-15)/2, 20+W%2, 3, loc.buy, function()
  470.   if db.users[tmpData.CURRENT_USER].count < cfg.logins then
  471.     computer.beep(1000, 0.05)
  472.     txBalance_wBuyList.text = tmpData.BALANCE_TEXT
  473.     txBalance_wBuyList.width = tmpData.BTXT_LEN
  474.     txTooltip_wBuyList.text = tmpData.tooltip
  475.     txTooltip_wBuyList.width = tmpData.ttp_len
  476.     netScan()
  477.     lItems_wBuyList:updateList(tmpData.uiStorage)
  478.     wBuyList:run()
  479.   end
  480. end)
  481. local bToSell_wMain = wMain:addButton('center', 6+(H-15)/2, 20+W%2, 3, loc.sell, function()
  482.   if db.users[tmpData.CURRENT_USER].count < cfg.logins then
  483.     modem.broadcast(cfg.port, 'import')
  484.     computer.beep(800, 0.05)
  485.     txTooltip_wSellList.text = tmpData.tooltip
  486.     txTooltip_wSellList.width = tmpData.ttp_len
  487.     txBalance_wSellList.text = tmpData.BALANCE_TEXT
  488.     txBalance_wSellList.width = tmpData.BTXT_LEN
  489.     txBalance_wSellList.posX = hW-(tmpData.BTXT_LEN/2)
  490.     wSellLoad:run()
  491.   end
  492. end)
  493. local bInfo_wMain = wMain:addButton('center', 10+(H-15)/2, 20+W%2, 3, loc.info, function()
  494.   computer.beep(900, 0.05)
  495.   txBalance_wInfo.text = tmpData.BALANCE_TEXT
  496.   txBalance_wInfo.width = tmpData.BTXT_LEN
  497.   txBalance_wInfo.posX = hW-(tmpData.BTXT_LEN/2)
  498.   txOperations_wInfo.text = loc.operations..cfg.logins-db.users[tmpData.CURRENT_USER].count
  499.   txOperations_wInfo.width = utf8.len(txOperations_wInfo.text)
  500.   txOperations_wInfo.posX = hW-(txOperations_wInfo.width/2)
  501.   txReset_wInfo.text = loc.reset:gsub('_', 60-math.ceil((os.time()-db.users[tmpData.CURRENT_USER].lastlogin)/4320))
  502.   txReset_wInfo.width = utf8.len(txReset_wInfo.text)
  503.   txReset_wInfo.posX = hW-(txReset_wInfo.width/2)
  504.   wInfo:run()
  505. end)
  506. -----------------------------------
  507. wMain:addHandler('touch', function(...)
  508.   modem.broadcast(cfg.port, 'stop')
  509.   local e = {...}
  510.   tmpData.CURRENT_USER = e[6]
  511.   tmpData.lastlogin = computer.uptime()
  512.   computer.addUser(tmpData.CURRENT_USER)
  513.   modem.broadcast(cfg.port, 'start')
  514.   if not db.users[tmpData.CURRENT_USER] then
  515.     db.users[tmpData.CURRENT_USER] = {
  516.       balance = 0,
  517.       count = 0,
  518.       lastlogin = os.time()
  519.     }
  520.   end
  521.   if not db.users[cfg.operator] then
  522.     db.users[cfg.operator] = {
  523.       balance = 0,
  524.       count = 0,
  525.       lastlogin = os.time()
  526.     }
  527.   end
  528.   if os.time()-db.users[tmpData.CURRENT_USER].lastlogin > 259200 then
  529.     db.users[tmpData.CURRENT_USER].lastlogin = os.time()
  530.     db.users[tmpData.CURRENT_USER].count = 0
  531.   end
  532.   update_txBalance()
  533. end)
  534. wMain:addLabel('left', 1, 10, tmpData.CURRENT_USER)
  535. _G.m_timer = event.timer(60, function()
  536.   if tmpData.CURRENT_USER and computer.uptime()-tmpData.lastlogin >= 120 then
  537.     logout()
  538.     wMain:run()
  539.     wBuyList.close()
  540.     wBuy.close()
  541.     wSellLoad.close()
  542.     wSellList.close()
  543.     wSell.close()
  544.     wInfo.close()
  545.     wMain:draw()
  546.   end
  547. end, math.huge)
  548. -----------------------------------
  549. tmpData.tooltip = add_sp(add_sp(loc.label, W-26)..loc.amount, W-16)..' '..loc.price
  550. tmpData.ttp_len = utf8.len(tmpData.tooltip)
  551. modem.setStrength(10)
  552. load_db()
  553. wMain:run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement