1. Добро пожаловать в раздел русскоязычной поддержки. Пожалуйста, ознакомьтесь с правилами раздела.

Проверка игрока при входе на сервер

Discussion in 'Помощь разработчикам плагинов' started by Qizz, Feb 19, 2012.

  1. Qizz New Member

    1) Как сделать, когда игрок заходит на сервер, чтоб сервер проверял есть ли он в некой таблице, если нет -> создание рядка с его ником.
    PS: самое непонятное, это как сделать проверку сразу как он зашел

    2) Как сделать проверку кто убил игрока в ПвП?


    Это не повод делать даблпост, есть кнопка "Edit".
  2. Rosen TShock Plugin Developer

    1) Ловим хук OnJoin.
    Проверить можно обычным SQL запросом, если данные хранятся в базе данных:
    Code:
    SELECT [колонка] FROM [таблица] WHERE [колонка]='[игрок]'
    Дальше обрабатываем полученный результат и профит.

    2) Этого пока и сам не знаю, но уверен, что нужно двигаться в сторону GetData и обработки пакетов.
  3. Qizz New Member

    Что-то мне подсказывает что надо ковырять HandlePlayerKillMe
  4. Rosen TShock Plugin Developer

    Раньше был плагин C3Mod. Если мне не изменяет склероз, то там был такой обработчик. Можно было бы оттуда подсмотреть, но сейчас его не могу найти.
  5. Qizz New Member

    Вот я как раз и смотрю его.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Xml;
    using System.Reflection;
    using Terraria;
    using Hooks;
    using MySql.Data.MySqlClient;
    using System.Threading;
    using System.ComponentModel;
    using C3Mod.GameTypes;
    using System.IO;
    using TShockAPI;
    using TShockAPI.DB;
    using TShockAPI.Net;
    using System.IO.Streams;
     
    namespace C3Mod
    {
        internal delegate bool GetDataHandlerDelegate(GetDataHandlerArgs args);
        internal class GetDataHandlerArgs : EventArgs
        {
            public TSPlayer Player { get; private set; }
            public MemoryStream Data { get; private set; }
     
            public Player TPlayer
            {
                get { return Player.TPlayer; }
            }
     
            public GetDataHandlerArgs(TSPlayer player, MemoryStream data)
            {
                Player = player;
                Data = data;
            }
        }
        internal static class GetDataHandlers
        {
            private static Dictionary<PacketTypes, GetDataHandlerDelegate> GetDataHandlerDelegates;
     
            public static void InitGetDataHandler()
            {
                GetDataHandlerDelegates = new Dictionary<PacketTypes, GetDataHandlerDelegate>
                {
                    {PacketTypes.PlayerKillMe, HandlePlayerKillMe},             
                    {PacketTypes.PlayerDamage, HandlePlayerDamage},
                };
            }
     
            public static bool HandlerGetData(PacketTypes type, TSPlayer player, MemoryStream data)
            {
                GetDataHandlerDelegate handler;
                if (GetDataHandlerDelegates.TryGetValue(type, out handler))
                {
                    try
                    {
                        return handler(new GetDataHandlerArgs(player, data));
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }
                return false;
            }
     
            private static bool HandlePlayerKillMe(GetDataHandlerArgs args)
            {
                int index = args.Player.Index; //Attacking Player
                byte PlayerID = (byte)args.Data.ReadByte();
                byte hitDirection = (byte)args.Data.ReadByte();
                Int16 Damage = (Int16)args.Data.ReadInt16();
                bool PVP = args.Data.ReadBoolean();
                var player = C3Tools.GetC3PlayerByIndex(PlayerID);
     
                if (player.SpawnProtectionEnabled)
                {
                    NetMessage.SendData(4, -1, PlayerID, player.PlayerName, PlayerID, 0f, 0f, 0f, 0);
                    return true;
                }
     
                if (player.GameType == "ffa")
                {
                    player.KillingPlayer.FFAScore++;
                    C3Tools.BroadcastMessageToGametype("ffa", player.KillingPlayer.PlayerName + " - Score : " + player.KillingPlayer.FFAScore + " -- kills -- " + player.PlayerName + " - Score : " + player.FFAScore, Color.Black);
                    player.Dead = true;
                    player.TSPlayer.TPlayer.dead = true;
                }
     
                if (player.KillingPlayer != null)
                {
                    C3Events.Death(player.KillingPlayer, player, player.GameType, PVP);
                    player.KillingPlayer = null;
                }
     
                return false;
            }
     
            private static bool HandlePlayerDamage(GetDataHandlerArgs args)
            {
                int index = args.Player.Index; //Attacking Player
                byte PlayerID = (byte)args.Data.ReadByte(); //Damaged Player
                byte hitDirection = (byte)args.Data.ReadByte();
                Int16 Damage = (Int16)args.Data.ReadInt16();
                var player = C3Tools.GetC3PlayerByIndex(PlayerID);
                bool PVP = args.Data.ReadBoolean();
                byte Crit = (byte)args.Data.ReadByte();
     
                if (player.SpawnProtectionEnabled)
                {
                    C3Tools.GetC3PlayerByIndex(index).TSPlayer.SendData(PacketTypes.PlayerUpdate, "", PlayerID);
                    return true;
                }
     
                if (index != PlayerID)
                {
                    player.KillingPlayer = C3Tools.GetC3PlayerByIndex(index);
                }
                else
                    player.KillingPlayer = null;
     
                return false;
            }
        }
    }

Share This Page