diff options
author | Holger Zickner <[email protected]> | 2004-07-09 06:50:52 +0000 |
---|---|---|
committer | Holger Zickner <[email protected]> | 2004-07-09 06:50:52 +0000 |
commit | 20a66a892a3f0704ef37f1eebb681edfee6fc165 (patch) | |
tree | 118e0e5ea00eecf450e4c63edc88c421d52a7db2 /src/jake2/server | |
parent | 6b36f9e0380b7c80aecdc78ef07a0cf473712416 (diff) |
import of Jake2
Diffstat (limited to 'src/jake2/server')
-rw-r--r-- | src/jake2/server/SV_CCMDS.java | 7 | ||||
-rw-r--r-- | src/jake2/server/SV_GAME.java | 6 | ||||
-rw-r--r-- | src/jake2/server/SV_INIT.java | 14 | ||||
-rw-r--r-- | src/jake2/server/SV_MAIN.java | 4 | ||||
-rw-r--r-- | src/jake2/server/SV_USER.java | 344 | ||||
-rw-r--r-- | src/jake2/server/SV_WORLD.java | 273 |
6 files changed, 358 insertions, 290 deletions
diff --git a/src/jake2/server/SV_CCMDS.java b/src/jake2/server/SV_CCMDS.java index 6c71224..76e348d 100644 --- a/src/jake2/server/SV_CCMDS.java +++ b/src/jake2/server/SV_CCMDS.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 18.01.2004 by RST. -// $Id: SV_CCMDS.java,v 1.2 2004-07-08 15:58:45 hzi Exp $ +// $Id: SV_CCMDS.java,v 1.3 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -228,7 +228,6 @@ public class SV_CCMDS extends SV_ENTS { f1.close(); } catch (IOException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } return; @@ -627,7 +626,7 @@ public class SV_CCMDS extends SV_ENTS { // copy off the level to the autosave slot if (0 == dedicated.value) { - //TODO: SV_WriteServerFile! + //TODO: SV_WriteServerFile. //SV_WriteServerFile(true); //SV_CopySaveGame("current", "save0"); @@ -658,7 +657,7 @@ public class SV_CCMDS extends SV_ENTS { } sv.state = ss_dead; // don't save current level when changing - //TODO: RST: disabled for debugging + //TODO: savegame //SV_WipeSavegame("current"); SV_GameMap_f(); } diff --git a/src/jake2/server/SV_GAME.java b/src/jake2/server/SV_GAME.java index 8f6eec4..9e3d8d2 100644 --- a/src/jake2/server/SV_GAME.java +++ b/src/jake2/server/SV_GAME.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 14.01.2004 by RST. -// $Id: SV_GAME.java,v 1.4 2004-07-08 20:56:54 hzi Exp $ +// $Id: SV_GAME.java,v 1.5 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -308,11 +308,11 @@ public class SV_GAME extends SV_INIT { } public static void PF_StartSound(edict_t entity, int channel, int sound_num, float volume, float attenuation, float timeofs) { + if (null == entity) return; - - //TODO: impl SV_StartSound SV_SEND.SV_StartSound (null, entity, channel, sound_num, volume, attenuation, timeofs); + } //============================================== diff --git a/src/jake2/server/SV_INIT.java b/src/jake2/server/SV_INIT.java index b4b4ee6..631e898 100644 --- a/src/jake2/server/SV_INIT.java +++ b/src/jake2/server/SV_INIT.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 14.01.2004 by RST. -// $Id: SV_INIT.java,v 1.3 2004-07-08 20:24:30 hzi Exp $ +// $Id: SV_INIT.java,v 1.4 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -250,16 +250,16 @@ public class SV_INIT extends Globals { sv.name=server; sv.configstrings[CS_NAME] = server; - CM.intwrap checksum_iw = new CM.intwrap(checksum); + int iw[] = {checksum}; if (serverstate != ss_game) { - sv.models[1] = CM.CM_LoadMap("", false, checksum_iw); // no real map + sv.models[1] = CM.CM_LoadMap("", false, iw); // no real map } else { - sv.configstrings[CS_MODELS + 1] = "maps/" + server + ".bsp"; - sv.models[1] = CM.CM_LoadMap(sv.configstrings[CS_MODELS + 1], false, checksum_iw); + sv.configstrings[CS_MODELS + 1] = "maps/" + server + ".bsp"; + sv.models[1] = CM.CM_LoadMap(sv.configstrings[CS_MODELS + 1], false, iw); } - checksum = checksum_iw.i; + checksum = iw[0]; sv.configstrings[CS_MAPCHECKSUM] = "" + checksum; // @@ -302,7 +302,7 @@ public class SV_INIT extends Globals { // set serverinfo variable Cvar.FullSet("mapname", sv.name, CVAR_SERVERINFO | CVAR_NOSET); - Com.Printf("-------------------------------------\n"); + //Com.Printf("-------------------------------------\n"); } /* diff --git a/src/jake2/server/SV_MAIN.java b/src/jake2/server/SV_MAIN.java index 464b056..510decc 100644 --- a/src/jake2/server/SV_MAIN.java +++ b/src/jake2/server/SV_MAIN.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 13.01.2004 by RST. -// $Id: SV_MAIN.java,v 1.2 2004-07-08 15:58:45 hzi Exp $ +// $Id: SV_MAIN.java,v 1.3 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -476,7 +476,7 @@ public class SV_MAIN extends SV_GAME { Cmd.TokenizeString(s.toCharArray(), false); c = Cmd.Argv(0); - Com.Printf("Packet " + NET.AdrToString(Netchan.net_from) + " : " + c + "\n"); + //Com.Printf("Packet " + NET.AdrToString(Netchan.net_from) + " : " + c + "\n"); //Com.Printf(Lib.hexDump(net_message.data, 64, false) + "\n"); if (0 == strcmp(c, "ping")) diff --git a/src/jake2/server/SV_USER.java b/src/jake2/server/SV_USER.java index c6e355e..65e5262 100644 --- a/src/jake2/server/SV_USER.java +++ b/src/jake2/server/SV_USER.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 17.01.2004 by RST. -// $Id: SV_USER.java,v 1.3 2004-07-08 20:24:30 hzi Exp $ +// $Id: SV_USER.java,v 1.4 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -29,7 +29,8 @@ import jake2.util.Lib; import java.io.IOException; -public class SV_USER extends SV_SEND { +public class SV_USER extends SV_SEND +{ static edict_t sv_player; @@ -47,14 +48,17 @@ public class SV_USER extends SV_SEND { SV_BeginDemoServer ================== */ - public static void SV_BeginDemoserver() { + public static void SV_BeginDemoserver() + { String name; - name = "demos/" + sv.name; - try { - sv.demofile = FS.FOpenFile(name); + name= "demos/" + sv.name; + try + { + sv.demofile= FS.FOpenFile(name); } - catch (IOException e) { + catch (IOException e) + { Com.Error(ERR_DROP, "Couldn't open " + name + "\n"); } if (sv.demofile == null) @@ -69,20 +73,23 @@ public class SV_USER extends SV_SEND { This will be sent on the initial connection and upon each server load. ================ */ - public static void SV_New_f() { + public static void SV_New_f() + { String gamedir; int playernum; edict_t ent; Com.DPrintf("New() from " + sv_client.name + "\n"); - if (sv_client.state != cs_connected) { + if (sv_client.state != cs_connected) + { Com.Printf("New not valid -- already spawned\n"); return; } // demo servers just dump the file message - if (sv.state == ss_demo) { + if (sv.state == ss_demo) + { SV_BeginDemoserver(); return; } @@ -91,7 +98,7 @@ public class SV_USER extends SV_SEND { // serverdata needs to go over for all types of servers // to make sure the protocol is right, and to set the gamedir // - gamedir = Cvar.VariableString("gamedir"); + gamedir= Cvar.VariableString("gamedir"); // send the serverdata MSG.WriteByte(sv_client.netchan.message, svc_serverdata); @@ -101,10 +108,10 @@ public class SV_USER extends SV_SEND { MSG.WriteString(sv_client.netchan.message, gamedir); if (sv.state == ss_cinematic || sv.state == ss_pic) - playernum = -1; + playernum= -1; else //playernum = sv_client - svs.clients; - playernum = sv_client.serverindex; + playernum= sv_client.serverindex; MSG.WriteShort(sv_client.netchan.message, playernum); @@ -114,12 +121,13 @@ public class SV_USER extends SV_SEND { // // game server // - if (sv.state == ss_game) { + if (sv.state == ss_game) + { // set up the entity for the client - ent = SV_GAME.ge.edicts[playernum + 1]; - ent.s.number = playernum + 1; - sv_client.edict = ent; - sv_client.lastcmd = new usercmd_t(); + ent= SV_GAME.ge.edicts[playernum + 1]; + ent.s.number= playernum + 1; + sv_client.edict= ent; + sv_client.lastcmd= new usercmd_t(); // begin fetching configstrings MSG.WriteByte(sv_client.netchan.message, svc_stufftext); @@ -133,29 +141,34 @@ public class SV_USER extends SV_SEND { SV_Configstrings_f ================== */ - public static void SV_Configstrings_f() { + public static void SV_Configstrings_f() + { int start; Com.DPrintf("Configstrings() from " + sv_client.name + "\n"); - if (sv_client.state != cs_connected) { + if (sv_client.state != cs_connected) + { Com.Printf("configstrings not valid -- already spawned\n"); return; } // handle the case of a level changing while a client was connecting - if (atoi(Cmd.Argv(1)) != svs.spawncount) { + if (atoi(Cmd.Argv(1)) != svs.spawncount) + { Com.Printf("SV_Configstrings_f from different level\n"); SV_New_f(); return; } - start = atoi(Cmd.Argv(2)); + start= atoi(Cmd.Argv(2)); // write a packet full of data - while (sv_client.netchan.message.cursize < MAX_MSGLEN / 2 && start < MAX_CONFIGSTRINGS) { - if (sv.configstrings[start] != null && sv.configstrings[start].length() != 0) { + while (sv_client.netchan.message.cursize < MAX_MSGLEN / 2 && start < MAX_CONFIGSTRINGS) + { + if (sv.configstrings[start] != null && sv.configstrings[start].length() != 0) + { MSG.WriteByte(sv_client.netchan.message, svc_configstring); MSG.WriteShort(sv_client.netchan.message, start); MSG.WriteString(sv_client.netchan.message, sv.configstrings[start]); @@ -165,11 +178,13 @@ public class SV_USER extends SV_SEND { // send next command - if (start == MAX_CONFIGSTRINGS) { + if (start == MAX_CONFIGSTRINGS) + { MSG.WriteByte(sv_client.netchan.message, svc_stufftext); MSG.WriteString(sv_client.netchan.message, "cmd baselines " + svs.spawncount + " 0\n"); } - else { + else + { MSG.WriteByte(sv_client.netchan.message, svc_stufftext); MSG.WriteString(sv_client.netchan.message, "cmd configstrings " + svs.spawncount + " " + start + "\n"); } @@ -180,35 +195,40 @@ public class SV_USER extends SV_SEND { SV_Baselines_f ================== */ - public static void SV_Baselines_f() { + public static void SV_Baselines_f() + { int start; entity_state_t nullstate; entity_state_t base; Com.DPrintf("Baselines() from " + sv_client.name + "\n"); - if (sv_client.state != cs_connected) { + if (sv_client.state != cs_connected) + { Com.Printf("baselines not valid -- already spawned\n"); return; } // handle the case of a level changing while a client was connecting - if (atoi(Cmd.Argv(1)) != svs.spawncount) { + if (atoi(Cmd.Argv(1)) != svs.spawncount) + { Com.Printf("SV_Baselines_f from different level\n"); SV_New_f(); return; } - start = atoi(Cmd.Argv(2)); + start= atoi(Cmd.Argv(2)); //memset (&nullstate, 0, sizeof(nullstate)); - nullstate = new entity_state_t(null); + nullstate= new entity_state_t(null); // write a packet full of data - while (sv_client.netchan.message.cursize < MAX_MSGLEN / 2 && start < MAX_EDICTS) { - base = sv.baselines[start]; - if (base.modelindex != 0 || base.sound != 0 || base.effects != 0) { + while (sv_client.netchan.message.cursize < MAX_MSGLEN / 2 && start < MAX_EDICTS) + { + base= sv.baselines[start]; + if (base.modelindex != 0 || base.sound != 0 || base.effects != 0) + { MSG.WriteByte(sv_client.netchan.message, svc_spawnbaseline); MSG.WriteDeltaEntity(nullstate, base, sv_client.netchan.message, true, true); } @@ -217,11 +237,13 @@ public class SV_USER extends SV_SEND { // send next command - if (start == MAX_EDICTS) { + if (start == MAX_EDICTS) + { MSG.WriteByte(sv_client.netchan.message, svc_stufftext); MSG.WriteString(sv_client.netchan.message, "precache " + svs.spawncount + "\n"); } - else { + else + { MSG.WriteByte(sv_client.netchan.message, svc_stufftext); MSG.WriteString(sv_client.netchan.message, "cmd baselines " + svs.spawncount + " " + start + "\n"); } @@ -232,17 +254,19 @@ public class SV_USER extends SV_SEND { SV_Begin_f ================== */ - public static void SV_Begin_f() { + public static void SV_Begin_f() + { Com.DPrintf("Begin() from " + sv_client.name + "\n"); // handle the case of a level changing while a client was connecting - if (atoi(Cmd.Argv(1)) != svs.spawncount) { + if (atoi(Cmd.Argv(1)) != svs.spawncount) + { Com.Printf("SV_Begin_f from different level\n"); SV_New_f(); return; } - sv_client.state = cs_spawned; + sv_client.state= cs_spawned; // call the game begin function SV_GAME.ge.ClientBegin(sv_player); @@ -257,7 +281,8 @@ public class SV_USER extends SV_SEND { SV_NextDownload_f ================== */ - public static void SV_NextDownload_f() { + public static void SV_NextDownload_f() + { int r; int percent; int size; @@ -265,18 +290,18 @@ public class SV_USER extends SV_SEND { if (sv_client.download == null) return; - r = sv_client.downloadsize - sv_client.downloadcount; + r= sv_client.downloadsize - sv_client.downloadcount; if (r > 1024) - r = 1024; + r= 1024; MSG.WriteByte(sv_client.netchan.message, svc_download); MSG.WriteShort(sv_client.netchan.message, r); sv_client.downloadcount += r; - size = sv_client.downloadsize; + size= sv_client.downloadsize; if (size == 0) - size = 1; - percent = sv_client.downloadcount * 100 / size; + size= 1; + percent= sv_client.downloadcount * 100 / size; MSG.WriteByte(sv_client.netchan.message, percent); SZ.Write(sv_client.netchan.message, sv_client.download, sv_client.downloadcount - r, r); @@ -284,7 +309,7 @@ public class SV_USER extends SV_SEND { return; FS.FreeFile(sv_client.download); - sv_client.download = null; + sv_client.download= null; } /* @@ -292,14 +317,15 @@ public class SV_USER extends SV_SEND { SV_BeginDownload_f ================== */ - public static void SV_BeginDownload_f() { + public static void SV_BeginDownload_f() + { String name; - int offset = 0; + int offset= 0; - name = Cmd.Argv(1); + name= Cmd.Argv(1); if (Cmd.Argc() > 2) - offset = atoi(Cmd.Argv(2)); // downloaded offset + offset= atoi(Cmd.Argv(2)); // downloaded offset // hacked by zoid to allow more conrol over download // first off, no .. or global allow check @@ -310,9 +336,11 @@ public class SV_USER extends SV_SEND { || name.charAt(0) == '/' // next up, skin check || (name.startsWith("players/") && 0 == allow_download_players.value) // now models || (name.startsWith("models/") && 0 == allow_download_models.value) // now sounds - || (name.startsWith("sound/") && 0 == allow_download_sounds.value) // now maps (note special case for maps, must not be in pak) + || (name.startsWith("sound/") + && 0 == allow_download_sounds.value) // now maps (note special case for maps, must not be in pak) || (name.startsWith("maps/") && 0 == allow_download_maps.value) // MUST be in a subdirectory - || name.indexOf('/') == -1) { // don't allow anything with .. path + || name.indexOf('/') == -1) + { // don't allow anything with .. path MSG.WriteByte(sv_client.netchan.message, svc_download); MSG.WriteShort(sv_client.netchan.message, -1); MSG.WriteByte(sv_client.netchan.message, 0); @@ -322,20 +350,22 @@ public class SV_USER extends SV_SEND { if (sv_client.download != null) FS.FreeFile(sv_client.download); - sv_client.download = FS.LoadFile(name); - sv_client.downloadsize = sv_client.download.length; - sv_client.downloadcount = offset; + sv_client.download= FS.LoadFile(name); + sv_client.downloadsize= sv_client.download.length; + sv_client.downloadcount= offset; if (offset > sv_client.downloadsize) - sv_client.downloadcount = sv_client.downloadsize; + sv_client.downloadcount= sv_client.downloadsize; if (sv_client.download == null // special check for maps, if it came from a pak file, don't allow // download ZOID - || (name.startsWith("maps/") && FS.file_from_pak != 0)) { + || (name.startsWith("maps/") && FS.file_from_pak != 0)) + { Com.DPrintf("Couldn't download " + name + " to " + sv_client.name + "\n"); - if (sv_client.download != null) { + if (sv_client.download != null) + { FS.FreeFile(sv_client.download); - sv_client.download = null; + sv_client.download= null; } MSG.WriteByte(sv_client.netchan.message, svc_download); @@ -357,7 +387,8 @@ public class SV_USER extends SV_SEND { The client is going to disconnect, so remove the connection immediately ================= */ - public static void SV_Disconnect_f() { + public static void SV_Disconnect_f() + { // SV_EndRedirect (); SV_DropClient(sv_client); } @@ -369,11 +400,13 @@ public class SV_USER extends SV_SEND { Dumps the serverinfo info string ================== */ - public static void SV_ShowServerinfo_f() { + public static void SV_ShowServerinfo_f() + { Info.Print(Cvar.Serverinfo()); } - public static void SV_Nextserver() { + public static void SV_Nextserver() + { String v; //ZOID, ss_pic can be nextserver'd in coop mode @@ -381,11 +414,12 @@ public class SV_USER extends SV_SEND { return; // can't nextserver while playing a normal game svs.spawncount++; // make sure another doesn't sneak in - v = Cvar.VariableString("nextserver"); + v= Cvar.VariableString("nextserver"); //if (!v[0]) if (v.length() == 0) Cbuf.AddText("killserver\n"); - else { + else + { Cbuf.AddText(v); Cbuf.AddText("\n"); } @@ -400,8 +434,10 @@ public class SV_USER extends SV_SEND { to the next server, ================== */ - public static void SV_Nextserver_f() { - if (Lib.atoi(Cmd.Argv(1)) != svs.spawncount) { + public static void SV_Nextserver_f() + { + if (Lib.atoi(Cmd.Argv(1)) != svs.spawncount) + { Com.DPrintf("Nextserver() from wrong level, from " + sv_client.name + "\n"); return; // leftover from last server } @@ -411,58 +447,80 @@ public class SV_USER extends SV_SEND { SV_Nextserver(); } - public static class ucmd_t { - public ucmd_t(String n, Runnable r) { - name = n; - this.r = r; + public static class ucmd_t + { + public ucmd_t(String n, Runnable r) + { + name= n; + this.r= r; } String name; Runnable r; } - static ucmd_t u1 = new ucmd_t("new", new Runnable() { - public void run() { + static ucmd_t u1= new ucmd_t("new", new Runnable() + { + public void run() + { SV_New_f(); } }); - static ucmd_t ucmds[] = { + static ucmd_t ucmds[]= { // auto issued - new ucmd_t("new", new Runnable() { public void run() { SV_New_f(); + new ucmd_t("new", new Runnable() + { public void run() + { SV_New_f(); } - }), new ucmd_t("configstrings", new Runnable() { - public void run() { + }), new ucmd_t("configstrings", new Runnable() + { + public void run() + { SV_Configstrings_f(); } - }), new ucmd_t("baselines", new Runnable() { - public void run() { + }), new ucmd_t("baselines", new Runnable() + { + public void run() + { SV_Baselines_f(); } - }), new ucmd_t("begin", new Runnable() { - public void run() { + }), new ucmd_t("begin", new Runnable() + { + public void run() + { SV_Begin_f(); } - }), new ucmd_t("nextserver", new Runnable() { - public void run() { + }), new ucmd_t("nextserver", new Runnable() + { + public void run() + { SV_Nextserver_f(); } - }), new ucmd_t("disconnect", new Runnable() { - public void run() { + }), new ucmd_t("disconnect", new Runnable() + { + public void run() + { SV_Disconnect_f(); } }), // issued by hand at client consoles - new ucmd_t("info", new Runnable() { - public void run() { + new ucmd_t("info", new Runnable() + { + public void run() + { SV_ShowServerinfo_f(); } - }), new ucmd_t("download", new Runnable() { - public void run() { + }), new ucmd_t("download", new Runnable() + { + public void run() + { SV_BeginDownload_f(); } - }), new ucmd_t("nextdl", new Runnable() { - public void run() { + }), new ucmd_t("nextdl", new Runnable() + { + public void run() + { SV_NextDownload_f(); } }) @@ -473,23 +531,26 @@ public class SV_USER extends SV_SEND { SV_ExecuteUserCommand ================== */ - public static void SV_ExecuteUserCommand(String s) { - ucmd_t u = null; + public static void SV_ExecuteUserCommand(String s) + { + ucmd_t u= null; Cmd.TokenizeString(s.toCharArray(), true); - sv_player = sv_client.edict; + sv_player= sv_client.edict; // SV_BeginRedirect (RD_CLIENT); - int i=0; - for (; i < ucmds.length; i++) { - u = ucmds[i]; - if (0 == strcmp(Cmd.Argv(0), u.name)) { + int i= 0; + for (; i < ucmds.length; i++) + { + u= ucmds[i]; + if (0 == strcmp(Cmd.Argv(0), u.name)) + { u.r.run(); break; } } - + if (i == ucmds.length && sv.state == ss_game) SV_GAME.ge.ClientCommand(sv_player); @@ -504,10 +565,12 @@ public class SV_USER extends SV_SEND { =========================================================================== */ - public static void SV_ClientThink(client_t cl, usercmd_t cmd) { + public static void SV_ClientThink(client_t cl, usercmd_t cmd) + { cl.commandMsec -= cmd.msec & 0xFF; - if (cl.commandMsec < 0 && sv_enforcetime.value != 0) { + if (cl.commandMsec < 0 && sv_enforcetime.value != 0) + { Com.DPrintf("commandMsec underflow from " + cl.name + "\n"); return; } @@ -515,7 +578,7 @@ public class SV_USER extends SV_SEND { SV_GAME.ge.ClientThink(cl.edict, cmd); } - public static final int MAX_STRINGCMDS = 8; + public static final int MAX_STRINGCMDS= 8; /* =================== SV_ExecuteClientMessage @@ -523,12 +586,13 @@ public class SV_USER extends SV_SEND { The current net_message is parsed for the given client =================== */ - public static void SV_ExecuteClientMessage(client_t cl) { + public static void SV_ExecuteClientMessage(client_t cl) + { int c; String s; - usercmd_t nullcmd = new usercmd_t(); - usercmd_t oldest = new usercmd_t(), oldcmd = new usercmd_t(), newcmd = new usercmd_t(); + usercmd_t nullcmd= new usercmd_t(); + usercmd_t oldest= new usercmd_t(), oldcmd= new usercmd_t(), newcmd= new usercmd_t(); int net_drop; int stringCmdCount; int checksum, calculatedChecksum; @@ -536,26 +600,29 @@ public class SV_USER extends SV_SEND { boolean move_issued; int lastframe; - sv_client = cl; - sv_player = sv_client.edict; + sv_client= cl; + sv_player= sv_client.edict; // only allow one move command - move_issued = false; - stringCmdCount = 0; + move_issued= false; + stringCmdCount= 0; - while (true) { - if (net_message.readcount > net_message.cursize) { + while (true) + { + if (net_message.readcount > net_message.cursize) + { Com.Printf("SV_ReadClientMessage: bad read:\n"); Com.Printf(Lib.hexDump(net_message.data, 32, false)); SV_DropClient(cl); return; } - c = MSG.ReadByte(net_message); + c= MSG.ReadByte(net_message); if (c == -1) break; - switch (c) { + switch (c) + { default : Com.Printf("SV_ReadClientMessage: unknown command char\n"); SV_DropClient(cl); @@ -565,7 +632,7 @@ public class SV_USER extends SV_SEND { break; case clc_userinfo : - cl.userinfo = MSG.ReadString(net_message); + cl.userinfo= MSG.ReadString(net_message); SV_MAIN.SV_UserinfoChanged(cl); break; @@ -573,41 +640,43 @@ public class SV_USER extends SV_SEND { if (move_issued) return; // someone is trying to cheat... - move_issued = true; - checksumIndex = net_message.readcount; - checksum = MSG.ReadByte(net_message); - lastframe = MSG.ReadLong(net_message); - - if (lastframe != cl.lastframe) { - cl.lastframe = lastframe; - if (cl.lastframe > 0) { - cl.frame_latency[cl.lastframe & (LATENCY_COUNTS - 1)] = + move_issued= true; + checksumIndex= net_message.readcount; + checksum= MSG.ReadByte(net_message); + lastframe= MSG.ReadLong(net_message); + + if (lastframe != cl.lastframe) + { + cl.lastframe= lastframe; + if (cl.lastframe > 0) + { + cl.frame_latency[cl.lastframe & (LATENCY_COUNTS - 1)]= svs.realtime - cl.frames[cl.lastframe & UPDATE_MASK].senttime; } } //memset (nullcmd, 0, sizeof(nullcmd)); - nullcmd = new usercmd_t(); + nullcmd= new usercmd_t(); MSG.ReadDeltaUsercmd(net_message, nullcmd, oldest); MSG.ReadDeltaUsercmd(net_message, oldest, oldcmd); MSG.ReadDeltaUsercmd(net_message, oldcmd, newcmd); - if (cl.state != cs_spawned) { - cl.lastframe = -1; + if (cl.state != cs_spawned) + { + cl.lastframe= -1; break; } // if the checksum fails, ignore the rest of the packet - calculatedChecksum = 0; - /* - = Com.BlockSequenceCRCByte( - net_message.data + checksumIndex + 1, + calculatedChecksum= + Com.BlockSequenceCRCByte( + net_message.data, checksumIndex + 1, net_message.readcount - checksumIndex - 1, cl.netchan.incoming_sequence); - */ - if (calculatedChecksum != checksum) { + if ((calculatedChecksum &0xff) != checksum) + { Com.DPrintf( "Failed command checksum for " + cl.name @@ -621,14 +690,17 @@ public class SV_USER extends SV_SEND { return; } - if (0 == sv_paused.value) { - net_drop = cl.netchan.dropped; - if (net_drop < 20) { + if (0 == sv_paused.value) + { + net_drop= cl.netchan.dropped; + if (net_drop < 20) + { //if (net_drop > 2) // Com.Printf ("drop %i\n", net_drop); - while (net_drop > 2) { + while (net_drop > 2) + { SV_ClientThink(cl, cl.lastcmd); net_drop--; @@ -648,7 +720,7 @@ public class SV_USER extends SV_SEND { break; case clc_stringcmd : - s = MSG.ReadString(net_message); + s= MSG.ReadString(net_message); // malicious users may try using too many string commands if (++stringCmdCount < MAX_STRINGCMDS) diff --git a/src/jake2/server/SV_WORLD.java b/src/jake2/server/SV_WORLD.java index 4e78084..2eb2ca6 100644 --- a/src/jake2/server/SV_WORLD.java +++ b/src/jake2/server/SV_WORLD.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 07.01.2000 by RST. -// $Id: SV_WORLD.java,v 1.3 2004-07-08 20:24:30 hzi Exp $ +// $Id: SV_WORLD.java,v 1.4 2004-07-09 06:50:49 hzi Exp $ package jake2.server; @@ -48,14 +48,13 @@ public class SV_WORLD extends SV_CCMDS //=============================================================================== // - public static void initNodes() { - for (int n = 0; n < AREA_NODES; n++) - sv_areanodes[n] = new areanode_t(); + for (int n= 0; n < AREA_NODES; n++) + sv_areanodes[n]= new areanode_t(); } - public static areanode_t sv_areanodes[] = new areanode_t[AREA_NODES]; + public static areanode_t sv_areanodes[]= new areanode_t[AREA_NODES]; static { initNodes(); @@ -70,21 +69,21 @@ public class SV_WORLD extends SV_CCMDS // ClearLink is used for new headnodes public static void ClearLink(link_t l) { - l.prev = l.next = l; + l.prev= l.next= l; } public static void RemoveLink(link_t l) { - l.next.prev = l.prev; - l.prev.next = l.next; + l.next.prev= l.prev; + l.prev.next= l.next; } public static void InsertLinkBefore(link_t l, link_t before) { - l.next = before; - l.prev = before.prev; - l.prev.next = l; - l.next.prev = l; + l.next= before; + l.prev= before.prev; + l.prev.next= l; + l.next.prev= l; } /* @@ -97,10 +96,10 @@ public class SV_WORLD extends SV_CCMDS public static areanode_t SV_CreateAreaNode(int depth, float[] mins, float[] maxs) { areanode_t anode; - float[] size = { 0, 0, 0 }; - float[] mins1 = { 0, 0, 0 }, maxs1 = { 0, 0, 0 }, mins2 = { 0, 0, 0 }, maxs2 = { 0, 0, 0 }; + float[] size= { 0, 0, 0 }; + float[] mins1= { 0, 0, 0 }, maxs1= { 0, 0, 0 }, mins2= { 0, 0, 0 }, maxs2= { 0, 0, 0 }; - anode = sv_areanodes[sv_numareanodes]; + anode= sv_areanodes[sv_numareanodes]; // just for debugging (rst) VectorCopy(mins, anode.mins_rst); @@ -113,27 +112,27 @@ public class SV_WORLD extends SV_CCMDS if (depth == AREA_DEPTH) { - anode.axis = -1; - anode.children[0] = anode.children[1] = null; + anode.axis= -1; + anode.children[0]= anode.children[1]= null; return anode; } VectorSubtract(maxs, mins, size); if (size[0] > size[1]) - anode.axis = 0; + anode.axis= 0; else - anode.axis = 1; + anode.axis= 1; - anode.dist = 0.5f * (maxs[anode.axis] + mins[anode.axis]); + anode.dist= 0.5f * (maxs[anode.axis] + mins[anode.axis]); VectorCopy(mins, mins1); VectorCopy(mins, mins2); VectorCopy(maxs, maxs1); VectorCopy(maxs, maxs2); - maxs1[anode.axis] = mins2[anode.axis] = anode.dist; + maxs1[anode.axis]= mins2[anode.axis]= anode.dist; - anode.children[0] = SV_CreateAreaNode(depth + 1, mins2, maxs2); - anode.children[1] = SV_CreateAreaNode(depth + 1, mins1, maxs1); + anode.children[0]= SV_CreateAreaNode(depth + 1, mins2, maxs2); + anode.children[1]= SV_CreateAreaNode(depth + 1, mins1, maxs1); return anode; } @@ -147,7 +146,7 @@ public class SV_WORLD extends SV_CCMDS public static void SV_ClearWorld() { initNodes(); - sv_numareanodes = 0; + sv_numareanodes= 0; SV_CreateAreaNode(0, sv.models[1].mins, sv.models[1].maxs); /* @@ -178,7 +177,7 @@ public class SV_WORLD extends SV_CCMDS if (null == ent.area.prev) return; // not linked in anywhere RemoveLink(ent.area); - ent.area.prev = ent.area.next = null; + ent.area.prev= ent.area.next= null; } /* @@ -186,18 +185,18 @@ public class SV_WORLD extends SV_CCMDS SV_LinkEdict =============== */ - public static final int MAX_TOTAL_ENT_LEAFS = 128; - + public static final int MAX_TOTAL_ENT_LEAFS= 128; + private static int leafs[]= new int[MAX_TOTAL_ENT_LEAFS]; + private static int clusters[]= new int[MAX_TOTAL_ENT_LEAFS]; + public static void SV_LinkEdict(edict_t ent) { areanode_t node; - // TODO: make static instead of new - int leafs[] = new int[MAX_TOTAL_ENT_LEAFS]; - int clusters[] = new int[MAX_TOTAL_ENT_LEAFS]; + int num_leafs; int j, k; int area; - int topnode = 0; + int topnode= 0; if (ent.area.prev != null) SV_UnlinkEdict(ent); // unlink from old position @@ -214,54 +213,54 @@ public class SV_WORLD extends SV_CCMDS // encode the size into the entity_state for client prediction if (ent.solid == SOLID_BBOX && 0 == (ent.svflags & SVF_DEADMONSTER)) { // assume that x/y are equal and symetric - int i = (int) (ent.maxs[0] / 8); + int i= (int) (ent.maxs[0] / 8); if (i < 1) - i = 1; + i= 1; if (i > 31) - i = 31; + i= 31; // z is not symetric - j = (int) ((-ent.mins[2]) / 8); + j= (int) ((-ent.mins[2]) / 8); if (j < 1) - j = 1; + j= 1; if (j > 31) - j = 31; + j= 31; // and z maxs can be negative... - k = (int) ((ent.maxs[2] + 32) / 8); + k= (int) ((ent.maxs[2] + 32) / 8); if (k < 1) - k = 1; + k= 1; if (k > 63) - k = 63; + k= 63; - ent.s.solid = (k << 10) | (j << 5) | i; + ent.s.solid= (k << 10) | (j << 5) | i; } else if (ent.solid == SOLID_BSP) { - ent.s.solid = 31; // a solid_bbox will never create this value + ent.s.solid= 31; // a solid_bbox will never create this value } else - ent.s.solid = 0; + ent.s.solid= 0; // set the abs box if (ent.solid == SOLID_BSP && (ent.s.angles[0] != 0 || ent.s.angles[1] != 0 || ent.s.angles[2] != 0)) { // expand for rotation float max, v; - max = 0; - for (int i = 0; i < 3; i++) + max= 0; + for (int i= 0; i < 3; i++) { - v = Math.abs(ent.mins[i]); + v= Math.abs(ent.mins[i]); if (v > max) - max = v; - v = Math.abs(ent.maxs[i]); + max= v; + v= Math.abs(ent.maxs[i]); if (v > max) - max = v; + max= v; } - for (int i = 0; i < 3; i++) + for (int i= 0; i < 3; i++) { - ent.absmin[i] = ent.s.origin[i] - max; - ent.absmax[i] = ent.s.origin[i] + max; + ent.absmin[i]= ent.s.origin[i] - max; + ent.absmax[i]= ent.s.origin[i] + max; } } else @@ -281,62 +280,65 @@ public class SV_WORLD extends SV_CCMDS ent.absmax[2]++; // link to PVS leafs - ent.num_clusters = 0; - ent.areanum = 0; - ent.areanum2 = 0; + ent.num_clusters= 0; + ent.areanum= 0; + ent.areanum2= 0; //get all leafs, including solids - CM.intwrap iw = new CM.intwrap(topnode); + int iw[] = {topnode}; - num_leafs = CM.CM_BoxLeafnums(ent.absmin, ent.absmax, leafs, MAX_TOTAL_ENT_LEAFS, iw); + num_leafs= CM.CM_BoxLeafnums(ent.absmin, ent.absmax, leafs, MAX_TOTAL_ENT_LEAFS, iw); - topnode = iw.i; + topnode= iw[0]; // set areas - for (int i = 0; i < num_leafs; i++) + for (int i= 0; i < num_leafs; i++) { - clusters[i] = CM.CM_LeafCluster(leafs[i]); - area = CM.CM_LeafArea(leafs[i]); + clusters[i]= CM.CM_LeafCluster(leafs[i]); + area= CM.CM_LeafArea(leafs[i]); if (area != 0) - { // doors may legally straggle two areas, + { + // doors may legally straggle two areas, // but nothing should evern need more than that if (ent.areanum != 0 && ent.areanum != area) { if (ent.areanum2 != 0 && ent.areanum2 != area && sv.state == ss_loading) Com.DPrintf("Object touching 3 areas at " + ent.absmin[0] + " " + ent.absmin[1] + " " + ent.absmin[2] + "\n"); - ent.areanum2 = area; + ent.areanum2= area; } else - ent.areanum = area; + ent.areanum= area; } } if (num_leafs >= MAX_TOTAL_ENT_LEAFS) - { // assume we missed some leafs, and mark by headnode - ent.num_clusters = -1; - ent.headnode = topnode; + { + // assume we missed some leafs, and mark by headnode + ent.num_clusters= -1; + ent.headnode= topnode; } else { - ent.num_clusters = 0; - for (int i = 0; i < num_leafs; i++) + ent.num_clusters= 0; + for (int i= 0; i < num_leafs; i++) { if (clusters[i] == -1) continue; // not a visible leaf - for (j = 0; j < i; j++) + for (j= 0; j < i; j++) if (clusters[j] == clusters[i]) break; if (j == i) { if (ent.num_clusters == MAX_ENT_CLUSTERS) - { // assume we missed some leafs, and mark by headnode - ent.num_clusters = -1; - ent.headnode = topnode; + { + // assume we missed some leafs, and mark by headnode + ent.num_clusters= -1; + ent.headnode= topnode; break; } - ent.clusternums[ent.num_clusters++] = clusters[i]; + ent.clusternums[ent.num_clusters++]= clusters[i]; } } } @@ -352,16 +354,16 @@ public class SV_WORLD extends SV_CCMDS return; // find the first node that the ent's box crosses - node = sv_areanodes[0]; + node= sv_areanodes[0]; while (true) { if (node.axis == -1) break; if (ent.absmin[node.axis] > node.dist) - node = node.children[0]; + node= node.children[0]; else if (ent.absmax[node.axis] < node.dist) - node = node.children[1]; + node= node.children[1]; else break; // crosses the node } @@ -386,19 +388,18 @@ public class SV_WORLD extends SV_CCMDS edict_t check; int count; - count = 0; + count= 0; // touch linked edicts if (area_type == AREA_SOLID) - start = node.solid_edicts; + start= node.solid_edicts; else - start = node.trigger_edicts; + start= node.trigger_edicts; - for (l = start.next; l != start; l = next) + for (l= start.next; l != start; l= next) { - next = l.next; - check = //EDICT_FROM_AREA(l); - (edict_t) l.o; + next= l.next; + check= (edict_t) l.o; if (check.solid == SOLID_NOT) continue; // deactivated @@ -416,7 +417,7 @@ public class SV_WORLD extends SV_CCMDS return; } - area_list[area_count] = check; + area_list[area_count]= check; area_count++; } @@ -438,57 +439,53 @@ public class SV_WORLD extends SV_CCMDS */ public static int SV_AreaEdicts(float[] mins, float[] maxs, edict_t list[], int maxcount, int areatype) { - area_mins = mins; - area_maxs = maxs; - area_list = list; - area_count = 0; - area_maxcount = maxcount; - area_type = areatype; + area_mins= mins; + area_maxs= maxs; + area_list= list; + area_count= 0; + area_maxcount= maxcount; + area_type= areatype; SV_AreaEdicts_r(sv_areanodes[0]); - /* - Com.Printf("found edicts in area:" + area_count + "\n"); - for (int n = 0; n < area_count; n++) { - Com.Printf("%4i : %25s", new Vargs().add(n).add(list[n].classname)); - } - */ return area_count; } //=========================================================================== + private static edict_t touch[]= new edict_t[MAX_EDICTS]; /* ============= SV_PointContents ============= */ + public static int SV_PointContents(float[] p) { - // TODO: make static instead new - edict_t touch[] = new edict_t[MAX_EDICTS], hit; + edict_t hit; + int i, num; int contents, c2; int headnode; float angles[]; // get base contents from world - contents = CM.PointContents(p, sv.models[1].headnode); + contents= CM.PointContents(p, sv.models[1].headnode); // or in contents from all the other entities - num = SV_AreaEdicts(p, p, touch, MAX_EDICTS, AREA_SOLID); + num= SV_AreaEdicts(p, p, touch, MAX_EDICTS, AREA_SOLID); - for (i = 0; i < num; i++) + for (i= 0; i < num; i++) { - hit = touch[i]; + hit= touch[i]; // might intersect, so do an exact clip - headnode = SV_HullForEntity(hit); - angles = hit.s.angles; + headnode= SV_HullForEntity(hit); + angles= hit.s.angles; if (hit.solid != SOLID_BSP) - angles = vec3_origin; // boxes don't rotate + angles= vec3_origin; // boxes don't rotate - c2 = CM.TransformedPointContents(p, headnode, hit.s.origin, hit.s.angles); + c2= CM.TransformedPointContents(p, headnode, hit.s.origin, hit.s.angles); contents |= c2; } @@ -514,7 +511,7 @@ public class SV_WORLD extends SV_CCMDS // decide which clipping hull to use, based on the size if (ent.solid == SOLID_BSP) { // explicit hulls in the BSP model - model = sv.models[ent.s.modelindex]; + model= sv.models[ent.s.modelindex]; if (null == model) Com.Error(ERR_FATAL, "MOVETYPE_PUSH with a non bsp model"); @@ -535,23 +532,23 @@ public class SV_WORLD extends SV_CCMDS ==================== */ + private static edict_t touchlist[]= new edict_t[MAX_EDICTS]; public static void SV_ClipMoveToEntities(moveclip_t clip) { int i, num; - // TODO: make static instead of new - edict_t touchlist[] = new edict_t[MAX_EDICTS]; + edict_t touch; trace_t trace; int headnode; float angles[]; - num = SV_AreaEdicts(clip.boxmins, clip.boxmaxs, touchlist, MAX_EDICTS, AREA_SOLID); + num= SV_AreaEdicts(clip.boxmins, clip.boxmaxs, touchlist, MAX_EDICTS, AREA_SOLID); // be careful, it is possible to have an entity in this // list removed before we get to it (killtriggered) - for (i = 0; i < num; i++) + for (i= 0; i < num; i++) { - touch = touchlist[i]; + touch= touchlist[i]; if (touch.solid == SOLID_NOT) continue; if (touch == clip.passedict) @@ -570,13 +567,13 @@ public class SV_WORLD extends SV_CCMDS continue; // might intersect, so do an exact clip - headnode = SV_HullForEntity(touch); - angles = touch.s.angles; + headnode= SV_HullForEntity(touch); + angles= touch.s.angles; if (touch.solid != SOLID_BSP) - angles = vec3_origin; // boxes don't rotate + angles= vec3_origin; // boxes don't rotate if ((touch.svflags & SVF_MONSTER) != 0) - trace = + trace= CM.TransformedBoxTrace( clip.start, clip.end, @@ -587,7 +584,7 @@ public class SV_WORLD extends SV_CCMDS touch.s.origin, angles); else - trace = + trace= CM.TransformedBoxTrace( clip.start, clip.end, @@ -600,17 +597,17 @@ public class SV_WORLD extends SV_CCMDS if (trace.allsolid || trace.startsolid || trace.fraction < clip.trace.fraction) { - trace.ent = touch; + trace.ent= touch; if (clip.trace.startsolid) { - clip.trace = trace; - clip.trace.startsolid = true; + clip.trace= trace; + clip.trace.startsolid= true; } else clip.trace.set(trace); } else if (trace.startsolid) - clip.trace.startsolid = true; + clip.trace.startsolid= true; } } @@ -623,17 +620,17 @@ public class SV_WORLD extends SV_CCMDS { int i; - for (i = 0; i < 3; i++) + for (i= 0; i < 3; i++) { if (end[i] > start[i]) { - boxmins[i] = start[i] + mins[i] - 1; - boxmaxs[i] = end[i] + maxs[i] + 1; + boxmins[i]= start[i] + mins[i] - 1; + boxmaxs[i]= end[i] + maxs[i] + 1; } else { - boxmins[i] = end[i] + mins[i] - 1; - boxmaxs[i] = start[i] + maxs[i] + 1; + boxmins[i]= end[i] + mins[i] - 1; + boxmaxs[i]= start[i] + maxs[i] + 1; } } @@ -651,27 +648,27 @@ public class SV_WORLD extends SV_CCMDS */ public static trace_t SV_Trace(float[] start, float[] mins, float[] maxs, float[] end, edict_t passedict, int contentmask) { - moveclip_t clip = new moveclip_t(); + moveclip_t clip= new moveclip_t(); if (mins == null) - mins = vec3_origin; + mins= vec3_origin; if (maxs == null) - maxs = vec3_origin; + maxs= vec3_origin; //memset ( clip, 0, sizeof ( moveclip_t ) ); // clip to world - clip.trace = CM.BoxTrace(start, end, mins, maxs, 0, contentmask); - clip.trace.ent = ge.edicts[0]; + clip.trace= CM.BoxTrace(start, end, mins, maxs, 0, contentmask); + clip.trace.ent= ge.edicts[0]; if (clip.trace.fraction == 0) return clip.trace; // blocked by the world - clip.contentmask = contentmask; - clip.start = start; - clip.end = end; - clip.mins = mins; - clip.maxs = maxs; - clip.passedict = passedict; + clip.contentmask= contentmask; + clip.start= start; + clip.end= end; + clip.mins= mins; + clip.maxs= maxs; + clip.passedict= passedict; VectorCopy(mins, clip.mins2); VectorCopy(maxs, clip.maxs2); |