当前位置: 首页>>代码示例>>C#>>正文


C# Plugins.HookContext类代码示例

本文整理汇总了C#中Terraria_Server.Plugins.HookContext的典型用法代码示例。如果您正苦于以下问题:C# HookContext类的具体用法?C# HookContext怎么用?C# HookContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HookContext类属于Terraria_Server.Plugins命名空间,在下文中一共展示了HookContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public override void Process(ClientConnection conn, byte[] readBuffer, int length, int num)
        {
            if (conn.State == SlotState.ACCEPTED)
            {
                SlotManager.Schedule (conn, conn.DesiredQueue);
                return;
            }

            int whoAmI = conn.SlotIndex;

            if (NetPlay.slots[whoAmI].state == SlotState.ASSIGNING_SLOT)
            {
                NetPlay.slots[whoAmI].state = SlotState.SENDING_WORLD;
            }

            var ctx = new HookContext() { Connection = conn, Player = conn.Player };
            var args = new HookArgs.WorldRequestMessage()
            {
                SpawnX = Main.spawnTileX,
                SpawnY = Main.spawnTileY
            };
            HookPoints.WorldRequestMessage.Invoke(ref ctx, ref args);

            //NetMessage.SendData(7, whoAmI);
            var msg = NetMessage.PrepareThreadInstance();
            msg.WorldData(args.SpawnX, args.SpawnY);
            msg.Send(whoAmI);
        }
开发者ID:emreuyls,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:28,代码来源:WorldRequestMessage.cs

示例2: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int playerId = readBuffer[num++]; //TODO: maybe check for forgery
            byte action = readBuffer[num];
            if (action == 1)
            {
                var player = Main.players[whoAmI];

                var ctx = new HookContext
                {
                    Connection = player.Connection,
                    Sender = player,
                    Player = player,
                };

                var args = new HookArgs.PlayerTriggeredEvent
                {
                    Type = WorldEventType.BOSS,
                    Name = "Skeletron",
                };

                HookPoints.PlayerTriggeredEvent.Invoke (ref ctx, ref args);

                if (ctx.CheckForKick () || ctx.Result == HookResult.IGNORE)
                    return;

                ProgramLog.Users.Log ("{0} @ {1}: Skeletron summoned by {2}.", player.IPAddress, whoAmI, player.Name);
                NetMessage.SendData (Packet.PLAYER_CHAT, -1, -1, string.Concat (player.Name, " has summoned Skeletron!"), 255, 255, 128, 150);
                NPC.SpawnSkeletron();
            }
            else if (action == 2)
            {
                NetMessage.SendData (51, -1, whoAmI, "", playerId, action, 0f, 0f, 0);
            }
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:35,代码来源:SummonSkeletronMessage.cs

示例3: ClientConnection

        public ClientConnection(Socket socket, int slot)
            : base(socket)
        {
            //var buf = NetMessage.buffer[id];
            //socket.SendBufferSize = 128000;
            connectedAt = time.Elapsed;

            if (slot >= 0) AssignSlot (slot);

            socket.LingerState = new LingerOption (true, 10);

            var ctx = new Terraria_Server.Plugins.HookContext
            {
                Connection = this,
            };

            var args = new Terraria_Server.Plugins.HookArgs.NewConnection ();

            Terraria_Server.Plugins.HookPoints.NewConnection.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick ())
                return;

            lock (All)
            {
                indexInAll = All.Count;
                All.Add (this);
            }

            StartReceiving (new byte [4192]);
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:31,代码来源:ClientConnection.cs

