/**************************************************************** if the client is capable of 'wanting hack', then the server will send the client a filename in the packet_join_game_reply packet. this function creates the file with a suitably random string in it and then sends the string to the server. If the server can open and read the string, then the client is given hack access. *****************************************************************/ void send_client_wants_hack(const char *filename) { if (filename[0] != '\0') { struct packet_single_want_hack_req req; struct section_file *file; if (!is_safe_filename(filename)) { return; } /* get the full filename path */ interpret_tilde(challenge_fullname, sizeof(challenge_fullname), "~/.freeciv/"); make_dir(challenge_fullname); sz_strlcat(challenge_fullname, filename); /* generate an authentication token */ randomize_string(req.token, sizeof(req.token)); file = secfile_new(FALSE); secfile_insert_str(file, req.token, "challenge.token"); if (!secfile_save(file, challenge_fullname, 0, FZ_PLAIN)) { log_error("Couldn't write token to temporary file: %s", challenge_fullname); } secfile_destroy(file); /* tell the server what we put into the file */ send_packet_single_want_hack_req(&client.conn, &req); } }
/***************************************************************************** Save the game (a manual save is triggert). *****************************************************************************/ bool api_server_save(lua_State *L, const char *filename) { LUASCRIPT_CHECK_STATE(L, FALSE); /* Limit the allowed characters in the filename. */ if (filename != NULL && !is_safe_filename(filename)) { return FALSE; } save_game(filename, "User request (Lua)", FALSE); return TRUE; }