File: servercmd.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 (157 lines) | stat: -rw-r--r-- 3,777 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
#include "c_defs.h"

/************************************************************************
 *
 * server command handling
 *
 * $Id: servercmd.c,v 1.4 2004/05/08 21:01:41 jon Exp $
 *
 * Copyright 2003 Jon Trulson under the ARTISTIC LICENSE. (See LICENSE).
 ***********************************************************************/

#include "conqdef.h"
#include "conqcom.h"
#include "conf.h"
#include "server.h"
#include "serverpkt.h"
#include "context.h"
#include "record.h"
#include "servercmd.h"
#include "conqlb.h"

void startRecord(void)
{
  char fname[MID_BUFFER_SIZE];
  char bname[MID_BUFFER_SIZE];
  char cbuf[MID_BUFFER_SIZE];
  time_t thetime;
  struct tm *tmtime;
  char tbuf[128];
  
  if (Context.recmode == RECMODE_ON)
    {
      clog("conquestd: startRecord: already recording.");
      clbStoreMsg(MSG_GOD, Context.snum, "We are already recording.");
      return;
    }

  /* make a filename.  This will be something like
     CONQSTATE/conquest-rec-MMDDYYYY-HHMM.cpr */

  thetime = getnow(NULL, 0);
  tmtime = localtime(&thetime);

  strftime(tbuf, 128 - 1, "%m%d%Y-%H%M", tmtime);

  sprintf(bname, "conquest-rec-%s.cqr", tbuf);

  sprintf(fname, "%s/%s", CONQSTATE, bname);

  if (recordOpenOutput(fname, TRUE))
    {                     /* we are almost ready... */
      Context.recmode = RECMODE_STARTING;
    }
  else
    {
      Context.recmode = RECMODE_OFF;
      clog("conquestd: Cannot record to %s", fname);
      sprintf(cbuf, "Cannot record to %s", bname);
      clbStoreMsg(MSG_GOD, Context.snum, cbuf);
      return;
    }

  /* start recording */
  if (Context.recmode == RECMODE_STARTING)
    {
      if (recordInitOutput(Context.unum, getnow(NULL, 0), 0))
        {
          Context.recmode = RECMODE_ON;
          clog("conquestd: Recording to %s", fname);
          sprintf(cbuf, "Recording to %s", bname);
          clbStoreMsg(MSG_GOD, Context.snum, cbuf);
        }
      else
        {
          Context.recmode = RECMODE_OFF;
          clog("conquestd: recordInitOutput failed");
          clbStoreMsg(MSG_GOD, Context.snum, 
                  "conquestd: recordInitOutput failed");
        }
    }

  return;
}

void stopRecord(void)
{
  if (Context.recmode != RECMODE_ON)
    {
      clog("conquestd: stopRecord: not recording.");
      clbStoreMsg(MSG_GOD, Context.snum, "We aren't recording.");
      return;
    }


  clog("conquestd: stopRecord: recording stopped");
  clbStoreMsg(MSG_GOD, Context.snum, "Recording stopped");
  recordCloseOutput();

  return;
}

int checkOperExec(int from, int to, char *msg)
{
  char tmsg[MESSAGE_SIZE];
  char *p;
  char *oerror = "Non sequiter. Your facts are uncoordinated.";

  /* first, if the message isn't to GOD, ignore */
  if (to != MSG_GOD)
    return FALSE;

  /* if it's not from a valid ship, ignore */
  if (from < 1 || from > MAXSHIPS)
    return FALSE;

  strncpy(tmsg, msg, MESSAGE_SIZE);
  upper(tmsg);

  if (strncmp(tmsg, "EXEC ", 5))
    return FALSE;               /* not for us. */

  /* it is for us, now check for allowability */
  if (!Users[Ships[from].unum].ooptions[OOPT_OPER])
    {                           /* nice try... */
      clbStoreMsg(MSG_GOD, from, "You are not a Conquest Operator.");
      clog("conquestd: EXEC from unprivileged ship: %d, '%s'", from,
           tmsg);
      return FALSE;
    }

  /* ok, let's see what is up. */
  p = &(tmsg[5]);

  if (!*p)
    {
      clbStoreMsg(MSG_GOD, from, oerror);
      return FALSE;
    }

  if (!strncmp(p, "RECON", 5))
    {
      startRecord();
      return TRUE;
    }

  if (!strncmp(p, "RECOFF", 6))
    {
      stopRecord();
      Context.recmode = RECMODE_OFF;
      return TRUE;
    }

  /* that's all we understand for now. */

  clbStoreMsg(MSG_GOD, from, oerror);
  return FALSE;
}