· 7 years ago · Jan 28, 2019, 07:48 PM
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE muclient>
3<!-- Saved on Monday, April 26, 2018, 7:21 AM -->
4<!-- MuClient version 4.51 -->
5
6<!-- Plugin "AlterAeonMapper" generated by Plugin Wizard -->
7
8<muclient>
9<plugin
10 name="AlterAeonMapper"
11 author="Nick Gammon and Master Vivi"
12 id="dd07d6dbe73fe0bd02ddb63d"
13 language="Lua"
14 purpose="Shows the mapper for Alter Aeon"
15 save_state="y"
16 date_written="2010-04-26 07:21:01"
17 requires="4.51"
18 version="1.0"
19 >
20
21</plugin>
22
23<aliases>
24
25 <!-- zooming aliases -->
26
27 <alias
28 match="mapper zoom out"
29 enabled="y"
30 sequence="100"
31 omit_from_command_history="y"
32 omit_from_output="y"
33 script="mapper.zoom_out"
34 >
35 </alias>
36
37<alias
38 match="mapper zoom in"
39 enabled="y"
40 sequence="100"
41 omit_from_command_history="y"
42 omit_from_output="y"
43 script="mapper.zoom_in"
44 >
45 </alias>
46<alias
47 match="mapper thisroom"
48 enabled="y"
49 sequence="100"
50 script="show_this_room"
51 regexp="n">
52</alias>
53
54 <!-- show/hide mapper -->
55
56 <alias
57 match="mapper hide"
58 enabled="y"
59 sequence="100"
60 script="mapper.hide"
61 >
62 </alias>
63
64 <alias
65 match="mapper show"
66 enabled="y"
67 sequence="100"
68 script="mapper.show"
69 >
70 </alias>
71<alias
72 match="^mapper help( (.*))?$"
73 enabled="y"
74 regexp="y"
75 script="OnHelp"
76></alias>
77
78<alias
79 match="^mapper updown$"
80 enabled="y"
81 regexp="y"
82 send_to="12"
83>
84<send>
85 mapper.show_up_down = not mapper.show_up_down
86 mapper.draw (current_room)
87</send>
88</alias>
89
90<alias
91 match="^mapper underlines?$"
92 enabled="y"
93 regexp="y"
94 send_to="12"
95>
96<send>
97 NoUnderline_hyperlinks = not NoUnderline_hyperlinks
98 Note("Mapper hyperlinks will " ..(NoUnderline_hyperlinks and "no longer" or "now").." be underlined.")
99 SetVariable("NoUnderline_hyperlinks", NoUnderline_hyperlinks and "1" or "0")
100</send>
101</alias>
102 <alias
103 match="mapper goto *"
104 enabled="y"
105 sequence="100"
106 script="map_goto"
107 >
108 </alias>
109<alias
110 match="mapper find *"
111 enabled="y"
112 sequence="100"
113 script="map_find"
114 regexp="n"
115></alias>
116<alias
117 match="mapper findpath * *"
118 enabled="y"
119 sequence="100"
120 omit_from_output="y"
121 script="findpathfast"
122></alias>
123
124 <alias
125 match="mapper where *"
126 enabled="y"
127 sequence="100"
128 script="map_where"
129 >
130 </alias>
131 <alias
132 match="mapper backup"
133 enabled="y"
134 sequence="100"
135 script="backup_db"
136 >
137 </alias>
138 <alias
139 match="^mapper delete room (\d+)$"
140 enabled="y"
141 regexp="y"
142 script="delete_room_alias"
143>
144</alias>
145<alias
146 match="^mapper delete area (.+)$"
147 enabled="y"
148 regexp="y"
149 script="delete_area_alias"
150>
151</alias>
152</aliases>
153
154
155<!-- Triggers -->
156
157<triggers>
158<trigger
159enabled="y"
160match="kxwt_rshort *"
161name="process_room_name"
162sequence="100"
163send_to="14"
164>
165<send>name="%1"</send>
166</trigger>
167<trigger
168enabled="y"
169match="kxwt_rvnum *"
170name="process_room_desc"
171sequence="100"
172send_to="14"
173>
174<send>uid="%1"</send>
175</trigger>
176<trigger
177enabled="y"
178match="kxwt_terrain *"
179name="process_terrain"
180sequence="100"
181send_to="14"
182>
183<send>terrain="%1"</send>
184</trigger>
185<trigger
186enabled="y"
187match="kxwt_area * *"
188name="process_area"
189sequence="100"
190send_to="14"
191>
192<send>area="%2"</send>
193</trigger>
194 <trigger
195 enabled="y"
196 match="[Exits: *]"
197 name="Exits_Line"
198 sequence="100"
199 send_to="14"
200 >
201<send>process_exits("%1")</send>
202 </trigger>
203
204
205</triggers>
206
207<!-- Timers -->
208
209<timers>
210 <timer
211 name="backup_timer"
212 enabled="y"
213 script="backup_db"
214 hour="23" minute="59" second="59"
215 active_closed="y" >
216 </timer>
217</timers>
218
219<!-- Script -->
220
221
222<script>
223<![CDATA[
224
225mapper = require "altermapper"
226require "serialize"
227require "copytable"
228uid = 0
229current_room=0
230current_area = 0
231expected_exit=-666
232from_room=0
233last_direction_moved=0
234terrain = 0
235area = 0
236last_backup = GetVariable("last_backup") or 0
237
238count = 0
239roomcount = 0
240rooms = {}
241
242valid_direction = {
243n = "n",
244s = "s",
245e = "e",
246w = "w",
247u = "u",
248d = "d",
249ne = "ne",
250sw = "sw",
251nw = "nw",
252no="n",
253ea="e",
254so="s",
255we="w",
256se = "se",
257north = "n",
258south = "s",
259east = "e",
260west = "w",
261up = "u",
262down = "d",
263northeast = "ne",
264northwest = "nw",
265southeast = "se",
266southwest = "sw",
267['in'] = "in",
268out = "out",
269} -- end of valid_direction
270
271terrain_color = {}
272
273-- -----------------------------------------------------------------
274-- Here on "Exits:" line ----- we have changed rooms
275-- -----------------------------------------------------------------
276
277function process_exits (exits_str)
278
279 -- genereate a "room ID" by hashing the room name, description and exits
280
281 -- break up exits into individual directions
282 exits = {}
283
284 for exit in string.gmatch (exits_str, "%w+") do
285 local ex = valid_direction [exit]
286 if ex then
287 exits [ex] = "-666" -- don't know where it goes yet
288 end -- if
289 end -- for
290
291 -- add to table if not known
292 if not rooms [uid] then
293 rooms [uid] = { name = name, desc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
294 add_update_room(uid, rooms[uid])
295 end -- if
296
297 -- save so we know current room later on
298 current_room = uid
299
300
301
302 -- call mapper to draw this rom
303 mapper.draw (uid)
304
305 -- try to work out where previous room's exit led
306 if expected_exit == "-666" and from_room then
307 fix_up_exit ()
308 end -- exit was wrong
309
310end -- process_exits
311
312-- -----------------------------------------------------------------
313-- Here on white coloured line - this is a room name or room exits
314-- -----------------------------------------------------------------
315
316function Name_Or_Exits (name, line, wildcards)
317
318 exits = string.match (line, "^Exits: (.*)")
319
320 if exits then
321 process_exits (exits)
322 end -- if
323
324 roomname = line
325 roomdesc = nil
326
327end -- Name_Or_Exits
328
329-- -----------------------------------------------------------------
330-- Here on yellow line - part of room description
331-- -----------------------------------------------------------------
332
333function Name_Line (name, line, wildcards)
334 roomdesc = (roomdesc or "" ) .. line .. "\n"
335end -- Name_Or_Exits
336-- -----------------------------------------------------------------
337-- for converting things like ^ $ * etc. into "escaped" sequences
338-- -----------------------------------------------------------------
339function fix_regexp_magic_characters (r)
340 return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
341end -- fix_regexp_magic_characters
342
343-- -----------------------------------------------------------------
344-- mapper 'get_room' callback - it wants to know about room uid
345-- -----------------------------------------------------------------
346
347function get_room (uid)
348
349 if not rooms [uid] then
350 return nil
351 end -- if
352
353 local room = copytable.deep (rooms [uid])
354
355 local texits = {}
356 for dir in pairs (room.exits) do
357 table.insert (texits, dir)
358 end -- for
359 table.sort (texits)
360
361 room.hovermessage = string.format (
362 "%s\tExits: %s\nRoom: %s\nArea: %s",
363 room.name,
364 table.concat (texits, ", "),
365 uid,
366 area,
367 terrain,
368 notes
369 -- depth,
370 -- table.concat (path, ",")
371 )
372
373 if uid == current_room then
374 room.bordercolour = ColourNameToRGB "red"
375 room.borderpenwidth = 2
376 end -- not in this area
377
378 return room
379
380end -- get_room
381
382-- -----------------------------------------------------------------
383-- We have changed rooms - work out where the previous room led to
384-- -----------------------------------------------------------------
385
386function fix_up_exit ()
387
388 -- where we were before
389 local room = rooms [from_room]
390
391 -- leads to here
392 room.exits [last_direction_moved] = current_room
393
394 -- clear for next time
395 last_direction_moved = nil
396 from_room = nil
397
398end -- fix_up_exit
399
400-- -----------------------------------------------------------------
401-- try to detect when we send a movement command
402-- -----------------------------------------------------------------
403
404function OnPluginSent (sText)
405 if valid_direction [sText] then
406 last_direction_moved = valid_direction [sText]
407 -- Note("Just moved", last_direction_moved)
408 if current_room and rooms [current_room] then
409 expected_exit = rooms [current_room].exits [last_direction_moved]
410 if expected_exit then
411 from_room = current_room
412 end -- if
413 -- Note("expected exit for this direction is to room", expected_exit)
414 end -- if
415 end -- if
416end -- function
417
418
419function show_this_room (name, line, wildcards)
420 local room = rooms[current_room]
421 if room ~= nil then
422 Note("Details about this room:")
423 Note("+---------------------------+")
424 Note("Name: "..(name or ""))
425 Note("ID: "..(uid or ""))
426 Note("Area: "..(area or ""))
427 Note("Terrain: "..(terrain or ""))
428 Note("Info: "..(room.info or ""))
429 Note("Notes: "..(room.notes or ""))
430 Note("Exits: "..(room.exits or ""))
431else
432 Note("THISROOM ERROR: You need to type 'LOOK' first to initialize the mapper before trying to get room information.")
433 end
434end -- show_this_room
435
436-- -----------------------------------------------------------------
437-- map_find: mapper find xxx
438-- -----------------------------------------------------------------
439function map_find (name, line, wildcards)
440
441 mapper.mapprint (string.rep ("-", 25) .. " Mapper search " .. string.rep ("-", 25))
442
443 local reset = ANSI (0)
444 local bold = ANSI (1)
445 local unbold = ANSI (22)
446
447 local matches = { }
448 local count = 0
449 local target = Trim (wildcards [1]:lower ())
450
451 if target == "" then
452 mapper.maperror ("No search string specified")
453 return
454 end -- if
455
456 if not mapper.check_we_can_find () then
457 return
458 end -- if find not OK
459
460 -- fix up any regular expression "magic" letters to be escaped by a %
461 local fixed_target = fix_regexp_magic_characters (target)
462
463 -- fix up for caseless searches in the room description (eg. "a" becomes "[aA]")
464 local caseless_target = string.gsub (fixed_target, "(%a)", function (a)
465 return "[" .. a:lower () .. a:upper () .. "]"
466 end -- function
467 )
468
469 -- do a simple string search to find matching rooms
470 for k, v in pairs (rooms) do
471
472 -- don't want nil descriptions
473 if not v.description then
474 v.description = ""
475 end -- if no description
476
477 if string.find (v.name:lower (), fixed_target) or
478 string.find (v.description:lower (), fixed_target) then
479 matches [k] = true
480 count = count + 1
481 end -- if match
482 end -- for each room
483
484 local function show_snippet (uid)
485 local room = rooms [uid]
486 if not room then
487 return
488 end -- if
489
490 -- don't bother if the wanted words was in the room name
491 if string.find (room.name:lower (), fixed_target) then
492 return
493 end -- if
494
495 -- otherwise show the wanted word in the description, in bold
496 AnsiNote (reset .. string.gsub (room.description, caseless_target, bold .. "%1" .. unbold))
497
498 end -- show_snippet
499
500 -- see if nearby
501 mapper.find (
502 function (uid)
503 local room = matches [uid]
504 if room then
505 matches [uid] = nil
506 end -- if
507 return room, next (matches) == nil
508 end, -- function
509 show_vnums, -- show vnum?
510 count, -- how many to expect
511 false, -- don't auto-walk
512 show_snippet -- show find snippet
513 )
514end -- map_find
515
516
517-- -----------------------------------------------------------------
518-- map_goto for: mapper goto xxx
519-- -----------------------------------------------------------------
520function map_goto (name, line, wildcards)
521 local wanted = wildcards [1]
522 -- check valid string
523 if string.match (wanted, "%D") then
524 mapper.maperror ("Room number must be numeric, you entered: " .. wanted)
525 return
526 end -- if
527
528 -- see if already there
529 if current_room and string.match (current_room, "^" .. wanted) then
530 mapper.mapprint ("You are already in that room.")
531 return
532 end -- if
533 -- find desired room
534 mapper.find (
535 function (uid)
536 local found = string.match (uid, "^" .. wanted)
537 return found, found
538 end, -- function
539 show_vnums, -- show vnum?
540 1, -- how many to expect
541 true -- just walk there
542 )
543end -- map_goto
544
545-- -----------------------------------------------------------------
546-- map_where: Show where a room is
547-- -----------------------------------------------------------------
548function map_where (name, line, wildcards)
549 if not mapper.check_we_can_find () then
550 return
551 end -- if
552 local wanted = wildcards [1]
553 if current_room and wanted == current_room then
554 mapper.mapprint ("You are already in that room.")
555 return
556 end -- if
557 local paths = mapper.find_paths (current_room,
558 function (uid)
559 return uid == wanted, -- wanted room?
560 uid == wanted -- stop searching?
561 end)
562 local uid, item = next (paths, nil) -- extract first (only) path
563 -- nothing? room not found
564 if not item then
565 mapper.mapprint (string.format ("Room %s not found", wanted))
566 return
567 end -- if
568 -- turn into speedwalk
569 local path = mapper.build_speedwalk (item.path)
570 -- display it
571 mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
572end -- map_where
573
574-- -----------------------------------------------------------------
575-- cannot_walk - we tried to walk but failed
576-- -----------------------------------------------------------------
577function cannot_walk (name, line, wildcards)
578 mapper.cancel_speedwalk ()
579 room_description = nil
580 current_exits = nil
581 room_name = nil
582 last_direction_moved = nil
583-- mapper.mapprint ("Attempt to walk cancelled.")
584
585end -- cannot_walk
586
587-- -----------------------------------------------------------------
588-- check_for_cannot_go - look up the line in a table of failure messages
589-- see table: cannot_move_messages
590-- -----------------------------------------------------------------
591function check_for_cannot_go (name, line, wildcards)
592
593 for _, v in ipairs (cannot_move_messages) do
594 if string.find (line, v) then
595 cannot_walk ()
596 break
597 end -- if match
598 end -- for each message
599end -- check_for_cannot_go
600
601function findpathfast(name, line, wildcards)
602 local src = wildcards[1]
603 local dest = wildcards[2]
604 rooms[src] = load_room_from_database(src)
605 rooms[dest] = load_room_from_database(dest)
606
607 if rooms[src] == nil then
608 mapper.mapprint (string.format ("Room %s not known.", src))
609 end
610 if rooms[dest] == nil then
611 mapper.mapprint (string.format ("Room %s not known.", dest))
612 end
613 if rooms[src] == nil or rooms[dest] == nil then
614 return
615 end
616
617 local foundpath = findpath(src, dest)
618 if foundpath == nil then
619 mapper.mapprint (string.format ("Path from %s to %s not found.", wildcards[1], wildcards[2]))
620 return
621 end
622
623 -- turn into speedwalk
624 local speedwalk = mapper.build_speedwalk (foundpath, speedwalk_prefix)
625
626 -- display it
627 if speedwalk ~= nil then
628 mapper.mapprint (string.format ("Path from %s to %s is: %s", wildcards[1], wildcards[2], speedwalk))
629 else
630 mapper.mapprint ("Pick different start and end rooms.")
631 end
632end
633
634function blackindigoPrint(msg)
635 ColourNote("blueviolet","black",msg)
636end
637function blackredPrint(msg)
638 ColourNote("black","red",msg)
639end
640function whiteindigoPrint(msg)
641 ColourNote("white","indigo",msg)
642end
643
644
645function setup_terrain_colors()
646terrain_color["0"]=tonumber("0x000000")--NOTSET
647terrain_color["1"]=tonumber("0x606060")--Building
648terrain_color["2"]=tonumber("0x805a22")--Town
649terrain_color["3"]=tonumber("0x00ff00")--FIELD
650terrain_color["4"]=tonumber("0x00c000")--LFOREST
651terrain_color["5"]=tonumber("0x008000")--TFOREST
652terrain_color["6"]=tonumber("0x004000")--DFOREST
653terrain_color["7"]=tonumber("0x406080")--SWAMP
654terrain_color["8"]=tonumber("0x60a060")--PLATEAU
655terrain_color["9"]=tonumber("0x00ffff")--SANDY
656terrain_color["10"]=tonumber("0xc0c0c0")--MOUNTAIN
657terrain_color["11"]=tonumber("0x808080")--ROCK
658terrain_color["12"]=tonumber("0x00ffff")--DESERT
659terrain_color["13"]=tonumber("0x805080")--TUNDRA
660terrain_color["14"]=ColourNameToRGB("lightyellow")--BEACH
661terrain_color["15"]=tonumber("0x409040")--HILL
662terrain_color["16"]=tonumber("0xf0f080")--DUNES
663terrain_color["17"]=tonumber("0x20c040")--JUNGLE
664terrain_color["18"]=ColourNameToRGB("darkblue")--OCEAN
665terrain_color["19"]=tonumber("0x00f0f0")--STREAM
666terrain_color["20"]=ColourNameToRGB("blue")--RIVER
667terrain_color["21"]=tonumber("0x021e6c")--UNDERWATER
668terrain_color["22"]=tonumber("0x303030")--UNDERGROUND
669terrain_color["23"]=tonumber("0x000000")--AIR
670terrain_color["24"]=tonumber("0x82f8e6")--ICE
671terrain_color["25"]=ColourNameToRGB("red")--LAVA
672terrain_color["26"]=tonumber("0x806060")--RUINS
673terrain_color["27"]=tonumber("0x404040")--CAVE
674terrain_color["28"]=tonumber("0x907040")--CITY
675terrain_color["29"]=tonumber("0x20a060")--MARSH
676terrain_color["30"]=tonumber("0xf0f0a0")--WASTELAND
677terrain_color["31"]=tonumber("0xffffff")--CLOUD
678terrain_color["32"]=ColourNameToRGB("blue")--WATER
679terrain_color["33"]=tonumber("0x808080")--METAL
680terrain_color["34"]=tonumber("0x006000")--TAIGA
681terrain_color["35"]=tonumber("0x404040")--SEWER
682terrain_color["36"]=ColourNameToRGB("indigo")--SHADOW
683 -- end of terrain_color
684end
685
686-- -----------------------------------------------------------------
687-- Plugin Install
688-- -----------------------------------------------------------------
689
690function OnPluginInstall ()
691
692 config = {} -- in case not found
693 setup_terrain_colors()
694
695 -- get saved configuration
696 assert (loadstring (GetVariable ("config") or "")) ()
697
698 -- and rooms
699 --assert (loadstring (GetVariable ("rooms") or "")) ()
700
701 -- new stuff for sql data
702 check_create_db()
703 load_rooms()
704
705 -- initialize mapper
706
707 mapper.init { config = config,
708 get_room = get_room, findpath = findpath,
709 show_help = OnHelp, -- to show help
710}
711 mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
712
713end -- OnPluginInstall
714
715function OnHelp (name, line, wildcards)
716 local help_header = " [Demon Mush Mapper Help] "
717
718 local help_index = [[
719 Mapper Help Index
720=============================================================================
721 mapper help --> Show this list
722-----------------------------------------------------------------------------
723 mapper help config --> Commands for configuring the mapper
724 mapper help exploring --> Commands to aid exploring
725 mapper help moving --> Commands for moving between rooms
726 mapper help utils --> Other utilitarian commands
727 mapper help search <txt> --> Searches through help lines looking for a
728 particular word or phrase.
729=============================================================================
730]]
731 local help_table = {
732 ['config'] = {
733['header'] = [[===== CONFIGURATION =============>]],
734[[mapper help --> This help
735 > (or click the "?" button on the top right)]],
736[[mapper zoom out --> Zoom out]],
737[[mapper zoom in --> Zoom in]],
738[[mapper hide --> Hide map]],
739[[mapper show --> Show map]],
740[[mapper updown --> Toggle up/down exit drawing]],
741[[mapper underlines --> Toggle underlining of clickable links]]
742},
743
744 ['utils'] = {
745['header'] = [[===== UTILITIES =================>]],
746
747[[mapper addnote --> Add a new note to the current room]],
748[[mapper addnote <note> --> Ditto, but skips the dialog]],
749},
750 ['searching'] = {
751['header'] = [[===== SEARCHING =================>]],
752[[mapper area <text> --> Full-text search limited to the current zone]],
753[[mapper find <text> --> Full-text search the whole database]],
754[[]],
755[[mapper notes --> Show nearby rooms that you marked with notes]],
756[[mapper notes <here/area> --> Ditto]],
757[[mapper shops --> Show all shops/banks]],
758[[mapper shops <here/area> --> Ditto]],
759[[mapper train --> Show all trainers]],
760[[mapper train <here/area> --> Ditto]],
761[[mapper quest --> Show all quest-givers]],
762[[mapper quest <here/area> --> Ditto]],
763[[]],
764[[mapper next --> Visit the next room in the most recent
765 > list of results.]],
766[[mapper next <index> --> Ditto, but skip to the given result index.]],
767[[mapper where <room id> --> Show directions to a room number]]
768},
769
770 ['exploring'] = {
771['header'] = [[===== EXPLORING =================>]],
772[[mapper thisroom --> Show details about the current room]],
773[[mapper showroom <room id> --> Draw the map as if you were standing in
774 > a different room]],
775[[mapper areas --> Show a list of all mapped areas]],
776[[mapper areas <name> --> Show a list of mapped areas partially
777 > matching <name>]],
778[[mapper unmapped --> List unmapped exit counts for known areas]],
779[[mapper unmapped <here/area> --> List unmapped exits in this or another area]]
780},
781
782 ['moving'] = {
783['header'] = [[===== MOVING ====================>]],
784[[mapper goto <room id> --> Run to a room by its room number]]
785}
786}
787
788 local function show_help(helps)
789 blackindigoPrint("")
790 blackindigoPrint(helps['header'])
791 blackindigoPrint("")
792 for i,v in ipairs(helps) do
793 blackindigoPrint(v)
794 end
795 end
796
797 blackindigoPrint("")
798 whiteindigoPrint(help_header)
799 blackindigoPrint("+---------------------------------------------------------------------------+")
800 badnews = true
801 if wildcards and wildcards[2] ~= "" then
802 badnews = false
803 if wildcards[2] == "all" then
804 show_help(help_table['config'])
805 show_help(help_table['exits'])
806 show_help(help_table['searching'])
807 show_help(help_table['exploring'])
808 show_help(help_table['moving'])
809 show_help(help_table['utils'])
810 elseif wildcards[2] == "config" then
811 show_help(help_table['config'])
812 elseif wildcards[2] == "searching" then
813 show_help(help_table['searching'])
814 elseif wildcards[2] == "exploring" then
815 show_help(help_table['exploring'])
816 elseif wildcards[2] == "moving" then
817 show_help(help_table['moving'])
818 elseif wildcards[2] == "utils" then
819 show_help(help_table['utils'])
820 elseif wildcards[2]:find("search ") == 1 then
821 local st, en = wildcards[2]:find("search ")
822 local pattern = Trim(wildcards[2]:sub(en+1))
823 ColourTell("cornflower","black","Searching help for: ")
824 ColourNote("red","black",pattern)
825 if pattern ~= "" then
826 for k,v in pairs(help_table) do
827 local done_header = false
828 for j,w in ipairs(v) do
829 if (w ~= "") and (w:find("--------",nil,true) == nil) and (w:find(pattern) ~= nil) then
830 if not done_header then
831 blackindigoPrint("")
832 blackindigoPrint(v['header'])
833 done_header = true
834 end
835 blackindigoPrint("")
836 local wtable = w:split(pattern)
837 for i,v in ipairs(wtable) do
838 ColourTell("cornflower","black",v)
839 if (i < #wtable) then
840 ColourTell("red", "black", pattern)
841 end
842 end
843 Note("")
844 end
845 end
846 end
847 else
848 badnews = true
849 end
850 else
851 badnews = true
852 end
853 end
854 if badnews then
855 blackindigoPrint("")
856 mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
857 blackindigoPrint("")
858 blackindigoPrint(help_index)
859 end
860 blackindigoPrint("")
861 blackindigoPrint("+---------------------------------------------------------------------------+")
862 blackindigoPrint("")
863end
864
865
866-- -----------------------------------------------------------------
867-- Plugin Save State
868-- -----------------------------------------------------------------
869
870function OnPluginSaveState ()
871 mapper.save_state ()
872 SetVariable ("config", "config = " .. serialize.save_simple (config))
873 SetVariable("last_backup", last_backup)
874end -- OnPluginSaveState
875
876------------------------------------------
877-- start of sql additions
878------------------------------------------
879function delete_room_alias(name, line, wildcards)
880 local num = wildcards[1]
881 if num then
882 delete_room(num)
883 end
884end
885
886function delete_area_alias(name, line, wildcards)
887 local a = wildcards[1]
888 if a then
889 delete_area(a)
890 end
891end
892
893function delete_room(num) -- delete room from rooms
894 for r, tbl in pairs(rooms) do -- for each room in table
895 if tostring(r) == tostring(num) then
896 rooms[r] = nil -- setting table item to nil deletes it
897 end
898 end
899 run_sql([[DELETE FROM rooms WHERE uid = ']]..num..[[']])
900 Note("Deleted", r, ".")
901end
902
903function delete_area(a)
904 local cnt = 0
905 for r, tbl in pairs(rooms) do -- for each room in table
906 if tostring(tbl.area) == tostring(a) then
907 rooms[r] = nil -- setting table item to nil deletes it
908 cnt = cnt + 1
909 end
910 end
911 run_sql([[DELETE FROM rooms WHERE area = ']]..fix_sql(a)..[[']])
912 Note("Deleted ", cnt, " rooms in '", a, "' area.")
913end
914
915function clean_file_name(f)
916 f = string.gsub(f, "[^%w]", "")
917 return f
918end
919
920function fix_sql(s)
921 if not s then -- nil value
922 return ""
923 end
924 return string.gsub(s, "'", "''")
925end
926
927function run_sql(sql)
928 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
929 --Note(sql)
930 rslt = db:exec(sql)
931 --Note(rslt)
932 db:close()
933end
934
935function load_rooms()
936 rooms = {}
937 sql = [[
938 SELECT * FROM rooms ORDER BY uid ASC;
939 ]]
940 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
941 local cnt = 0
942 for row in db:nrows(sql) do
943 cnt = cnt + 1
944 rooms[row.uid] = {
945 name = row.name,
946 desc = row.desc,
947 area = row.area,
948 fillcolour = row.fillcolour,
949 fillbrush = row.fillbrush,
950 bordercolour = row.bordercolour,
951 info = row.info,
952 notes = row.notes,
953 exits = loadstring("return "..row.exits)()
954 }
955 end
956 Note("Loaded ", cnt, " rooms from database.")
957 db:close()
958
959 if tonumber(last_backup) == 0 then
960 backup_db()
961 end
962end
963
964function check_update_room(uid, room)
965 if not rooms[uid] or (serialize.save_simple(room) ~= serialize.save_simple(rooms[uid])) then
966 add_update_room(uid, room)
967 end
968end
969
970function add_update_room(uid, room)
971 sql = [[
972 INSERT OR REPLACE INTO rooms (uid, name, desc, area, fillcolour, fillbrush, bordercolour, info, notes, exits)
973 VALUES
974 (']]..uid..[[',
975 ']]..fix_sql(room.name)..[[',
976 ']]..room.desc..[[',
977 ']]..fix_sql(room.area)..[[',
978 ']]..fix_sql(room.fillcolour)..[[',
979 ']]..fix_sql(room.fillbrush)..[[',
980 ']]..fix_sql(room.bordercolour)..[[',
981 ']]..fix_sql(room.info)..[[',
982 ']]..fix_sql(room.notes)..[[',
983 ']]..fix_sql(serialize.save_simple(room.exits))..[[')
984 ]]
985 run_sql(sql)
986end
987
988function check_create_db()
989 sql = [[
990 CREATE TABLE IF NOT EXISTS rooms (
991 uid TEXT PRIMARY KEY,
992 name TEXT,
993 desc TEXT,
994 area TEXT,
995 fillcolour INTEGER,
996 fillbrush INTEGER,
997 bordercolour INTEGER,
998 info TEXT,
999 notes TEXT,
1000 exits TEXT
1001 )
1002 ]]
1003 run_sql(sql)
1004end
1005
1006------------------------------------------
1007-- end of sql additions
1008------------------------------------------
1009
1010------------------------------------------
1011-- backup stuff
1012------------------------------------------
1013-- If you want to do manual backups, make an alias with: script="backup_db"
1014------------------------------------------
1015
1016function backup_db()
1017 Note("Creating database backup.")
1018 local bk_nm = GetInfo(66).."db_backups\\"..clean_file_name(WorldName())..".db."..os.date("%A")
1019 ffi = require("ffi")
1020 ffi.cdef[[
1021 bool CreateDirectoryA(const char *lpPathName, void *lpSecurityAttributes);
1022 bool CopyFileA(const char* lpExistingFileName, const char * lpNewFileName, bool bFailIfExists);
1023 unsigned long GetLastError(void);
1024 ]]
1025
1026 succ = ffi.C.CreateDirectoryA(GetInfo(66).."db_backups\\", nil)
1027 err_no = ffi.C.GetLastError()
1028 if err_no and err_no ~= 183 and err_no ~= 127 then
1029 Note("Error creating directory: ", err_no)
1030 end
1031
1032 succ = ffi.C.CopyFileA(GetInfo(66)..clean_file_name(WorldName())..".db", bk_nm, false)
1033
1034 Note("Backup created: ", bk_nm)
1035 last_backup = os.time()
1036end
1037
1038------------------------------------------
1039-- end backup stuff
1040------------------------------------------
1041]]>
1042</script>
1043
1044
1045</muclient>