changeset 1670:3a089138b01c

Updates and improvements to the example tfrc.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 01 Mar 2024 12:51:33 +0200
parents 97df3a9b3d45
children b0c58647c169
files example-tfrc.txt
diffstat 1 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/example-tfrc.txt	Mon Feb 12 11:54:44 2024 +0200
+++ b/example-tfrc.txt	Fri Mar 01 12:51:33 2024 +0200
@@ -7,6 +7,7 @@
 ;; Add some worlds
 /test addworld("bat", "lp.*", "bat.org", 23, "myname", "password")
 
+
 ;; Set player character name before loading scripts.
 ;; You need to set this to your character name, for example "Ggr"
 /eval /set set_plrname=Mycharname
@@ -19,13 +20,18 @@
 /eval /set set_saveprefix=bat-
 
 
+;; Define a helper macro to load modules from under user home directory
+;; $HOME/ggrtf/ -- adjust this as necessary
+/def -i gloadmod = /eval /load %{HOME}/tf/%{*}
+
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Character set / locale
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; You MAY need to set your character set encoding/locale to have
 ;; non-ASCII characters work properly in BatMUD. This is outside of
 ;; the scope of GgrTF, but it is discussed in more depth in the
-;; user's manual.
+;; user manual.
 
 ;; This setting needs to match an installed locale for *NIX style systems.
 ;/setenv LANG=en_US.iso88591
@@ -38,11 +44,8 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Load GgrTF
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; We define a helper macro to load modules from
-;; under user's home directory $HOME/ggrtf/
-/def -i gloadmod = /eval /load %{HOME}/ggrtf/%{*}
 
-;; Preloader module MUST be loaded first
+;; The preloader module MUST be loaded first
 /gloadmod ggrtf-pre.tf
 
 ;; And the main module after that ...
@@ -79,14 +82,40 @@
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Re-start logging (examples below, uncomment one)
+;; (Re-)start logging
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Log to tiny.log in CWD (current working directory)
-; /log on
+;; Function that returns log filename without directory path
+;; Example returns: "YYYY-MM-DD-worldname-charname.log"
+/def -i prget_log_filename =\
+	/return strcat(ftime("%Y-%m-%d"), "-", fg_world, "-", tolower(set_plrname), ".log")
+
+
+;; Start logging to a file
+/def -i prlogfile_start =\
+	/set logfile_enabled=1%;\
+	/set logfile_prevtime=$[time()]%;\
+	/set set_logfile=$[strcat(set_logdir, prget_log_filename())]%;\
+	/eval /log %{set_logfile}
+
 
-;; Log to tiny.log in user's home directory
-; /eval /log %{HOME}/tiny.log
+;; On world connection establish, begin logging
+/def -i -F -p9999 -hCONNECT ghook_log_start =\
+	/log OFF%;\
+	/prlogfile_start
+
+;; On world disconnect, stop logging
+/def -i -F -p9999 -hDISCONNECT ghook_log_stop =\
+	/set logfile_enabled=0%;\
+	/log OFF
 
-;; Log to tiny-YYYY-MM-DD.log in user's home directory
-; /eval /log %{HOME}/tiny-$[ftime("%Y-%m-%d")].log
+;; On date change, restart logging
+/def -i glogfile_check_date =\
+	/if (logfile_enabled & ftime("%Y-%m-%d", logfile_prevtime) !~ ftime("%Y-%m-%d"))\
+		/msq Day changed, switching logfile ...%;\
+		/log OFF%;\
+		/prlogfile_start%;\
+	/endif%;\
+	/set logfile_prevtime=$[time()]
 
+/eval /if (!logfile_timer) /repeat -1 i /glogfile_check_date%;/endif
+/set logfile_timer=1