aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
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 /ShiftOS_TheReturn
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'
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/SaveSystem.cs2
-rw-r--r--ShiftOS_TheReturn/ServerManager.cs16
-rw-r--r--ShiftOS_TheReturn/UserManagementCommands.cs61
3 files changed, 77 insertions, 2 deletions
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;
+ }
}