-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.c
343 lines (266 loc) · 6.56 KB
/
print.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
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
#include "print.h"
#include "server.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void PrintWrongPriceBuy (struct banker *);
void PrintWrongItemBuy (struct banker *);
void PrintWrongPriceSell (struct banker *);
void PrintWrongItemSell (struct banker *);
void PrintCantCreateProd (struct banker *);
void PrintWillCreateProd (struct banker *);
void PrintBankrupt (struct client *);
void PrintMadeProd (struct client *, int i);
void PrintGameNotStarted (int);
void PrintServerInfo (int, int);
void PrintDescriptors (int *, int);
void PrintToFDSuccessConnect (int);
void PrintToAll (struct clientlist *, char *);
void PrintSuccessBuy (struct clientlist *);
void PrintSuccessSell (struct clientlist *);
void PrintSuccessBuild (struct clientlist *);
void PrintTurnOn (struct clientlist *);
void PrintComing (int, int);
/*
*/
void PrintWrongPriceBuy (struct banker * bank)
{
int fd;
char * strInfoPrice;
fd = bank->clList->current->contact->fd;
strInfoPrice = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfoPrice,
"Wrong price! Max. price:\t%d.\n",
bank->buy->price
);
write (fd, strInfoPrice, strlen (strInfoPrice)+1);
free (strInfoPrice);
}
/*
*/
void PrintWrongItemBuy (struct banker * bank)
{
int fd;
char * strInfoItem;
fd = bank->clList->current->contact->fd;
strInfoItem = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfoItem,
"Wrong item! Max. item:\t%d.\n",
bank->buy->item
);
write (fd, strInfoItem, strlen (strInfoItem) + 1);
free (strInfoItem);
}
/*
*/
void PrintWrongPriceSell (struct banker * bank)
{
int fd;
char * strInfoPrice;
fd = bank->clList->current->contact->fd;
strInfoPrice = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfoPrice,
"Wrong price! Min. price:\t%d.\n",
bank->sell->price
);
write (fd, strInfoPrice, strlen (strInfoPrice)+1);
free (strInfoPrice);
}
/*
*/
void PrintWrongItemSell (struct banker * bank)
{
int fd;
char * strInfoItem;
fd = bank->clList->current->contact->fd;
strInfoItem = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfoItem,
"Wrong item! Max. item:\t%d.\n",
bank->sell->item
);
write (fd, strInfoItem, strlen (strInfoItem) + 1);
free (strInfoItem);
}
/* Print to current user that he can't create prod,
* because factory not enough.
*/
void PrintCantCreateProd (struct banker * bank)
{
char * strInfo;
int fd;
fd = bank->clList->current->contact->fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfo,
"You can't create product in month more than have factory\n"
);
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/* Print prod which may be will be create
*/
void PrintWillCreateProd (struct banker * bank)
{
struct stuff * data;
char * strInfo;
int fd;
data = bank->clList->current->data;
fd = bank->clList->current->contact->fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfo, "You'll create %d production in all.\n",
data->order);
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/* Print to user that he is bankrupt
*/
void PrintBankrupt (struct client * user)
{
char * strInfo;
int fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
fd = user->contact->fd;
sprintf (strInfo, "You are bankrupt!\n");
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/*
*/
void PrintMadeProd (struct client* user, int i)
{
int fd;
char * strInfo;
strInfo = (char *) malloc (MESSAGE_LENGHT);
fd = user->contact->fd;
sprintf (strInfo, "Made %d production.\n", i);
write (fd, strInfo , strlen(strInfo) + 1);
user->data->order = 0;
free (strInfo);
}
/* Print to fd that game not started.
*/
void PrintGameNotStarted (int fd)
{
char * str;
str = (char *) malloc (MESSAGE_LENGHT);
sprintf (str, "Game not started.\nYou can use only \"help\".\n");
write (fd, str, strlen(str) + 1);
free (str);
}
/* Print in server maxPlayers and ports got from argv.
*/
void PrintServerInfo (int port, int numPl)
{
printf ("Max. players:%d\n", numPl);
printf ("Port:%d.\n", port);
}
/* */
void PrintDescriptors (int *arr_d, int cur_num)
{
int i;
printf ("Current number of players:%d\n", cur_num);
printf ("List of descriptors:\n");
for ( i = 0; i < cur_num; i++ )
printf ("fd=%d.", arr_d[i]);
printf ("\n");
}
/* Print to fd that client is connected.
*/
void PrintToFDSuccessConnect (int fd)
{
char * strConnected;
strConnected = (char *) malloc (MESSAGE_LENGHT);
sprintf (strConnected, "You're connected to server.\n");
write ( fd, strConnected, strlen(strConnected) + 1 );
free (strConnected);
}
/* Print to all char * strInfo;
*/
void PrintToAll(struct clientlist * clList, char * strInfo)
{
struct client * user;
int fd;
user = clList->first;
while ( user != NULL )
{
fd = user->contact->fd;
write (fd, strInfo, strlen(strInfo) + 1);
user = user->next;
}
}
/* Print to cur client that lots buy get.
*/
void PrintSuccessBuy (struct clientlist *clList)
{
struct client * user;
char * strInfo;
int fd;
user = clList->current;
fd = user->contact->fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfo,
"Lots to buy get. All previous buy-lots lost.\n"
);
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/* Print to cur client that lots sell get
*/
void PrintSuccessSell (struct clientlist * clList)
{
struct client * user;
char * strInfo;
int fd;
user = clList->current;
fd = user->contact->fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfo,
"Lots to sell get. All previous sell-lots lost.\n"
);
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/* Print to cur client about start building factory;
*/
void PrintSuccessBuild (struct clientlist * clList)
{
struct client * user;
char * strInfo;
int fd;
user = clList->current;
fd = user->contact->fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfo,
"You start build factory. After 5 months consctruc end.\n"
);
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/* Print to current user that "turn" used.
*/
void PrintTurnOn (struct clientlist * clList)
{
struct client * user;
char * strInfo;
int fd;
user = clList->current;
fd = user->contact->fd;
strInfo = (char *) malloc (MESSAGE_LENGHT);
sprintf (strInfo,
"Turn cmd get. Now you can use only info-cmd before change month.\n"
);
write (fd, strInfo, strlen(strInfo) + 1);
free (strInfo);
}
/* In fd print coming (if game not started).
*/
void PrintComing (int fd, int statusStartGame)
{
char * strIn;
strIn = (char *) malloc (MESSAGE_LENGHT);
sprintf (strIn, "\n>");
if ( statusStartGame != 0 )
{
write (fd, strIn, strlen(strIn) + 1);
}
free (strIn);
}