public static void Init(quakeparms_t parms) { _Params = parms; Cache.Init(1024 * 1024 * 16); // debug Cbuf.Init(); Cmd.Init(); View.Init(); Chase.Init(); InitVCR(parms); Common.Init(parms.basedir, parms.argv); InitLocal(); Wad.LoadWadFile("gfx.wad"); Key.Init(); Con.Init(); Menu.Init(); Progs.Init(); Mod.Init(); Net.Init(); Server.Init(); //Con.Print("Exe: "__TIME__" "__DATE__"\n"); //Con.Print("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0)); Render.InitTextures(); // needed even for dedicated servers if (Client.cls.state != cactive_t.ca_dedicated) { _BasePal = Common.LoadFile("gfx/palette.lmp"); if (_BasePal == null) { Sys.Error("Couldn't load gfx/palette.lmp"); } _ColorMap = Common.LoadFile("gfx/colormap.lmp"); if (_ColorMap == null) { Sys.Error("Couldn't load gfx/colormap.lmp"); } // on non win32, mouse comes before video for security reasons Input.Init(); Vid.Init(_BasePal); Drawer.Init(); Scr.Init(); Render.Init(); Sound.Init(); CDAudio.Init(); Sbar.Init(); Client.Init(); } Cbuf.InsertText("exec quake.rc\n"); _IsInitialized = true; Con.DPrint("========Quake Initialized=========\n"); }
/// <summary> /// Cmd_StuffCmds_f /// Adds command line parameters as script statements /// Commands lead with a +, and continue until a - or another + /// quake +prog jctest.qp +cmd amlev1 /// quake -nosound +cmd amlev1 /// </summary> static void StuffCmds_f() { if (_Argc != 1) { Con.Print("stuffcmds : execute command line parameters\n"); return; } // build the combined string to parse from StringBuilder sb = new StringBuilder(1024); for (int i = 1; i < _Argc; i++) { if (!String.IsNullOrEmpty(_Argv[i])) { sb.Append(_Argv[i]); if (i + 1 < _Argc) { sb.Append(" "); } } } // pull out the commands string text = sb.ToString(); sb.Length = 0; for (int i = 0; i < text.Length; i++) { if (text[i] == '+') { i++; int j = i; while ((j < text.Length) && (text[j] != '+') && (text[j] != '-')) { j++; } sb.Append(text.Substring(i, j - i + 1)); sb.AppendLine(); i = j - 1; } } if (sb.Length > 0) { Cbuf.InsertText(sb.ToString()); } }
// Cmd_Exec_f static void Exec_f() { if (_Argc != 2) { Con.Print("exec <filename> : execute a script file\n"); return; } byte[] bytes = Common.LoadFile(_Argv[1]); if (bytes == null) { Con.Print("couldn't exec {0}\n", _Argv[1]); return; } string script = Encoding.ASCII.GetString(bytes); Con.Print("execing {0}\n", _Argv[1]); Cbuf.InsertText(script); }
/// <summary> /// CL_NextDemo /// /// Called to play the next demo in the demo loop /// </summary> public static void NextDemo() { if (cls.demonum == -1) { return; // don't play demos } Scr.BeginLoadingPlaque(); if (String.IsNullOrEmpty(cls.demos[cls.demonum]) || cls.demonum == MAX_DEMOS) { cls.demonum = 0; if (String.IsNullOrEmpty(cls.demos[cls.demonum])) { Con.Print("No demos listed with startdemos\n"); cls.demonum = -1; return; } } Cbuf.InsertText(String.Format("playdemo {0}\n", cls.demos[cls.demonum])); cls.demonum++; }
// void Cmd_ExecuteString (char *text, cmd_source_t src); // Parses a single line of text into arguments and tries to execute it. // The text can come from the command buffer, a remote client, or stdin. // // A complete command line has been parsed, so try to execute it // FIXME: lookupnoadd the token to speed search? public static void ExecuteString(string text, cmd_source_t src) { _Source = src; TokenizeString(text); // execute the command line if (_Argc <= 0) { return; // no tokens } // check functions xcommand_t handler = Find(_Argv[0]); // must search with comparison like Q_strcasecmp() if (handler != null) { handler(); } else { // check alias string alias = FindAlias(_Argv[0]); // must search with compare func like Q_strcasecmp if (!String.IsNullOrEmpty(alias)) { Cbuf.InsertText(alias); } else { // check cvars if (!Cvar.Command()) { Con.Print("Unknown command \"{0}\"\n", _Argv[0]); } } } }
/// <summary> /// SV_ReadClientMessage /// Returns false if the client should be killed /// </summary> static bool ReadClientMessage() { while (true) { int ret = Net.GetMessage(Host.HostClient.netconnection); if (ret == -1) { Con.DPrint("SV_ReadClientMessage: NET_GetMessage failed\n"); return(false); } if (ret == 0) { return(true); } Net.Reader.Reset(); bool flag = true; while (flag) { if (!Host.HostClient.active) { return(false); // a command caused an error } if (Net.Reader.IsBadRead) { Con.DPrint("SV_ReadClientMessage: badread\n"); return(false); } int cmd = Net.Reader.ReadChar(); switch (cmd) { case -1: flag = false; // end of message ret = 1; break; case Protocol.clc_nop: break; case Protocol.clc_stringcmd: string s = Net.Reader.ReadString(); if (Host.HostClient.privileged) { ret = 2; } else { ret = 0; } if (Common.SameText(s, "status", 6)) { ret = 1; } else if (Common.SameText(s, "god", 3)) { ret = 1; } else if (Common.SameText(s, "notarget", 8)) { ret = 1; } else if (Common.SameText(s, "fly", 3)) { ret = 1; } else if (Common.SameText(s, "name", 4)) { ret = 1; } else if (Common.SameText(s, "noclip", 6)) { ret = 1; } else if (Common.SameText(s, "say", 3)) { ret = 1; } else if (Common.SameText(s, "say_team", 8)) { ret = 1; } else if (Common.SameText(s, "tell", 4)) { ret = 1; } else if (Common.SameText(s, "color", 5)) { ret = 1; } else if (Common.SameText(s, "kill", 4)) { ret = 1; } else if (Common.SameText(s, "pause", 5)) { ret = 1; } else if (Common.SameText(s, "spawn", 5)) { ret = 1; } else if (Common.SameText(s, "begin", 5)) { ret = 1; } else if (Common.SameText(s, "prespawn", 8)) { ret = 1; } else if (Common.SameText(s, "kick", 4)) { ret = 1; } else if (Common.SameText(s, "ping", 4)) { ret = 1; } else if (Common.SameText(s, "give", 4)) { ret = 1; } else if (Common.SameText(s, "ban", 3)) { ret = 1; } if (ret == 2) { Cbuf.InsertText(s); } else if (ret == 1) { Cmd.ExecuteString(s, cmd_source_t.src_client); } else { Con.DPrint("{0} tried to {1}\n", Host.HostClient.name, s); } break; case Protocol.clc_disconnect: return(false); case Protocol.clc_move: ReadClientMove(ref Host.HostClient.cmd); break; default: Con.DPrint("SV_ReadClientMessage: unknown command char\n"); return(false); } } if (ret != 1) { break; } } return(true); }