Mercurial > ~darius > hgwebdir.cgi > paradise_server
comparison src/tool-mes.c @ 8:0836fb919dfa
First entry of Paradise Server 2.9 patch 10 Beta
author | darius |
---|---|
date | Sat, 06 Dec 1997 04:37:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:814de70c9f67 | 8:0836fb919dfa |
---|---|
1 /*-------------------------------------------------------------------------- | |
2 NETREK II -- Paradise | |
3 | |
4 Permission to use, copy, modify, and distribute this software and its | |
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL | |
6 purpose and without fee is hereby granted, provided that this copyright | |
7 notice appear in all copies. No representations are made about the | |
8 suitability of this software for any purpose. This software is provided | |
9 "as is" without express or implied warranty. | |
10 | |
11 Xtrek Copyright 1986 Chris Guthrie | |
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith | |
13 Scott Silvey | |
14 Paradise II (Netrek II) Copyright 1993 Larry Denys | |
15 Kurt Olsen | |
16 Brandon Gillespie | |
17 --------------------------------------------------------------------------*/ | |
18 | |
19 | |
20 #include "config.h" | |
21 | |
22 #include <stdio.h> | |
23 #include "defs.h" | |
24 #include "data.h" | |
25 #include "shmem.h" | |
26 | |
27 void | |
28 usage(char name[]) | |
29 { | |
30 char *message[255] = { | |
31 "\nSend messages (accepted from stdin).\n", | |
32 "\n\t'%s <recipient> [options]'\n\n", | |
33 "Recipients can be:\n", | |
34 "\ta number from 0-9 or a letter from a-j to send to one player\n", | |
35 "\ta team letter [FRKO] to send to that team\n", | |
36 "\tthe letter 'A' to send to ALL.\n", | |
37 "\nOptions:\n", | |
38 "\t-w without the 'who' part of the message ('GOD->ALL')\n", | |
39 "\t-n string from somebody other than 'GOD'\n\n", | |
40 "" | |
41 }; | |
42 int x; | |
43 | |
44 fprintf(stderr, "-- Netrek II (Paradise), %s --\n", PARAVERS); | |
45 for (x = 0; *message[x] != '\0'; x++) | |
46 fprintf(stderr, message[x], name); | |
47 | |
48 exit(1); | |
49 } | |
50 | |
51 void | |
52 pmessage(from_to, str, recip, group) | |
53 /* ==[ printing of message func ]== */ | |
54 char *from_to; | |
55 char *str; | |
56 int recip; | |
57 int group; | |
58 { | |
59 struct message *cur; | |
60 if (++(mctl->mc_current) >= MAXMESSAGE) | |
61 mctl->mc_current = 0; | |
62 cur = &messages[mctl->mc_current]; | |
63 cur->m_no = mctl->mc_current; | |
64 cur->m_flags = group; | |
65 cur->m_time = 0; | |
66 cur->m_recpt = recip; | |
67 cur->m_from = 255; | |
68 (void) sprintf(cur->m_data, "%s%s", from_to, str); | |
69 cur->m_flags |= MVALID; | |
70 } | |
71 | |
72 int | |
73 main(int argc, char **argv) | |
74 { | |
75 char ch; | |
76 char to[80]; | |
77 char from[80]; | |
78 char buf2[80]; | |
79 int target; | |
80 int flag; | |
81 char name[32]; | |
82 | |
83 strcpy(from, "GOD"); | |
84 strcpy(to, "ALL"); | |
85 | |
86 strcpy(name, argv[0]); | |
87 | |
88 if (argc == 1) | |
89 usage(name); | |
90 | |
91 if ((target = letter_to_pnum(argv[1][0])) >= 0) | |
92 { /*--[ personal ]--*/ | |
93 flag = MINDIV; | |
94 /* | |
95 * r = &players[target]; printf("debug: 1"); to[0] = | |
96 * team_to_letter(r->p_team); to[1] = 0; | |
97 */ | |
98 strcpy(to, argv[1]); | |
99 } | |
100 else | |
101 switch (ch = argv[1][0]) | |
102 { /*--[ better be a team ]--*/ | |
103 case 'A': | |
104 target = 0; | |
105 flag = MALL; | |
106 break; | |
107 case 'F': | |
108 target = FED; | |
109 flag = MTEAM; | |
110 strcpy(to, "FED"); | |
111 break; | |
112 case 'R': | |
113 target = ROM; | |
114 flag = MTEAM; | |
115 strcpy(to, "ROM"); | |
116 break; | |
117 case 'K': | |
118 target = KLI; | |
119 flag = MTEAM; | |
120 strcpy(to, "KLI"); | |
121 break; | |
122 case 'O': | |
123 target = ORI; | |
124 flag = MTEAM; | |
125 strcpy(to, "ORI"); | |
126 break; | |
127 case 'S': | |
128 printf("+> This options is not compatable yet"); | |
129 exit(1); | |
130 flag = 0; | |
131 break; | |
132 default: | |
133 usage(name); | |
134 flag = 0; | |
135 break; | |
136 } | |
137 | |
138 /* | |
139 * =========================[ check for options ]========================= | |
140 */ | |
141 | |
142 if (argc >= 3) | |
143 { | |
144 if (strcmp(argv[2], "-w") == 0) | |
145 { /*-----[ without to/from ]-----*/ | |
146 from[0] = 0; | |
147 } | |
148 else if (strcmp(argv[2], "-n") == 0) | |
149 { /*--[ different from name ]---*/ | |
150 if (argc <= 2) /*--[ other than GOD ]--------*/ | |
151 usage(name); | |
152 if (argc >= 3) | |
153 { | |
154 strcpy(from, argv[3]); | |
155 } | |
156 else | |
157 { | |
158 usage(name); | |
159 } | |
160 } | |
161 else if (strcmp(argv[1], "-u") == 0 || strcmp(argv[1], "-h") == 0) | |
162 { | |
163 usage(name); | |
164 } | |
165 } | |
166 | |
167 /* | |
168 * ===[ merge the to/from strings, make sure they are the same length ]=== | |
169 */ | |
170 | |
171 if (from[0] == 0 || to[0] == 0) | |
172 { | |
173 strcpy(buf2, ""); | |
174 } | |
175 else | |
176 { | |
177 if (strlen(from) <= 2) | |
178 { | |
179 strcpy(buf2, " "); | |
180 } | |
181 strcat(buf2, from); | |
182 strcat(buf2, "->"); | |
183 strcat(buf2, to); | |
184 | |
185 while (strlen(buf2) < 9) | |
186 { /*---[ if it's too short, extend it ]---*/ | |
187 strcat(buf2, " "); | |
188 } | |
189 strcat(buf2, " "); /*---[ throw in an extra space ]---*/ | |
190 } | |
191 /* | |
192 * =========================[ send it on its way ]======================== | |
193 */ | |
194 | |
195 openmem(0); | |
196 | |
197 while (1) | |
198 { | |
199 char buf[80]; | |
200 int len; | |
201 | |
202 printf(buf2); | |
203 if (0 == fgets(buf, sizeof(buf), stdin)) | |
204 break; | |
205 len = strlen(buf); | |
206 if (buf[len - 1] == '\n') | |
207 buf[--len] = 0; | |
208 pmessage(buf2, buf, target, flag); | |
209 } | |
210 } |