~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to server/voting.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2010-02-23 22:09:02 UTC
  • mfrom: (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100223220902-s3spqi1x4e190y0t
[ Karl Goetz ]
* Remove civserver files in /etc/ggzd/ (Closes: 523772, 517787)
* Adding ${misc:Depends} to all binary packages (lintian warnings)

[ Clint Adams ]
* New upstream version.
  - Drop data_dsc_use_bindir.diff (binary pathnames have changed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#include <math.h>
19
19
 
 
20
/* utility */
20
21
#include "fcintl.h"
21
22
#include "log.h"
22
23
#include "support.h"
23
24
 
 
25
/* common */
24
26
#include "capability.h"
25
27
#include "connection.h"
26
28
#include "packets.h"
27
29
#include "player.h"
28
30
 
 
31
/* server */
29
32
#include "commands.h"
30
33
#include "console.h"
31
 
#include "plrhand.h"
 
34
#include "hand_gen.h"
 
35
#include "notify.h"
32
36
#include "settings.h"
33
37
#include "stdinhand.h"
 
38
 
34
39
#include "voting.h"
35
40
 
36
 
 
37
41
struct vote_list *vote_list = NULL;
38
42
int vote_number_sequence = 0;
39
43
 
86
90
  }
87
91
 
88
92
  conn_list_iterate(dest, conn) {
89
 
    if (!has_capability("voteinfo", conn->capability)
90
 
        || !conn_can_vote(conn, pvote)) {
 
93
    if (!conn_can_see_vote(conn, pvote)) {
91
94
      continue;
92
95
    }
93
96
    send_packet_vote_new(conn, &packet);
126
129
  }
127
130
 
128
131
  conn_list_iterate(dest, aconn) {
129
 
    if (!has_capability("voteinfo", aconn->capability)
130
 
        || !conn_can_vote(aconn, pvote)) {
 
132
    if (!conn_can_see_vote(aconn, pvote)) {
131
133
      continue;
132
134
    }
133
135
    send_packet_vote_update(aconn, &packet);
152
154
  }
153
155
 
154
156
  conn_list_iterate(dest, pconn) {
155
 
    if (!has_capability("voteinfo", pconn->capability)) {
156
 
      continue;
157
 
    }
158
157
    send_packet_vote_remove(pconn, &packet);
159
158
  } conn_list_iterate_end;
160
159
}
179
178
  }
180
179
 
181
180
  conn_list_iterate(dest, pconn) {
182
 
    if (!has_capability("voteinfo", pconn->capability)
183
 
        || !conn_can_vote(pconn, pvote)) {
 
181
    if (!conn_can_see_vote(pconn, pvote)) {
184
182
      continue;
185
183
    }
186
184
    send_packet_vote_resolve(pconn, &packet);
230
228
    lsend_vote_remove(NULL, pvote);
231
229
    free_vote(pvote);
232
230
  } vote_list_iterate_end;
233
 
  vote_list_unlink_all(vote_list);
 
231
  vote_list_clear(vote_list);
234
232
}
235
233
 
236
234
/***************************************************************************
357
355
  pvote = fc_malloc(sizeof(struct vote));
358
356
  pvote->caller_id = caller->id;
359
357
  pvote->command_id = command_id;
360
 
  pcmd = &commands[command_id];
 
358
  pcmd = command_by_number(command_id);
361
359
 
362
 
  sz_strlcpy(pvote->cmdline, pcmd->name);
 
360
  sz_strlcpy(pvote->cmdline, command_name(pcmd));
363
361
  if (allargs != NULL && allargs[0] != '\0') {
364
362
    sz_strlcat(pvote->cmdline, " ");
365
363
    sz_strlcat(pvote->cmdline, allargs);
371
369
 
372
370
  vote_list_append(vote_list, pvote);
373
371
 
374
 
  pvote->flags = pcmd->vote_flags;
375
 
  pvote->need_pc = (double) pcmd->vote_percent / 100.0;
 
372
  pvote->flags = command_vote_flags(pcmd);
 
373
  pvote->need_pc = (double) command_vote_percent(pcmd) / 100.0;
376
374
 
377
375
  if (pvote->flags & VCF_NOPASSALONE) {
378
376
    int num_voters = count_voters(pvote);
518
516
  }
519
517
 
520
518
  if (passed) {
521
 
    notify_team(callplr, NULL, E_CHAT_MSG,
 
519
    notify_team(callplr, NULL, E_VOTE_RESOLVED, ftc_vote_passed,
522
520
                _("%s %d \"%s\" is passed %d to %d with "
523
521
                  "%d abstentions and %d who did not vote."),
524
522
                title, pvote->vote_no, pvote->cmdline, pvote->yes,
525
523
                pvote->no, pvote->abstain, num_voters - num_cast);
526
524
  } else {
527
 
    notify_team(callplr, NULL, E_CHAT_MSG,
 
525
    notify_team(callplr, NULL, E_VOTE_RESOLVED, ftc_vote_failed,
528
526
                _("%s %d \"%s\" failed with %d against, %d for, "
529
527
                  "%d abstentions and %d who did not vote."),
530
528
                title, pvote->vote_no, pvote->cmdline, pvote->no,
544
542
 
545
543
    switch (pvc->vote_cast) {
546
544
    case VOTE_YES:
547
 
      notify_team(callplr, NULL, E_CHAT_MSG,
 
545
      notify_team(callplr, NULL, E_VOTE_RESOLVED, ftc_vote_yes,
548
546
                  _("%s %d: %s voted yes."),
549
547
                  title, pvote->vote_no, pconn->username);
550
548
      break;
551
549
    case VOTE_NO:
552
 
      notify_team(callplr, NULL, E_CHAT_MSG,
 
550
      notify_team(callplr, NULL, E_VOTE_RESOLVED, ftc_vote_no,
553
551
                  _("%s %d: %s voted no."),
554
552
                  title, pvote->vote_no, pconn->username);
555
553
      break;
556
554
    case VOTE_ABSTAIN:
557
 
      notify_team(callplr, NULL, E_CHAT_MSG,
 
555
      notify_team(callplr, NULL, E_VOTE_RESOLVED, ftc_vote_abstain,
558
556
                  _("%s %d: %s chose to abstain."),
559
557
                  title, pvote->vote_no, pconn->username);
560
558
      break;
772
770
}
773
771
 
774
772
/**************************************************************************
775
 
  Sends a packet_vote_new to pconn (if voteinfo capable) for every
776
 
  currently running vote.
 
773
  Sends a packet_vote_new to pconn for every currently running vote.
777
774
**************************************************************************/
778
775
void send_running_votes(struct connection *pconn)
779
776
{
780
 
  if (!pconn || !has_capability("voteinfo", pconn->capability)) {
781
 
    return;
782
 
  }
783
 
 
784
 
  if (!vote_list || vote_list_size(vote_list) < 1) {
 
777
  if (!pconn || !vote_list || vote_list_size(vote_list) < 1) {
785
778
    return;
786
779
  }
787
780
 
790
783
 
791
784
  connection_do_buffer(pconn);
792
785
  vote_list_iterate(vote_list, pvote) {
793
 
    if (conn_can_vote(pconn, pvote)) {
 
786
    if (conn_can_see_vote(pconn, pvote)) {
794
787
      lsend_vote_new(pconn->self, pvote);
 
788
      lsend_vote_update(pconn->self, pvote, count_voters(pvote));
795
789
    }
796
790
  } vote_list_iterate_end;
797
791
  connection_do_unbuffer(pconn);
798
792
}
799
793
 
800
794
/**************************************************************************
801
 
  Sends a packet_vote_update to every voteinfo-capabale conn in dest. If
802
 
  dest is NULL, then sends to all established connections.
 
795
  Sends a packet_vote_update to every conn in dest. If dest is NULL, then
 
796
  sends to all established connections.
803
797
**************************************************************************/
804
798
void send_updated_vote_totals(struct conn_list *dest)
805
799
{