Nilorea Library

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros
n_user.c
Go to the documentation of this file.
1
17 #include "nilorea.h"
18
19
20 int create_list_of_user( N_USER *list , int max ){
21
22 int IT=0;
23
24 Malloc( list -> list , N_USER_BOX , max );
25
26 if( !list -> list )
27 return FALSE;
28
29 list -> max = max ;
30 list -> highter = 0;
31
32 for( IT = 0;IT < max ;IT ++)
33 {
34 list-> list[IT].state=0 ;
35 list-> list[IT].netw = NULL;
36 }
37
38 /*
39 * CONFIGURATION
40 */
41 pthread_mutex_init( &list -> user_bolt , NULL );
42
43 return TRUE;
44
45 }
46
47
48
49 int add_user( N_USER *list ){
50
51 int it = -1;
52
53 pthread_mutex_lock( &list -> user_bolt );
54
55 do{
56
57 it++;
58
59 }while( list -> list[ it ] . state != 0);
60
61 list -> list[ it ] . state = 1;
62
63 if( it > list -> highter ) list -> highter = it;
64
65 pthread_mutex_unlock( &list -> user_bolt );
66
67 return it;
68
69 }
70
71
72
73 int rem_user( N_USER *list ,int id ){
74
75 pthread_mutex_lock( &list -> user_bolt );
76
77 if( list -> list[ id ] . state == 0 )
78 return FALSE;
79
80 if( list -> list[ id ] . netw )
81 Close_Network( &list -> list[ id ] . netw );
82
83 list -> list[ id ] . state = 0;
84
85 if( id == list -> highter ) list -> highter --;
86
87 pthread_mutex_unlock( &list -> user_bolt );
88
89 return TRUE;
90
91 }
92
93
94
95 int add_msg_to_all( N_USER *list , N_STR *msg ){
96
97 int it;
98
99 pthread_mutex_lock( &list -> user_bolt );
100
101 for( it = 0 ; it < list -> max ; it ++ ){
102
103 if( list -> list[ it ] . state != 0 )
104 {
105 Add_Msg( list -> list[ it ] . netw , n_strdup( msg ) );
106 }
107 }
108
109 pthread_mutex_unlock( &list -> user_bolt );
110
111 return TRUE;
112
113 }
114
115
116
117 int add_msg_to_user( N_USER *list , int id , N_STR *msg ){
118
119 pthread_mutex_lock( &list -> user_bolt );
120
121 if( list -> list[ id ] . state != 0 )
122 Add_Msg( list -> list[ id ] . netw , msg );
123
124 pthread_mutex_unlock( &list -> user_bolt );
125
126 return TRUE;
127
128 }