Skip to content

Commit

Permalink
UpdateChecker: testing new web api
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed Jun 5, 2018
1 parent b3d30b9 commit 33f26d8
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 27 deletions.
124 changes: 97 additions & 27 deletions vMenuServer/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,128 @@ private async void CheckUpdates()
try
{
await Delay(500);

// create a UUID for this server to check versions and keep track of unique servers.
string UUID;
var existingUuid = LoadResourceFile(GetCurrentResourceName(), "uuid");
if (existingUuid != null && existingUuid != "")
{
UUID = existingUuid;
}
else
{
Guid uuid = Guid.NewGuid();
UUID = uuid.ToString();
SaveResourceFile(GetCurrentResourceName(), "uuid", UUID, UUID.Length);
}
// sets the UUID convar.
ExecuteCommand($"sets vMenuUUID {UUID.Substring(0, UUID.LastIndexOf('-'))}");


// Get a response from the specified url.
RequestResponse result = await r.Http("https://vespura.com/vMenu-version.json");
// TODO: create webserver api for proper version checking.
RequestResponse result = await r.Http($"https://vespura.com/vmenu/version?id={UUID}&version={MainServer.Version}");


Debug.WriteLine("\r\n[vMenu] Checking for updates.");

// If the result status = 200 (status code OK) then continue.
switch (result.status)
{
case System.Net.HttpStatusCode.OK:
// Get the results
var currentVersion = GetResourceMetadata(GetCurrentResourceName(), "version", 0);
dynamic output = JsonConvert.DeserializeObject<dynamic>(result.content);
string version = output["version"].ToString();
string date = output["date"].ToString();
string changes = output["changes"].ToString() ?? "N/A";

// Output the info.
Debug.WriteLine($"[vMenu] Current version: {currentVersion}");
Debug.WriteLine($"[vMenu] Latest version: {version}");
Debug.WriteLine($"[vMenu] Release Date: {date}");

// If up to date :)
if (currentVersion == version)
dynamic UpdateData = JsonConvert.DeserializeObject(result.content);
if ((bool)UpdateData["up_to_date"])
{
// yay up to date! :) Snail is happy.
Debug.WriteLine("\r\n[vMenu] You are currently using the latest version, good job!");
Debug.WriteLine("[vMenu] Your version of vMenu is up to date! Good job!");
}
// If not up to date :(
else
{
Debug.WriteLine("[vMenu] WARNING: Your version of vMenu is OUTDATED!");
Debug.WriteLine("[vMenu] WARNING: Your version: " + MainServer.Version);
Debug.WriteLine("[vMenu] WARNING: Latest version: " + UpdateData["latest_version"]);
Debug.WriteLine("[vMenu] WARNING: Release date: " + UpdateData["release_date"]);
Debug.WriteLine("[vMenu] WARNING: Changelog summary: " + UpdateData["update_message"]);
Debug.WriteLine("[vMenu] WARNING: Please update as soon as possible!");
Debug.WriteLine("[vMenu] WARNING: Download: https://github.com/tomgrobbe/vMenu/releases/");
Debug.WriteLine("\n");
MainServer.UpToDate = false;

// Snail is sad :(
Debug.WriteLine("\r\n[vMenu] You are NOT using the latest version. Please update to the latest version as soon as possible.");
Debug.WriteLine("[vMenu] Download the latest version here: https://github.com/tomgrobbe/vMenu/releases/ !");
Debug.WriteLine($"[vMenu] New in version {version}: \t{changes}\r\n");
}

break;
default:
Debug.WriteLine("[vMenu] An error occurred while checking for the latest version. Please try again in a few hours.");
Debug.Write($"[vMenu] Error details: {result.content}\n");
break;
}
}
// Awww an exception. RIP.
// Aw damn! An exception. :(
catch (Exception e)
{
Debug.WriteLine("\r\n\r\n[vMenu] An error occurred while checking for updates. If you require immediate assistance email: [email protected].");
Debug.WriteLine($"[vMenu] Error info: {e.Message.ToString()}\r\n\r\n");
Debug.Write($"[vMenu] Error info: {e.Message.ToString()}\r\n\r\n");
}
CheckedForUpdates = true;
}

//private async void CheckUpdates()
//{
// // Create a new request object.
// Request r = new Request();

// // Try to request a response.
// try
// {
// await Delay(500);
// // Get a response from the specified url.
// RequestResponse result = await r.Http("https://vespura.com/vMenu-version.json");
// // TODO: create webserver api for proper version checking.

// Debug.WriteLine("\r\n[vMenu] Checking for updates.");

// // If the result status = 200 (status code OK) then continue.
// switch (result.status)
// {
// case System.Net.HttpStatusCode.OK:
// // Get the results
// var currentVersion = GetResourceMetadata(GetCurrentResourceName(), "version", 0);
// dynamic output = JsonConvert.DeserializeObject<dynamic>(result.content);
// string version = output["version"].ToString();
// string date = output["date"].ToString();
// string changes = output["changes"].ToString() ?? "N/A";

// // Output the info.
// Debug.WriteLine($"[vMenu] Current version: {currentVersion}");
// Debug.WriteLine($"[vMenu] Latest version: {version}");
// Debug.WriteLine($"[vMenu] Release Date: {date}");

// // If up to date :)
// if (currentVersion == version)
// {
// // yay up to date! :) Snail is happy.
// Debug.WriteLine("\r\n[vMenu] You are currently using the latest version, good job!");
// }
// // If not up to date :(
// else
// {
// MainServer.UpToDate = false;

// // Snail is sad :(
// Debug.WriteLine("\r\n[vMenu] You are NOT using the latest version. Please update to the latest version as soon as possible.");
// Debug.WriteLine("[vMenu] Download the latest version here: https://github.com/tomgrobbe/vMenu/releases/ !");
// Debug.WriteLine($"[vMenu] New in version {version}: \t{changes}\r\n");
// }

// break;
// default:
// Debug.WriteLine("[vMenu] An error occurred while checking for the latest version. Please try again in a few hours.");
// break;
// }
// }
// // Awww an exception. RIP.
// catch (Exception e)
// {
// Debug.WriteLine("\r\n\r\n[vMenu] An error occurred while checking for updates. If you require immediate assistance email: [email protected].");
// Debug.WriteLine($"[vMenu] Error info: {e.Message.ToString()}\r\n\r\n");
// }
// CheckedForUpdates = true;
//}
}
}
3 changes: 3 additions & 0 deletions vMenuServer/config/permissions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,6 @@ add_ace builtin.everyone "vMenu.VoiceChat.Enable" allow
add_ace builtin.everyone "vMenu.VoiceChat.ShowSpeaker" allow

add_ace group.moderator "vMenu.VoiceChat.StaffChannel" allow # Restrict the voice chat staff channel to moderators and admins only

# needed for vMenu version checks, please do not remove.
add_ace resource.vMenu command.sets allow

0 comments on commit 33f26d8

Please sign in to comment.