barebones-masterserver icon indicating copy to clipboard operation
barebones-masterserver copied to clipboard

Observable Dictionaries not being updated on clients.

Open leonardochaia opened this issue 8 years ago • 2 comments

Hi, I've been playing around with the ProfilesModule and I've found that the ObservableDictionary classes will not send its changes back to clients once the MasterServer receives them. This is because the updates queue is not being updated when changes arrive at the MasterServer. Other observables work fine since they always send their primitive value.

I've created a branch on my fork to reproduce the issue. I've modified the ProfilesTestScript in order to reproduce the bug. When the FillProfileValues finishes on the game server imitation, AddWood will be called which will increment the Wood key in the _serverInventory.

These changes are sent to the MasterServer, and it ApplyUpdate to the edited profile. But since those changes aren't done by using the SetValue/Remove methods, the _updates queue in the dictionary is not change.

When the ProfilesModule does the SendUpdatesToClient, and eventually calls the GetUpdates of every property in the profile, the ObservableDictionary has no UpdateEntry on its _update so nothing is sent back to clients.

I've created the PR #137 so it's easy for us to apply the needed changes, which I'm looking for some guidance on.

I've fixed the issue by adding the proper UpdateEntry to the queue when the ApplyUpdates method is called on the ObservableDictionary. This is working fine, but maybe this should only be done on the MasterServer and not on the client/gameserver? Do you see any infinite-loop possible, where updates keeps being sent over the network?

public override void ApplyUpdates(byte[] data)
{
	using (var ms = new MemoryStream(data))
	{
		using (var reader = new EndianBinaryReader(EndianBitConverter.Big,ms))
		{
			var count = reader.ReadInt32();

			for (var i = 0; i 
					_updates.Enqueue(new UpdateEntry()
					{
						Key = key,
						Operation = RemoveOperation,
					});

					continue;
				}

				var value = reader.ReadString();

				if (_values.ContainsKey(key))
				{
					_values[key] = value;
				}
				else
				{
					_values.Add(key, value);
				}
				 _updates.Enqueue(new UpdateEntry()
				{
					Key = key,
					Operation =  SetOperation,
					Value = value
				});
			}
		}
	}
	MarkDirty();
}

leonardochaia avatar Sep 11 '17 18:09 leonardochaia

I believe we can close this issue, as this have been merged to the main branch, doesn't it?

joaoborks avatar Dec 28 '17 20:12 joaoborks

This hasn't been merged. It definitely needs fixing, had exactly this issue.

achia avatar Jan 27 '18 09:01 achia