📄 cl_parse.java
字号:
/* * CL_parse.java * Copyright (C) 2004 * * $Id: CL_parse.java,v 1.21 2005/02/19 21:16:03 salomo Exp $ *//* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package jake2.client;import jake2.Defines;import jake2.Globals;import jake2.game.Cmd;import jake2.game.entity_state_t;import jake2.qcommon.*;import jake2.render.model_t;import jake2.sound.S;import jake2.sys.Sys;import jake2.util.Lib;import jake2.util.Math3D;import java.io.IOException;import java.io.RandomAccessFile;/** * CL_parse */public class CL_parse { //// cl_parse.c -- parse a message received from the server public static String svc_strings[] = { "svc_bad", "svc_muzzleflash", "svc_muzzlflash2", "svc_temp_entity", "svc_layout", "svc_inventory", "svc_nop", "svc_disconnect", "svc_reconnect", "svc_sound", "svc_print", "svc_stufftext", "svc_serverdata", "svc_configstring", "svc_spawnbaseline", "svc_centerprint", "svc_download", "svc_playerinfo", "svc_packetentities", "svc_deltapacketentities", "svc_frame" }; // ============================================================================= public static String DownloadFileName(String fn) { return FS.Gamedir() + "/" + fn; } /* * =============== CL_CheckOrDownloadFile * * Returns true if the file exists, otherwise it attempts to start a * download from the server. =============== */ public static boolean CheckOrDownloadFile(String filename) { RandomAccessFile fp; String name; 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 name = DownloadFileName(Globals.cls.downloadtempname); fp = Lib.fopen(name, "r+b"); if (fp != null) { // it exists long len = 0; try { len = fp.length(); } catch (IOException e) { } 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; } /* * =============== CL_Download_f * * Request a download from the server =============== */ public static xcommand_t Download_f = new xcommand_t() { public 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) { // it exists, no need to // download Com.Printf("File already exists.\n"); return; } Globals.cls.downloadname = filename; Com.Printf("Downloading " + Globals.cls.downloadname + "\n"); // 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"; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname); Globals.cls.downloadnumber++; } }; /* * ====================== CL_RegisterSounds ====================== */ public static void RegisterSounds() { S.BeginRegistration(); CL_tent.RegisterTEntSounds(); for (int i = 1; i < Defines.MAX_SOUNDS; i++) { if (Globals.cl.configstrings[Defines.CS_SOUNDS + i] == null || Globals.cl.configstrings[Defines.CS_SOUNDS + i] .equals("") || Globals.cl.configstrings[Defines.CS_SOUNDS + i] .equals("\0")) break; Globals.cl.sound_precache[i] = S .RegisterSound(Globals.cl.configstrings[Defines.CS_SOUNDS + i]); Sys.SendKeyEvents(); // pump message loop } S.EndRegistration(); } /* * ===================== 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); int 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 e) { } Globals.cls.download = null; } CL.RequestNextDownload(); return; } // open the file if not opened yet if (Globals.cls.download == null) { String name = DownloadFileName(Globals.cls.downloadtempname).toLowerCase(); FS.CreatePath(name); Globals.cls.download = Lib.fopen(name, "rw"); if (Globals.cls.download == null) { Globals.net_message.readcount += size; Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\n"); CL.RequestNextDownload(); return; } } //fwrite(net_message.data[net_message.readcount], 1, size, // cls.download); 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) { // 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 { String oldn, newn; //char oldn[MAX_OSPATH]; //char newn[MAX_OSPATH]; // Com.Printf ("100%%\n"); try { Globals.cls.download.close(); } catch (IOException e) { } // rename the temp file to it's final name oldn = DownloadFileName(Globals.cls.downloadtempname); newn = DownloadFileName(Globals.cls.downloadname); int r = Lib.rename(oldn, newn); if (r != 0) Com.Printf("failed to rename.\n"); Globals.cls.download = null; Globals.cls.downloadpercent = 0; // get another file if needed CL.RequestNextDownload(); } } /* * ===================================================================== * * SERVER CONNECTING MESSAGES * * ===================================================================== */ /* * ================== CL_ParseServerData ================== */ //checked once, was ok. public static void ParseServerData() { String str; int i; Com.DPrintf("ParseServerData():Serverdata packet received.\n"); // // wipe the client_state_t struct // CL.ClearState(); Globals.cls.state = Defines.ca_connected; // parse protocol version number i = MSG.ReadLong(Globals.net_message); Globals.cls.serverProtocol = i; // BIG HACK to let demos from release work with the 3.0x patch!!! if (Globals.server_state != 0 && Defines.PROTOCOL_VERSION == 34) { } else if (i != Defines.PROTOCOL_VERSION) Com.Error(Defines.ERR_DROP, "Server returned version " + i + ", not " + Defines.PROTOCOL_VERSION); Globals.cl.servercount = MSG.ReadLong(Globals.net_message); Globals.cl.attractloop = MSG.ReadByte(Globals.net_message) != 0; // game directory str = MSG.ReadString(Globals.net_message); Globals.cl.gamedir = str; Com.dprintln("gamedir=" + str); // set gamedir if (str.length() > 0 && (FS.fs_gamedirvar.string == null || FS.fs_gamedirvar.string.length() == 0 || FS.fs_gamedirvar.string .equals(str)) || (str.length() == 0 && (FS.fs_gamedirvar.string != null || FS.fs_gamedirvar.string .length() == 0))) Cvar.Set("game", str); // parse player entity number Globals.cl.playernum = MSG.ReadShort(Globals.net_message); Com.dprintln("numplayers=" + Globals.cl.playernum); // get the full level name str = MSG.ReadString(Globals.net_message); Com.dprintln("levelname=" + str); if (Globals.cl.playernum == -1) { // playing a cinematic or showing a // pic, not a level SCR.PlayCinematic(str); } else { // seperate the printfs so the server message can have a color // Com.Printf( // "\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n"); // Com.Printf('\02' + str + "\n"); Com.Printf("Levelname:" + str + "\n"); // need to prep refresh at next oportunity Globals.cl.refresh_prepped = false; } } /* * ================== CL_ParseBaseline ================== */ public static void ParseBaseline() { entity_state_t es; int newnum; entity_state_t nullstate = new entity_state_t(null); //memset(nullstate, 0, sizeof(nullstate)); int bits[] = { 0 }; newnum = CL_ents.ParseEntityBits(bits); es = Globals.cl_entities[newnum].baseline; CL_ents.ParseDelta(nullstate, es, newnum, bits[0]); } /* * ================ CL_LoadClientinfo * * ================ */ public static void LoadClientinfo(clientinfo_t ci, String s) { int i; int t; //char model_name[MAX_QPATH]; //char skin_name[MAX_QPATH]; //char model_filename[MAX_QPATH]; //char skin_filename[MAX_QPATH]; //char weapon_filename[MAX_QPATH]; String model_name, skin_name, model_filename, skin_filename, weapon_filename; ci.cinfo = s; //ci.cinfo[sizeof(ci.cinfo) - 1] = 0; // isolate the player's name ci.name = s; //ci.name[sizeof(ci.name) - 1] = 0; t = s.indexOf('\\'); //t = strstr(s, "\\"); if (t != -1) { ci.name = s.substring(0, t); s = s.substring(t + 1, s.length()); //s = t + 1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -