blob: cc03f5a56ebeb6c167a9d6cc2b5bc7566c3d1fcf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static ShiftOS.Objects.ShiftFS.Utils;
namespace ShiftOS.Engine
{
public static class KernelWatchdog
{
public static void Log(string e, string desc)
{
string line = $"[{DateTime.Now}] <{e}> {desc}";
if (FileExists("0:/system/data/kernel.log"))
{
string contents = ReadAllText("0:/system/data/kernel.log");
contents += Environment.NewLine + line;
WriteAllText("0:/system/data/kernel.log", contents);
}
else
{
WriteAllText("0:/system/data/kernel.log", line);
}
}
private static bool _mudConnected = true;
public static bool InKernelMode { get; private set; }
public static bool MudConnected
{
get
{
return _mudConnected;
}
set
{
if(value == false)
{
foreach(var win in AppearanceManager.OpenForms)
{
foreach(var attr in win.ParentWindow.GetType().GetCustomAttributes(true))
{
if(attr is MultiplayerOnlyAttribute)
{
ConsoleEx.Bold = true;
ConsoleEx.Underline = false;
ConsoleEx.Italic = true;
ConsoleEx.ForegroundColor = ConsoleColor.Red;
Console.Write("Error:");
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Cannot disconnect from multi-user domain because an app that depends on it is open.");
TerminalBackend.PrintPrompt();
return;
}
}
}
}
_mudConnected = value;
Desktop.PopulateAppLauncher();
}
}
public static bool IsSafe(Type type)
{
if (InKernelMode == true)
return true;
foreach (var attrib in type.GetCustomAttributes(false))
{
if (attrib is KernelModeAttribute)
return false;
}
return true;
}
public static bool IsSafe(MethodInfo type)
{
if (InKernelMode == true)
return true;
foreach (var attrib in type.GetCustomAttributes(false))
{
if (attrib is KernelModeAttribute)
return false;
}
return true;
}
public static void EnterKernelMode()
{
InKernelMode = true;
Console.WriteLine("<kernel> Watchdog deactivated, system-level access granted.");
}
public static void LeaveKernelMode()
{
InKernelMode = false;
Console.WriteLine("<kernel> Kernel mode disabled.");
}
internal static bool CanRunOffline(Type method)
{
if (MudConnected)
return true;
foreach (var attr in method.GetCustomAttributes(false))
{
if (attr is MultiplayerOnlyAttribute)
return false;
}
return true;
}
internal static bool CanRunOffline(MethodInfo method)
{
if (MudConnected)
return true;
foreach(var attr in method.GetCustomAttributes(false))
{
if (attr is MultiplayerOnlyAttribute)
return false;
}
return true;
}
}
}
|