@@ -1361,11 +1361,14 @@ void Cmd_Where_f( gentity_t *ent ) {
1361
1361
Cmd_CallVote_f
1362
1362
==================
1363
1363
*/
1364
+ #define CALLVOTE_ARG2_NONE 1
1365
+ #define CALLVOTE_ARG2_INTREGAL 2
1364
1366
void Cmd_CallVote_f ( gentity_t * ent ) {
1365
1367
char * c ;
1366
1368
int i ;
1367
1369
char arg1 [MAX_STRING_TOKENS ];
1368
1370
char arg2 [MAX_STRING_TOKENS ];
1371
+ int arg2Flags , arg2RangeMin , arg2RangeMax ;
1369
1372
1370
1373
if ( !g_allowVote .integer ) {
1371
1374
trap_SendServerCommand ( ent - g_entities , "print \"Voting not allowed here.\n\"" );
@@ -1401,23 +1404,73 @@ void Cmd_CallVote_f( gentity_t *ent ) {
1401
1404
}
1402
1405
}
1403
1406
1407
+ arg2Flags = 0 ;
1408
+ arg2RangeMin = 0 ;
1409
+ arg2RangeMax = INT_MAX ;
1410
+
1404
1411
if ( !Q_stricmp ( arg1 , "map_restart" ) ) {
1412
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1413
+ arg2RangeMax = 60 ; // max 1 minute
1414
+
1415
+ // default to 5 seconds if no argument was specified
1416
+ if ( !arg2 [0 ] ) {
1417
+ Q_strncpyz ( arg2 , "5" , sizeof ( arg2 ) );
1418
+ }
1405
1419
} else if ( !Q_stricmp ( arg1 , "nextmap" ) ) {
1420
+ arg2Flags = CALLVOTE_ARG2_NONE ;
1406
1421
} else if ( !Q_stricmp ( arg1 , "map" ) ) {
1422
+ // string
1407
1423
} else if ( !Q_stricmp ( arg1 , "g_gametype" ) ) {
1424
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1425
+ arg2RangeMax = GT_MAX_GAME_TYPE - 1 ;
1408
1426
} else if ( !Q_stricmp ( arg1 , "kick" ) ) {
1427
+ // string
1409
1428
} else if ( !Q_stricmp ( arg1 , "kicknum" ) ) {
1429
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1430
+ arg2RangeMax = MAX_CLIENTS ;
1410
1431
} else if ( !Q_stricmp ( arg1 , "g_doWarmup" ) ) {
1432
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1433
+ arg2RangeMax = 1 ;
1411
1434
} else if ( !Q_stricmp ( arg1 , "timelimit" ) ) {
1435
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1436
+ arg2RangeMax = 240 ; // 4 hours
1412
1437
} else if ( !Q_stricmp ( arg1 , "fraglimit" ) ) {
1438
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1439
+ arg2RangeMax = 999 ;
1413
1440
} else if ( !Q_stricmp ( arg1 , "capturelimit" ) ) {
1441
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1442
+ arg2RangeMax = 999 ;
1414
1443
} else if ( !Q_stricmp ( arg1 , "g_instagib" ) ) {
1444
+ arg2Flags = CALLVOTE_ARG2_INTREGAL ;
1445
+ arg2RangeMax = 1 ;
1415
1446
} else {
1416
1447
trap_SendServerCommand ( ent - g_entities , "print \"Invalid vote string.\n\"" );
1417
1448
trap_SendServerCommand ( ent - g_entities , "print \"Vote commands are: map_restart, nextmap, map <mapname>, g_gametype <n>, kick <player>, kicknum <playernum>, g_doWarmup <boolean>, timelimit <time>, fraglimit <frags>, capturelimit <captures>, g_instagib <boolean>.\n\"" );
1418
1449
return ;
1419
1450
}
1420
1451
1452
+ if ( ( arg2Flags & CALLVOTE_ARG2_NONE ) && arg2 [0 ] != '\0' ) {
1453
+ trap_SendServerCommand ( ent - g_entities , va ( "print \"Vote command %s does not accept an argument.\n\"" , arg1 ) );
1454
+ return ;
1455
+ }
1456
+ else if ( arg2 [0 ] == '\0' ) {
1457
+ trap_SendServerCommand ( ent - g_entities , va ( "print \"Vote command %s requires an argument.\n\"" , arg1 ) );
1458
+ return ;
1459
+ }
1460
+
1461
+ if ( ( arg2Flags & CALLVOTE_ARG2_INTREGAL ) ) {
1462
+ if ( !StringIsInteger ( arg2 ) ) {
1463
+ trap_SendServerCommand ( ent - g_entities , va ( "print \"Vote command %s argument must be a number.\n\"" , arg1 ) );
1464
+ return ;
1465
+ }
<
8000
/code>
1466
+
1467
+ i = atoi ( arg2 );
1468
+ if ( i < arg2RangeMin || i > arg2RangeMax ) {
1469
+ trap_SendServerCommand ( ent - g_entities , va ( "print \"Vote command %s argument must be %d to %d.\n\"" , arg1 , arg2RangeMin , arg2RangeMax ) );
1470
+ return ;
1471
+ }
1472
+ }
1473
+
1421
1474
// if there is still a vote to be executed
1422
1475
if ( level .voteExecuteTime ) {
1423
1476
// don't start a vote when map change or restart is in progress
@@ -1445,6 +1498,17 @@ void Cmd_CallVote_f( gentity_t *ent ) {
1445
1498
// special case for map changes, we want to reset the nextmap setting
1446
1499
// this allows a player to change maps, but not upset the map rotation
1447
1500
char s [MAX_STRING_CHARS ];
1501
+ char filename [MAX_QPATH ];
1502
+
1503
+ if ( strstr ( arg2 , ".." ) || strstr ( arg2 , "::" ) || strlen ( arg2 ) + 9 >= MAX_QPATH ) {
1504
+ trap_SendServerCommand ( ent - g_entities , "print \"Invalid map name.\n\"" );
1505
+ return ;
1506
+ }
1507
+ Com_sprintf ( filename , sizeof ( filename ), "maps/%s.bsp" , arg2 );
1508
+ if ( trap_FS_FOpenFile ( filename , NULL , FS_READ ) <= 0 ) {
1509
+ trap_SendServerCommand ( ent - g_entities , "print \"Map not found.\n\"" );
1510
+ return ;
1511
+ }
1448
1512
1449
1513
trap_Cvar_VariableStringBuffer ( "nextmap" , s , sizeof (s ) );
1450
1514
if (* s ) {
0 commit comments