Add player name length checks
This commit is contained in:
parent
8e9d896f2d
commit
d7d8aa1039
@ -79,6 +79,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "httpfetch.h"
|
#include "httpfetch.h"
|
||||||
#include "guiEngine.h"
|
#include "guiEngine.h"
|
||||||
#include "mapsector.h"
|
#include "mapsector.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
#include "database-sqlite3.h"
|
#include "database-sqlite3.h"
|
||||||
#ifdef USE_LEVELDB
|
#ifdef USE_LEVELDB
|
||||||
@ -1843,6 +1844,13 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (current_playername.length() > PLAYERNAME_SIZE-1) {
|
||||||
|
error_message = wgettext("Player name to long.");
|
||||||
|
playername = current_playername.substr(0,PLAYERNAME_SIZE-1);
|
||||||
|
g_settings->set("name", playername);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Run game
|
Run game
|
||||||
*/
|
*/
|
||||||
|
@ -1448,14 +1448,21 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
/*
|
/*
|
||||||
Set up player
|
Set up player
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Get player name
|
|
||||||
char playername[PLAYERNAME_SIZE];
|
char playername[PLAYERNAME_SIZE];
|
||||||
for(u32 i=0; i<PLAYERNAME_SIZE-1; i++)
|
unsigned int playername_length = 0;
|
||||||
{
|
for (; playername_length < PLAYERNAME_SIZE; playername_length++ ) {
|
||||||
playername[i] = data[3+i];
|
playername[playername_length] = data[3+playername_length];
|
||||||
|
if (data[3+playername_length] == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
playername[PLAYERNAME_SIZE-1] = 0;
|
|
||||||
|
if (playername_length == PLAYERNAME_SIZE) {
|
||||||
|
actionstream<<"Server: Player with name exceeding max length "
|
||||||
|
<<"tried to connect from "<<addr_s<<std::endl;
|
||||||
|
DenyAccess(peer_id, L"Name to long");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(playername[0]=='\0')
|
if(playername[0]=='\0')
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user