project_files/frontlib/net/netconn_send.c
changeset 7275 15f722e0b96f
parent 7271 5608ac657362
child 7314 6171f0bad318
equal deleted inserted replaced
7273:8eed495fd8da 7275:15f722e0b96f
     8 
     8 
     9 #include <stdlib.h>
     9 #include <stdlib.h>
    10 #include <string.h>
    10 #include <string.h>
    11 #include <zlib.h>
    11 #include <zlib.h>
    12 
    12 
    13 // TODO state changes
       
    14 
       
    15 // cmdname is always given as literal from functions in this file, so it is never null.
    13 // cmdname is always given as literal from functions in this file, so it is never null.
    16 static int sendVoid(flib_netconn *conn, const char *cmdname) {
    14 static int sendVoid(flib_netconn *conn, const char *cmdname) {
    17 	if(!conn) {
    15 	if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) {
    18 		flib_log_e("null parameter trying to send %s command.", cmdname);
       
    19 		return -1;
    16 		return -1;
    20 	}
    17 	}
    21 	return flib_netbase_sendf(conn->netBase, "%s\n\n", cmdname);
    18 	return flib_netbase_sendf(conn->netBase, "%s\n\n", cmdname);
    22 }
    19 }
    23 
    20 
       
    21 // Testing for !*str prevents sending 0-length parameters (they trip up the protocol)
    24 static int sendStr(flib_netconn *conn, const char *cmdname, const char *str) {
    22 static int sendStr(flib_netconn *conn, const char *cmdname, const char *str) {
    25 	if(!conn || !str) {
    23 	if(log_e_if(!conn || !str || !*str, "Invalid parameter sending %s command", cmdname)) {
    26 		flib_log_e("null parameter trying to send %s command.", cmdname);
       
    27 		return -1;
    24 		return -1;
    28 	}
    25 	}
    29 	return flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", cmdname, str);
    26 	return flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", cmdname, str);
    30 }
    27 }
    31 
    28 
    32 static int sendInt(flib_netconn *conn, const char *cmdname, int param) {
    29 static int sendInt(flib_netconn *conn, const char *cmdname, int param) {
    33 	if(!conn) {
    30 	if(log_e_if(!conn, "Invalid parameter sending %s command", cmdname)) {
    34 		flib_log_e("null parameter trying to send %s command.", cmdname);
       
    35 		return -1;
    31 		return -1;
    36 	}
    32 	}
    37 	return flib_netbase_sendf(conn->netBase, "%s\n%i\n\n", cmdname, param);
    33 	return flib_netbase_sendf(conn->netBase, "%s\n%i\n\n", cmdname, param);
    38 }
    34 }
    39 
    35 
    40 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg) {
    36 int flib_netconn_send_quit(flib_netconn *conn, const char *quitmsg) {
    41 	return sendStr(conn, "QUIT", quitmsg ? quitmsg : "User quit");
    37 	return sendStr(conn, "QUIT", (quitmsg && *quitmsg) ? quitmsg : "User quit");
    42 }
    38 }
    43 
    39 
    44 int flib_netconn_send_chat(flib_netconn *conn, const char *chat) {
    40 int flib_netconn_send_chat(flib_netconn *conn, const char *chat) {
    45 	return sendStr(conn, "CHAT", chat);
    41 	if(chat && *chat) {
       
    42 		return sendStr(conn, "CHAT", chat);
       
    43 	}
       
    44 	return 0;
    46 }
    45 }
    47 
    46 
    48 int flib_netconn_send_teamchat(flib_netconn *conn, const char *chat) {
    47 int flib_netconn_send_teamchat(flib_netconn *conn, const char *chat) {
    49 	return sendStr(conn, "TEAMCHAT", chat);
    48 	if(chat && *chat) {
       
    49 		return sendStr(conn, "TEAMCHAT", chat);
       
    50 	}
       
    51 	return 0;
    50 }
    52 }
    51 
    53 
    52 int flib_netconn_send_nick(flib_netconn *conn, const char *nick) {
    54 int flib_netconn_send_nick(flib_netconn *conn, const char *nick) {
    53 	int result = -1;
    55 	int result = -1;
    54 	if(!conn || !nick) {
    56 	if(!log_badparams_if(!conn || !nick || !*nick)) {
    55 		flib_log_e("null parameter in flib_netconn_send_nick");
       
    56 	} else {
       
    57 		char *tmpName = flib_strdupnull(nick);
    57 		char *tmpName = flib_strdupnull(nick);
    58 		if(tmpName) {
    58 		if(tmpName) {
    59 			if(!flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "NICK", nick)) {
    59 			if(!flib_netbase_sendf(conn->netBase, "%s\n%s\n\n", "NICK", nick)) {
    60 				free(conn->playerName);
    60 				free(conn->playerName);
    61 				conn->playerName = tmpName;
    61 				conn->playerName = tmpName;
    68 	return result;
    68 	return result;
    69 }
    69 }
    70 
    70 
    71 int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd) {
    71 int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd) {
    72 	int result = -1;
    72 	int result = -1;
    73 	if(!conn || !latin1Passwd) {
    73 	if(!log_badparams_if(!conn || !latin1Passwd)) {
    74 		flib_log_e("null parameter in flib_netconn_send_password");
       
    75 	} else {
       
    76 		md5_state_t md5state;
    74 		md5_state_t md5state;
    77 		uint8_t md5bytes[16];
    75 		uint8_t md5bytes[16];
    78 		char md5hex[33];
    76 		char md5hex[33];
    79 		md5_init(&md5state);
    77 		md5_init(&md5state);
    80 		md5_append(&md5state, (unsigned char*)latin1Passwd, strlen(latin1Passwd));
    78 		md5_append(&md5state, (unsigned char*)latin1Passwd, strlen(latin1Passwd));
    87 	}
    85 	}
    88 	return result;
    86 	return result;
    89 }
    87 }
    90 
    88 
    91 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room) {
    89 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room) {
    92 	return sendStr(conn, "JOIN_ROOM", room);
    90 	if(!sendStr(conn, "JOIN_ROOM", room)) {
       
    91 		conn->isChief = false;
       
    92 		return 0;
       
    93 	}
       
    94 	return -1;
    93 }
    95 }
    94 
    96 
    95 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room) {
    97 int flib_netconn_send_createRoom(flib_netconn *conn, const char *room) {
    96 	return sendStr(conn, "CREATE_ROOM", room);
    98 	if(!sendStr(conn, "CREATE_ROOM", room)) {
       
    99 		conn->isChief = true;
       
   100 		return 0;
       
   101 	}
       
   102 	return -1;
    97 }
   103 }
    98 
   104 
    99 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
   105 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
   100 	return sendStr(conn, "ROOM_NAME", roomName);
   106 	return sendStr(conn, "ROOM_NAME", roomName);
   101 }
   107 }
   102 
   108 
   103 int flib_netconn_send_leaveRoom(flib_netconn *conn) {
   109 int flib_netconn_send_leaveRoom(flib_netconn *conn) {
   104 	return sendVoid(conn, "PART");
   110 	if(flib_netconn_is_in_room_context(conn) && !sendVoid(conn, "PART")) {
       
   111 		netconn_leaveRoom(conn);
       
   112 		return 0;
       
   113 	}
       
   114 	return -1;
   105 }
   115 }
   106 
   116 
   107 int flib_netconn_send_toggleReady(flib_netconn *conn) {
   117 int flib_netconn_send_toggleReady(flib_netconn *conn) {
   108 	return sendVoid(conn, "TOGGLE_READY");
   118 	return sendVoid(conn, "TOGGLE_READY");
   109 }
   119 }
   110 
   120 
       
   121 static void addTeamToPendingList(flib_netconn *conn, const flib_team *team) {
       
   122 	flib_team *teamcopy = flib_team_copy(team);
       
   123 	if(teamcopy) {
       
   124 		teamcopy->remoteDriven = false;
       
   125 		free(teamcopy->ownerName);
       
   126 		teamcopy->ownerName = flib_strdupnull(conn->playerName);
       
   127 		if(teamcopy->ownerName) {
       
   128 			flib_teamlist_delete(&conn->pendingTeamlist, team->name);
       
   129 			flib_teamlist_insert(&conn->pendingTeamlist, teamcopy, 0);
       
   130 		}
       
   131 	}
       
   132 	flib_team_release(teamcopy);
       
   133 }
       
   134 
   111 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team) {
   135 int flib_netconn_send_addTeam(flib_netconn *conn, const flib_team *team) {
   112 	int result = -1;
   136 	int result = -1;
   113 	if(!conn || !team) {
   137 	if(!log_badparams_if(!conn || !team)) {
   114 		flib_log_e("null parameter in flib_netconn_send_addTeam");
   138 		bool missingInfo = !team->name || !team->grave || !team->fort || !team->voicepack || !team->flag;
   115 	} else {
       
   116 		bool missingInfo = !team->name || !team->color || !team->grave || !team->fort || !team->voicepack || !team->flag;
       
   117 		for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
   139 		for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
   118 			missingInfo |= !team->hogs[i].name || !team->hogs[i].hat;
   140 			missingInfo |= !team->hogs[i].name || !team->hogs[i].hat;
   119 		}
   141 		}
   120 		if(missingInfo) {
   142 		if(!log_e_if(missingInfo, "Incomplete team definition")) {
   121 			flib_log_e("Incomplete team definition for flib_netconn_send_addTeam");
       
   122 		} else {
       
   123 			flib_vector *vec = flib_vector_create();
   143 			flib_vector *vec = flib_vector_create();
   124 			if(vec) {
   144 			if(vec) {
   125 				bool error = false;
   145 				bool error = false;
   126 				error |= flib_vector_appendf(vec, "ADD_TEAM\n%s\n%lu\n%s\n%s\n%s\n%s\n%i\n", team->name, (unsigned long)team->color, team->grave, team->fort, team->voicepack, team->flag, team->hogs[0].difficulty);
   146 				error |= flib_vector_appendf(vec, "ADD_TEAM\n%s\n%i\n%s\n%s\n%s\n%s\n%i\n", team->name, team->colorIndex, team->grave, team->fort, team->voicepack, team->flag, team->hogs[0].difficulty);
   127 				for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
   147 				for(int i=0; i<HEDGEHOGS_PER_TEAM; i++) {
   128 					error |= flib_vector_appendf(vec, "%s\n%s\n", team->hogs[i].name, team->hogs[i].hat);
   148 					error |= flib_vector_appendf(vec, "%s\n%s\n", team->hogs[i].name, team->hogs[i].hat);
   129 				}
   149 				}
   130 				error |= flib_vector_appendf(vec, "\n");
   150 				error |= flib_vector_appendf(vec, "\n");
   131 				if(!error) {
   151 				if(!error && !flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec))) {
   132 					result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec));
   152 					addTeamToPendingList(conn, team);
       
   153 					result = 0;
   133 				}
   154 				}
   134 			}
   155 			}
   135 			flib_vector_destroy(vec);
   156 			flib_vector_destroy(vec);
   136 		}
   157 		}
   137 	}
   158 	}
   138 	return result;
   159 	return result;
   139 }
   160 }
   140 
   161 
   141 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) {
   162 int flib_netconn_send_removeTeam(flib_netconn *conn, const char *teamname) {
   142 	return sendStr(conn, "REMOVE_TEAM", teamname);
   163 	if(!sendStr(conn, "REMOVE_TEAM", teamname)) {
       
   164 		flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
       
   165 		if(team && !team->remoteDriven) {
       
   166 			flib_teamlist_delete(&conn->teamlist, teamname);
       
   167 		}
       
   168 		return 0;
       
   169 	}
       
   170 	return -1;
   143 }
   171 }
   144 
   172 
   145 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size) {
   173 int flib_netconn_send_engineMessage(flib_netconn *conn, const uint8_t *message, size_t size) {
   146 	int result = -1;
   174 	int result = -1;
   147 	if(!conn || (!message && size>0)) {
   175 	if(!log_badparams_if(!conn || (!message && size>0))) {
   148 		flib_log_e("null parameter in flib_netconn_send_engineMessage");
       
   149 	} else {
       
   150 		char *base64encout = NULL;
   176 		char *base64encout = NULL;
   151 		base64_encode_alloc((const char*)message, size, &base64encout);
   177 		base64_encode_alloc((const char*)message, size, &base64encout);
   152 		if(base64encout) {
   178 		if(base64encout) {
   153 			result = flib_netbase_sendf(conn->netBase, "EM\n%s\n\n", base64encout);
   179 			result = flib_netbase_sendf(conn->netBase, "EM\n%s\n\n", base64encout);
   154 		}
   180 		}
   156 	}
   182 	}
   157 	return result;
   183 	return result;
   158 }
   184 }
   159 
   185 
   160 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) {
   186 int flib_netconn_send_teamHogCount(flib_netconn *conn, const char *teamname, int hogcount) {
   161 	if(!conn || !teamname || hogcount<1 || hogcount>HEDGEHOGS_PER_TEAM) {
   187 	if(!log_badparams_if(!conn || !teamname || hogcount<1 || hogcount>HEDGEHOGS_PER_TEAM)
   162 		flib_log_e("invalid parameter in flib_netconn_send_teamHogCount");
   188 			&& !flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount)) {
   163 		return -1;
   189 		if(conn->isChief) {
   164 	}
   190 			flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
   165 	return flib_netbase_sendf(conn->netBase, "HH_NUM\n%s\n%i\n\n", teamname, hogcount);
   191 			if(team) {
   166 }
   192 				team->hogsInGame = hogcount;
   167 
   193 			}
   168 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, uint32_t colorRGB) {
   194 		}
   169 	if(!conn || !teamname) {
   195 		return 0;
   170 		flib_log_e("null parameter in flib_netconn_send_teamColor");
   196 	}
   171 		return -1;
   197 	return -1;
   172 	}
   198 }
   173 	return flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%lu\n\n", teamname, (unsigned long)colorRGB);
   199 
       
   200 int flib_netconn_send_teamColor(flib_netconn *conn, const char *teamname, int colorIndex) {
       
   201 	if(!log_badparams_if(!conn || !teamname)
       
   202 			&& !flib_netbase_sendf(conn->netBase, "TEAM_COLOR\n%s\n%i\n\n", teamname, colorIndex)) {
       
   203 		if(conn->isChief) {
       
   204 			flib_team *team = flib_teamlist_find(&conn->teamlist, teamname);
       
   205 			if(team) {
       
   206 				team->colorIndex = colorIndex;
       
   207 			}
       
   208 		}
       
   209 		return 0;
       
   210 	}
       
   211 	return -1;
   174 }
   212 }
   175 
   213 
   176 int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset) {
   214 int flib_netconn_send_weaponset(flib_netconn *conn, const flib_weaponset *weaponset) {
   177 	if(!conn || !weaponset) {
   215 	if(!log_badparams_if(!conn || !weaponset)) {
   178 		flib_log_e("null parameter in flib_netconn_send_weaponset");
   216 		char ammostring[WEAPONS_COUNT*4+1];
   179 		return -1;
   217 		strcpy(ammostring, weaponset->loadout);
   180 	}
   218 		strcat(ammostring, weaponset->crateprob);
   181 
   219 		strcat(ammostring, weaponset->delay);
   182 	char ammostring[WEAPONS_COUNT*4+1];
   220 		strcat(ammostring, weaponset->crateammo);
   183 	strcpy(ammostring, weaponset->loadout);
   221 		if(!flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring)) {
   184 	strcat(ammostring, weaponset->crateprob);
   222 			if(conn->isChief) {
   185 	strcat(ammostring, weaponset->delay);
   223 				netconn_setWeaponset(conn, weaponset);
   186 	strcat(ammostring, weaponset->crateammo);
   224 			}
   187 	return flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring);
   225 			return 0;
       
   226 		}
       
   227 	}
       
   228 	return -1;
   188 }
   229 }
   189 
   230 
   190 int flib_netconn_send_map(flib_netconn *conn, const flib_map *map) {
   231 int flib_netconn_send_map(flib_netconn *conn, const flib_map *map) {
   191 	if(!conn || !map) {
   232 	if(log_badparams_if(!conn || !map)) {
   192 		flib_log_e("null parameter in flib_netconn_send_map");
       
   193 		return -1;
   233 		return -1;
   194 	}
   234 	}
   195 	bool error = false;
   235 	bool error = false;
   196 
   236 
   197 	if(map->seed) {
   237 	if(map->seed) {
   211 	}
   251 	}
   212 	return error;
   252 	return error;
   213 }
   253 }
   214 
   254 
   215 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) {
   255 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) {
   216 	return sendStr(conn, "CFG\nMAP", mapName);
   256 	if(!sendStr(conn, "CFG\nMAP", mapName)) {
       
   257 		if(conn->isChief) {
       
   258 			char *copy = flib_strdupnull(mapName);
       
   259 			if(copy) {
       
   260 				free(conn->map->name);
       
   261 				conn->map->name = copy;
       
   262 			}
       
   263 		}
       
   264 		return 0;
       
   265 	}
       
   266 	return -1;
   217 }
   267 }
   218 
   268 
   219 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) {
   269 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) {
   220 	return sendInt(conn, "CFG\nMAPGEN", mapGen);
   270 	if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) {
       
   271 		if(conn->isChief) {
       
   272 			conn->map->mapgen = mapGen;
       
   273 		}
       
   274 		return 0;
       
   275 	}
       
   276 	return -1;
   221 }
   277 }
   222 
   278 
   223 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) {
   279 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) {
   224 	return sendInt(conn, "CFG\nTEMPLATE", templateFilter);
   280 	if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) {
       
   281 		if(conn->isChief) {
       
   282 			conn->map->templateFilter = templateFilter;
       
   283 		}
       
   284 		return 0;
       
   285 	}
       
   286 	return -1;
   225 }
   287 }
   226 
   288 
   227 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) {
   289 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) {
   228 	return sendInt(conn, "CFG\nMAZE_SIZE", mazeSize);
   290 	if(!sendInt(conn, "CFG\nMAZE_SIZE", mazeSize)) {
       
   291 		if(conn->isChief) {
       
   292 			conn->map->mazeSize = mazeSize;
       
   293 		}
       
   294 		return 0;
       
   295 	}
       
   296 	return -1;
   229 }
   297 }
   230 
   298 
   231 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) {
   299 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) {
   232 	return sendStr(conn, "CFG\nSEED", seed);
   300 	if(!sendStr(conn, "CFG\nSEED", seed)) {
       
   301 		if(conn->isChief) {
       
   302 			char *copy = flib_strdupnull(seed);
       
   303 			if(copy) {
       
   304 				free(conn->map->seed);
       
   305 				conn->map->seed = copy;
       
   306 			}
       
   307 		}
       
   308 		return 0;
       
   309 	}
       
   310 	return -1;
   233 }
   311 }
   234 
   312 
   235 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) {
   313 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) {
   236 	return sendStr(conn, "CFG\nTHEME", theme);
   314 	if(!sendStr(conn, "CFG\nTHEME", theme)) {
       
   315 		if(conn->isChief) {
       
   316 			char *copy = flib_strdupnull(theme);
       
   317 			if(copy) {
       
   318 				free(conn->map->theme);
       
   319 				conn->map->theme = copy;
       
   320 			}
       
   321 		}
       
   322 		return 0;
       
   323 	}
       
   324 	return -1;
   237 }
   325 }
   238 
   326 
   239 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) {
   327 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) {
   240 	int result = -1;
   328 	int result = -1;
   241 	if(!conn || (!drawData && size>0) || size>SIZE_MAX/2) {
   329 	if(!log_badparams_if(!conn || (!drawData && size>0) || size>SIZE_MAX/2)) {
   242 		flib_log_e("invalid parameter in flib_netconn_send_map");
       
   243 	} else {
       
   244 		uLongf zippedSize = compressBound(size);
   330 		uLongf zippedSize = compressBound(size);
   245 		uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header
   331 		uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header
   246 		if(zipped) {
   332 		if(zipped) {
   247 			// Create the QCompress size header (uint32 big endian)
   333 			// Create the QCompress size header (uint32 big endian)
   248 			zipped[0] = (size>>24) & 0xff;
   334 			zipped[0] = (size>>24) & 0xff;
   263 				free(base64encout);
   349 				free(base64encout);
   264 			}
   350 			}
   265 		}
   351 		}
   266 		free(zipped);
   352 		free(zipped);
   267 	}
   353 	}
       
   354 
       
   355 	if(!result && conn->isChief) {
       
   356 		uint8_t *copy = flib_bufdupnull(drawData, size);
       
   357 		if(copy) {
       
   358 			free(conn->map->drawData);
       
   359 			conn->map->drawData = copy;
       
   360 			conn->map->drawDataSize = size;
       
   361 		}
       
   362 	}
   268 	return result;
   363 	return result;
   269 }
   364 }
   270 
   365 
   271 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) {
   366 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) {
   272 	return sendStr(conn, "CFG\nSCRIPT", scriptName);
   367 	if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) {
       
   368 		if(conn->isChief) {
       
   369 			netconn_setScript(conn, scriptName);
       
   370 		}
       
   371 		return 0;
       
   372 	}
       
   373 	return -1;
   273 }
   374 }
   274 
   375 
   275 int flib_netconn_send_scheme(flib_netconn *conn, const flib_cfg *scheme) {
   376 int flib_netconn_send_scheme(flib_netconn *conn, const flib_cfg *scheme) {
   276 	int result = -1;
   377 	int result = -1;
   277 	if(!conn || !scheme) {
   378 	if(!log_badparams_if(!conn || !scheme)) {
   278 		flib_log_e("null parameter in flib_netconn_send_scheme");
       
   279 	} else {
       
   280 		flib_vector *vec = flib_vector_create();
   379 		flib_vector *vec = flib_vector_create();
   281 		if(vec) {
   380 		if(vec) {
   282 			bool error = false;
   381 			bool error = false;
   283 			error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name);
   382 			error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name);
   284 			for(int i=0; i<scheme->meta->modCount; i++) {
   383 			for(int i=0; i<scheme->meta->modCount; i++) {
   292 				result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec));
   391 				result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec));
   293 			}
   392 			}
   294 		}
   393 		}
   295 		flib_vector_destroy(vec);
   394 		flib_vector_destroy(vec);
   296 	}
   395 	}
       
   396 
       
   397 	if(!result && conn->isChief) {
       
   398 		netconn_setScheme(conn, scheme);
       
   399 	}
   297 	return result;
   400 	return result;
   298 }
   401 }
   299 
   402 
   300 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) {
   403 int flib_netconn_send_roundfinished(flib_netconn *conn, bool withoutError) {
   301 	return sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0);
   404 	if(!sendInt(conn, "ROUNDFINISHED", withoutError ? 1 : 0)) {
       
   405 		if(conn->netconnState == NETCONN_STATE_INGAME) {
       
   406 			conn->netconnState = NETCONN_STATE_ROOM;
       
   407 		}
       
   408 		return 0;
       
   409 	}
       
   410 	return -1;
   302 }
   411 }
   303 
   412 
   304 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) {
   413 int flib_netconn_send_ban(flib_netconn *conn, const char *playerName) {
   305 	return sendStr(conn, "BAN", playerName);
   414 	return sendStr(conn, "BAN", playerName);
   306 }
   415 }
   332 int flib_netconn_send_clearAccountsCache(flib_netconn *conn) {
   441 int flib_netconn_send_clearAccountsCache(flib_netconn *conn) {
   333 	return sendVoid(conn, "CLEAR_ACCOUNTS_CACHE");
   442 	return sendVoid(conn, "CLEAR_ACCOUNTS_CACHE");
   334 }
   443 }
   335 
   444 
   336 int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value) {
   445 int flib_netconn_send_setServerVar(flib_netconn *conn, const char *name, const char *value) {
   337 	if(!conn || !name || !value) {
   446 	if(log_badparams_if(!conn || !name || !value)) {
   338 		flib_log_e("null parameter trying to send SET_SERVER_VAR command.");
       
   339 		return -1;
   447 		return -1;
   340 	}
   448 	}
   341 	return flib_netbase_sendf(conn->netBase, "%s\n%s\n%s\n\n", "SET_SERVER_VAR", name, value);
   449 	return flib_netbase_sendf(conn->netBase, "%s\n%s\n%s\n\n", "SET_SERVER_VAR", name, value);
   342 }
   450 }
   343 
   451