📄 sv_user.java
字号:
/* * 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. * */// Created on 17.01.2004 by RST.// $Id: SV_USER.java,v 1.10 2005/12/17 20:32:01 salomo Exp $package jake2.server;import jake2.Defines;import jake2.Globals;import jake2.game.Cmd;import jake2.game.GameAI;import jake2.game.GameBase;import jake2.game.Info;import jake2.game.PlayerClient;import jake2.game.edict_t;import jake2.game.entity_state_t;import jake2.game.usercmd_t;import jake2.qcommon.Cbuf;import jake2.qcommon.Com;import jake2.qcommon.Cvar;import jake2.qcommon.FS;import jake2.qcommon.MSG;import jake2.qcommon.SZ;import jake2.util.Lib;import java.io.IOException;public class SV_USER { static edict_t sv_player; 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() { SV_USER.SV_New_f(); } }); static ucmd_t ucmds[] = { // auto issued new ucmd_t("new", new Runnable() { public void run() { SV_USER.SV_New_f(); } }), new ucmd_t("configstrings", new Runnable() { public void run() { SV_USER.SV_Configstrings_f(); } }), new ucmd_t("baselines", new Runnable() { public void run() { SV_USER.SV_Baselines_f(); } }), new ucmd_t("begin", new Runnable() { public void run() { SV_USER.SV_Begin_f(); } }), new ucmd_t("nextserver", new Runnable() { public void run() { SV_USER.SV_Nextserver_f(); } }), new ucmd_t("disconnect", new Runnable() { public void run() { SV_USER.SV_Disconnect_f(); } }), // issued by hand at client consoles new ucmd_t("info", new Runnable() { public void run() { SV_USER.SV_ShowServerinfo_f(); } }), new ucmd_t("download", new Runnable() { public void run() { SV_USER.SV_BeginDownload_f(); } }), new ucmd_t("nextdl", new Runnable() { public void run() { SV_USER.SV_NextDownload_f(); } }) }; public static final int MAX_STRINGCMDS = 8; /* * ============================================================ * * USER STRINGCMD EXECUTION * * sv_client and sv_player will be valid. * ============================================================ */ /* * ================== SV_BeginDemoServer ================== */ public static void SV_BeginDemoserver() { String name; name = "demos/" + SV_INIT.sv.name; try { SV_INIT.sv.demofile = FS.FOpenFile(name); } catch (IOException e) { Com.Error(Defines.ERR_DROP, "Couldn't open " + name + "\n"); } if (SV_INIT.sv.demofile == null) Com.Error(Defines.ERR_DROP, "Couldn't open " + name + "\n"); } /* * ================ SV_New_f * * Sends the first message from the server to a connected client. This will * be sent on the initial connection and upon each server load. * ================ */ public static void SV_New_f() { String gamedir; int 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; } // demo servers just dump the file message if (SV_INIT.sv.state == Defines.ss_demo) { SV_BeginDemoserver(); return; } // // 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"); // send the serverdata 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_client - svs.clients; playernum = SV_MAIN.sv_client.serverindex; MSG.WriteShort(SV_MAIN.sv_client.netchan.message, playernum); // send full levelname MSG.WriteString(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.configstrings[Defines.CS_NAME]); // // game server // if (SV_INIT.sv.state == Defines.ss_game) { // set up the entity for the client 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(); // begin fetching configstrings 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"); } } /* * ================== SV_Configstrings_f ================== */ public static void SV_Configstrings_f() { int 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; } // handle the case of a level changing while a client was connecting 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)); // write a packet full of data 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++; } // send next command 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"); } } /* * ================== SV_Baselines_f ================== */ public static void SV_Baselines_f() { int start; entity_state_t nullstate; entity_state_t base; 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; } // handle the case of a level changing while a client was connecting 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)); //memset (&nullstate, 0, sizeof(nullstate)); nullstate = new entity_state_t(null); // write a packet full of data while (SV_MAIN.sv_client.netchan.message.cursize < Defines.MAX_MSGLEN / 2 && start < Defines.MAX_EDICTS) { base = SV_INIT.sv.baselines[start]; if (base.modelindex != 0 || base.sound != 0 || base.effects != 0) { MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_spawnbaseline); MSG.WriteDeltaEntity(nullstate, base, SV_MAIN.sv_client.netchan.message, true, true); } start++; } // send next command 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"); } } /* * ================== SV_Begin_f ================== */ public static void SV_Begin_f() { Com.DPrintf("Begin() from " + SV_MAIN.sv_client.name + "\n"); // handle the case of a level changing while a client was connecting if (Lib.atoi(Cmd.Argv(1)) != SV_INIT.svs.spawncount) { Com.Printf("SV_Begin_f from different level\n"); SV_New_f(); return; } SV_MAIN.sv_client.state = Defines.cs_spawned; // call the game begin function PlayerClient.ClientBegin(SV_USER.sv_player); Cbuf.InsertFromDefer(); } //============================================================================= /* * ================== SV_NextDownload_f ================== */ public static void SV_NextDownload_f() { int r; int percent; int size;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -