Skip to content

Commit

Permalink
0.2.1, snoop now lets you take and place items. Icon. Right click tex…
Browse files Browse the repository at this point in the history
…tbox to clear. Fix tab for login.
  • Loading branch information
JavidPack committed Jul 12, 2018
1 parent e45fc75 commit 86ae136
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 12 deletions.
9 changes: 7 additions & 2 deletions HEROsModNetwork/GeneralMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public static void ProcessData(ref BinaryReader reader, int playerNumber)
case MessageType.RequestTeleport:
ProcessRequestTeleport(ref reader, playerNumber);
break;

case MessageType.SyncItemNonOwner:
HEROsModServices.SnoopWindow.ProcessSyncItemNonOwner(ref reader, playerNumber);
break;
}
}

Expand Down Expand Up @@ -1222,7 +1226,7 @@ public static void RequestTeleport(Vector2 destination)
Network.SendDataToServer();
}

private enum MessageType : byte
internal enum MessageType : byte
{
UsingHEROsMod,
RequestTimeChange,
Expand Down Expand Up @@ -1267,7 +1271,8 @@ private enum MessageType : byte
RequestBanPlayer,
RequestTeleport,
RequestForcedSundial,
CurrentToggles
CurrentToggles,
SyncItemNonOwner
}

public enum TimeChangeType
Expand Down
1 change: 1 addition & 0 deletions HEROsModNetwork/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ public enum MessageType
{
GeneralMessage,
LoginMessage,
SnoopMessage,
CTFMessage
}

Expand Down
81 changes: 72 additions & 9 deletions HEROsModServices/PlayerList.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using HEROsMod.UIKit;
using HEROsMod.UIKit.UIComponents;
using System;
using System.IO;
using System.Linq;
using Terraria;
using HEROsMod.HEROsModNetwork;

namespace HEROsMod.HEROsModServices
{
Expand Down Expand Up @@ -416,7 +418,7 @@ private void dropdown_selectedChanged(object sender, EventArgs e)
}
else
{
//send new group to servera
//send new group to server
HEROsModNetwork.Group playersNewGroup = HEROsModNetwork.Network.GetGroupByName(dropdown.GetItem(dropdown.SelectedItem));
HEROsModNetwork.LoginService.RequestSetPlayerGroup(playerIndex, playersNewGroup);
}
Expand Down Expand Up @@ -453,8 +455,10 @@ public SnoopWindow()
//itemsView.Y = spacing;
for (int i = 0; i < 50; i++)
{
Slot slot = new Slot(0, true);
slot.ItemChanged += ItemSlot_ItemChanged;
Slot slot = new Slot(0, false);
slot.functionalSlot = true;
int index = i;
slot.ItemChanged += (a, b) => ItemSlot_ItemChanged(slot, index);
slot.X = 8 + i % 10 * slot.Width;
slot.Y = 8 + i / 10 * slot.Height;

Expand All @@ -465,20 +469,28 @@ public SnoopWindow()
for (int i = 50; i < 58; i++)
{
int index = i - 50;
Slot slot = new Slot(0, true);
Slot slot = new Slot(0, false);
slot.functionalSlot = true;
int idx = i;
slot.ItemChanged += (a, b) => ItemSlot_ItemChanged(slot, idx);
slot.Scale = .6f;
slot.X = 8 + index % 2 * slot.Width;
slot.Y = yPos + index / 2 * slot.Height;
itemsView.AddChild(slot);
}
Slot mouseSlot = new Slot(0, true);
Slot mouseSlot = new Slot(0, false);
mouseSlot.functionalSlot = true;
mouseSlot.ItemChanged += (a, b) => ItemSlot_ItemChanged(mouseSlot, 58);
mouseSlot.X = itemsView.GetLastChild().X + itemsView.GetLastChild().Width + 4;
mouseSlot.Y = itemsView.GetLastChild().Y + itemsView.GetLastChild().Height - mouseSlot.Height;
itemsView.AddChild(mouseSlot);
float xPos = mouseSlot.X + mouseSlot.Width + 4;
for (int i = 0; i < 16; i++)
{
Slot slot = new Slot(0, true);
Slot slot = new Slot(0, false);
slot.functionalSlot = true;
int index = i;
slot.ItemChanged += (a, b) => ItemSlot_ItemChanged(slot, index, true);
slot.Scale = .7f;
slot.X = xPos + i % 8 * slot.Width;
slot.Y = yPos + i / 8 * slot.Height;
Expand All @@ -498,10 +510,10 @@ public SnoopWindow()
itemsView.AddChild(label);
}

private void ItemSlot_ItemChanged(object sender, EventArgs e)
private void ItemSlot_ItemChanged(Slot slot, int index, bool armor = false)
{
Slot slot = (Slot)sender;

Main.playerInventory = true;
RequestSyncItemNonOwner(player, slot.item, index + (armor ? 59 : 0));
//ErrorLogger.Log("Slot " + slot.item.type);
}

Expand All @@ -527,5 +539,56 @@ public void SetPlayer(Player player)
{
this.player = player;
}

internal static void RequestSyncItemNonOwner(Player player, Item item, int index)
{
var packet = HEROsMod.instance.GetPacket();
packet.Write((byte)Network.MessageType.GeneralMessage);
packet.Write((byte)GeneralMessages.MessageType.SyncItemNonOwner);
packet.Write((byte)player.whoAmI);
packet.Write((byte)index);
Terraria.ModLoader.IO.ItemIO.Send(item, packet, true);
packet.Send();
}

internal static void ProcessSyncItemNonOwner(ref BinaryReader reader, int playerNumber)
{
if (Main.netMode == Terraria.ID.NetmodeID.Server)
{
if (Network.Players[playerNumber].Group.HasPermission("Snoop"))
{
byte player = reader.ReadByte();
int inventoryindex = reader.ReadByte();
Item item = Terraria.ModLoader.IO.ItemIO.Receive(reader, true);

var packet = HEROsMod.instance.GetPacket();
packet.Write((byte)Network.MessageType.GeneralMessage);
packet.Write((byte)GeneralMessages.MessageType.SyncItemNonOwner);
packet.Write((byte)player);
packet.Write((byte)inventoryindex);
Terraria.ModLoader.IO.ItemIO.Send(item, packet, true);
packet.Send(player);
}
}
else
{
byte player = reader.ReadByte();
int inventoryindex = reader.ReadByte();
Item item = Terraria.ModLoader.IO.ItemIO.Receive(reader, true);

if (player == Main.myPlayer)
{
if (inventoryindex < 59)
Main.LocalPlayer.inventory[inventoryindex] = item;
else
Main.LocalPlayer.armor[inventoryindex - 59] = item;
// send 5 or just let clientClone take care of it?
}
else
{
// Bug
}
}
}
}
}
1 change: 1 addition & 0 deletions UIKit/UITextbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private string passwordString
public UITextbox()
{
this.onLeftClick += new EventHandler(UITextbox_onLeftClick);
this.onRightClick += (a, b) => Text = "";
label.ForegroundColor = Color.Black;
label.Scale = Height / label.Height;
label.TextOutline = false;
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = HERO, jopojelly
version = 0.2.0.4
version = 0.2.1
displayName = HERO's Mod
homepage = http://forums.terraria.org/index.php?threads/heros-mod-creative-mode-server-management-and-over-25-tools-1-3-1-1-compatible.44650/
buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, tmod\*, ignore\*, ZVidBuild\*, Images\Old*, Images\AllIcons.psd, .git\*, LICENSE, .gitignore
Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 86ae136

Please sign in to comment.