1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/* This file is executed by pike */
string dir;
string log_dir;
string key;
string get_regvalue(string value)
{
string ret;
foreach( ({ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, }), int w)
catch {
if(ret = RegGetValue(w, "SOFTWARE\\Idonex\\Roxen\\1.3", value))
return ret;
};
}
object _roxen;
object roxen()
{
if(!_roxen)
_roxen = all_constants()["roxen"];
return _roxen;
}
void write_status_file()
{
call_out(write_status_file, 30);
object fd = Stdio.File();
if(fd->open(log_dir+"\\status", "wct"))
{
fd->write(roxen()->config_url()+"\r\n");
foreach(roxen()->configurations, object c)
fd->write(c->query_name()+"\r\n"+
c->query("MyWorldLocation")+"\r\n");
fd->close();
} else
werror("Failed to open status file.\n");
}
function mw;
void my_werror(string fmt, mixed ... args)
{
if(sizeof(args))
mw(sprintf(fmt, @args));
else
mw(fmt);
}
void read_from_stdin()
{
while(!file_stat(log_dir + "\\" + key)) sleep(2);
rm(log_dir + "\\" + key);
exit(0);
}
int main(int argc, array (string) argv)
{
int redirect = 1; // Default is to redirect stdout with friends.
/* Syntax: ntroxenloader.pike <roxen-directory> <roxen loader options> */
if(argc > 1 && argv[1][0]=='+')
{
key = argv[1][1..];
argv = argv[1..];
argc--;
}
if(argc > 1 && argv[1] == "-verbose")
{
redirect = 0;
argv = argv[1..];
argc--;
}
dir = get_regvalue("installation_directory");
if(!dir)
{
werror("Failed to get registry entry for installation directory.\n"
"Aborting.\n");
exit(0);
}
log_dir = get_regvalue("log_directory");
if(!log_dir) log_dir = dir + "\\logs";
dir += "\\server\\";
dir = replace(dir, "\\\\", "\\");
if(!cd(dir))
{
werror("Failed to cd to "+dir+"\n");
exit(0);
}
add_module_path( dir+"etc\\modules" );
add_include_path( dir+"etc\\include" );
add_include_path( dir+"base_server" );
add_program_path( dir+"base_server" );
add_include_path( dir );
add_program_path( dir );
object fd = Stdio.File();
mkdir(log_dir);
if(redirect)
{
mkdir(log_dir+"\\debug");
for(int i=10;i>0;i--)
mv(log_dir+"\\debug\\default."+i, log_dir+"\\debug\\default."+(i+1));
if(fd->open(log_dir+"\\debug\\default.1", "wct"))
{
fd->dup2( Stdio.stderr );
fd->dup2( Stdio.stdout );
mw = fd->write;
add_constant("werror", my_werror);
add_constant("write", my_werror);
} else {
werror("Failed to do redirection\n");
}
}
function rget=
lambda(string ent) {
string res ;
catch(res=RegGetValue(HKEY_CURRENT_USER,"SOFTWARE\\Idonex\\Pike\\0.6",ent));
if(res) return res;
catch(res=RegGetValue(HKEY_LOCAL_MACHINE,"SOFTWARE\\Idonex\\Pike\\0.6",ent));
if(res) return res;
return "<undefined>";
};
werror("Primary bootstrap complete.\n"
" Pike master file : "+rget("PIKE_MASTER")+"\n"
" Pike share directory : "+rget("share_prefix")+"\n"
" Pike arch directory : "+rget("lib_prefix")+"\n"
" Roxen base directory : "+dir+"\n"
" Roxen configurations : "+dir+"\\configurations\n"
" Roxen status file : "+log_dir+"\\status\n"
" Roxen shutdown file : "+(key?log_dir+"\\"+key:"None")+"\n"
" Roxen log directory : "+log_dir+"\n"
" Roxen arguments : "+(sizeof(argv)>2?argv[1..]*" ":"None")+"\n"
#if constant(_Crypto) && constant(Crypto)
" This version of roxen has crypto algorithms available\n"
#endif
"\n");
werror("Compiling second level bootstrap ["
+dir+"base_server\\roxenloader.pike]\n");
call_out(write_status_file, 1);
if(key) thread_create(read_from_stdin);
return ((program)(dir+"base_server\\roxenloader.pike"))()
->main(argc, argv);
}
|