votelist_t *MapWithMostVotes (float *p) { float p_most = 0.0f, votes = 0.f; votelist_t *search = NULL, *most = NULL; if (map_votes == NULL) return (NULL); //find map_num_clients map_num_clients = _numclients(); if (map_num_clients == 0) return (NULL); most = NULL; for (search = map_votes; search != NULL; search = search->next) { votes = (float)((float)search->num_votes / (float)map_num_clients); if (votes > p_most) { p_most = votes; most = search; } } if (p != NULL) *p = p_most; return (most); }
configlist_t *ConfigWithMostVotes (float *p) { float p_most; configlist_t *search, *most; p_most = 0.0; if (config_votes == NULL) return (NULL); //find config_num_clients config_num_clients = _numclients(); if (config_num_clients == 0) return (NULL); most = NULL; for (search = config_votes; search != NULL; search = search->next) { if ((float) ((float) search->num_votes / (float) config_num_clients) > p_most) { p_most = (float) ((float) search->num_votes / (float) config_num_clients); most = search; } } if (p != NULL) *p = p_most; return (most); }
void Cmd_Kicklist_f(edict_t *ent) { char buf[MAX_STRING_CHARS], tbuf[256]; if (!use_kickvote->value) { gi.cprintf(ent, PRINT_HIGH, "Kick voting is disabled.\n"); return; } strcpy(buf, "Available players to kick:\n\n"); _printplayerlist(ent, buf, _vkMarkThis); // adding vote settings Com_sprintf (tbuf, sizeof(tbuf), "Vote rules: %i client%s min. (currently %i),\n" \ "%.1f%% must have voted overall (currently %.1f%%)\n" \ "and %.1f%% on the same (currently %.1f%% on %s),\n" \ "kicked players %s be temporarily banned.\n\n", (int) (kickvote_min->value), (kickvote_min->value == 1) ? "" : "s", _numclients(), kickvote_need->value, Allkickvotes, kickvote_pass->value, Mostkickpercent, Mostkickvotes == NULL ? "nobody" : Mostkickvotes->client->pers.netname, kickvote_tempban ? "will" : "won't"); // double percent sign! cprintf will process them as format strings. Q_strncatz(buf, tbuf, sizeof(buf)); gi.cprintf(ent, PRINT_MEDIUM, "%s", buf); }
void Cmd_Kicklist_f (edict_t * ent, char *argument) { char buf[16384], tbuf[2048]; strcpy (buf, "\nAvailable players to kick:\n\n"); _printplayerlist (ent, buf, _vkMarkThis); // adding vote settings sprintf (tbuf, "Vote rules: %i client%s min. (currently %i),\n" \ "%.1f%%%% must have voted overall (currently %.1f%%%%)\n" \ "and %.1f%%%% on the same (currently %.1f%%%% on %s),\n" \ "kicked players %s be temporarily banned.\n\n", (int) (kickvote_min->value), (kickvote_min->value == 1) ? " " : "s ", _numclients (), kickvote_need->value, Allkickvotes, kickvote_pass->value, Mostkickpercent, Mostkickvotes == NULL ? "nobody" : Mostkickvotes->client->pers.netname, kickvote_tempban ? "will" : "won't"); // double percent sign! cprintf will process them as format strings. strcat (buf, tbuf); gi.cprintf (ent, PRINT_MEDIUM, buf); }
void _CheckKickVote (void) { int i, j, votes, maxvotes, playernum, playervoted; edict_t *other, *target, *mtarget; if (kickvotechanged == false) return; kickvotechanged = false; playernum = _numclients (); if (playernum < kickvote_need->value) return; maxvotes = 0; mtarget = NULL; playervoted = 0; for (i = 1; i <= game.maxclients; i++) { other = &g_edicts[i]; if (other->client && other->inuse && other->client->resp.kickvote) { votes = 0; target = other->client->resp.kickvote; playervoted++; for (j = 1; j <= game.maxclients; j++) { other = &g_edicts[j]; if (other->client && other->inuse && other->client->resp.kickvote == target) votes++; } if (votes > maxvotes) { maxvotes = votes; mtarget = target; } } } Mostkickvotes = NULL; if (!mtarget) return; Mostkickvotes = mtarget; Mostkickpercent = (float) (((float) maxvotes / (float) playernum) * 100.0); Allkickvotes = (float) (((float) playervoted / (float) playernum) * 100.0); if (Allkickvotes < kickvote_need->value) return; if (Mostkickpercent < kickvote_pass->value) return; // finally _DoKick (mtarget); }
void _CheckKickVote (void) { int i, j, votes, maxvotes, playernum, playervoted; edict_t *ent, *other, *target, *mtarget; if (kickvotechanged == false) return; kickvotechanged = false; playernum = _numclients (); maxvotes = 0; mtarget = NULL; playervoted = 0; for (i = 0, other = g_edicts + 1; i < game.maxclients; i++, other++) { if (!other->client || !other->inuse) continue; target = other->client->resp.kickvote; if (!target || target == mtarget) continue; votes = 0; playervoted++; for (j = 0, ent = g_edicts + 1; j < game.maxclients; j++, ent++) { if (ent->client && ent->inuse && ent->client->resp.kickvote == target) votes++; } if (votes > maxvotes) { maxvotes = votes; mtarget = target; } } Mostkickvotes = NULL; if (!mtarget) return; Mostkickvotes = mtarget; Mostkickpercent = (float) (((float) maxvotes / (float) playernum) * 100.0); Allkickvotes = (float) (((float) playervoted / (float) playernum) * 100.0); if (playernum < kickvote_min->value) return; if (Allkickvotes < kickvote_need->value) return; if (Mostkickpercent < kickvote_pass->value) return; // finally _DoKick (mtarget); }
void _CalcScrambleVotes (int *numclients, int *numvotes, float *percent) { int i; edict_t *ent; *numclients = _numclients (); *numvotes = 0; *percent = 0.00f; for (i = 1; i <= game.maxclients; i++) { ent = &g_edicts[i]; if (ent->client && ent->inuse && ent->client->resp.scramblevote) { (*numvotes)++; } } if(*numvotes > 0) (*percent) = (float) (((float) *numvotes / (float) *numclients) * 100.0); }