From 760e784ffcf52904d2ac256a006053abc3289827 Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 12 Dec 2006 08:33:11 +0000 Subject: [PATCH] Multiplayer code for "map" and "changelevel" git-svn-id: https://svn.eduke32.com/eduke32@413 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 9 +- polymer/eduke32/source/osdcmds.c | 161 +++++++++++++++++++++++++------ 2 files changed, 134 insertions(+), 36 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index d860be280..ceec1dd14 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -9328,6 +9328,7 @@ static void Startup(long argc, char **argv) char *dot, *slash; boardfilename[0] = '/'; + boardfilename[1] = 0; Bstrcat(boardfilename, CommandMap); dot = Bstrrchr(boardfilename,'.'); @@ -9493,18 +9494,18 @@ void sendboardname(void) int j; int ch; - tempbuf[0] = 9; - tempbuf[1] = 0; + packbuf[0] = 9; + packbuf[1] = 0; Bcorrectfilename(boardfilename,0); j = Bstrlen(boardfilename); boardfilename[j] = 0; - Bstrcat(tempbuf+1,boardfilename); + Bstrcat(packbuf+1,boardfilename); for (ch=connecthead;ch >= 0;ch=connectpoint2[ch]) { - if (ch != myconnectindex) sendpacket(ch,tempbuf,j+1); + if (ch != myconnectindex) sendpacket(ch,packbuf,j+1); if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master } } diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index a67be6b41..408d7dec3 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "crc32.h" #include +extern int gotvote[MAXPLAYERS], votes[MAXPLAYERS], voting; struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat; int osdcmd_quit(const osdfuncparm_t *parm) @@ -97,6 +98,65 @@ int osdcmd_changelevel(const osdfuncparm_t *parm) } } + if (numplayers > 1) + { + if (myconnectindex == connecthead && networkmode == 0) + { + int i; + + tempbuf[0] = 5; + tempbuf[1] = ud.m_level_number = level; + tempbuf[2] = ud.m_volume_number = volume; + tempbuf[3] = ud.m_player_skill; + tempbuf[4] = ud.m_monsters_off; + tempbuf[5] = ud.m_respawn_monsters; + tempbuf[6] = ud.m_respawn_items; + tempbuf[7] = ud.m_respawn_inventory; + tempbuf[8] = ud.m_coop; + tempbuf[9] = ud.m_marker; + tempbuf[10] = ud.m_ffire; + tempbuf[11] = ud.m_noexits; + + for (i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) sendpacket(i,tempbuf,12); + if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + } + else if (voting == -1) + { + ud.m_volume_number = volume; + ud.m_level_number = level; + + if (ps[myconnectindex].i) + { + int i; + + Bmemset(votes,0,sizeof(votes)); + Bmemset(gotvote,0,sizeof(gotvote)); + votes[myconnectindex] = gotvote[myconnectindex] = 1; + voting = myconnectindex; + + tempbuf[0] = 18; + tempbuf[1] = 1; + tempbuf[2] = myconnectindex; + tempbuf[3] = ud.m_volume_number; + tempbuf[4] = ud.m_level_number; + + for (i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) sendpacket(i,tempbuf,5); + if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + } + if ((gametype_flags[ud.m_coop] & GAMETYPE_FLAG_PLAYERSFRIENDLY) && !(gametype_flags[ud.m_coop] & GAMETYPE_FLAG_TDM)) + ud.m_noexits = 0; + + ps[myconnectindex].gm |= MODE_MENU; + cmenu(603); + } + return OSDCMD_OK; + } if (ps[myconnectindex].gm & MODE_GAME) { // in-game behave like a cheat @@ -133,13 +193,15 @@ int osdcmd_map(const osdfuncparm_t *parm) if (parm->numparms != 1) return OSDCMD_SHOWHELP; +#if 0 if (numplayers > 1) { OSD_Printf("Command not allowed in multiplayer\n"); return OSDCMD_OK; } - filename[0] = '/'; - strcat(filename,parm->parms[0]); +#endif + + strcpy(filename,parm->parms[0]); if (strchr(filename,'.') == 0) strcat(filename,".map"); @@ -150,9 +212,72 @@ int osdcmd_map(const osdfuncparm_t *parm) } kclose(i); - strcpy(boardfilename, filename); + boardfilename[0] = '/'; + boardfilename[1] = 0; + strcat(boardfilename, filename); + + if (numplayers > 1) + { + if (myconnectindex == connecthead && networkmode == 0) + { + sendboardname(); + + tempbuf[0] = 5; + tempbuf[1] = ud.m_level_number = 7; + tempbuf[2] = ud.m_volume_number = 0; + tempbuf[3] = ud.m_player_skill; + tempbuf[4] = ud.m_monsters_off; + tempbuf[5] = ud.m_respawn_monsters; + tempbuf[6] = ud.m_respawn_items; + tempbuf[7] = ud.m_respawn_inventory; + tempbuf[8] = ud.m_coop; + tempbuf[9] = ud.m_marker; + tempbuf[10] = ud.m_ffire; + tempbuf[11] = ud.m_noexits; + + for (i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) sendpacket(i,tempbuf,12); + if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + } + else if (voting == -1) + { + sendboardname(); + + ud.m_volume_number = 0; + ud.m_level_number = 7; + + if (ps[myconnectindex].i) + { + int i; + + Bmemset(votes,0,sizeof(votes)); + Bmemset(gotvote,0,sizeof(gotvote)); + votes[myconnectindex] = gotvote[myconnectindex] = 1; + voting = myconnectindex; + + tempbuf[0] = 18; + tempbuf[1] = 1; + tempbuf[2] = myconnectindex; + tempbuf[3] = ud.m_volume_number; + tempbuf[4] = ud.m_level_number; + + for (i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) sendpacket(i,tempbuf,5); + if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + } + if ((gametype_flags[ud.m_coop] & GAMETYPE_FLAG_PLAYERSFRIENDLY) && !(gametype_flags[ud.m_coop] & GAMETYPE_FLAG_TDM)) + ud.m_noexits = 0; + + ps[myconnectindex].gm |= MODE_MENU; + cmenu(603); + } + return OSDCMD_OK; + } - Bcorrectfilename(boardfilename,0); if (ps[myconnectindex].gm & MODE_GAME) { @@ -752,33 +877,6 @@ int osdcmd_usemousejoy(const osdfuncparm_t *parm) return OSDCMD_SHOWHELP; } -int osdcmd_mpmap(const osdfuncparm_t *parm) -{ - int i; - char filename[256]; - - if (parm->numparms != 1) return OSDCMD_SHOWHELP; - - strcpy(filename,parm->parms[0]); - if (strchr(filename,'.') == 0) - strcat(filename,".map"); - - if ((i = kopen4load(filename,0)) < 0) - { - OSD_Printf("map: file \"%s\" not found.\n", filename); - return OSDCMD_OK; - } - kclose(i); - - strcpy(boardfilename, filename); - - Bcorrectfilename(boardfilename,0); - - sendboardname(); - - return OSDCMD_OK; -} - int osdcmd_name(const osdfuncparm_t *parm) { if (parm->numparms != 1) @@ -819,7 +917,6 @@ int registerosdcommands(void) { OSD_RegisterFunction("changelevel","changelevel : warps to the given level", osdcmd_changelevel); OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); - OSD_RegisterFunction("mpmap","mpmap : sets user map name in multiplayer", osdcmd_mpmap); } OSD_RegisterFunction("addpath","addpath : adds path to game filesystem", osdcmd_addpath);