project_files/frontlib/net/netprotocol.c
changeset 7338 1ed603a54ebd
parent 7320 e704706008d4
child 7482 d70a5b0d1190
equal deleted inserted replaced
7336:f821f7d727b7 7338:1ed603a54ebd
   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 }