Internally used by PUN. A LoadbalancingPeer provides the operations and enum definitions needed to use the loadbalancing server application which is also used in Photon Cloud.
The LoadBalancingPeer does not keep a state, instead this is done by a LoadBalancingClient.
상속: PhotonPeer
예제 #1
0
파일: DemoGUI.cs 프로젝트: mortske/Citadels
    public void OnApplicationPause(bool willPause)
    {
        if (willPause)
        {
            lock (threadClientLock)
            {
                threadClient = this.GameInstance;
            }
            thread = new Thread(this.SendAcks);
            thread.IsBackground = true;
            thread.Start();
        }
        else
        {
            lock (threadClientLock)
            {
                threadClient = null;
            }
        }


        LoadBalancingPeer lbPeer = this.GameInstance.loadBalancingPeer;

        Debug.Log("OnApplicationPause " + (willPause ? "SLEEP":"WAKE") + " time: " + DateTime.Now.ToLongTimeString() + " " + lbPeer.BytesIn + "in " + lbPeer.BytesOut + "out");


        if (!willPause)
        {
            lbPeer.Service();
            int timeSinceLastReceive = Environment.TickCount - lbPeer.TimestampOfLastSocketReceive;
            Debug.Log("IsConnectedAndReady: " + this.GameInstance.IsConnectedAndReady + " timeSinceLastReceive: " + timeSinceLastReceive);
        }
    }
예제 #2
0
 private void Awake()
 {
     networkHandler           = PhotonNetwork.NetworkingClient.LoadBalancingPeer;
     defaultTextColor         = additionalPingText.color;
     additionalPingText.color = Color.white;
     packetLossText.color     = Color.white;
 }
        // inspired by PhotonVoiceStatsGui.TrafficStatsWindow
        protected virtual void DisplayTrafficStats(LoadBalancingPeer peer)
        {
            this.showTrafficStats = EditorGUILayout.Foldout(this.showTrafficStats, new GUIContent("Traffic Stats", "Traffic Statistics for Photon Client"));
            if (this.showTrafficStats)
            {
                #if DEBUG_DISCARD
                if (peer.DeltaUnreliableNumber > this.maxDeltaUnreliableNumber)
                {
                    this.maxDeltaUnreliableNumber = peer.DeltaUnreliableNumber;
                }
                if (peer.CountDiscarded > this.maxCountDiscarded)
                {
                    this.maxCountDiscarded = peer.CountDiscarded;
                }
                GUILayout.Label(string.Format("Discarded: {0} (max: {1}) UnreliableDelta: {2} (max: {3})", peer.CountDiscarded, this.maxCountDiscarded, peer.DeltaUnreliableNumber, maxDeltaUnreliableNumber));
                #endif

                peer.TrafficStatsEnabled = EditorGUILayout.Toggle(new GUIContent("Enabled", "Enable or disable traffic Statistics for Photon Peer"), peer.TrafficStatsEnabled);
                if (peer.TrafficStatsEnabled)
                {
                    GUILayout.Box("Game Level Stats");
                    var  gls            = peer.TrafficStatsGameLevel;
                    long elapsedSeconds = peer.TrafficStatsElapsedMs / 1000;
                    if (elapsedSeconds == 0)
                    {
                        elapsedSeconds = 1;
                    }
                    GUILayout.Label(string.Format("Time elapsed: {0} seconds", elapsedSeconds));
                    GUILayout.Label(string.Format("Total: Out {0,4} | In {1,4} | Sum {2,4}",
                                                  gls.TotalOutgoingMessageCount,
                                                  gls.TotalIncomingMessageCount,
                                                  gls.TotalMessageCount));
                    GUILayout.Label(string.Format("Average: Out {0,4} | In {1,4} | Sum {2,4}",
                                                  gls.TotalOutgoingMessageCount / elapsedSeconds,
                                                  gls.TotalIncomingMessageCount / elapsedSeconds,
                                                  gls.TotalMessageCount / elapsedSeconds));
                    GUILayout.Box("Packets Stats");
                    GUILayout.Label(string.Concat("Incoming: \n", peer.TrafficStatsIncoming));
                    GUILayout.Label(string.Concat("Outgoing: \n", peer.TrafficStatsOutgoing));
                    GUILayout.Box("Health Stats");
                    GUILayout.Label(string.Format("ping: {0}[+/-{1}]ms resent:{2}",
                                                  peer.RoundTripTime,
                                                  peer.RoundTripTimeVariance,
                                                  peer.ResentReliableCommands));
                    GUILayout.Label(string.Format(
                                        "max ms between\nsend: {0,4} \ndispatch: {1,4} \nlongest dispatch for: \nev({3}):{2,3}ms \nop({5}):{4,3}ms",
                                        gls.LongestDeltaBetweenSending,
                                        gls.LongestDeltaBetweenDispatching,
                                        gls.LongestEventCallback,
                                        gls.LongestEventCallbackCode,
                                        gls.LongestOpResponseCallback,
                                        gls.LongestOpResponseCallbackOpCode));
                    if (GUILayout.Button("Reset"))
                    {
                        peer.TrafficStatsReset();
                    }
                }
            }
        }
예제 #4
0
파일: DemoGUI.cs 프로젝트: mortske/Citadels
    void OnApplicationQuit()
    {
        this.GameInstance.Disconnect();     // let's try to do a regular disconnect on app quit

        LoadBalancingPeer lbPeer = this.GameInstance.loadBalancingPeer;

        lbPeer.StopThread();   // for the Editor it's better stop any connection immediately
    }
예제 #5
0
    internal void SendPlayerInfo(LoadBalancingPeer peer)
    {
        if (peer == null)
        {
            return;
        }

        // Setting up the content of the event. Here we want to send a player's info: nickName and color.
        Hashtable eventInfo = new Hashtable();

        eventInfo.Add((byte)EventKey.PlayerName, this.NickName);
        eventInfo.Add((byte)EventKey.PlayerReady, this.PlayerReady);

        // The event's code must be of type byte, so we have to cast it. We do this above as well, to get routine ;)
        peer.OpRaiseEvent((byte)EventCode.PlayerInfo, eventInfo, null, SendOptions.SendReliable);
    }
예제 #6
0
        internal QuantumNetworkCommunicator(LoadBalancingPeer loadBalancingPeer, Boolean autoDisconnect)
        {
            _autoDisconenct = autoDisconnect;

            _loadBalancingPeer = loadBalancingPeer;
            _loadBalancingPeer.TimePingInterval = 50;

            _parameters = new Dictionary <Byte, Object>();
            _parameters[ParameterCode.ReceiverGroup] = (byte)ReceiverGroup.All;

            _eventOptions = new RaiseEventOptions();

            _sendOperationOptions = new SendOptions {
                DeliveryMode = DeliveryMode.ReliableUnsequenced
            };
        }
예제 #7
0
        /// <summary>
        /// Raises an event with the player's position data.
        /// "isSendReliable"        decides if these events are reliable or unreliable.
        /// "Game.RaiseEncrypted"   decided if the event is encrypted.
        ///
        /// Once more: Neither sending reliable nor encrypting this event makes sense in a game.
        /// Both is just done as showcase!
        /// </summary>
        /// <remarks>
        /// Each running client will know many players, but only one is the "local" one, which
        /// actually sends it's position! See Game.SendPostion(), which choses the local player only.
        /// </remarks>
        /// <param name="peer"></param>
        internal void SendEvMove(LoadBalancingPeer peer)
        {
            if (peer == null)
            {
                return;
            }

            // prepare the event data we want to send
            // this could contain more key-values as needed by a game (think: rotation, y-coordinate)
            Hashtable eventContent = new Hashtable();

            eventContent.Add((byte)DemoEventKey.PlayerPositionX, (byte)this.posX);
            eventContent.Add((byte)DemoEventKey.PlayerPositionY, (byte)this.posY);

            // if encryption is turned off, we simply use OpRaiseEvent
            peer.OpRaiseEvent((byte)DemoEventCode.PlayerMove, eventContent, isSendReliable, null);
        }
예제 #8
0
    internal void SendPlayerLocation(LoadBalancingPeer peer)
    {
        if (peer == null)
        {
            return;
        }

        Hashtable eventContent = new Hashtable();

        eventContent.Add((byte)EventKey.PlayerPositionX, (float)this.XPosition);
        eventContent.Add((byte)EventKey.PlayerPositionY, (float)this.YPosition);

        peer.OpRaiseEvent((byte)EventCode.PlayerMove, eventContent, new RaiseEventOptions {
            Receivers = ReceiverGroup.All
        }, new SendOptions()
        {
            DeliveryMode = DeliveryMode.UnreliableUnsequenced
        });
    }
    public void SendClaimWin()
    {
        var player = (RealtimePlayer)LocalPlayer;

        if (LoadBalancingPeer == null)
        {
            return;
        }

        Hashtable eventContent = new Hashtable();

        eventContent.Add((byte)EventKey.PlayerName, player.NickName);

        LoadBalancingPeer.OpRaiseEvent((byte)EventCode.ClaimWin, eventContent, new RaiseEventOptions {
            Receivers = ReceiverGroup.All
        }, new SendOptions()
        {
            DeliveryMode = DeliveryMode.Reliable
        });
    }
예제 #10
0
        private static void EnterWorldPostfix(string __1)
        {
            if (__1.Contains("~server("))
            {
                string[] tags   = __1.Split('~');
                string   server = tags.First(s => s.StartsWith("server("));
                server = server.Substring(7, server.Length - 8);
                string[] addressParts = server.Split(',');

                if (addressParts[0] != ss.AppSettings.Server || addressParts[1] != ss.AppSettings.Port.ToString())
                {
                    Log("Switching to server " + addressParts[0] + ":" + addressParts[1]);

                    ss.AppSettings.UseNameServer = false;
                    ss.AppSettings.Server        = addressParts[0];
                    ss.AppSettings.Port          = int.Parse(addressParts[1]);

                    //VRCFlowNetworkManager.Instance.Method_Public_Void_0();
                    VRCFlowNetworkManager.Instance.Disconnect();
                }
            }
            else if (__1.Contains("~cloud("))
            {
                string[] tags   = __1.Split('~');
                string   server = tags.First(s => s.StartsWith("cloud("));
                server = server.Substring(6, server.Length - 7);
                string[] addressParts = server.Split(',');

                if (!ss.AppSettings.UseNameServer || ss.AppSettings.FixedRegion != addressParts[0] || ss.AppSettings.AppIdRealtime != addressParts[1] || ss.AppSettings.AppVersion != addressParts[2])
                {
                    Log("Switching to cloud " + addressParts[0] + ":" + addressParts[1] + ":" + addressParts[2]);

                    ss.AppSettings.UseNameServer = true;
                    ss.AppSettings.Server        = "";
                    ss.AppSettings.Port          = 0;
                    ss.AppSettings.FixedRegion   = addressParts[0];
                    ss.AppSettings.AppIdRealtime = addressParts[1];
                    ss.AppSettings.AppVersion    = addressParts[2];

                    //VRCFlowNetworkManager.Instance.Method_Public_Void_0();
                    VRCFlowNetworkManager.Instance.Disconnect();
                }
            }
            else
            {
                if (!ss.AppSettings.UseNameServer || ss.AppSettings.FixedRegion != defaultServer.region || ss.AppSettings.AppIdRealtime != defaultServer.appId || ss.AppSettings.AppVersion != defaultServer.appVersion)
                {
                    Log("Switching to " + defaultServer.name);

                    ss.AppSettings.UseNameServer = true;
                    ss.AppSettings.Server        = "";
                    ss.AppSettings.Port          = 0;
                    ss.AppSettings.FixedRegion   = defaultServer.region;
                    ss.AppSettings.AppIdRealtime = defaultServer.appId;
                    ss.AppSettings.AppVersion    = defaultServer.appVersion;

                    //ObjectPublicIPhotonPeerListenerObStBoStObCoDiBo2ObUnique loadbalancingclient = PhotonNetwork.field_Public_Static_ObjectPublicIPhotonPeerListenerObStBoStObCoDiBo2ObUnique_0;
                    //PhotonPeerPublicTyDi2ByObUnique loadbalancingpeer = loadbalancingclient.prop_PhotonPeerPublicTyDi2ByObUnique_0;
                    LoadBalancingClient loadbalancingclient = PhotonNetwork.NetworkingClient;
                    LoadBalancingPeer   loadbalancingpeer   = loadbalancingclient.LoadBalancingPeer;
                    loadbalancingpeer.SerializationProtocolType = SerializationProtocol.GpBinaryV18;

                    //VRCFlowNetworkManager.Instance.Method_Public_Void_0();
                    VRCFlowNetworkManager.Instance.Disconnect();
                }
            }
        }
 /**
  *  @brief Instantiates a new PhotonTrueSyncCommunicator based on a Photon's LoadbalancingPeer.
  *
  *  @param loadBalancingPeer Instance of a Photon's LoadbalancingPeer.
  **/
 internal PhotonTrueSyncCommunicator(LoadBalancingPeer loadBalancingPeer)
 {
     this.loadBalancingPeer = loadBalancingPeer;
 }
예제 #12
0
 /**
  *  @brief Instantiates a new PhotonTrueSyncCommunicator based on a Photon's LoadbalancingPeer.
  *
  *  @param loadBalancingPeer Instance of a Photon's LoadbalancingPeer.
  **/
 internal PhotonTrueSyncCommunicator(LoadBalancingPeer i_LoadBalancingPeer)
 {
     m_LoadBalancingPeer = i_LoadBalancingPeer;
 }