Check password and etc before downloading files

This commit is contained in:
fickleheart 2019-03-09 13:30:22 -06:00
parent 6bba2f16c0
commit 2954b68e12
3 changed files with 79 additions and 11 deletions

View file

@ -1128,18 +1128,21 @@ typedef enum
#endif #endif
CL_CONNECTED, CL_CONNECTED,
CL_ABORTED, CL_ABORTED,
CL_ASKDOWNLOADFILES,
CL_WAITDOWNLOADFILESRESPONSE,
CL_CHALLENGE CL_CHALLENGE
} cl_mode_t; } cl_mode_t;
static void GetPackets(void); static void GetPackets(void);
static cl_mode_t cl_mode = CL_SEARCHING; static cl_mode_t cl_mode = CL_SEARCHING;
static boolean cl_needsdownload = false;
static UINT8 cl_challengenum = 0; static UINT8 cl_challengenum = 0;
static UINT8 cl_challengequestion[17]; static UINT8 cl_challengequestion[17];
static char cl_challengepassword[65]; static char cl_challengepassword[65];
static UINT8 cl_challengeanswer[17]; static UINT8 cl_challengeanswer[17];
static boolean cl_challengeattempted; static UINT8 cl_challengeattempted = 0;
// Player name send/load // Player name send/load
@ -1237,6 +1240,9 @@ static inline void CL_DrawConnectionStatus(void)
case CL_WAITJOINRESPONSE: case CL_WAITJOINRESPONSE:
cltext = M_GetText("Requesting to join..."); cltext = M_GetText("Requesting to join...");
break; break;
case CL_ASKDOWNLOADFILES:
case CL_WAITDOWNLOADFILESRESPONSE:
cltext = M_GetText("Waiting to download files...");
default: default:
cltext = M_GetText("Connecting to server..."); cltext = M_GetText("Connecting to server...");
break; break;
@ -1314,6 +1320,7 @@ static boolean CL_SendJoin(void)
netbuffer->u.clientcfg.localplayers = localplayers; netbuffer->u.clientcfg.localplayers = localplayers;
netbuffer->u.clientcfg.version = VERSION; netbuffer->u.clientcfg.version = VERSION;
netbuffer->u.clientcfg.subversion = SUBVERSION; netbuffer->u.clientcfg.subversion = SUBVERSION;
netbuffer->u.clientcfg.needsdownload = cl_needsdownload;
netbuffer->u.clientcfg.challengenum = cl_challengenum; netbuffer->u.clientcfg.challengenum = cl_challengenum;
memcpy(netbuffer->u.clientcfg.challengeanswer, cl_challengeanswer, 16); memcpy(netbuffer->u.clientcfg.challengeanswer, cl_challengeanswer, 16);
@ -1989,9 +1996,12 @@ static boolean CL_ServerConnectionSearchTicker(boolean viams, tic_t *asksent)
), NULL, MM_NOTHING); ), NULL, MM_NOTHING);
return false; return false;
} }
cl_mode = CL_ASKDOWNLOADFILES;
// no problem if can't send packet, we will retry later // no problem if can't send packet, we will retry later
if (CL_SendRequestFile()) //if (CL_SendRequestFile())
cl_mode = CL_DOWNLOADFILES; // cl_mode = CL_DOWNLOADFILES;
} }
} }
else else
@ -2059,6 +2069,7 @@ static boolean CL_ServerConnectionTicker(boolean viams, const char *tmpsave, tic
/* FALLTHRU */ /* FALLTHRU */
case CL_ASKJOIN: case CL_ASKJOIN:
cl_needsdownload = false;
CL_LoadServerFiles(); CL_LoadServerFiles();
#ifdef JOININGAME #ifdef JOININGAME
// prepare structures to save the file // prepare structures to save the file
@ -2070,6 +2081,14 @@ static boolean CL_ServerConnectionTicker(boolean viams, const char *tmpsave, tic
cl_mode = CL_WAITJOINRESPONSE; cl_mode = CL_WAITJOINRESPONSE;
break; break;
case CL_ASKDOWNLOADFILES:
cl_needsdownload = true;
if (CL_SendJoin())
cl_mode = CL_WAITDOWNLOADFILESRESPONSE;
break;
#ifdef JOININGAME #ifdef JOININGAME
case CL_DOWNLOADSAVEGAME: case CL_DOWNLOADSAVEGAME:
// At this state, the first (and only) needed file is the gamestate // At this state, the first (and only) needed file is the gamestate
@ -2085,6 +2104,7 @@ static boolean CL_ServerConnectionTicker(boolean viams, const char *tmpsave, tic
case CL_CHALLENGE: case CL_CHALLENGE:
case CL_WAITJOINRESPONSE: case CL_WAITJOINRESPONSE:
case CL_WAITDOWNLOADFILESRESPONSE:
case CL_CONNECTED: case CL_CONNECTED:
default: default:
break; break;
@ -2193,7 +2213,7 @@ boolean CL_Responder(event_t *ev)
cl_challengepassword[len] = ch; cl_challengepassword[len] = ch;
} }
cl_challengeattempted = false; cl_challengeattempted = 0;
} }
else if (ch == KEY_BACKSPACE) else if (ch == KEY_BACKSPACE)
{ {
@ -2202,14 +2222,14 @@ boolean CL_Responder(event_t *ev)
if (len > 0) if (len > 0)
cl_challengepassword[len-1] = 0; cl_challengepassword[len-1] = 0;
cl_challengeattempted = false; cl_challengeattempted = 0;
} }
else if (ch == KEY_ENTER) else if (ch == KEY_ENTER)
{ {
// Done? // Done?
D_ComputeChallengeAnswer(cl_challengequestion, cl_challengepassword, cl_challengeanswer); D_ComputeChallengeAnswer(cl_challengequestion, cl_challengepassword, cl_challengeanswer);
cl_mode = CL_ASKJOIN; cl_mode = cl_needsdownload ? CL_ASKDOWNLOADFILES : CL_ASKJOIN;
cl_challengeattempted = true; cl_challengeattempted = 1;
} }
return true; return true;
@ -2293,7 +2313,7 @@ static void CL_ConnectToServer(boolean viams)
SL_ClearServerList(servernode); SL_ClearServerList(servernode);
#endif #endif
cl_challengeattempted = false; cl_challengeattempted = 0;
do do
{ {
@ -3753,6 +3773,13 @@ static void HandleConnect(SINT8 node)
} }
} }
if (netbuffer->u.clientcfg.needsdownload)
{
netbuffer->packettype = PT_DOWNLOADFILESOKAY;
HSendPacket(node, true, 0, 0);
return;
}
// client authorised to join // client authorised to join
nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]);
if (!nodeingame[node]) if (!nodeingame[node])
@ -3761,6 +3788,7 @@ static void HandleConnect(SINT8 node)
#ifndef NONET #ifndef NONET
newnode = true; newnode = true;
#endif #endif
SV_AddNode(node); SV_AddNode(node);
/// \note Wait what??? /// \note Wait what???
@ -3927,12 +3955,19 @@ static void HandlePacketFromAwayNode(SINT8 node)
break; break;
} }
SERVERONLY SERVERONLY
if (cl_mode == CL_WAITJOINRESPONSE) if (cl_mode == CL_WAITJOINRESPONSE || cl_mode == CL_WAITDOWNLOADFILESRESPONSE)
{ {
cl_challengenum = netbuffer->u.joinchallenge.challengenum; cl_challengenum = netbuffer->u.joinchallenge.challengenum;
memcpy(cl_challengequestion, netbuffer->u.joinchallenge.question, 16); memcpy(cl_challengequestion, netbuffer->u.joinchallenge.question, 16);
cl_mode = CL_CHALLENGE; cl_mode = CL_CHALLENGE;
if (cl_challengeattempted == 2)
{
// We already sent a correct password, so throw it back up again.
D_ComputeChallengeAnswer(cl_challengequestion, cl_challengepassword, cl_challengeanswer);
cl_mode = CL_ASKJOIN;
}
} }
break; break;
@ -3964,6 +3999,38 @@ static void HandlePacketFromAwayNode(SINT8 node)
} }
break; break;
case PT_DOWNLOADFILESOKAY:
if (server && serverrunning)
{ // But wait I thought I'm the server?
Net_CloseConnection(node);
break;
}
SERVERONLY
// This should've already been checked, but just to be safe...
if (!CL_CheckDownloadable())
{
D_QuitNetGame();
CL_Reset();
D_StartTitle();
M_StartMessage(M_GetText(
"You cannot connect to this server\n"
"because you cannot download the files\n"
"that you are missing from the server.\n\n"
"See the console or log file for\n"
"more details.\n\n"
"Press ESC\n"
), NULL, MM_NOTHING);
break;
}
cl_challengeattempted = 2;
CONS_Printf("trying to download\n");
if (CL_SendRequestFile())
cl_mode = CL_DOWNLOADFILES;
break;
case PT_SERVERCFG: // Positive response of client join request case PT_SERVERCFG: // Positive response of client join request
{ {
INT32 j; INT32 j;

View file

@ -75,6 +75,7 @@ typedef enum
PT_BASICKEEPALIVE,// Keep the network alive during wipes, as tics aren't advanced and NetUpdate isn't called PT_BASICKEEPALIVE,// Keep the network alive during wipes, as tics aren't advanced and NetUpdate isn't called
PT_JOINCHALLENGE, // You must give a password to joinnnnn PT_JOINCHALLENGE, // You must give a password to joinnnnn
PT_DOWNLOADFILESOKAY, // You can download files from the server....
PT_CANFAIL, // This is kind of a priority. Anything bigger than CANFAIL PT_CANFAIL, // This is kind of a priority. Anything bigger than CANFAIL
// allows HSendPacket(*, true, *, *) to return false. // allows HSendPacket(*, true, *, *) to return false.
@ -356,7 +357,7 @@ typedef struct
UINT8 version; // Different versions don't work UINT8 version; // Different versions don't work
UINT8 subversion; // Contains build version UINT8 subversion; // Contains build version
UINT8 localplayers; UINT8 localplayers;
UINT8 mode; UINT8 needsdownload;
UINT8 challengenum; // Non-zero if trying to join with a password attempt UINT8 challengenum; // Non-zero if trying to join with a password attempt
UINT8 challengeanswer[16]; // Join challenge UINT8 challengeanswer[16]; // Join challenge
} ATTRPACK clientconfig_pak; } ATTRPACK clientconfig_pak;

View file

@ -868,7 +868,7 @@ static void DebugPrintpacket(const char *header)
break; break;
case PT_CLIENTJOIN: case PT_CLIENTJOIN:
fprintf(debugfile, " number %d mode %d\n", netbuffer->u.clientcfg.localplayers, fprintf(debugfile, " number %d mode %d\n", netbuffer->u.clientcfg.localplayers,
netbuffer->u.clientcfg.mode); netbuffer->u.clientcfg.needsdownload);
break; break;
case PT_SERVERTICS: case PT_SERVERTICS:
{ {