Removed NioTSO client and server

- NioTSO client isn't needed because we're using RayLib
- Added FreeSO's API server to handle most backend operations
This commit is contained in:
Tony Bark 2024-05-01 02:55:43 -04:00
parent f12ba1502b
commit 22191ce648
591 changed files with 53264 additions and 3362 deletions

View file

@ -0,0 +1,17 @@
using FSO.Common.Model;
namespace FSO.Server.Database.DA.Tuning
{
public class DbTuning : DynTuningEntry
{
public DbTuningType owner_type { get; set; }
public int owner_id { get; set; }
}
public enum DbTuningType
{
STATIC = 1,
DYNAMIC = 2,
EVENT = 3
}
}

View file

@ -0,0 +1,20 @@
namespace FSO.Server.Database.DA.Tuning
{
public class DbTuningPreset
{
public int preset_id;
public string name;
public string description;
public int flags;
}
public class DbTuningPresetItem
{
public int item_id;
public int preset_id;
public string tuning_type;
public int tuning_table;
public int tuning_index;
public float value;
}
}

View file

@ -0,0 +1,20 @@
using System.Collections.Generic;
namespace FSO.Server.Database.DA.Tuning
{
public interface ITuning
{
IEnumerable<DbTuning> All();
IEnumerable<DbTuning> AllCategory(string type, int table);
IEnumerable<DbTuningPreset> GetAllPresets();
IEnumerable<DbTuningPresetItem> GetPresetItems(int preset_id);
bool ActivatePreset(int preset_id, int owner_id);
bool ClearPresetTuning(int owner_id);
bool ClearInactiveTuning(int[] active_ids);
int CreatePreset(DbTuningPreset preset);
int CreatePresetItem(DbTuningPresetItem item);
bool DeletePreset(int preset_id);
}
}

View file

@ -0,0 +1,72 @@
using Dapper;
using System.Collections.Generic;
using System.Linq;
namespace FSO.Server.Database.DA.Tuning
{
public class SqlTuning : AbstractSqlDA, ITuning
{
public SqlTuning(ISqlContext context) : base(context)
{
}
public IEnumerable<DbTuning> All()
{
return Context.Connection.Query<DbTuning>("SELECT * FROM fso_tuning");
}
public IEnumerable<DbTuning> AllCategory(string type, int table)
{
return Context.Connection.Query<DbTuning>("SELECT * FROM fso_tuning WHERE tuning_type = @type AND tuning_table = @table", new { type = type, table = table });
}
public IEnumerable<DbTuningPreset> GetAllPresets()
{
return Context.Connection.Query<DbTuningPreset>("SELECT * FROM fso_tuning_presets");
}
public IEnumerable<DbTuningPresetItem> GetPresetItems(int preset_id)
{
return Context.Connection.Query<DbTuningPresetItem>("SELECT * FROM fso_tuning_preset_items WHERE preset_id = @preset_id", new { preset_id });
}
public bool ActivatePreset(int preset_id, int owner_id)
{
return Context.Connection.Execute("INSERT IGNORE INTO fso_tuning (tuning_type, tuning_table, tuning_index, value, owner_type, owner_id) " +
"SELECT p.tuning_type, p.tuning_table, p.tuning_index, p.value, 'EVENT' as owner_type, @owner_id as owner_id " +
"FROM fso_tuning_preset_items as p " +
"WHERE p.preset_id = @preset_id", new { preset_id, owner_id }) > 0;
}
public bool ClearPresetTuning(int owner_id)
{
return Context.Connection.Execute("DELETE FROM fso_tuning WHERE owner_type = 'EVENT' AND owner_id = owner_id", new { owner_id } ) > 0;
}
public bool ClearInactiveTuning(int[] active_ids)
{
return Context.Connection.Execute("DELETE FROM fso_tuning WHERE owner_type = 'EVENT' AND owner_id NOT IN @active_ids", new { active_ids }) > 0;
}
public int CreatePreset(DbTuningPreset preset)
{
var result = Context.Connection.Query<int>("INSERT INTO fso_tuning_presets (name, description, flags) "
+ "VALUES (@name, @description, @flags); SELECT LAST_INSERT_ID();",
preset).FirstOrDefault();
return result;
}
public int CreatePresetItem(DbTuningPresetItem item)
{
var result = Context.Connection.Query<int>("INSERT INTO fso_tuning_preset_items (preset_id, tuning_type, tuning_table, tuning_index, value) "
+ "VALUES (@preset_id, @tuning_type, @tuning_table, @tuning_index, @value); SELECT LAST_INSERT_ID();",
item).FirstOrDefault();
return result;
}
public bool DeletePreset(int preset_id)
{
return Context.Connection.Execute("DELETE FROM fso_tuning_presets WHERE preset_id = @preset_id", new { preset_id }) > 0;
}
}
}