SHOW:
|
|
- or go back to the newest paste.
| 1 | local key="lipAPI.public_key" | |
| 2 | -- http://pastebin.com/VStLRx0P | |
| 3 | ||
| 4 | -- Server Patched Version of LIP | |
| 5 | -- reduce results of WorldInterface.getBlockInfos() and EntityDetector.getEntityList() | |
| 6 | -- add methods WorldInterface.getBlockDatatags() and EntityDetector.getEntityListAdvanced() | |
| 7 | - | error("Timeout should be a positive number",2)
|
| 7 | + | local modLIP_ServerPatchedVersion = true |
| 8 | ||
| 9 | local timeout = 5 | |
| 10 | - | timeout = math.max(.1,tonumber(n)) |
| 10 | + | |
| 11 | local id = os.getComputerID() | |
| 12 | ||
| 13 | - | local modem = peripheral.find("modem", function(name, object) return object.isWireless() end)
|
| 13 | + | --Set global to local |
| 14 | local _max = math.max | |
| 15 | - | error("Not found: wireless modem",2)
|
| 15 | + | local _format = string.format |
| 16 | local _find = peripheral.find | |
| 17 | local _startTimer,_cancelTimer = os.startTimer,os.cancelTimer | |
| 18 | local _pullEvent = os.pullEvent | |
| 19 | ||
| 20 | function setTimeout(n) | |
| 21 | - | local _timeout = os.startTimer(timeout) |
| 21 | + | |
| 22 | error("LIP:Timeout should be a positive number",2)
| |
| 23 | exit() | |
| 24 | - | local e, p, to, from, result, dist = os.pullEvent() |
| 24 | + | |
| 25 | timeout = _max(.1,tonumber(n)) | |
| 26 | end | |
| 27 | local function request(_p) | |
| 28 | local modem = _find("modem", function(name, object) return object.isWireless() end)
| |
| 29 | if not modem then | |
| 30 | - | error(result[2],2) |
| 30 | + | error("LIP:Not found: wireless modem",2)
|
| 31 | exit() | |
| 32 | end | |
| 33 | - | elseif e=="timer" and p==_timeout then |
| 33 | + | |
| 34 | - | error("408 Request Timeout",2)
|
| 34 | + | |
| 35 | if not keepOpen then modem.open(id) end | |
| 36 | local _timeout = _startTimer(timeout) | |
| 37 | modem.transmit(channel,id,data) | |
| 38 | while true do | |
| 39 | local e, p, to, from, result, dist = _pullEvent() | |
| 40 | if e=="modem_message" and to==id and from==channel then | |
| 41 | _cancelTimer(_timeout) | |
| 42 | if not keepOpen then modem.close(id) end | |
| 43 | if result[1] then | |
| 44 | - | getBlockDatatags = function(x,y,z) return request({"WorldInterface","getBlockDatatags",x,y,z}) end,
|
| 44 | + | |
| 45 | else | |
| 46 | error("LIP_Server:"..result[2],2)
| |
| 47 | - | getMethods = function(str) if str then return request({"WorldInterface","getMethods",str}) else return request({"WorldInterface","getMethods"}) end end,
|
| 47 | + | |
| 48 | end | |
| 49 | elseif e=="timer" then | |
| 50 | error("LIP_Server:code_408 Request Timeout",2)
| |
| 51 | - | getEntityListAdvanced = function(r,x,y,z) return request({"EntityDetector","getEntityListAdvanced",r,x,y,z}) end,
|
| 51 | + | |
| 52 | end | |
| 53 | - | getMethods = function(str) if str then return request({"EntityDetector","getMethods",str}) else return request({"EntityDetector","getMethods"}) end end,
|
| 53 | + | |
| 54 | - | } |
| 54 | + | |
| 55 | ||
| 56 | WorldInterface = {
| |
| 57 | getBiome = function(x,y,z) return request({"WorldInterface","getBiome",x,y,z}) end,
| |
| 58 | getWeather = function() return request({"WorldInterface","getWeather"}) end,
| |
| 59 | getBlockInfos = function(x,y,z) return request({"WorldInterface","getBlockInfos",x,y,z}) end,
| |
| 60 | getRealDate = function() return request({"WorldInterface","getRealDate"}) end,
| |
| 61 | getPlayerList = function() return request({"WorldInterface","getPlayerList"}) end,
| |
| 62 | getMethods = function(methodName) | |
| 63 | methodName = methodName or false | |
| 64 | if methodName=="getBiome" then | |
| 65 | b = true | |
| 66 | r = [[WorldInterface.getBiome(X,Y,Z) | |
| 67 | Return the biome type at coordinates in the world.]] | |
| 68 | elseif methodName=="getWeather" then | |
| 69 | b = true | |
| 70 | r = [[WorldInterface.getWeather() | |
| 71 | Return the weather in the world like "Rain", "Thunder", "Clear".]] | |
| 72 | elseif methodName=="getBlockInfos" then | |
| 73 | b = true | |
| 74 | r = _format([[WorldInterface.getBlockInfos(X,Y,Z) | |
| 75 | Return %s informations about the block at one coordinate like name, metadatas,%s etc...]], | |
| 76 | modLIP_ServerPatchedVersion and "main" or "every", | |
| 77 | modLIP_ServerPatchedVersion and "" or " datatags,") | |
| 78 | elseif modLIP_ServerPatchedVersion and methodName=="getBlockDatatags" then | |
| 79 | b = true | |
| 80 | r = [[WorldInterface.getBlockDatatags(X,Y,Z) | |
| 81 | Return every datatags about the block at one coordinate like name, metadatas, datatags, etc...]] | |
| 82 | elseif methodName=="getRealDate" then | |
| 83 | b = true | |
| 84 | r = [[WorldInterface.getRealDate() | |
| 85 | Return the date of the server like | |
| 86 | "Sun Sep 04 23:39:44 CEST 2016"]] | |
| 87 | elseif methodName=="getPlayerList" then | |
| 88 | b = true | |
| 89 | r = [[WorldInterface.getPlayerList() | |
| 90 | Return the list of the online players.]] | |
| 91 | elseif methodName=="getMethods" then | |
| 92 | b = true | |
| 93 | r = [[WorldInterface.getMethods() | |
| 94 | WorldInterface.getMethods(MethodName) | |
| 95 | Return list of every function of World Interface. | |
| 96 | Return information about specific method, if MethodName is specified.]] | |
| 97 | else | |
| 98 | b = true | |
| 99 | r = string.format([[WorldInterface.getBiome(X,Y,Z) | |
| 100 | WorldInterface.getWeather() | |
| 101 | WorldInterface.getBlockInfos(X,Y,Z)%s | |
| 102 | WorldInterface.getRealDate() | |
| 103 | WorldInterface.getPlayerList() | |
| 104 | WorldInterface.getMethods(MethodName)]], modLIP_ServerPatchedVersion and "\nWorldInterface.BlockDatatags(X,Y,Z)" or "") | |
| 105 | end | |
| 106 | end, | |
| 107 | } | |
| 108 | EntityDetector = {
| |
| 109 | getEntityList = function(r,x,y,z) return request({"EntityDetector","getEntityList",r,x,y,z}) end,
| |
| 110 | getPlayerDetail = function(name) return request({"EntityDetector","getPlayerDetail",name}) end,
| |
| 111 | getMethods = function(methodName) | |
| 112 | methodName = methodName or false | |
| 113 | if methodName=="getEntityList" then | |
| 114 | b = true | |
| 115 | r = _format([[EntityDetector.getEntityList(Range,X,Y,Z) | |
| 116 | Return %s informations about every entities like monsters and players in a radius, and coordinate define center of the radius.]], | |
| 117 | modLIP_ServerPatchedVersion and "main" or "every") | |
| 118 | elseif modLIP_ServerPatchedVersion and methodName=="getEntityListAdvanced" then | |
| 119 | b = true | |
| 120 | r = [[EntityDetector.getEntityListAdvanced(Range,X,Y,Z) | |
| 121 | Return every informations about every entities like monsters and players in a radius, and coordinate define center of the radius.]] | |
| 122 | elseif methodName=="getPlayerDetail" then | |
| 123 | b = true | |
| 124 | r = [[EntityDetector.getPlayerDetail(PlayerName) | |
| 125 | Return every informations about the player like health, armor etc.]] | |
| 126 | elseif methodName=="getMethods" then | |
| 127 | b = true | |
| 128 | r = [[EntityDetector.getMethods() | |
| 129 | EntityDetector.getMethods(MethodName) | |
| 130 | Return list of every function of Entity Detector. | |
| 131 | Return information about specific methode, if methodName is specified.]] | |
| 132 | else | |
| 133 | b = true | |
| 134 | r = _format([[EntityDetector.getEntityList(Range,X,Y,Z)%s | |
| 135 | EntityDetector.getPlayerDetail(PlayerName) | |
| 136 | EntityDetector.getMethods(MethodName)]], | |
| 137 | modLIP_ServerPatchedVersion and "\nEntityDetector.getEntityListAdvanced(Range,X,Y,Z)" or "") | |
| 138 | end | |
| 139 | end, | |
| 140 | } | |
| 141 | ||
| 142 | if modLIP_ServerPatchedVersion then | |
| 143 | WorldInterface.getBlockDatatags = function(x,y,z) | |
| 144 | return request({"WorldInterface","getBlockDatatags",x,y,z})
| |
| 145 | end | |
| 146 | EntityDetector.getEntityListAdvanced = function(r,x,y,z) | |
| 147 | return request({"EntityDetector","getEntityListAdvanced",r,x,y,z})
| |
| 148 | end | |
| 149 | end |