示例#1
0
 //FIXME: ONLY FOR TESTING; SPAWNS ARE REQUESTED BY CLIENTS AND NOT THE SPAWNER ITSELF
 public void SpawnRoom()
 {
     _client.SendMessage(Message.Create(MessageTags.RequestSpawnFromClientToMaster,
                                        new RoomOptions {
         MaxPlayers = 8, Region = "EU", WorldName = "ExampleGame", RoomName = "Act1"
     }), SendMode.Reliable);
 }
示例#2
0
        public void MessageNameToServer(string name)
        {
            if (IsConnected)
            {
                using (DarkRiftWriter writer = DarkRiftWriter.Create()) {
                    writer.Write(name);

                    using (Message message = Message.Create((ushort)Tags.Tag.SET_NAME, writer)) {
                        client.SendMessage(message, SendMode.Reliable);
                    }
                }
            }
        }
        public async Task <bool> Authenticate(DarkRiftClient client)
        {
            authSuccessToken = new TaskCompletionSource <ushort>();
            using (var writer = DarkRiftWriter.Create())
            {
                using (var message = Message.Create((ushort)MasterServerNoReplyTags.AuthRequest, writer))
                {
                    client.SendMessage(message, SendMode.Reliable);
                    client.MessageReceived += SendPassword;
                    await Task.Yield();

                    Task.WaitAny(Task.Delay(config.AuthRequestDelay), authSuccessToken.Task);
                    if (authSuccessToken.Task.IsCompletedSuccessfully)
                    {
                        if (authSuccessToken.Task.Result != (ushort)MasterServerAuthReplies.Success)
                        {
                            throw new DRAuthException("Authentication failed");
                        }
                        return(authSuccessToken.Task.Result == (ushort)MasterServerAuthReplies.Success);
                    }
                    else
                    {
                        authSuccessToken = null;
                        throw new DRAuthException("Authentication Timed Out..");
                    }
                }
            }
        }
        public void WhenAClientConnectsAndImmedtiatelySendsAMessages()
        {
            DarkRiftClient client = new DarkRiftClient();

            using (DarkRiftWriter writer = DarkRiftWriter.Create())
            {
                writer.Write("Hello");
                using Message message = Message.Create(0, writer);

                client.Connect(
                    new BichannelClientConnection(
                        IPAddress.Loopback,
                        world.GetServer(0).ClientManager.Port,
                        world.GetServer(0).NetworkListenerManager.GetNetworkListenersByType <AbstractBichannelListener>()[0].UdpPort,
                        true
                        )
                    );

                bool success = client.SendMessage(message, SendMode.Reliable);
                Assert.IsTrue(success);
            }


            world.AddClient(client);

#if DEBUG
            // We've just requested a load of objects that wont be returned until we close
            // UDP receive TCP receive in client; TCP receive in server
            performanceSteps.ExpectedUnaccountedForSocketAsyncEventArgs += 3;
#endif

            messageAssertions.ExpectMessageOnServer(new ReceivedMessage("Hello", client.ID, 0, 0, SendMode.Reliable));
        }
 /// <summary>
 /// Extension shorthand for sending empty unreliable messages.
 /// </summary>
 /// <param name="client">Client to which this should be sent.</param>
 /// <param name="tag"></param>
 public static void SendEmptyMessageUnreliable(this DarkRiftClient client, ushort tag)
 {
     using (DarkRiftWriter writer = DarkRiftWriter.Create())
     {
         using (DarkRift.Message msg = DarkRift.Message.Create(tag, writer))
             client.SendMessage(msg, SendMode.Unreliable);
     }
 }
 /// <summary>
 /// Extension shorthand for sending empty unreliable messages.
 /// </summary>
 /// <param name="client">Client to which this should be sent.</param>
 /// <param name="tag"></param>
 public static void SendEmptyMessageUnreliable <TTag>(this DarkRiftClient client, TTag tag)
     where TTag : struct, Enum, IConvertible
 {
     using (DarkRiftWriter writer = DarkRiftWriter.Create())
     {
         using (DarkRift.Message msg = DarkRift.Message.Create(Convert.ToUInt16(tag), writer))
             client.SendMessage(msg, SendMode.Unreliable);
     }
 }
        /// <summary>
        /// Extension shorthand for sending reliable messages.
        /// </summary>
        /// <typeparam name="TTag">Type of the message that inherits from IMessage & IDarkRiftSerializable</typeparam>
        /// <param name="client">Client to which this should be sent.</param>
        /// <param name="message">Message object</param>
        public static void SendMessageReliable <TTag>(this DarkRiftClient client, IDarkRiftMessage <TTag> message)
            where TTag : struct, Enum, IConvertible
        {
            using (DarkRiftWriter writer = DarkRiftWriter.Create())
            {
                writer.Write(message);

                using (DarkRift.Message msg = DarkRift.Message.Create(Convert.ToUInt16(message.Tag), writer))
                    client.SendMessage(msg, SendMode.Reliable);
            }
        }
示例#8
0
        private void HandleAccessRoom(IClient client, Message message)
        {
            if (_pendingAccessValidations.ContainsKey(client.ID))
            {
                return;
            }

            var data = message.Deserialize <StringPacket>();

            if (data != null)
            {
                var token = data.Data;

                _pendingAccessValidations[client.ID] = client;

                //Ask master for validation
                _client.SendMessage(Message.Create(MessageTags.ValidateRoomAccess, new RoomAccessValidatePacket {
                    ClientID = client.ID, RoomID = RoomID, Token = token
                }), SendMode.Reliable);
            }
        }
示例#9
0
 public void SendMessage(Message message, SendMode sendMode)
 {
     _darkRiftClient.SendMessage(message, sendMode);
 }