CLre/CLre_server/API/MainServer/ServerEngines.cs

75 lines
2.6 KiB
C#
Raw Normal View History

using System;
2021-05-27 01:22:23 +01:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using CLre_server.API.Engines;
using Game.DataLoader;
using GameServer;
using HarmonyLib;
using Svelto.Context;
using Svelto.DataStructures;
using Svelto.ECS;
using User.Server;
namespace CLre_server.API.MainServer
{
class ServerReadyEngine : ServerEnginePostBuild, IWaitForFrameworkInitialization, IWaitForFrameworkDestruction
{
internal static event EventHandler<StartedEventArgs> serverEngineReady;
internal static event EventHandler<StartedEventArgs> serverFrameworkReady;
internal static event EventHandler<StopEventArgs> serverFrameworkDestroyed;
public override void Ready()
{
GameServerSettings gss = Server.Instance.GameServerSettings;
if (serverEngineReady != null) serverEngineReady(this, new StartedEventArgs
{
photonVersion = PhotonNetwork.gameVersion,
photonRegion = PhotonNetwork.CloudRegion,
2021-05-27 01:22:23 +01:00
gameGuid = gss == null ? "" : gss.GetGameGuid(),
worldName = gss == null ? "" : gss.GetWorldName(),
});
}
public void OnFrameworkInitialized()
{
GameServerSettings gss = Server.Instance.GameServerSettings;
if (serverFrameworkReady != null) serverFrameworkReady(this, new StartedEventArgs
{
photonVersion = PhotonNetwork.gameVersion,
photonRegion = PhotonNetwork.CloudRegion,
2021-05-27 01:22:23 +01:00
gameGuid = gss == null ? "" : gss.GetGameGuid(),
worldName = gss == null ? "" : gss.GetWorldName(),
});
}
public void OnFrameworkDestroyed()
{
if (serverFrameworkDestroyed != null) serverFrameworkDestroyed(this, new StopEventArgs{});
}
}
class ServerDatabaseQueryEngine : ServerEnginePostBuild
{
public override void Ready()
{
}
public AccountIdServerNode[] GetConnectedAccounts()
{
FieldInfo f = AccessTools.Field(AccessTools.TypeByName("User.Server.AccountExclusiveGroups"), "accountGroup");
ExclusiveGroup accountGroup = (ExclusiveGroup) f.GetValue(null);
ReadOnlyCollectionStruct<AccountIdServerNode> accounts =
entitiesDB.QueryEntityViews<AccountIdServerNode>(accountGroup);
List<AccountIdServerNode> list = new List<AccountIdServerNode>();
foreach (var a in accounts)
{
list.Add(a);
}
return list.ToArray();
}
}
}