annotate src/input.c @ 14:b7fe2e0e4b86

Added #defines which hold the chance of nebulous terrain affecting your weapons systems.
author darius
date Sat, 06 Dec 1997 06:27:50 +0000
parents aa38447a4b21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
5 documentation for any NON-COMMERCIAL purpose (following the terms of
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
6 the GNU General Public License (read the file 'COPYING')) and without
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
7 fee is hereby granted, provided that this copyright notice appear in all
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
8 copies. No representations are made about the suitability of this
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 software for any purpose. This software is provided "as is" without
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10 express or implied warranty.
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Xtrek Copyright 1986 Chris Guthrie
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Scott Silvey
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Paradise II (Netrek II) Copyright 1993 Larry Denys
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Kurt Olsen
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 Brandon Gillespie
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19 Comprehensive credits are available in the file "CREDITS"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 --------------------------------------------------------------------------*/
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include "config.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include <stdio.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include <string.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include <math.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include <sys/types.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27 #include <sys/time.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 #include <signal.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 #include <errno.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30 #include "defs.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 #include "struct.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32 #include "data.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 #include "shmem.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35 static int sendflag = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37 extern int intrupt();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38 extern void start_interruptor();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 extern int isClientDead();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40 int reconnect();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41 extern int readFromClient();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 extern void stop_interruptor();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 extern int exitGame();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 extern int closeUdpConn();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45 extern unsigned int sleep();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 extern int connectToClient();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 extern void (*r_signal()) ();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 setflag()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 sendflag = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 input()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 fd_set readfds;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61 start_interruptor();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 /* Idea: read from client often, send to client not so often */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64 while (me->p_status == PALIVE ||
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 me->p_status == PEXPLODE ||
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 me->p_status == PDEAD ||
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 me->p_status == POBSERVE)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 if (isClientDead())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 if (!reconnect())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72 exit(0);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 FD_ZERO(&readfds);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75 FD_SET(sock, &readfds);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 if (udpSock >= 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77 FD_SET(udpSock, &readfds);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 /*
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 * blocks indefinitely unless client input or timerDelay SIGALRM causes
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 * EINTR
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84 if (socketWait() > 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 readFromClient();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88 if (sendflag)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 intrupt();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 sendflag = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 /* statements below are executed once per timerDelay */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 if (me->p_updates > delay)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97 me->p_flags &= ~(PFWAR);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99 if (me->p_updates > rdelay)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 me->p_flags &= ~(PFREFITTING);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 /*
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 * this will ghostbust a player if no ping has been received in
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 * ping_ghostbust_interval seconds
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 if (configvals->ping_allow_ghostbust
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 && (me->p_status == PALIVE || me->p_status == POBSERVE)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 && ping_ghostbust > configvals->ping_ghostbust_interval)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 me->p_ghostbuster = 100000; /* ghostbusted */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 else
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 /* Keep self from being nuked... */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115 me->p_ghostbuster = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 stop_interruptor();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 int
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121 reconnect()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123 int i;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 if (noressurect)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 exitGame();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127 stop_interruptor();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 r_signal(SIGIO, SIG_IGN);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130 #ifdef DEBUG
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 printf("Ack! The client went away!\n");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 printf("I will attempt to resurrect him!\n");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133 fflush(stdout);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135 commMode = COMM_TCP;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136 if (udpSock >= 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137 closeUdpConn();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 /* For next two minutes, we try to restore connection */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 shutdown(sock, 2);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 sock = -1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 for (i = 0;; i++)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 me->p_ghostbuster = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 sleep(5);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 if (connectToClient(host, nextSocket))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 break;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 if (i == 23)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 #ifdef DEBUG
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151 printf("Oh well, maybe I'm getting rusty!\n");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 fflush(stdout);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154 return 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 start_interruptor();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 #ifdef DEBUG
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159 printf("A miracle! He's alive!\n");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160 fflush(stdout);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162 return 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
163 }