📄 playerclient.java
字号:
ent.model = "players/male/tris.md2"; ent.pain = PlayerClient.player_pain; ent.die = PlayerClient.player_die; ent.waterlevel = 0; ent.watertype = 0; ent.flags &= ~Defines.FL_NO_KNOCKBACK; ent.svflags &= ~Defines.SVF_DEADMONSTER; Math3D.VectorCopy(mins, ent.mins); Math3D.VectorCopy(maxs, ent.maxs); Math3D.VectorClear(ent.velocity); // clear playerstate values ent.client.ps.clear(); client.ps.pmove.origin[0] = (short) (spawn_origin[0] * 8); client.ps.pmove.origin[1] = (short) (spawn_origin[1] * 8); client.ps.pmove.origin[2] = (short) (spawn_origin[2] * 8); if (GameBase.deathmatch.value != 0 && 0 != ((int) GameBase.dmflags.value & Defines.DF_FIXED_FOV)) { client.ps.fov = 90; } else { client.ps.fov = Lib.atoi(Info.Info_ValueForKey( client.pers.userinfo, "fov")); if (client.ps.fov < 1) client.ps.fov = 90; else if (client.ps.fov > 160) client.ps.fov = 160; } client.ps.gunindex = GameBase.gi .modelindex(client.pers.weapon.view_model); // clear entity state values ent.s.effects = 0; ent.s.modelindex = 255; // will use the skin specified model ent.s.modelindex2 = 255; // custom gun model // sknum is player num and weapon number // weapon number will be added in changeweapon ent.s.skinnum = ent.index - 1; ent.s.frame = 0; Math3D.VectorCopy(spawn_origin, ent.s.origin); ent.s.origin[2] += 1; // make sure off ground Math3D.VectorCopy(ent.s.origin, ent.s.old_origin); // set the delta angle for (i = 0; i < 3; i++) { client.ps.pmove.delta_angles[i] = (short) Math3D .ANGLE2SHORT(spawn_angles[i] - client.resp.cmd_angles[i]); } ent.s.angles[Defines.PITCH] = 0; ent.s.angles[Defines.YAW] = spawn_angles[Defines.YAW]; ent.s.angles[Defines.ROLL] = 0; Math3D.VectorCopy(ent.s.angles, client.ps.viewangles); Math3D.VectorCopy(ent.s.angles, client.v_angle); // spawn a spectator if (client.pers.spectator) { client.chase_target = null; client.resp.spectator = true; ent.movetype = Defines.MOVETYPE_NOCLIP; ent.solid = Defines.SOLID_NOT; ent.svflags |= Defines.SVF_NOCLIENT; ent.client.ps.gunindex = 0; GameBase.gi.linkentity(ent); return; } else client.resp.spectator = false; if (!GameUtil.KillBox(ent)) { // could't spawn in? } GameBase.gi.linkentity(ent); // force the current weapon up client.newweapon = client.pers.weapon; PlayerWeapon.ChangeWeapon(ent); } /** * A client has just connected to the server in deathmatch mode, so clear * everything out before starting them. */ public static void ClientBeginDeathmatch(edict_t ent) { GameUtil.G_InitEdict(ent, ent.index); InitClientResp(ent.client); // locate ent at a spawn point PutClientInServer(ent); if (GameBase.level.intermissiontime != 0) { PlayerHud.MoveClientToIntermission(ent); } else { // send effect GameBase.gi.WriteByte(Defines.svc_muzzleflash); //gi.WriteShort(ent - g_edicts); GameBase.gi.WriteShort(ent.index); GameBase.gi.WriteByte(Defines.MZ_LOGIN); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PVS); } GameBase.gi.bprintf(Defines.PRINT_HIGH, ent.client.pers.netname + " entered the game\n"); // make sure all view stuff is valid PlayerView.ClientEndServerFrame(ent); } /** * Called when a client has finished connecting, and is ready to be placed * into the game. This will happen every level load. */ public static void ClientBegin(edict_t ent) { int i; //ent.client = game.clients + (ent - g_edicts - 1); ent.client = GameBase.game.clients[ent.index - 1]; if (GameBase.deathmatch.value != 0) { ClientBeginDeathmatch(ent); return; } // if there is already a body waiting for us (a loadgame), just // take it, otherwise spawn one from scratch if (ent.inuse == true) { // the client has cleared the client side viewangles upon // connecting to the server, which is different than the // state when the game is saved, so we need to compensate // with deltaangles for (i = 0; i < 3; i++) ent.client.ps.pmove.delta_angles[i] = (short) Math3D .ANGLE2SHORT(ent.client.ps.viewangles[i]); } else { // a spawn point will completely reinitialize the entity // except for the persistant data that was initialized at // ClientConnect() time GameUtil.G_InitEdict(ent, ent.index); ent.classname = "player"; InitClientResp(ent.client); PutClientInServer(ent); } if (GameBase.level.intermissiontime != 0) { PlayerHud.MoveClientToIntermission(ent); } else { // send effect if in a multiplayer game if (GameBase.game.maxclients > 1) { GameBase.gi.WriteByte(Defines.svc_muzzleflash); GameBase.gi.WriteShort(ent.index); GameBase.gi.WriteByte(Defines.MZ_LOGIN); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PVS); GameBase.gi.bprintf(Defines.PRINT_HIGH, ent.client.pers.netname + " entered the game\n"); } } // make sure all view stuff is valid PlayerView.ClientEndServerFrame(ent); } /** * Called whenever the player updates a userinfo variable. * * The game can override any of the settings in place (forcing skins or * names, etc) before copying it off. * */ public static String ClientUserinfoChanged(edict_t ent, String userinfo) { String s; int playernum; // check for malformed or illegal info strings if (!Info.Info_Validate(userinfo)) { return "\\name\\badinfo\\skin\\male/grunt"; } // set name s = Info.Info_ValueForKey(userinfo, "name"); ent.client.pers.netname = s; // set spectator s = Info.Info_ValueForKey(userinfo, "spectator"); // spectators are only supported in deathmatch if (GameBase.deathmatch.value != 0 && !s.equals("0")) ent.client.pers.spectator = true; else ent.client.pers.spectator = false; // set skin s = Info.Info_ValueForKey(userinfo, "skin"); playernum = ent.index - 1; // combine name and skin into a configstring GameBase.gi.configstring(Defines.CS_PLAYERSKINS + playernum, ent.client.pers.netname + "\\" + s); // fov if (GameBase.deathmatch.value != 0 && 0 != ((int) GameBase.dmflags.value & Defines.DF_FIXED_FOV)) { ent.client.ps.fov = 90; } else { ent.client.ps.fov = Lib .atoi(Info.Info_ValueForKey(userinfo, "fov")); if (ent.client.ps.fov < 1) ent.client.ps.fov = 90; else if (ent.client.ps.fov > 160) ent.client.ps.fov = 160; } // handedness s = Info.Info_ValueForKey(userinfo, "hand"); if (s.length() > 0) { ent.client.pers.hand = Lib.atoi(s); } // save off the userinfo in case we want to check something later ent.client.pers.userinfo = userinfo; return userinfo; } /** * Called when a player begins connecting to the server. The game can refuse * entrance to a client by returning false. If the client is allowed, the * connection process will continue and eventually get to ClientBegin() * Changing levels will NOT cause this to be called again, but loadgames * will. */ public static boolean ClientConnect(edict_t ent, String userinfo) { String value; // check to see if they are on the banned IP list value = Info.Info_ValueForKey(userinfo, "ip"); if (GameSVCmds.SV_FilterPacket(value)) { userinfo = Info.Info_SetValueForKey(userinfo, "rejmsg", "Banned."); return false; } // check for a spectator value = Info.Info_ValueForKey(userinfo, "spectator"); if (GameBase.deathmatch.value != 0 && value.length() != 0 && 0 != Lib.strcmp(value, "0")) { int i, numspec; if (!passwdOK(GameBase.spectator_password.string, value)) { userinfo = Info.Info_SetValueForKey(userinfo, "rejmsg", "Spectator password required or incorrect."); return false; } // count spectators for (i = numspec = 0; i < GameBase.maxclients.value; i++) if (GameBase.g_edicts[i + 1].inuse && GameBase.g_edicts[i + 1].client.pers.spectator) numspec++; if (numspec >= GameBase.maxspectators.value) { userinfo = Info.Info_SetValueForKey(userinfo, "rejmsg", "Server spectator limit is full."); return false; } } else { // check for a password value = Info.Info_ValueForKey(userinfo, "password"); if (!passwdOK(GameBase.spectator_password.string, value)) { userinfo = Info.Info_SetValueForKey(userinfo, "rejmsg", "Password required or incorrect."); return false; } } // they can connect ent.client = GameBase.game.clients[ent.index - 1]; // if there is already a body waiting for us (a loadgame), just // take it, otherwise spawn one from scratch if (ent.inuse == false) { // clear the respawning variables InitClientResp(ent.client); if (!GameBase.game.autosaved || null == ent.client.pers.weapon) InitClientPersistant(ent.client); } userinfo = ClientUserinfoChanged(ent, userinfo); if (GameBase.game.maxclients > 1) GameBase.gi.dprintf(ent.client.pers.netname + " connected\n"); ent.svflags = 0; // make sure we start with known default ent.client.pers.connected = true; return true; } /** * Called when a player drops from the server. Will not be called between levels. */ public static void ClientDisconnect(edict_t ent) { int playernum; if (ent.client == null) return; GameBase.gi.bprintf(Defines.PRINT_HIGH, ent.client.pers.netname + " disconnected\n"); // send effect GameBase.gi.WriteByte(Defines.svc_muzzleflash); GameBase.gi.WriteShort(ent.index); GameBase.gi.WriteByte(Defines.MZ_LOGOUT); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PVS); GameBase.gi.unlinkentity(ent); ent.s.modelindex = 0; ent.solid = Defines.SOLID_NOT; ent.inuse = false; ent.classname = "disconnected"; ent.client.pers.connected = false; playernum = ent.index - 1; GameBase.gi.configstring(Defines.CS_PLAYERSKINS + playernum, ""); } /* * static int CheckBlock(int c) * { * int v, i; * v = 0; * for (i = 0; i < c; i++) * v += ((byte *) b)[i]; * return v; * } * * public static void PrintPmove(pmove_t * pm) * { * unsigned c1, c2; * * c1 = CheckBlock(&pm.s, sizeof(pm.s)); * c2 = CheckBlock(&pm.cmd, sizeof(pm.cmd));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -