mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
fixed auto rename if two players sets the same name
This commit is contained in:
parent
4986238fc8
commit
9425cbef57
|
@ -24,7 +24,9 @@ enum
|
||||||
|
|
||||||
SNDFLAG_LOOP=1,
|
SNDFLAG_LOOP=1,
|
||||||
SNDFLAG_POS=2,
|
SNDFLAG_POS=2,
|
||||||
SNDFLAG_ALL=3
|
SNDFLAG_ALL=3,
|
||||||
|
|
||||||
|
MAX_NAME_LENGTH=32
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -60,7 +60,6 @@ enum
|
||||||
/* this should be revised */
|
/* this should be revised */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
MAX_NAME_LENGTH=32,
|
|
||||||
MAX_CLANNAME_LENGTH=32,
|
MAX_CLANNAME_LENGTH=32,
|
||||||
MAX_INPUT_SIZE=128,
|
MAX_INPUT_SIZE=128,
|
||||||
MAX_SNAPSHOT_PACKSIZE=900
|
MAX_SNAPSHOT_PACKSIZE=900
|
||||||
|
|
|
@ -202,11 +202,38 @@ const char *server_clientname(int client_id)
|
||||||
return clients[client_id].name;
|
return clients[client_id].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int server_try_setclientname(int client_id, const char *name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < MAX_CLIENTS; i++)
|
||||||
|
if(i != client_id && clients[i].state >= SRVCLIENT_STATE_READY)
|
||||||
|
{
|
||||||
|
if(strcmp(name, clients[i].name) == 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
str_copy(clients[client_id].name, name, MAX_NAME_LENGTH);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void server_setclientname(int client_id, const char *name)
|
void server_setclientname(int client_id, const char *name)
|
||||||
{
|
{
|
||||||
|
char nametry[MAX_NAME_LENGTH];
|
||||||
|
int i;
|
||||||
if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY)
|
if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY)
|
||||||
return;
|
return;
|
||||||
str_copy(clients[client_id].name, name, MAX_NAME_LENGTH);
|
|
||||||
|
str_copy(nametry, name, MAX_NAME_LENGTH);
|
||||||
|
if(server_try_setclientname(client_id, nametry))
|
||||||
|
{
|
||||||
|
/* auto rename */
|
||||||
|
for(i = 1;; i++)
|
||||||
|
{
|
||||||
|
str_format(nametry, MAX_NAME_LENGTH, "(%d)%s", i, name);
|
||||||
|
if(server_try_setclientname(client_id, nametry) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void server_setclientscore(int client_id, int score)
|
void server_setclientscore(int client_id, int score)
|
||||||
|
|
|
@ -2109,17 +2109,20 @@ void mods_message(int msgtype, int client_id)
|
||||||
p++;
|
p++;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//
|
// copy old name
|
||||||
if(msgtype == NETMSGTYPE_CL_CHANGEINFO && strcmp(msg->name, server_clientname(client_id)) != 0)
|
char oldname[MAX_NAME_LENGTH];
|
||||||
|
str_copy(oldname, server_clientname(client_id), MAX_NAME_LENGTH);
|
||||||
|
|
||||||
|
server_setclientname(client_id, msg->name);
|
||||||
|
if(msgtype == NETMSGTYPE_CL_CHANGEINFO && strcmp(oldname, server_clientname(client_id)) != 0)
|
||||||
{
|
{
|
||||||
char chattext[256];
|
char chattext[256];
|
||||||
str_format(chattext, sizeof(chattext), "*** %s changed name to %s", server_clientname(client_id), msg->name);
|
str_format(chattext, sizeof(chattext), "*** %s changed name to %s", oldname, server_clientname(client_id));
|
||||||
send_chat(-1, -1, chattext);
|
send_chat(-1, -1, chattext);
|
||||||
}
|
}
|
||||||
|
|
||||||
//send_set_name(client_id, players[client_id].name, name);
|
// set skin
|
||||||
str_copy(players[client_id].skin_name, msg->skin, sizeof(players[client_id].skin_name));
|
str_copy(players[client_id].skin_name, msg->skin, sizeof(players[client_id].skin_name));
|
||||||
server_setclientname(client_id, msg->name);
|
|
||||||
|
|
||||||
gameobj->on_player_info_change(&players[client_id]);
|
gameobj->on_player_info_change(&players[client_id]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue