public override void Execute( ) { String filename; if (Cmd.Argc() != 2) { Com.Printf("Usage: download <filename>\\n"); return; } filename = Cmd.Argv(1); if (filename.IndexOf("..") != -1) { Com.Printf("Refusing to download a path with ..\\n"); return; } if (FS.LoadFile(filename) != null) { Com.Printf("File already exists.\\n"); return; } Globals.cls.downloadname = filename; Com.Printf("Downloading " + Globals.cls.downloadname + "\\n"); Globals.cls.downloadtempname = Com.StripExtension(Globals.cls.downloadname); Globals.cls.downloadtempname += ".tmp"; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname); Globals.cls.downloadnumber++; }
public static void SV_BroadcastPrintf(Int32 level, String s) { client_t cl; if (Globals.dedicated.value != 0) { Com.Printf(s); } for (var i = 0; i < SV_MAIN.maxclients.value; i++) { cl = SV_INIT.svs.clients[i]; if (level < cl.messagelevel) { continue; } if (cl.state != Defines.cs_spawned) { continue; } MSG.WriteByte(cl.netchan.message, Defines.svc_print); MSG.WriteByte(cl.netchan.message, level); MSG.WriteString(cl.netchan.message, s); } }
public static Int32 SV_FindIndex(String name, Int32 start, Int32 max, Boolean create) { Int32 i; if (name == null || name.Length == 0) { return(0); } for (i = 1; i < max && sv.configstrings[start + i] != null; i++) { if (0 == Lib.Strcmp(sv.configstrings[start + i], name)) { return(i); } } if (!create) { return(0); } if (i == max) { Com.Error(Defines.ERR_DROP, "*Index: overflow"); } sv.configstrings[start + i] = name; if (sv.state != Defines.ss_loading) { SZ.Clear(sv.multicast); MSG.WriteChar(sv.multicast, Defines.svc_configstring); MSG.WriteShort(sv.multicast, start + i); MSG.WriteString(sv.multicast, name); SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R); } return(i); }
public static void SV_FinalMessage(String message, Boolean reconnect) { Int32 i; client_t cl; SZ.Clear(Globals.net_message); MSG.WriteByte(Globals.net_message, Defines.svc_print); MSG.WriteByte(Globals.net_message, Defines.PRINT_HIGH); MSG.WriteString(Globals.net_message, message); if (reconnect) { MSG.WriteByte(Globals.net_message, Defines.svc_reconnect); } else { MSG.WriteByte(Globals.net_message, Defines.svc_disconnect); } for (i = 0; i < SV_INIT.svs.clients.Length; i++) { cl = SV_INIT.svs.clients[i]; if (cl.state >= Defines.cs_connected) { Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data); } } for (i = 0; i < SV_INIT.svs.clients.Length; i++) { cl = SV_INIT.svs.clients[i]; if (cl.state >= Defines.cs_connected) { Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data); } } }
/** * PF_Configstring */ public static void PF_Configstring(int index, string val) { if (index < 0 || index >= Defines.MAX_CONFIGSTRINGS) { Com.Error(Defines.ERR_DROP, "configstring: bad index " + index + "\n"); } if (val == null) { val = ""; } // change the string in sv SV_INIT.sv.configstrings[index] = val; if (SV_INIT.sv.state != Defines.ss_loading) { // send the update to // everyone SZ.Clear(SV_INIT.sv.multicast); MSG.WriteChar(SV_INIT.sv.multicast, Defines.svc_configstring); MSG.WriteShort(SV_INIT.sv.multicast, index); MSG.WriteString(SV_INIT.sv.multicast, val); SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R); } }
public static void SV_ClientPrintf(client_t cl, Int32 level, String s) { if (level < cl.messagelevel) { return; } MSG.WriteByte(cl.netchan.message, Defines.svc_print); MSG.WriteByte(cl.netchan.message, level); MSG.WriteString(cl.netchan.message, s); }
public static void SV_BroadcastCommand(String s) { if (SV_INIT.sv.state == 0) { return; } MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_stufftext); MSG.WriteString(SV_INIT.sv.multicast, s); SV_Multicast(null, Defines.MULTICAST_ALL_R); }
public static void PF_centerprintf(edict_t ent, string fmt) { int n; n = ent.index; if (n < 1 || n > SV_MAIN.maxclients.value) { return; } MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_centerprint); MSG.WriteString(SV_INIT.sv.multicast, fmt); PF_Unicast(ent, true); }
/** * PF_centerprintf * * centerprint to a single client. */ public static void PF_centerprintf(edict_t ent, string fmt) { int n; n = ent.index; if (n < 1 || n > SV_MAIN.maxclients.value) { return; // Com_Error (ERR_DROP, "centerprintf to a non-client"); } MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_centerprint); MSG.WriteString(SV_INIT.sv.multicast, fmt); SV_GAME.PF_Unicast(ent, true); }
public static void SV_FlushRedirect(Int32 sv_redirected, Byte[] outputbuf) { if (sv_redirected == Defines.RD_PACKET) { var s = ("print\\n" + Lib.CtoJava(outputbuf)); Netchan.Netchan_OutOfBand(Defines.NS_SERVER, Globals.net_from, s.Length, Lib.StringToBytes(s)); } else if (sv_redirected == Defines.RD_CLIENT) { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_print); MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.PRINT_HIGH); MSG.WriteString(SV_MAIN.sv_client.netchan.message, outputbuf); } }
public static void SV_Baselines_f( ) { Int32 start; entity_state_t nullstate; entity_state_t base_renamed; Com.DPrintf("Baselines() from " + SV_MAIN.sv_client.name + "\\n"); if (SV_MAIN.sv_client.state != Defines.cs_connected) { Com.Printf("baselines not valid -- already spawned\\n"); return; } if (Lib.Atoi(Cmd.Argv(1)) != SV_INIT.svs.spawncount) { Com.Printf("SV_Baselines_f from different level\\n"); SV_New_f(); return; } start = Lib.Atoi(Cmd.Argv(2)); nullstate = new entity_state_t(null); while (SV_MAIN.sv_client.netchan.message.cursize < Defines.MAX_MSGLEN / 2 && start < Defines.MAX_EDICTS) { base_renamed = SV_INIT.sv.baselines[start]; if (base_renamed.modelindex != 0 || base_renamed.sound != 0 || base_renamed.effects != 0) { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_spawnbaseline); MSG.WriteDeltaEntity(nullstate, base_renamed, SV_MAIN.sv_client.netchan.message, true, true); } start++; } if (start == Defines.MAX_EDICTS) { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext); MSG.WriteString(SV_MAIN.sv_client.netchan.message, "precache " + SV_INIT.svs.spawncount + "\\n"); } else { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext); MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd baselines " + SV_INIT.svs.spawncount + " " + start + "\\n"); } }
public static Boolean CheckOrDownloadFile(String filename) { if (filename.IndexOf("..") != -1) { Com.Printf("Refusing to download a path with ..\\n"); return(true); } if (FS.FileLength(filename) > 0) { return(true); } Globals.cls.downloadname = filename; Globals.cls.downloadtempname = Com.StripExtension(Globals.cls.downloadname); Globals.cls.downloadtempname += ".tmp"; var name = DownloadFileName(Globals.cls.downloadtempname); QuakeFile fp = new QuakeFile(name, FileAccess.ReadWrite); if (fp != null) { Int64 len = 0; try { len = fp.Length; } catch (IOException e) { } Globals.cls.download = fp; Com.Printf("Resuming " + Globals.cls.downloadname + "\\n"); MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname + " " + len); } else { Com.Printf("Downloading " + Globals.cls.downloadname + "\\n"); MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname); } Globals.cls.downloadnumber++; return(false); }
public static void SV_New_f( ) { String gamedir; Int32 playernum; edict_t ent; Com.DPrintf("New() from " + SV_MAIN.sv_client.name + "\\n"); if (SV_MAIN.sv_client.state != Defines.cs_connected) { Com.Printf("New not valid -- already spawned\\n"); return; } if (SV_INIT.sv.state == Defines.ss_demo) { SV_BeginDemoserver(); return; } gamedir = Cvar.VariableString("gamedir"); MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_serverdata); MSG.WriteInt(SV_MAIN.sv_client.netchan.message, Defines.PROTOCOL_VERSION); MSG.WriteLong(SV_MAIN.sv_client.netchan.message, SV_INIT.svs.spawncount); MSG.WriteByte(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.attractloop ? 1 : 0); MSG.WriteString(SV_MAIN.sv_client.netchan.message, gamedir); if (SV_INIT.sv.state == Defines.ss_cinematic || SV_INIT.sv.state == Defines.ss_pic) { playernum = -1; } else { playernum = SV_MAIN.sv_client.serverindex; } MSG.WriteShort(SV_MAIN.sv_client.netchan.message, playernum); MSG.WriteString(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.configstrings[Defines.CS_NAME]); if (SV_INIT.sv.state == Defines.ss_game) { ent = GameBase.g_edicts[playernum + 1]; ent.s.number = playernum + 1; SV_MAIN.sv_client.edict = ent; SV_MAIN.sv_client.lastcmd = new usercmd_t(); MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext); MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd configstrings " + SV_INIT.svs.spawncount + " 0\\n"); } }
public static void SV_Configstrings_f( ) { Int32 start; Com.DPrintf("Configstrings() from " + SV_MAIN.sv_client.name + "\\n"); if (SV_MAIN.sv_client.state != Defines.cs_connected) { Com.Printf("configstrings not valid -- already spawned\\n"); return; } if (Lib.Atoi(Cmd.Argv(1)) != SV_INIT.svs.spawncount) { Com.Printf("SV_Configstrings_f from different level\\n"); SV_New_f(); return; } start = Lib.Atoi(Cmd.Argv(2)); while (SV_MAIN.sv_client.netchan.message.cursize < Defines.MAX_MSGLEN / 2 && start < Defines.MAX_CONFIGSTRINGS) { if (SV_INIT.sv.configstrings[start] != null && SV_INIT.sv.configstrings[start].Length != 0) { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_configstring); MSG.WriteShort(SV_MAIN.sv_client.netchan.message, start); MSG.WriteString(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.configstrings[start]); } start++; } if (start == Defines.MAX_CONFIGSTRINGS) { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext); MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd baselines " + SV_INIT.svs.spawncount + " 0\\n"); } else { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext); MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd configstrings " + SV_INIT.svs.spawncount + " " + start + "\\n"); } }
/** * Used by SV_Shutdown to send a final message to all connected clients * before the server goes down. The messages are sent immediately, not just * stuck on the outgoing message list, because the server is going to * totally exit after returning from this function. */ public static void SV_FinalMessage(string message, bool reconnect) { int i; client_t cl; SZ.Clear(Globals.net_message); MSG.WriteByte(Globals.net_message, Defines.svc_print); MSG.WriteByte(Globals.net_message, Defines.PRINT_HIGH); MSG.WriteString(Globals.net_message, message); if (reconnect) { MSG.WriteByte(Globals.net_message, Defines.svc_reconnect); } else { MSG.WriteByte(Globals.net_message, Defines.svc_disconnect); } // send it twice // stagger the packets to crutch operating system limited buffers for (i = 0; i < SV_INIT.svs.clients.Length; i++) { cl = SV_INIT.svs.clients[i]; if (cl.state >= Defines.cs_connected) { Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data); } } for (i = 0; i < SV_INIT.svs.clients.Length; i++) { cl = SV_INIT.svs.clients[i]; if (cl.state >= Defines.cs_connected) { Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data); } } }
/** * SV_FindIndex. */ public static int SV_FindIndex(string name, int start, int max, bool create) { int i; if (name == null || name.Length == 0) { return(0); } for (i = 1; i < max && SV_INIT.sv.configstrings[start + i] != null; i++) { if (0 == Lib.strcmp(SV_INIT.sv.configstrings[start + i], name)) { return(i); } } if (!create) { return(0); } if (i == max) { Com.Error(Defines.ERR_DROP, "*Index: overflow"); } SV_INIT.sv.configstrings[start + i] = name; if (SV_INIT.sv.state != Defines.ss_loading) { // send the update to everyone SZ.Clear(SV_INIT.sv.multicast); MSG.WriteChar(SV_INIT.sv.multicast, Defines.svc_configstring); MSG.WriteShort(SV_INIT.sv.multicast, start + i); MSG.WriteString(SV_INIT.sv.multicast, name); SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R); } return(i); }
public static void SendCmd() { int i; usercmd_t cmd, oldcmd; int checksumIndex; i = Globals.cls.netchan.outgoing_sequence & (Defines.CMD_BACKUP - 1); cmd = Globals.cl.cmds[i]; Globals.cl.cmd_time[i] = (int)Globals.cls.realtime; CreateCmd(cmd); Globals.cl.cmd.Set(cmd); if (Globals.cls.state == Defines.ca_disconnected || Globals.cls.state == Defines.ca_connecting) { return; } if (Globals.cls.state == Defines.ca_connected) { if (Globals.cls.netchan.message.cursize != 0 || Globals.curtime - Globals.cls.netchan.last_sent > 1000) { Netchan.Transmit(Globals.cls.netchan, 0, new byte[0]); } return; } if (Globals.userinfo_modified) { CL.FixUpGender(); Globals.userinfo_modified = false; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_userinfo); MSG.WriteString(Globals.cls.netchan.message, Cvar.Userinfo()); } SZ.Init(buf, data, data.Length); if (cmd.buttons != 0 && Globals.cl.cinematictime > 0 && !Globals.cl.attractloop && Globals.cls.realtime - Globals.cl.cinematictime > 1000) { SCR.FinishCinematic(); } MSG.WriteByte(buf, Defines.clc_move); checksumIndex = buf.cursize; MSG.WriteByte(buf, 0); if (cl_nodelta.value != 0F || !Globals.cl.frame.valid || Globals.cls.demowaiting) { MSG.WriteLong(buf, -1); } else { MSG.WriteLong(buf, Globals.cl.frame.serverframe); } i = (Globals.cls.netchan.outgoing_sequence - 2) & (Defines.CMD_BACKUP - 1); cmd = Globals.cl.cmds[i]; nullcmd.Clear(); MSG.WriteDeltaUsercmd(buf, nullcmd, cmd); oldcmd = cmd; i = (Globals.cls.netchan.outgoing_sequence - 1) & (Defines.CMD_BACKUP - 1); cmd = Globals.cl.cmds[i]; MSG.WriteDeltaUsercmd(buf, oldcmd, cmd); oldcmd = cmd; i = (Globals.cls.netchan.outgoing_sequence) & (Defines.CMD_BACKUP - 1); cmd = Globals.cl.cmds[i]; MSG.WriteDeltaUsercmd(buf, oldcmd, cmd); buf.data[checksumIndex] = Com.BlockSequenceCRCByte(buf.data, checksumIndex + 1, buf.cursize - checksumIndex - 1, Globals.cls.netchan.outgoing_sequence); Netchan.Transmit(Globals.cls.netchan, buf.cursize, buf.data); }
public static void PF_WriteString(string s) { MSG.WriteString(SV_INIT.sv.multicast, s); }
public static void SV_ServerRecord_f( ) { String name; Byte[] buf_data = new Byte[32768]; sizebuf_t buf = new sizebuf_t(); Int32 len; Int32 i; if (Cmd.Argc() != 2) { Com.Printf("serverrecord <demoname>\\n"); return; } if (SV_INIT.svs.demofile != null) { Com.Printf("Already recording.\\n"); return; } if (SV_INIT.sv.state != Defines.ss_game) { Com.Printf("You must be in a level to record.\\n"); return; } name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2"; Com.Printf("recording to " + name + ".\\n"); FS.CreatePath(name); try { SV_INIT.svs.demofile = new QuakeFile(name, FileAccess.ReadWrite); } catch (Exception e) { Com.Printf("ERROR: couldn't open.\\n"); return; } SZ.Init(SV_INIT.svs.demo_multicast, SV_INIT.svs.demo_multicast_buf, SV_INIT.svs.demo_multicast_buf.Length); SZ.Init(buf, buf_data, buf_data.Length); MSG.WriteByte(buf, Defines.svc_serverdata); MSG.WriteLong(buf, Defines.PROTOCOL_VERSION); MSG.WriteLong(buf, SV_INIT.svs.spawncount); MSG.WriteByte(buf, 2); MSG.WriteString(buf, Cvar.VariableString("gamedir")); MSG.WriteShort(buf, -1); MSG.WriteString(buf, SV_INIT.sv.configstrings[Defines.CS_NAME]); for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++) { if (SV_INIT.sv.configstrings[i].Length == 0) { MSG.WriteByte(buf, Defines.svc_configstring); MSG.WriteShort(buf, i); MSG.WriteString(buf, SV_INIT.sv.configstrings[i]); } } Com.DPrintf("signon message length: " + buf.cursize + "\\n"); len = EndianHandler.SwapInt(buf.cursize); try { SV_INIT.svs.demofile.Write(len); SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize); } catch (IOException e1) { e1.PrintStackTrace(); } }
/** * CL_CheckOrDownloadFile returns true if the file exists, * otherwise it attempts to start a * download from the server. */ public static bool CheckOrDownloadFile(string filename) { if (filename.IndexOf("..") != -1) { Com.Printf("Refusing to download a path with ..\n"); return(true); } if (FS.FileLength(filename) > 0) { // it exists, no need to download return(true); } Globals.cls.downloadname = filename; // download to a temp name, and only rename // to the real name when done, so if interrupted // a runt file wont be left Globals.cls.downloadtempname = Com.StripExtension(Globals.cls.downloadname); Globals.cls.downloadtempname += ".tmp"; // ZOID // check to see if we already have a tmp for this file, if so, try to // resume // open the file if not opened yet var name = CL_parse.DownloadFileName(Globals.cls.downloadtempname); Stream fp = File.OpenWrite(name); if (fp != null) { // it exists long len = 0; try { len = fp.Length; } catch (IOException) { } Globals.cls.download = fp; // give the server an offset to start the download Com.Printf("Resuming " + Globals.cls.downloadname + "\n"); MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname + " " + len); } else { Com.Printf("Downloading " + Globals.cls.downloadname + "\n"); MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname); } Globals.cls.downloadnumber++; return(false); }