public static void ForwardToServer( ) { String cmd; cmd = Cmd.Argv(0); if (Globals.cls.state <= Defines.ca_connected || cmd[0] == '-' || cmd[0] == '+') { Com.Printf("Unknown command \\\"" + cmd + "\\\"\\n"); return; } MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); SZ.Print(Globals.cls.netchan.message, cmd); if (Cmd.Argc() > 1) { SZ.Print(Globals.cls.netchan.message, " "); SZ.Print(Globals.cls.netchan.message, Cmd.Args()); } }
public static void ParseDownload( ) { Int32 size = MSG.ReadShort(Globals.net_message); var percent = MSG.ReadByte(Globals.net_message); if (size == -1) { Com.Printf("Server does not have this file.\\n"); if (Globals.cls.download != null) { try { Globals.cls.download.Close(); } catch (IOException e) { } Globals.cls.download = null; } CL.RequestNextDownload(); return; } if (Globals.cls.download == null) { var name = DownloadFileName(Globals.cls.downloadtempname).ToLower(); FS.CreatePath(name); Globals.cls.download = new QuakeFile(name, FileAccess.ReadWrite); if (Globals.cls.download == null) { Globals.net_message.readcount += size; Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\\n"); CL.RequestNextDownload(); return; } } try { Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size); } catch (Exception e) { } Globals.net_message.readcount += size; if (percent != 100) { Globals.cls.downloadpercent = percent; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); SZ.Print(Globals.cls.netchan.message, "nextdl"); } else { try { Globals.cls.download.Close(); } catch (IOException e) { } var oldn = DownloadFileName(Globals.cls.downloadtempname); var newn = DownloadFileName(Globals.cls.downloadname); var r = Lib.Rename(oldn, newn); if (r != 0) { Com.Printf("failed to rename.\\n"); } Globals.cls.download = null; Globals.cls.downloadpercent = 0; CL.RequestNextDownload(); } }
/* * ===================== CL_ParseDownload * * A download message has been received from the server * ===================== */ public static void ParseDownload() { // read the data int size = MSG.ReadShort(Globals.net_message); var percent = MSG.ReadByte(Globals.net_message); if (size == -1) { Com.Printf("Server does not have this file.\n"); if (Globals.cls.download != null) { // if here, we tried to resume a file but the server said no try { Globals.cls.download.Close(); } catch (IOException) { } Globals.cls.download = null; } Cl.RequestNextDownload(); return; } // open the file if not opened yet if (Globals.cls.download == null) { var name = CL_parse.DownloadFileName(Globals.cls.downloadtempname).ToLower(); FS.CreatePath(name); Globals.cls.download = File.OpenWrite(name); if (Globals.cls.download == null) { Globals.net_message.readcount += size; Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\n"); Cl.RequestNextDownload(); return; } } try { Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size); } catch (Exception) { } Globals.net_message.readcount += size; if (percent != 100) { // request next block // change display routines by zoid Globals.cls.downloadpercent = percent; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); SZ.Print(Globals.cls.netchan.message, "nextdl"); } else { try { Globals.cls.download.Close(); } catch (IOException) { } // rename the temp file to it's final name var oldn = CL_parse.DownloadFileName(Globals.cls.downloadtempname); var newn = CL_parse.DownloadFileName(Globals.cls.downloadname); File.Move(oldn, newn); Globals.cls.download = null; Globals.cls.downloadpercent = 0; // get another file if needed Cl.RequestNextDownload(); } }