File: cuclient.c

package info (click to toggle)
conquest 8.1-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,984 kB
  • ctags: 3,086
  • sloc: ansic: 39,393; sh: 8,540; yacc: 446; makefile: 296; lex: 146
file content (364 lines) | stat: -rw-r--r-- 7,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#include "c_defs.h"

/************************************************************************
 *
 * client specific stuff
 *
 * $Id: cuclient.c,v 1.3 2004/11/14 08:26:40 jon Exp $
 *
 * Copyright 2003 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
 ***********************************************************************/

#include "global.h"
#include "conf.h"
#include "conqnet.h"
#include "protocol.h"
#include "packet.h"
#include "client.h"
#include "clientlb.h"
#include "cd2lb.h"
#include "iolb.h"
#include "cumisc.h"
#include "conqcom.h"
#include "conqlb.h"
#include "context.h"
#include "record.h"
#include "disputil.h"

void cucPseudo( int unum, int snum )
{
  char ch, buf[MSGMAXLINE];
  
  buf[0] = EOS;

  cdclrl( MSG_LIN1, 2 );
  c_strcpy( "Old pseudonym: ", buf );
  if ( snum > 0 && snum <= MAXSHIPS )
    appstr( Ships[snum].alias, buf );
  else
    appstr( Users[unum].alias, buf );
  cdputc( buf, MSG_LIN1 );
  ch = mcuGetCX( "Enter a new pseudonym: ",
	     MSG_LIN2, -4, TERMS, buf, MAXUSERPNAME );
  if ( ch == TERM_ABORT || buf[0] == EOS)
    {
      cdclrl( MSG_LIN1, 2 );
      return;
    }

  sendSetName(buf);

  cdclrl( MSG_LIN1, 2 );
  
  return;
  
}

/*  dowar - declare war or peace */
/*  SYNOPSIS */
/*    int snum */
/*    dowar( snum ) */
void cucDoWar( int snum )
{
  int i, entertime, now; 
  Unsgn8 war;
  int twar[NUMPLAYERTEAMS], dowait;
  int ch;
  
  for ( i = 0; i < NUMPLAYERTEAMS; i = i + 1 )
    twar[i] = Ships[snum].war[i];
  
  cdclrl( MSG_LIN1, 2 );
  
  while ( clbStillAlive( Context.snum ) )
    {
      cdputs(clbWarPrompt(Context.snum, twar), MSG_LIN1, 1);

      cdrefresh();
      if ( iogtimed( &ch, 1.0 ) == FALSE )
	{
	  continue; /* next; */
	}
      
      ch = (char)tolower( ch );
      if ( ch == TERM_ABORT )
	break;
      if ( ch == TERM_EXTRA )
	{
	  /* Now update the war settings. */
	  dowait = FALSE;
	  war = 0;
	  for ( i = 0; i < NUMPLAYERTEAMS; i = i + 1 )
	    {
	      if ( twar[i] && ! Ships[snum].war[i] )
		dowait = TRUE;

	      if (twar[i])
		war |= (1 << i);

	      /* we'll let it happen locally as well... */
	      Users[Ships[snum].unum].war[i] = twar[i];
	      Ships[snum].war[i] = twar[i];
	    }
	  
	  sendCommand(CPCMD_SETWAR, (Unsgn16)war);

	  /* Only check for computer delay when flying. */
	  if ( Ships[snum].status != SS_RESERVED && dowait )
	    {
	      /* We've set war with at least one team, stall a little. */
	      mcuPutMsg(
		       "Reprogramming the battle computer, please stand by...",
		       MSG_LIN2 );
	      cdrefresh();
	      grand( &entertime );
	      while ( dgrand( entertime, &now ) < REARM_GRAND )
		{
		  /* See if we're still alive. */
		  if ( ! clbStillAlive( Context.snum ) )
		    return;
		  
		  /* Sleep */
 		  c_sleep( ITER_SECONDS );
		}
	    }
	  break;
	}
      
      for ( i = 0; i < NUMPLAYERTEAMS; i = i + 1 )
	if ( ch == (char)tolower( Teams[i].teamchar ) )
	  {
	    if ( ! twar[i] || ! Ships[snum].rwar[i] )
	      {
		twar[i] = ! twar[i];
		goto ccont1;	/* next 2  */
	      }
	    break;
	  }
      cdbeep();
      
    ccont1:				/* goto  */
      ;
    }
  
  cdclrl( MSG_LIN1, 2 );
  
  return;
  
}


/* compose and send a message. If remote is true, we will use sendMessage,
   else stormsg (for local cb updates) */
