[Half-Life AMXX] / adminvote.sma Repository:
ViewVC logotype

Diff of /adminvote.sma

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1, Tue Oct 30 09:08:11 2007 UTC revision 44, Mon Oct 11 23:53:51 2010 UTC
# Line 35  Line 35 
35  #include <amxmodx>  #include <amxmodx>
36  #include <amxmisc>  #include <amxmisc>
37    
38    
39  new g_Answer[128]  new g_Answer[128]
40  new g_optionName[4][32]  new g_optionName[4][64]
41  new g_voteCount[4]  new g_voteCount[4]
42  new g_validMaps  new g_validMaps
43  new g_yesNoVote  new g_yesNoVote
# Line 58  Line 59 
59          register_menucmd(register_menuid("Choose map: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")          register_menucmd(register_menuid("Choose map: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
60          register_menucmd(register_menuid("Kick "), MENU_KEY_1|MENU_KEY_2, "voteCount")          register_menucmd(register_menuid("Kick "), MENU_KEY_1|MENU_KEY_2, "voteCount")
61          register_menucmd(register_menuid("Ban "), MENU_KEY_1|MENU_KEY_2, "voteCount")          register_menucmd(register_menuid("Ban "), MENU_KEY_1|MENU_KEY_2, "voteCount")
62          register_menucmd(register_menuid("Vote: "), MENU_KEY_1|MENU_KEY_2, "voteCount")          register_menucmd(register_menuid("Vote: "), MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4, "voteCount")
63          register_menucmd(register_menuid("The result: "), MENU_KEY_1|MENU_KEY_2, "actionResult")          register_menucmd(register_menuid("The result: "), MENU_KEY_1|MENU_KEY_2, "actionResult")
64          register_concmd("amx_votemap", "cmdVoteMap", ADMIN_VOTE, "<map> [map] [map] [map]")          register_concmd("amx_votemap", "cmdVoteMap", ADMIN_VOTE, "<map> [map] [map] [map]")
65          register_concmd("amx_votekick", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")          register_concmd("amx_votekick", "cmdVoteKickBan", ADMIN_VOTE, "<name or #userid>")
# Line 82  Line 83 
83                  get_user_name(id, name, 31)                  get_user_name(id, name, 31)
84                  log_amx("Vote: ^"%s<%d><%s><>^" cancel vote session", name, get_user_userid(id), authid)                  log_amx("Vote: ^"%s<%d><%s><>^" cancel vote session", name, get_user_userid(id), authid)
85    
                 new players[32], pnum, lTag[16], activity = get_cvar_num("amx_show_activity")  
                 get_players(players, pnum, "c")  
86    
87                  for (new i = 0; i < pnum;i ++)                  new maxpl=get_maxplayers();
88                  {                  new msg[256];
89                          format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")                  for (new i = 1; i <= maxpl; i++)
90                          switch (activity)                  {
91                          {                          if (is_user_connected(i) && !is_user_bot(i))
92                                  case 2: client_print(players[i], print_chat, "%L", LANG_PLAYER, "ADMIN_CANC_VOTE_2", lTag, name)                          {
93                                  case 1: client_print(players[i], print_chat, "%L", LANG_PLAYER, "ADMIN_CANC_VOTE_1", lTag)                                  // HACK: ADMIN_CANC_VOTE_{1,2} keys were designed very poorly.  Remove all : and %s in it.
94                                    LookupLangKey(msg, charsmax(msg), "ADMIN_CANC_VOTE_1", i);
95                                    replace_all(msg, charsmax(msg), "%s", "");
96                                    replace_all(msg, charsmax(msg), ":", "");
97                                    trim(msg);
98                                    show_activity_id(i, id, name, msg);
99                          }                          }
100                  }                  }
101    
# Line 310  Line 314 
314          else          else
315                  log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")", name, get_user_userid(id), authid, g_optionName[0], g_optionName[1], g_optionName[2], g_optionName[3])                  log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")", name, get_user_userid(id), authid, g_optionName[0], g_optionName[1], g_optionName[2], g_optionName[3])
316    
317          new lTag[16], activity = get_cvar_num("amx_show_activity")          new maxpl=get_maxplayers();
318            new msg[256];
319          if (activity > 0)          for (new i = 1; i <= maxpl; i++)
320          {          {
321                  new players[32], pnum                  if (is_user_connected(i) && !is_user_bot(i))
322                    {
323                  get_players(players, pnum, "c")                          // HACK: ADMIN_VOTE_MAP_{1,2} keys were designed very poorly.  Remove all : and %s in it.
324                  for (new i = 0; i < pnum; i++)                          LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_MAP_1", i);
325                  {                          replace_all(msg, charsmax(msg), "%s", "");
326                          format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")                          replace_all(msg, charsmax(msg), ":", "");
327                            trim(msg);
328                          switch (activity)                          show_activity_id(i, id, name, msg);
                         {  
                                 case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_MAP_2", lTag, name)  
                                 case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_MAP_1", lTag)  
                         }  
329                  }                  }
330          }          }
331    
# Line 372  Line 372 
372                  return PLUGIN_HANDLED                  return PLUGIN_HANDLED
373          }          }
374    
375          read_argv(2, g_optionName[0], 31)          new count=read_argc();
376          read_argv(3, g_optionName[1], 31)  
377            for (new i=0;i<4 && (i+2)<count;i++)
378            {
379                    read_argv(i+2, g_optionName[i], sizeof(g_optionName[])-1);
380            }
381    
382          new authid[32], name[32]          new authid[32], name[32]
383    
# Line 381  Line 385 
385          get_user_name(id, name, 31)          get_user_name(id, name, 31)
386          log_amx("Vote: ^"%s<%d><%s><>^" vote custom (question ^"%s^") (option#1 ^"%s^") (option#2 ^"%s^")", name, get_user_userid(id), authid, quest, g_optionName[0], g_optionName[1])          log_amx("Vote: ^"%s<%d><%s><>^" vote custom (question ^"%s^") (option#1 ^"%s^") (option#2 ^"%s^")", name, get_user_userid(id), authid, quest, g_optionName[0], g_optionName[1])
387    
388          new activity = get_cvar_num("amx_show_activity")          new maxpl=get_maxplayers();
389            new msg[256];
390          if (activity > 0)          for (new i = 1; i <= maxpl; i++)
         {  
                 new players[32], pnum, lTag[16]  
   
                 get_players(players, pnum, "c")  
                 for (new i = 0; i < pnum; i++)  
391                  {                  {
392                          format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "PLAYER")                  if (is_user_connected(i) && !is_user_bot(i))
   
                         switch (activity)  
393                          {                          {
394                                  case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_CUS_2", lTag, name)                          // HACK: ADMIN_VOTE_CUS_{1,2} keys were designed very poorly.  Remove all : and %s in it.
395                                  case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_CUS_1", lTag)                          LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_CUS_1", i);
396                          }                          replace_all(msg, charsmax(msg), "%s", "");
397                            replace_all(msg, charsmax(msg), ":", "");
398                            trim(msg);
399                            show_activity_id(i, id, name, msg);
400                  }                  }
401          }          }
402    
403          new menu_msg[256], lVote[16]          new menu_msg[512], lVote[16]
404    
405          format(lVote, 15, "%L", LANG_SERVER, "VOTE")          format(lVote, 15, "%L", LANG_SERVER, "VOTE")
         new keys = MENU_KEY_1|MENU_KEY_2  
