File: nWelcome.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 (258 lines) | stat: -rw-r--r-- 6,696 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
/* 
 * Welcome to this node
 *
 * $Id: nWelcome.c,v 1.6 2004/11/21 23:53:30 jon Exp $
 *
 * Copyright 1999-2004 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
 */

#include "c_defs.h"
#include "context.h"
#include "global.h"
#include "datatypes.h"
#include "color.h"
#include "conf.h"
#include "conqcom.h"
#include "client.h"
#include "nWelcome.h"
#include "nMenu.h"
#include "gldisplay.h"
#include "node.h"

#define S_DONE         0        /* nothing to display */
#define S_GREETINGS    1        /* GREETINGS - new user */
#define S_ERROR        2        /* some problem */

static int state;

static int fatal = FALSE;
static int serror = FALSE;
static int newuser = FALSE;
static spAck_t sack;
static time_t snooze = (time_t)0;          /* sleep time */

static string sorry1="I'm sorry, but the game is closed for repairs right now.";
static string sorry2="I'm sorry, but there is no room for a new player right now.";
static string sorryn="Please try again some other time.  Thank you.";
static string selected_str="You have been selected to command a";
static string starship_str=" starship.";
static string prepare_str="Prepare to be beamed aboard...";



static int nWelcomeDisplay(dspConfig_t *);

static scrNode_t nWelcomeNode = {
  nWelcomeDisplay,              /* display */
  NULL,                         /* idle */
  NULL,                          /* input */
  NULL                          /* next */
};

/*  gretds - block letter "greetings..." */
/*  SYNOPSIS */
/*    gretds */
static void gretds()
{
  int col,lin;
  string g1=" GGG   RRRR   EEEEE  EEEEE  TTTTT   III   N   N   GGG    SSSS";
  string g2="G   G  R   R  E      E        T      I    NN  N  G   G  S";
  string g3="G      RRRR   EEE    EEE      T      I    N N N  G       SSS";
  string g4="G  GG  R  R   E      E        T      I    N  NN  G  GG      S  ..  ..  ..";
  string g5=" GGG   R   R  EEEEE  EEEEE    T     III   N   N   GGG   SSSS   ..  ..  ..";
  
  col = (int)(Context.maxcol - strlen(g5)) / (int)2;
  lin = 1;
  cprintf( lin,col,ALIGN_NONE,"#%d#%s", InfoColor, g1);
  lin++;
  cprintf( lin,col,ALIGN_NONE,"#%d#%s", InfoColor, g2);
  lin++;
  cprintf( lin,col,ALIGN_NONE,"#%d#%s", InfoColor, g3);
  lin++;
  cprintf( lin,col,ALIGN_NONE,"#%d#%s", InfoColor, g4);
  lin++;
  cprintf( lin,col,ALIGN_NONE,"#%d#%s", InfoColor, g5);
  
  return;
  
}

void nWelcomeInit(void)
{
  spClientStat_t *scstat = NULL;
  int pkttype;
  Unsgn8 buf[PKT_MAXSIZE];
  int sockl[2] = {cInfo.sock, cInfo.usock};

  /* now look for SP_CLIENTSTAT or SP_ACK */
  if ((pkttype = 
       readPacket(PKT_FROMSERVER, sockl, buf, PKT_MAXSIZE, 60)) <= 0)
    {
      clog("nWelcomeInit: read SP_CLIENTSTAT or SP_ACK failed: %d\n",
           pkttype);
      fatal = TRUE;
      return;
    }

  setNode(&nWelcomeNode);

  switch (pkttype)
    {
    case SP_CLIENTSTAT:
      scstat = (spClientStat_t *)buf;

      Context.unum = (int)ntohs(scstat->unum);
      Context.snum = scstat->snum;
      Ships[Context.snum].team = scstat->team;
      break;
    case SP_ACK:
      sack = *(spAck_t *)buf;
      state = S_ERROR;
      serror = TRUE;

      break;
    default:
      clog("nWelcomeInit: got unexpected packet type %d\n", pkttype);
      fatal = TRUE;
      state = S_ERROR;
      return;

      break;
    }

  if (pkttype == SP_CLIENTSTAT && (scstat->flags & SPCLNTSTAT_FLAG_NEW))
    {
      newuser = TRUE;
      state = S_GREETINGS;
      snooze = (time(0) + 3);
    }
  else
    {
      newuser = FALSE;
      if (!serror)
        state = S_DONE;           /* need to wait for user packet */
      else
        snooze = (time(0) + 4);

    }


  return;
}


static int nWelcomeDisplay(dspConfig_t *dsp)
{
  Unsgn8 buf[PKT_MAXSIZE];
  int team, col = 0;
  time_t t = time(0);
  int sockl[2] = {cInfo.sock, cInfo.usock};

  if (fatal)
    return NODE_EXIT;           /* see ya! */

  if (snooze)
    {
      if (serror)                 /* an error */
        {
          if (t > snooze)     /* time to go */
            {
              snooze = 0;
              return NODE_EXIT;
            }
        }
      else
        {                       /* new user */
          if (t > snooze)
            {
              state = S_DONE;
              snooze = 0;
              return NODE_OK;
            }
        }
    }


  switch (state)
    {
    case S_GREETINGS:
      /* Must be a new player. */
      if ( ConqInfo->closed )
        {
          /* Can't enroll if the game is closed. */
          cprintf(MSG_LIN2/2,col,ALIGN_CENTER,"#%d#%s", InfoColor, sorry1 );
          cprintf(MSG_LIN2/2+1,col,ALIGN_CENTER,"#%d#%s", InfoColor, sorryn );
        }
      else
        {
          team = Ships[Context.snum].team;
          gretds();                 /* 'GREETINGS' */
          
          if ( vowel( Teams[team].name[0] ) )
            cprintf(MSG_LIN2/2,0,ALIGN_CENTER,"#%d#%s%c #%d#%s #%d#%s",
                    InfoColor,selected_str,'n',CQC_A_BOLD,Teams[team].name,
                    InfoColor,starship_str);
          else
            cprintf(MSG_LIN2/2,0,ALIGN_CENTER,"#%d#%s #%d#%s #%d#%s",
                    InfoColor,selected_str,CQC_A_BOLD,Teams[team].name,
                    InfoColor,starship_str);

          cprintf(MSG_LIN2/2+1,0,ALIGN_CENTER,"#%d#%s",
                  InfoColor, prepare_str );
        }

      return NODE_OK;
      break;

    case S_ERROR:
      switch (sack.code)
        {
        case PERR_CLOSED:
          cprintf(MSG_LIN2/2,col,ALIGN_CENTER,"#%d#%s", InfoColor, sorry1 );
          cprintf(MSG_LIN2/2+1,col,ALIGN_CENTER,"#%d#%s", InfoColor, sorryn );
          break;

        case PERR_REGISTER:
          cprintf(MSG_LIN2/2,col,ALIGN_CENTER,"#%d#%s", InfoColor, sorry2 );
          cprintf(MSG_LIN2/2+1,col,ALIGN_CENTER,"#%d#%s", InfoColor, sorryn );
          break;

        case PERR_NOSHIP:
          cprintf(MSG_LIN2/2, 0, ALIGN_CENTER,
                  "I'm sorry, but there are no ships available right now.");
          cprintf((MSG_LIN2/2)+1, 0, ALIGN_CENTER, 
                  sorryn);
          break;

        default:
          clog("nWelcomeDisplay: unexpected ACK code %d\n", sack.code);
          break;
        }

      return NODE_OK;
      break;

    case S_DONE:
      if (waitForPacket(PKT_FROMSERVER, sockl, SP_USER, buf, PKT_MAXSIZE,
                        60, NULL) <= 0)
        {
          clog("nWelcomeDisplay: waitforpacket SP_USER returned error");
          return NODE_EXIT;
        }
      else
        procUser(buf);

      nMenuInit();
      return NODE_OK;
      break;

    default:
      clog("nWelcomeDisplay: unknown state %d", state);
      return NODE_EXIT;
      break;
    }

  return NODE_OK;
}