138 flib_log_e("base64 decoding of drawn map failed."); |
138 flib_log_e("base64 decoding of drawn map failed."); |
139 } |
139 } |
140 free(base64decout); |
140 free(base64decout); |
141 return result; |
141 return result; |
142 } |
142 } |
|
143 |
|
144 flib_room *flib_room_from_netmsg(char **params) { |
|
145 flib_room *result = NULL; |
|
146 flib_room *tmpRoom = flib_calloc(1, sizeof(flib_room)); |
|
147 if(tmpRoom) { |
|
148 tmpRoom->inProgress = !strcmp(params[0], "True"); |
|
149 tmpRoom->name = flib_strdupnull(params[1]); |
|
150 tmpRoom->playerCount = atoi(params[2]); |
|
151 tmpRoom->teamCount = atoi(params[3]); |
|
152 tmpRoom->owner = flib_strdupnull(params[4]); |
|
153 tmpRoom->map = flib_strdupnull(params[5]); |
|
154 tmpRoom->scheme = flib_strdupnull(params[6]); |
|
155 tmpRoom->weapons = flib_strdupnull(params[7]); |
|
156 if(tmpRoom->name && tmpRoom->owner && tmpRoom->map && tmpRoom->scheme && tmpRoom->weapons) { |
|
157 result = tmpRoom; |
|
158 tmpRoom = NULL; |
|
159 } |
|
160 } |
|
161 flib_room_destroy(tmpRoom); |
|
162 return result; |
|
163 } |
|
164 |
|
165 int fillRoomArray(flib_room **array, char **params, int count) { |
|
166 for(int i=0; i<count; i++) { |
|
167 array[i] = flib_room_from_netmsg(params + 8*i); |
|
168 if(!array[i]) { |
|
169 return -1; |
|
170 } |
|
171 } |
|
172 return 0; |
|
173 } |
|
174 |
|
175 flib_room **flib_room_array_from_netmsg(char **params, int count) { |
|
176 flib_room **result = flib_calloc(count, sizeof(flib_room*)); |
|
177 if(result) { |
|
178 if(fillRoomArray(result, params, count)) { |
|
179 for(int i=0; i<count; i++) { |
|
180 flib_room_destroy(result[i]); |
|
181 } |
|
182 free(result); |
|
183 result = NULL; |
|
184 } |
|
185 } |
|
186 return result; |
|
187 } |