Advertisement
Guest User

atcmd_restrictions_v100

a guest
Sep 4th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.54 KB | None | 0 0
  1. Index: src/map/atcommand.c
  2. ===================================================================
  3. --- src/map/atcommand.c (revision 14829)
  4. +++ src/map/atcommand.c (working copy)
  5. @@ -8916,6 +8916,13 @@
  6.     return ( i < ARRAYLENGTH(atcommand_info) ) ? &atcommand_info[i] : NULL;
  7.  }
  8.  
  9. +int get_atcommandindex_byname(const char* name)
  10. +{
  11. +   int i;
  12. +   if( *name == atcommand_symbol || *name == charcommand_symbol ) name++; // for backwards compatibility
  13. +   ARR_FIND( 0, ARRAYLENGTH(atcommand_info), i, strcmpi(atcommand_info[i].command, name) == 0 );
  14. +   return ( i < ARRAYLENGTH(atcommand_info) ) ? i : -1;
  15. +}
  16.  
  17.  /*==========================================
  18.   * Retrieve the command's required gm level
  19. @@ -8942,6 +8949,7 @@
  20.    
  21.     TBL_PC * ssd = NULL; //sd for target
  22.     AtCommandInfo * info;
  23. +   int index;
  24.  
  25.     nullpo_retr(false, sd);
  26.    
  27. @@ -9032,7 +9040,9 @@
  28.         params[0] = '\0';
  29.    
  30.     //Grab the command information and check for the proper GM level required to use it or if the command exists
  31. -   info = get_atcommandinfo_byname(command);
  32. +   index = get_atcommandindex_byname(command);
  33. +   info = ( index > 0) ? &atcommand_info[index] : NULL;
  34. +  
  35.     if( info == NULL || info->func == NULL || ( type && ((*atcmd_msg == atcommand_symbol && pc_isGM(sd) < info->level) || (*atcmd_msg == charcommand_symbol && pc_isGM(sd) < info->level2)) ) )
  36.     {
  37.             sprintf(output, msg_txt(153), command); // "%s is Unknown Command."
  38. @@ -9040,6 +9050,12 @@
  39.             return true;
  40.     }
  41.    
  42. +   //Atcmd Restrictions
  43. +   if(type && atcmd_restrictions[MAX_MAP_PER_SERVER * sd->bl.m + index] > pc_isGM(sd)) {
  44. +       clif_displaymessage(fd, "This command has been disabled on this map." );
  45. +       return false;
  46. +   }
  47. +
  48.     //Attempt to use the command
  49.     if( strcmpi("adjgmlvl",command+1) && ssd ) { lv = ssd->gmlevel; ssd->gmlevel = sd->gmlevel; }
  50.     if ( (info->func(fd, (*atcmd_msg == atcommand_symbol) ? sd : ssd, command, params) != 0) )
  51. @@ -9187,3 +9203,13 @@
  52.  
  53.     return 0;
  54.  }
  55. +
  56. +void init_atcmd_restrictions()
  57. +{
  58. +   atcmd_restrictions = (int *)aCalloc(MAX_MAP_PER_SERVER * ARRAYLENGTH(atcommand_info), sizeof(int));
  59. +}
  60. +
  61. +void clear_atcmd_restrictions()
  62. +{
  63. +   aFree(atcmd_restrictions);
  64. +}
  65. Index: src/map/atcommand.h
  66. ===================================================================
  67. --- src/map/atcommand.h (revision 14829)
  68. +++ src/map/atcommand.h (working copy)
  69. @@ -45,4 +45,9 @@
  70.  int msg_config_read(const char* cfgName);
  71.  void do_final_msg(void);
  72.  
  73. +int* atcmd_restrictions;
  74. +void init_atcmd_restrictions();
  75. +void clear_atcmd_restrictions();
  76. +int get_atcommandindex_byname(const char* name);
  77. +
  78.  #endif /* _ATCOMMAND_H_ */
  79. Index: src/map/map.c
  80. ===================================================================
  81. --- src/map/map.c   (revision 14829)
  82. +++ src/map/map.c   (working copy)
  83. @@ -3462,7 +3462,8 @@
  84.     do_final_unit();
  85.     do_final_battleground();
  86.     do_final_duel();
  87. -  
  88. +   clear_atcmd_restrictions();
  89. +
  90.     map_db->destroy(map_db, map_db_final);
  91.    
  92.     for (i=0; i<map_num; i++) {
  93. @@ -3671,6 +3672,9 @@
  94.  
  95.     map_readallmaps();
  96.  
  97. +   //atcmd restrictions
  98. +   init_atcmd_restrictions();
  99. +
  100.     add_timer_func_list(map_freeblock_timer, "map_freeblock_timer");
  101.     add_timer_func_list(map_clearflooritem_timer, "map_clearflooritem_timer");
  102.     add_timer_func_list(map_removemobs_timer, "map_removemobs_timer");
  103. Index: src/map/script.c
  104. ===================================================================
  105. --- src/map/script.c    (revision 14829)
  106. +++ src/map/script.c    (working copy)
  107. @@ -3806,6 +3806,10 @@
  108.  {
  109.     userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  110.     scriptlabel_db->clear(scriptlabel_db, NULL);
  111. +  
  112. +   //atcmd restrictions
  113. +   clear_atcmd_restrictions();
  114. +   init_atcmd_restrictions();
  115.  
  116.     if(sleep_db) {
  117.         struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  118. @@ -14867,7 +14871,27 @@
  119.     return 0;
  120.  }
  121.  
  122. +//restrictatcmd(<map>, <atcmd>, <mingmlvl>)
  123. +BUILDIN_FUNC(restrictatcmd)
  124. +{
  125. +   int m,a,gm;
  126.  
  127. +   m = map_mapname2mapid(script_getstr(st,2));
  128. +   a = get_atcommandindex_byname(script_getstr(st,3));
  129. +   gm=script_getnum(st,4);
  130. +  
  131. +   if(m < 0) {
  132. +       ShowError("buildin_restrictatcmd: Invalid map\n");
  133. +       return 1;
  134. +   } else if( a < 0) {
  135. +       ShowError("buildin_restrictatcmd: Invalid atcmd\n");
  136. +       return 1;
  137. +   }
  138. +
  139. +   atcmd_restrictions[MAX_MAP_PER_SERVER * m + a] = gm;
  140. +   return 0;
  141. +}
  142. +
  143.  // declarations that were supposed to be exported from npc_chat.c
  144.  #ifdef PCRE_SUPPORT
  145.  BUILDIN_FUNC(defpattern);
  146. @@ -15270,5 +15294,7 @@
  147.     BUILDIN_DEF(checkquest, "i?"),
  148.     BUILDIN_DEF(changequest, "ii"),
  149.     BUILDIN_DEF(showevent, "ii"),
  150. +
  151. +   BUILDIN_DEF(restrictatcmd, "ssi"),
  152.     {NULL,NULL,NULL},
  153.  };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement