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):
InteractionPkt Interaction = new InteractionPkt();
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) {
((Interactable) Target).Interact();
} else {

View File

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