Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GTANetworkAPI;
- using UW.Data.Models.Players;
- using UW.Data.Repositories;
- using Newtonsoft.Json;
- using System.Collections.Generic;
- using UW.Data.Models.Factions;
- using System.Linq;
- using UW.Global;
- using UW.Misc;
- using UW.Player;
- using TestData = UW.Global.TestDataFunctions;
- using Microsoft.EntityFrameworkCore.Storage;
- using Microsoft.EntityFrameworkCore.Infrastructure;
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json.Linq;
- using Microsoft.CSharp.RuntimeBinder;
- namespace GTAUnderworld
- {
- public class Main : Script
- {
- [ServerEvent(Event.ResourceStart)]
- public void OnResourceStart()
- {
- NAPI.Server.SetGlobalServerChat(false);
- using (var context = new UW.Data.UnderworldContext())
- {
- // Creates the database if not exists
- bool dbExists = (context.GetService<IDatabaseCreator>() as RelationalDatabaseCreator).Exists();
- if (!dbExists)
- {
- NAPI.Util.ConsoleOutput("Database didn't exist before, it does now.");
- }
- else
- {
- NAPI.Util.ConsoleOutput("Database exists.");
- }
- context.Database.Migrate();
- // context.Database.EnsureCreated();
- LoadDataFunctions.InsertInteriorsInDbIfTableEmpty();
- TestData.LoadTestData();
- if (context.Vehicles.Count() == 0)
- {
- TestData.AddSAAFVehicles();
- }
- if(context.Items.Count() == 0)
- {
- var itemrepo = new ItemRepository();
- foreach(var item in GlobalData.items)
- {
- itemrepo.Add(item);
- }
- }
- }
- LoadDataFunctions.LoadInteriorIPLs();
- LoadDataFunctions.LoadAllHouses();
- LoadDataFunctions.LoadAllATMs();
- LoadDataFunctions.LoadTurfs();
- LoadDataFunctions.LoadAllLabels();
- LoadDataFunctions.LoadAllTeleports();
- LoadDataFunctions.SpawnAllVehicles();
- }
- /*
- [ServerEvent(Event.PlayerDeath)]
- public void OnPlayerDeath(Client sender)
- {
- sender.RemoveAllWeapons();
- }*/
- /*
- [RemoteEvent("GetCharactersByAccountId")]
- public void GetCharactersByAccountId(Client sender)
- {
- int id = ClientFunctions.GetClientAccountId(sender);
- var repo = new PlayerRepository();
- var chars = repo.GetByAccountId(id);
- sender.TriggerEvent("showCharacters", chars);
- }*/
- [ServerEvent(Event.PlayerConnected)]
- public void OnPlayerConnected(Client sender)
- {
- if (!GlobalData.HasAnyoneLoggedIn)
- {
- GlobalData.HasAnyoneLoggedIn = true;
- foreach (var atm in Constants.ATM_LIST)
- {
- //set streetname of ATM todo.
- }
- }
- int count = 0;
- while (GlobalData.ServerIDs.ContainsKey(count))
- {
- count++;
- }
- ClientFunctions.SetClientPlayerServerId(sender, count);
- GlobalData.ServerIDs.Add(count, sender);
- CharacterFunctions.InitializePlayerData(sender);
- sender.SendChatMessage("You are now connected. Log into your account. (Logged in with ID " + count + "). Use /testlogin <accountName> to automatically log into your character.");
- }
- [ServerEvent(Event.PlayerSpawn)]
- public void OnPlayerSpawn(Client sender)
- {
- if (ClientFunctions.GetClientPlayerId(sender) > 0)
- {
- Player player = GlobalFunctions.GetPlayerModelFromClient(sender, sender);
- if (player != null)
- {
- sender.Position = new Vector3(player.PositionX, player.PositionY, player.PositionZ);
- sender.SendChatMessage("[DEBUG] You have spawned.");
- }
- }
- //set dimension for correct spawn..
- }
- [ServerEvent(Event.PlayerDisconnected)]
- public void OnPlayerDisconnected(Client player, DisconnectionType type, string reason)
- {
- switch (type)
- {
- case DisconnectionType.Left:
- NAPI.Chat.SendChatMessageToAll("~b~" + player.Name + "~w~ has quit the server.");
- break;
- case DisconnectionType.Timeout:
- NAPI.Chat.SendChatMessageToAll("~b~" + player.Name + "~w~ has timed out.");
- break;
- case DisconnectionType.Kicked:
- NAPI.Chat.SendChatMessageToAll("~b~" + player.Name + "~w~ has been kicked for " + reason);
- break;
- }
- if (GlobalData.ServerIDs.ContainsValue(player))
- {
- GlobalData.ServerIDs.Remove(ClientFunctions.GetClientPlayerServerId(player));
- }
- if (GlobalData.rePM.ContainsKey(player))
- {
- GlobalData.rePM.Remove(player);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement