Advertisement
slatenails

votedef.h

Aug 1st, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.19 KB | None | 0 0
  1. /*
  2.  * Zandronum source code
  3.  * Copyright (C) 2012 Santeri Piippo
  4.  *
  5.  * 1. Redistributions of source code must retain the above copyright notice,
  6.  *    this list of conditions and the following disclaimer.
  7.  * 2. Redistributions in binary form must reproduce the above copyright notice,
  8.  *    this list of conditions and the following disclaimer in the documentation
  9.  *    and/or other materials provided with the distribution.
  10.  * 3. Neither the name of the Skulltag Development Team nor the names of its
  11.  *    contributors may be used to endorse or promote products derived from this
  12.  *    software without specific prior written permission.
  13.  * 4. Redistributions in any form must be accompanied by information on how to
  14.  *    obtain complete source code for the software and any accompanying
  15.  *    software that uses the software. The source code must either be included
  16.  *    in the distribution or be available for no more than the cost of
  17.  *    distribution plus a nominal fee, and must be freely redistributable
  18.  *    under reasonable conditions. For an executable file, complete source
  19.  *    code means the source code for all modules it contains. It does not
  20.  *    include source code for modules or files that typically accompany the
  21.  *    major components of the operating system on which the executable file
  22.  *    runs.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  28.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34.  * POSSIBILITY OF SUCH DAMAGE.
  35.  *
  36.  * Filename: votedef.h
  37.  *
  38.  * Description: VOTEDEF declarations
  39.  *
  40.  * -----------------------------------------------------------------------------
  41.  */
  42.  
  43. #ifndef VOTEDEF_H
  44. #define VOTEDEF_H
  45.  
  46. #include "zstring.h"
  47. #include "basictypes.h"
  48. #include "networkshared.h"
  49. #include "doomdef.h"
  50.  
  51. class FBaseCVar;
  52.  
  53. class VoteDef
  54. {
  55. public:
  56.     // ============================================================================
  57.     // Vote parameter types
  58.     enum ArgumentType
  59.     {
  60.         Int,                // integer number
  61.         Float,              // floating point number
  62.         Player,             // any valid player
  63.         MapType,            // map type for changemap and map
  64.         NumArgTypes,        // end of parm list, must be last in this list!
  65.     };
  66.  
  67.     // ============================================================================
  68.     // Flags for votes
  69.     enum
  70.     {
  71.         NoPassedLimit           = ( 1 <<  0 ), // this vote can be called without delay as long as it passes
  72.         NotSelf                 = ( 1 <<  1 ), // player argument must not be the caller
  73.         NotAdmin                = ( 1 <<  2 ), // player argument must not be an admin
  74.         PlayerIndex             = ( 1 <<  3 ), // player argument given as an index instead of a name
  75.         PlayerInGame            = ( 1 <<  4 ), // player given must be in game
  76.         NumFlags                =         5    // end of vote list
  77.     };
  78.  
  79.     // ============================================================================
  80.     // Native type - also tokens for k_NativeNames
  81.     enum NativeType
  82.     {
  83.         Kick,
  84.         KickFromGame,
  85.         ChangeMap,
  86.         Map,
  87.         FragLimit,
  88.         TimeLimit,
  89.         PointLimit,
  90.         DuelLimit,
  91.         WinLimit,
  92.         NumNatives,
  93.     };
  94.  
  95.     // ============================================================================
  96.     // Enum type for k_PropertyTokens
  97.     enum
  98.     {
  99.         VTPROP_ARGUMENT,
  100.         VTPROP_ACSSCRIPT,
  101.         VTPROP_DESCRIPTION,
  102.         VTPROP_FLAGS,
  103.         VTPROP_FORBIDCVAR,
  104.         VTPROP_VALUERANGE,
  105.     };
  106.  
  107.     // ============================================================================
  108.     // Structure for input for ApplyCommand
  109.     struct ApplyInput
  110.     {
  111.         unsigned type;          // Type of vote
  112.         FString arg;            // Vote argument
  113.         FString reason;         // Reason string
  114.         unsigned yes, no;       // Count of yes/no votes
  115.         unsigned caller;        // Index of vote caller
  116.     };
  117.  
  118.     // ============================================================================
  119.     // Structure for result from ApplyCommand
  120.     struct ApplyResult
  121.     {
  122.         FString command;        // Resulting command string (natives)
  123.         FString error;          // Failed? Why?
  124.         long arg;               // Script argument
  125.     };
  126.  
  127.     // ============================================================================
  128.     VoteDef( const FString& name, NativeType native );
  129.     ~VoteDef( );
  130.  
  131.     const ArgumentType&     argType( ) const;
  132.     void                    copyTo( VoteDef* other ) const;
  133.     const FString&          description( ) const;
  134.     const DWORD&            flags( ) const;
  135.     FBaseCVar*              forbidCVar( ) const;
  136.     int                     getIndex( ) const;
  137.     FString                 getUsage( ) const;
  138.     const float&            max( ) const;
  139.     const float&            min( ) const;
  140.     const FString&          name( ) const;
  141.     const NativeType&       nativeType( ) const;
  142.     const ULONG&            scriptNum( ) const;
  143.  
  144.     // ============================================================================
  145.     static bool             applyCommand( ApplyInput input, ApplyResult& result );
  146.     static void             deinit( );
  147.     static VoteDef*         findByIndex( unsigned index );
  148.     static VoteDef*         findByName( FString name );
  149.     static void             init( );
  150.     static FString          makeSummary( const ApplyInput& input );
  151.     static unsigned         numTypes( );
  152.     static void             parseLump( int lump );
  153.     static void             storeIPAddresses( );
  154.  
  155. protected:
  156.     // ============================================================================
  157.     FString        m_name;              // Name of the type
  158.     ULONG          m_script;            // Script number to execute
  159.     DWORD          m_flags;             // Flags of this vote
  160.     ArgumentType   m_argType;           // Argument type
  161.     FString        m_description;       // Description string
  162.     FBaseCVar*     m_forbidCVar;        // CVar that forbids the use of this vote
  163.     bool           m_autogenForbidCVar; // Was the name of the CVar auto-generated?
  164.     float          m_min, m_max;        // Minimum and maximum input values
  165.     NativeType     m_native;            // Native vote type, these have special behavior.
  166.  
  167.     // ============================================================================
  168.     static TArray<VoteDef*> k_Defs;                  // The one array of vote type definitions.
  169.     static NETADDRESS_s     k_IPStorage[MAXPLAYERS]; // IP addresses of clients for kick votes.
  170.     static const char*      k_ParameterTokens[];     // Tokens for the parser
  171.     static const char*      k_PropertyTokens[];
  172.     static const char*      k_FlagTokens[];
  173.     static const char*      k_NativeNames[];
  174.  
  175.     // Is the given player an admin as far as +ISADMIN is concerned?
  176.     static bool playerIsAdmin( ULONG idx );
  177. };
  178.  
  179. #endif // VOTEDEF_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement