Skip to content

Commit 0e2383e

Browse files
committed
Potentially fix the erroneous duplicate name checks
Resulting in single name players getting a number prepended at map restart/join
1 parent 1836ecd commit 0e2383e

5 files changed

Lines changed: 42 additions & 40 deletions

File tree

code/game/g_client.c

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ Forces a client's skin (for teamplay)
856856
ClientCheckName
857857
============
858858
*/
859-
static void ClientCleanName( int clientNum, const char *in, char *out, int outSize ) {
859+
static void ClientCleanName( int clientNum, const char *in, char *out, int outSize, qboolean dupecheck ) {
860860
int len, colorlessLen;
861861
char ch;
862862
char *p;
@@ -870,7 +870,7 @@ static void ClientCleanName( int clientNum, const char *in, char *out, int outSi
870870
len = 0;
871871
colorlessLen = 0;
872872
p = out;
873-
*p = 0;
873+
*p = '\0';
874874
spaces = 0;
875875

876876
while( 1 ) {
@@ -880,7 +880,7 @@ static void ClientCleanName( int clientNum, const char *in, char *out, int outSi
880880
}
881881

882882
// don't allow leading spaces
883-
if( !*p && ch == ' ' ) {
883+
if( *p == '\0' && ch == ' ') {
884884
continue;
885885
}
886886

@@ -927,49 +927,51 @@ static void ClientCleanName( int clientNum, const char *in, char *out, int outSi
927927
colorlessLen++;
928928
len++;
929929
}
930-
*out = 0;
930+
*out = '\0';
931931

932932
// don't allow empty names
933933
if( *p == 0 || colorlessLen == 0 ) {
934934
Q_strncpyz( p, "ETF_Player", outSize );
935935
}
936936

937-
// djbob: stop colliding nicks
938-
// Perhaps add a list of nicks which will be forcefully changed
939-
Q_strncpyz( buffer, p, outSize );
940-
Q_CleanStr( buffer );
937+
if ( dupecheck ) {
938+
// djbob: stop colliding nicks
939+
// Perhaps add a list of nicks which will be forcefully changed
940+
Q_strncpyz( buffer, p, outSize );
941+
Q_CleanStr( buffer );
941942

942-
a = 0 ;
943-
for( i = 0; i < MAX_CLIENTS; i++ ) {
944-
char buf[128], buf_2[128];
943+
a = 0 ;
944+
for( i = 0; i < MAX_CLIENTS; i++ ) {
945+
char buf[128], buf_2[128];
945946

946-
if(!g_entities[i].inuse || g_entities[i].s.number == clientNum || (g_entities[i].client->pers.connected < CON_CONNECTING)) {
947-
continue;
948-
}
947+
if(!g_entities[i].inuse || g_entities[i].s.number == clientNum || (g_entities[i].client->pers.connected < CON_CONNECTING)) {
948+
continue;
949+
}
949950

950-
if(a) {
951-
Com_sprintf(buf, outSize, "%d_%s", a, buffer);
952-
} else {
953-
Q_strncpyz( buf, buffer, outSize );
954-
}
951+
if(a) {
952+
Com_sprintf(buf, outSize, "%d_%s", a, buffer);
953+
} else {
954+
Q_strncpyz( buf, buffer, outSize );
955+
}
955956

956-
Q_strncpyz( buf_2, g_entities[i].client->pers.netname, outSize );
957-
Q_CleanStr( buf_2 );
957+
Q_strncpyz( buf_2, g_entities[i].client->pers.netname, outSize );
958+
Q_CleanStr( buf_2 );
958959

959960

960-
if(!Q_stricmp(buf_2, buf)) {
961-
a++;
962-
i = -1;
961+
if(!Q_stricmp(buf_2, buf)) {
962+
a++;
963+
i = -1;
964+
}
963965
}
964-
}
965966

966-
if(a) {
967-
//Keeger -- seems somehow Com_sprintf borks when using the destination as an argument
968-
//cause the original way produced "1_1_1_1_" garbage.
969-
Q_strncpyz( buffer, p, outSize ); //re-make buffer to colorized string
970-
Com_sprintf(p, outSize, "%d_%s", a, buffer); //replace the p arg with buffer and bug goes away...
967+
if(a) {
968+
//Keeger -- seems somehow Com_sprintf borks when using the destination as an argument
969+
//cause the original way produced "1_1_1_1_" garbage.
970+
Q_strncpyz( buffer, p, outSize ); //re-make buffer to colorized string
971+
Com_sprintf(p, outSize, "%d_%s", a, buffer); //replace the p arg with buffer and bug goes away...
972+
}
973+
// djbob
971974
}
972-
// djbob
973975
}
974976

975977

@@ -984,7 +986,7 @@ The game can override any of the settings and call trap_SetUserinfo
984986
if desired.
985987
============
986988
*/
987-
qboolean ClientUserinfoChanged( int clientNum, const char *reason ) {
989+
qboolean ClientUserinfoChanged( int clientNum, const char *reason, qboolean dupecheck ) {
988990
gentity_t *ent;
989991
const char *s;
990992
char oldname[MAX_NETNAME];
@@ -1077,7 +1079,7 @@ qboolean ClientUserinfoChanged( int clientNum, const char *reason ) {
10771079
// set name.
10781080
Q_strncpyz ( oldname, client->pers.netname, sizeof( oldname ) );
10791081
s = Info_ValueForKey (userinfo, "name");
1080-
ClientCleanName( clientNum, s, client->pers.netname, sizeof(client->pers.netname) );
1082+
ClientCleanName( clientNum, s, client->pers.netname, sizeof(client->pers.netname), dupecheck );
10811083

10821084
//if ( client->sess.sessionTeam == Q3F_TEAM_SPECTATOR ) {
10831085
if ( Q3F_IsSpectator(ent->client)) { // RR2DO2
@@ -1337,7 +1339,7 @@ const char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot )
13371339

13381340
client->ps.clientNum = clientNum;
13391341

1340-
if ( !ClientUserinfoChanged( clientNum, "connect" ) ) {
1342+
if ( !ClientUserinfoChanged( clientNum, "connect", qfalse ) ) {
13411343
return ban_reason;
13421344
}
13431345

@@ -1382,7 +1384,7 @@ const char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot )
13821384
client->pers.connected = CON_CONNECTING;
13831385
client->pers.connectTime = level.time;
13841386

1385-
ClientUserinfoChanged( clientNum, "connect" );
1387+
ClientUserinfoChanged( clientNum, "connect", qtrue );
13861388

13871389
// don't do the "xxx connected" messages if they were caried over from previous level
13881390
if ( firstTime ) {
@@ -1587,7 +1589,7 @@ qboolean ClientSpawn(gentity_t *ent) {
15871589
if( client->sess.sessionClass == Q3F_CLASS_MAX )
15881590
client->ps.persistant[PERS_CURRCLASS] = G_Q3F_SelectRandomClass( client->sess.sessionTeam, ent );
15891591
else client->ps.persistant[PERS_CURRCLASS] = client->sess.sessionClass;
1590-
ClientUserinfoChanged( client - level.clients, "spawn with new class" );
1592+
ClientUserinfoChanged( client - level.clients, "spawn with new class", qtrue );
15911593
}
15921594
}
15931595
else beginclass = qfalse;

code/game/g_cmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ qboolean SetTeam( gentity_t *ent, const char *s ) {
839839
// Golliwog.
840840

841841
// get and distribute relevent paramters
842-
ClientUserinfoChanged( clientNum, "setteam" );
842+
ClientUserinfoChanged( clientNum, "setteam", qtrue );
843843

844844
ClientBegin( clientNum );
845845

code/game/g_local.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ void MoveClientToIntermission(gentity_t* client);
958958
// g_client.c
959959
//
960960
const char *ClientConnect( int clientNum, qboolean firstTime, qboolean isBot );
961-
qboolean ClientUserinfoChanged( int clientNum, const char *reason );
961+
qboolean ClientUserinfoChanged( int clientNum, const char *reason, qboolean dupecheck );
962962
void ClientDisconnect( int clientNum );
963963
void ClientBegin( int clientNum );
964964
void ClientCommand( int clientNum );

code/game/g_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Q_EXPORT intptr_t vmMain( int command, intptr_t arg0, intptr_t arg1, intptr_t ar
138138
ClientThink( arg0 );
139139
return 0;
140140
case GAME_CLIENT_USERINFO_CHANGED:
141-
ClientUserinfoChanged( arg0, "game" );
141+
ClientUserinfoChanged( arg0, "game", qtrue );
142142
return 0;
143143
case GAME_CLIENT_DISCONNECT:
144144
ClientDisconnect( arg0 );

code/game/g_q3f_playerclass.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ static void G_Q3F_AgentThink( gentity_t *ent )
962962
BG_PlayerStateToEntityState( &client->ps, &ent->activator->s, qtrue );
963963
}
964964
if( infochange )
965-
ClientUserinfoChanged( ent->activator->s.number, "agentthink" );
965+
ClientUserinfoChanged( ent->activator->s.number, "agentthink", qtrue );
966966

967967
if( (!disguiseendtime || (level.time >= disguiseendtime && disguiseendtime != -1)) &&
968968
(!invisendtime || (level.time >= invisendtime && invisendtime != -1)) )

0 commit comments

Comments
 (0)