Advertisement
slatenails

votedef - other changes

Aug 1st, 2013
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 42.37 KB | None | 0 0
  1. diff -r af45c72387f5 src/CMakeLists.txt
  2. --- a/src/CMakeLists.txt    Sat Jul 27 09:47:16 2013 +0200
  3. +++ b/src/CMakeLists.txt    Fri Aug 02 02:25:44 2013 +0300
  4. @@ -829,6 +829,7 @@
  5.     v_pfx.cpp
  6.     v_text.cpp
  7.     v_video.cpp
  8. +   votedef.cpp
  9.     w_wad.cpp
  10.     wi_stuff.cpp
  11.     zstrformat.cpp
  12. diff -r af45c72387f5 src/callvote.cpp
  13. --- a/src/callvote.cpp  Sat Jul 27 09:47:16 2013 +0200
  14. +++ b/src/callvote.cpp  Fri Aug 02 02:25:44 2013 +0300
  15. @@ -65,13 +65,14 @@
  16.  #include "sv_main.h"
  17.  #include "v_video.h"
  18.  #include "maprotation.h"
  19. +#include "votedef.h"
  20.  #include <list>
  21.  
  22.  //*****************************************************************************
  23.  // VARIABLES
  24.  
  25.  static VOTESTATE_e             g_VoteState;
  26. -static FString                 g_VoteCommand;
  27. +static FString                 g_VoteDisplay;
  28.  static FString                 g_VoteReason;
  29.  static ULONG                   g_ulVoteCaller;
  30.  static ULONG                   g_ulVoteCountdownTicks = 0;
  31. @@ -83,6 +84,8 @@
  32.  static ULONG                   g_ulPlayersWhoVotedNo[(MAXPLAYERS / 2) + 1];
  33.  static NETADDRESS_s            g_KickVoteVictimAddress;
  34.  static std::list<VOTE_s>       g_PreviousVotes;
  35. +static VoteDef::ApplyInput     g_VoteData;
  36. +static FString                 g_zCurrentSummary;
  37.  
  38.  //*****************************************************************************
  39.  // PROTOTYPES
  40. @@ -90,9 +93,8 @@
  41.  static void            callvote_EndVote( void );
  42.  static ULONG           callvote_CountPlayersWhoVotedYes( void );
  43.  static ULONG           callvote_CountPlayersWhoVotedNo( void );
  44. -static bool            callvote_CheckForFlooding( FString &Command, FString &Parameters, ULONG ulPlayer );
  45. -static bool            callvote_CheckValidity( FString &Command, FString &Parameters );
  46. -static ULONG           callvote_GetVoteType( const char *pszCommand );
  47. +static bool            callvote_CheckForFlooding( ULONG& Command, FString& Parameters, ULONG ulPlayer );
  48. +static bool            callvote_CheckValidity( ULONG ulCommand, FString &Parameters );
  49.  
  50.  //*****************************************************************************
  51.  // FUNCTIONS
  52. @@ -153,18 +155,31 @@
  53.                     ( NETWORK_GetState( ) != NETSTATE_CLIENT ) &&
  54.                     ( CLIENTDEMO_IsPlaying( ) == false ))
  55.                 {
  56. -                   // [BB, RC] If the vote is a kick vote, we have to rewrite g_VoteCommand to both use the stored IP, and temporarily ban it.
  57. -                   // [Dusk] Write the kick reason into the ban reason, [BB] but only if it's not empty.
  58. -                   if ( strncmp( g_VoteCommand, "kick", 4 ) == 0 )
  59. +                   // [Dusk] VOTEDEFized
  60. +                   VoteDef* pVoteType = VoteDef::findByIndex( g_VoteData.type );
  61. +                   VoteDef::ApplyResult output;
  62. +                   g_VoteData.yes = callvote_CountPlayersWhoVotedYes( );
  63. +                   g_VoteData.no = callvote_CountPlayersWhoVotedNo( );
  64. +                   if ( VoteDef::applyCommand( g_VoteData, output ))
  65.                     {
  66. -                       g_VoteCommand.Format( "addban %s 10min \"Vote kick, %d to %d", NETWORK_AddressToString( g_KickVoteVictimAddress ), static_cast<int>(callvote_CountPlayersWhoVotedYes( )), static_cast<int>(callvote_CountPlayersWhoVotedNo( )) );
  67. -                       if ( g_VoteReason.IsNotEmpty() )
  68. -                           g_VoteCommand.AppendFormat ( " (%s)", g_VoteReason.GetChars( ) );
  69. -                       g_VoteCommand += ".\"";
  70. +                       if ( pVoteType->nativeType() != VoteDef::NumNatives )
  71. +                       {
  72. +                           Printf( "[VOTE] -> %s\n", output.command.GetChars() );
  73. +                           AddCommandString( const_cast<char*>( output.command.GetChars() ));
  74. +                       }
  75. +                       else
  76. +                       {
  77. +                           Printf( "[VOTE] -> Script %lu (%ld)\n", pVoteType->scriptNum(), output.arg );
  78. +                           int p = g_VoteData.caller;
  79. +                           AActor* mo = ( playeringame[p] && players[p].mo != NULL ) ? players[p].mo : NULL;
  80. +                           P_StartScript( mo, NULL, pVoteType->scriptNum(), NULL, false,
  81. +                               output.arg, 0, 0, 1, false );
  82. +                       }
  83.                     }
  84. +                   else
  85. +                       SERVER_Printf( PRINT_HIGH, "\\c[Orange]Vote command error: %s\n", output.error.GetChars() );
  86. +               }
  87.  
  88. -                   AddCommandString( (char *)g_VoteCommand.GetChars( ));
  89. -               }
  90.                 // Reset the module.
  91.                 CALLVOTE_ClearVote( );
  92.             }
  93. @@ -175,7 +190,7 @@
  94.  
  95.  //*****************************************************************************
  96.  //
  97. -void CALLVOTE_BeginVote( FString Command, FString Parameters, FString Reason, ULONG ulPlayer )
  98. +void CALLVOTE_BeginVote( ULONG Command, FString Parameters, FString Reason, ULONG ulPlayer )
  99.  {
  100.     // Don't allow a vote in the middle of another vote.
  101.     if ( g_VoteState != VOTESTATE_NOVOTE )
  102. @@ -185,6 +200,13 @@
  103.         return;
  104.     }
  105.  
  106. +   g_VoteData.arg = Parameters;
  107. +   g_VoteData.caller = SERVER_GetCurrentClient( );
  108. +   g_VoteData.yes = g_VoteData.no = 0;
  109. +   g_VoteData.type = Command;
  110. +   g_VoteData.reason = Reason;
  111. +   g_zCurrentSummary = VoteDef::makeSummary( g_VoteData );
  112. +
  113.     // Check and make sure all the parameters are valid.
  114.     if ( callvote_CheckValidity( Command, Parameters ) == false )
  115.         return;
  116. @@ -196,36 +218,44 @@
  117.     // Play the announcer sound for this.
  118.     ANNOUNCER_PlayEntry( cl_announcer, "VoteNow" );
  119.  
  120. +   VoteDef* pVoteType = VoteDef::findByIndex( Command );
  121. +
  122.     // Create the vote console command.
  123. -   g_VoteCommand = Command;
  124. -   g_VoteCommand += " ";
  125. -   g_VoteCommand += Parameters;
  126. +   // [Dusk] Note: this is only used for clients' vote displays.
  127. +   // The real command (or script call) is generated later on.
  128. +   g_VoteDisplay = pVoteType->name();
  129. +   if( Parameters.IsNotEmpty() )
  130. +   {
  131. +       g_VoteDisplay += " ";
  132. +       g_VoteDisplay += Parameters;
  133. +   }
  134. +
  135.     g_ulVoteCaller = ulPlayer;
  136.     g_VoteReason = Reason.Left(25);
  137.  
  138. +   // [Dusk] Store IP addresses in VOTEDEF memory so that nobody gets away from kickvotes.
  139. +   VoteDef::storeIPAddresses();
  140. +
  141.     // Create the record of the vote for flood prevention.
  142.     {
  143.         VOTE_s VoteRecord;
  144. +       time( &VoteRecord.tTimeCalled );
  145.         VoteRecord.fsParameter = Parameters;
  146. -       time_t tNow;
  147. -       time( &tNow );
  148. -       VoteRecord.tTimeCalled = tNow;
  149.         VoteRecord.Address = SERVER_GetClient( g_ulVoteCaller )->Address;
  150. -       VoteRecord.ulVoteType = callvote_GetVoteType( Command );
  151. -
  152. -       if ( VoteRecord.ulVoteType == VOTECMD_KICK )
  153. -           VoteRecord.KickAddress = g_KickVoteVictimAddress;
  154. -
  155. +       VoteRecord.ulVoteType = Command;
  156. +       VoteRecord.fsSummary = g_zCurrentSummary;
  157.         g_PreviousVotes.push_back( VoteRecord );
  158.     }
  159.  
  160.     // Display the message in the console.
  161.     {
  162. -       FString ReasonBlurb = ( g_VoteReason.Len( )) ? ( ", reason: \"" + g_VoteReason + "\"" ) : "";
  163. +       FString ReasonBlurb = ( g_VoteReason.Len( )) ? ( ", reason: \"" + g_VoteReason + "\"" ) : "";
  164. +       FString IPString;
  165.         if ( NETWORK_GetState( ) == NETSTATE_SERVER )
  166. -           Printf( "%s\\c- (%s) has called a vote (\"%s\"%s).\n", players[ulPlayer].userinfo.netname, NETWORK_AddressToString( SERVER_GetClient( ulPlayer )->Address ), g_VoteCommand.GetChars(), ReasonBlurb.GetChars() );
  167. -       else
  168. -           Printf( "%s\\c- has called a vote (\"%s\"%s).\n", players[ulPlayer].userinfo.netname, g_VoteCommand.GetChars(), ReasonBlurb.GetChars() );
  169. +           IPString.Format( " (%s)", NETWORK_AddressToString( SERVER_GetClient( ulPlayer )->Address ));
  170. +
  171. +       Printf( "%s%s\\c- has called a vote (\"%s\"%s).\n", players[ulPlayer].userinfo.netname,
  172. +           IPString.GetChars(), g_VoteDisplay.GetChars(), ReasonBlurb.GetChars() );
  173.     }
  174.  
  175.     g_VoteState = VOTESTATE_INVOTE;
  176. @@ -245,7 +275,7 @@
  177.     ULONG   ulIdx;
  178.  
  179.     g_VoteState = VOTESTATE_NOVOTE;
  180. -   g_VoteCommand = "";
  181. +   g_VoteDisplay = "";
  182.     g_ulVoteCaller = MAXPLAYERS;
  183.     g_ulVoteCountdownTicks = 0;
  184.     g_ulShowVoteScreenTicks = 0;
  185. @@ -367,7 +397,7 @@
  186.     if ( ulPlayer == g_ulVoteCaller && ( NETWORK_GetState( ) == NETSTATE_SERVER ))
  187.     {
  188.         // [BB] If a player canceled his own vote, don't prevent others from making this type of vote again.
  189. -       g_PreviousVotes.back( ).ulVoteType = NUM_VOTECMDS;
  190. +       g_PreviousVotes.back( ).ulVoteType = VoteDef::numTypes();
  191.  
  192.         SERVER_Printf( PRINT_HIGH, "Vote caller cancelled the vote.\n" );
  193.         g_bVoteCancelled = true;
  194. @@ -431,7 +461,7 @@
  195.     {
  196.         return ( true );
  197.     }
  198. -  
  199. +
  200.     SERVERCOMMANDS_PlayerVote( ulPlayer, false );
  201.  
  202.     ulNumYes = callvote_CountPlayersWhoVotedYes( );
  203. @@ -496,11 +526,8 @@
  204.  void CALLVOTE_EndVote( bool bPassed )
  205.  {
  206.     // This is a client-only function.
  207. -   if (( NETWORK_GetState( ) != NETSTATE_CLIENT ) &&
  208. -       ( CLIENTDEMO_IsPlaying( ) == false ))
  209. -   {
  210. +   if ( NETWORK_InClientMode() == false )
  211.         return;
  212. -   }
  213.  
  214.     g_bVotePassed = bPassed;
  215.     callvote_EndVote( );
  216. @@ -510,7 +537,7 @@
  217.  //
  218.  const char *CALLVOTE_GetCommand( void )
  219.  {
  220. -   return ( g_VoteCommand.GetChars( ));
  221. +   return ( g_VoteDisplay.GetChars( ));
  222.  }
  223.  
  224.  //*****************************************************************************
  225. @@ -645,10 +672,9 @@
  226.  
  227.  //*****************************************************************************
  228.  //
  229. -static bool callvote_CheckForFlooding( FString &Command, FString &Parameters, ULONG ulPlayer )
  230. +static bool callvote_CheckForFlooding( ULONG &Command, FString &Parameters, ULONG ulPlayer )
  231.  {
  232.     NETADDRESS_s    Address = SERVER_GetClient( ulPlayer )->Address;
  233. -   ULONG           ulVoteType = callvote_GetVoteType( Command );
  234.     time_t tNow;
  235.     time( &tNow );
  236.  
  237. @@ -663,11 +689,17 @@
  238.     // Run through the vote cache (backwards, from recent to old) and search for grounds on which to reject the vote.
  239.     for( std::list<VOTE_s>::reverse_iterator i = g_PreviousVotes.rbegin(); i != g_PreviousVotes.rend(); ++i )
  240.     {
  241. +       VoteDef* type = VoteDef::findByIndex( i->ulVoteType );
  242. +       if( !type )
  243. +           continue;
  244. +
  245.         // One *type* of vote per voter per ## minutes (excluding kick votes if they passed).
  246. -       if ( !( i->ulVoteType == VOTECMD_KICK && i->bPassed ) && NETWORK_CompareAddress( i->Address, Address, true ) && ( ulVoteType == i->ulVoteType ) && (( tNow - i->tTimeCalled ) < VOTER_VOTETYPE_INTERVAL * MINUTE ))
  247. +       if ( !( type->flags() & VoteDef::NoPassedLimit && i->bPassed ) && NETWORK_CompareAddress( i->Address, Address, true ) &&
  248. +           ( g_VoteData.type == i->ulVoteType ) && (( tNow - i->tTimeCalled ) < VOTER_VOTETYPE_INTERVAL * MINUTE ))
  249.         {
  250.             int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTER_VOTETYPE_INTERVAL * MINUTE - tNow ) / MINUTE );
  251. -           SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another %s vote.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ), Command.GetChars() );
  252. +           SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another %s vote.\n",
  253. +               iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ), type->name().GetChars() );
  254.             return false;
  255.         }
  256.  
  257. @@ -675,28 +707,21 @@
  258.         if ( NETWORK_CompareAddress( i->Address, Address, true ) && (( tNow - i->tTimeCalled ) < VOTER_NEWVOTE_INTERVAL * MINUTE ))
  259.         {
  260.             int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTER_NEWVOTE_INTERVAL * MINUTE - tNow ) / MINUTE );
  261. -           SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another vote.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
  262. +           SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another vote.\n",
  263. +                   iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
  264.             return false;
  265.         }
  266.  
  267.         // Specific votes ("map map30") that fail can't be re-proposed for ## minutes.
  268. -       if (( ulVoteType == i->ulVoteType ) && ( !i->bPassed ) && (( tNow - i->tTimeCalled ) < VOTE_LITERALREVOTE_INTERVAL * MINUTE ))
  269. +       // [Dusk] Generalized - use VOTEDEF summaries. This takes care of the IP checking for instance.
  270. +       if (( g_zCurrentSummary == i->fsSummary ) && ( !i->bPassed ) && (( tNow - i->tTimeCalled ) < VOTE_LITERALREVOTE_INTERVAL * MINUTE ))
  271.         {
  272.             int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTE_LITERALREVOTE_INTERVAL * MINUTE - tNow ) / MINUTE );
  273.  
  274. -           // Kickvotes (can't give the IP to clients!).
  275. -           if (( i->ulVoteType == VOTECMD_KICK ) && ( !i->bPassed ) && NETWORK_CompareAddress( i->KickAddress, g_KickVoteVictimAddress, true ))
  276. -           {
  277. -               SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific player was recently on voted to be kicked, but the vote failed. You must wait %d minute%s to call it again.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
  278. -               return false;
  279. -           }
  280. -
  281. -           // Other votes.
  282. -           if (( i->ulVoteType != VOTECMD_KICK ) && ( stricmp( i->fsParameter.GetChars(), Parameters.GetChars() ) == 0 ))
  283. -           {
  284. -               SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific vote (\"%s %s\") was recently called, and failed. You must wait %d minute%s to call it again.\n", Command.GetChars(), Parameters.GetChars(), iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
  285. -               return false;
  286. -           }
  287. +           SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific vote was recently "
  288. +               "called, and failed. You must wait %d minute%s to call it again.\n",
  289. +               Parameters.GetChars(), iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
  290. +           return false;
  291.         }
  292.     }
  293.  
  294. @@ -705,15 +730,17 @@
  295.  
  296.  //*****************************************************************************
  297.  //
  298. -static bool callvote_CheckValidity( FString &Command, FString &Parameters )
  299. +static bool callvote_CheckValidity( ULONG Type, FString& Parameters )
  300.  {
  301.     // Get the type of vote this is.
  302. +/*
  303.     ULONG   ulVoteCmd = callvote_GetVoteType( Command.GetChars( ));
  304.     if ( ulVoteCmd == NUM_VOTECMDS )
  305.         return ( false );
  306. +*/
  307.  
  308.     // Check for any illegal characters.
  309. -   if ( ulVoteCmd != VOTECMD_KICK )
  310. +   // if ( ulVoteCmd != VOTECMD_KICK )
  311.     {
  312.         int i = 0;
  313.         while ( Parameters.GetChars()[i] != '\0' )
  314. @@ -729,97 +756,14 @@
  315.     }
  316.  
  317.     // Then, make sure the parameter for each vote is valid.
  318. +   // [Dusk] Use VoteDef::applyCommand to test this
  319.     int parameterInt = atoi( Parameters.GetChars() );
  320. -   switch ( ulVoteCmd )
  321. +   VoteDef::ApplyResult output;
  322. +
  323. +   if( !VoteDef::applyCommand( g_VoteData, output ))
  324.     {
  325. -   case VOTECMD_KICK:
  326. -       {
  327. -           if ( NETWORK_GetState( ) == NETSTATE_SERVER )
  328. -           {
  329. -               // Store the player's IP so he can't get away.
  330. -               ULONG ulIdx = SERVER_GetPlayerIndexFromName( Parameters.GetChars( ), true, false );
  331. -               if ( ulIdx < MAXPLAYERS )
  332. -               {
  333. -                   if ( static_cast<LONG>(ulIdx) == SERVER_GetCurrentClient( ))
  334. -                   {
  335. -                       SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "You cannot votekick yourself!\n" );
  336. -                       return ( false );
  337. -                   }
  338. -                   // [BB] Don't allow anyone to kick somebody who is on the admin list.
  339. -                   if ( SERVER_GetAdminList()->isIPInList( SERVER_GetClient( ulIdx )->Address ) )
  340. -                   {
  341. -                       SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "This player is a server admin and thus can't be kicked!\n" );
  342. -                       return ( false );
  343. -                   }
  344. -                   g_KickVoteVictimAddress = SERVER_GetClient( ulIdx )->Address;
  345. -                   return ( true );
  346. -               }
  347. -               else
  348. -               {
  349. -                   SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "That player doesn't exist.\n" );
  350. -                   return ( false );
  351. -               }
  352. -           }
  353. -       }
  354. -       break;
  355. -   case VOTECMD_MAP:
  356. -   case VOTECMD_CHANGEMAP:
  357. -
  358. -       // Don't allow the command if the map doesn't exist.
  359. -       if ( !P_CheckIfMapExists( Parameters.GetChars( )))
  360. -       {
  361. -           if ( NETWORK_GetState( ) == NETSTATE_SERVER )
  362. -               SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "That map does not exist.\n" );
  363. -           return ( false );
  364. -       }
  365. -      
  366. -       // Don't allow us to leave the map rotation.
  367. -       if ( NETWORK_GetState( ) == NETSTATE_SERVER )
  368. -       {
  369. -           if ( sv_maprotation && ( MAPROTATION_IsMapInRotation( Parameters.GetChars( ) ) == false ) )
  370. -           {
  371. -               SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "That map is not in the map rotation.\n" );
  372. -               return ( false );
  373. -           }
  374. -       }
  375. -       break;
  376. -   case VOTECMD_FRAGLIMIT:
  377. -   case VOTECMD_WINLIMIT:
  378. -   case VOTECMD_DUELLIMIT:
  379. -
  380. -       // Parameteter be between 0 and 255.
  381. -       if (( parameterInt < 0 ) || ( parameterInt >= 256 ))
  382. -       {
  383. -           if ( NETWORK_GetState( ) == NETSTATE_SERVER )
  384. -               SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "%s parameters must be between 0 and 255.\n", Command.GetChars() );
  385. -           return ( false );
  386. -       }
  387. -       else if ( parameterInt == 0 )
  388. -       {
  389. -           if (( Parameters.GetChars()[0] != '0' ) || ( Parameters.Len() != 1 ))
  390. -               return ( false );
  391. -       }
  392. -       Parameters.Format( "%d", parameterInt );
  393. -       break;
  394. -   case VOTECMD_TIMELIMIT:
  395. -   case VOTECMD_POINTLIMIT:
  396. -
  397. -       // Parameteter must be between 0 and 65535.
  398. -       if (( parameterInt < 0 ) || ( parameterInt >= 65536 ))
  399. -       {
  400. -           if ( NETWORK_GetState( ) == NETSTATE_SERVER )
  401. -               SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient( ), "%s parameters must be between 0 and 65535.\n", Command.GetChars() );
  402. -           return ( false );
  403. -       }
  404. -       else if ( parameterInt == 0 )
  405. -       {
  406. -           if (( Parameters.GetChars()[0] != '0' ) || ( Parameters.Len() != 1 ))
  407. -               return ( false );
  408. -       }
  409. -       Parameters.Format( "%d", parameterInt );
  410. -       break;
  411. -   default:
  412. -
  413. +       SERVER_PrintfPlayer( PRINT_HIGH, SERVER_GetCurrentClient(),
  414. +           "Cannot call that vote: %s\n", output.error.GetChars() );
  415.         return ( false );
  416.     }
  417.  
  418. @@ -828,30 +772,6 @@
  419.  }
  420.  
  421.  //*****************************************************************************
  422. -//
  423. -static ULONG callvote_GetVoteType( const char *pszCommand )
  424. -{
  425. -   if ( stricmp( "kick", pszCommand ) == 0 )
  426. -       return VOTECMD_KICK;
  427. -   else if ( stricmp( "map", pszCommand ) == 0 )
  428. -       return VOTECMD_MAP;
  429. -   else if ( stricmp( "changemap", pszCommand ) == 0 )
  430. -       return VOTECMD_CHANGEMAP;
  431. -   else if ( stricmp( "fraglimit", pszCommand ) == 0 )
  432. -       return VOTECMD_FRAGLIMIT;
  433. -   else if ( stricmp( "timelimit", pszCommand ) == 0 )
  434. -       return VOTECMD_TIMELIMIT;
  435. -   else if ( stricmp( "winlimit", pszCommand ) == 0 )
  436. -       return VOTECMD_WINLIMIT;
  437. -   else if ( stricmp( "duellimit", pszCommand ) == 0 )
  438. -       return VOTECMD_DUELLIMIT;
  439. -   else if ( stricmp( "pointlimit", pszCommand ) == 0 )
  440. -       return VOTECMD_POINTLIMIT;
  441. -
  442. -   return NUM_VOTECMDS;
  443. -}
  444. -
  445. -//*****************************************************************************
  446.  // CONSOLE COMMANDS/VARIABLES
  447.  
  448.  CUSTOM_CVAR( Int, sv_minvoters, 1, CVAR_ARCHIVE )
  449. @@ -874,6 +794,8 @@
  450.  CCMD( callvote )
  451.  {
  452.     ULONG   ulVoteCmd;
  453. +   FString arg, reason;
  454. +   VoteDef* pVoteDef;
  455.  
  456.     // Don't allow a vote unless the player is a client.
  457.     if ( NETWORK_GetState( ) != NETSTATE_CLIENT )
  458. @@ -885,7 +807,7 @@
  459.     if ( CLIENT_GetConnectionState( ) != CTS_ACTIVE )
  460.         return;
  461.  
  462. -   if ( argv.argc( ) < 3 )
  463. +   if ( argv.argc( ) < 2 )
  464.     {
  465.         Printf( "callvote <command> <parameters> [reason]: Calls a vote\n" );
  466.         return;
  467. @@ -898,22 +820,33 @@
  468.         return;
  469.     }
  470.  
  471. -   ulVoteCmd = callvote_GetVoteType( argv[1] );
  472. -   if ( ulVoteCmd == NUM_VOTECMDS )
  473. +   pVoteDef = VoteDef::findByName( argv[1] );
  474. +   if ( pVoteDef == NULL )
  475.     {
  476.         Printf( "Invalid callvote command.\n" );
  477.         return;
  478.     }
  479.  
  480. -   if ( argv.argc( ) >= 4 )
  481. -       CLIENTCOMMANDS_CallVote( ulVoteCmd, argv[2], argv[3] );
  482. +   // [Dusk] We may need a second argument
  483. +   if ( pVoteDef->argType( ) != VoteDef::NumArgTypes )
  484. +   {
  485. +       if ( argv.argc( ) < 3 )
  486. +       {
  487. +           Printf( "You need to supply an argument to call a %s vote:\nUsage: %s",
  488. +                   pVoteDef->name( ).GetChars( ), pVoteDef->getUsage( ).GetChars( ));
  489. +           return;
  490. +       }
  491. +      
  492. +       arg = ( argv.argc( ) >= 3 ) ? argv[2] : "";
  493. +       reason = ( argv.argc( ) >= 4 ) ? argv[3] : "";
  494. +   }
  495.     else
  496. -       CLIENTCOMMANDS_CallVote( ulVoteCmd, argv[2], "" );
  497. -/*
  498. -   g_lBytesSent += g_LocalBuffer.cursize;
  499. -   if ( g_lBytesSent > g_lMaxBytesSent )
  500. -       g_lMaxBytesSent = g_lBytesSent;
  501. -*/
  502. +   {
  503. +       arg = "";
  504. +       reason = ( argv.argc( ) >= 3 ) ? argv[2] : "";
  505. +   }
  506. +
  507. +   CLIENTCOMMANDS_CallVote( pVoteDef->getIndex(), arg, reason );
  508.     NETWORK_LaunchPacket( CLIENT_GetLocalBuffer( ), CLIENT_GetServerAddress( ));
  509.     NETWORK_ClearBuffer( CLIENT_GetLocalBuffer( ));
  510.  }
  511. diff -r af45c72387f5 src/callvote.h
  512. --- a/src/callvote.h    Sat Jul 27 09:47:16 2013 +0200
  513. +++ b/src/callvote.h    Fri Aug 02 02:25:44 2013 +0300
  514. @@ -67,21 +67,6 @@
  515.  #define VOTE_LONGEST_INTERVAL          10  // Sets when old votes are removed from the flood cache. Set to the longest interval of the above.
  516.  
  517.  //*****************************************************************************
  518. -enum
  519. -{
  520. -   VOTECMD_KICK,
  521. -   VOTECMD_MAP,
  522. -   VOTECMD_CHANGEMAP,
  523. -   VOTECMD_FRAGLIMIT,
  524. -   VOTECMD_TIMELIMIT,
  525. -   VOTECMD_WINLIMIT,
  526. -   VOTECMD_DUELLIMIT,
  527. -   VOTECMD_POINTLIMIT,
  528. -
  529. -   NUM_VOTECMDS
  530. -};
  531. -
  532. -//*****************************************************************************
  533.  typedef enum
  534.  {
  535.     VOTESTATE_NOVOTE,
  536. @@ -101,18 +86,18 @@
  537.     // Time that this vote was called.
  538.     time_t          tTimeCalled;
  539.  
  540. -   // The type of vote (see NUM_VOTECMDS).
  541. +   // The type of vote.
  542.     ULONG           ulVoteType;
  543. -  
  544. +
  545.     // Parameter of the vote ("map01", "50", etc).
  546.     FString         fsParameter;
  547.  
  548. -   // For kick votes: the address being kicked.
  549. -   NETADDRESS_s    KickAddress;
  550. -
  551.     // Was it passed?
  552.     bool            bPassed;
  553.  
  554. +   // [Dusk] VoteDef summary
  555. +   FString         fsSummary;
  556. +
  557.  } VOTE_s;
  558.  
  559.  //*****************************************************************************
  560. @@ -121,7 +106,7 @@
  561.  void           CALLVOTE_Construct( void );
  562.  void           CALLVOTE_Tick( void );
  563.  //void         CALLVOTE_Render( void );
  564. -void           CALLVOTE_BeginVote( FString Command, FString Parameters, FString Reason, ULONG ulPlayer );
  565. +void           CALLVOTE_BeginVote( ULONG Command, FString Parameters, FString Reason, ULONG ulPlayer );
  566.  void           CALLVOTE_ClearVote( void );
  567.  bool           CALLVOTE_VoteYes( ULONG ulPlayer );
  568.  bool           CALLVOTE_VoteNo( ULONG ulPlayer );
  569. diff -r af45c72387f5 src/cl_main.cpp
  570. --- a/src/cl_main.cpp   Sat Jul 27 09:47:16 2013 +0200
  571. +++ b/src/cl_main.cpp   Fri Aug 02 02:25:44 2013 +0300
  572. @@ -9859,7 +9859,7 @@
  573.  //
  574.  static void client_CallVote( BYTESTREAM_s *pByteStream )
  575.  {
  576. -   FString     command;
  577. +   ULONG       ulCommand;
  578.     FString     parameters;
  579.     FString     reason;
  580.     ULONG       ulVoteCaller;
  581. @@ -9868,7 +9868,7 @@
  582.     ulVoteCaller = NETWORK_ReadByte( pByteStream );
  583.  
  584.     // Read in the command.
  585. -   command = NETWORK_ReadString( pByteStream );
  586. +   ulCommand = NETWORK_ReadLong( pByteStream );
  587.  
  588.     // Read in the parameters.
  589.     parameters = NETWORK_ReadString( pByteStream );
  590. @@ -9877,7 +9877,7 @@
  591.     reason = NETWORK_ReadString( pByteStream );
  592.  
  593.     // Begin the vote!
  594. -   CALLVOTE_BeginVote( command, parameters, reason, ulVoteCaller );
  595. +   CALLVOTE_BeginVote( ulCommand, parameters, reason, ulVoteCaller );
  596.  }
  597.  
  598.  //*****************************************************************************
  599. diff -r af45c72387f5 src/d_main.cpp
  600. --- a/src/d_main.cpp    Sat Jul 27 09:47:16 2013 +0200
  601. +++ b/src/d_main.cpp    Fri Aug 02 02:25:44 2013 +0300
  602. @@ -140,6 +140,7 @@
  603.  #include "g_shared/pwo.h"
  604.  
  605.  #include "win32/g15/g15.h"
  606. +#include "votedef.h"
  607.  EXTERN_CVAR(Bool, hud_althud)
  608.  void DrawHUD();
  609.  
  610. @@ -2113,6 +2114,9 @@
  611.     // [BB] Parse the GAMEMODE lump.
  612.     GAMEMODE_ParseGamemodeInfo( );
  613.  
  614. +   // [Dusk] Initialize vote definitions
  615. +   VoteDef::init();
  616. +
  617.     // [RH] Initialize localizable strings.
  618.     GStrings.LoadStrings (false);
  619.  
  620. diff -r af45c72387f5 src/m_menu.h
  621. --- a/src/m_menu.h  Sat Jul 27 09:47:16 2013 +0200
  622. +++ b/src/m_menu.h  Fri Aug 02 02:25:44 2013 +0300
  623. @@ -141,6 +141,7 @@
  624.     weaponslot,
  625.     txslider,
  626.     mnnumber,
  627. +   votetype, // [Dusk]
  628.  
  629.  } itemtype;
  630.  
  631. diff -r af45c72387f5 src/m_options.cpp
  632. --- a/src/m_options.cpp Sat Jul 27 09:47:16 2013 +0200
  633. +++ b/src/m_options.cpp Fri Aug 02 02:25:44 2013 +0300
  634. @@ -109,6 +109,7 @@
  635.  
  636.  // [ZZ] PWO header file
  637.  #include "g_shared/pwo.h"
  638. +#include "votedef.h"
  639.  
  640.  // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  641.  
  642. @@ -191,6 +192,11 @@
  643.  static LONG    g_lSavedColor;
  644.  static bool    g_bSwitchColorBack;
  645.  
  646. +// [Dusk] I want to display an error prompt if the vote type validation fails.
  647. +// M_StartMessage however relies on the value being a char array - so I'm defining
  648. +// a buffer here for that.
  649. +static char g_VoteMenuFailure[256];
  650. +
  651.  value_t YesNo[2] = {
  652.     { 0.0, "No" },
  653.     { 1.0, "Yes" }
  654. @@ -1768,8 +1774,10 @@
  655.     if ( !bAllowBots && ( players[lPlayer].bIsBot ))
  656.         return ( false );
  657.  
  658. +/*
  659.     if ( lPlayer == consoleplayer )
  660.         return ( false );
  661. +*/
  662.  
  663.     return ( true );
  664.  }
  665. @@ -1887,221 +1895,69 @@
  666.  
  667.  //====================================================================================
  668.  //
  669. -// Call Vote-->Kick Player Menu
  670. -//
  671. -//====================================================================================
  672. -
  673. -CVAR( String, menu_votereason, "", 0 );
  674. -
  675. -void kickplayermenu_Kick( void );
  676. -
  677. -//*****************************************************************************
  678. -//
  679. -static menuitem_t kickplayermenu_Items[] =
  680. -{
  681. -   { discretes,"Player",           {&menu_playerslider_idx},           {1.0}, {0.0},   {0.0}, {NULL} },
  682. -   { redtext,  " ",                {NULL},                 {0.0}, {0.0},   {0.0}, {NULL} },
  683. -   { string,   "Reason for kicking:",{&menu_votereason},           {0.0}, {0.0},   {0.0}, {NULL} },
  684. -   { more,     "Kick!",            {NULL},                         {0.0}, {0.0},   {0.0}, {(value_t *)kickplayermenu_Kick} },
  685. -};
  686. -
  687. -// [BB, RC] Line number of the "Player:" entry from kickplayermenu_Items. If the line number is changed, the value has to be adjusted.
  688. -#define KICKPLAYER_SLIDER_LOCATION 0
  689. -
  690. -//*****************************************************************************
  691. -//
  692. -menu_t KickPlayerMenu = {
  693. -   "KICK A PLAYER",
  694. -   0,
  695. -   countof(kickplayermenu_Items),
  696. -   0,
  697. -   kickplayermenu_Items,
  698. -   0,
  699. -   0,
  700. -};
  701. -
  702. -//*****************************************************************************
  703. -//
  704. -void kickplayermenu_Kick( void )
  705. -{
  706. -   // Clean the name of color codes.
  707. -   FString Name = AvailablePlayers[menu_playerslider_idx].name.GetChars( );
  708. -   V_RemoveColorCodes( Name );
  709. -   V_EscapeBacklashes( Name );
  710. -
  711. -   FString Reason = menu_votereason.GetGenericRep( CVAR_String ).String;
  712. -   V_EscapeBacklashes( Reason );
  713. -
  714. -   // Execute the command.
  715. -   char    szString[256];
  716. -   sprintf( szString, "callvote kick \"%s\" \"%s\"", Name.Left( 96 ).GetChars(), Reason.Left( 25 ).GetChars());
  717. -   AddCommandString( szString );
  718. -   M_ClearMenus( );
  719. -}
  720. -
  721. -//*****************************************************************************
  722. -//
  723. -void kickplayermenu_Show( void )
  724. -{
  725. -   if ( SERVER_CountPlayers( false ) < 2 )
  726. -   {
  727. -       M_ClearMenus( );
  728. -       M_StartMessage( "There is nobody else here to kick!\n\npress any key.", NULL, false );
  729. -       return;
  730. -   }
  731. -
  732. -   // Set up the player selection slider.
  733. -   playerslider_BuildList( false );
  734. -   kickplayermenu_Items[KICKPLAYER_SLIDER_LOCATION].b.numvalues = static_cast<float>(AvailablePlayers.Size());
  735. -   kickplayermenu_Items[KICKPLAYER_SLIDER_LOCATION].e.valuestrings = &AvailablePlayers[0];
  736. -
  737. -   M_SwitchMenu( &KickPlayerMenu );
  738. -}
  739. -
  740. -//====================================================================================
  741. -//
  742. -// Call Vote-->Map Menu
  743. -//
  744. -//====================================================================================
  745. -
  746. -CVAR( String, menu_mapvotemap, "", 0 );
  747. -CVAR( Bool, menu_mapvoteintermission, false, 0 );
  748. -
  749. -//*****************************************************************************
  750. -//
  751. -void mapvotemenu_Vote( void )
  752. -{
  753. -   // Sanitize the inputs.
  754. -   FString     Map = menu_mapvotemap.GetGenericRep( CVAR_String ).String;
  755. -   FString     Reason = menu_votereason.GetGenericRep( CVAR_String ).String;
  756. -   V_EscapeBacklashes( Map );
  757. -   V_EscapeBacklashes( Reason );
  758. -
  759. -   if ( !Map.Len( ) )
  760. -   {
  761. -       Printf( "You didn't specify a map!\n" );
  762. -       return;
  763. -   }
  764. -
  765. -   // Execute the command.
  766. -   char        szString[256];
  767. -   sprintf( szString, "callvote %s %s \"%s\"", ( menu_mapvoteintermission.GetGenericRep( CVAR_Bool ).Bool ? "changemap" : "map" ), Map.Left( 128 ).GetChars(), Reason.Left( 25 ).GetChars() );
  768. -   AddCommandString( szString );
  769. -   M_ClearMenus( );
  770. -}
  771. -
  772. -//*****************************************************************************
  773. -//
  774. -static menuitem_t mapvotemenu_Items[] =
  775. -{
  776. -   { string,   "Map",              {&menu_mapvotemap},             {0.0}, {0.0},   {0.0}, {NULL} },
  777. -   { discrete, "Intermission",     {&menu_mapvoteintermission},    {2.0}, {0.0},   {0.0}, {YesNo} },  
  778. -   { redtext,  " ",                {NULL},                         {0.0}, {0.0},   {0.0}, {NULL} },
  779. -   { string,   "Reason for change:",{&menu_votereason},            {0.0}, {0.0},   {0.0}, {NULL} },
  780. -   { more,     "Vote!",            {NULL},                         {0.0}, {0.0},   {0.0}, {(value_t *)mapvotemenu_Vote} },
  781. -};
  782. -
  783. -//*****************************************************************************
  784. -//
  785. -menu_t MapVoteMenu = {
  786. -   "CHANGE MAP",
  787. -   0,
  788. -   countof(mapvotemenu_Items),
  789. -   0,
  790. -   mapvotemenu_Items,
  791. -   0,
  792. -   0,
  793. -};
  794. -
  795. -//*****************************************************************************
  796. -//
  797. -void mapvotemenu_Show( void )
  798. -{
  799. -   M_SwitchMenu( &MapVoteMenu );
  800. -}
  801. -
  802. -//====================================================================================
  803. -//
  804. -// Call Vote-->Limit Menu
  805. -//
  806. -//====================================================================================
  807. -
  808. -//*****************************************************************************
  809. -//
  810. -value_t limitvote_Types[5] = {
  811. -   { 0.0, "fraglimit" },
  812. -   { 1.0, "timelimit" },
  813. -   { 2.0, "winlimit" },
  814. -   { 3.0, "duellimit" },
  815. -   { 4.0, "pointlimit" }
  816. -};
  817. -
  818. -//*****************************************************************************
  819. -//
  820. -CVAR( Int, menu_limitvote_type, 0, 0 );
  821. -CVAR( String, menu_limitvote_value, "", 0 );
  822. -
  823. -//*****************************************************************************
  824. -//
  825. -void limitvotemenu_Vote( void )
  826. -{
  827. -   // Sanitize the inputs.
  828. -   int         iVoteType = menu_limitvote_type.GetGenericRep( CVAR_Int ).Int;
  829. -   int         iLimit =  atoi( menu_limitvote_value.GetGenericRep( CVAR_String ).String );
  830. -   FString     Reason = menu_votereason.GetGenericRep( CVAR_String ).String;
  831. -   V_EscapeBacklashes( Reason );
  832. -
  833. -   if ( iVoteType >= 5 || iVoteType < 0 )
  834. -       return;
  835. -
  836. -   // Execute the command.
  837. -   char        szString[512];
  838. -   sprintf( szString, "callvote %s %d \"%s\"", limitvote_Types[iVoteType].name, iLimit, Reason.Left( 25 ).GetChars() );
  839. -   AddCommandString( szString );
  840. -   M_ClearMenus( );
  841. -}
  842. -
  843. -//*****************************************************************************
  844. -//
  845. -static menuitem_t limitvotemenu_Items[] =
  846. -{
  847. -   { discrete, "Type of limit",    {&menu_limitvote_type},         {5.0}, {0.0},   {0.0}, {limitvote_Types} },
  848. -   { string,   "New value",        {&menu_limitvote_value},        {0.0}, {0.0},   {0.0}, {NULL} },
  849. -   { redtext,  " ",                {NULL},                         {0.0}, {0.0},   {0.0}, {NULL} },
  850. -   { string,   "Reason for change:",{&menu_votereason},            {0.0}, {0.0},   {0.0}, {NULL} },   
  851. -   { more,     "Vote!",            {NULL},                         {0.0}, {0.0},   {0.0}, {(value_t *)limitvotemenu_Vote} },
  852. -};
  853. -
  854. -//*****************************************************************************
  855. -//
  856. -menu_t limitvoteMenu = {
  857. -   "CHANGE LIMIT",
  858. -   0,
  859. -   countof(limitvotemenu_Items),
  860. -   0,
  861. -   limitvotemenu_Items,
  862. -   0,
  863. -   0,
  864. -};
  865. -
  866. -//*****************************************************************************
  867. -//
  868. -void limitvotemenu_Show( void )
  869. -{
  870. -   M_SwitchMenu( &limitvoteMenu );
  871. -}
  872. -
  873. -//====================================================================================
  874. -//
  875.  // Call Vote Menu
  876.  //
  877.  //====================================================================================
  878.  
  879. +// [Dusk]
  880. +CVAR( Int, menu_votetype, 0, CVAR_ARCHIVE )
  881. +CVAR( String, menu_votearg, "", CVAR_ARCHIVE )
  882. +CVAR( Int, menu_votenumarg, 0, CVAR_ARCHIVE )
  883. +CVAR( String, menu_votereason, "", 0 )
  884. +
  885. +// [Dusk] Call a VOTEDEF-based vote
  886. +static void votemenu_go( )
  887. +{
  888. +   M_ClearMenus();
  889. +
  890. +   VoteDef* def = VoteDef::findByIndex( menu_votetype );
  891. +   if ( !def )
  892. +       return;
  893. +
  894. +   VoteDef::ApplyInput in;
  895. +   VoteDef::ApplyResult out;
  896. +   in.type = menu_votetype;
  897. +   in.caller = consoleplayer;
  898. +
  899. +   // [Dusk] Determine the argument to callvote.
  900. +   if ( def->argType() == VoteDef::MapType )
  901. +   {
  902. +       // [Dusk] If this is a map, we need to pass the string argument
  903. +       in.arg = menu_votearg;
  904. +   }
  905. +   else if ( def->argType() == VoteDef::Player && !( def->flags() & VoteDef::PlayerIndex ))
  906. +   {
  907. +       // [Dusk] A player's name is wanted - pass that.
  908. +       in.arg = players[menu_votenumarg].userinfo.netname;
  909. +       V_ColorizeString( in.arg );
  910. +       V_RemoveColorCodes( in.arg );
  911. +   }
  912. +   else // [Dusk] Otherwise pass the numeric value
  913. +       in.arg.Format( "%d", (int) menu_votenumarg );
  914. +
  915. +   // [Dusk] Validate the vote command now
  916. +   if ( VoteDef::applyCommand( in, out ))
  917. +   {
  918. +       // [Dusk] Vote seems good, call it now.
  919. +       CLIENTCOMMANDS_CallVote( menu_votetype, in.arg, menu_votereason );
  920. +       NETWORK_LaunchPacket( CLIENT_GetLocalBuffer( ), CLIENT_GetServerAddress( ));
  921. +       NETWORK_ClearBuffer( CLIENT_GetLocalBuffer( ));
  922. +   }
  923. +   else
  924. +   {
  925. +       // [Dusk] Failed - tell the user why.
  926. +       sprintf( g_VoteMenuFailure, "Couldn't call that: %s\n\npress any key.", out.error.GetChars() );
  927. +       M_StartMessage( g_VoteMenuFailure, NULL, false );
  928. +   }
  929. +}
  930. +
  931.  static menuitem_t CallVoteItems[] =
  932.  {
  933. -   { more,     "Kick a player",            {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)kickplayermenu_Show} },
  934. -   { more,     "Change the map",           {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)mapvotemenu_Show} },
  935. -   { more,     "Change a limit",           {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)limitvotemenu_Show} },
  936. +   { votetype, "Vote action",      {&menu_votetype},       {0.0}, {100.0}, {1.0}, {NULL} },
  937. +   { string,   "Vote argument",    {&menu_votearg},        {0.0}, {0.0},   {0.0}, {NULL} },
  938. +   { string,   "Reason for vote",  {&menu_votereason},     {0.0}, {0.0},   {0.0}, {NULL} },
  939. +   { redtext,  " ",                {NULL},                 {0.0}, {0.0},   {0.0}, {NULL} },
  940. +   { more,     "Call the vote",    {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *) votemenu_go} },
  941.  };
  942.  
  943.  menu_t CallVoteMenu = {
  944. @@ -2127,6 +1983,7 @@
  945.  void M_StartBrowserMenu( void );
  946.  void M_Spectate( void );
  947.  void M_CallVote( void );
  948. +void M_VoteTypeChanged( bool first );
  949.  void M_ChangeTeam( void );
  950.  void M_Skirmish( void );
  951.  
  952. @@ -2140,7 +1997,7 @@
  953.     { more,     "Spectate",             {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)M_Spectate} },
  954.     { more,     "Switch teams",             {NULL},                 {0.0}, {0.0}, {0.0}, {(value_t *)M_ChangeTeam} },
  955.     { redtext,  " ",                    {NULL},                 {0.0}, {0.0},   {0.0}, {NULL} },
  956. -   { more,     "Call a vote",          {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)M_CallVote} },  
  957. +   { more,     "Call a vote",          {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)M_CallVote} },
  958.     { more,     "Ignore a player",          {NULL},                 {0.0}, {0.0},   {0.0}, {(value_t *)ignoreplayermenu_Show} },
  959.     { redtext,  " ",                    {NULL},                 {0.0}, {0.0},   {0.0}, {NULL} },
  960.     { discrete, "Allow skins",          {&cl_skins},            {3.0}, {0.0},   {0.0}, {AllowSkinVals} },
  961. @@ -2191,10 +2048,69 @@
  962.         return;
  963.     }
  964.  
  965. +   M_VoteTypeChanged( true );
  966.     M_SwitchMenu( &CallVoteMenu );
  967.  }
  968.  
  969.  //*****************************************************************************
  970. +// [Dusk] Hmm. Now that votes are generalized the argument passed is of variable
  971. +// type. Thus, we have to change the argument field dynamically based on the type
  972. +// of the argument of the vote we scrolled to.
  973. +//
  974. +// This also resets the argument, first because the argument of one type may be
  975. +// out of bounds or otherwise of completely different meaning for another.
  976. +void M_VoteTypeChanged( bool first )
  977. +{
  978. +   VoteDef* def = VoteDef::findByIndex( menu_votetype );
  979. +   if ( !def )
  980. +       return;
  981. +
  982. +   VoteDef::ArgumentType argtype = def->argType();
  983. +   menuitem_t* item = &CallVoteItems[1];
  984. +   item->label = "Vote argument";
  985. +
  986. +   switch ( argtype )
  987. +   {
  988. +       case VoteDef::Player:
  989. +           // Set up the player selection slider.
  990. +           playerslider_BuildList( false );
  991. +           item->type = discretes;
  992. +           item->a.intcvar = &menu_votenumarg;
  993. +           item->b.numvalues = static_cast<float>( AvailablePlayers.Size( ));
  994. +           item->e.valuestrings = &AvailablePlayers[0];
  995. +
  996. +           if ( !first )
  997. +               menu_votenumarg = AvailablePlayers[0].value;
  998. +           break;
  999. +
  1000. +       case VoteDef::Int:
  1001. +       case VoteDef::Float:
  1002. +           item->type = number;
  1003. +           item->a.intcvar = &menu_votenumarg;
  1004. +           item->b.min = def->min();
  1005. +           item->c.max = def->max();
  1006. +           item->d.step = 1.0f;
  1007. +
  1008. +           if ( !first )
  1009. +               menu_votenumarg = def->min();
  1010. +           break;
  1011. +
  1012. +       case VoteDef::MapType:
  1013. +           item->type = string;
  1014. +           item->a.stringcvar = &menu_votearg;
  1015. +
  1016. +           if ( !first )
  1017. +               menu_votearg = "";
  1018. +           break;
  1019. +
  1020. +       case VoteDef::NumArgTypes:
  1021. +           item->type = redtext;
  1022. +           item->label = "";
  1023. +           break;
  1024. +   }
  1025. +}
  1026. +
  1027. +//*****************************************************************************
  1028.  //
  1029.  void M_SkulltagVersionDrawer( void )
  1030.  {
  1031. @@ -5097,6 +5013,24 @@
  1032.                     screen->DrawText( SmallFont, CR_GREY, x, y, szString, DTA_Clean, true, TAG_DONE );
  1033.                 }
  1034.                 break;
  1035. +
  1036. +           // [Dusk]
  1037. +           case votetype:
  1038. +               {
  1039. +                   VoteDef* def = VoteDef::findByIndex( *item->a.intcvar );
  1040. +                   FString text;
  1041. +
  1042. +                   if ( !def )
  1043. +                       text = "UNKNOWN";
  1044. +                   else if ( def->description( ).IsNotEmpty( ))
  1045. +                       text = def->description( );
  1046. +                   else
  1047. +                       text = def->name( );
  1048. +
  1049. +                   screen->DrawText( SmallFont, CR_GREY, x, y, text.GetChars(), DTA_Clean, true, TAG_DONE );
  1050. +               }
  1051. +               break;
  1052. +
  1053.             default:
  1054.                 break;
  1055.             }
  1056. @@ -5989,6 +5923,21 @@
  1057.                 S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
  1058.                 break;
  1059.  
  1060. +           // [Dusk]
  1061. +           case votetype:
  1062. +               {
  1063. +                   int i = *item->a.intcvar;
  1064. +                   i--;
  1065. +
  1066. +                   if ( i < 0 )
  1067. +                       i = VoteDef::numTypes() - 1;
  1068. +
  1069. +                   *item->a.intcvar = i;
  1070. +               }
  1071. +               M_VoteTypeChanged( false );
  1072. +               S_Sound( CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE );
  1073. +               break;
  1074. +
  1075.             default:
  1076.                 break;
  1077.         }
  1078. @@ -6421,6 +6370,21 @@
  1079.                 S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
  1080.                 break;
  1081.  
  1082. +           // [Dusk]
  1083. +           case votetype:
  1084. +               {
  1085. +                   int i = *item->a.intcvar;
  1086. +                   i++;
  1087. +
  1088. +                   if ( i >= (int) VoteDef::numTypes() )
  1089. +                       i = 0;
  1090. +
  1091. +                   *item->a.intcvar = i;
  1092. +               }
  1093. +               M_VoteTypeChanged( false );
  1094. +               S_Sound( CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE );
  1095. +               break;
  1096. +
  1097.             default:
  1098.                 break;
  1099.         }
  1100. diff -r af45c72387f5 src/network.cpp
  1101. --- a/src/network.cpp   Sat Jul 27 09:47:16 2013 +0200
  1102. +++ b/src/network.cpp   Fri Aug 02 02:25:44 2013 +0300
  1103. @@ -307,6 +307,8 @@
  1104.     lumpsToAuthenticateMode.push_back( ALL_LUMPS );
  1105.     lumpsToAuthenticate.push_back( "GAMEMODE" );
  1106.     lumpsToAuthenticateMode.push_back( ALL_LUMPS );
  1107. +   lumpsToAuthenticate.push_back( "VOTEDEF" );
  1108. +   lumpsToAuthenticateMode.push_back( ALL_LUMPS );
  1109.  
  1110.     FString checksum, longChecksum;
  1111.     bool noProtectedLumpsAutoloaded = true;
  1112. diff -r af45c72387f5 src/sv_commands.cpp
  1113. --- a/src/sv_commands.cpp   Sat Jul 27 09:47:16 2013 +0200
  1114. +++ b/src/sv_commands.cpp   Fri Aug 02 02:25:44 2013 +0300
  1115. @@ -5348,31 +5348,14 @@
  1116.  //*****************************************************************************
  1117.  //*****************************************************************************
  1118.  //
  1119. -void SERVERCOMMANDS_CallVote( ULONG ulPlayer, FString Command, FString Parameters, FString Reason, ULONG ulPlayerExtra, ULONG ulFlags )
  1120. -{
  1121. -   ULONG   ulIdx;
  1122. -
  1123. -   if ( PLAYER_IsValidPlayer( ulPlayer ) == false )
  1124. -       return;
  1125. -
  1126. -   for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ )
  1127. -   {
  1128. -       if ( SERVER_IsValidClient( ulIdx ) == false )
  1129. -           continue;
  1130. -
  1131. -       if ((( ulFlags & SVCF_SKIPTHISCLIENT ) && ( ulPlayerExtra == ulIdx )) ||
  1132. -           (( ulFlags & SVCF_ONLYTHISCLIENT ) && ( ulPlayerExtra != ulIdx )))
  1133. -       {
  1134. -           continue;
  1135. -       }
  1136. -
  1137. -       SERVER_CheckClientBuffer( ulIdx, 2 + ULONG( Command.Len() ) + ULONG ( Parameters.Len() ), true );
  1138. -       NETWORK_WriteHeader( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, SVC_CALLVOTE );
  1139. -       NETWORK_WriteByte( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, ulPlayer );
  1140. -       NETWORK_WriteString( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, Command.GetChars() );
  1141. -       NETWORK_WriteString( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, Parameters.GetChars() );
  1142. -       NETWORK_WriteString( &SERVER_GetClient( ulIdx )->PacketBuffer.ByteStream, Reason.GetChars() );
  1143. -   }
  1144. +void SERVERCOMMANDS_CallVote( ULONG ulPlayer, ULONG Command, FString Parameters, FString Reason, ULONG ulPlayerExtra, ULONG ulFlags )
  1145. +{
  1146. +   NetCommand command( SVC_CALLVOTE );
  1147. +   command.addByte( ulPlayer );
  1148. +   command.addLong( Command );
  1149. +   command.addString( Parameters );
  1150. +   command.addString( Reason );
  1151. +   command.sendCommandToClients( ulPlayerExtra, ulFlags );
  1152.  }
  1153.  
  1154.  //*****************************************************************************
  1155. diff -r af45c72387f5 src/sv_commands.h
  1156. --- a/src/sv_commands.h Sat Jul 27 09:47:16 2013 +0200
  1157. +++ b/src/sv_commands.h Fri Aug 02 02:25:44 2013 +0300
  1158. @@ -272,7 +272,7 @@
  1159.  void   SERVERCOMMANDS_StopSectorSequence( sector_t *pSector, ULONG ulPlayerExtra = MAXPLAYERS, ULONG ulFlags = 0 );
  1160.  
  1161.  // Voting commands. These handle the voting.
  1162. -void   SERVERCOMMANDS_CallVote( ULONG ulPlayer, FString Command, FString Parameters, FString Reason, ULONG ulPlayerExtra = MAXPLAYERS, ULONG ulFlags = 0 );
  1163. +void   SERVERCOMMANDS_CallVote( ULONG ulPlayer, ULONG Command, FString Parameters, FString Reason, ULONG ulPlayerExtra = MAXPLAYERS, ULONG ulFlags = 0 );
  1164.  void   SERVERCOMMANDS_PlayerVote( ULONG ulPlayer, bool bVoteYes, ULONG ulPlayerExtra = MAXPLAYERS, ULONG ulFlags = 0 );
  1165.  void   SERVERCOMMANDS_VoteEnded( bool bVotePassed, ULONG ulPlayerExtra = MAXPLAYERS, ULONG ulFlags = 0 );
  1166.  
  1167. diff -r af45c72387f5 src/sv_main.cpp
  1168. --- a/src/sv_main.cpp   Sat Jul 27 09:47:16 2013 +0200
  1169. +++ b/src/sv_main.cpp   Fri Aug 02 02:25:44 2013 +0300
  1170. @@ -113,6 +113,7 @@
  1171.  #include "domination.h"
  1172.  #include "a_movingcamera.h"
  1173.  #include "cl_main.h"
  1174. +#include "votedef.h"
  1175.  
  1176.  //*****************************************************************************
  1177.  // MISC CRAP THAT SHOULDN'T BE HERE BUT HAS TO BE BECAUSE OF SLOPPY CODING
  1178. @@ -5802,61 +5803,21 @@
  1179.     }
  1180.  
  1181.     // Check if the specific type of vote is allowed.
  1182. -   bool bVoteAllowed = false;
  1183. -   switch ( ulVoteCmd )
  1184. -   {
  1185. -   case VOTECMD_KICK:
  1186. -
  1187. -       bVoteAllowed = !sv_nokickvote;
  1188. -       sprintf( szCommand, "kick" );
  1189. -       break;
  1190. -   case VOTECMD_MAP:
  1191. -
  1192. -       bVoteAllowed = !sv_nomapvote;
  1193. -       sprintf( szCommand, "map" );
  1194. -       break;
  1195. -   case VOTECMD_CHANGEMAP:
  1196. -
  1197. -       bVoteAllowed = !sv_nochangemapvote;
  1198. -       sprintf( szCommand, "changemap" );
  1199. -       break;
  1200. -   case VOTECMD_FRAGLIMIT:
  1201. -
  1202. -       bVoteAllowed = !sv_nofraglimitvote;
  1203. -       sprintf( szCommand, "fraglimit" );
  1204. -       break;
  1205. -   case VOTECMD_TIMELIMIT:
  1206. -
  1207. -       bVoteAllowed = !sv_notimelimitvote;
  1208. -       sprintf( szCommand, "timelimit" );
  1209. -       break;
  1210. -   case VOTECMD_WINLIMIT:
  1211. -
  1212. -       bVoteAllowed = !sv_nowinlimitvote;
  1213. -       sprintf( szCommand, "winlimit" );
  1214. -       break;
  1215. -   case VOTECMD_DUELLIMIT:
  1216. -
  1217. -       bVoteAllowed = !sv_noduellimitvote;
  1218. -       sprintf( szCommand, "duellimit" );
  1219. -       break;
  1220. -   case VOTECMD_POINTLIMIT:
  1221. -
  1222. -       bVoteAllowed = !sv_nopointlimitvote;
  1223. -       sprintf( szCommand, "pointlimit" );
  1224. -       break;
  1225. -   default:
  1226. -
  1227. -       return ( false );
  1228. -   }
  1229. -
  1230. -   // Begin the vote, if that type is allowed.
  1231. -   if ( bVoteAllowed )
  1232. -       CALLVOTE_BeginVote( szCommand, Parameters, Reason, g_lCurrentClient );
  1233. -   else
  1234. -       SERVER_PrintfPlayer( PRINT_HIGH, g_lCurrentClient, "%s votes are disabled on this server.\n", szCommand );
  1235. -
  1236. -   return ( false );
  1237. +   // [Dusk] VOTEDEFized
  1238. +   VoteDef* pVoteType = VoteDef::findByIndex( ulVoteCmd );
  1239. +   if( !pVoteType )
  1240. +       return false; // Unknown vote type
  1241. +
  1242. +   if( pVoteType->forbidCVar()->GetGenericRep( CVAR_Bool ).Bool )
  1243. +   {
  1244. +       SERVER_PrintfPlayer( PRINT_HIGH, g_lCurrentClient, "%s votes are disabled on this server.\n",
  1245. +           pVoteType->name().GetChars( ));
  1246. +       return false;
  1247. +   }
  1248. +
  1249. +   // Begin the vote
  1250. +   CALLVOTE_BeginVote( ulVoteCmd, Parameters, Reason, g_lCurrentClient );
  1251. +   return false;
  1252.  }
  1253.  
  1254.  //*****************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement