Exemple #1
0
    private void OnMsgRecv(object sender, Server.ServerMsgEventArgs e)
    {
        if (!connectionManager.Contains(e.Client))
        {
            // Do this only if it is a new connection
            Packet p = PacketBuilder.Build(Packet.PacketType.Text, Constants.WelcomeMsg);
            server.Send(e.Client, p.ToArray(), p.Size);
            //Debug.Log("[S->C]: Welcome");

            Trans spawn = spawnTrans[connectionManager.Count % spawnTrans.Count];
            p = PacketBuilder.Build(Packet.PacketType.Spawn, spawn);
            server.Send(e.Client, p.ToArray(), p.Size);
            //Debug.Log("[S->C]: Spawn");
        }
        Connection connection = connectionManager.AddOrUpdateConnection(e.Client);

        int    dataIndex = 0;
        Packet packet    = PacketBuilder.Parse(e.Buffer, ref dataIndex);

        switch (packet.Type)
        {
        case Packet.PacketType.Text:
            string text = ((PacketText)packet).Data;
            if (text == Constants.ServeRequest)
            {
                Debug.Log("Serving Ball");
                ballController.serve = true;
            }
            Debug.Log("[C(" + e.Client + ")->S]: " + text
                      + " (" + packet.Size + " of " + e.Len + " bytes)");
            foreach (var c in connectionManager.Connections)
            {
                if (c.endPoint == e.Client)
                {
                    continue;
                }

                server.Send(c.endPoint, packet.ToArray(), packet.Size);
            }
            break;

        case Packet.PacketType.Sensors:
            List <Trans> transforms = ((PacketSensors)packet).Data;
            connection.clientData.Update(transforms);
            break;

        case Packet.PacketType.Benchmark:
            NetBenchmarks b = ((PacketBenchmark)packet).Data;
            Debug.Log("RTT: " + (b.recvTimeStamp - b.sendTimeStamp) + " ms.");
            break;

        default:
            Debug.Assert(false);
            Debug.LogError("Invalid PacketType" + " (" + packet.Size + " of " + e.Len + " bytes)");
            break;
        }
    }
Exemple #2
0
        public void Save(IConnectionViewModel connectionViewModel)
        {
            Shell.AssertIsOnMainThread();
            if (connectionViewModel == null || !connectionViewModel.HasChanges)
            {
                return;
            }

            if ((connectionViewModel.IsRenamed || IsEditingNew) &&
                ConnectionManager.GetConnection(connectionViewModel.Name) != null)
            {
                Shell.ShowMessage(Resources.ConnectionManager_CantSaveWithTheSameName.FormatCurrent(connectionViewModel.Name), MessageButtons.OK);
                return;
            }

            if (connectionViewModel.IsConnected)
            {
                var confirm = Shell.ShowMessage(Resources.ConnectionManager_RenameActiveConnectionConfirmation.FormatCurrent(connectionViewModel.OriginalName), MessageButtons.YesNo);
                if (confirm == MessageButtons.Yes)
                {
                    var message = Resources.ConnectionManager_RenameConnectionProgressBarMessage.FormatInvariant(connectionViewModel.OriginalName, connectionViewModel.Name);
                    try {
                        Shell.ProgressDialog.Show(ct => ConnectionManager.DisconnectAsync(ct), message);
                    } catch (OperationCanceledException) {
                        return;
                    }
                }
            }

            ConnectionManager.AddOrUpdateConnection(connectionViewModel);

            if (connectionViewModel.IsRenamed)
            {
                ConnectionManager.TryRemove(connectionViewModel.OriginalName);
            }

            EditedConnection = null;
            IsEditingNew     = false;
            UpdateConnections();
        }