Permalink
Browse files

Download server-sent plugins as zip files and extract them, instead o…

…f just gml
  • Loading branch information...
1 parent 8fa30a0 commit a0d6a71ee12507cb0d23721c7e9ed600b9825eee @hikari-no-yume hikari-no-yume committed Mar 2, 2013
View
@@ -0,0 +1,29 @@
+ 7-Zip Command line version
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ License for use and distribution
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ 7-Zip Copyright (C) 1999-2010 Igor Pavlov.
+
+ 7za.exe is distributed under the GNU LGPL license
+
+ Notes:
+ You can use 7-Zip on any computer, including a computer in a commercial
+ organization. You don't need to register or pay for 7-Zip.
+
+
+ GNU LGPL information
+ --------------------
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You can receive a copy of the GNU Lesser General Public License from
+ http://www.gnu.org/
View
@@ -493,10 +493,14 @@ This game uses the Faucet Forwarding Extension, created by NAGN, which wraps lib
miniupnp is availible under the BSD license: see miniupnp.license for full license.
You can find more about Faucet Forwarding at its GitHub Page:
https://github.com/nagn/Faucet-Forwarding
+
+This game uses the 7-zip command line version, available under the LGPL, see 7zip.license for full license.
+You can find more information on it here: http://www.7-zip.org/
+
Readme Changelog
2/7/09 - fishmatt - cleaned everything up for 2.0
5/3/09 - mrfredman - updated things for 2.1
3/20/10 - technoviking - updated things for 2.2
3/16/11 - Psychopath - updated things for 2.3
3/31/11 - Medo - some more updating
-10/13/11 - Psychopath - updated things for 2.4
+10/13/11 - Psychopath - updated things for 2.4
View
@@ -1,6 +1,7 @@
gg2.gmk
gg2.gb1
gg2.exe
+/7za.exe
gg2.ini
gg2updater.gmk
gg2updater.gb1
@@ -9,4 +10,4 @@ gmksplit.exe
*.orig
Maps
Plugins
-Screenshots
+Screenshots
Binary file not shown.
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<include>
+ <filename>7za.exe</filename>
+ <filepath>D:\Projects\2011\Gang Garrison 2\server plugins 7zip\7za920\7za.exe</filepath>
+ <original>true</original>
+ <originalSize>587776</originalSize>
+ <hasContent>true</hasContent>
+ <exportTo>WORKING_DIRECTORY</exportTo>
+ <otherExportDirectory/>
+ <overwriteExisting>true</overwriteExisting>
+ <freeMemAfterExport>true</freeMemAfterExport>
+ <removeAtGameEnd>false</removeAtGameEnd>
+</include>
@@ -3,6 +3,8 @@
<resource name="game_init" type="RESOURCE"/>
<resource name="loadplugins" type="RESOURCE"/>
<resource name="loadserverplugins" type="RESOURCE"/>
+ <resource name="extractzip" type="RESOURCE"/>
+ <resource name="deletedir" type="RESOURCE"/>
<resource name="offloadSpawnPoints" type="RESOURCE"/>
<resource name="removePlayer" type="RESOURCE"/>
<resource name="ServerJoinUpdate" type="RESOURCE"/>
@@ -0,0 +1,4 @@
+// used by loadserverplugins(), uses cmd's built-in rmdir command
+// argument0 - directory path
+
+execute_program("cmd", '/C rmdir /S /Q "' + argument0 + '"', true);
@@ -0,0 +1,14 @@
+// used by loadserverplugins(), relies on 7za.exe Included File
+// argument0 - Zip filename
+// argument1 - Destination
+// argument2 - Overwrite
+
+var args;
+
+args = 'x "'+argument0+'" -o"'+argument1+'"';
+
+if (argument2) {
+ args = args + ' -aoa';
+}
+
+execute_program("7za.exe", args, true);
@@ -1,11 +1,13 @@
// loads plugins from ganggarrison.com asked for by server
// argument0 - comma separated plugin list
-var list, text, i, file, handle, tempfile, failed;
+var list, text, i, file, url, handle, tempdir, tempdirprefix, tempfile, failed;
failed = false;
list = ds_list_create();
text = argument0;
+tempdirprefix = "~tmp-";
+// split plugin list string
while (string_pos(",", text) != 0) {
ds_list_add(list, string_copy(text,0,string_pos(",",text)-1));
text = string_copy(text,string_pos(",",text)+1,string_length(text)-string_pos(",",text));
@@ -17,42 +19,77 @@ if (string_length(text) > 0) {
// Download plugins
for (i = 0; i < ds_list_size(list); i += 1) {
file = ds_list_find_value(list, i);
+
+ // we need a temporary file to download to
tempfile = working_directory + "\~" + file + ".tmp";
- handle = DM_CreateDownload(PLUGIN_SOURCE + file + ".gml", tempfile);
+ // construct the URL (http://ganggarrison.com/plugins/$PLUGINNAME$.zip)
+ url = PLUGIN_SOURCE + file + ".zip";
+
+ // let's make the download handle
+ handle = DM_CreateDownload(url, tempfile);
+
+ // download it
DM_StartDownload(handle);
while (DM_DownloadStatus(handle) != 3) {}
DM_StopDownload(handle);
DM_CloseDownload(handle);
+ // if the file doesn't exist, the download presumably failed
if (!file_exists(tempfile)) {
failed = true;
break;
+ } else {
+ // let's choose a temporary directory name
+ tempdir = working_directory + "\" + tempdirprefix + file;
+
+ // let's get 7-zip to extract the files
+ extractzip(tempfile, tempdir, true);
+
+ // if the directory doesn't exist, extracting presumably failed
+ if (!directory_exists(tempdir)) {
+ failed = true;
+ break;
+ }
}
}
+
if (!failed) {
// Execute plugins
for (i = 0; i < ds_list_size(list); i += 1) {
file = ds_list_find_value(list, i);
- tempfile = working_directory + "\~" + file + ".tmp";
+ tempdir = working_directory + "\" + tempdirprefix + file;
+
// Debugging facility, so we know *which* plugin caused compile/execute error
fp = file_text_open_write(working_directory + "\last_plugin.log");
file_text_write_string(fp, file);
file_text_close(fp);
- // Execute
- execute_file(tempfile);
+
+ // Execute plugin
+ execute_file(
+ // the plugin's main gml file must be in the root of the zip
+ // it is called plugin.gml
+ tempdir + "\plugin.gml",
+ // the plugin needs to know where it is
+ // so the temporary directory is passed as first argument
+ tempdir
+ );
}
}
-
-
// Clear up
file_delete(working_directory + "\last_plugin.log");
for (i = 0; i < ds_list_size(list); i += 1) {
file = ds_list_find_value(list, i);
+
+ // delete the download temporary file
tempfile = working_directory + "\~" + file + ".tmp";
file_delete(tempfile);
+
+ // delete the temporary plugin directory using rmdir
+ tempdir = working_directory + "\" + tempdirprefix + file;
+ deletedir(tempdir);
}
ds_list_destroy(list);

0 comments on commit a0d6a71

Please sign in to comment.