1#!/usr/bin/env swipl
    2/* * module  MUD server startup script in SWI-Prolog
    3
    4?- 
    5 consult(library(prologmud_sample_games/run_mud_server)).
    6
    7
    8*/
    9% ==============================================
   10% INIT LOCAL DIR
   11% ==============================================
   12
   13:- '$set_typein_module'(baseKB).   14:- '$set_source_module'(baseKB).   15
   16:- set_prolog_flag(lm_no_autoload,false).   17:- set_prolog_flag(lm_pfc_lean,false).   18
   19:- prolog_load_context(directory,D),cd(D).   20
   21%:- if(current_prolog_flag(argv,[])).
   22:- if(\+ ((current_prolog_flag(argv,X),member(E,X),atom_concat('--',_,E)))).   23:- current_prolog_flag('argv',WasArgV),
   24   set_prolog_flag('argv',['-l','run_mud_server.pl',
   25   '--all','--pdt','--world','--repl','--lisp','--lispsock','--sumo',
   26   '--planner','--cliop','--sigma','--www',
   27   '--irc','--swish','--docs','--plweb',
   28   '--elfinder',
   29   '--defaults'|WasArgV]).   30:- current_prolog_flag('argv',Is),writeq(set_prolog_flag('argv',Is)),!,nl.   31:- endif.   32%:- endif.
   33
   34/*
   35:- set_prolog_flag(stack_limit, 32 000 000 000).
   36:- set_prolog_stack(global, limit(32*10**9)).
   37:- set_prolog_stack(local, limit(32*10**9)).
   38:- set_prolog_stack(trail, limit(32*10**9)).
   39*/
   40
   41
   42% ==============================================
   43% Enable History
   44% ==============================================
   45:- if(\+ current_predicate(setup_hist0/0)).   46:- if(exists_source(library(editline))). 
   47:- if(\+ current_prolog_flag(windows,true)).   48:- use_module(library(editline)).   49:- endif.   50:- else.   51:- if(exists_source(library(readline))).   52:- use_module(library(readline)).   53:- endif.   54:- endif.   55setup_hist0:-  '$toplevel':setup_history.
   56:- setup_hist0.   57:- endif.   58   
   59% ==============================================
   60% Add Pack Directories
   61% ==============================================
   62:- use_module(library(prolog_pack)).   63:- multifile(user:file_search_path/2).   64:-   dynamic(user:file_search_path/2).   65
   66dir_from0(Rel,Y):-
   67    ((getenv('LOGICMOO_WS',Dir);
   68      prolog_load_context(directory,Dir);
   69      'w:/opt/logicmoo_workspace/'=Dir;      
   70      '~/logicmoo_workspace'=Dir;
   71      '/opt/logicmoo_workspace/'=Dir;
   72      fail)),
   73    absolute_file_name(Rel,Y,[relative_to(Dir),file_type(directory),file_errors(fail)]),
   74    exists_directory(Y),!.
   75
   76add_pack_path0(packs_sys):-pack_property(pfc,_),!.
   77add_pack_path0(Rel):- 
   78   dir_from0(Rel,Y),
   79   (( \+ user:file_search_path(pack,Y)) ->asserta(user:file_search_path(pack,Y));true).
   80
   81:- if( \+ exists_source(library(logicmoo_common))).   82:- add_pack_path0(packs_sys).   83:- endif.   84
   85:- if( \+ exists_source(library(logicmoo_hyhtn))).   86:- add_pack_path0(packs_xtra).   87:- endif.   88
   89:- add_pack_path0(packs_usr).   90:- add_pack_path0(packs_web).   91:- add_pack_path0(packs_xtra).   92:- add_pack_path0(packs_lib).   93:- initialization(attach_packs,now).   94
   95update_packs:- !.
   96update_packs:-    
   97   use_module(library(prolog_pack)),
   98   (pack_property(prologmud_samples,version(Version));
   99    pack_property(pfc,version(Version))),!,
  100   use_module(library(git)),
  101   forall(
  102   (pack_property(Pack,version(Version)), pack_property(Pack,directory(Dir)),
  103      directory_file_path(Dir, '.git', GitDir),
  104      %(exists_file(GitDir);exists_directory(GitDir)),
  105       access_file(GitDir,read),
  106       access_file(GitDir,write)),
  107     ( print_message(informational, pack(git_fetch(Dir))),
  108     git([fetch], [ directory(Dir) ]),
  109     git_describe(V0, [ directory(Dir) ]),
  110     git_describe(V1, [ directory(Dir), commit('origin/master') ]),
  111     (   V0 == V1
  112     ->  print_message(informational, pack(up_to_date(Pack)))
  113     ;   true,
  114         git([merge, 'origin/master'], [ directory(Dir) ]),
  115         pack_rebuild(Pack)
  116     ))),
  117   initialization(attach_packs,now).
  118
  119:- update_packs.  120
  121:- pack_list_installed.  122
  123
  124% ==============================================
  125% SETUP KB EXTENSIONS
  126% ==============================================
  127
  128:- use_module(library(logicmoo_utils_all)).  129
  130%:- setenv('DISPLAY', '').
  131:- use_module(library(plunit)).  132:- kb_global(plunit:loading_unit/4).  133
  134
  135% ==============================================
  136% [Required] Load the Logicmoo User System
  137% ==============================================
  138:- user:load_library_system(library(logicmoo_lib)).  139
  140
  141% ==============================================
  142% ============= MUD SERVER CODE LOADING =============
  143% ==============================================
  144
  145:- if(\+ exists_source(prologmud(mud_loader))).  146:- must((absolute_file_name(pack('prologmud/prolog/prologmud'),Dir),asserta(user:file_search_path(prologmud,Dir)))).  147:- sanity(exists_source(prologmud(mud_loader))).  148:- endif.  149
  150:- if( \+ app_argv('--noworld')).  151:- baseKB:ensure_loaded(prologmud(mud_loader)).  152:- endif.  153
  154% ==============================================
  155% ============= MUD SERVER CODE LOADED =============
  156% ==============================================
  157
  158:- with_mpred_trace_exec(ain(isLoaded(iSourceCode7))).  159
  160:- flag_call(runtime_debug=true).  161
  162:- if((gethostname(ubuntu),fail)). % INFO this fail is so we can start faster
  163:- show_entry(gripe_time(40, doall(baseKB:regression_test))).  164:- endif.  165
  166
  167% ==============================================
  168% [Optional] Creates or suppliments a world
  169% ==============================================
  170
  171:- if( \+ user:file_search_path(sample_games,_Dir)).  172:- must((absolute_file_name(pack('prologmud_samples/prolog/prologmud_sample_games'),Dir),asserta(user:file_search_path(sample_games,Dir)))).  173:- sanity(user:file_search_path(sample_games,_Dir)).  174:- endif.  175
  176:- dynamic(lmconf:eachRule_Preconditional/1).  177:- dynamic(lmconf:eachFact_Preconditional/1).  178:- assert_setting01(lmconf:eachRule_Preconditional(true)).  179:- assert_setting01(lmconf:eachFact_Preconditional(true)).  180
  181:- if(functorDeclares(mobExplorer)).  182
  183:- sanity(functorDeclares(tSourceData)).  184:- sanity(functorDeclares(mobExplorer)).  185
  186
  187==>((tCol(tLivingRoom),
  188 tSet(tRegion),
  189 tSet(tLivingRoom),
  190
  191 tSet(mobExplorer),
  192 genls(tLivingRoom,tRegion),
  193 genls(tOfficeRoom,tRegion),
  194
  195
  196genlsFwd(tLivingRoom,tRegion),
  197genlsFwd(tOfficeRoom,tRegion),
  198
  199% create some seats
  200mobExplorer(iExplorer1),
  201mobExplorer(iExplorer2),
  202mobExplorer(iExplorer3),
  203mobExplorer(iExplorer4),
  204mobExplorer(iExplorer5),
  205mobExplorer(iExplorer6),
  206
  207(tHumanBody(skRelationAllExistsFn)==>{trace_or_throw(tHumanBody(skRelationAllExistsFn))}),
  208
  209genls(mobExplorer,tHominid))).
  210
  211:- endif.  212
  213
  214% ==============================================
  215% [Required] isRuntime Hook
  216% ==============================================
  217(((localityOfObject(P,_),isRuntime)==>{if_defined(put_in_world(P))})).
  218%:- user:use_module(library('file_scope')).
  219:- set_prolog_flag_until_eof(do_renames,term_expansion).  220
  221
  222
  223% ==============================================
  224% [Optional] Creates or suppliments a world
  225% ==============================================
  226:- if( \+ app_argv('--noworld')).  227:- if( \+ tRegion(_)).  228
  229==> prologHybrid(mudAreaConnected(tRegion,tRegion),rtSymmetricBinaryPredicate).
  230==> rtArgsVerbatum(mudAreaConnected).
  231
  232==>((
  233tRegion(iLivingRoom7),
  234tRegion(iOfficeRoom7),
  235
  236mobExplorer(iExplorer7),
  237wearsClothing(iExplorer7,'iBoots773'),
  238wearsClothing(iExplorer7,'iCommBadge774'),
  239wearsClothing(iExplorer7,'iGoldUniform775'),
  240mudStowing(iExplorer7,'iPhaser776'))).
  241
  242:- kb_shared(baseKB:tCol/1).  243:- kb_shared(baseKB:ttCoercable/1).  244% :- add_import_module(mpred_type_isa,baseKB,end).
  245onSpawn(localityOfObject(iExplorer7,tLivingRoom)).
  246
  247==>((
  248pddlSomethingIsa('iBoots773',['tBoots','ProtectiveAttire','PortableObject','tWearAble']),
  249pddlSomethingIsa('iCommBadge774',['tCommBadge','ProtectiveAttire','PortableObject','tNecklace']),
  250pddlSomethingIsa('iGoldUniform775',['tGoldUniform','ProtectiveAttire','PortableObject','tWearAble']),
  251pddlSomethingIsa('iPhaser776',['tPhaser','Handgun',tWeapon,'LightingDevice','PortableObject','Device-SingleUser','tWearAble']),
  252
  253mobMonster(iCommanderdata66),
  254mobExplorer(iCommanderdata66),
  255mudDescription(iCommanderdata66,txtFormatFn("Very scary looking monster named ~w",[iCommanderdata66])),
  256tAgent(iCommanderdata66),
  257tHominid(iCommanderdata66),
  258wearsClothing(iCommanderdata66,'iBoots673'),
  259wearsClothing(iCommanderdata66,'iCommBadge674'),
  260wearsClothing(iCommanderdata66,'iGoldUniform675'),
  261mudStowing(iCommanderdata66,'iPhaser676'),
  262
  263pddlSomethingIsa('iBoots673',['tBoots','ProtectiveAttire','PortableObject','tWearAble']),
  264pddlSomethingIsa('iCommBadge674',['tCommBadge','ProtectiveAttire','PortableObject','tNecklace']),
  265pddlSomethingIsa('iGoldUniform675',['tGoldUniform','ProtectiveAttire','PortableObject','tWearAble']),
  266pddlSomethingIsa('iPhaser676',['tPhaser','Handgun',tWeapon,'LightingDevice','PortableObject','Device-SingleUser','tWearAble']))).
  267
  268
  269onSpawn(localityOfObject(iCommanderdata66,tOfficeRoom)).
  270onSpawn(mudAreaConnected(tLivingRoom,tOfficeRoom)).
  271:- endif.  272:- endif.  273
  274:- if( \+ is_startup_script(_) ).  275:- init_why("run_mud_server").  276:- endif.  277
  278
  279:- set_prolog_flag(access_level,system).  280:- debug.  281
  282
  283
  284% ==============================================
  285% [Optionaly] Start the telent server % iCommanderdata66
  286% ==============================================
  287:- if( \+ app_argv('--nonet')).  288
  289start_telnet:- 
  290   user:ensure_loaded(init_mud_server),
  291  on_x_log_cont((call(call,start_mud_telnet))).
  292
  293:- after_boot(start_telnet).  294
  295% :- assert_setting01(lmconf:eachFact_Preconditional(isRuntime)).
  296
  297% [Manditory] This loads the game and initializes so test can be ran
  298:- baseKB:ensure_loaded(sample_games('src_game_nani/objs_misc_household.pfc')).  299:- baseKB:ensure_loaded(sample_games('src_game_nani/a_nani_household.pfc')).  300:- endif.  301
  302% isa(starTrek,mtHybrid).
  303%lst :- !.
  304lst :- baseKB:ensure_loaded(sample_games('src_game_startrek/?*.pfc*')).
  305lstr :- forall(registered_mpred_file(F),baseKB:ensure_loaded(F)).
  306
  307% ==============================================
  308% [Optional] the following game files though can be loaded separate instead
  309% ==============================================
  310:- declare_load_dbase(sample_games('src_game_nani/?*.pfc*')).  311
  312% ==============================================
  313% [Optional] the following worlds are in version control in examples
  314% ==============================================
  315% :- add_game_dir(sample_games('src_game_wumpus'),prolog_repl).
  316% :- add_game_dir(sample_games('src_game_sims'),prolog_repl).
  317% :- add_game_dir(sample_games('src_game_nani'),prolog_repl).
  318%:- add_game_dir(sample_games('src_game_startrek'),prolog_repl).
  319:- declare_load_dbase(sample_games('src_game_startrek/?*.pfc*')).  320
  321%:- check_clause_counts.
  322
  323:- sanity(argIsa(genlPreds,2,_)).  324
  325:- after_boot_sanity_test(argIsa(genlPreds,2,_)).  326
  327
  328% ==============================================
  329% Sanity tests
  330% ==============================================
  331:- if( \+ app_argv('--noworld')).  332sanity_test_ifood_rez:- ignore((
  333     user:ensure_loaded(init_mud_server),
  334     % mpred_notrace_exec,
  335     % flag_call(runtime_debug>true),
  336     ain(isa(iFoodRez2,tFood)),must(isa(iFoodRez2,tEatAble)))),
  337    must((call(call,parseIsa_Call(tEatAble,O,["food"],Rest)),O=iFoodRez2,Rest=[])).
  338
  339:- after_boot_sanity_test((dmsg(sanity_test_ifood_rez))).  340
  341
  342:- after_boot_sanity_test((gripe_time(1.0,must(coerce("s",vtDirection,_))))).  343:- after_boot_sanity_test((gripe_time(2.0,must( \+ coerce(l,vtDirection,_))))).  344:- endif.  345:- after_boot_sanity_test((statistics)).  346:- after_boot_sanity_test(check_clause_counts).  347
  348
  349% ==============================================
  350% [Required/Optional]  Ensures...
  351% ==============================================
  352
  353% :- after_boot(set_prolog_flag(runtime_debug,0)).
  354:- during_boot(set_prolog_flag(unsafe_speedups,false)).  355
  356:- if( \+ app_argv('--noworld')).  357:- if(app_argv('--world')).  358:- lst.  359:- endif.  360:- lstr.  361:- endif.  362
  363lar0 :- app_argv('--repl'),!,dmsg("Ctrl-D to start MUD"),prolog,lar.
  364lar0 :- lar.
  365       
  366lar :- % set_prolog_flag(dmsg_level,never),
  367     start_runtime,
  368       if_defined(login_and_run,wdmsg("MUD code not loaded")).
  369
  370
  371%:- after_boot(qsave_lm(lm_init_mud)).
  372%:- after_boot(lar0).
  373
  374:- after_boot((statistics,dmsg("Type lar.<enter> at the '?-' prompt to start the MUD (a shortcut for ?- login_and_run. )"))).  375
  376:- if(gethostname(gitlab)).                                            
  377
  378:- set_prolog_flag(runtime_debug,3).  379:- set_prolog_flag(runtime_safety,3).  380:- set_prolog_flag(runtime_speed,0).  381
  382:- else.  383
  384:- set_prolog_flag(runtime_debug,1).  385:- set_prolog_flag(runtime_safety,1).  386:- set_prolog_flag(runtime_speed,1).  387
  388:- endif.  389
  390:- during_boot(ain(tSourceData(iWorldData8))).  391
  392start_runtime:- 
  393   ain(isLoaded(iWorldData8)),
  394   with_mpred_trace_exec(ain(isRuntime)).
  395
  396:- after_boot(start_runtime).  397
  398%:- setenv('DISPLAY', '').
  399:- add_history(profile(ain(tAgent(foofy)))).  400:- add_history(listing(inRegion)).  401:- add_history(listing(localityOfObject)).  402:- add_history(listing(mudAtLoc)).