コード例 #1
0
 public void SendConfig(MatchConfig config)
 {
     using (var rental = ObjectPool <ServerUpdateConfigMessage> .Shared.Borrow()) {
         rental.RentedObject.MatchConfig = config;
         Connection.Send(MessageCodes.UpdateConfig, rental.RentedObject);
     }
 }
コード例 #2
0
        public void OnAuthRequestMessage(INetworkConnection conn, AuthRequestMessage msg)
        {
            logger.LogFormat(LogType.Log, "Authentication Request: {0} {1}", msg.AuthUsername, msg.AuthPassword);

            // check the credentials by calling your web server, database table, playfab api, or any method appropriate.
            if (msg.AuthUsername == Username && msg.AuthPassword == Password)
            {
                // create and send msg to client so it knows to proceed
                var authResponseMessage = new AuthResponseMessage
                {
                    Code    = 100,
                    Message = "Success"
                };

                conn.Send(authResponseMessage);

                // Invoke the event to complete a successful authentication
                base.OnServerAuthenticate(conn);
            }
            else
            {
                // create and send msg to client so it knows to disconnect
                var authResponseMessage = new AuthResponseMessage
                {
                    Code    = 200,
                    Message = "Invalid Credentials"
                };

                conn.Send(authResponseMessage);

                // disconnect the client after 1 second so that response message gets delivered
                StartCoroutine(DelayedDisconnect(conn, 1));
            }
        }
コード例 #3
0
        // called after successful authentication
        void OnServerAuthenticated(INetworkConnection conn)
        {
            logger.Log("NetworkSceneManager.OnServerAuthenticated");

            conn.Send(new SceneMessage {
                scenePath = NetworkScenePath, additiveScenes = additiveSceneList.ToArray()
            });
            conn.Send(new SceneReadyMessage());
        }
コード例 #4
0
        public IEnumerator ReadyMessageSetsClientReadyTest()
        {
            connectionToServer.Send(new ReadyMessage());

            yield return(null);

            // ready?
            Assert.That(connectionToClient.IsReady, Is.True);
        }
コード例 #5
0
 public void SetReady(bool isReady)
 {
     if (ServerConnection == null)
     {
         return;
     }
     using (var rental = ObjectPool <PeerReadyMessage> .Shared.Borrow()) {
         rental.RentedObject.IsReady = isReady;
         ServerConnection.Send(MessageCodes.ClientReady, rental.RentedObject);
     }
 }
コード例 #6
0
        internal void SendSpawnMessage(NetworkIdentity identity, INetworkConnection conn)
        {
            // for easier debugging
            if (logger.LogEnabled())
            {
                logger.Log("Server SendSpawnMessage: name=" + identity.name + " sceneId=" + identity.sceneId.ToString("X") + " netid=" + identity.NetId);
            }

            // one writer for owner, one for observers
            using (PooledNetworkWriter ownerWriter = NetworkWriterPool.GetWriter(), observersWriter = NetworkWriterPool.GetWriter())
            {
                bool isOwner = identity.ConnectionToClient == conn;

                ArraySegment <byte> payload = CreateSpawnMessagePayload(isOwner, identity, ownerWriter, observersWriter);

                conn.Send(new SpawnMessage
                {
                    netId         = identity.NetId,
                    isLocalPlayer = conn.Identity == identity,
                    isOwner       = isOwner,
                    sceneId       = identity.sceneId,
                    assetId       = identity.AssetId,
                    // use local values for VR support
                    position = identity.transform.localPosition,
                    rotation = identity.transform.localRotation,
                    scale    = identity.transform.localScale,

                    payload = payload,
                });
            }
        }
コード例 #7
0
 /// <inheritdoc />
 public void Broadcast(ref byte[] data)
 {
     if (currentConnection != null)
     {
         currentConnection.Send(ref data);
     }
 }
コード例 #8
0
ファイル: ChatNetworkManager.cs プロジェクト: twglhk/Mirage
 public void OnClientAuthenticated(INetworkConnection conn)
 {
     // tell the server to create a player with this name
     conn.Send(new CreatePlayerMessage {
         name = PlayerName
     });
 }
コード例 #9
0
ファイル: NetworkClient.cs プロジェクト: aka-coke/MirrorNG
        /// <summary>
        /// Signal that the client connection is ready to enter the game.
        /// <para>This could be for example when a client enters an ongoing game and has finished loading the current scene. The server should respond to the SYSTEM_READY event with an appropriate handler which instantiates the players object for example.</para>
        /// </summary>
        /// <param name="conn">The client connection which is ready.</param>
        /// <returns>True if succcessful</returns>
        public void Ready(INetworkConnection conn)
        {
            if (ready)
            {
                throw new InvalidOperationException("A connection has already been set as ready. There can only be one.");
            }

            if (conn == null)
            {
                throw new InvalidOperationException("Ready() called with invalid connection object: conn=null");
            }

            if (logger.LogEnabled())
            {
                logger.Log("ClientScene.Ready() called with connection [" + conn + "]");
            }


            // Set these before sending the ReadyMessage, otherwise host client
            // will fail in InternalAddPlayer with null readyConnection.
            ready              = true;
            Connection         = conn;
            Connection.IsReady = true;

            // Tell server we're ready to have a player object spawned
            conn.Send(new ReadyMessage());
        }
コード例 #10
0
        protected void SendTargetRPCInternal(INetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
        {
            // this was in Weaver before
            if (!Server || !Server.Active)
            {
                throw new InvalidOperationException("RPC Function " + rpcName + " called on client.");
            }

            // connection parameter is optional. assign if null.
            if (conn == null)
            {
                conn = ConnectionToClient;
            }

            // This cannot use Server.active, as that is not specific to this object.
            if (!IsServer)
            {
                logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
                return;
            }

            // construct the message
            var message = new RpcMessage
            {
                netId          = NetId,
                componentIndex = ComponentIndex,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, rpcName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            conn.Send(message, channelId);
        }
コード例 #11
0
 /// <inheritdoc />
 public void Broadcast(byte[] data, long offset, long length)
 {
     if (currentConnection != null)
     {
         currentConnection.Send(data, offset, length);
     }
 }
コード例 #12
0
        public Task <bool> RunRemoteLocalizationAsync(INetworkConnection connection, Guid spatialLocalizerID, ISpatialLocalizationSettings settings)
        {
            DebugLog($"Initiating remote localization: {connection.ToString()}, {spatialLocalizerID.ToString()}");
            if (remoteLocalizationSessions.TryGetValue(connection, out var currentCompletionSource))
            {
                DebugLog($"Canceling existing remote localization session: {connection.ToString()}");
                currentCompletionSource.TrySetCanceled();
                remoteLocalizationSessions.Remove(connection);
            }

            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            remoteLocalizationSessions.Add(connection, taskCompletionSource);

            using (MemoryStream stream = new MemoryStream())
                using (BinaryWriter message = new BinaryWriter(stream))
                {
                    message.Write(LocalizeCommand);
                    message.Write(spatialLocalizerID);
                    settings.Serialize(message);

                    byte[] data = stream.ToArray();
                    connection.Send(ref data);
                }

            return(taskCompletionSource.Task);
        }
コード例 #13
0
 public override void OnClientAuthenticate(INetworkConnection conn)
 {
     conn.RegisterHandler <AcceptPasswordMessage>(AcceptPasswordMessageHandler);
     conn.Send(new PasswordMessage()
     {
         password = authPassword
     });
 }
コード例 #14
0
ファイル: NetworkServer.cs プロジェクト: RaveKev/MirrorNG
        internal void HideForConnection(NetworkIdentity identity, INetworkConnection conn)
        {
            var msg = new ObjectHideMessage
            {
                netId = identity.NetId
            };

            conn.Send(msg);
        }
コード例 #15
0
ファイル: NetworkServer.cs プロジェクト: RaveKev/MirrorNG
        void SpawnObserversForConnection(INetworkConnection conn)
        {
            if (logger.LogEnabled())
            {
                logger.Log("Spawning " + Spawned.Count + " objects for conn " + conn);
            }

            if (!conn.IsReady)
            {
                // client needs to finish initializing before we can spawn objects
                // otherwise it would not find them.
                return;
            }

            // let connection know that we are about to start spawning...
            conn.Send(new ObjectSpawnStartedMessage());

            // add connection to each nearby NetworkIdentity's observers, which
            // internally sends a spawn message for each one to the connection.
            foreach (NetworkIdentity identity in Spawned.Values)
            {
                // try with far away ones in ummorpg!
                //TODO this is different
                if (identity.gameObject.activeSelf)
                {
                    if (logger.LogEnabled())
                    {
                        logger.Log("Sending spawn message for current server objects name='" + identity.name + "' netId=" + identity.NetId + " sceneId=" + identity.sceneId);
                    }

                    bool visible = identity.OnCheckObserver(conn);
                    if (visible)
                    {
                        identity.AddObserver(conn);
                    }
                }
            }

            // let connection know that we finished spawning, so it can call
            // OnStartClient on each one (only after all were spawned, which
            // is how Unity's Start() function works too)
            conn.Send(new ObjectSpawnFinishedMessage());
        }
コード例 #16
0
 private void SendComponentCreation(INetworkConnection connection)
 {
     using (MemoryStream memoryStream = new MemoryStream())
         using (BinaryWriter message = new BinaryWriter(memoryStream))
         {
             this.ComponentBroadcasterService.WriteHeader(message, this, ComponentBroadcasterChangeType.Created);
             message.Flush();
             connection.Send(memoryStream.GetBuffer(), 0, memoryStream.Position);
         }
 }
コード例 #17
0
    public async UniTask DisconnectLate(INetworkConnection conn, float time)
    {
        await UniTask.Delay((int)(time * 1000));

        conn.Send(new AcceptPasswordMessage()
        {
            allowed = false
        });
        conn.Disconnect();
    }
コード例 #18
0
 private void SendComponentCreation(INetworkConnection connection)
 {
     using (MemoryStream memoryStream = new MemoryStream())
         using (BinaryWriter message = new BinaryWriter(memoryStream))
         {
             this.ComponentBroadcasterService.WriteHeader(message, this, ComponentBroadcasterChangeType.Created);
             message.Flush();
             var data = memoryStream.ToArray();
             connection.Send(ref data);
         }
 }
コード例 #19
0
 private void PasswordMessageHandler(INetworkConnection conn, PasswordMessage msg)
 {
     if (msg.password == authPassword)
     {
         conn.Send(new AcceptPasswordMessage()
         {
             allowed = true
         });
         base.OnServerAuthenticate(conn);
     }
 }
 private void SendLocalizationCompleteCommand(INetworkConnection socketEndpoint, bool localizationSuccessful)
 {
     using (MemoryStream stream = new MemoryStream())
         using (BinaryWriter message = new BinaryWriter(stream))
         {
             message.Write(LocalizationCompleteCommand);
             message.Write(localizationSuccessful);
             message.Flush();
             socketEndpoint.Send(stream.GetBuffer(), 0, stream.Position);
         }
 }
コード例 #21
0
        // called after successful authentication
        void OnServerAuthenticated(INetworkConnection conn)
        {
            logger.Log("NetworkSceneManager.OnServerAuthenticated");

            if (!string.IsNullOrEmpty(NetworkSceneName))
            {
                conn.Send(new SceneMessage {
                    sceneName = NetworkSceneName
                });
            }
        }
コード例 #22
0
        private void SendComponentCreation(INetworkConnection connection)
        {
            using (MemoryStream memoryStream = new MemoryStream())
                using (BinaryWriter message = new BinaryWriter(memoryStream))
                {
                    this.ComponentBroadcasterService.WriteHeader(message, this, ComponentBroadcasterChangeType.Created);
                    message.Flush();

                    memoryStream.TryGetBuffer(out var buffer);
                    connection.Send(buffer.Array, buffer.Offset, buffer.Count);
                }
        }
コード例 #23
0
 private void SendLocalizationCompleteCommand(INetworkConnection socketEndpoint, bool localizationSuccessful)
 {
     using (MemoryStream stream = new MemoryStream())
         using (BinaryWriter message = new BinaryWriter(stream))
         {
             message.Write(LocalizationCompleteCommand);
             message.Write(localizationSuccessful);
             message.Flush();
             stream.TryGetBuffer(out var buffer);
             socketEndpoint.Send(buffer.Array, buffer.Offset, buffer.Count);
         }
 }
コード例 #24
0
        private void SendLocalizationCompleteCommand(INetworkConnection socketEndpoint, bool localizationSuccessful)
        {
            using (MemoryStream stream = new MemoryStream())
                using (BinaryWriter message = new BinaryWriter(stream))
                {
                    message.Write(LocalizationCompleteCommand);
                    message.Write(localizationSuccessful);

                    byte[] data = stream.ToArray();
                    socketEndpoint.Send(ref data);
                }
        }
コード例 #25
0
ファイル: BasicAuthenticator.cs プロジェクト: twglhk/Mirage
        public override void OnClientAuthenticate(INetworkConnection conn)
        {
            conn.RegisterHandler <AuthResponseMessage>(OnAuthResponseMessage);

            var authRequestMessage = new AuthRequestMessage
            {
                AuthUsername = Username,
                AuthPassword = Password
            };

            conn.Send(authRequestMessage);
        }
コード例 #26
0
        private void OnPacketRelayRequest(INetworkConnection con, Packet gmsg)
        {
            PacketRelay        relay   = (PacketRelay)gmsg;
            INetworkConnection userCon = ConnectionManager.GetUserConnection(relay.To);

            if (userCon == null)
            {
                // target user not attached.  sorry it didn't work out.
                return;
            }

            userCon.Send(relay.Message, relay.Flags);
        }
コード例 #27
0
        // called after successful authentication
        void OnServerAuthenticated(INetworkConnection conn)
        {
            logger.Log("NetworkSceneManager.OnServerAuthenticated");

            // proceed with the login handshake by calling OnServerConnect
            if (!string.IsNullOrEmpty(NetworkSceneName))
            {
                var msg = new SceneMessage {
                    sceneName = NetworkSceneName
                };
                conn.Send(msg);
            }
        }
コード例 #28
0
ファイル: NetworkServer.cs プロジェクト: RaveKev/MirrorNG
        /// <summary>
        /// Sets the client of the connection to be not-ready.
        /// <para>Clients that are not ready do not receive spawned objects or state synchronization updates. They client can be made ready again by calling SetClientReady().</para>
        /// </summary>
        /// <param name="conn">The connection of the client to make not ready.</param>
        public void SetClientNotReady(INetworkConnection conn)
        {
            if (conn.IsReady)
            {
                if (logger.LogEnabled())
                {
                    logger.Log("PlayerNotReady " + conn);
                }
                conn.IsReady = false;
                conn.RemoveObservers();

                conn.Send(new NotReadyMessage());
            }
        }
コード例 #29
0
        /// <summary>
        /// Sets the client of the connection to be not-ready.
        /// <para>Clients that are not ready do not receive spawned objects or state synchronization updates. They client can be made ready again by calling SetClientReady().</para>
        /// </summary>
        /// <param name="conn">The connection of the client to make not ready.</param>
        public void SetClientNotReady(INetworkConnection conn)
        {
            if (conn.IsReady)
            {
                if (LogFilter.Debug)
                {
                    Debug.Log("PlayerNotReady " + conn);
                }
                conn.IsReady = false;
                conn.RemoveObservers();

                conn.Send(new NotReadyMessage());
            }
        }
コード例 #30
0
ファイル: NetworkTime.cs プロジェクト: twglhk/Mirage
        // executed at the server when we receive a ping message
        // reply with a pong containing the time from the client
        // and time from the server
        internal void OnServerPing(INetworkConnection conn, NetworkPingMessage msg)
        {
            if (logger.LogEnabled())
            {
                logger.Log("OnPingServerMessage  conn=" + conn);
            }

            var pongMsg = new NetworkPongMessage
            {
                clientTime = msg.clientTime,
                serverTime = LocalTime()
            };

            conn.Send(pongMsg, Channel.Unreliable);
        }
コード例 #31
0
ファイル: ServerBase.cs プロジェクト: kamilion/WISP
 private void RelayPacketToRemoteUser(AuthTicket target, Packet msg, ServerUser from, INetworkConnection con)
 {
     PacketRelay relay = MakeRelayPacket(target.TargetServer, target.AccountID, from, msg);
     con.Send(relay);
 }