public static void Sync(INetworker networker) { // For now, allowing both sides to push. This behaviour needs to be replaced in general anyways if (networker.Hosting || true) { var save = Scene.Current.FindComponent <GamePieces>()?.GetSave(); if (!save.HasValue || save.Value.Res == null) { Logs.Game.WriteWarning("Attempted to sync, but no gave save found."); OldContext.ShowNotification("Error", "Failed to start sync.", 3); } else { SendSave(networker, save.Value.Res); OldContext.ShowNotification("Info", "Sync started.", 3); } } else if (networker.Connected) { networker.SendData(CommandChannel, "Sync"); OldContext.ShowNotification("Info", "Sync requested.", 3); } else { Logs.Game.WriteWarning($"Cannot try to sync while {networker.Status.ToString().ToLower()}"); } }
private static void SendSave(INetworker networker, Save save) { using (var stream = new MemoryStream()) { Serializer.WriteObject(save, stream); // This seems a bit silly. Is there a better way to get a string from Duality's Serialization? // Especially since UTF8 is a reasonable guess, not a guarantee. networker.SendData(SaveChannel, Encoding.UTF8.GetString(stream.ToArray())); } }
public void EndTurn() { if (TurnEnded) { return; } TurnEnded = true; _inputMachine.SetState(null); _networker.SendData(EventCode.EndTurn, new EndTurnData { TurnNumber = TurnNumber }); _bus.Publish(new TurnBoundaryMessage(this, false)); }
public static void SendSpin(INetworker networker, float targetAngle, string name) { if (!networker.Connected) { return; } using (var stream = new MemoryStream()) { Serializer.WriteObject(new SpinMessage { Name = name, Angle = targetAngle }, stream); networker.SendData(SpinChannel, Encoding.UTF8.GetString(stream.ToArray())); } }
public static void SendMovement(INetworker networker, DragAction action, string name, Vector3?pos = null) { if (!networker.Connected) { return; } using (var stream = new MemoryStream()) { Serializer.WriteObject(new DragMessage { Action = action, Name = name, Pos = pos }, stream); networker.SendData(DragChannel, Encoding.UTF8.GetString(stream.ToArray())); } }
public static void SendDiceRoll(INetworker networker, string diceID, float time, int side) { if (!networker.Connected) { return; } using (var stream = new MemoryStream()) { Serializer.WriteObject(new DiceMessage { Time = time, DiceID = diceID, Side = side }, stream); networker.SendData(DiceChannel, Encoding.UTF8.GetString(stream.ToArray())); } }