145 lines
4.7 KiB
C#
145 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.Server.Extensions;
|
|
using ReallifeGamemode.Server.Job;
|
|
using ReallifeGamemode.Server.Managers;
|
|
using ReallifeGamemode.Server.Util;
|
|
using ReallifeGamemode.Services;
|
|
using ReallifeGamemode.Server.Services;
|
|
using ReallifeGamemode.Server.Types;
|
|
using ReallifeGamemode.Server.Report;
|
|
using ReallifeGamemode.Server.Factions.Medic;
|
|
|
|
/**
|
|
* @overview Life of German Reallife - Event Login (Login.cs)
|
|
* @author VegaZ
|
|
* @copyright (c) 2008 - 2018 Life of German
|
|
*/
|
|
|
|
namespace ReallifeGamemode.Server.Events
|
|
{
|
|
public class Disconnect : Script
|
|
{
|
|
[ServerEvent(Event.PlayerDisconnected)]
|
|
public void OnPlayerDisconnected(Player player, DisconnectionType type, string reason)
|
|
{
|
|
if (!player.IsLoggedIn()) return;
|
|
|
|
if (type == DisconnectionType.Left)
|
|
{
|
|
NAPI.Util.ConsoleOutput(player.Name + " left");
|
|
}
|
|
if (type == DisconnectionType.Kicked)
|
|
{
|
|
NAPI.Util.ConsoleOutput(player.Name + " kicked");
|
|
}
|
|
if (type == DisconnectionType.Timeout)
|
|
{
|
|
NAPI.Util.ConsoleOutput(player.Name + " Timeoutet");
|
|
}
|
|
|
|
/*if (GlobalHelper.DutyAdmins.Contains(player))
|
|
{
|
|
GlobalHelper.DutyAdmins.Remove(player);
|
|
}*/
|
|
|
|
if (player.GetUser().IsAdmin(AdminLevel.MAPPING))
|
|
{
|
|
ChatService.BroadcastAdmin("!{#FFFF00}*** " + player.Name + " hat den Server verlassen", AdminLevel.MAPPING);
|
|
}
|
|
|
|
TaxiDriverJob taxiJob = JobManager.GetJob<TaxiDriverJob>();
|
|
TaxiContract taxiContract = taxiJob.TaxiContracts.Where(t => t.Name == player.Name).FirstOrDefault();
|
|
|
|
if (taxiContract != null)
|
|
{
|
|
if (taxiJob.TaxiContracts.Contains(taxiContract))
|
|
{
|
|
taxiJob.TaxiContracts.Remove(taxiContract);
|
|
}
|
|
}
|
|
var listReports = Report.Report.listReports;
|
|
ReportManage temp;
|
|
for (int a = 0; a < listReports.Count; a++)
|
|
{
|
|
temp = listReports[a];
|
|
if (temp.getAdmin().Equals(player.Name))
|
|
{
|
|
listReports.Remove(temp);
|
|
|
|
Player user = PlayerService.GetPlayerByNameOrId(temp.getUser());
|
|
user.SendChatMessage("!{#008fff}[REPORT]!{#FFFFFF} Chat beendet. Der Admin hat den Server verlassen");
|
|
break;
|
|
}
|
|
|
|
if (temp.getUser().Equals(player.Name))
|
|
{
|
|
listReports.Remove(temp);
|
|
|
|
Player admin = PlayerService.GetPlayerByNameOrId(temp.getAdmin());
|
|
admin.SendChatMessage("!{#008fff}[REPORT]!{#FFFFFF} Chat beendet. Der User hat den Server verlassen");
|
|
break;
|
|
}
|
|
}
|
|
|
|
//Vehicle LastVehicle = player.GetData<Vehicle>("LastVehicle");
|
|
JobBase job = JobManager.GetJob(player.GetUser().JobId ?? -1);
|
|
if (job != null)
|
|
{
|
|
if (job.GetUsersInJob().Contains(player))
|
|
{
|
|
if (player.Vehicle != null)
|
|
{
|
|
//if (player.Vehicle.GetData<bool>("timerJobVehicleRespawn") == true)
|
|
//{
|
|
if (player.Vehicle.GetServerVehicle() is JobVehicle vehJ)
|
|
{
|
|
player.Vehicle.ResetData("timerJobVehicleRespawn");
|
|
ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(player.Vehicle);
|
|
ServerVehicleExtensions.Spawn(sVeh, player.Vehicle);
|
|
}
|
|
//}
|
|
}
|
|
if (Managers.JobManager.playerTimersJobVehicleRespawn.ContainsKey(player))
|
|
{
|
|
Managers.JobManager.playerTimersJobVehicleRespawn[player].Stop();
|
|
}
|
|
player.ResetData("PilotenBase");
|
|
job.StopJob(player);
|
|
ChatService.SendMessage(player, $"~y~[JOB]~s~ Du hast deinen Job ~o~{job.Name}~s~ beendet.");
|
|
if (player.GetData<bool>("HatRoute") == true)
|
|
{
|
|
CheckPointHandle.DeleteCheckpoints(player);
|
|
player.ResetData("HatRoute");
|
|
}
|
|
}
|
|
}
|
|
|
|
using (var saveUser = new DatabaseContext())
|
|
{
|
|
var user = player.GetUser(saveUser);
|
|
Vector3 pos = player.Position;
|
|
|
|
user.PositionX = pos.X;
|
|
user.PositionY = pos.Y;
|
|
user.PositionZ = pos.Z;
|
|
saveUser.SaveChanges();
|
|
user.Dead = player.HasData("isDead") ? (bool)player.GetData<bool>("isDead") : false;
|
|
}
|
|
player.SetData("isLoggedIn", false);
|
|
player.TriggerEvent("CLIENT:DestroyPed", 1);
|
|
player.TriggerEvent("CLIENT:DestroyPed", 2);
|
|
player.TriggerEvent("CLIENT:DestroyPed", 3);
|
|
player.TriggerEvent("CLIENT:DestroyPed", 4);
|
|
Medic.delHealTasks(player);
|
|
Medic.delReviveTasks(player);
|
|
}
|
|
}
|
|
}
|