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;
- using UW.Business;
- using System.Threading.Tasks;
- using UW.Warehouse;
- using System.Text;
- namespace GTAUnderworld
- {
- public class Main : Script
- {
- [Command("setadminlevel")]
- public void SetAdminLevel(Client sender, int level)
- {
- if(level > -1 && level < 8)
- {
- var senderPlayer = GlobalFunctions.GetPlayerModelFromClient(sender);
- if (senderPlayer == null) return;
- senderPlayer.AdminLevel = level;
- var repo = new PlayerRepository();
- repo.Update(senderPlayer);
- ClientFunctions.SetClientAdminLevel(sender, level);
- ClientFunctions.SetClientAdminRank(sender, GlobalFunctions.GetAdminNameFromLevel(level));
- GlobalFunctions.AdminMessage(sender, "You have been promoted to "+ GlobalFunctions.GetAdminNameFromLevel(level) + ".");
- }
- else {
- GlobalFunctions.ErrorMessage(sender, "Available levels: 0-7");
- }
- }
- [ServerEvent(Event.ResourceStart)]
- public void OnResourceStart()
- {
- NAPI.Server.SetGlobalServerChat(false);
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- string host = NAPI.Resource.GetSetting<string>(this, "host");
- string user = NAPI.Resource.GetSetting<string>(this, "username");
- string pass = NAPI.Resource.GetSetting<string>(this, "password");
- string db = NAPI.Resource.GetSetting<string>(this, "database");
- UW.Data.ContextFactory.SetConnectionString(host,db,user,pass);
- // using (var context = new UW.Data.UnderworldContext())
- // {
- // Creates the database if not exists
- bool dbExists = (UW.Data.ContextFactory.Instance.GetService<IDatabaseCreator>() as RelationalDatabaseCreator).Exists();
- if (!dbExists)
- {
- NAPI.Util.ConsoleOutput("Database didn't exist before, it does now.");
- }
- else
- {
- NAPI.Util.ConsoleOutput("Database exists.");
- }
- UW.Data.ContextFactory.Instance.Database.Migrate();
- // context.Database.Migrate();
- // context.Database.EnsureCreated();
- LoadDataFunctions.InsertInteriorsInDbIfTableEmpty();
- TestData.LoadTestData();
- // }
- LoadDataFunctions.LoadInteriorIPLs();
- LoadDataFunctions.LoadAllHouses();
- LoadDataFunctions.LoadAllATMs();
- LoadDataFunctions.LoadTurfs();
- LoadDataFunctions.LoadAllLabels();
- LoadDataFunctions.LoadAllTeleports();
- LoadDataFunctions.SpawnAllVehicles();
- BusinessFunctions.LoadAllBusinesses();
- WarehouseFunctions.LoadAllWarehouses();
- }
- [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.");
- //To be improved:
- var repo = new TurfRepository();
- var turfs = repo.GetAll();
- Task.Run(() =>
- {
- sender.TriggerEvent("turf:playerConnected", NAPI.Util.ToJson(turfs));
- });
- }
- [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