Files
reallife-gamemode/Server/Events/Disconnect.cs
Lennart Kampshoff 52138ff832 Fixed login position
2018-10-08 12:04:13 +02:00

55 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Server.Extensions;
/**
* @overview Life of German Reallife - Event Login (Login.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.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");
}
using (var saveUser = new Model.DatabaseContext())
{
var user = player.GetUser(saveUser);
if(user == null)
{
return;
}
else
{
user.PositionX = player.Position.X;
user.PositionY = player.Position.Y;
user.PositionZ = player.Position.Z;
saveUser.SaveChanges();
}
}
player.SetData("isLoggedIn", false);
}
}
}