-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate token when connecting to a server, not when fetching the list.
Generating a token no longer fetches the entire server list. This also instructs the list server to not generate a token for the LIST action, since we're now trying to restrict tokens to a specific server host/port instead of the player IP.
- Loading branch information
Showing
10 changed files
with
196 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* bzflag | ||
* Copyright (c) 1993-2024 Tim Riker | ||
* | ||
* This package is free software; you can redistribute it and/or | ||
* modify it under the terms of the license found in the file | ||
* named COPYING that should have accompanied this file. | ||
* | ||
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
*/ | ||
|
||
#ifndef BZF_SERVERAUTH_H | ||
#define BZF_SERVERAUTH_H | ||
|
||
#include "common.h" | ||
|
||
/* system interface headers */ | ||
#include <vector> | ||
|
||
/* common interface headers */ | ||
#include "StartupInfo.h" | ||
#include "cURLManager.h" | ||
|
||
class ServerAuth : cURLManager | ||
{ | ||
public: | ||
ServerAuth(); | ||
virtual ~ServerAuth(); | ||
|
||
void requestToken(StartupInfo *info); | ||
void finalization(char *data, unsigned int length, bool good); | ||
|
||
private: | ||
StartupInfo *startupInfo; | ||
}; | ||
|
||
#endif // BZF_SERVERAUTH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* bzflag | ||
* Copyright (c) 1993-2024 Tim Riker | ||
* | ||
* This package is free software; you can redistribute it and/or | ||
* modify it under the terms of the license found in the file | ||
* named COPYING that should have accompanied this file. | ||
* | ||
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
*/ | ||
|
||
/* interface header */ | ||
#include "ServerAuth.h" | ||
|
||
/* system headers */ | ||
#include <cstring> | ||
|
||
/* common implementation headers */ | ||
#include "TextUtils.h" | ||
#include "ErrorHandler.h" | ||
|
||
ServerAuth::ServerAuth() | ||
{ | ||
} | ||
|
||
ServerAuth::~ServerAuth() | ||
{ | ||
} | ||
|
||
void ServerAuth::requestToken(StartupInfo *info) | ||
{ | ||
startupInfo = info; | ||
|
||
std::string url = info->listServerURL; | ||
|
||
std::string msg = "action=GETTOKEN&callsign="; | ||
msg += TextUtils::url_encode(info->callsign); | ||
msg += "&password="; | ||
msg += TextUtils::url_encode(info->password); | ||
if (info->serverName[0] != '\0') | ||
{ | ||
msg += "&nameport="; | ||
msg += info->serverName; | ||
msg += ':'; | ||
msg += std::to_string(info->serverPort); | ||
} | ||
setPostMode(msg); | ||
setURL(url); | ||
addHandle(); | ||
} | ||
|
||
void ServerAuth::finalization(char *_data, unsigned int length, bool good) | ||
{ | ||
if (good) | ||
{ | ||
char *base = (char *)_data; | ||
char *endS = base + length; | ||
const char tokenIdentifier[] = "TOKEN: "; | ||
const char noTokenIdentifier[] = "NOTOK: "; | ||
const char errorIdentifier[] = "ERROR: "; | ||
const char noticeIdentifier[] = "NOTICE: "; | ||
|
||
while (base < endS) | ||
{ | ||
// find next newline | ||
char* scan = base; | ||
while (scan < endS && *scan != '\n') | ||
scan++; | ||
|
||
// if no newline then no more complete replies | ||
if (scan >= endS) | ||
break; | ||
*scan++ = '\0'; | ||
|
||
// look for TOKEN: and save token if found also look for NOTOK: | ||
// and record "badtoken" into the token string and print an | ||
// error | ||
if (strncmp(base, tokenIdentifier, strlen(tokenIdentifier)) == 0) | ||
{ | ||
strncpy(startupInfo->token, (char *)(base + strlen(tokenIdentifier)), | ||
TokenLen - 1); | ||
startupInfo->token[TokenLen - 1] = '\0'; | ||
#ifdef DEBUG | ||
std::vector<std::string> args; | ||
args.push_back(startupInfo->token); | ||
printError("got token: {1}", &args); | ||
#endif | ||
} | ||
else if (!strncmp(base, noTokenIdentifier, | ||
strlen(noTokenIdentifier))) | ||
{ | ||
printError("ERROR: did not get token:"); | ||
printError(base); | ||
strcpy(startupInfo->token, "badtoken\0"); | ||
} | ||
else if (!strncmp(base, errorIdentifier, strlen(errorIdentifier))) | ||
{ | ||
printError(base); | ||
strcpy(startupInfo->token, "badtoken\0"); | ||
} | ||
else if (!strncmp(base, noticeIdentifier, strlen(noticeIdentifier))) | ||
printError(base); | ||
|
||
// next reply | ||
base = scan; | ||
} | ||
} | ||
else | ||
strcpy(startupInfo->token, "badtoken\0"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters