コード例 #1
0
        private void MigrateHost(int newHostId, int oldHostId, bool broadcast)
        {
            if (ClientDict.ContainsKey(newHostId))
            {
                if (broadcast)
                {
                    var newProperties = new Hashtable {
                        { GamePropertyKey.MasterClientId, newHostId }
                    };
                    var expectedProperties = new Hashtable {
                        { GamePropertyKey.MasterClientId, oldHostId }
                    };
                    SetRoomProperties(newProperties, expectedProperties);
                }

                Server = ClientDict[newHostId];
                HostMigratedSubject.OnNext(Server);
            }
        }
コード例 #2
0
        private void InitializeEvents()
        {
            _listener.NetworkReceiveEvent += (peer, reader) =>
            {
                var bytes = reader.Data;
                var evt   = Serializer.Deserialize(bytes, reader.AvailableBytes);

                EventSubject.OnNext(evt);
            };

            _listener.NetworkReceiveUnconnectedEvent += (endpoint, reader, type) =>
            {
                Debug.Log("NetworkReceiveUnconnectedEvent");
            };

            _listener.PeerConnectedEvent += peer =>
            {
                Debug.Log("Peer connected on " + _manager.LocalPort + " :" + peer.EndPoint.Host + ":" + peer.EndPoint.Port);
                var client = new Client(_isServer ? 2 : 1);
                if (!ClientDict.ContainsKey(client.ClientId))
                {
                    AddClient(client, true);
                }
            };

            _listener.PeerDisconnectedEvent += (peer, info) =>
            {
                Debug.Log("Peer disconnected on " + _manager.LocalPort + " :" + peer.EndPoint.Host + ":" + peer.EndPoint.Port);
                RemoveClient(_isServer ? 2 : 1);
            };

            _listener.NetworkErrorEvent += (endpoint, code) =>
            {
                Debug.LogError("Error with code: " + code);
            };
        }