void cucSendMsg( int from, int terse, int remote )
{
  int i, j; 
  char buf[MSGMAXLINE] = "", msg[MESSAGE_SIZE] = "";
  int ch;
  int editing; 
  string mto="Message to: ";
  string nf="Not found.";
  string huh="I don't understand.";

  int append_flg;  /* when user types to the limit. */
  int do_append_flg;
  
  static int to = MSG_NOONE;
  
  /* First, find out who we're sending to. */
  cdclrl( MSG_LIN1, 2 );
  buf[0] = EOS;
  ch = cdgetx( mto, MSG_LIN1, 1, TERMS, buf, MSGMAXLINE, TRUE );
  if ( ch == TERM_ABORT )
    {
      cdclrl( MSG_LIN1, 1 );
      return;
    }
  
  /* TAB or RETURN means use the target from the last message. */
  editing = ( (ch == TERM_EXTRA || ch == TERM_NORMAL) && buf[0] == EOS );
  if ( editing )
    {
      /* Make up a default string using the last target. */
      if ( to > 0 && to <= MAXSHIPS )
	sprintf( buf, "%d", to );
      else if ( -to >= 0 && -to < NUMPLAYERTEAMS )
	c_strcpy( Teams[-to].name, buf );
      else switch ( to )
	{
	case MSG_ALL:
	  c_strcpy( "All", buf );
	  break;
	case MSG_GOD:
	  c_strcpy( "GOD", buf );
	  break;
	case MSG_IMPLEMENTORS:
	  c_strcpy( "Implementors", buf );
	  break;
	case MSG_FRIENDLY:
	  c_strcpy( "Friend", buf );
	  break;
	default:
	  buf[0] = EOS;
	  break;
	}
      
    }
  
  /* Got a target, parse it. */
  delblanks( buf );
  upper( buf );
  if ( alldig( buf ) == TRUE )
    {
      /* All digits means a ship number. */
      i = 0;
      safectoi( &j, buf, i );		/* ignore status */
      if ( j < 1 || j > MAXSHIPS )
	{
	  mcuPutMsg( "No such ship.", MSG_LIN2 );
	  return;
	}
      if ( Ships[j].status != SS_LIVE )
	{
	  mcuPutMsg( nf, MSG_LIN2 );
	  return;
	}
      to = j;
    }
  else switch ( buf[0] )
    {
    case 'A':
    case 'a':
      to = MSG_ALL;
      break;
    case 'G':
    case 'g':
      to = MSG_GOD;
      break;
    case 'I':
    case 'i':
      to = MSG_IMPLEMENTORS;
      break;
    default:
      /* check for 'Friend' */
      if (buf[0] == 'F' && buf[1] == 'R')
	{			/* to friendlies */
	  to = MSG_FRIENDLY;
	}
      else
	{
	  /* Check for a team character. */
	  for ( i = 0; i < NUMPLAYERTEAMS; i = i + 1 )
	    if ( buf[0] == Teams[i].teamchar || buf[0] == (char)tolower(Teams[i].teamchar) )
	      break;
	  if ( i >= NUMPLAYERTEAMS )
	    {
	      mcuPutMsg( huh, MSG_LIN2 );
	      return;
	    }
	  to = -i;
	};
      break;
    }
  
  /* Now, construct a header for the selected target. */
  c_strcpy( "Message to ", buf );
  if ( to > 0 && to <= MAXSHIPS )
    {
      if ( Ships[to].status != SS_LIVE )
	{
	  mcuPutMsg( nf, MSG_LIN2 );
	  return;
	}
      appship( to, buf );
      appchr( ':', buf );
    }
  else if ( -to >= 0 && -to < NUMPLAYERTEAMS )
    {
      appstr( Teams[-to].name, buf );
      appstr( "s:", buf );
    }
  else switch ( to ) 
    {
    case MSG_ALL:
      appstr( "everyone:", buf );
      break;
    case MSG_GOD:
      appstr( "GOD:", buf );
      break;
    case MSG_IMPLEMENTORS:
      appstr( "The Implementors:", buf );
      break;
    case MSG_FRIENDLY:
      appstr( "Friend:", buf );
      break;
    default:
      mcuPutMsg( huh, MSG_LIN2 );
      return;
      break;
    }
  
  if ( ! terse )
    appstr( " (ESCAPE to abort)", buf );
  
  mcuPutMsg( buf, MSG_LIN1 );
  cdclrl( MSG_LIN2, 1 );
  
  if ( ! editing )
    msg[0] = EOS;
  
  if ( to == MSG_IMPLEMENTORS )
    i = MSGMAXLINE;
  else
    i = MESSAGE_SIZE;
  
  append_flg = TRUE;
  while (append_flg == TRUE) {
  append_flg = FALSE;
  do_append_flg = TRUE;
  msg[0] = EOS;
  if ( cdgetp( ">", MSG_LIN2, 1, TERMS, msg, i, 
	       &append_flg, do_append_flg, TRUE ) != TERM_ABORT )
    {
      if ( to != MSG_IMPLEMENTORS )
	{
	  if (remote)		/* remotes don't send 'from' */
	    sendMessage(to, msg);
	  else
	    clbStoreMsg( from, to, msg ); /* conqoper */
	}
      else
	{
	  /* Handle a message to the Implementors. */
	  c_strcpy( "Communique from ", buf );
	  if ( from > 0 && from <= MAXSHIPS )
	    {
	      appstr( Ships[from].alias, buf );
	      appstr( " on board ", buf );
	      appship( from, buf );
	    }
	  else if ( from == MSG_GOD )
	    appstr( "GOD", buf );
	  else
	    {
	      appchr( '(', buf );
	      appint( from, buf );
	      appchr( ')', buf );
	    }
	  if (remote)           /* remotes don't send 'from' */
	    sendMessage(MSG_IMPLEMENTORS, msg);
	  else
	    clbStoreMsg( from, MSG_IMPLEMENTORS, msg ); /* GOD == IMP (conqoper) */
	  /* log it to the logfile too */
	  clog("MSG: MESSAGE TO IMPLEMENTORS: %s: %s", buf, msg);
	}
    }
  } /* end while loop */ 
  cdclrl( MSG_LIN1, 2 );
  
  return;
  
}