本文整理汇总了C#中Terraria_Server.Plugins.HookContext.CheckForKick方法的典型用法代码示例。如果您正苦于以下问题:C# HookContext.CheckForKick方法的具体用法?C# HookContext.CheckForKick怎么用?C# HookContext.CheckForKick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terraria_Server.Plugins.HookContext
的用法示例。
在下文中一共展示了HookContext.CheckForKick方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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]);
}
示例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);
}
}
示例3: 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 ();
}
示例4: 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;
}
}
示例5: 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);
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
}
示例9: 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);
}
示例10: 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);
}
}
示例11: 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);
}
}
示例12: StrikeNPC
/// <summary>
/// Damages the NPC
/// </summary>
/// <param name="aggressor">Sender who struck the NPC</param>
/// <param name="Damage">Damage to calculate</param>
/// <param name="knockBack">Knockback amount</param>
/// <param name="hitDirection">Direction of strike</param>
/// <param name="crit">If the hit was critical</param>
/// <returns>Amount of damage actually done</returns>
public bool StrikeNPC(ISender aggressor, int Damage, float knockBack, int hitDirection, bool crit = false)
{
if (!this.Active || this.life <= 0)
{
return false;
}
var proj = aggressor as Projectile;
var ctx = new HookContext
{
Sender = aggressor,
Player = proj != null ? (proj.Creator as Player) : (aggressor as Player),
};
ctx.Connection = ctx.Player != null ? ctx.Player.Connection : null;
var args = new HookArgs.NpcHurt
{
Victim = this,
Damage = Damage,
HitDirection = hitDirection,
Knockback = knockBack,
Critical = crit,
};
HookPoints.NpcHurt.Invoke (ref ctx, ref args);
if (ctx.CheckForKick () || ctx.Result == HookResult.IGNORE)
return false;
StrikeNPCInternal (args.Damage, args.Knockback, args.HitDirection, args.Critical);
return true;
}
示例13: OnPlayerJoined
public static void OnPlayerJoined(int plr)
{
var player = Main.players[plr];
var ctx = new HookContext
{
Connection = player.Connection,
Player = player,
Sender = player,
};
var args = new HookArgs.PlayerEnteringGame
{
Slot = plr,
};
HookPoints.PlayerEnteringGame.Invoke (ref ctx, ref args);
if (ctx.CheckForKick ())
{
return;
}
var msg = NetMessage.PrepareThreadInstance ();
var motd = Program.properties.Greeting.Split('@');
for (int i = 0; i < motd.Length; i++)
{
if (motd[i] != null && motd[i].Trim().Length > 0)
{
msg.PlayerChat (255, motd[i], 0, 0, 255);
}
}
string list = "";
for (int i = 0; i < 255; i++)
{
if (Main.players[i].Active)
{
if (list == "")
list += Main.players[i].Name;
else
list = list + ", " + Main.players[i].Name;
}
}
msg.PlayerChat (255, "Current players: " + list + ".", 255, 240, 20);
msg.Send (plr); // send these before the login event, so messages from plugins come after
var slot = NetPlay.slots[plr];
slot.announced = true;
// to player
msg.Clear();
msg.SendSyncOthersForPlayer (plr);
ProgramLog.Users.Log ("{0} @ {1}: ENTER {2}", slot.remoteAddress, plr, player.Name);
if (player.HasHackedData())
{
player.Kick("No Hacked Health or Mana is allowed.");
}
// to other players
msg.Clear();
msg.PlayerChat (255, player.Name + " has joined.", 255, 240, 20);
msg.ReceivingPlayerJoined (plr);
msg.SendSyncPlayerForOthers (plr); // broadcasts the preceding message too
var args2 = new HookArgs.PlayerEnteredGame
{
Slot = plr,
};
ctx.SetResult (HookResult.DEFAULT);
HookPoints.PlayerEnteredGame.Invoke (ref ctx, ref args2);
if (ctx.CheckForKick ())
{
return;
}
}
示例14: Process
public override void Process(ClientConnection conn, byte[] readBuffer, int length, int num)
{
int start = num - 1;
string password = Encoding.ASCII.GetString(readBuffer, num, length - num + start);
if (conn.State == SlotState.SERVER_AUTH)
{
var ctx = new HookContext
{
Connection = conn,
};
var args = new HookArgs.ServerPassReceived
{
Password = password,
};
HookPoints.ServerPassReceived.Invoke (ref ctx, ref args);
if (ctx.CheckForKick ())
return;
if (ctx.Result == HookResult.ASK_PASS)
{
var msg = NetMessage.PrepareThreadInstance ();
msg.PasswordRequest ();
conn.Send (msg.Output);
}
else if (ctx.Result == HookResult.CONTINUE || password == NetPlay.password)
{
conn.State = SlotState.ACCEPTED;
var msg = NetMessage.PrepareThreadInstance ();
msg.ConnectionResponse (253 /* dummy value, real slot assigned later */);
conn.Send (msg.Output);
return;
}
conn.Kick ("Incorrect server password.");
}
else if (conn.State == SlotState.PLAYER_AUTH)
{
var name = conn.Player.Name ?? "";
var ctx = new HookContext
{
Connection = conn,
Player = conn.Player,
Sender = conn.Player,
};
var args = new HookArgs.PlayerPassReceived
{
Password = password,
};
HookPoints.PlayerPassReceived.Invoke (ref ctx, ref args);
if (ctx.CheckForKick ())
return;
if (ctx.Result == HookResult.ASK_PASS)
{
var msg = NetMessage.PrepareThreadInstance ();
msg.PasswordRequest ();
conn.Send (msg.Output);
}
else // HookResult.DEFAULT
{
var lower = name.ToLower();
bool reserved = false;
//conn.Queue = (int)loginEvent.Priority;
foreach (var otherPlayer in Main.players)
{
//var otherSlot = Netplay.slots[otherPlayer.whoAmi];
var otherConn = otherPlayer.Connection;
if (otherPlayer.Name != null
&& lower == otherPlayer.Name.ToLower()
&& otherConn != null
&& otherConn.State >= SlotState.CONNECTED)
{
if (! reserved)
{
reserved = SlotManager.HandoverSlot (otherConn, conn);
}
otherConn.Kick ("Replaced by new connection.");
}
}
//conn.State = SlotState.SENDING_WORLD;
if (! reserved) // reserved slots get assigned immediately during the kick
{
SlotManager.Schedule (conn, conn.DesiredQueue);
}
//NetMessage.SendData (4, -1, whoAmI, name, whoAmI); // broadcast player data now
//.........这里部分代码省略.........
示例15: OpenDoor
public static bool OpenDoor(int x, int y, int direction, ISender sender)
{
if (sender == null)
{
sender = new ConsoleSender();
}
if (Program.properties.NPCDoorOpenCancel && sender is NPC)
return false;
var ctx = new HookContext
{
Sender = sender,
};
var args = new HookArgs.DoorStateChanged
{
X = x, Y = y,
Direction = direction,
Open = true,
};
HookPoints.DoorStateChanged.Invoke (ref ctx, ref args);
if (ctx.CheckForKick ())
return false;
if (ctx.Result == HookResult.IGNORE)
return false;
if (ctx.Result == HookResult.RECTIFY)
{
NetMessage.SendData(19, -1, -1, "", 1, (float)x, (float)y, 0); //Inform the client of the update
return false;
}
int num = 0;
if (Main.tile.At(x, y - 1).FrameY == 0 && Main.tile.At(x, y - 1).Type == Main.tile.At(x, y).Type)
{
num = y - 1;
}
else if (Main.tile.At(x, y - 2).FrameY == 0 && Main.tile.At(x, y - 2).Type == Main.tile.At(x, y).Type)
{
num = y - 2;
}
else if (Main.tile.At(x, y + 1).FrameY == 0 && Main.tile.At(x, y + 1).Type == Main.tile.At(x, y).Type)
{
num = y + 1;
}
else
{
num = y;
}
int num2 = x;
short num3 = 0;
int num4;
if (direction == -1)
{
num2 = x - 1;
num3 = 36;
num4 = x - 1;
}
else
{
num2 = x;
num4 = x + 1;
}
bool flag = true;
for (int k = num; k < num + 3; k++)
{
if (Main.tile.At(num4, k).Active)
{
if (Main.tile.At(num4, k).Type != 3 && Main.tile.At(num4, k).Type != 24 && Main.tile.At(num4, k).Type != 52 && Main.tile.At(num4, k).Type != 61 && Main.tile.At(num4, k).Type != 62 && Main.tile.At(num4, k).Type != 69 && Main.tile.At(num4, k).Type != 71 && Main.tile.At(num4, k).Type != 73 && Main.tile.At(num4, k).Type != 74)
{
flag = false;
break;
}
WorldModify.KillTile(num4, k, false, false, false);
}
}
if (flag)
{
Main.tile.At(num2, num).SetActive (true);
Main.tile.At(num2, num).SetType (11);
Main.tile.At(num2, num).SetFrameY (0);
Main.tile.At(num2, num).SetFrameX (num3);
Main.tile.At(num2 + 1, num).SetActive (true);
Main.tile.At(num2 + 1, num).SetType (11);
Main.tile.At(num2 + 1, num).SetFrameY (0);
Main.tile.At(num2 + 1, num).SetFrameX ((short)(num3 + 18));
Main.tile.At(num2, num + 1).SetActive (true);
Main.tile.At(num2, num + 1).SetType (11);
Main.tile.At(num2, num + 1).SetFrameY (18);
Main.tile.At(num2, num + 1).SetFrameX (num3);
Main.tile.At(num2 + 1, num + 1).SetActive (true);
Main.tile.At(num2 + 1, num + 1).SetType (11);
Main.tile.At(num2 + 1, num + 1).SetFrameY (18);
Main.tile.At(num2 + 1, num + 1).SetFrameX ((short)(num3 + 18));
Main.tile.At(num2, num + 2).SetActive (true);
Main.tile.At(num2, num + 2).SetType (11);
//.........这里部分代码省略.........