Update of /cvsroot/netrek/server/Vanilla/ntserv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20227/ntserv
Modified Files:
data.c ntscmds.c main.c openmem.c
Log Message:
vote to ban
Index: ntscmds.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/ntscmds.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ntscmds.c 23 Apr 2006 10:39:10 -0000 1.7
+++ ntscmds.c 24 Apr 2006 12:35:17 -0000 1.8
@@ -30,6 +30,10 @@
void do_player_eject(int who, int player, int mflags, int sendto);
#endif
+#if defined (ALLOW_BAN)
+void do_player_ban(int who, int player, int mflags, int sendto);
+#endif
+
#if defined (AUTO_INL)
void do_start_inl(void);
#endif
@@ -71,6 +75,9 @@
#if defined (ALLOW_EJECT)
void eject_player(int who);
#endif
+#if defined (ALLOW_BAN)
+void ban_player(int who);
+#endif
void do_client_query(char *comm, struct message *mess, int who);
void do_ping_query(char *comm, struct message *mess, int who);
void do_stats_query(char *comm, struct message *mess, int who);
@@ -189,6 +196,13 @@
do_player_eject, /* EJECT */
2, PV_EJECT, 120, 600},
#endif
+#if defined(ALLOW_BAN)
+ { "BAN",
+ C_VC_TEAM | C_GLOG | C_PLAYER | C_PR_INPICKUP,
+ "Eject and ban a player e.g. 'BAN 0'",
+ do_player_ban, /* BAN */
+ 2, PV_BAN, 120, 600},
+#endif
#if defined(TRIPLE_PLANET_MAYHEM)
{ "TRIPLE",
C_VC_ALL | C_GLOG | C_PR_INPICKUP,
@@ -272,9 +286,24 @@
}
pmessage(0, MALL, addr_mess(who,MALL),
- " %2s has been ejected by their team", j->p_mapchars);
+ "%2s has been ejected by their team", j->p_mapchars);
eject_player(j->p_no);
+}
+
+void eject_player(int who)
+{
+ struct player *j;
+
+ j = &players[who];
+ j->p_ship.s_type = STARBASE;
+ j->p_whydead=KQUIT;
+ j->p_explode=10;
+ /* note VICIOUS_EJECT prevents animation of ship explosion */
+ j->p_status=PEXPLODE;
+ j->p_whodead=me->p_no;
+ bay_release(j);
+
#if defined(VICIOUS_EJECT)
/* Eject AND free the slot. I am sick
of the idiots who login and just
@@ -288,22 +317,57 @@
freeslot(j);
}
#endif
+
}
+#endif /* ALLOW_EJECT */
-void eject_player(int who)
+#if defined (ALLOW_BAN)
+void do_player_ban(int who, int player, int mflags, int sendto)
{
- struct player* j;
+ struct player *j;
+ char *reason = NULL;
- j = &players[who];
- j->p_ship.s_type = STARBASE;
- j->p_whydead=KQUIT;
- j->p_explode=10;
- /* note VICIOUS_EJECT prevents animation of ship explosion */
- j->p_status=PEXPLODE;
- j->p_whodead=me->p_no;
- bay_release(j);
+ j = &players[player];
+
+ if (j->p_status == PFREE) {
+ reason = "You may not ban a free slot.";
+ } else if (j->p_flags & PFROBOT) {
+ reason = "You may not ban a robot.";
+ } else if (j->p_team != players[who].p_team) {
+ reason = "You may not ban players of the other team.";
+ }
+
+ if (reason != NULL) {
+ pmessage(players[who].p_team, MTEAM,
+ addr_mess(players[who].p_team,MTEAM),
+ reason);
+ return;
+ }
+
+ pmessage(0, MALL, addr_mess(who,MALL),
+ "%2s has been temporarily banned by their team", j->p_mapchars);
+
+ eject_player(j->p_no);
+ ban_player(j->p_no);
}
-#endif /* ALLOW_EJECT */
+
+void ban_player(int who)
+{
+ int i;
+ struct player *j = &players[who];
+ for (i=0; i<MAXBANS; i++) {
+ struct ban *b = &bans[i];
+ if (b->b_expire == 0) {
+ strcpy(b->b_ip, j->p_ip);
+ b->b_expire = 100;
+ ERROR(2,( "ban of %s was voted\n", b->b_ip));
+ return;
+ }
+ }
+ pmessage(0, MALL, addr_mess(who,MALL),
+ " temporary ban list is full, ban ineffective");
+}
+#endif /* ALLOW_BAN */
#if defined(AUTO_PRACTICE)
void do_start_basep(void)
Index: data.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/data.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- data.c 22 Apr 2006 11:31:53 -0000 1.4
+++ data.c 24 Apr 2006 12:35:17 -0000 1.5
@@ -23,6 +23,7 @@
struct ship *shipvals;
struct pqueue *queues;
struct queuewait *waiting;
+struct ban *bans;
int oldalert = PFGREEN; /* Avoid changing more than we have to */
Index: main.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- main.c 22 Apr 2006 11:31:53 -0000 1.6
+++ main.c 24 Apr 2006 12:35:17 -0000 1.7
@@ -42,7 +42,8 @@
static void sendMotd(void);
static void sendConfigMsg(void);
static void printStats(void);
-static int checkbanned(char *login, char *host);
+static int check_temporary_bans(char *ip);
+static int check_permanent_bans(char *login, char *host);
extern int ignored[MAXPLAYER];
int indie = 0; /* always be indie 8/28/91 TC */
@@ -406,25 +407,34 @@
me->p_status = PALIVE; /* Put player in game */
me->p_ghostbuster = 0;
- if (!bypassed)
- if (checkbanned(login, host) == TRUE) {
- FILE *logfile;
- time_t curtime;
-
- pmessage(0, MALL, "GOD->ALL","%s (%s@%s) is banned from the game.",
- me->p_name, me->p_login, host);
- new_warning(UNDEF,"You are banned from the game.");
- me->p_explode=100;
- me->p_status=PEXPLODE;
- me->p_whydead=KQUIT; /* make him self destruct */
- me->p_whodead=0;
- logfile=fopen(LogFileName, "a");
- if (logfile) {
- curtime=time(NULL);
- fprintf(logfile, "Banned and exiting: %s (%s@%s), (%c), %s",
- me->p_name, me->p_login, host, shipnos[me->p_no], ctime(&curtime)
-);
- fclose(logfile);
+ if (!bypassed) {
+ char *reason = NULL;
+ if (check_permanent_bans(login, host) == TRUE) {
+ reason = "banned by the administrator";
+ } else if (check_permanent_bans(login, me->p_ip) == TRUE) {
+ reason = "banned by the administrator";
+ } else if (check_temporary_bans(me->p_ip) == TRUE) {
+ reason = "banned by the players";
+ }
+ if (reason != NULL) {
+ FILE *logfile;
+ time_t curtime;
+
+ pmessage(0, MALL, "GOD->ALL","%s (%s@%s) is %s.",
+ me->p_name, me->p_login, me->p_ip, reason);
+ new_warning(UNDEF,"You are banned from the game.");
+ me->p_explode=100;
+ me->p_status=PEXPLODE;
+ me->p_whydead=KQUIT; /* make him self destruct */
+ me->p_whodead=0;
+ logfile=fopen(LogFileName, "a");
+ if (logfile) {
+ curtime=time(NULL);
+ fprintf(logfile, "Banned and exiting: %s (%s@%s), (%c), %s",
+ me->p_name, me->p_login, host, shipnos[me->p_no], ctime(&curtime)
+ );
+ fclose(logfile);
+ }
}
}
@@ -813,12 +823,34 @@
fclose(logfile);
}
-static int checkbanned(char *login, char *host)
+/* check temporary bans voted */
+static int check_temporary_bans(char *ip)
+{
+ int i;
+ for(i=0; i<MAXBANS; i++) {
+ struct ban *b = &bans[i];
+ if (b->b_expire) {
+ if (!strcmp(b->b_ip, ip)) {
+ ERROR(2,( "ban of %s has been probed\n", b->b_ip));
+ b->b_expire += 10;
+ return TRUE;
+ }
+ b->b_expire--;
+ if (!b->b_expire) {
+ ERROR(2,( "ban of %s has expired\n", b->b_ip));
+ }
+ }
+ }
+ return FALSE;
+}
+
+/* check permanent bans in file */
+static int check_permanent_bans(char *login, char *host)
{
FILE *bannedfile;
char log_buf[64], host_buf[64], line_buf[160];
char *position;
- int num1;
+ int num1;
int Hits=0; /* Hits==2 means we're banned */
if ((bannedfile = fopen(Banned_File, "r")) == NULL) {
Index: openmem.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/openmem.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- openmem.c 22 Apr 2006 02:16:46 -0000 1.2
+++ openmem.c 24 Apr 2006 12:35:17 -0000 1.3
@@ -79,6 +79,7 @@
shipvals = sharedMemory->shipvals;
queues = sharedMemory->queues;
waiting = sharedMemory->waiting;
+ bans = sharedMemory->bans;
}
/*ARGSUSED*/