Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. using GTANetworkAPI;
  2. using UW.Data.Models.Players;
  3. using UW.Data.Repositories;
  4. using Newtonsoft.Json;
  5. using System.Collections.Generic;
  6. using UW.Data.Models.Factions;
  7. using System.Linq;
  8. using UW.Global;
  9. using UW.Misc;
  10. using UW.Player;
  11. using TestData = UW.Global.TestDataFunctions;
  12. using Microsoft.EntityFrameworkCore.Storage;
  13. using Microsoft.EntityFrameworkCore.Infrastructure;
  14. using Microsoft.EntityFrameworkCore;
  15. using Newtonsoft.Json.Linq;
  16. using Microsoft.CSharp.RuntimeBinder;
  17.  
  18. namespace GTAUnderworld
  19. {
  20. public class Main : Script
  21. {
  22. [ServerEvent(Event.ResourceStart)]
  23. public void OnResourceStart()
  24. {
  25.  
  26. NAPI.Server.SetGlobalServerChat(false);
  27.  
  28. using (var context = new UW.Data.UnderworldContext())
  29. {
  30. // Creates the database if not exists
  31. bool dbExists = (context.GetService<IDatabaseCreator>() as RelationalDatabaseCreator).Exists();
  32.  
  33.  
  34.  
  35. if (!dbExists)
  36. {
  37. NAPI.Util.ConsoleOutput("Database didn't exist before, it does now.");
  38. }
  39. else
  40. {
  41. NAPI.Util.ConsoleOutput("Database exists.");
  42.  
  43. }
  44. context.Database.Migrate();
  45.  
  46. // context.Database.EnsureCreated();
  47. LoadDataFunctions.InsertInteriorsInDbIfTableEmpty();
  48. TestData.LoadTestData();
  49.  
  50. if (context.Vehicles.Count() == 0)
  51. {
  52. TestData.AddSAAFVehicles();
  53. }
  54.  
  55. if(context.Items.Count() == 0)
  56. {
  57. var itemrepo = new ItemRepository();
  58. foreach(var item in GlobalData.items)
  59. {
  60. itemrepo.Add(item);
  61. }
  62. }
  63. }
  64.  
  65. LoadDataFunctions.LoadInteriorIPLs();
  66. LoadDataFunctions.LoadAllHouses();
  67. LoadDataFunctions.LoadAllATMs();
  68. LoadDataFunctions.LoadTurfs();
  69. LoadDataFunctions.LoadAllLabels();
  70. LoadDataFunctions.LoadAllTeleports();
  71. LoadDataFunctions.SpawnAllVehicles();
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. }
  86. /*
  87. [ServerEvent(Event.PlayerDeath)]
  88. public void OnPlayerDeath(Client sender)
  89. {
  90. sender.RemoveAllWeapons();
  91. }*/
  92.  
  93. /*
  94. [RemoteEvent("GetCharactersByAccountId")]
  95. public void GetCharactersByAccountId(Client sender)
  96. {
  97. int id = ClientFunctions.GetClientAccountId(sender);
  98. var repo = new PlayerRepository();
  99. var chars = repo.GetByAccountId(id);
  100. sender.TriggerEvent("showCharacters", chars);
  101. }*/
  102.  
  103. [ServerEvent(Event.PlayerConnected)]
  104. public void OnPlayerConnected(Client sender)
  105. {
  106. if (!GlobalData.HasAnyoneLoggedIn)
  107. {
  108. GlobalData.HasAnyoneLoggedIn = true;
  109. foreach (var atm in Constants.ATM_LIST)
  110. {
  111. //set streetname of ATM todo.
  112. }
  113. }
  114.  
  115. int count = 0;
  116.  
  117. while (GlobalData.ServerIDs.ContainsKey(count))
  118. {
  119. count++;
  120. }
  121.  
  122. ClientFunctions.SetClientPlayerServerId(sender, count);
  123.  
  124. GlobalData.ServerIDs.Add(count, sender);
  125.  
  126. CharacterFunctions.InitializePlayerData(sender);
  127. sender.SendChatMessage("You are now connected. Log into your account. (Logged in with ID " + count + "). Use /testlogin <accountName> to automatically log into your character.");
  128.  
  129. }
  130.  
  131. [ServerEvent(Event.PlayerSpawn)]
  132. public void OnPlayerSpawn(Client sender)
  133. {
  134.  
  135. if (ClientFunctions.GetClientPlayerId(sender) > 0)
  136. {
  137. Player player = GlobalFunctions.GetPlayerModelFromClient(sender, sender);
  138. if (player != null)
  139. {
  140. sender.Position = new Vector3(player.PositionX, player.PositionY, player.PositionZ);
  141. sender.SendChatMessage("[DEBUG] You have spawned.");
  142.  
  143. }
  144. }
  145.  
  146.  
  147. //set dimension for correct spawn..
  148.  
  149. }
  150.  
  151. [ServerEvent(Event.PlayerDisconnected)]
  152. public void OnPlayerDisconnected(Client player, DisconnectionType type, string reason)
  153. {
  154. switch (type)
  155. {
  156. case DisconnectionType.Left:
  157. NAPI.Chat.SendChatMessageToAll("~b~" + player.Name + "~w~ has quit the server.");
  158. break;
  159.  
  160. case DisconnectionType.Timeout:
  161. NAPI.Chat.SendChatMessageToAll("~b~" + player.Name + "~w~ has timed out.");
  162. break;
  163.  
  164. case DisconnectionType.Kicked:
  165. NAPI.Chat.SendChatMessageToAll("~b~" + player.Name + "~w~ has been kicked for " + reason);
  166. break;
  167. }
  168.  
  169. if (GlobalData.ServerIDs.ContainsValue(player))
  170. {
  171. GlobalData.ServerIDs.Remove(ClientFunctions.GetClientPlayerServerId(player));
  172. }
  173.  
  174. if (GlobalData.rePM.ContainsKey(player))
  175. {
  176. GlobalData.rePM.Remove(player);
  177. }
  178. }
  179.  
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement