Fix client receiving their own interaction messages

This commit is contained in:
Sofia 2017-05-11 05:03:07 +03:00
parent 8f8aec70e3
commit 810f6a428f
3 changed files with 18 additions and 6 deletions

View File

@ -200,8 +200,11 @@ namespace Cyber.Networking.Clientside {
case (PktType.InteractPkt): case (PktType.InteractPkt):
InteractionPkt Interaction = new InteractionPkt(); InteractionPkt Interaction = new InteractionPkt();
Interaction.Deserialize(msg.reader); Interaction.Deserialize(msg.reader);
if (Interaction.OwnerSyncBaseID == Player.Character.ID) {
break;
}
SyncBase Target = Spawner.SyncDB.Get(Interaction.SyncBaseID); SyncBase Target = Spawner.SyncDB.Get(Interaction.InteractSyncBaseID);
if (Target != null && Target is Interactable) { if (Target != null && Target is Interactable) {
((Interactable) Target).Interact(); ((Interactable) Target).Interact();
} else { } else {

View File

@ -11,14 +11,19 @@ namespace Cyber.Networking.Messages {
/// <summary> /// <summary>
/// ID of the interactible. /// ID of the interactible.
/// </summary> /// </summary>
public int SyncBaseID; public int InteractSyncBaseID;
/// <summary>
/// Id of the interactor.
/// </summary>
public int OwnerSyncBaseID;
/// <summary> /// <summary>
/// Creates an InteraktionPkt, which contains the message "someone interacted". /// Creates an InteraktionPkt, which contains the message "someone interacted".
/// </summary> /// </summary>
/// <param name="SyncBaseID"></param> /// <param name="SyncBaseID"></param>
public InteractionPkt(int syncBaseID) { public InteractionPkt(int syncBaseID) {
SyncBaseID = syncBaseID; InteractSyncBaseID = syncBaseID;
} }
/// <summary> /// <summary>
@ -31,7 +36,8 @@ namespace Cyber.Networking.Messages {
/// </summary> /// </summary>
/// <param name="reader"></param> /// <param name="reader"></param>
public override void Deserialize(NetworkReader reader) { public override void Deserialize(NetworkReader reader) {
SyncBaseID = reader.ReadInt32(); InteractSyncBaseID = reader.ReadInt32();
OwnerSyncBaseID = reader.ReadInt32();
} }
/// <summary> /// <summary>
@ -39,7 +45,8 @@ namespace Cyber.Networking.Messages {
/// </summary> /// </summary>
/// <param name="writer"></param> /// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) { public override void Serialize(NetworkWriter writer) {
writer.Write(SyncBaseID); writer.Write(InteractSyncBaseID);
writer.Write(OwnerSyncBaseID);
} }
} }

View File

@ -177,7 +177,9 @@ namespace Cyber.Networking.Serverside {
Interaction.Deserialize(msg.reader); Interaction.Deserialize(msg.reader);
Character Sender = Players[msg.conn.connectionId].Character; Character Sender = Players[msg.conn.connectionId].Character;
SyncBase Target = Spawner.SyncDB.Get(Interaction.SyncBaseID); SyncBase Target = Spawner.SyncDB.Get(Interaction.InteractSyncBaseID);
Interaction.OwnerSyncBaseID = Sender.ID;
if (Target != null && Target is Interactable) { if (Target != null && Target is Interactable) {
Interactable Interacted = (Interactable) Target; Interactable Interacted = (Interactable) Target;