aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Objects
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Objects')
-rw-r--r--ShiftOS.Objects/ChatRoom.cs16
-rw-r--r--ShiftOS.Objects/EngineShiftnetSubscription.cs2
-rw-r--r--ShiftOS.Objects/Save.cs85
-rw-r--r--ShiftOS.Objects/ShiftOS.Objects.csproj3
-rw-r--r--ShiftOS.Objects/Shop.cs2
-rw-r--r--ShiftOS.Objects/UniteClient.cs236
-rw-r--r--ShiftOS.Objects/UserConfig.cs37
7 files changed, 376 insertions, 5 deletions
diff --git a/ShiftOS.Objects/ChatRoom.cs b/ShiftOS.Objects/ChatRoom.cs
new file mode 100644
index 0000000..e4c89ce
--- /dev/null
+++ b/ShiftOS.Objects/ChatRoom.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Objects
+{
+ public class ChatRoom
+ {
+ public string Id { get; set; }
+ public string Name { get; set; }
+
+ public List<ChatMessage> Messages { get; set; }
+ }
+}
diff --git a/ShiftOS.Objects/EngineShiftnetSubscription.cs b/ShiftOS.Objects/EngineShiftnetSubscription.cs
index 1296a98..c319f18 100644
--- a/ShiftOS.Objects/EngineShiftnetSubscription.cs
+++ b/ShiftOS.Objects/EngineShiftnetSubscription.cs
@@ -10,7 +10,7 @@ namespace ShiftOS.Objects
{
public string Name { get; set; }
public string Description { get; set; }
- public int CostPerMonth { get; set; }
+ public uint CostPerMonth { get; set; }
public int DownloadSpeed { get; set; }
public string Company { get; set; }
}
diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs
index 2a02bbc..7891a22 100644
--- a/ShiftOS.Objects/Save.cs
+++ b/ShiftOS.Objects/Save.cs
@@ -26,20 +26,94 @@ using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Threading;
namespace ShiftOS.Objects
{
//Better to store this stuff server-side so we can do some neat stuff with hacking...
public class Save
{
+ public bool MusicEnabled = true;
+ public bool SoundEnabled = true;
+ public int MusicVolume = 100;
[Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")]
public string Username { get; set; }
+ private List<Action> _setCpCallbacks = new List<Action>(); // everything in this list is called by Codepoints.set() and syncCp().
+ private ulong _cp = 0; // locally cached codepoints counter
+ private Object _cpLock = new Object(); // locked when modifying or reading the codepoints counter
+ private Object _webLock = new Object(); // locked when communicating with the server
+ private Timer _updTimer; // timer to start a new sync thread every 5 minutes
+
+ // Sync local Codepoints count with the server.
+ public void syncCp()
+ {
+ new Thread(() =>
+ {
+ lock (_cpLock)
+ {
+ lock (_webLock)
+ {
+ var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken);
+ _cp = uc.GetCodepoints();
+ }
+ }
+ foreach (Action a in _setCpCallbacks)
+ a();
+ }).Start();
+ }
+
+ // we have to write these wrapper functions so we can keep _setCpCallbacks private,
+ // so that it doesn't get serialised
+ public void addSetCpCallback(Action callback)
+ {
+ _setCpCallbacks.Add(callback);
+ }
+
+ public void removeSetCpCallback(Action callback)
+ {
+ _setCpCallbacks.Remove(callback);
+ }
+
+ public ulong Codepoints
+ {
+ get
+ {
+ if (_updTimer == null)
+ _updTimer = new Timer((o) => syncCp(), null, 0, 300000);
+ lock (_cpLock)
+ {
+ return _cp;
+ }
+ }
+ set
+ {
+ lock (_cpLock)
+ {
+ _cp = value;
+ new Thread(() =>
+ {
+ lock (_webLock)
+ {
+ try
+ {
+ var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken);
+ uc.SetCodepoints(value);
+ }
+ catch
+ { }
+ }
+ })
+ {
+ IsBackground = false
+ }.Start();
+ }
+ foreach (Action a in _setCpCallbacks)
+ a();
+ }
+ }
- public long Codepoints { get; set; }
public Dictionary<string, bool> Upgrades { get; set; }
public int StoryPosition { get; set; }
public string Language { get; set; }
@@ -99,6 +173,11 @@ namespace ShiftOS.Objects
}
public List<ClientSave> Users { get; set; }
+
+ /// <summary>
+ /// DO NOT MODIFY THIS. EVER. YOU WILL BREAK THE STORYLINE. Let the engine do it's job.
+ /// </summary>
+ public string PickupPoint { get; set; }
}
public class SettingsObject : DynamicObject
diff --git a/ShiftOS.Objects/ShiftOS.Objects.csproj b/ShiftOS.Objects/ShiftOS.Objects.csproj
index 7a19aeb..9ed8c3b 100644
--- a/ShiftOS.Objects/ShiftOS.Objects.csproj
+++ b/ShiftOS.Objects/ShiftOS.Objects.csproj
@@ -45,6 +45,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="ChatRoom.cs" />
<Compile Include="ClientSave.cs" />
<Compile Include="EngineShiftnetSubscription.cs" />
<Compile Include="Job.cs" />
@@ -56,8 +57,10 @@
<Compile Include="Save.cs" />
<Compile Include="ShiftFS.cs" />
<Compile Include="Shop.cs" />
+ <Compile Include="UniteClient.cs" />
<Compile Include="Unite\Download.cs" />
<Compile Include="Unite\ReleaseQuery.cs" />
+ <Compile Include="UserConfig.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/ShiftOS.Objects/Shop.cs b/ShiftOS.Objects/Shop.cs
index 65f5746..c603523 100644
--- a/ShiftOS.Objects/Shop.cs
+++ b/ShiftOS.Objects/Shop.cs
@@ -42,7 +42,7 @@ namespace ShiftOS.Objects
{
public string Name { get; set; }
public string Description { get; set; }
- public int Cost { get; set; }
+ public ulong Cost { get; set; }
public int FileType { get; set; }
public byte[] MUDFile { get; set; }
}
diff --git a/ShiftOS.Objects/UniteClient.cs b/ShiftOS.Objects/UniteClient.cs
new file mode 100644
index 0000000..ccd721b
--- /dev/null
+++ b/ShiftOS.Objects/UniteClient.cs
@@ -0,0 +1,236 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using ShiftOS.Objects;
+
+namespace ShiftOS.Unite
+{
+ public class UniteClient
+ {
+ /// <summary>
+ /// Gets a string represents the user token for this Unite Client.
+ /// </summary>
+ public string Token { get; private set; }
+
+ /// <summary>
+ /// Gets the base URL used in all API calls. Retrieved from the user's servers.json file.
+ /// </summary>
+ public string BaseURL
+ {
+ get
+ {
+ return UserConfig.Get().UniteUrl;
+ }
+ }
+
+ /// <summary>
+ /// Get the display name of a user.
+ /// </summary>
+ /// <param name="id">The user ID to look at.</param>
+ /// <returns></returns>
+ public string GetDisplayNameId(string id)
+ {
+ return MakeCall("/API/GetDisplayName/" + id);
+ }
+
+ /// <summary>
+ /// Get the Pong highscore stats for all users.
+ /// </summary>
+ /// <returns></returns>
+ public PongHighscoreModel GetPongHighscores()
+ {
+ return JsonConvert.DeserializeObject<PongHighscoreModel>(MakeCall("/API/GetPongHighscores"));
+ }
+
+ /// <summary>
+ /// Create a new instance of the <see cref="UniteClient"/> object.
+ /// </summary>
+ /// <param name="baseurl">Unused.</param>
+ /// <param name="usertoken">The user API token to use for this client (see http://getshiftos.ml/Manage and click "API" to see your tokens)</param>
+ public UniteClient(string baseurl, string usertoken)
+ {
+ //Handled by the servers.json file
+ //BaseURL = baseurl;
+ Token = usertoken;
+ }
+
+ /// <summary>
+ /// Make a call to the Unite API using the current user token and base URL.
+ /// </summary>
+ /// <param name="url">The path, relative to the base URL, to call.</param>
+ /// <returns>The server's response.</returns>
+ internal string MakeCall(string url)
+ {
+ var webrequest = WebRequest.Create(BaseURL + url);
+ webrequest.Headers.Add("Authentication: Token " + Token);
+ using (var response = webrequest.GetResponse())
+ {
+ using (var stream = response.GetResponseStream())
+ {
+ using (var reader = new System.IO.StreamReader(stream))
+ {
+ return reader.ReadToEnd();
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Get the Pong codepoint highscore for the current user.
+ /// </summary>
+ /// <returns>The amount of Codepoints returned by the server</returns>
+ public ulong GetPongCP()
+ {
+ return Convert.ToUInt64(MakeCall("/API/GetPongCP"));
+ }
+
+ /// <summary>
+ /// Get the pong highest level score for this user
+ /// </summary>
+ /// <returns>The highest level the user has reached.</returns>
+ public int GetPongLevel()
+ {
+ return Convert.ToInt32(MakeCall("/API/GetPongLevel"));
+ }
+
+ /// <summary>
+ /// Set the user's highest level record for Pong.
+ /// </summary>
+ /// <param name="value">The level to set the record to.</param>
+ public void SetPongLevel(int value)
+ {
+ MakeCall("/API/SetPongLevel/" + value.ToString());
+ }
+
+ /// <summary>
+ /// Set the pong Codepoints record for the user
+ /// </summary>
+ /// <param name="value">The amount of Codepoints to set the record to</param>
+ public void SetPongCP(ulong value)
+ {
+ MakeCall("/API/SetPongCP/" + value.ToString());
+ }
+
+ /// <summary>
+ /// Get the user's email address.
+ /// </summary>
+ /// <returns>The user's email address.</returns>
+ public string GetEmail()
+ {
+ return MakeCall("/API/GetEmail");
+ }
+
+ /// <summary>
+ /// Get the user's system name.
+ /// </summary>
+ /// <returns>The user's system name.</returns>
+ public string GetSysName()
+ {
+ return MakeCall("/API/GetSysName");
+ }
+
+ /// <summary>
+ /// Set the user's system name.
+ /// </summary>
+ /// <param name="value">The system name to set the record to.</param>
+ public void SetSysName(string value)
+ {
+ MakeCall("/API/SetSysName/" + value);
+ }
+
+ /// <summary>
+ /// Get the user's display name.
+ /// </summary>
+ /// <returns>The user's display name.</returns>
+ public string GetDisplayName()
+ {
+ return MakeCall("/API/GetDisplayName");
+ }
+
+ /// <summary>
+ /// Set the user's display name.
+ /// </summary>
+ /// <param name="value">The display name to set the user's account to.</param>
+ public void SetDisplayName(string value)
+ {
+ MakeCall("/API/SetDisplayName/" + value.ToString());
+ }
+
+ /// <summary>
+ /// Get the user's full name if they have set it in their profile.
+ /// </summary>
+ /// <returns>Empty string if the user hasn't set their fullname, else, a string representing their fullname.</returns>
+ public string GetFullName()
+ {
+ return MakeCall("/API/GetFullName");
+ }
+
+ /// <summary>
+ /// Set the user's fullname.
+ /// </summary>
+ /// <param name="value">The new fullname.</param>
+ public void SetFullName(string value)
+ {
+ MakeCall("/API/SetFullName/" + value.ToString());
+ }
+
+ /// <summary>
+ /// Get the user's codepoints.
+ /// </summary>
+ /// <returns>The amount of codepoints stored on the server for this user.</returns>
+ public ulong GetCodepoints()
+ {
+ return Convert.ToUInt64(MakeCall("/API/GetCodepoints"));
+ }
+
+ /// <summary>
+ /// Set the user's codepoints.
+ /// </summary>
+ /// <param name="value">The amount of codepoints to set the user's codepoints value to.</param>
+ public void SetCodepoints(ulong value)
+ {
+ MakeCall("/API/SetCodepoints/" + value.ToString());
+ }
+ }
+
+ /// <summary>
+ /// API data model for Unite pong highscores.
+ /// </summary>
+ public class PongHighscoreModel
+ {
+ /// <summary>
+ /// Amount of pages in this list.
+ /// </summary>
+ public int Pages { get; set; }
+
+ /// <summary>
+ /// An array representing the highscores found on the server.
+ /// </summary>
+ public PongHighscore[] Highscores { get; set; }
+ }
+
+ /// <summary>
+ /// API data model for a single Pong highscore.
+ /// </summary>
+ public class PongHighscore
+ {
+ /// <summary>
+ /// The user ID linked to this highscore.
+ /// </summary>
+ public string UserId { get; set; }
+
+ /// <summary>
+ /// The highscore's level record.
+ /// </summary>
+ public int Level { get; set; }
+
+ /// <summary>
+ /// The highscore's codepoint cashout record.
+ /// </summary>
+ public long CodepointsCashout { get; set; }
+ }
+}
diff --git a/ShiftOS.Objects/UserConfig.cs b/ShiftOS.Objects/UserConfig.cs
new file mode 100644
index 0000000..61d11b8
--- /dev/null
+++ b/ShiftOS.Objects/UserConfig.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+
+namespace ShiftOS.Objects
+{
+ public class UserConfig
+ {
+ public string UniteUrl { get; set; }
+ public string DigitalSocietyAddress { get; set; }
+ public int DigitalSocietyPort { get; set; }
+
+ public static UserConfig Get()
+ {
+ var conf = new UserConfig
+ {
+ UniteUrl = "http://getshiftos.ml",
+ DigitalSocietyAddress = "michaeltheshifter.me",
+ DigitalSocietyPort = 13370
+ };
+
+ if (!File.Exists("servers.json"))
+ {
+ File.WriteAllText("servers.json", JsonConvert.SerializeObject(conf, Formatting.Indented));
+ }
+ else
+ {
+ conf = JsonConvert.DeserializeObject<UserConfig>(File.ReadAllText("servers.json"));
+ }
+ return conf;
+ }
+ }
+}