/// <summary> /// Send all the values to a specified client. /// </summary> /// <param name="clientId">The client that needs the values.</param> protected override sealed void SendAllToClient(ulong clientId) { if (!MyAPIGateway.Multiplayer.IsServer) { alwaysLog("Cannot send values, this is not the server", Logger.severity.ERROR); return; } foreach (KeyValuePair <long, TScript> pair in Registrar.IdScripts <TScript>()) { TValue value = _getter(pair.Value); if (!IsDefault(value)) { SendValue(pair.Key, value, clientId); } } }
protected override sealed void WriteToSave(List <byte> bytes) { if (!MyAPIGateway.Multiplayer.IsServer) { alwaysLog("Cannot write values, this is not the server", Logger.severity.ERROR); return; } Dictionary <TValue, List <long> > values = new Dictionary <TValue, List <long> >(); foreach (KeyValuePair <long, TScript> pair in Registrar.IdScripts <TScript>()) { TValue v = _getter(pair.Value); if (IsDefault(v)) { continue; } List <long> ids; if (!values.TryGetValue(v, out ids)) { ids = new List <long>(); values.Add(v, ids); } ids.Add(pair.Key); } ByteConverter.AppendBytes(bytes, values.Count); foreach (KeyValuePair <TValue, List <long> > valueEntity in values) { ByteConverter.AppendBytes(bytes, valueEntity.Key); ByteConverter.AppendBytes(bytes, valueEntity.Value.Count); foreach (long entity in valueEntity.Value) { ByteConverter.AppendBytes(bytes, entity); } } }