Zappy - Year end project 2
This is a project that Epitech asked us to create in order to allow us to reveiw the notions of the current year.
Loading...
Searching...
No Matches
client_management.c
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** my_zappy
4** File description:
5** client_management
6*/
7
8#include <unistd.h>
9
10#include "server_handler.h"
11
13{
14 for (int i = 0; i < MAX_CLIENT; i++) {
15 client[i] = DEFAULT_CLIENT;
16 }
17}
18
19int get_client(cli_t client[MAX_CLIENT], const int fd)
20{
21 for (int i = 0; i < MAX_CLIENT; i++) {
22 if (client[i].fd == fd) {
23 return (i);
24 }
25 }
26 return (-1);
27}
28
29int delete_client(cli_t client[MAX_CLIENT], const int fd)
30{
31 for (int i = 0; i < MAX_CLIENT; i++) {
32 if (client[i].fd != fd) {
33 continue;
34 }
35 close(client[i].fd);
36 if (client[i].team_name != NULL) {
37 free(client[i].team_name);
38 }
39 client[i] = DEFAULT_CLIENT;
40 return (0);
41 }
42 return (-1);
43}
44
46{
47 for (int i = 0; i < MAX_CLIENT; i++) {
48 if (client[i].fd != UNKNOWN) {
49 close(client[i].fd);
50 }
51 if (client[i].team_name != NULL) {
52 free(client[i].team_name);
53 }
54 client[i] = DEFAULT_CLIENT;
55 }
56}
void delete_all_client(cli_t client[MAX_CLIENT])
The function to delete a every client from the cli_t structure.
int delete_client(cli_t client[MAX_CLIENT], const int fd)
The function to delete a specific client from the cli_t structure by the fd.
int get_client(cli_t client[MAX_CLIENT], const int fd)
The function to get the client index in the structure by the fd.
void init_client(cli_t client[MAX_CLIENT])
The function to initialize the cli_t structure.
#define MAX_CLIENT
Definition constants.h:15
#define UNKNOWN
Definition constants.h:16
A structure to store every client/player data.