406    
407          format(menu_msg, 255, g_coloredMenus ? "\y%s: %s\w^n^n1.  %s^n2.  %s" : "%s: %s^n^n1.  %s^n2.  %s", lVote, quest, g_optionName[0], g_optionName[1])          count-=2;
408            if (count>4)
409            {
410                    count=4;
411            }
412            // count now shows how many options were listed
413            new keys=0;
414            for (new i=0;i<count;i++)
415            {
416                    keys |= (1<<i);
417            }
418    
419            new len=formatex(menu_msg, sizeof(menu_msg)-1, g_coloredMenus ? "\y%s: %s\w^n^n" : "%s: %s^n^n", lVote, quest);
420    
421            for (new i=0;i<count;i++)
422            {
423                    len+=formatex(menu_msg[len], sizeof(menu_msg) - 1 - len ,"%d.  %s^n",i+1,g_optionName[i]);
424            }
425          g_execResult = false          g_execResult = false
426    
427          new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0          new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
428    
429          set_cvar_float("amx_last_voting", get_gametime() + vote_time)          set_cvar_float("amx_last_voting", get_gametime() + vote_time)
430          g_voteRatio = get_cvar_float("amx_vote_ratio")          g_voteRatio = get_cvar_float("amx_vote_ratio")
431            replace_all(quest,sizeof(quest)-1,"%","");
432          format(g_Answer, 127, "%s - %%s", quest)          format(g_Answer, 127, "%s - %%s", quest)
433          show_menu(0, keys, menu_msg, floatround(vote_time), "Vote: ")          show_menu(0, keys, menu_msg, floatround(vote_time), "Vote: ")
434          set_task(vote_time, "checkVotes", 99889988)          set_task(vote_time, "checkVotes", 99889988)
# Line 449  Line 466 
466          new arg[32]          new arg[32]
467          read_argv(1, arg, 31)          read_argv(1, arg, 31)
468    
469          new player = cmd_target(id, arg, 1)          new player = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF)
470    
471          if (!player)          if (!player)
472                  return PLUGIN_HANDLED                  return PLUGIN_HANDLED
# Line 474  Line 491 
491          format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1.  %s^n2.  %s" : "%s %s?^n^n1.  %s^n2.  %s", lKickBan, arg, lYes, lNo)          format(menu_msg, 255, g_coloredMenus ? "\y%s %s?\w^n^n1.  %s^n2.  %s" : "%s %s?^n^n1.  %s^n2.  %s", lKickBan, arg, lYes, lNo)
492          g_yesNoVote = 1          g_yesNoVote = 1
493    
494            new bool:ipban=false;
495    
496          if (voteban)          if (voteban)
497                  get_user_authid(player, g_optionName[0], 31)          {
498                    get_user_authid(player, g_optionName[0], sizeof(g_optionName[])-1);
499    
500                    // Do the same check that's in plmenu to determine if this should be an IP ban instead
501                    if (equal("4294967295", g_optionName[0])
502                            || equal("HLTV", g_optionName[0])
503                            || equal("STEAM_ID_LAN", g_optionName[0])
504                            || equali("VALVE_ID_LAN", g_optionName[0]))
505                    {
506                            get_user_ip(player, g_optionName[0], sizeof(g_optionName[])-1, 1);
507    
508                            ipban=true;
509                    }
510    
511            }
512          else          else
513            {
514                  num_to_str(get_user_userid(player), g_optionName[0], 31)                  num_to_str(get_user_userid(player), g_optionName[0], 31)
515            }
516    
517          new authid[32], name[32]          new authid[32], name[32]
518    
# Line 485  Line 520 
520          get_user_name(id, name, 31)          get_user_name(id, name, 31)
521          log_amx("Vote: ^"%s<%d><%s><>^" vote %s (target ^"%s^")", name, get_user_userid(id), authid, voteban ? "ban" : "kick", arg)          log_amx("Vote: ^"%s<%d><%s><>^" vote %s (target ^"%s^")", name, get_user_userid(id), authid, voteban ? "ban" : "kick", arg)
522    
523          new activity = get_cvar_num("amx_show_activity")          new maxpl=get_maxplayers();
524          if (activity > 0)          new msg[256];
525          {          new right[256];
526                  new players[32], pnum, lTag[16]          new dummy[1];
527            for (new i = 1; i <= maxpl; i++)
528                  get_players(players, pnum, "c")          {
529                  for (new i = 0; i < pnum; i++)                  if (is_user_connected(i) && !is_user_bot(i))
530                  {                  {
531                          format(lTag, 15, "%L", players[i], is_user_admin(id) ? "ADMIN" : "USER")                          formatex(lKickBan, charsmax(lKickBan), "%L", i, voteban ? "BAN" : "KICK");
532                          format(lKickBan, 15, "%L", players[i], voteban ? "BAN" : "KICK")  
533                            // HACK: ADMIN_VOTE_FOR{1,2} keys are really weird.  Tokenize and ignore the text before the :
534                          switch (activity)                          LookupLangKey(msg, charsmax(msg), "ADMIN_VOTE_FOR_1", i);
535                          {                          strtok(msg, dummy, 0, right, charsmax(right), ':');
536                                  case 2: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_FOR_2", lTag, name, lKickBan, arg)                          trim(right);
537                                  case 1: client_print(players[i], print_chat, "%L", players[i], "ADMIN_VOTE_FOR_1", lTag, lKickBan, arg)                          show_activity_id(i, id, name, right, lKickBan, arg);
                         }  
538                  }                  }
539          }          }
540    
# Line 510  Line 544 
544    
545          set_cvar_float("amx_last_voting", get_gametime() + vote_time)          set_cvar_float("amx_last_voting", get_gametime() + vote_time)
546          g_voteRatio = get_cvar_float(voteban ? "amx_voteban_ratio" : "amx_votekick_ratio")          g_voteRatio = get_cvar_float(voteban ? "amx_voteban_ratio" : "amx_votekick_ratio")
547          g_Answer = voteban ? "banid 30.0 %s kick" : "kick #%s"  
548            if (voteban)
549            {
550                    if (ipban==true)
551                    {
552                            g_Answer = "addip 30.0 %s";
553                    }
554                    else
555                    {
556                            g_Answer = "banid 30.0 %s kick";
557    
558                    }
559            }
560            else
561            {
562                    g_Answer = "kick #%s";
563            }
564          show_menu(0, keys, menu_msg, floatround(vote_time), voteban ? "Ban " : "Kick ")          show_menu(0, keys, menu_msg, floatround(vote_time), voteban ? "Ban " : "Kick ")
565          set_task(vote_time, "checkVotes", 99889988)          set_task(vote_time, "checkVotes", 99889988)
566          g_voteCaller = id          g_voteCaller = id

Legend:
Removed from v.1  
changed lines
  Added in v.44

Contact
ViewVC Help
Powered by ViewVC 1.0.4