示例4: Process

        public override void Process(ClientConnection conn, byte[] readBuffer, int length, int num)
        {
            var data = Encoding.ASCII.GetString (readBuffer, num, length - 1);
            var lines = data.Split ('\n');

            foreach (var line in lines)
            {
                if (line == "tdcm1")
                {
                    //player.HasClientMod = true;
                    ProgramLog.Log ("{0} is a TDCM protocol version 1 client.", conn.RemoteAddress);
                }
                else if (line == "tdsmcomp1")
                {
                    conn.CompressionVersion = 1;
                    ProgramLog.Log ("{0} supports TDSM compression version 1.", conn.RemoteAddress);
                }
            }

            var ctx = new HookContext
            {
                Connection = conn,
            };

            var args = new HookArgs.DisconnectReceived
            {
                Content = data,
                Lines   = lines,
            };

            HookPoints.DisconnectReceived.Invoke (ref ctx, ref args);

            ctx.CheckForKick ();
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:34,代码来源:DisconnectMessage.cs

示例5: OnUnkownPacketSend

        public static void OnUnkownPacketSend(ref HookContext ctx, ref HookArgs.UnkownSendPacket args)
        {
            switch (args.PacketId)
            {
                case (int)Packets.CLIENT_MOD_GOD:
                    {
                        NetMessageExtension msg = new NetMessageExtension();

                        if (args.RemoteClient != -1)
                        {
                            var player = Main.players[args.RemoteClient];

                            if (player.HasClientMod)
                            {
                                if (Server.AllowTDCMRPG)
                                {
                                    Server.notifyOps(
                                        String.Format("Failed attempt to {0} God Mode on an RPG Server.", true, (args.Number == 1) ? "give" : "remove"));
                                    return;
                                }

                                Server.notifyOps(
                                    String.Format("{0} {1} God Mode.", true, player.Name, (args.Number == 1) ? "has" : "doesn't have"));

                                msg.GodTDCMClient(args.Number == 1);
                                args.Message = msg;
                                ctx.SetResult(HookResult.IGNORE); //Let TDSM know it's to ignore returning.
                            }
                        }
                        break;
                    }

            }
        }
开发者ID:TimeBomb,项目名称:Essentials-TDSM,代码行数:34,代码来源:Net.cs

示例6: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            short identity = BitConverter.ToInt16(readBuffer, num);
            num += 2;
            byte owner = readBuffer[num];

            owner = (byte)whoAmI;

            int index = Projectile.FindExisting(identity, owner);
            if (index == 1000) return;

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player = player,
                Sender = player,
            };

            var args = new HookArgs.KillProjectileReceived
            {
                Id = identity,
                Owner = owner,
                Index = (short)index,
            };

            HookPoints.KillProjectileReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                var msg = NetMessage.PrepareThreadInstance();
                msg.Projectile(Main.projectile[index]);
                msg.Send(whoAmI);
                return;
            }

            var projectile = Main.projectile[index];

            if (projectile.Owner == owner && projectile.identity == identity)
            {
                projectile.Kill(null, null);
                projectile.Reset();
                NetMessage.SendData(29, -1, whoAmI, "", (int)identity, (float)owner);
            }
        }
开发者ID:emreuyls,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:56,代码来源:KillProjectileMessage.cs

示例7: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int x = BitConverter.ToInt32(readBuffer, num);
            num += 4;
            int y = BitConverter.ToInt32(readBuffer, num);
            num += 4;

            var player = Main.players[whoAmI];

            if (Math.Abs(player.Position.X / 16 - x) >= 7 || Math.Abs(player.Position.Y / 16 - y) >= 7)
            {
                return;
            }

            int chestIndex = Chest.FindChest(x, y);

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player = player,
                Sender = player,
            };

            var args = new HookArgs.ChestOpenReceived
            {
                X = x,
                Y = y,
                ChestIndex = (short)chestIndex,
            };

            HookPoints.ChestOpenReceived.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.DEFAULT && chestIndex > -1)
            {
                var user = Chest.UsingChest(chestIndex);
                if (user >= 0 && user != whoAmI) return;

                for (int i = 0; i < Chest.MAX_ITEMS; i++)
                {
                    NetMessage.SendData(32, whoAmI, -1, "", chestIndex, (float)i);
                }
                NetMessage.SendData(33, whoAmI, -1, "", chestIndex);
                Main.players[whoAmI].chest = chestIndex;
                return;
            }
        }
开发者ID:emreuyls,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:56,代码来源:OpenChestMessage.cs

示例8: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int playerIndex = readBuffer[num];

            if (playerIndex != whoAmI)
            {
                NetPlay.slots[whoAmI].Kick ("Cheating detected (PLAYER_PVP_CHANGE forgery).");
                return;
            }

            var pvp = readBuffer[num + 1] == 1;
            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player = player,
                Sender = player,
            };

            var args = new HookArgs.PvpSettingReceived
            {
                PvpFlag = pvp,
            };

            HookPoints.PvpSettingReceived.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick ())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                NetMessage.SendData(30, whoAmI, -1, "", whoAmI);
                return;
            }

            player.hostile = pvp;

            string message = (player.hostile) ? " has enabled PvP!" : " has disabled PvP!";

            NetMessage.SendData(30, -1, whoAmI, "", whoAmI);
            NetMessage.SendData(25, -1, -1, player.Name + message, 255, (float)Main.teamColor[player.team].R, (float)Main.teamColor[player.team].G, (float)Main.teamColor[player.team].B);
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:50,代码来源:PlayerPvPChangeMessage.cs

示例9: OnServerStateChange

 void OnServerStateChange(ref HookContext ctx, ref HookArgs.ServerStateChange args)
 {
     if (args.ServerChangeState == ServerState.LOADED)
     {
         ProgramLog.Plugin.Log("Starting fishy mod...");
         fishy = new Fishy();
         ProgramLog.Plugin.Log("Fishy mod Started.");
     }
     else if (args.ServerChangeState == ServerState.STOPPING || args.ServerChangeState == ServerState.RESTARTING)
     {
         ProgramLog.Plugin.Log("Stopping fishy mod...");
         fishy.Stop();
         ProgramLog.Plugin.Log("Fishy mod Stopped.");
     }
 }
开发者ID:elevatorguy,项目名称:TDSM_fishy,代码行数:15,代码来源:fishyPlugin.cs

示例10: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int start = num - 1;
            int playerIndex = readBuffer[num++];

            if (playerIndex != whoAmI)
            {
                NetPlay.slots[whoAmI].Kick ("Cheating detected (KILL_PLAYER forgery).");
                return;
            }

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = NetPlay.slots[whoAmI].conn,
                Sender = player,
                Player = player,
            };

            var args = new HookArgs.ObituaryReceived
            {
                Direction = (int)readBuffer[num++] - 1,
                Damage = BitConverter.ToInt16 (readBuffer, num++),
                PvpFlag = readBuffer[++num]
            };
            string obituary;
            if (!ParseString(readBuffer, num + 1, length - num - 1 + start, out obituary))
            {
                NetPlay.slots[whoAmI].Kick("Invalid characters in obituary message.");
                return;
            }
            args.Obituary = obituary;

            HookPoints.ObituaryReceived.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick ())
                return;

            if (ctx.Result == HookResult.IGNORE)
                return;

            ProgramLog.Death.Log ("{0} @ {1}: [Death] {2}{3}", player.IPAddress, whoAmI, player.Name ?? "<null>", args.Obituary);

            player.KillMe (args.Damage, args.Direction, args.PvpFlag == 1, args.Obituary);

            NetMessage.SendData(44, -1, whoAmI, args.Obituary, whoAmI, args.Direction, args.Damage, args.PvpFlag);
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:48,代码来源:KillPlayerPvPMessage.cs

示例11: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int x = BitConverter.ToInt32(readBuffer, num);
            num += 4;
            int y = BitConverter.ToInt32(readBuffer, num);

            if (Main.tile.At(x, y).Type != 21)
                return;

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Player = player,
                Sender = player,
            };

            var args = new HookArgs.ChestBreakReceived
            {
                X = x, Y = y,
            };

            HookPoints.ChestBreakReceived.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick ())
            {
                return;
            }

            if (ctx.Result == HookResult.IGNORE)
            {
                return;
            }

            if (ctx.Result == HookResult.RECTIFY)
            {
                NetMessage.SendTileSquare(whoAmI, x, y, 3);
                return;
            }

            WorldModify.KillTile(x, y, false, false, false, player);
            if (!Main.tile.At(x, y).Active || Main.tile.At(x, y).Type != 21)
            {
                NetMessage.SendData(17, -1, -1, "", 0, (float)x, (float)y);
            }
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:47,代码来源:KillTileMessage.cs

