aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAShifter <[email protected]>2017-05-05 10:16:29 -0600
committerAShifter <[email protected]>2017-05-05 10:16:29 -0600
commita7fff72826ba12a9a87ad4edf38526174e330acb (patch)
tree2afba9246adeca69cffc98b77eb4183f680c6165
parent13b35b32c2c429e6bd2d7b41ca43cc62f305dbc5 (diff)
parent9a2373ec42faeef719cff1c7076af87ef44179a7 (diff)
downloadshiftos_thereturn-a7fff72826ba12a9a87ad4edf38526174e330acb.tar.gz
shiftos_thereturn-a7fff72826ba12a9a87ad4edf38526174e330acb.tar.bz2
shiftos_thereturn-a7fff72826ba12a9a87ad4edf38526174e330acb.zip
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
-rw-r--r--ShiftOS.Objects/ShiftFS.cs37
-rw-r--r--ShiftOS.WinForms/Applications/Pong.cs245
-rw-r--r--ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs62
-rw-r--r--ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs51
-rw-r--r--ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx120
-rw-r--r--ShiftOS.WinForms/ShiftOS.WinForms.csproj9
-rw-r--r--ShiftOS_TheReturn/SaveSystem.cs2
-rw-r--r--ShiftOS_TheReturn/ServerManager.cs16
-rw-r--r--ShiftOS_TheReturn/UserManagementCommands.cs61
9 files changed, 494 insertions, 109 deletions
diff --git a/ShiftOS.Objects/ShiftFS.cs b/ShiftOS.Objects/ShiftFS.cs
index c2121f0..45cdb14 100644
--- a/ShiftOS.Objects/ShiftFS.cs
+++ b/ShiftOS.Objects/ShiftFS.cs
@@ -32,23 +32,16 @@ using System.Threading;
namespace ShiftOS.Objects.ShiftFS
{
- public enum Permissions
- {
- User,
- Administrator,
- Superuser,
- All
- }
public class File
{
public string Name;
public byte[] Data;
public byte[] HeaderData;
public bool ReadAccessToLowUsers;
- public Permissions permissions;
+ public UserPermissions permissions;
public System.IO.Stream GetStream()
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
return new System.IO.MemoryStream(Data);
}
@@ -59,7 +52,7 @@ namespace ShiftOS.Objects.ShiftFS
return null;
}
- public File(string name, byte[] data, bool ReadAccess_to_low_users, Permissions perm)
+ public File(string name, byte[] data, bool ReadAccess_to_low_users, UserPermissions perm)
{
Name = name;
Data = data;
@@ -73,31 +66,31 @@ namespace ShiftOS.Objects.ShiftFS
public List<File> Files = new List<File>();
public List<Directory> Subdirectories = new List<Directory>();
public bool ReadAccessToLowUsers;
- public Permissions permissions;
+ public UserPermissions permissions;
public void AddFile(File file)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
Files.Add(file);
}
}
public void RemoveFile(string name)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
Files.Remove(Files.Find(x => x.Name == name));
}
}
public void RemoveFile(File file)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
Files.Remove(file);
}
}
public File FindFileByName(string name)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
return Files.Find(x => x.Name == name);
}
@@ -105,28 +98,28 @@ namespace ShiftOS.Objects.ShiftFS
}
public void AddDirectory(Directory dir)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
Subdirectories.Add(dir);
}
}
public void RemoveDirectory(string name)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
Subdirectories.Remove(Subdirectories.Find(x => x.Name == name));
}
}
public void RemoveDirectory(Directory dir)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
Subdirectories.Remove(dir);
}
}
public Directory FindDirectoryByName(string name)
{
- if ((int)CurrentUser >= (int)permissions || permissions == Permissions.All)
+ if ((int)CurrentUser <= (int)permissions)
{
return Subdirectories.Find(x => x.Name == name);
}
@@ -136,7 +129,7 @@ namespace ShiftOS.Objects.ShiftFS
public static class Utils
{
- public static Permissions CurrentUser { get; set; }
+ public static UserPermissions CurrentUser { get; set; }
public static List<Directory> Mounts { get; set; }
@@ -232,7 +225,7 @@ namespace ShiftOS.Objects.ShiftFS
{
try
{
- dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, Permissions.All));
+ dir.AddFile(new File(pathlist[pathlist.Length - 1], Encoding.UTF8.GetBytes(contents), false, CurrentUser));
}
catch { }
}
@@ -281,7 +274,7 @@ namespace ShiftOS.Objects.ShiftFS
if (!FileExists(path))
{
- dir.AddFile(new File(pathlist[pathlist.Length - 1], contents, false, Permissions.All));
+ dir.AddFile(new File(pathlist[pathlist.Length - 1], contents, false, CurrentUser));
}
else
{
diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs
index 04c963f..d63f406 100644
--- a/ShiftOS.WinForms/Applications/Pong.cs
+++ b/ShiftOS.WinForms/Applications/Pong.cs
@@ -123,7 +123,7 @@ namespace ShiftOS.WinForms.Applications
int OpponentY = 0;
- bool IsLeader = false;
+ bool IsLeader = true;
int LeaderX = 0;
int LeaderY = 0;
@@ -368,75 +368,124 @@ namespace ShiftOS.WinForms.Applications
public void ServerMessageReceivedHandler(ServerMessage msg)
{
- if (msg.Name == "pong_mp_setballpos")
- {
- var pt = JsonConvert.DeserializeObject<Point>(msg.Contents);
- LeaderX = pt.X;
- LeaderY = pt.Y;
- }
- else if(msg.Name == "pong_mp_left")
+ if (IsMultiplayerSession)
{
- this.Invoke(new Action(() =>
+ if (msg.Name == "pong_mp_setballpos")
{
- AppearanceManager.Close(this);
- }));
- Infobox.Show("Opponent has closed Pong.", "The opponent has closed Pong, therefore the connection between you two has dropped.");
- }
- else if (msg.Name == "pong_mp_youlose")
- {
- this.Invoke(new Action(LoseMP));
- }
- else if (msg.Name == "pong_mp_setopponenty")
- {
- int y = Convert.ToInt32(msg.Contents);
- OpponentY = y;
- }
- else if (msg.Name == "pong_handshake_matchmake")
- {
- if (!PossibleMatchmakes.Contains(msg.Contents))
- PossibleMatchmakes.Add(msg.Contents);
- this.Invoke(new Action(ListMatchmakes));
- }
- else if (msg.Name == "pong_handshake_resendid")
- {
- ServerManager.Forward("all", "pong_handshake_matchmake", YouGUID);
- }
- else if (msg.Name == "pong_handshake_complete")
- {
- IsLeader = true;
+ var pt = JsonConvert.DeserializeObject<Point>(msg.Contents);
+ LeaderX = pt.X;
+ LeaderY = pt.Y;
+ }
+ else if (msg.Name == "pong_mp_left")
+ {
+ this.Invoke(new Action(() =>
+ {
+ AppearanceManager.Close(this);
+ }));
+ Infobox.Show("Opponent has closed Pong.", "The opponent has closed Pong, therefore the connection between you two has dropped.");
+ }
+ else if (msg.Name == "pong_mp_youlose")
+ {
+ this.Invoke(new Action(LoseMP));
+ }
+ else if (msg.Name == "pong_mp_setopponenty")
+ {
+ int y = Convert.ToInt32(msg.Contents);
+ OpponentY = y;
+ }
+ else if (msg.Name == "pong_handshake_matchmake")
+ {
+ if (!PossibleMatchmakes.Contains(msg.Contents))
+ PossibleMatchmakes.Add(msg.Contents);
+ this.Invoke(new Action(ListMatchmakes));
+ }
+ else if (msg.Name == "pong_handshake_resendid")
+ {
+ ServerManager.Forward("all", "pong_handshake_matchmake", YouGUID);
+ }
+ else if (msg.Name == "pong_handshake_complete")
+ {
+ IsLeader = true;
- OpponentGUID = msg.Contents;
- LeaveMatchmake();
- this.Invoke(new Action(() =>
+ OpponentGUID = msg.Contents;
+ LeaveMatchmake();
+ this.Invoke(new Action(() =>
+ {
+ pnlmultiplayerhandshake.Hide();
+ StartLevel();
+ }));
+ }
+ else if(msg.Name == "pong_mp_levelcompleted")
{
- pnlmultiplayerhandshake.Hide();
- StartLevel();
- }));
- }
- else if (msg.Name == "pong_handshake_chosen")
- {
- IsLeader = false;
- LeaveMatchmake();
- OpponentGUID = msg.Contents;
- YouGUID = ServerManager.thisGuid.ToString();
- SendFollowerGUID();
- this.Invoke(new Action(() =>
+ level = Convert.ToInt32(msg.Contents) + 1;
+ this.Invoke(new Action(CompleteLevel));
+ }
+ else if (msg.Name == "pong_handshake_chosen")
{
- pnlmultiplayerhandshake.Hide();
- }));
- }
- else if (msg.Name == "pong_handshake_left")
- {
- if (this.PossibleMatchmakes.Contains(msg.Contents))
- this.PossibleMatchmakes.Remove(msg.Contents);
- this.Invoke(new Action(ListMatchmakes));
- }
- else if (msg.Name == "pong_mp_youwin")
- {
- this.Invoke(new Action(Win));
+ IsLeader = false;
+ LeaveMatchmake();
+ OpponentGUID = msg.Contents;
+ YouGUID = ServerManager.thisGuid.ToString();
+ //Start the timers.
+ counter.Start();
+ SendFollowerGUID();
+ this.Invoke(new Action(() =>
+ {
+ pnlmultiplayerhandshake.Hide();
+ }));
+ }
+ else if(msg.Name == "pong_mp_cashedout")
+ {
+ this.Invoke(new Action(() =>
+ {
+ btncashout_Click(this, EventArgs.Empty);
+ }));
+ Infobox.Show("Cashed out.", "The other player has cashed out their Codepoints. Therefore, we have automatically cashed yours out.");
+ }
+ else if(msg.Name == "pong_mp_startlevel")
+ {
+ OpponentAgrees = true;
+ if(YouAgree == false)
+ {
+ Infobox.PromptYesNo("Play another level?", "The opponent wants to play another level. Would you like to as well?", (answer)=>
+ {
+ YouAgree = answer;
+ ServerManager.Forward(OpponentGUID, "pong_mp_level_callback", YouAgree.ToString());
+ });
+ }
+ }
+ else if(msg.Name == "pong_mp_level_callback")
+ {
+ bool agreed = bool.Parse(msg.Contents);
+ OpponentAgrees = agreed;
+ if (OpponentAgrees)
+ {
+ if (IsLeader)
+ {
+ //this.Invoke(new Action(()))
+ }
+ }
+ }
+ else if (msg.Name == "pong_handshake_left")
+ {
+ if (this.PossibleMatchmakes.Contains(msg.Contents))
+ this.PossibleMatchmakes.Remove(msg.Contents);
+ this.Invoke(new Action(ListMatchmakes));
+ }
+ else if(msg.Name == "pong_mp_clockupdate")
+ {
+ secondsleft = Convert.ToInt32(msg.Contents);
+ }
+ else if (msg.Name == "pong_mp_youwin")
+ {
+ this.Invoke(new Action(Win));
+ }
}
}
+ bool OpponentAgrees = false;
+ bool YouAgree = false;
+
public void ListMatchmakes()
{
lvotherplayers.Items.Clear();
@@ -543,37 +592,50 @@ namespace ShiftOS.WinForms.Applications
}
+ public void CompleteLevel()
+ {
+ if (SaveSystem.CurrentSave.UniteAuthToken != null)
+ {
+ try
+ {
+ var unite = new ShiftOS.Unite.UniteClient("http://getshiftos.ml", SaveSystem.CurrentSave.UniteAuthToken);
+ if (unite.GetPongLevel() < level)
+ unite.SetPongLevel(level);
+ }
+ catch { }
+ }
+ //Only set these stats if the user is the leader.
+ if (IsLeader)
+ {
+ secondsleft = 60;
+ level = level + 1;
+ generatenextlevel();
+ }
+
+ pnlgamestats.Show();
+ pnlgamestats.BringToFront();
+ pnlgamestats.Location = new Point((pgcontents.Width / 2) - (pnlgamestats.Width / 2), (pgcontents.Height / 2) - (pnlgamestats.Height / 2));
+
+ counter.Stop();
+ gameTimer.Stop();
+
+ }
+
// ERROR: Handles clauses are not supported in C#
private void counter_Tick(object sender, EventArgs e)
{
- if (this.Left < Screen.PrimaryScreen.Bounds.Width)
+ if (IsLeader)
{
- secondsleft = secondsleft - 1;
- if (secondsleft == 1)
+ if (this.Left < Screen.PrimaryScreen.Bounds.Width)
{
- secondsleft = 60;
- level = level + 1;
- if (SaveSystem.CurrentSave.UniteAuthToken != null)
+ secondsleft = secondsleft - 1;
+ if (secondsleft == 1)
{
- try
- {
- var unite = new ShiftOS.Unite.UniteClient("http://getshiftos.ml", SaveSystem.CurrentSave.UniteAuthToken);
- if (unite.GetPongLevel() < level)
- unite.SetPongLevel(level);
- }
- catch { }
+ CompleteLevel();
}
- generatenextlevel();
- pnlgamestats.Show();
- pnlgamestats.BringToFront();
- pnlgamestats.Location = new Point((pgcontents.Width / 2) - (pnlgamestats.Width / 2), (pgcontents.Height / 2) - (pnlgamestats.Height / 2));
-
- counter.Stop();
- gameTimer.Stop();
- SendHighscores();
- }
- lblstatscodepoints.Text = Localization.Parse("{CODEPOINTS}: ") + (levelrewards[level - 1] + beatairewardtotal).ToString();
+ lblstatscodepoints.Text = Localization.Parse("{CODEPOINTS}: ") + (levelrewards[level - 1] + beatairewardtotal).ToString();
+ }
}
SetupStats();
}
@@ -824,6 +886,19 @@ namespace ShiftOS.WinForms.Applications
unite.SetPongCP(totalreward);
}
}
+ if (IsMultiplayerSession)
+ {
+ ServerManager.Forward(OpponentGUID, "pong_mp_cashedout", null);
+ StopMultiplayerSession();
+ }
+ }
+
+ public void StopMultiplayerSession()
+ {
+ IsMultiplayerSession = false;
+ IsLeader = true;
+ OpponentGUID = "";
+ YouGUID = "";
}
private void newgame()
diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs
new file mode 100644
index 0000000..c6a7d83
--- /dev/null
+++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs
@@ -0,0 +1,62 @@
+namespace ShiftOS.WinForms.DesktopWidgets
+{
+ partial class HeartbeatWidget
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.lbheartbeat = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // lbheartbeat
+ //
+ this.lbheartbeat.AutoSize = true;
+ this.lbheartbeat.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.lbheartbeat.Location = new System.Drawing.Point(0, 0);
+ this.lbheartbeat.Name = "lbheartbeat";
+ this.lbheartbeat.Size = new System.Drawing.Size(35, 13);
+ this.lbheartbeat.TabIndex = 0;
+ this.lbheartbeat.Text = "label1";
+ //
+ // HeartbeatWidget
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.AutoSize = true;
+ this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
+ this.Controls.Add(this.lbheartbeat);
+ this.Name = "HeartbeatWidget";
+ this.Size = new System.Drawing.Size(35, 13);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Label lbheartbeat;
+ }
+}
diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs
new file mode 100644
index 0000000..d38cdc3
--- /dev/null
+++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using ShiftOS.WinForms.Tools;
+using ShiftOS.Engine;
+
+namespace ShiftOS.WinForms.DesktopWidgets
+{
+ [DesktopWidget("Server ping", "See the time spent between client requests and server replies in the digital society.")]
+ public partial class HeartbeatWidget : UserControl, IDesktopWidget
+ {
+ public HeartbeatWidget()
+ {
+ InitializeComponent();
+ tmr.Interval = 1;
+ tmr.Tick += (o, a) =>
+ {
+ if(ts != ServerManager.DigitalSocietyPing)
+ {
+ ts = ServerManager.DigitalSocietyPing;
+ lbheartbeat.Text = "Server ping: " + ts.ToString();
+ }
+ };
+ }
+
+ //Fun fact. I misspelled this as "TimeSpam."
+ TimeSpan ts;
+
+ public void OnSkinLoad()
+ {
+ ControlManager.SetupControls(this);
+ }
+
+ public void OnUpgrade()
+ {
+ }
+
+ Timer tmr = new Timer();
+
+ public void Setup()
+ {
+ tmr.Start();
+ }
+ }
+}
diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root> \ No newline at end of file
diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj
index 9fc237f..1607ae9 100644
--- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj
+++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj
@@ -298,6 +298,12 @@
<Compile Include="DesktopWidgets\CodepointsWidget.Designer.cs">
<DependentUpon>CodepointsWidget.cs</DependentUpon>
</Compile>
+ <Compile Include="DesktopWidgets\HeartbeatWidget.cs">
+ <SubType>UserControl</SubType>
+ </Compile>
+ <Compile Include="DesktopWidgets\HeartbeatWidget.Designer.cs">
+ <DependentUpon>HeartbeatWidget.cs</DependentUpon>
+ </Compile>
<Compile Include="DesktopWidgets\TerminalWidget.cs">
<SubType>UserControl</SubType>
</Compile>
@@ -502,6 +508,9 @@
<EmbeddedResource Include="DesktopWidgets\CodepointsWidget.resx">
<DependentUpon>CodepointsWidget.cs</DependentUpon>
</EmbeddedResource>
+ <EmbeddedResource Include="DesktopWidgets\HeartbeatWidget.resx">
+ <DependentUpon>HeartbeatWidget.cs</DependentUpon>
+ </EmbeddedResource>
<EmbeddedResource Include="DesktopWidgets\TerminalWidget.resx">
<DependentUpon>TerminalWidget.cs</DependentUpon>
</EmbeddedResource>
diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs
index c3289ea..f29e5b8 100644
--- a/ShiftOS_TheReturn/SaveSystem.cs
+++ b/ShiftOS_TheReturn/SaveSystem.cs
@@ -70,7 +70,7 @@ namespace ShiftOS.Engine
{
var root = new ShiftOS.Objects.ShiftFS.Directory();
root.Name = "System";
- root.permissions = Permissions.All;
+ root.permissions = UserPermissions.Guest;
System.IO.File.WriteAllText(Paths.SaveFile, JsonConvert.SerializeObject(root));
}
diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs
index 0bdfcd9..792b38d 100644
--- a/ShiftOS_TheReturn/ServerManager.cs
+++ b/ShiftOS_TheReturn/ServerManager.cs
@@ -35,6 +35,7 @@ using ShiftOS;
using static ShiftOS.Engine.SaveSystem;
using Newtonsoft.Json;
using System.Net.Sockets;
+using System.Diagnostics;
namespace ShiftOS.Engine
{
@@ -54,6 +55,12 @@ namespace ShiftOS.Engine
private static NetObjectClient client { get; set; }
private static bool UserDisconnect = false;
+ public static TimeSpan DigitalSocietyPing
+ {
+ get;
+ private set;
+ }
+
public static void Disconnect()
{
UserDisconnect = true;
@@ -139,6 +146,11 @@ namespace ShiftOS.Engine
};
client.OnReceived += (o, a) =>
{
+ if (PingTimer.IsRunning)
+ {
+ DigitalSocietyPing = PingTimer.Elapsed;
+ PingTimer.Reset();
+ }
var msg = a.Data.Object as ServerMessage;
if (msg.Name == "Welcome")
{
@@ -207,6 +219,8 @@ namespace ShiftOS.Engine
}
}
+ private static Stopwatch PingTimer = new Stopwatch();
+
public static void SendMessage(string name, string contents)
{
var sMsg = new ServerMessage
@@ -215,7 +229,7 @@ namespace ShiftOS.Engine
Contents = contents,
GUID = thisGuid.ToString(),
};
-
+ PingTimer.Start();
client.Send(new NetObject("msg", sMsg));
}
diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs
index 62735a3..1c3c0ed 100644
--- a/ShiftOS_TheReturn/UserManagementCommands.cs
+++ b/ShiftOS_TheReturn/UserManagementCommands.cs
@@ -53,7 +53,68 @@ namespace ShiftOS.Engine
return true;
}
+ [Command("set_acl")]
+ [RequiresArgument("user")]
+ [RequiresArgument("val")]
+ public static bool SetUserPermission(Dictionary<string, object> args)
+ {
+ int permission = 0;
+ string username = args["user"].ToString();
+ try
+ {
+ permission = Convert.ToInt32(args["val"].ToString());
+ }
+ catch
+ {
+ Console.WriteLine("Error: Permission value must be an integer.");
+ return true;
+ }
+
+ if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==username) == null)
+ {
+ Console.WriteLine("Error: User not found.");
+ return true;
+ }
+
+ UserPermissions uperm = UserPermissions.Guest;
+
+ switch (permission)
+ {
+ case 0:
+ uperm = UserPermissions.Guest;
+ break;
+ case 1:
+ uperm = UserPermissions.User;
+ break;
+ case 2:
+ uperm = UserPermissions.Admin;
+ break;
+ case 3:
+ uperm = UserPermissions.Root;
+ break;
+ default:
+ Console.WriteLine("Permission value must be between 0 and 4.");
+ return true;
+ }
+
+ //Permissions are backwards... oops...
+ if(uperm < SaveSystem.CurrentUser.Permissions)
+ {
+ Console.WriteLine("Error: Cannot set user permissions to values greater than your own!");
+ return true;
+ }
+ var oldperm = SaveSystem.Users.FirstOrDefault(x => x.Username == username).Permissions;
+ if (SaveSystem.CurrentUser.Permissions > oldperm)
+ {
+ Console.WriteLine("Error: Can't set the permission of this user. They have more rights than you.");
+ return true;
+ }
+
+ SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == username).Permissions = uperm;
+ Console.WriteLine("User permissions updated.");
+ return true;
+ }
}