-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.c
115 lines (107 loc) · 2.88 KB
/
security.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* security.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmerchin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/12 16:03:33 by bmerchin #+# #+# */
/* Updated: 2021/01/12 16:04:35 by bmerchin ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int security_check(t_data *data)
{
if (data->security[8] != 1)
{
ft_putstr_bn("Error\nWrong amount of starting directions");
return (1);
}
if (data->security[9] != 0)
{
ft_putstr_bn("Error\nThere is at least one missing wall on the map");
return (1);
}
if (data->security[10] != 0)
{
ft_putstr_bn("Error\nThere is an invalid character on the map");
return (1);
}
return (0);
}
int security_cub_av_check(char **av, t_data *data, int ac)
{
if (ft_strncmp(av[2], "--save", 10) == 0 && ac == 3)
data->save = 1;
else
{
ft_putstr_bn("Error\nWrong number of arguments");
return (1);
}
return (0);
}
int security_cub(int ac, char **av, t_data *data, int fd)
{
int i;
int len;
i = 0;
len = ft_strlen(av[1]);
data->save = 0;
while (i < 20)
data->security[i++] = 0;
if (ac != 2 && security_cub_av_check(av, data, ac))
return (1);
if (av[1][len - 1] != 'b' || av[1][len - 2] != 'u' ||
av[1][len - 3] != 'c' || av[1][len - 4] != '.')
{
ft_putstr_bn("Error\nYour map fomat must be .cub");
return (1);
}
if (fd < 0)
{
ft_putstr_bn("Error\nOpen Folder, wrong map");
return (1);
}
return (0);
}
int security_data_extension(t_data *data)
{
if (data->x_screen_size > 10000 || data->y_screen_size > 10000)
{
ft_putstr_bn("Error\nYour Map resolution is too big");
return (1);
}
if (data->x_screen_size < 5 || data->y_screen_size < 5)
{
ft_putstr_bn("Error\nYour Map resolution is too small");
return (1);
}
return (0);
}
int security_data(t_data *data)
{
int i;
i = -1;
while (++i < 8)
{
if (data->security[i] == 0)
{
ft_putstr_bn("Error\nData Missing in .cub");
printf("Trigerred issue %d (Wrong data or missing)\n", i);
return (1);
}
if (data->security[i] > 1)
{
if (i == 3 && BONUS && data->security[i] == 1
+ NUM_SPRITE_BOMUS + NUM_TEXTURE_BONUS)
;
else
{
ft_putstr_bn("Error\nBad data in the first part");
printf("The security issue %d was trigerred\n", i);
return (1);
}
}
}
return (security_data_extension(data));
}