59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using GTANetworkAPI;
|
|
using ReallifeGamemode.Server.Extensions;
|
|
using ReallifeGamemode.Server.Job;
|
|
using ReallifeGamemode.Server.Managers;
|
|
using ReallifeGamemode.Server.Models;
|
|
|
|
/**
|
|
* @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(Client 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");
|
|
}
|
|
|
|
JobManager.GetJob(player.GetUser()?.JobId ?? 0)?.StopJob(player);
|
|
|
|
using (var saveUser = new DatabaseContext())
|
|
{
|
|
var user = player.GetUser(saveUser);
|
|
Vector3 pos = player.Position;
|
|
|
|
if (!float.IsNaN(pos.X) && !float.IsNaN(pos.Y) && !float.IsNaN(pos.Z))
|
|
{
|
|
user.PositionX = pos.X;
|
|
user.PositionY = pos.Y;
|
|
user.PositionZ = pos.Z;
|
|
saveUser.SaveChanges();
|
|
}
|
|
|
|
user.Dead = player.HasData("isDead") ? player.GetData("isDead") : false;
|
|
}
|
|
player.SetData("isLoggedIn", false);
|
|
}
|
|
}
|
|
} |