fixed auto rename if two players sets the same name

This commit is contained in:
Magnus Auvinen 2008-03-18 20:31:13 +00:00
parent 4986238fc8
commit 9425cbef57
4 changed files with 40 additions and 9 deletions

View file

@ -24,7 +24,9 @@ enum
SNDFLAG_LOOP=1,
SNDFLAG_POS=2,
SNDFLAG_ALL=3
SNDFLAG_ALL=3,
MAX_NAME_LENGTH=32
};
/*

View file

@ -60,7 +60,6 @@ enum
/* this should be revised */
enum
{
MAX_NAME_LENGTH=32,
MAX_CLANNAME_LENGTH=32,
MAX_INPUT_SIZE=128,
MAX_SNAPSHOT_PACKSIZE=900

View file

@ -202,11 +202,38 @@ const char *server_clientname(int client_id)
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)
{
char nametry[MAX_NAME_LENGTH];
int i;
if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY)
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)

View file

@ -2109,17 +2109,20 @@ void mods_message(int msgtype, int client_id)
p++;
}*/
//
if(msgtype == NETMSGTYPE_CL_CHANGEINFO && strcmp(msg->name, server_clientname(client_id)) != 0)
// copy old name
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];
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_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));
server_setclientname(client_id, msg->name);
gameobj->on_player_info_change(&players[client_id]);