diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-03-18 20:31:13 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-03-18 20:31:13 +0000 |
| commit | 9425cbef579fcce696468c3b4118e64f9d6232d3 (patch) | |
| tree | 22845b0b960494b021ef31f1f84270ecc9627594 /src/engine | |
| parent | 4986238fc82ac5d25914ff5bdc15fff82a2455e2 (diff) | |
| download | zcatch-9425cbef579fcce696468c3b4118e64f9d6232d3.tar.gz zcatch-9425cbef579fcce696468c3b4118e64f9d6232d3.zip | |
fixed auto rename if two players sets the same name
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/e_if_other.h | 4 | ||||
| -rw-r--r-- | src/engine/e_protocol.h | 1 | ||||
| -rw-r--r-- | src/engine/server/es_server.c | 29 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/engine/e_if_other.h b/src/engine/e_if_other.h index b3a61e7f..66e2d3a8 100644 --- a/src/engine/e_if_other.h +++ b/src/engine/e_if_other.h @@ -24,7 +24,9 @@ enum SNDFLAG_LOOP=1, SNDFLAG_POS=2, - SNDFLAG_ALL=3 + SNDFLAG_ALL=3, + + MAX_NAME_LENGTH=32 }; /* diff --git a/src/engine/e_protocol.h b/src/engine/e_protocol.h index 0bca00a4..46e1b8c2 100644 --- a/src/engine/e_protocol.h +++ b/src/engine/e_protocol.h @@ -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 diff --git a/src/engine/server/es_server.c b/src/engine/server/es_server.c index 83c65548..855b1708 100644 --- a/src/engine/server/es_server.c +++ b/src/engine/server/es_server.c @@ -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) |