示例12: Process

        //TODO: redesign signs
        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int start = num - 1;
            short signIndex = BitConverter.ToInt16(readBuffer, num);
            num += 2;
            int x = BitConverter.ToInt32(readBuffer, num);
            num += 4;
            int y = BitConverter.ToInt32(readBuffer, num);
            num += 4;

            short existing = (short)Sign.ReadSign (x, y);
            if (existing >= 0)
                signIndex = existing;

            string SignText;
            if (!ParseString(readBuffer, num, length - num + start, out SignText))
                return; // invalid characters

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Sender = player,
                Player = player,
            };

            var args = new HookArgs.SignTextSet
            {
                X = x, Y = y,
                SignIndex = signIndex,
                Text = SignText,
                OldSign = Main.sign[signIndex],
            };

            HookPoints.SignTextSet.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick () || ctx.Result == HookResult.IGNORE)
                return;

            if (Main.sign[signIndex] == null) Main.sign[signIndex] = new Sign ();
            Main.sign[signIndex].x = args.X;
            Main.sign[signIndex].y = args.Y;
            Sign.TextSign (signIndex, args.Text);
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:46,代码来源:WriteSignMessage.cs

示例13: LoadPlugins

        public static void LoadPlugins()
        {
            ProgramLog.Log(Languages.Startup_LoadingPlugins);
            Terraria_Server.Plugins.PluginManager.Initialize(Statics.PluginPath, Statics.LibrariesPath);

            var ctx = new HookContext()
            {
                Sender = ConsoleSender = new ConsoleSender()
            };

            var eArgs = new HookArgs.ServerStateChange()
            {
                ServerChangeState = ServerState.INITIALIZING
            };

            HookPoints.ServerStateChange.Invoke(ref ctx, ref eArgs);
            PluginManager.LoadPlugins();
            ProgramLog.Log(Languages.Startup_PluginsLoaded + ' ' + PluginManager.PluginCount);
        }
开发者ID:BomllsJ,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:19,代码来源:Program.cs

示例14: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            int x = BitConverter.ToInt32(readBuffer, num);
            num += 4;
            int y = BitConverter.ToInt32(readBuffer, num);
            num += 4;

            int signIndex = Sign.ReadSign(x, y);

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Sender = player,
                Player = player,
            };

            var args = new HookArgs.SignTextGet
            {
                X = x, Y = y,
                SignIndex = (short)signIndex,
                Text = (signIndex >= 0 && Main.sign[signIndex] != null) ? Main.sign[signIndex].text : null,
            };

            HookPoints.SignTextGet.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick () || ctx.Result == HookResult.IGNORE)
                return;

            if (args.Text != null)
            {
                var msg = NetMessage.PrepareThreadInstance ();
                msg.WriteSign (signIndex, x, y, args.Text);
                msg.Send (whoAmI);
            }
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:37,代码来源:ReadSignMessage.cs

示例15: Process

        public override void Process(int whoAmI, byte[] readBuffer, int length, int num)
        {
            if (readBuffer[num++] != whoAmI)
            {
                NetPlay.slots[whoAmI].Kick ("Cheating detected (PLAYER_STATE_UPDATE forgery).");
                return;
            }

            var player = Main.players[whoAmI];

            var ctx = new HookContext
            {
                Connection = player.Connection,
                Sender = player,
                Player = player,
            };

            var args = new HookArgs.StateUpdateReceived ();

            args.Parse (readBuffer, num);

            HookPoints.StateUpdateReceived.Invoke (ref ctx, ref args);

            if (ctx.CheckForKick ())
                return;

            player.oldVelocity = player.Velocity;
            args.ApplyParams (player);
            args.ApplyKeys (player);
            player.fallStart = (int)(player.Position.Y / 16f);

            if (NetPlay.slots[whoAmI].state == SlotState.PLAYING)
            {
                NetMessage.SendData(13, -1, whoAmI, "", whoAmI);
            }
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:36,代码来源:PlayerStateUpdateMessage.cs


注:本文中的Terraria_Server.Plugins.HookContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。