· 6 years ago · Mar 26, 2019, 08:24 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<!DOCTYPE muclient [
6 <!ENTITY show_vnums "true" >
7 <!ENTITY show_timing "false" >
8 <!ENTITY show_completed "false" >
9 <!ENTITY show_database_mods "true" >
10 <!ENTITY show_other_areas "true" >
11 <!ENTITY show_area_exits "true" >
12 <!ENTITY show_up_down "false" >
13 <!ENTITY speedwalk_prefix "" >
14]>
15<!-- Plugin "AlterAeonMapper" generated by Plugin Wizard -->
16
17<muclient>
18<plugin
19 name="DemonMUSH_Mapper"
20 author="Master Vivi, Endymion, Valour"
21 id="dd07d6dbe73fe0bd02ddb63d"
22 language="Lua"
23 purpose="Shows the mapper for Alter Aeon"
24 save_state="y"
25 date_written="2018-04-26 07:21:01"
26 requires="4.51"
27 version="1.0"
28 >
29
30</plugin>
31
32<aliases>
33
34 <!-- zooming aliases -->
35
36 <alias
37 match="mapper zoom out"
38 enabled="y"
39 sequence="100"
40 omit_from_command_history="y"
41 omit_from_output="y"
42 script="mapper.zoom_out"
43 >
44 </alias>
45
46<alias
47 match="mapper zoom in"
48 enabled="y"
49 sequence="100"
50 omit_from_command_history="y"
51 omit_from_output="y"
52 script="mapper.zoom_in"
53 >
54 </alias>
55<alias
56 match="mapper thisroom"
57 enabled="y"
58 sequence="100"
59 script="show_this_room"
60 regexp="n">
61</alias>
62<alias
63 match="^mapper addnote( .*)?$"
64 regexp="y"
65 enabled="y"
66 sequence="100"
67 send_to="12"
68>
69<send>
70 room_edit_note(nil,nil,Trim("%1"))
71</send>
72</alias>
73<alias
74 match="^mapper next( .*)?$"
75 enabled="y"
76 regexp="y"
77 sequence="100"
78 send_to="12"
79>
80<send>
81mapper.gotoNextResult(Trim("%1"))
82</send>
83</alias>
84
85 <alias
86 match="mapper resume"
87 enabled="y"
88 sequence="100"
89 script="map_resume"
90 >
91
92 </alias>
93 <alias
94 match="mapper stop"
95 enabled="y"
96 sequence="100"
97 script="mapper.cancel_speedwalk"
98 >
99 </alias>
100
101 <!-- show/hide mapper -->
102
103 <alias
104 match="mapper hide"
105 enabled="y"
106 sequence="100"
107 script="mapper.hide"
108 >
109 </alias>
110
111 <alias
112 match="mapper show"
113 enabled="y"
114 sequence="100"
115 script="mapper.show"
116 >
117 </alias>
118<alias
119 match="^mapper help( (.*))?$"
120 enabled="y"
121 regexp="y"
122 script="OnHelp"
123></alias>
124
125<alias
126 match="^mapper updown$"
127 enabled="y"
128 regexp="y"
129 send_to="12"
130>
131<send>
132 mapper.show_up_down = not mapper.show_up_down
133 mapper.draw (current_room)
134</send>
135</alias>
136
137<alias
138 match="^mapper underlines?$"
139 enabled="y"
140 regexp="y"
141 send_to="12"
142>
143<send>
144 NoUnderline_hyperlinks = not NoUnderline_hyperlinks
145 Note("Mapper hyperlinks will " ..(NoUnderline_hyperlinks and "no longer" or "now").." be underlined.")
146 SetVariable("NoUnderline_hyperlinks", NoUnderline_hyperlinks and "1" or "0")
147</send>
148</alias>
149 <alias
150 match="mapper goto *"
151 enabled="y"
152 sequence="100"
153 script="map_goto"
154 >
155 </alias>
156<alias
157 match="mapper find *"
158 enabled="y"
159 sequence="100"
160 script="map_find"
161 regexp="n"
162></alias>
163<alias
164 match="mapper findpath * *"
165 enabled="y"
166 sequence="100"
167 omit_from_output="y"
168 script="findpathfast"
169></alias>
170
171 <alias
172 match="mapper where *"
173 enabled="y"
174 sequence="100"
175 script="map_where"
176 >
177 </alias>
178 <alias
179 match="mapper backup"
180 enabled="y"
181 sequence="100"
182 script="backup_db"
183 >
184 </alias>
185 <alias
186 match="^mapper delete room (\d+)$"
187 enabled="y"
188 regexp="y"
189 script="delete_room_alias"
190>
191</alias>
192<alias
193 match="^mapper delete area (.+)$"
194 enabled="y"
195 regexp="y"
196 script="delete_area_alias"
197>
198</alias>
199<alias
200 match="^mapper flag shop$"
201 enabled="y"
202 regexp="y"
203 sequence="100"
204 send_to="12"
205><send>shoptoggle()</send>
206</alias>
207<alias
208 match="^mapper flag waypoint$"
209 enabled="y"
210 regexp="y"
211 sequence="100"
212 send_to="12"
213><send>waypointtoggle()</send>
214</alias>
215<alias
216 match="^mapper flag alchemyguild$"
217 enabled="y"
218 regexp="y"
219 sequence="100"
220 send_to="12"
221><send>alchemyguildtoggle()</send>
222</alias>
223<alias
224 match="^mapper flag teacher$"
225 enabled="y"
226 regexp="y"
227 sequence="100"
228 send_to="12"
229><send>teachertoggle()</send>
230</alias>
231<alias
232 match="^mapper flag employer$"
233 enabled="y"
234 regexp="y"
235 sequence="100"
236 send_to="12"
237><send>employertoggle()</send>
238</alias>
239<alias
240 match="^mapper flag priest$"
241 enabled="y"
242 regexp="y"
243 sequence="100"
244 send_to="12"
245><send>priesttoggle()</send>
246</alias>
247<alias
248 match="^mapper flag forge$"
249 enabled="y"
250 regexp="y"
251 sequence="100"
252 send_to="12"
253><send>forgetoggle()</send>
254</alias>
255<alias
256 match="^mapper flag bank$"
257 enabled="y"
258 regexp="y"
259 sequence="100"
260 send_to="12"
261><send>banktoggle()</send>
262</alias>
263<alias
264 match="^mapper flag warrior trainer$"
265 enabled="y"
266 regexp="y"
267 sequence="100"
268 send_to="12"
269><send>warriortrainertoggle()</send>
270</alias>
271<alias
272 match="^mapper flag thief trainer$"
273 enabled="y"
274 regexp="y"
275 sequence="100"
276 send_to="12"
277><send>thieftrainertoggle()</send>
278</alias>
279<alias
280 match="^mapper flag druid trainer$"
281 enabled="y"
282 regexp="y"
283 sequence="100"
284 send_to="12"
285><send>druidtrainertoggle()</send>
286</alias>
287<alias
288 match="^mapper flag mage trainer$"
289 enabled="y"
290 regexp="y"
291 sequence="100"
292 send_to="12"
293><send>magetrainertoggle()</send>
294</alias>
295<alias
296 match="^mapper flag cleric trainer$"
297 enabled="y"
298 regexp="y"
299 sequence="100"
300 send_to="12"
301><send>clerictrainertoggle()</send>
302</alias>
303<alias
304 match="^mapper flag necromancer trainer$"
305 enabled="y"
306 regexp="y"
307 sequence="100"
308 send_to="12"
309><send>necromancertrainertoggle()</send>
310</alias>
311<alias
312 match="^mapper flag ranger trainer$"
313 enabled="y"
314 regexp="y"
315 sequence="100"
316 send_to="12"
317><send>rangertrainertoggle()</send>
318</alias>
319<alias
320match="UpdateTownSpecial"
321enabled="y"
322sequence="100"
323>
324<send>
325where shops | prefix {Where Shop}
326where banks | prefix {Where Bank}
327where teachers | prefix {Where Teacher}
328where guildmasters | prefix {Where Guildmaster}
329where employers | prefix {Where Employer}
330where priests | prefix {Where Priest}
331where forges | prefix {Where Forge}
332</send>
333</alias>
334</aliases>
335
336
337<!-- Triggers -->
338
339<triggers>
340 <trigger
341 enabled="n"
342 match="^kxwt\_waypoint$"
343 omit_from_log="y"
344 omit_from_output="y"
345 regexp="y"
346 send_to="14"
347 sequence="100"
348 >
349<send>waypointtoggle()</send>
350 </trigger>
351 <trigger
352 enabled="y"
353 match="kxwt_rshort *"
354 name="process_room_name"
355 sequence="100"
356 send_to="14"
357 >
358 <send>
359 name="%1"
360 if rooms ~= nil and
361 rooms[uid] ~= nil and
362 rooms[uid].notes ~= nil and
363 rooms[uid].notes ~= ""
364 then
365 mapper.mapprint("Note:", rooms[uid].notes)
366 end
367 </send>
368 </trigger>
369 <trigger
370 enabled="y"
371 match="kxwt_rvnum *"
372 name="process_room_desc"
373 sequence="100"
374 script="room_number"
375 >
376 </trigger>
377 <trigger
378 enabled="y"
379 match="kxwt_walkdir *"
380 name="moved_direction"
381 sequence="100"
382 script="moved_direction"
383 >
384 </trigger>
385 <trigger
386 enabled="y"
387 match="kxwt_terrain *"
388 name="process_terrain"
389 sequence="100"
390 send_to="14"
391 >
392 <send>terrain="%1"</send>
393 </trigger>
394 <trigger
395 enabled="y"
396 match="kxwt_area * *"
397 name="process_area"
398 sequence="100"
399 send_to="14"
400 >
401 <send>area="%2"</send>
402 </trigger>
403 <trigger
404 enabled="y"
405 match="[Exits: *]"
406 name="Exits_Line"
407 sequence="100"
408 send_to="14"
409 >
410 <send>process_exits("%1")</send>
411 </trigger>
412 <trigger
413 enabled="y"
414 match="Alas, you cannot go that way."
415 script="mapper.cancel_speedwalk"
416 sequence="100"
417 ></trigger>
418 <trigger
419 enabled="y"
420 match="* would be left behind."
421 script="mapper.cancel_speedwalk"
422 sequence="100"
423 ></trigger>
424 <trigger
425 enabled="y"
426 match="You are too exhausted to continue your stealthy movement!"
427 script="mapper.cancel_speedwalk"
428 sequence="100"
429 ></trigger>
430 <trigger
431 enabled="y"
432 match="You are too exhausted."
433 script="mapper.cancel_speedwalk"
434 sequence="100"
435 ></trigger>
436 <trigger
437 enabled="y"
438 match="You follow * *."
439 script="mapper.cancel_speedwalk"
440 sequence="100"
441 ></trigger>
442 <trigger
443 enabled="y"
444 match="You'll have to climb to go there."
445 script="mapper.cancel_speedwalk"
446 sequence="100"
447 ></trigger>
448 <trigger
449 enabled="y"
450 match="You can't just walk away from a fight!"
451 script="mapper.cancel_speedwalk"
452 sequence="100"
453 ></trigger>
454 <trigger
455 enabled="y"
456 match="The * is closed."
457 script="mapper.cancel_speedwalk"
458 sequence="100"
459 ></trigger>
460 <trigger
461 enabled="y"
462 match="* blocks your path, preventing you from passing."
463 script="mapper.cancel_speedwalk"
464 sequence="100"
465 ></trigger>
466 <trigger
467 enabled="y"
468 match="^The (door|gate) is closed\.$"
469 regexp="y"
470 name="Door_Closed"
471 script="Door_Closed"
472 sequence="100"
473 >
474 </trigger>
475 <trigger
476 enabled="y"
477 match="The wooden door is closed."
478 regexp=""
479 name="woodendoor_closed"
480 script="Door_Closed"
481 sequence="100"
482 >
483 </trigger>
484<trigger
485 enabled="n"
486 match="^{Where (.*)}\w{1,2}(?:.*->)?\s+(.*)$"
487 regexp="y"
488 name="InfoUpdate"
489 script="updateRoomInfo"
490 sequence="100"
491>
492</trigger>
493</triggers>
494
495<!-- Timers -->
496
497<timers>
498 <timer
499 name="backup_timer"
500 enabled="y"
501 script="backup_db"
502 hour="1" minute="01" second="59"
503 active_closed="y" >
504 </timer>
505</timers>
506
507<!-- Script -->
508
509
510<script>
511local show_other_areas = &show_other_areas;
512<![CDATA[
513
514mapper = require "altermapper"
515require "serialize"
516require "copytable"
517uid = 0
518current_room=nil
519current_area = 0
520expected_exit=-666
521from_room=""
522last_direction_moved=nil
523terrain = 0
524area = 0
525last_backup = GetVariable("last_backup") or 0
526notes = 0
527default_width = 269
528default_height = 335
529local posx = 100
530local posy = 100
531local DIFFERENT_AREA_COLOUR = "#ff0000"
532
533
534count = 0
535roomcount = 0
536rooms = {}
537local user_terrain_colour = {}
538
539local kxwt_dirs = {
540 ["0"] = "n",
541 ["2"] = "s",
542 ["4"] = "ne",
543 ["6"] = "sw",
544 ["5"] = "se",
545 ["7"] = "nw",
546 ["3"] = "w",
547 ["1"] = "e",
548 ["20"] = "u",
549 ["30"] = "d",
550 ["99"] = "unk" -- idk what to do here (nothing?) (i'm not sure either, maybe wait till it happens and you can duplicate it)
551}
552
553valid_direction = {
554n = "n",
555s = "s",
556e = "e",
557w = "w",
558u = "u",
559d = "d",
560ne = "ne",
561sw = "sw",
562nw = "nw",
563no="n",
564ea="e",
565so="s",
566we="w",
567se = "se",
568north = "n",
569south = "s",
570east = "e",
571west = "w",
572up = "u",
573down = "d",
574northeast = "ne",
575northwest = "nw",
576southeast = "se",
577southwest = "sw",
578['in'] = "in",
579out = "out",
580} -- end of valid_direction
581
582
583terrain_color = {}
584
585-----------------------------------------
586-- ADDING TRIGGER STUFF
587-----------------------------------------
588
589function room_number(name, line, args)
590 uid = args[1] -- this was in the <send> previously
591 from_room = current_room or ""
592 current_room = args[1]
593end
594
595function moved_direction(name, line, args)
596 last_direction_moved = kxwt_dirs[args[1]] or "unk"
597end
598
599------------------------------------------
600--Update Town Special Procedure
601------------------------------------------
602
603function updateRoomInfo(name, line, wildcards)
604 local roomtype, room = wildcards[1], wildcards[2]
605
606 local roomuid, matchFound = 0, false
607 for i,v in pairs(rooms) do
608 if v.name == Trim(room) then
609 roomuid = i
610 matchFound = true
611 break
612 end
613 end
614
615 if matchFound == true then
616 if not string.find(rooms[roomuid].info, roomtype) then
617 rooms[roomuid].info = rooms[roomuid].info .. " " .. roomtype
618 add_update_room(roomuid, rooms[roomuid])
619 mapper.draw(roomuid)
620 end
621 else
622 print("Room not mapped!")
623 end
624end
625
626-----------------------------------------
627-- DONE ADDING TRIGGER STUFF
628-----------------------------------------
629
630function shoptoggle()
631rooms[current_room].info = rooms[current_room].info.."shop"
632 add_update_room(current_room, rooms[current_room])
633 mapper.draw(current_room)
634end -- shoptoggle
635function banktoggle()
636rooms[current_room].info = rooms[current_room].info.."bank"
637 add_update_room(current_room, rooms[current_room])
638 mapper.draw(current_room)
639end -- banktoggle
640function waypointtoggle()
641rooms[current_room].info = rooms[current_room].info.."waypoint"
642 add_update_room(current_room, rooms[current_room])
643 mapper.draw(current_room)
644end -- waypointtoggle
645function guildtoggle()
646rooms[current_room].info = rooms[current_room].info.."guild"
647 add_update_room(current_room, rooms[current_room])
648 mapper.draw(current_room)
649end -- guildtoggle
650function alchemyguildtoggle()
651rooms[current_room].info = rooms[current_room].info.."alchemyguild"
652 add_update_room(current_room, rooms[current_room])
653 mapper.draw(current_room)
654end -- alchemyguildtoggle
655function teachertoggle()
656rooms[current_room].info = rooms[current_room].info.."teacher"
657 add_update_room(current_room, rooms[current_room])
658 mapper.draw(current_room)
659end -- teachertoggle
660function employertoggle()
661rooms[current_room].info = rooms[current_room].info.."employer"
662 add_update_room(current_room, rooms[current_room])
663 mapper.draw(current_room)
664end -- employertoggle
665function priesttoggle()
666rooms[current_room].info = rooms[current_room].info.."priest"
667 add_update_room(current_room, rooms[current_room])
668 mapper.draw(current_room)
669end -- priesttoggle
670function forgetoggle()
671rooms[current_room].info = rooms[current_room].info.."forge"
672 add_update_room(current_room, rooms[current_room])
673 mapper.draw(current_room)
674end -- forgetoggle
675function warriortrainertoggle()
676rooms[current_room].info = rooms[current_room].info.."warriortrainer"
677 add_update_room(current_room, rooms[current_room])
678 mapper.draw(current_room)
679end -- warriortrainertoggle
680function thieftrainertoggle()
681rooms[current_room].info = rooms[current_room].info.."thieftrainer"
682 add_update_room(current_room, rooms[current_room])
683 mapper.draw(current_room)
684end -- thieftrainertoggle
685function druidtrainertoggle()
686rooms[current_room].info = rooms[current_room].info.."druidtrainer"
687 add_update_room(current_room, rooms[current_room])
688 mapper.draw(current_room)
689end -- druidtrainertoggle
690function magetrainertoggle()
691rooms[current_room].info = rooms[current_room].info.."magetrainer"
692 add_update_room(current_room, rooms[current_room])
693 mapper.draw(current_room)
694end -- magetrainertoggle
695function clerictrainertoggle()
696rooms[current_room].info = rooms[current_room].info.."clerictrainer"
697 add_update_room(current_room, rooms[current_room])
698 mapper.draw(current_room)
699end -- clerictrainertoggle
700function necromancertrainertoggle()
701rooms[current_room].info = rooms[current_room].info.."necromancertrainer"
702 add_update_room(current_room, rooms[current_room])
703 mapper.draw(current_room)
704end -- necromancertrainertoggle
705function rangertrainertoggle()
706rooms[current_room].info = rooms[current_room].info.."rangertrainer"
707 add_update_room(current_room, rooms[current_room])
708 mapper.draw(current_room)
709end -- rangertrainertoggle
710
711function room_toggle_inn (room, uid)
712 room_toggle_thing (room, uid, "inn", "an inn")
713end -- room_toggle_inn
714
715function room_toggle_train (room, uid)
716 room_toggle_thing (room, uid, "train", "a training room")
717end -- room_toggle_train
718
719function room_toggle_guild (room, uid)
720 room_toggle_thing (room, uid, "guild", "a guild master room")
721end -- room_toggle_guild
722
723
724function room_edit_note(room, vuid, newnotes)
725 if vuid == nil and current_room ~= nil then
726 vuid = current_room
727 room = rooms[vuid]
728 end
729
730 if vuid == nil then -- still nothing?
731 print("No room received from the mud yet. Try using the 'LOOK' command first.")
732 return
733 end
734
735 if newnotes == nil or newnotes == "" then
736 if room.notes ~= nil and room.notes ~= "" then
737 newnotes = utils.inputbox("Modify room comment (clear it to delete from database)", room.name, room.notes)
738 else
739 newnotes = utils.inputbox("Enter room comment (creates a note for this room)", room.name, room.notes)
740 end -- if
741 end
742
743 if not newnotes then
744 return
745 end -- if cancelled
746
747 if newnotes == "" then
748 if room.notes == nil or room.notes == "" then
749 mapper.mapprint("No comment entered, note not saved.")
750 return
751 else
752 mapper.mapprint("Note from room " .. current_room .. " deleted. Was previously: " .. room.notes)
753 rooms[current_room].notes = ""
754 add_update_room(current_room, rooms[current_room])
755 mapper.draw(current_room)
756 end
757 end
758
759 if rooms[current_room].notes == newnotes then
760 return -- no change made
761 end
762
763 local oldNote = room.note
764
765 rooms[current_room].notes = newnotes
766 add_update_room(current_room, rooms[current_room])
767 mapper.draw(current_room)
768
769 if oldNote ~= nil and #oldNote > 0 then
770 mapper.mapprint("Note for room", current_room, "changed to:", newnotes)
771 else
772 mapper.mapprint("Note added to room", current_room, ":", newnotes)
773 end
774end
775
776
777-- -----------------------------------------------------------------
778-- Here on "Exits:" line ----- we have changed rooms
779-- -----------------------------------------------------------------
780
781function process_exits (exits_str)
782 --Note("process exits")
783 if current_room == from_room then
784 --Note(current_room, ", ", from_room)
785 --Note("same room")
786 --return
787 end
788
789 -- genereate a "room ID" by hashing the room name, description and exits
790 -- break up exits into individual directions
791 exits = {}
792
793 for exit in string.gmatch (exits_str, "%w+") do
794 local ex = valid_direction [exit]
795 if ex then
796 exits [ex] = "-666" -- don't know where it goes yet
797 end -- if
798 end -- for
799
800 -- add to table if not known
801 --Note("add room to table")
802 if not rooms [uid] then
803 rooms [uid] = { name = name, desc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
804 add_update_room(uid, rooms[uid])
805 end -- if
806
807 -- save so we know current room later on
808 current_room = uid
809
810 -- add exit into mapper
811 --Note("add exit")
812 if from_room ~= "" and last_direction_moved then -- we were in a room # that we got from kxwt, and then moved to another room
813 --Note("rooms[", from_room, "].exits[", last_direction_moved, "] = ", current_room)
814 rooms[from_room].exits[last_direction_moved] = current_room
815 add_update_room(from_room, rooms[from_room])
816 last_direction_moved = nil -- remove last direction so updating a room only happens when we walk somewhere
817 end
818
819 -- call mapper to draw this room
820 mapper.draw (uid)
821
822end -- process_exits
823
824-- -----------------------------------------------------------------
825-- Here on white coloured line - this is a room name or room exits
826-- -----------------------------------------------------------------
827
828function Name_Or_Exits (name, line, wildcards)
829
830 exits = string.match (line, "^Exits: (.*)")
831
832 if exits then
833 process_exits (exits)
834 end -- if
835
836 roomname = line
837 roomdesc = nil
838
839end -- Name_Or_Exits
840
841-- -----------------------------------------------------------------
842-- Here on yellow line - part of room description
843-- -----------------------------------------------------------------
844
845function Name_Line (name, line, wildcards)
846 roomdesc = (roomdesc or "" ) .. line .. "\n"
847end -- Name_Or_Exits
848-- -----------------------------------------------------------------
849-- for converting things like ^ $ * etc. into "escaped" sequences
850-- -----------------------------------------------------------------
851function fix_regexp_magic_characters (r)
852 return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
853end -- fix_regexp_magic_characters
854
855-- -----------------------------------------------------------------
856-- mapper 'get_room' callback - it wants to know about room uid
857-- -----------------------------------------------------------------
858
859function get_room (uid)
860
861
862 if not rooms [uid] then
863 return nil
864 end -- if
865
866 local room = copytable.deep (rooms [uid])
867 local notes = ""
868 if room.notes and room.notes ~= "" then
869 notes = "\nNote: " .. room.notes
870 end -- if notes
871
872 local texits = {}
873 for dir in pairs (room.exits) do
874 table.insert (texits, dir)
875 end -- for
876 table.sort (texits)
877
878 if uid == current_room then
879 current_area = room.area
880 end -- if
881
882 room.hovermessage = string.format (
883"%s\tExits: %s\nRoom: %s\nArea: %s \nTerrain: %s%s",
884 room.name,
885 table.concat (texits, ", "),
886 uid,
887 area,
888 terrain,
889 notes
890 -- depth,
891 -- table.concat (path, ",")
892 )
893
894
895 -- SPECIAL ROOM COLOUR FILLS
896special_room = false
897 if room.info and room.info ~= "" then
898 if string.match (room.info, "waypoint") then
899 special_room = true
900 elseif string.match (room.info, "bank") then
901 special_room = true
902 elseif string.match (room.info, "alchemyguild") then
903 special_room = true
904 elseif string.match (room.info, "teacher") then
905 special_room = true
906 elseif string.match (room.info, "employer") then
907 special_room = true
908 elseif string.match (room.info, "priest") then
909 special_room = true
910 elseif string.match (room.info, "forge") then
911 special_room = true
912 elseif string.match (room.info, "warriortrainer") then
913 special_room = true
914 elseif string.match (room.info, "thieftrainer") then
915 special_room = true
916 elseif string.match (room.info, "druidtrainer") then
917 special_room = true
918 elseif string.match (room.info, "clerictrainer") then
919 special_room = true
920 elseif string.match (room.info, "magetrainer") then
921 special_room = true
922 elseif string.match (room.info, "necromancertrainer") then
923 special_room = true
924 elseif string.match (room.info, "rangertrainer") then
925 special_room = true
926
927 end
928end -- if
929 if uid == current_room and special_room then
930 room.bordercolour = mapper.OUR_ROOM_COLOUR.colour
931 room.borderpenwidth = 3
932
933 elseif room.area ~= current_area then
934 room.bordercolour = ColourNameToRGB "red"
935 end -- not in this area
936 return room
937
938
939end -- get_room
940
941function show_this_room (name, line, wildcards)
942 local room = rooms[current_room]
943 if room ~= nil then
944 Note("Details about this room:")
945 Note("+---------------------------+")
946 Note("Name: "..(name or ""))
947 Note("ID: "..(uid or ""))
948 Note("Area: "..(area or ""))
949 Note("Terrain: "..(terrain or ""))
950 Note("Info: "..(room.info or ""))
951 Note("Notes: "..(room.notes or ""))
952 Note("Exits: "..(room.exits or ""))
953else
954 Note("THISROOM ERROR: You need to type 'LOOK' first to initialize the mapper before trying to get room information.")
955 end
956end -- show_this_room
957
958function room_click (uid, flags)
959
960 -- check we got room at all
961 if not uid then
962 return nil
963 end -- if
964
965 -- look it up
966 local room = rooms [uid]
967
968 -- not cached - see if in database
969 if not room then
970return
971 end -- not in cache
972
973 if not room then
974 return
975 end -- if still not there
976
977 local function checkmark (which)
978 if rooms [uid] [which] then
979 return "+"
980 else
981 return ""
982 end -- if
983 end -- checkmark
984
985
986 local handlers = {
987 { name = "Edit bookmark", func = room_edit_bookmark} ,
988 { name = "-", } ,
989 { name = "Add Exit", func = room_add_exit} ,
990 { name = "Change Exit", func = room_change_exit} ,
991 { name = "Delete Exit", func = room_delete_exit} ,
992 { name = "-", } ,
993 { name = checkmark ("shop") .. "Shop", func = room_toggle_shop } ,
994 { name = checkmark ("train") .. "Trainer", func = room_toggle_train } ,
995 { name = checkmark ("inn") .. "Inn", func = room_toggle_inn } ,
996 { name = checkmark ("guild") .. "Guildmaster", func = room_toggle_guild } ,
997 } -- handlers
998
999 local t, tf = {}, {}
1000 for _, v in pairs (handlers) do
1001 table.insert (t, v.name)
1002 tf [v.name] = v.func
1003 end -- for
1004
1005 local choice = WindowMenu (mapper.win,
1006 WindowInfo (mapper.win, 14),
1007 WindowInfo (mapper.win, 15),
1008 table.concat (t, "|"))
1009
1010 local f = tf [choice]
1011
1012 if f then
1013 f (room, uid)
1014 end -- if handler found
1015
1016end -- room_click
1017
1018
1019-- -----------------------------------------------------------------
1020-- map_find: mapper find xxx
1021-- -----------------------------------------------------------------
1022function map_find (name, line, wildcards)
1023
1024 mapper.mapprint (string.rep ("-", 25) .. " Mapper search " .. string.rep ("-", 25))
1025
1026 local reset = ANSI (0)
1027 local bold = ANSI (1)
1028 local unbold = ANSI (22)
1029
1030 local matches = { }
1031 local count = 0
1032 local target = Trim (wildcards [1]:lower ())
1033
1034 if target == "" then
1035 mapper.maperror ("No search string specified")
1036 return
1037 end -- if
1038
1039 if not mapper.check_we_can_find () then
1040 return
1041 end -- if find not OK
1042
1043 -- fix up any regular expression "magic" letters to be escaped by a %
1044 local fixed_target = fix_regexp_magic_characters (target)
1045
1046 -- fix up for caseless searches in the room description (eg. "a" becomes "[aA]")
1047 local caseless_target = string.gsub (fixed_target, "(%a)", function (a)
1048 return "[" .. a:lower () .. a:upper () .. "]"
1049 end -- function
1050 )
1051
1052 -- do a simple string search to find matching rooms
1053 for k, v in pairs (rooms) do
1054
1055 -- don't want nil descriptions
1056 if not v.description then
1057 v.description = ""
1058 end -- if no description
1059
1060 if string.find (v.name:lower (), fixed_target) or
1061 string.find (v.description:lower (), fixed_target) then
1062 matches [k] = true
1063 count = count + 1
1064 end -- if match
1065 end -- for each room
1066
1067 local function show_snippet (uid)
1068 local room = rooms [uid]
1069 if not room then
1070 return
1071 end -- if
1072
1073 -- don't bother if the wanted words was in the room name
1074 if string.find (room.name:lower (), fixed_target) then
1075 return
1076 end -- if
1077
1078 -- otherwise show the wanted word in the description, in bold
1079 AnsiNote (reset .. string.gsub (room.description, caseless_target, bold .. "%1" .. unbold))
1080
1081 end -- show_snippet
1082
1083 -- see if nearby
1084 mapper.find (
1085 function (uid)
1086 local room = matches [uid]
1087 if room then
1088 matches [uid] = nil
1089 end -- if
1090 return room, next (matches) == nil
1091 end, -- function
1092 show_vnums, -- show vnum?
1093 count, -- how many to expect
1094 false, -- don't auto-walk
1095 show_snippet -- show find snippet
1096 )
1097end -- map_find
1098
1099
1100
1101-- -----------------------------------------------------------------
1102-- map_goto for: mapper goto xxx
1103-- -----------------------------------------------------------------
1104function map_goto (name, line, wildcards)
1105 local wanted = wildcards [1]
1106 -- check valid string
1107 if string.match (wanted, "%D") then
1108 mapper.maperror ("Room number must be numeric, you entered: " .. wanted)
1109 return
1110 end -- if
1111
1112 -- see if already there
1113 if current_room and string.match (current_room, "^" .. wanted) then
1114 mapper.mapprint ("You are already in that room.")
1115 return
1116 end -- if
1117 -- find desired room
1118 mapper.find (
1119 function (uid)
1120 local found = string.match (uid, "^" .. wanted)
1121 return found, found
1122 end, -- function
1123 show_vnums, -- show vnum?
1124 1, -- how many to expect
1125 true -- just walk there
1126 )
1127end -- map_goto
1128
1129function map_resume (name, line, wildcards)
1130
1131 local wanted = mapper.last_hyperlink_uid or mapper.last_speedwalk_uid
1132
1133 if not wanted then
1134 mapper.print "No outstanding speedwalks or hyperlinks."
1135 return
1136 end -- if nothing to do
1137
1138 -- find desired room
1139 mapper.find (
1140 function (uid)
1141 return uid == wanted, uid == wanted
1142 end, -- function
1143 show_vnums, -- show vnum?
1144 1, -- how many to expect
1145 true -- just walk there
1146 )
1147
1148end -- map_resume
1149
1150-- -----------------------------------------------------------------
1151-- map_where: Show where a room is
1152-- -----------------------------------------------------------------
1153function map_where (name, line, wildcards)
1154 if not mapper.check_we_can_find () then
1155 return
1156 end -- if
1157 local wanted = wildcards [1]
1158 if current_room and wanted == current_room then
1159 mapper.mapprint ("You are already in that room.")
1160 return
1161 end -- if
1162 local paths = mapper.find_paths (current_room,
1163 function (uid)
1164 return uid == wanted, -- wanted room?
1165 uid == wanted -- stop searching?
1166 end)
1167 local uid, item = next (paths, nil) -- extract first (only) path
1168 -- nothing? room not found
1169 if not item then
1170 mapper.mapprint (string.format ("Room %s not found", wanted))
1171 return
1172 end -- if
1173 -- turn into speedwalk
1174 local path = mapper.build_speedwalk (item.path)
1175 -- display it
1176 mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
1177end -- map_where
1178
1179-- -----------------------------------------------------------------
1180-- cannot_walk - we tried to walk but failed
1181-- -----------------------------------------------------------------
1182function cannot_walk (name, line, wildcards)
1183 mapper.cancel_speedwalk ()
1184 room_description = nil
1185 current_exits = nil
1186 room_name = nil
1187 last_direction_moved = nil
1188-- mapper.mapprint ("Attempt to walk cancelled.")
1189
1190end -- cannot_walk
1191
1192function confirm_delete_area(a)
1193 response = utils.umsgbox("Delete area: "..a.."?", "Delete Area", "okcancel", "?", 2)
1194 if response == "ok" then
1195 delete_area(a)
1196 end
1197end
1198
1199function Door_Closed (name, line, wildcards)
1200
1201local dirs = {
1202 n = "north",
1203 s = "south",
1204 e = "east",
1205 w = "west",
1206 u = "up",
1207 d = "down",
1208 ne = "northeast",
1209 sw = "southwest",
1210 nw = "northwest",
1211 se = "southeast",
1212 ['in'] = "in",
1213 out = "out",
1214 } -- end of available
1215
1216 if last_direction_moved then
1217 Send ("open " .. dirs [last_direction_moved])
1218 Send (dirs [last_direction_moved])
1219 end -- if
1220
1221end -- Door_Closed
1222
1223
1224-- -----------------------------------------------------------------
1225-- check_for_cannot_go - look up the line in a table of failure messages
1226-- see table: cannot_move_messages
1227-- -----------------------------------------------------------------
1228function check_for_cannot_go (name, line, wildcards)
1229
1230 for _, v in ipairs (cannot_move_messages) do
1231 if string.find (line, v) then
1232 cannot_walk ()
1233 break
1234 end -- if match
1235 end -- for each message
1236end -- check_for_cannot_go
1237
1238function findpathfast(name, line, wildcards)
1239 local src = wildcards[1]
1240 local dest = wildcards[2]
1241 rooms[src] = load_room_from_database(src)
1242 rooms[dest] = load_room_from_database(dest)
1243
1244 if rooms[src] == nil then
1245 mapper.mapprint (string.format ("Room %s not known.", src))
1246 end
1247 if rooms[dest] == nil then
1248 mapper.mapprint (string.format ("Room %s not known.", dest))
1249 end
1250 if rooms[src] == nil or rooms[dest] == nil then
1251 return
1252 end
1253
1254 local foundpath = findpath(src, dest)
1255 if foundpath == nil then
1256 mapper.mapprint (string.format ("Path from %s to %s not found.", wildcards[1], wildcards[2]))
1257 return
1258 end
1259
1260 -- turn into speedwalk
1261 local speedwalk = mapper.build_speedwalk (foundpath, speedwalk_prefix)
1262
1263 -- display it
1264 if speedwalk ~= nil then
1265 mapper.mapprint (string.format ("Path from %s to %s is: %s", wildcards[1], wildcards[2], speedwalk))
1266 else
1267 mapper.mapprint ("Pick different start and end rooms.")
1268 end
1269end
1270
1271function blackindigoPrint(msg)
1272 ColourNote("blueviolet","black",msg)
1273end
1274function blackredPrint(msg)
1275 ColourNote("black","red",msg)
1276end
1277function whiteindigoPrint(msg)
1278 ColourNote("white","indigo",msg)
1279end
1280
1281
1282function setup_terrain_colors()
1283terrain_color["0"]=tonumber("0x000000")--NOTSET
1284terrain_color["1"]=tonumber("0x606060")--Building
1285terrain_color["2"]=tonumber("0x805a22")--Town
1286terrain_color["3"]=tonumber("0x00ff00")--FIELD
1287terrain_color["4"]=tonumber("0x00c000")--LFOREST
1288terrain_color["5"]=tonumber("0x008000")--TFOREST
1289terrain_color["6"]=tonumber("0x004000")--DFOREST
1290terrain_color["7"]=tonumber("0x406080")--SWAMP
1291terrain_color["8"]=tonumber("0x60a060")--PLATEAU
1292terrain_color["9"]=ColourNameToRGB("khaki")--SANDY
1293terrain_color["10"]=tonumber("0xc0c0c0")--MOUNTAIN
1294terrain_color["11"]=tonumber("0x808080")--ROCK
1295terrain_color["12"]=ColourNameToRGB("burlywood")--DESERT
1296terrain_color["13"]=tonumber("0x805080")--TUNDRA
1297terrain_color["14"]=ColourNameToRGB("lightyellow")--BEACH
1298terrain_color["15"]=tonumber("0x409040")--HILL
1299terrain_color["16"]=ColourNameToRGB("navajowhite")--DUNES
1300terrain_color["17"]=tonumber("0x20c040")--JUNGLE
1301terrain_color["18"]=ColourNameToRGB("darkblue")--OCEAN
1302terrain_color["19"]=tonumber("0x00f0f0")--STREAM
1303terrain_color["20"]=ColourNameToRGB("blue")--RIVER
1304terrain_color["21"]=tonumber("0x021e6c")--UNDERWATER
1305terrain_color["22"]=tonumber("0x303030")--UNDERGROUND
1306terrain_color["23"]=ColourNameToRGB("lightskyblue")--AIR
1307terrain_color["24"]=tonumber("0x82f8e6")--ICE
1308terrain_color["25"]=ColourNameToRGB("red")--LAVA
1309terrain_color["26"]=tonumber("0x806060")--RUINS
1310terrain_color["27"]=tonumber("0x404040")--CAVE
1311terrain_color["28"]=tonumber("0x907040")--CITY
1312terrain_color["29"]=tonumber("0x20a060")--MARSH
1313terrain_color["30"]=tonumber("0xf0f0a0")--WASTELAND
1314terrain_color["31"]=tonumber("0xffffff")--CLOUD
1315terrain_color["32"]=ColourNameToRGB("blue")--WATER
1316terrain_color["33"]=tonumber("0x808080")--METAL
1317terrain_color["34"]=tonumber("0x006000")--TAIGA
1318terrain_color["35"]=tonumber("0x404040")--SEWER
1319terrain_color["36"]=ColourNameToRGB("indigo")--SHADOW
1320terrain_color["37"]=ColourNameToRGB("indigo")--CATACOMB
1321terrain_color["38"]=ColourNameToRGB("olivedrab")--MIRE
1322terrain_color["39"]=ColourNameToRGB("indigo")--CRYSTAL
1323 -- end of terrain_color
1324end
1325
1326-- -----------------------------------------------------------------
1327-- Plugin Install
1328-- -----------------------------------------------------------------
1329
1330function OnPluginInstall ()
1331
1332 config = {} -- in case not found
1333 setup_terrain_colors()
1334
1335 -- get saved configuration
1336 assert (loadstring (GetVariable ("config") or "")) ()
1337
1338 -- and rooms
1339 --assert (loadstring (GetVariable ("rooms") or "")) ()
1340
1341 -- new stuff for sql data
1342 check_create_db()
1343 load_rooms()
1344
1345 -- initialize mapper
1346
1347 mapper.init { config = config,
1348 get_room = get_room, findpath = findpath,
1349 room_click = room_click, -- called on RH click on room square,
1350 show_help = OnHelp, -- to show help,
1351 show_other_areas = show_other_areas, -- want to see areas other than the current one?
1352}
1353 mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
1354
1355
1356end -- OnPluginInstall
1357
1358function OnHelp (name, line, wildcards)
1359 local help_header = " [Demon Mush Mapper Help] "
1360
1361 local help_index = [[
1362 Mapper Help Index
1363=============================================================================
1364 mapper help --> Show this list
1365-----------------------------------------------------------------------------
1366 mapper help config --> Commands for configuring the mapper
1367 mapper help moving --> Commands for moving between rooms
1368 mapper help utils --> Other utilitarian commands
1369 mapper help searching --> Used for finding notes, shops, guildmasters, etc
1370=============================================================================
1371]]
1372 local help_table = {
1373 ['config'] = {
1374['header'] = [[===== CONFIGURATION =============>]],
1375[[mapper help --> This help
1376 > (or click the "?" button on the top right)]],
1377[[mapper zoom out --> Zoom out]],
1378[[mapper zoom in --> Zoom in]],
1379[[mapper hide --> Hide map]],
1380[[mapper show --> Show map]],
1381[[mapper updown --> Toggle up/down exit drawing]],
1382[[mapper underlines --> Toggle underlining of clickable links]]
1383},
1384
1385 ['utils'] = {
1386['header'] = [[===== UTILITIES =================>]],
1387[[mapper backup --> Creates a backup of the mapper database]],
1388[[mapper addnote --> Add a new note to the current room]],
1389[[mapper addnote <note> --> Ditto, but skips the dialog]]
1390},
1391 ['searching'] = {
1392['header'] = [[===== SEARCHING =================>]],
1393[[mapper find <text> --> Full-text search the whole database]],
1394[[]],
1395[[mapper notes --> Show nearby rooms that you marked with notes]],
1396[[mapper notes <here/area> --> Ditto]],
1397[[mapper shops --> Show all shops/banks]],
1398[[mapper shops <here/area> --> Ditto]],
1399[[mapper train --> Show all trainers]],
1400[[mapper train <here/area> --> Ditto]],
1401[[mapper quest --> Show all quest-givers]],
1402[[mapper quest <here/area> --> Ditto]],
1403[[]],
1404[[mapper next --> Visit the next room in the most recent
1405 > list of results.]],
1406[[mapper next <index> --> Ditto, but skip to the given result index.]],
1407[[mapper where <room id> --> Show directions to a room number]]
1408},
1409
1410
1411 ['moving'] = {
1412['header'] = [[===== MOVING ====================>]],
1413[[mapper goto <room id> --> Run to a room by its room number]]
1414}
1415}
1416
1417 local function show_help(helps)
1418 blackindigoPrint("")
1419 blackindigoPrint(helps['header'])
1420 blackindigoPrint("")
1421 for i,v in ipairs(helps) do
1422 blackindigoPrint(v)
1423 end
1424 end
1425
1426 blackindigoPrint("")
1427 whiteindigoPrint(help_header)
1428 blackindigoPrint("+---------------------------------------------------------------------------+")
1429 badnews = true
1430 if wildcards and wildcards[2] ~= "" then
1431 badnews = false
1432 if wildcards[2] == "all" then
1433 show_help(help_table['config'])
1434 show_help(help_table['exits'])
1435 show_help(help_table['searching'])
1436 show_help(help_table['moving'])
1437 show_help(help_table['utils'])
1438 elseif wildcards[2] == "config" then
1439 show_help(help_table['config'])
1440 elseif wildcards[2] == "searching" then
1441 show_help(help_table['searching'])
1442 elseif wildcards[2] == "moving" then
1443 show_help(help_table['moving'])
1444 elseif wildcards[2] == "utils" then
1445 show_help(help_table['utils'])
1446 elseif wildcards[2]:find("search ") == 1 then
1447 local st, en = wildcards[2]:find("search ")
1448 local pattern = Trim(wildcards[2]:sub(en+1))
1449 ColourTell("cornflower","black","Searching help for: ")
1450 ColourNote("red","black",pattern)
1451 if pattern ~= "" then
1452 for k,v in pairs(help_table) do
1453 local done_header = false
1454 for j,w in ipairs(v) do
1455 if (w ~= "") and (w:find("--------",nil,true) == nil) and (w:find(pattern) ~= nil) then
1456 if not done_header then
1457 blackindigoPrint("")
1458 blackindigoPrint(v['header'])
1459 done_header = true
1460 end
1461 blackindigoPrint("")
1462 local wtable = w:split(pattern)
1463 for i,v in ipairs(wtable) do
1464 ColourTell("cornflower","black",v)
1465 if (i < #wtable) then
1466 ColourTell("red", "black", pattern)
1467 end
1468 end
1469 Note("")
1470 end
1471 end
1472 end
1473 else
1474 badnews = true
1475 end
1476 else
1477 badnews = true
1478 end
1479 end
1480 if badnews then
1481 blackindigoPrint("")
1482 mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
1483 blackindigoPrint("")
1484 blackindigoPrint(help_index)
1485 end
1486 blackindigoPrint("")
1487 blackindigoPrint("+---------------------------------------------------------------------------+")
1488 blackindigoPrint("")
1489end
1490
1491
1492-- -----------------------------------------------------------------
1493-- Plugin Save State
1494-- -----------------------------------------------------------------
1495
1496function OnPluginSaveState ()
1497 mapper.save_state ()
1498 SetVariable ("config", "config = " .. serialize.save_simple (config))
1499 SetVariable("last_backup", last_backup)
1500end -- OnPluginSaveState
1501
1502------------------------------------------
1503-- start of sql additions
1504------------------------------------------
1505function delete_room_alias(name, line, wildcards)
1506 local num = wildcards[1]
1507 if num then
1508 delete_room(num)
1509 end
1510end
1511
1512function delete_area_alias(name, line, wildcards)
1513 local a = wildcards[1]
1514 if a then
1515 delete_area(a)
1516 end
1517end
1518
1519function delete_room(num) -- delete room from rooms
1520 for r, tbl in pairs(rooms) do -- for each room in table
1521 if tostring(r) == tostring(num) then
1522 rooms[r] = nil -- setting table item to nil deletes it
1523 end
1524 end
1525 run_sql([[DELETE FROM rooms WHERE uid = ']]..num..[[']])
1526 Note("Deleted ", num, ".")
1527 SendNoEcho("look")
1528end
1529
1530function delete_area(a)
1531 local cnt = 0
1532 for r, tbl in pairs(rooms) do -- for each room in table
1533 if tostring(tbl.area) == tostring(a) then
1534 rooms[r] = nil -- setting table item to nil deletes it
1535 cnt = cnt + 1
1536 end
1537 end
1538 run_sql([[DELETE FROM rooms WHERE area = ']]..fix_sql(a)..[[']])
1539 Note("Deleted ", cnt, " rooms in '", a, "' area.")
1540end
1541
1542function clean_file_name(f)
1543 f = string.gsub(f, "[^%w]", "")
1544 return f
1545end
1546
1547function fix_sql(s)
1548 if not s then -- nil value
1549 return ""
1550 end
1551 return string.gsub(s, "'", "''")
1552end
1553
1554function run_sql(sql)
1555 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
1556 --Note(sql)
1557 rslt = db:exec(sql)
1558 --Note(rslt)
1559 db:close()
1560end
1561
1562function load_rooms()
1563 rooms = {}
1564sql = [[
1565 UPDATE rooms SET fillcolour = 0 WHERE fillcolour = ''
1566 ]]
1567run_sql(sql)
1568 sql = [[
1569 SELECT * FROM rooms ORDER BY uid ASC;
1570 ]]
1571 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
1572 local cnt = 0
1573 for row in db:nrows(sql) do
1574 cnt = cnt + 1
1575 rooms[row.uid] = {
1576 name = row.name,
1577 desc = row.desc,
1578 area = row.area,
1579 fillcolour = row.fillcolour,
1580 fillbrush = row.fillbrush,
1581 bordercolour = row.bordercolour,
1582 info = row.info,
1583 notes = row.notes,
1584 exits = loadstring("return "..row.exits)()
1585 }
1586 end
1587 Note("Loaded ", cnt, " rooms from database.")
1588 db:close()
1589
1590 if tonumber(last_backup) == 0 then
1591 backup_db()
1592 end
1593end
1594
1595function check_update_room(uid, room)
1596 if not rooms[uid] or (serialize.save_simple(room) ~= serialize.save_simple(rooms[uid])) then
1597 add_update_room(uid, room)
1598 end
1599end
1600
1601function add_update_room(uid, room)
1602 sql = [[
1603 INSERT OR REPLACE INTO rooms (uid, name, desc, area, fillcolour, fillbrush, bordercolour, info, notes, exits)
1604 VALUES
1605 (']]..uid..[[',
1606 ']]..fix_sql(room.name)..[[',
1607 ']]..room.desc..[[',
1608 ']]..fix_sql(room.area)..[[',
1609 ']]..fix_sql(room.fillcolour)..[[',
1610 ']]..fix_sql(room.fillbrush)..[[',
1611 ']]..fix_sql(room.bordercolour)..[[',
1612 ']]..fix_sql(room.info)..[[',
1613 ']]..fix_sql(room.notes)..[[',
1614 ']]..fix_sql(serialize.save_simple(room.exits))..[[')
1615 ]]
1616 run_sql(sql)
1617end
1618
1619function check_create_db()
1620 sql = [[
1621 CREATE TABLE IF NOT EXISTS rooms (
1622 uid TEXT PRIMARY KEY,
1623 name TEXT,
1624 desc TEXT,
1625 area TEXT,
1626 fillcolour INTEGER,
1627 fillbrush INTEGER,
1628 bordercolour INTEGER,
1629 info TEXT,
1630 notes TEXT,
1631 exits TEXT
1632 )
1633 ]]
1634 run_sql(sql)
1635end
1636
1637------------------------------------------
1638-- end of sql additions
1639------------------------------------------
1640
1641------------------------------------------
1642-- backup stuff
1643------------------------------------------
1644-- If you want to do manual backups, make an alias with: script="backup_db"
1645------------------------------------------
1646
1647function backup_db()
1648 Note("Creating database backup.")
1649 local bk_nm = GetInfo(66).."db_backups\\"..clean_file_name(WorldName())..".db."..os.date("%A")
1650 ffi = require("ffi")
1651 ffi.cdef[[
1652 bool CreateDirectoryA(const char *lpPathName, void *lpSecurityAttributes);
1653 bool CopyFileA(const char* lpExistingFileName, const char * lpNewFileName, bool bFailIfExists);
1654 unsigned long GetLastError(void);
1655 ]]
1656
1657 succ = ffi.C.CreateDirectoryA(GetInfo(66).."db_backups\\", nil)
1658 err_no = ffi.C.GetLastError()
1659 if err_no and err_no ~= 183 and err_no ~= 127 then
1660 Note("Error creating directory: ", err_no)
1661 end
1662
1663 succ = ffi.C.CopyFileA(GetInfo(66)..clean_file_name(WorldName())..".db", bk_nm, false)
1664
1665 Note("Backup created: ", bk_nm)
1666 last_backup = os.time()
1667end
1668
1669------------------------------------------
1670-- end backup stuff
1671------------------------------------------
1672
1673-- Special thanks to Fiendish, Endymion, Valour, and Nick Gammon for all of their assistance with the mapper, and the original basis from which its built.
1674
1675]]>
1676</script>
1677
1678
1679</muclient>