Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2KB

  1. using System;
  2. using System.Reflection;
  3. using GameNetworkLayer.Shared;
  4. using HarmonyLib;
  5. using Svelto.Context;
  6. using Svelto.ECS;
  7. namespace CLre_server.API.MainServer
  8. {
  9. public class UserVerification
  10. {
  11. public static UserVerification Instance { get; internal set; }
  12. private delegate void DisconnectPlayer_VerificationFailedProto(int playerId, string error);
  13. private delegate void DisconnectPlayerProto(int playerId, NetworkDispatcherCode code);
  14. private readonly DisconnectPlayer_VerificationFailedProto _disconnectPlayerVerificationFailed;
  15. private readonly DisconnectPlayerProto _disconnectPlayer;
  16. // This doesn't seem to do actually generate a popup, but it will stop the player from loading in
  17. /*public void DisconnectPlayer_VerificationFailed(int playerId, string error)
  18. {
  19. _disconnectPlayerVerificationFailed(playerId, error);
  20. }*/
  21. public void DisconnectPlayer(int playerId, NetworkDispatcherCode code = NetworkDispatcherCode.ModVerificationFail)
  22. {
  23. _disconnectPlayer(playerId, code);
  24. }
  25. internal UserVerification(IQueryingEntitiesEngine uvs)
  26. {
  27. Type uvsType = AccessTools.TypeByName("User.Server.UserVerificationServer");
  28. _disconnectPlayerVerificationFailed =
  29. Utility.Reflection.MethodAsDelegate<DisconnectPlayer_VerificationFailedProto>(uvsType,
  30. "DisconnectPlayer_VerificationFailed",
  31. //parameters: new [] {typeof(int), typeof(string)},
  32. instance: uvs);
  33. _disconnectPlayer =
  34. Utility.Reflection.MethodAsDelegate<DisconnectPlayerProto>(uvsType, "DisconnectPlayer", instance: uvs);
  35. }
  36. }
  37. // This seems to think that __instance is always simply a System.Object (caused by Harmony?), which doesn't work
  38. /*[HarmonyPatch]
  39. class UserVerificationServer_Constructor_Patch
  40. {
  41. private static IQueryingEntitiesEngine uvs = null;
  42. [HarmonyPrefix]
  43. public static void BeforeMethodCall()
  44. {
  45. }
  46. [HarmonyPostfix]
  47. public static void AfterMethodCall(IQueryingEntitiesEngine __instance)
  48. {
  49. uvs = __instance;
  50. UserVerification.Instance = new UserVerification(__instance);
  51. }
  52. [HarmonyTargetMethod]
  53. public static MethodBase Target()
  54. {
  55. return AccessTools.Constructor(AccessTools.TypeByName("User.Server.UserVerificationServer"));
  56. }
  57. }*/
  58. [HarmonyPatch]
  59. class MainGameServer_CreatePlayerDisconnectionSequence_Patch
  60. {
  61. private static IQueryingEntitiesEngine uvs = null;
  62. [HarmonyPrefix]
  63. public static void BeforeMethodCall()
  64. {
  65. }
  66. [HarmonyPostfix]
  67. public static void AfterMethodCall(IQueryingEntitiesEngine userVerificationEng)
  68. {
  69. uvs = userVerificationEng;
  70. UserVerification.Instance = new UserVerification(userVerificationEng);
  71. }
  72. [HarmonyTargetMethod]
  73. public static MethodBase Target()
  74. {
  75. return AccessTools.Method("GameServer.GameFramework.MainGameServer:CreatePlayerDisconnectionSequence");
  76. }
  77. }
  78. }