forked from jjsimpso/AberMUD
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FlagControl.c
181 lines (164 loc) · 2.91 KB
/
FlagControl.c
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
/****************************************************************************\
* *
* C R E A T O R O F L E G E N D S *
* (AberMud Version 5) *
* *
* The Creator Of Legends System is (C) Copyright 1989 Alan Cox, All Rights *
* Reserved. *
* *
\****************************************************************************/
#include "System.h"
/*
* Flag handlers
*
* 1.00 Initial release
* 1.01 Strict ANSIfication
*/
Module "Flag Controller";
Version "1.01";
Author "Alan Cox";
char *FlagName[512]; /* Crude but effective ! */
/*
* Given a name, find the flag number
*/
int GetFlagByName(char *x)
{
short c=0;
while(c<512)
{
if((FlagName[c])&&(stricmp(FlagName[c],x)==0))
return(c);
c++;
}
return(-1);
}
/*
* Set the name of a flag
*/
void SetFlagName(short f, char *x)
{
if(f<0||f>511)
return;
if(FlagName[f]!=NULL)
free(FlagName[f]);
if(x==NULL)
{
FlagName[f]=NULL;
return;
}
if((FlagName[f]=malloc(strlen(x)+1))==NULL)
Error("FlagController: No Free Memory.\n");
strcpy(FlagName[f],x);
}
/*
* Get the name of a flag
*/
char *GetFlagName(short f)
{
static char b[8];
if((f>=0)&&(f<512)&&(FlagName[f]))
return(FlagName[f]);
else
{
sprintf(b,"%d",f);
return(b);
}
}
/*
* The actual flag naming command function
*/
void Cmd_NameFlag(ITEM *i)
{
short n=GetNumber();
char *c=WordBuffer;
if(n==-1)
{
SendItem(i,"Which flag number ?\n");
return;
}
GetAll();
if(!strlen(c))
{
SendItem(i,"You must specify a name for the flag.\n");
return;
}
if(*c!='@')
{
SendItem(i,"Flags must start with the '@' character.\n");
return;
}
if(GetFlagByName(c)!=-1)
{
SendItem(i,"But flag %d is already called '%s'.\n",
GetFlagByName(c),c);
return;
}
if((n<0)||(n>511))
{
SendItem(i,"Flag numbers are from 0-511 inclusive.\n");
return;
}
SetFlagName(n,c);
SendItem(i,"Flag %d is now called %s.\n",n,c);
}
/*
* UnName a flag - command
*/
void Cmd_UnNameFlag(ITEM *i)
{
short n=GetNumber();
if(n==-1)
{
SendItem(i,"Which flag number ?\n");
return;
}
if((n<0)||(n>511))
{
SendItem(i,"Flag numbers are from 0-511 inclusive.\n");
return;
}
SetFlagName(n,NULL);
SendItem(i,"Flag %d is now un-named.\n",n);
}
/*
* The listflag command
*/
void Cmd_ListFlags(ITEM *i)
{
/*
* LISTFLAG lists all flags, LISTFLAG @NAME lists flag 'name'
* LISTFLAG n lists flag n
*/
int v;
GetAll();
if(!strlen(WordBuffer))
{
short c=0;
while(c<512)
{
if(FlagName[c])
SendItem(i,"%-3d %s\n",c,GetFlagName(c)+1);
c++;
}
return;
}
if(sscanf(WordBuffer,"%d",&v)==0)
{
if(*WordBuffer=='@')
{
if(GetFlagByName(WordBuffer))
SendItem(i,"%-3d %s\n",
GetFlagByName(WordBuffer),WordBuffer);
return;
}
else
SendItem(i,"Flag names always start with '@'.\n");
}
else
{
if(FlagName[v])
{
SendItem(i,"%-3d %s\n",v,GetFlagName((short)v));
}
}
}