📄 d_clisrv.c
字号:
// Emacs style mode select -*- C++ -*-//-----------------------------------------------------------------------------//// $Id: d_clisrv.c,v 1.37 2001/04/27 13:32:13 bpereira Exp $//// Copyright (C) 1998-2000 by DooM Legacy Team.//// 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.////// $Log: d_clisrv.c,v $// Revision 1.37 2001/04/27 13:32:13 bpereira// no message//// Revision 1.36 2001/04/01 17:35:06 bpereira// no message//// Revision 1.35 2001/03/30 17:12:49 bpereira// no message//// Revision 1.34 2001/03/03 06:17:33 bpereira// no message//// Revision 1.33 2001/02/24 13:35:19 bpereira// no message//// Revision 1.32 2001/02/10 12:27:13 bpereira// no message//// Revision 1.31 2001/01/25 22:15:41 bpereira// added heretic support//// Revision 1.30 2000/11/11 13:59:45 bpereira// no message//// Revision 1.29 2000/11/02 17:50:06 stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.28 2000/10/22 00:20:53 hurdler// Updated for the latest master server code//// Revision 1.27 2000/10/21 23:21:56 hurdler// Minor updates//// Revision 1.26 2000/10/21 08:43:28 bpereira// no message//// Revision 1.25 2000/10/17 10:09:27 hurdler// Update master server code for easy connect from menu//// Revision 1.24 2000/10/16 20:02:28 bpereira// no message//// Revision 1.23 2000/10/08 13:29:59 bpereira// no message//// Revision 1.22 2000/10/01 10:18:16 bpereira// no message//// Revision 1.21 2000/09/28 20:57:14 bpereira// no message//// Revision 1.20 2000/09/15 19:49:21 bpereira// no message//// Revision 1.19 2000/09/10 10:37:28 metzgermeister// *** empty log message ***//// Revision 1.18 2000/09/01 19:34:37 bpereira// no message//// Revision 1.17 2000/08/31 14:30:55 bpereira// no message//// Revision 1.16 2000/08/21 11:06:43 hurdler// Add ping and some fixes//// Revision 1.15 2000/08/16 15:44:18 hurdler// update master server code//// Revision 1.14 2000/08/16 14:10:01 hurdler// add master server code//// Revision 1.13 2000/08/11 19:10:13 metzgermeister// *** empty log message ***//// Revision 1.12 2000/08/11 12:25:23 hurdler// latest changes for v1.30//// Revision 1.11 2000/08/03 17:57:41 bpereira// no message//// Revision 1.10 2000/04/30 10:30:10 bpereira// no message//// Revision 1.9 2000/04/24 20:24:38 bpereira// no message//// Revision 1.8 2000/04/16 18:38:06 bpereira// no message//// Revision 1.7 2000/04/04 00:32:45 stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.6 2000/03/29 19:39:48 bpereira// no message//// Revision 1.5 2000/03/08 17:02:42 hurdler// fix the joiningame problem under Linux//// Revision 1.4 2000/03/06 16:51:08 hurdler// hack for OpenGL / Open Entry problem//// Revision 1.3 2000/02/27 16:30:28 hurdler// dead player bug fix + add allowmlook <yes|no>//// Revision 1.2 2000/02/27 00:42:10 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:32 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// DOOM Network game communication and protocol,// all OS independend parts.////-----------------------------------------------------------------------------#include <time.h>#if defined (__DJGPP__) || defined (LINUX)#include <unistd.h>#endif#include "doomdef.h"#include "command.h"#include "i_net.h"#include "i_system.h"#include "i_video.h"#include "d_net.h"#include "d_netcmd.h"#include "d_main.h"#include "g_game.h"#include "hu_stuff.h"#include "keys.h"#include "doomstat.h"#include "m_argv.h"#include "m_menu.h"#include "console.h"#include "d_netfil.h"#include "byteptr.h"#include "p_saveg.h"#include "p_setup.h"#include "z_zone.h"#include "p_tick.h"#include "p_local.h"#include "m_misc.h"#include "am_map.h"#include "m_random.h"#include "d_clisrv.h"#include "mserv.h"//// NETWORKING//// gametic is the tic about to (or currently being) run// maketic is the tic that hasn't had control made for it yet// server:// nettics is the tic for eatch node// firstticstosend is the lowest value of nettics// client:// neededtic is the tic needed by the client for run the game// firstticstosend is used to optimize a condition// normaly maketic>=gametic>0,#define PREDICTIONQUEUE BACKUPTICS#define PREDICTIONMASK (PREDICTIONQUEUE-1)boolean server = true; // true or false but !server=clientboolean serverrunning = false;char serverplayer;// server specific varsstatic byte playernode[MAXPLAYERS];static tic_t cl_maketic[MAXNETNODES];static char nodetoplayer[MAXNETNODES];static char nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen)static byte playerpernode[MAXNETNODES]; // used specialy for scplitscreenstatic boolean nodeingame[MAXNETNODES]; // set false as nodes leave gamestatic tic_t nettics[MAXNETNODES]; // what tic the client have receivedstatic tic_t supposedtics[MAXNETNODES];// nettics prevision for smaller packetstatic byte nodewaiting[MAXNETNODES];static tic_t firstticstosend; // min of the netticsstatic short consistancy[BACKUPTICS];static tic_t tictoclear=0; // optimize d_clearticcmdstatic tic_t maketic;#ifdef CLIENTPREDICTION2tic_t localgametic;#endifboolean dedicated; // dedicate server// client specificstatic ticcmd_t localcmds;static ticcmd_t localcmds2;static boolean cl_packetmissed;boolean drone;// here it is for the secondary local player (splitscreen)static byte mynode; // my address pointofview serverstatic byte localtextcmd[MAXTEXTCMD];static byte localtextcmd2[MAXTEXTCMD]; // splitscreenstatic tic_t neededtic;char servernode; // the number of the server node// engineticcmd_t netcmds[BACKUPTICS][MAXPLAYERS];static byte textcmds[BACKUPTICS][MAXPLAYERS][MAXTEXTCMD];boolean notimecheck; // check file time through network ?consvar_t cv_playdemospeed = {"playdemospeed","0",0,CV_Unsigned};// some software don't support largest packet// (original sersetup, not exactely, but the probabylity of sending a packet// of 512 octet is like 0.1)USHORT software_MAXPACKETLENGTH;int ExpandTics (int low){ int delta; delta = low - (maketic&0xff); if (delta >= -64 && delta <= 64) return (maketic&~0xff) + low; if (delta > 64) return (maketic&~0xff) - 256 + low; if (delta < -64) return (maketic&~0xff) + 256 + low;#ifdef PARANOIA I_Error ("ExpandTics: strange value %i at maketic %i",low,maketic);#endif return 0;}// -----------------------------------------------------------------// Some extra data function for handle textcmd buffer// -----------------------------------------------------------------static void (*listnetxcmd[MAXNETXCMD])(char **p,int playernum);void RegisterNetXCmd(netxcmd_t id,void (*cmd_f) (char **p,int playernum)){#ifdef PARANOIA if(id>=MAXNETXCMD) I_Error("command id %d too big",id); if(listnetxcmd[id]!=0) I_Error("Command id %d already used",id);#endif listnetxcmd[id]=cmd_f;}void SendNetXCmd(byte id,void *param,int nparam){ if(demoplayback) return; if(localtextcmd[0]+1+nparam>MAXTEXTCMD) {#ifdef PARANOIA I_Error("No more place in the buffer for netcmd %d\n",id);#else CONS_Printf("\2Net Command fail\n");#endif return; } localtextcmd[0]++; localtextcmd[localtextcmd[0]]=id; if(param && nparam) { memcpy(&localtextcmd[localtextcmd[0]+1],param,nparam); localtextcmd[0]+=nparam; }}// splitscreen playervoid SendNetXCmd2(byte id,void *param,int nparam){ if(demoplayback) return; if(localtextcmd2[0]+1+nparam>MAXTEXTCMD) {#ifdef PARANOIA I_Error("No more place in the buffer for netcmd %d\n",id);#else CONS_Printf("\2Net Command fail\n");#endif return; } localtextcmd2[0]++; localtextcmd2[localtextcmd2[0]]=id; if(param && nparam) { memcpy(&localtextcmd2[localtextcmd2[0]+1],param,nparam); localtextcmd2[0]+=nparam; }}static void ExtraDataTicker(void){ int i,tic; byte *curpos,*bufferend; tic=gametic % BACKUPTICS; for(i=0;i<MAXPLAYERS;i++) if((playeringame[i]) || (i==0)) { curpos=(byte *)&(textcmds[tic][i]); bufferend=&curpos[curpos[0]+1]; curpos++; while(curpos<bufferend) { if(*curpos < MAXNETXCMD && listnetxcmd[*curpos]) { byte id=*curpos; curpos++; DEBFILE(va("executing x_cmd %d ply %d ",id,i)); (listnetxcmd[id])((char **)&curpos,i); DEBFILE("done\n"); } else I_Error("Got unknow net command [%d]=%d (max %d)\n" ,curpos-(byte *)&(textcmds[tic][i]) ,*curpos,textcmds[tic][i][0]); } }}static void D_Clearticcmd(int tic){ int i; for(i=0;i<MAXPLAYERS;i++) { textcmds[tic%BACKUPTICS][i][0]=0; netcmds[tic%BACKUPTICS][i].angleturn = 0; //&= ~TICCMD_RECEIVED; } DEBFILE(va("clear tic %5d (%2d)\n",tic,tic%BACKUPTICS));}// -----------------------------------------------------------------// end of extra data function// -----------------------------------------------------------------// -----------------------------------------------------------------// extra data function for lmps// -----------------------------------------------------------------// desciption of extradate byte of LEGACY 1.12 not the same of the 1.20// 1.20 don't have the extradata bits fields but a byte for eatch command// see XD_xxx in d_netcmd.h//// if extradatabit is set, after the ziped tic you find this ://// type | description// ---------+--------------// byte | size of the extradata// byte | the extradata (xd) bits : see XD_...// with this byte you know what parameter folow// if(xd & XDNAMEANDCOLOR)// byte | color// char[MAXPLAYERNAME] | name of the player// endif// if(xd & XD_WEAPON_PREF)// byte | original weapon switch : boolean, true if use the old// | weapon switch methode// char[NUMWEAPONS] | the weapon switch priority// byte | autoaim : true if use the old autoaim system// endifboolean AddLmpExtradata(byte **demo_point,int playernum){ int tic; tic=gametic % BACKUPTICS; if(textcmds[tic][playernum][0]==0) return false; memcpy(*demo_point,textcmds[tic][playernum],textcmds[tic][playernum][0]+1); *demo_point += textcmds[tic][playernum][0]+1; return true;}void ReadLmpExtraData(byte **demo_pointer,int playernum){ unsigned char nextra,ex; if(!demo_pointer) { textcmds[gametic%BACKUPTICS][playernum][0]=0; return; } nextra=**demo_pointer; if(demoversion==112) // support old demos v1.12 { int size=0; char *p=*demo_pointer+1; // skip nextra textcmds[gametic%BACKUPTICS][playernum][0]=0; ex=*p++; if(ex & 1) { size=textcmds[gametic%BACKUPTICS][playernum][0]; textcmds[gametic%BACKUPTICS][playernum][size+1]=XD_NAMEANDCOLOR; memcpy(&textcmds[gametic%BACKUPTICS][playernum][size+2], p, MAXPLAYERNAME+1); p+=MAXPLAYERNAME+1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -