commit af978406a469aa22e6cf8829da161538f61aaa74
Author: j4ck <50369519+j4cegh@users.noreply.github.com>
Date: Thu Jun 2 01:24:42 2022 +0300
Initial commit
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9998c3d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,34 @@
+# Common IntelliJ Platform excludes
+
+# User specific
+**/.idea/**/workspace.xml
+**/.idea/**/tasks.xml
+**/.idea/shelf/*
+**/.idea/dictionaries
+**/.idea/httpRequests/
+
+# Sensitive or high-churn files
+**/.idea/**/dataSources/
+**/.idea/**/dataSources.ids
+**/.idea/**/dataSources.xml
+**/.idea/**/dataSources.local.xml
+**/.idea/**/sqlDataSources.xml
+**/.idea/**/dynamic.xml
+
+# Rider
+# Rider auto-generates .iml files, and contentModel.xml
+**/.idea/**/*.iml
+**/.idea/**/contentModel.xml
+**/.idea/**/modules.xml
+
+*.suo
+*.user
+.vs/
+[Bb]in/
+[Oo]bj/
+_UpgradeReport_Files/
+[Pp]ackages/
+
+Thumbs.db
+Desktop.ini
+.DS_Store
diff --git a/.idea/.idea.RSND/.idea/.gitignore b/.idea/.idea.RSND/.idea/.gitignore
new file mode 100644
index 0000000..c7ca351
--- /dev/null
+++ b/.idea/.idea.RSND/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/modules.xml
+/.idea.RSND.iml
+/contentModel.xml
+/projectSettingsUpdater.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.RSND/.idea/encodings.xml b/.idea/.idea.RSND/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.RSND/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.RSND/.idea/indexLayout.xml b/.idea/.idea.RSND/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.RSND/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/RSND.sln b/RSND.sln
new file mode 100644
index 0000000..4e312f7
--- /dev/null
+++ b/RSND.sln
@@ -0,0 +1,16 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSND", "RSND\RSND.csproj", "{1C728CE6-0609-415C-99A9-9345B32243F8}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {1C728CE6-0609-415C-99A9-9345B32243F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1C728CE6-0609-415C-99A9-9345B32243F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1C728CE6-0609-415C-99A9-9345B32243F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1C728CE6-0609-415C-99A9-9345B32243F8}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal
diff --git a/RSND/Core/Database.cs b/RSND/Core/Database.cs
new file mode 100644
index 0000000..258eb1c
--- /dev/null
+++ b/RSND/Core/Database.cs
@@ -0,0 +1,47 @@
+using Newtonsoft.Json;
+using RSND.Core.DbInternals;
+using RSND.Core.Querying.Queries;
+
+namespace RSND.Core;
+
+public class Database
+{
+ List
tables = new();
+
+ public void CreateTable(Table table)
+ {
+ tables.Add(table);
+ }
+
+ private static string GetRowsJson(Row[]? rows)
+ {
+ return JsonConvert.SerializeObject(new { Rows = rows });
+ }
+
+ public string GetValue(GetQuery? query)
+ {
+ Console.WriteLine(tables.Count);
+ var table = query?.Table;
+ var where = query?.Where;
+
+ var split = where?.Split("|");
+ var colName = split?[0];
+ var condition = split?[1];
+ var param = split?[2];
+
+ if (query?.Select != "*") return "";
+
+
+ var tableToReturn = tables.Find(x => x.Name == table);
+ var rows = tableToReturn?.Rows?.Where(x => x.Columns.FirstOrDefault(y => y.Data.Key == colName)?.Data.Value == param).ToArray();
+
+ return GetRowsJson(rows);
+ }
+
+ public static void Loop()
+ {
+ while (true)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/RSND/Core/DbClient.cs b/RSND/Core/DbClient.cs
new file mode 100644
index 0000000..5c7e127
--- /dev/null
+++ b/RSND/Core/DbClient.cs
@@ -0,0 +1,93 @@
+using Fleck;
+using Newtonsoft.Json;
+using RSND.Core.DbInternals;
+using RSND.Core.Querying;
+using RSND.Core.Querying.Queries;
+
+namespace RSND.Core;
+
+public class DbClient
+{
+ private readonly IWebSocketConnection _socket;
+
+ public DbClient(IWebSocketConnection socket)
+ {
+ _socket = socket;
+
+ RsndMain.Db.CreateTable(new Table
+ {
+ Name = "j4ces.table",
+ Rows = new []
+ {
+ new Row
+ {
+ Columns = new []
+ {
+ new Column("id", "1"),
+ new Column("amog us", "is THE GAME")
+ }
+ },
+ new Row
+ {
+ Columns = new []
+ {
+ new Column("id", "1"),
+ new Column("fortnite", "is THE GAME")
+ }
+ }
+ }
+ });
+ }
+
+ private void InvalidQuery()
+ {
+ _socket.Send(JsonConvert.SerializeObject(new Response
+ {
+ Success = false,
+ Message = "Invalid query"
+ }));
+ }
+
+ public void Handle()
+ {
+ _socket.OnMessage = message =>
+ {
+ QueryType? queryType = QueryHelper.GetQueryType(message);
+
+ RunQuery(message, queryType);
+ };
+ }
+
+ private void RunQuery(string? query, QueryType? queryType)
+ {
+ if (query == null || queryType == null)
+ InvalidQuery();
+
+ // check if
+ switch (queryType)
+ {
+ case QueryType.GetValue:
+ {
+ GetQuery getQuery = JsonConvert.DeserializeObject(query);
+ var queryResult = RsndMain.Db.GetValue(getQuery);
+ _socket.Send(queryResult);
+ Console.WriteLine($"Yooo: {queryResult}");
+ break;
+ }
+
+ case QueryType.CreateTable:
+ {
+ /*RsndMain.Db.CreateTable(new Table
+ {
+ Name = query.Table
+ });*/
+ break;
+ }
+
+ case null:
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/RSND/Core/DbInternals/Column.cs b/RSND/Core/DbInternals/Column.cs
new file mode 100644
index 0000000..caced45
--- /dev/null
+++ b/RSND/Core/DbInternals/Column.cs
@@ -0,0 +1,11 @@
+namespace RSND.Core.DbInternals;
+
+public class Column
+{
+ public KeyValuePair Data;
+
+ public Column(string name, string value)
+ {
+ Data = new KeyValuePair(name, value);
+ }
+}
\ No newline at end of file
diff --git a/RSND/Core/DbInternals/Row.cs b/RSND/Core/DbInternals/Row.cs
new file mode 100644
index 0000000..ea6961a
--- /dev/null
+++ b/RSND/Core/DbInternals/Row.cs
@@ -0,0 +1,6 @@
+namespace RSND.Core.DbInternals;
+
+public class Row
+{
+ public Column[]? Columns;
+}
\ No newline at end of file
diff --git a/RSND/Core/DbInternals/Table.cs b/RSND/Core/DbInternals/Table.cs
new file mode 100644
index 0000000..a39debe
--- /dev/null
+++ b/RSND/Core/DbInternals/Table.cs
@@ -0,0 +1,7 @@
+namespace RSND.Core.DbInternals;
+
+public class Table
+{
+ public string? Name;
+ public Row[]? Rows;
+}
\ No newline at end of file
diff --git a/RSND/Core/Querying/BaseQuery.cs b/RSND/Core/Querying/BaseQuery.cs
new file mode 100644
index 0000000..7a6b2ba
--- /dev/null
+++ b/RSND/Core/Querying/BaseQuery.cs
@@ -0,0 +1,14 @@
+namespace RSND.Core.Querying;
+
+///
+/// The required values that any query must have.
+///
+public class BaseQuery
+{
+ public BaseQuery(string type)
+ {
+ Type = type;
+ }
+
+ public string Type { get; set; }
+}
\ No newline at end of file
diff --git a/RSND/Core/Querying/IQuery.cs b/RSND/Core/Querying/IQuery.cs
new file mode 100644
index 0000000..f80650f
--- /dev/null
+++ b/RSND/Core/Querying/IQuery.cs
@@ -0,0 +1,6 @@
+namespace RSND.Core.Querying;
+
+public interface IQuery
+{
+
+}
\ No newline at end of file
diff --git a/RSND/Core/Querying/Queries/GetQuery.cs b/RSND/Core/Querying/Queries/GetQuery.cs
new file mode 100644
index 0000000..4d8bdf8
--- /dev/null
+++ b/RSND/Core/Querying/Queries/GetQuery.cs
@@ -0,0 +1,9 @@
+namespace RSND.Core.Querying.Queries;
+
+public class GetQuery : IQuery
+{
+ public string Type { get; set; }
+ public string Table { get; set; }
+ public string Select { get; set; }
+ public string Where { get; set; }
+}
\ No newline at end of file
diff --git a/RSND/Core/Querying/QueryHelper.cs b/RSND/Core/Querying/QueryHelper.cs
new file mode 100644
index 0000000..0b02239
--- /dev/null
+++ b/RSND/Core/Querying/QueryHelper.cs
@@ -0,0 +1,22 @@
+using Newtonsoft.Json;
+
+namespace RSND.Core.Querying.Queries;
+
+public static class QueryHelper
+{
+ public static QueryType? GetQueryType(string queryJson)
+ {
+ BaseQuery? query = JsonConvert.DeserializeObject(queryJson);
+
+ if (query != null)
+ {
+ return query.Type switch
+ {
+ "GetValue" => QueryType.GetValue,
+ _ => null
+ };
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/RSND/Core/Querying/QueryType.cs b/RSND/Core/Querying/QueryType.cs
new file mode 100644
index 0000000..e2d333a
--- /dev/null
+++ b/RSND/Core/Querying/QueryType.cs
@@ -0,0 +1,7 @@
+namespace RSND.Core.Querying;
+
+public enum QueryType
+{
+ GetValue,
+ CreateTable
+}
\ No newline at end of file
diff --git a/RSND/Core/Response.cs b/RSND/Core/Response.cs
new file mode 100644
index 0000000..cab2c21
--- /dev/null
+++ b/RSND/Core/Response.cs
@@ -0,0 +1,7 @@
+namespace RSND.Core;
+
+public class Response
+{
+ public bool Success { get; set; }
+ public string Message { get; set; }
+}
\ No newline at end of file
diff --git a/RSND/Program.cs b/RSND/Program.cs
new file mode 100644
index 0000000..7c394c6
--- /dev/null
+++ b/RSND/Program.cs
@@ -0,0 +1,3 @@
+using RSND;
+
+RsndMain.Run();
\ No newline at end of file
diff --git a/RSND/RSND.csproj b/RSND/RSND.csproj
new file mode 100644
index 0000000..3528f15
--- /dev/null
+++ b/RSND/RSND.csproj
@@ -0,0 +1,15 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/RSND/RsndMain.cs b/RSND/RsndMain.cs
new file mode 100644
index 0000000..10b4a81
--- /dev/null
+++ b/RSND/RsndMain.cs
@@ -0,0 +1,27 @@
+using Fleck;
+using RSND.Core;
+
+namespace RSND;
+
+public static class RsndMain
+{
+ public static Database Db = new();
+
+ public static void Run()
+ {
+ WebSocketServer server = new WebSocketServer("ws://0.0.0.0:7878");
+
+ FleckLog.Level = LogLevel.Error;
+
+ server.Start(socket =>
+ {
+ socket.OnOpen = () =>
+ {
+ var dbClient = new DbClient(socket);
+ dbClient.Handle();
+ };
+ });
+
+ Database.Loop();
+ }
+}
\ No newline at end of file