/** * Any variables with latched values will be updated. */ public static void GetLatchedVars() { cvar_t var; for (var = Globals.cvar_vars; var != null; var = var.next) { if (var.latched_string == null || var.latched_string.Length == 0) { continue; } var.@string = var.latched_string; var.latched_string = null; var.value = Lib.atof(var.@string); if (var.name.Equals("game")) { FS.SetGamedir(var.@string); FS.ExecAutoexec(); } } }
/** Prints out messages, which can also be redirected to a remote client. */ public static void Printf(string fmt, params object[] vargs) { var msg = Com.sprintf(Com._debugContext + fmt, vargs); if (Com.rd_target != 0) { if (msg.Length + Com.rd_buffer.Length > Com.rd_buffersize - 1) { Com.rd_flusher(Com.rd_target, Com.rd_buffer); Com.rd_buffer.Length = 0; } Com.rd_buffer.Append(msg); return; } Console.Print(msg); // also echo to debugging console Sys.ConsoleOutput(msg); // logfile if (Globals.logfile_active != null && Globals.logfile_active.value != 0) { string name; if (Globals.logfile == null) { name = FS.Gamedir() + "/qconsole.log"; if (Globals.logfile_active.value > 2) { try { Globals.logfile = File.AppendText(name); } catch (Exception e) { System.Console.WriteLine(e); } } else { try { Globals.logfile = File.CreateText(name); } catch (Exception e1) { System.Console.WriteLine(e1); } } } if (Globals.logfile != null) { try { Globals.logfile.Write(msg); } catch (Exception e) { System.Console.WriteLine(e); } } // fflush (logfile); // force it to save every time } }
/** * Gereric set function, sets the value of the variable, with forcing its even possible to * override the variables write protection. */ private static cvar_t Set2(string var_name, string value, bool force) { var var = Cvar.FindVar(var_name); if (var == null) { // create it return(Cvar.Get(var_name, value, 0)); } if ((var.flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0) { if (!Cvar.InfoValidate(value)) { Com.Printf("invalid info cvar value\n"); return(var); } } if (!force) { if ((var.flags & Defines.CVAR_NOSET) != 0) { Com.Printf(var_name + " is write protected.\n"); return(var); } if ((var.flags & Defines.CVAR_LATCH) != 0) { if (var.latched_string != null) { if (value.Equals(var.latched_string)) { return(var); } var.latched_string = null; } else { if (value.Equals(var.@string)) { return(var); } } if (Globals.server_state != 0) { Com.Printf(var_name + " will be changed for next game.\n"); var.latched_string = value; } else { var.@string = value; var.value = Lib.atof(var.@string); if (var.name.Equals("game")) { FS.SetGamedir(var.@string); FS.ExecAutoexec(); } } return(var); } } else { if (var.latched_string != null) { var.latched_string = null; } } if (value.Equals(var.@string)) { return(var); // not changed } var.modified = true; if ((var.flags & Defines.CVAR_USERINFO) != 0) { Globals.userinfo_modified = true; // transmit at next oportunity } var.@string = value; try { var.value = float.Parse(var.@string, CultureInfo.InvariantCulture); } catch (Exception) { var.value = 0.0f; } return(var); }
/** * This function initializes the different subsystems of * the game engine. The setjmp/longjmp mechanism of the original * was replaced with exceptions. * @param args the original unmodified command line arguments */ public static void Init(string[] args) { try { // prepare enough of the subsystems to handle // cvar and command buffer management Com.InitArgv(args); Cbuf.Init(); Cmd.Init(); Cvar.Init(); Key.Init(); // we need to add the early commands twice, because // a basedir or cddir needs to be set before execing // config files, but we want other parms to override // the settings of the config files Cbuf.AddEarlyCommands(false); Cbuf.Execute(); if (Globals.dedicated.value != 1.0f) { Console.WriteLine("initializing filesystem..."); } FS.InitFilesystem(); if (Globals.dedicated.value != 1.0f) { Console.WriteLine("loading config..."); } Qcommon.reconfigure(false); FS.markBaseSearchPaths(); // mark the default search paths Qcommon.reconfigure(true); // reload default.cfg and config.cfg // // init commands and vars // Cmd.AddCommand("error", Com.Error_f); Globals.host_speeds = Cvar.Get("host_speeds", "0", 0); Globals.log_stats = Cvar.Get("log_stats", "0", 0); Globals.developer = Cvar.Get("developer", "0", Defines.CVAR_ARCHIVE); Globals.timescale = Cvar.Get("timescale", "0", 0); Globals.fixedtime = Cvar.Get("fixedtime", "0", 0); Globals.logfile_active = Cvar.Get("logfile", "0", 0); Globals.showtrace = Cvar.Get("showtrace", "0", 0); Globals.dedicated = Cvar.Get("dedicated", "0", Defines.CVAR_NOSET); var s = Com.sprintf("%4.2f %s %s %s", Globals.VERSION, Qcommon.CPUSTRING, Globals.__DATE__, Qcommon.BUILDSTRING); Cvar.Get("version", s, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET); if (Globals.dedicated.value != 1.0f) { Console.WriteLine("initializing network subsystem..."); } NET.Init(); //ok Netchan.Netchan_Init(); //ok if (Globals.dedicated.value != 1.0f) { Console.WriteLine("initializing server subsystem..."); } SV_MAIN.SV_Init(); //ok if (Globals.dedicated.value != 1.0f) { Console.WriteLine("initializing client subsystem..."); } Cl.Init(); // add + commands from command line if (!Cbuf.AddLateCommands()) { // if the user didn't give any commands, run default action if (Globals.dedicated.value == 0) { Cbuf.AddText("d1\n"); } else { Cbuf.AddText("dedicated_start\n"); } Cbuf.Execute(); } else { // the user asked for something explicit // so drop the loading plaque SCR.EndLoadingPlaque(); } Com.Printf("====== Quake2 Initialized ======\n\n"); // save config when configuration is completed Cl.WriteConfiguration(); } catch (Exception) { Sys.Error("Error during initialization"); } }