Exemplo n.º 1
0
        public async Task Connect()
        {
            Protocol = new Protocol(true);

            socket = new Websocket(Receive);

            ApiToken = await FFB.Instance.Api.GetToken();

            try
            {
                string uri = "ws://fumbbl.com:22223/command";
                //string uri = "ws://localhost:22227/command";

                await Task.Delay(100);

                LogManager.Info($"Networking Connecting to {uri}");
                MainHandler.Instance.AddReport(RawString.Create($"Connecting to {uri}"));
                await socket.Connect(uri);

                LogManager.Debug("Networking Connected");

                RequestVersion();
            }
            catch (Exception e)
            {
                LogManager.Error($"<style=\"Error\">Error connecting: {e.Message}</style>");
                MainHandler.Instance.AddReport(RawString.Create($"<style=\"Error\">Error connecting: {e.Message}</style>"));
            }
        }
Exemplo n.º 2
0
    private void DebugClicked(ClickEvent ev)
    {
        FFB.Instance.Model.HomeCoach = new Coach()
        {
            Name   = "Foo",
            IsHome = true
        };

        FFB.Instance.Model.AwayCoach = new Coach()
        {
            Name   = "Bar",
            IsHome = false
        };


        ev.StopPropagation();
        var pos = new Fumbbl.Model.Types.Position();

        pos.IconURL     = "i/585610";
        pos.PortraitURL = "i/318621";
        Player p = new Player();

        p.Position    = pos;
        p.Id          = "Debug Player " + UnityEngine.Random.Range(1, 1000);
        p.Coordinate  = new Coordinate(UnityEngine.Random.Range(1, 25), UnityEngine.Random.Range(1, 14));
        p.PlayerState = PlayerState.Get(UnityEngine.Random.Range(1, 5));
        FFB.Instance.Model.Add(p);

        var trackNumber = new TrackNumber()
        {
            Coordinate = new Coordinate(UnityEngine.Random.Range(1, 25), UnityEngine.Random.Range(1, 14)),
            Number     = UnityEngine.Random.Range(1, 10)
        };

        FFB.Instance.Model.Add(trackNumber);

        var pushbackSquare = new PushbackSquare()
        {
            Coordinate = new Coordinate(UnityEngine.Random.Range(1, 25), UnityEngine.Random.Range(1, 14)),
            Direction  = "West"
        };

        FFB.Instance.Model.Add(pushbackSquare);

        FFB.Instance.Model.ActingPlayer.PlayerId = p.Id;

        for (int i = 0; i < 20; i++)
        {
            FFB.Instance.AddReport(RawString.Create($"<b>* * * Test message {i} * * *</b>"));
            FFB.Instance.AddChatEntry(i % 2 == 0 ? "Foo" : "Bar", $"Test Chat message {i} - long line to force line wrapping to happen... Blah blah blah.");
        }
    }
Exemplo n.º 3
0
        internal void HandleNetCommand(NetCommand netCommand)
        {
            var commandHandler = CommandFactory.GetReflectedInstance(netCommand.GetType());

            if (commandHandler != null)
            {
                commandHandler.HandleCommand(netCommand);
            }
            else
            {
                FFB.Instance.AddReport(RawString.Create($"Missing handler for NetCommand {netCommand.GetType().Name}"));
            }
        }
Exemplo n.º 4
0
        public override void Apply(Ffb.Dto.Commands.ServerModelSync command)
        {
            var list = command?.modelChangeList?.modelChangeArray;

            if (list != null)
            {
                foreach (var obj in list)
                {
                    ModelChange change = FFB.Instance.ModelChangeFactory.DeserializeJson(obj, obj?["modelChangeId"]?.ToString());
                    if (change != null)
                    {
                        FFB.Instance.Model.ApplyChange(change);
                    }
                    else
                    {
                        FFB.Instance.AddReport(RawString.Create($"<b>* * * Missing DTO for ModelChange {obj?["modelChangeId"]} * * *</b>"));
                    }
                }
            }

            list = command?.reportList?.reports;
            if (list != null)
            {
                foreach (var obj in list)
                {
                    Report report = FFB.Instance.ReportFactory.DeserializeJson(obj, obj?["reportId"]?.ToString());
                    if (report != null)
                    {
                        FFB.Instance.AddReport(report);
                    }
                    else
                    {
                        FFB.Instance.AddReport(RawString.Create($"<b>* * * Missing DTO for Report {obj?["reportId"]} * * *</b>"));
                    }
                }
            }

            var sound = command?.sound.key;

            if (!string.IsNullOrEmpty(sound))
            {
                FFB.Instance.PlaySound(sound);
            }
        }
Exemplo n.º 5
0
        private void Receive(string data)
        {
            string  message = Protocol.Decompress(data);
            JObject obj     = JObject.Parse(message);

            if (obj?["netCommandId"].ToString() == "serverModelSync")
            {
            }

            NetCommand netCommand = NetCommandFactory.DeserializeJson(obj, obj?["netCommandId"]?.ToString());

            if (netCommand != null)
            {
                FFB.Instance.HandleNetCommand(netCommand);
            }
            else
            {
                FFB.Instance.AddReport(RawString.Create($"<b>* * * Missing DTO for NetCommand {obj?["netCommandId"]} * * *</b>"));
            }
        }
Exemplo n.º 6
0
 public override void Apply(Ffb.Dto.Commands.ServerJoin command)
 {
     FFB.Instance.AddReport(RawString.Create($"{command.clientMode} {command.coach} joins the game"));
 }
Exemplo n.º 7
0
 public override void Apply(Ffb.Dto.Commands.ServerVersion command)
 {
     FFB.Instance.AddReport(RawString.Create($"Connected - Server version {command.serverVersion}"));
     FFB.Instance.Network.Spectate(FFB.Instance.GameId);
 }