- Protocol: SpanWriter/SpanReader, frame [u32][u16][payload], tutti i messaggi dei due versi con byte di estensione, codec di tutti i 38 comandi, test di round-trip, troncamento e corruzione. - Comandi delle fasi successive con formato definitivo (NotImplemented). - ClientWorld e ProtocolClient condivisi da client Godot e test: copia del terreno a chunk, entità, rete con gli stessi id, moto dei treni. - TrackPreview estratto dai comandi: anteprima del client e piano del server con lo stesso codice; stazioni e depositi demoliti esclusi dagli agganci. - Server: GameLoop con accumulatore e velocità effettiva, sessioni con coda a due classi e ripresa, delta per hash, TrackWorks a lotti, moto dei treni nel viewport, resoconti giornalieri, /health, /metrics, /api/saves, autosave a rotazione, log JSON, --local e --healthcheck. - Docker: Dockerfile, compose, modello Unraid; build senza rete. - viaferrea-tools smoke: collaudo end-to-end contro un server in esecuzione. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
36 lines
1.7 KiB
C#
36 lines
1.7 KiB
C#
namespace ViaFerrea.Protocol.Messages;
|
|
|
|
/// <summary>Decodifica per id: l'unico punto in cui un id diventa un tipo.</summary>
|
|
public static class MessageCodec
|
|
{
|
|
public static IMessage Read(MessageId id, ref SpanReader r) => id switch
|
|
{
|
|
MessageId.Hello => Hello.Read(ref r),
|
|
MessageId.Ping => Ping.Read(ref r),
|
|
MessageId.Subscribe => Subscribe.Read(ref r),
|
|
MessageId.Command => CommandMessage.Read(ref r),
|
|
MessageId.SetSpeed => SetSpeed.Read(ref r),
|
|
MessageId.ListSaves => ListSaves.Read(ref r),
|
|
MessageId.Save => Save.Read(ref r),
|
|
MessageId.Load => Load.Read(ref r),
|
|
MessageId.NewGame => NewGame.Read(ref r),
|
|
MessageId.Welcome => Welcome.Read(ref r),
|
|
MessageId.Reject => Reject.Read(ref r),
|
|
MessageId.Pong => Pong.Read(ref r),
|
|
MessageId.MapChunk => MapChunk.Read(ref r),
|
|
MessageId.EntitySnapshot => EntitySnapshot.Read(ref r),
|
|
MessageId.EntityDelta => EntityDelta.Read(ref r),
|
|
MessageId.TrackWorks => TrackWorks.Read(ref r),
|
|
MessageId.TrainMotion => TrainMotion.Read(ref r),
|
|
MessageId.DailyDigest => DailyDigest.Read(ref r),
|
|
MessageId.MaintenanceAlert => MaintenanceAlert.Read(ref r),
|
|
MessageId.EmploymentReport => EmploymentReport.Read(ref r),
|
|
MessageId.MarketTape => MarketTape.Read(ref r),
|
|
MessageId.CommandResult => CommandResultMessage.Read(ref r),
|
|
MessageId.Notification => Notification.Read(ref r),
|
|
MessageId.Newspaper => Newspaper.Read(ref r),
|
|
MessageId.SaveList => SaveList.Read(ref r),
|
|
_ => throw new ProtocolException($"messaggio sconosciuto: {(ushort)id}"),
|
|
};
|
|
}
|