mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-19 04:24:54 -04:00
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:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
37
server/FSO.Server.Database/DA/LotVisits/DbLotVisit.cs
Executable file
37
server/FSO.Server.Database/DA/LotVisits/DbLotVisit.cs
Executable file
|
@ -0,0 +1,37 @@
|
|||
using FSO.Common.Enum;
|
||||
using System;
|
||||
|
||||
namespace FSO.Server.Database.DA.LotVisitors
|
||||
{
|
||||
public class DbLotVisit
|
||||
{
|
||||
public int lot_visit_id { get; set; }
|
||||
public uint avatar_id { get; set; }
|
||||
public int lot_id { get; set; }
|
||||
public DbLotVisitorType type { get; set; }
|
||||
public DbLotVisitorStatus status { get; set; }
|
||||
public DateTime time_created { get; set; }
|
||||
public DateTime? time_closed { get; set; }
|
||||
}
|
||||
|
||||
public class DbLotVisitNhood : DbLotVisit
|
||||
{
|
||||
public uint neighborhood_id { get; set; }
|
||||
public uint location { get; set; }
|
||||
public LotCategory category { get; set; }
|
||||
}
|
||||
|
||||
public enum DbLotVisitorType
|
||||
{
|
||||
owner,
|
||||
roommate,
|
||||
visitor
|
||||
}
|
||||
|
||||
public enum DbLotVisitorStatus
|
||||
{
|
||||
active,
|
||||
closed,
|
||||
failed
|
||||
}
|
||||
}
|
66
server/FSO.Server.Database/DA/LotVisits/ILotVisits.cs
Executable file
66
server/FSO.Server.Database/DA/LotVisits/ILotVisits.cs
Executable file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FSO.Server.Database.DA.LotVisitors
|
||||
{
|
||||
public interface ILotVisits
|
||||
{
|
||||
/// <summary>
|
||||
/// Records a new visit to a lot. A visit id is returned which can be used to record
|
||||
/// when the visit ends
|
||||
/// </summary>
|
||||
/// <param name="avatar_id"></param>
|
||||
/// <param name="visitor_type"></param>
|
||||
/// <param name="lot_id"></param>
|
||||
/// <returns></returns>
|
||||
int? Visit(uint avatar_id, DbLotVisitorType visitor_type, int lot_id);
|
||||
|
||||
/// <summary>
|
||||
/// Records that a visit has ended
|
||||
/// </summary>
|
||||
/// <param name="visit_id"></param>
|
||||
void Leave(int visit_id);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the timestamp on active visits. This helps detect the difference between
|
||||
/// a long visit and an error where the visit did not get closed.
|
||||
///
|
||||
/// This also lets us calculate Top 100 without downtime as we can be inclusive
|
||||
/// of active tickets
|
||||
/// </summary>
|
||||
/// <param name="visit_ids"></param>
|
||||
void Renew(IEnumerable<int> visit_ids);
|
||||
|
||||
/// <summary>
|
||||
/// Purge data older than the date given
|
||||
/// </summary>
|
||||
/// <param name="days"></param>
|
||||
void PurgeByDate(DateTime date);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<DbLotVisit> StreamBetween(int shard_id, DateTime start, DateTime end);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<DbLotVisitNhood> StreamBetweenPlusNhood(int shard_id, DateTime start, DateTime end);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<DbLotVisitNhood> StreamBetweenOneNhood(uint nhood_id, DateTime start, DateTime end);
|
||||
|
||||
|
||||
}
|
||||
}
|
50
server/FSO.Server.Database/DA/LotVisits/LotVisitUtils.cs
Executable file
50
server/FSO.Server.Database/DA/LotVisits/LotVisitUtils.cs
Executable file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
|
||||
namespace FSO.Server.Database.DA.LotVisits
|
||||
{
|
||||
public static class LotVisitUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Calculates the overlap between two date ranges.
|
||||
/// Useful utility function for calculating visit hours.
|
||||
/// </summary>
|
||||
/// <param name="day"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
public static TimeSpan CalculateDateOverlap(DateTime r1_start, DateTime r1_end, DateTime r2_start, DateTime r2_end)
|
||||
{
|
||||
var startsInRange = r2_start >= r1_start && r2_start <= r1_end;
|
||||
var endsInRange = r2_end <= r1_end && r2_end >= r1_start;
|
||||
|
||||
if (startsInRange && endsInRange)
|
||||
{
|
||||
//Within the range / equal
|
||||
return r2_end.Subtract(r2_start);
|
||||
}
|
||||
else if (startsInRange)
|
||||
{
|
||||
//Starts within range but does not end in range
|
||||
return r1_end.Subtract(r2_start);
|
||||
}
|
||||
else if (endsInRange)
|
||||
{
|
||||
//Ends in range but does not start in range
|
||||
return r2_end.Subtract(r1_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TimeSpan(0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns midnight of the current day.
|
||||
/// Useful utility function for calculating visit hours.
|
||||
/// </summary>
|
||||
public static DateTime Midnight()
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
return new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
82
server/FSO.Server.Database/DA/LotVisits/SqlLotVisits.cs
Executable file
82
server/FSO.Server.Database/DA/LotVisits/SqlLotVisits.cs
Executable file
|
@ -0,0 +1,82 @@
|
|||
using Dapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace FSO.Server.Database.DA.LotVisitors
|
||||
{
|
||||
public class SqlLotVisits : AbstractSqlDA, ILotVisits
|
||||
{
|
||||
public SqlLotVisits(ISqlContext context) : base(context){
|
||||
}
|
||||
|
||||
public int? Visit(uint avatar_id, DbLotVisitorType visitor_type, int lot_id)
|
||||
{
|
||||
try {
|
||||
//Stored procedure will handle erroring any active visits that should no longer be active
|
||||
return Context.Connection.Query<int>("SELECT `fso_lot_visits_create`(@avatar_id, @lot_id, @type)", new {
|
||||
avatar_id = avatar_id,
|
||||
lot_id = lot_id,
|
||||
type = visitor_type.ToString()
|
||||
}).First();
|
||||
}catch(Exception ex){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Leave(int visit_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Context.Connection.Query("UPDATE `fso_lot_visits` SET status = 'closed', time_closed = current_timestamp WHERE lot_visit_id = @visit_id AND `status` = 'active'", new { visit_id = visit_id });
|
||||
}catch(Exception ex){
|
||||
}
|
||||
}
|
||||
|
||||
public void Renew(IEnumerable<int> visit_ids)
|
||||
{
|
||||
try{
|
||||
Context.Connection.Query("UPDATE `fso_lot_visits` SET time_closed = current_timestamp WHERE lot_visit_id IN @visit_ids AND `status` = 'active'", new { visit_ids = visit_ids });
|
||||
}catch (Exception ex){
|
||||
}
|
||||
}
|
||||
|
||||
public void PurgeByDate(DateTime date)
|
||||
{
|
||||
Context.Connection.Query("DELETE FROM `fso_lot_visits` WHERE time_closed IS NOT NULL AND time_closed < @date", new { date = date });
|
||||
Context.Connection.Query("DELETE FROM `fso_lot_visits` WHERE time_closed IS NULL AND time_created < @date", new { date = date });
|
||||
}
|
||||
|
||||
public IEnumerable<DbLotVisit> StreamBetween(int shard_id, DateTime start, DateTime end)
|
||||
{
|
||||
return Context.Connection.Query<DbLotVisit>(
|
||||
"SELECT * FROM `fso_lot_visits` v INNER JOIN fso_lots l ON v.lot_id = l.lot_id " +
|
||||
"WHERE l.shard_id = @shard_id AND status != 'failed' " +
|
||||
"AND time_closed IS NOT NULL " +
|
||||
"AND type = 'visitor' " +
|
||||
"AND (time_created BETWEEN @start AND @end OR time_closed BETWEEN @start and @end)",
|
||||
new { start = start, end = end, shard_id = shard_id }, buffered: false);
|
||||
}
|
||||
|
||||
public IEnumerable<DbLotVisitNhood> StreamBetweenPlusNhood(int shard_id, DateTime start, DateTime end)
|
||||
{
|
||||
return Context.Connection.Query<DbLotVisitNhood>(
|
||||
"SELECT * FROM `fso_lot_visits` v INNER JOIN fso_lots l ON v.lot_id = l.lot_id " +
|
||||
"WHERE l.shard_id = @shard_id AND status != 'failed' " +
|
||||
"AND time_closed IS NOT NULL " +
|
||||
"AND (time_created BETWEEN @start AND @end OR time_closed BETWEEN @start and @end)",
|
||||
new { start = start, end = end, shard_id = shard_id }, buffered: false);
|
||||
}
|
||||
|
||||
public IEnumerable<DbLotVisitNhood> StreamBetweenOneNhood(uint neighborhood_id, DateTime start, DateTime end)
|
||||
{
|
||||
return Context.Connection.Query<DbLotVisitNhood>(
|
||||
"SELECT * FROM `fso_lot_visits` v INNER JOIN fso_lots l ON v.lot_id = l.lot_id " +
|
||||
"WHERE l.neighborhood_id = @neighborhood_id AND status != 'failed' " +
|
||||
"AND time_closed IS NOT NULL " +
|
||||
"AND type = 'visitor' " +
|
||||
"AND (time_created BETWEEN @start AND @end OR time_closed BETWEEN @start and @end)",
|
||||
new { start = start, end = end, neighborhood_id = neighborhood_id }, buffered: false);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue