[Plugin] Homes Plugin!? - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: [Plugin] Homes Plugin!? (/thread-1661.html) |
RE: [Plugin] Homes Plugin!? - nouseforname - 11-26-2014 (11-26-2014, 06:09 AM)xoft Wrote: Where is your DBExec function coming from? Are you using one of the sqlite wrappers from any of the plugins? I am not putting anything into the list cause it didnt work yet, Thats why i didnt post the "add" thingy into my post. Anyway, i think the "nrows" method is the right tip for me. The DBExec: function cStorage:DBExec(a_SQL, a_Callback, a_CallbackParam) local ErrCode = self.DB:exec(a_SQL, a_Callback, a_CallbackParam); if (ErrCode ~= sqlite3.OK) then LOGWARNING(PluginPrefix .. "Error " .. ErrCode .. " (" .. self.DB:errmsg() .. ") while processing SQL command >>" .. a_SQL .. "<<" ); return false; end return true; end Actually my main issue is how to insert a table into a table. so you get th nested table. This doesnt seem to work with "table.insert(myTable, insertTable)" RE: [Plugin] Homes Plugin!? - nouseforname - 11-27-2014 Finally i got what i wanted. The "nrows" was the correct one for me. The ingame command calls the handle function: function HandleHomeListCommand(a_split, player) a_List = g_Storage:GetList(player:GetName()) for i=1,#a_List do local msg = cChatColor.Green .. i .. ". " .. a_List[i].Name .. " @ " .. a_List[i].World player:SendMessage(msg) end return true end Inside handle function the GetList function is called, which will return a nested table with all player data: function cStorage:GetList( player ) local a_List = {} local sql = "SELECT * FROM " .. PluginName .. " WHERE Player='" .. player .. "'" for rowData in self.DB:nrows(sql) do a_List[#a_List+1] = rowData end return a_List end This is working well for me. Lets see what comes next RE: [Plugin] Homes Plugin!? - xoft - 11-27-2014 Try to use the "local" keyword as much as possible - variables in Lua are global by default, and you don't want your variables from one function overwritten with variables from another function. Also don't forget to use SQL placeholders, as this will decrease the possibility of an SQL injection attack. If you implemented the home-geting function as local sql = "SELECT * FROM Homes WHERE Name = " .. a_HomeNamewhat would happen if I called my home "a; DROP TABLE Homes"? There would be a quite astonished server admin RE: [Plugin] Homes Plugin!? - nouseforname - 11-27-2014 (11-27-2014, 02:56 AM)xoft Wrote: Try to use the "local" keyword as much as possible - variables in Lua are global by default, and you don't want your variables from one function overwritten with variables from another function.i know this and try it already as i don't like global vars. But thanks for the hint I know i forgot one "local" in the above sample. Quote:Also don't forget to use SQL placeholders, as this will decrease the possibility of an SQL injection attack.Yes you are right, but i think i do it bit different way, so nothing strange should happen. We will see. Anyway, when i am done i will post it and ask for some imrovement suggestions as i am new to lua. Even i know quite a few other programming/scripting languages i guess it could be improved Edit: Also its not possible to set the name with spaces inside, due to the args are splitted by whitespace even if you use quotation marks [Plugin] Homes RC1 - nouseforname - 11-27-2014 Here we go. Please test it and let me know if there is something wrong with it. Plugin Homes: -- * plugin homes.lua -- * provides functions to create, request and list and delete player homes with names and configurable limit -- * permission "homes.home" -- * Usage /home [[name]|set|list|delete|help] [name] -- * /home => port you to your default home -- * /home myHome => port you to home 'myHome' -- * /home set => set the actual position as default home -- * /home set myHome => set the actual position as 'myHome' -- * /home list => list all your home by name and world -- * /home delete myHome => delete 'myHome" -- * /home help => shows this help -- * Configurable limit of homes for each rank. 0=infinite -- * Homes.ini: -- * [Limits] -- * Default=3 -- * VIP=5 -- * Operator=10 -- * Admin=0 -- * created by nouseforname @ http://nouseforname.de -- * november 2014 Download: https://github.com/nouseforname/Homes RE: [Plugin] Homes Plugin!? - xoft - 11-27-2014 How about setting up a GitHub repo for the plugin, so that you get a platform for getting improvements? RE: [Plugin] Homes Plugin!? - xoft - 11-27-2014 Also, an explicitly declared license would be nice. RE: [Plugin] Homes Plugin!? - nouseforname - 11-27-2014 (11-27-2014, 06:27 AM)xoft Wrote: How about setting up a GitHub repo for the plugin, so that you get a platform for getting improvements?Maybe after release, actually i am just curious about creating this. I dont think i will follow up with other plugins. (11-27-2014, 06:44 AM)xoft Wrote: Also, an explicitly declared license would be nice.Which license is usually used for these plugins? Its open source anyway. btw: why dont you just edit your former post Edit: License Added GitHub created https://github.com/nouseforname/Homes RE: [Plugin] Homes Plugin!? - bearbin - 11-27-2014 The MIT or Apache licenses are good for plugins. And software isn't open source unless it has an OS license on it. Anyway, thanks for uploading it. RE: [Plugin] Homes Plugin!? - nouseforname - 11-27-2014 (11-27-2014, 05:44 PM)bearbin Wrote: The MIT or Apache licenses are good for plugins. And software isn't open source unless it has an OS license on it.Well, i used Apache license now. What i meant with open source is, everybody can see and change it. Quote:Anyway, thanks for uploading it.Hope its useful for somebody |